mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-28 03:08:14 +00:00
Fix tests
This commit is contained in:
parent
068c31038f
commit
2ba6eac113
@ -48,6 +48,7 @@ class Qemu(BaseManager):
|
|||||||
|
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self._guest_cid_lock = asyncio.Lock()
|
self._guest_cid_lock = asyncio.Lock()
|
||||||
|
self.config_disk = "config.img"
|
||||||
self._init_config_disk()
|
self._init_config_disk()
|
||||||
|
|
||||||
async def create_node(self, *args, **kwargs):
|
async def create_node(self, *args, **kwargs):
|
||||||
@ -353,12 +354,10 @@ class Qemu(BaseManager):
|
|||||||
Initialize the default config disk
|
Initialize the default config disk
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self.config_disk = "config.img"
|
|
||||||
try:
|
try:
|
||||||
self.get_abs_image_path(self.config_disk)
|
self.get_abs_image_path(self.config_disk)
|
||||||
except (NodeError, ImageMissingError) as e:
|
except (NodeError, ImageMissingError):
|
||||||
config_disk_zip = get_resource("compute/qemu/resources/{}.zip"
|
config_disk_zip = get_resource("compute/qemu/resources/{}.zip".format(self.config_disk))
|
||||||
.format(self.config_disk))
|
|
||||||
if config_disk_zip and os.path.exists(config_disk_zip):
|
if config_disk_zip and os.path.exists(config_disk_zip):
|
||||||
directory = self.get_images_directory()
|
directory = self.get_images_directory()
|
||||||
try:
|
try:
|
||||||
@ -366,5 +365,4 @@ class Qemu(BaseManager):
|
|||||||
except OSError as e:
|
except OSError as e:
|
||||||
log.warning("Config disk creation: {}".format(e))
|
log.warning("Config disk creation: {}".format(e))
|
||||||
else:
|
else:
|
||||||
log.warning("Config disk: image '{}' missing"
|
log.warning("Config disk: image '{}' missing".format(self.config_disk))
|
||||||
.format(self.config_disk))
|
|
||||||
|
@ -131,13 +131,13 @@ class QemuVM(BaseNode):
|
|||||||
# config disk
|
# config disk
|
||||||
self.config_disk_name = self.manager.config_disk
|
self.config_disk_name = self.manager.config_disk
|
||||||
self.config_disk_image = ""
|
self.config_disk_image = ""
|
||||||
|
if self.config_disk_name:
|
||||||
if not shutil.which("mcopy"):
|
if not shutil.which("mcopy"):
|
||||||
log.warning("Config disk: 'mtools' are not installed.")
|
log.warning("Config disk: 'mtools' are not installed.")
|
||||||
self.config_disk_name = ""
|
self.config_disk_name = ""
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
self.config_disk_image = self.manager.get_abs_image_path(
|
self.config_disk_image = self.manager.get_abs_image_path(self.config_disk_name)
|
||||||
self.config_disk_name)
|
|
||||||
except (NodeError, ImageMissingError) as e:
|
except (NodeError, ImageMissingError) as e:
|
||||||
log.warning("Config disk: image '{}' missing"
|
log.warning("Config disk: image '{}' missing"
|
||||||
.format(self.config_disk_name))
|
.format(self.config_disk_name))
|
||||||
|
@ -337,6 +337,7 @@ def test_set_qemu_path_kvm_binary(vm, fake_qemu_binary):
|
|||||||
|
|
||||||
async def test_set_platform(compute_project, manager):
|
async def test_set_platform(compute_project, manager):
|
||||||
|
|
||||||
|
manager.config_disk = None # avoids conflict with config.img support
|
||||||
with patch("shutil.which", return_value="/bin/qemu-system-x86_64") as which_mock:
|
with patch("shutil.which", return_value="/bin/qemu-system-x86_64") as which_mock:
|
||||||
with patch("gns3server.compute.qemu.QemuVM._check_qemu_path"):
|
with patch("gns3server.compute.qemu.QemuVM._check_qemu_path"):
|
||||||
vm = QemuVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", compute_project, manager, platform="x86_64")
|
vm = QemuVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", compute_project, manager, platform="x86_64")
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
import uuid
|
import uuid
|
||||||
import os
|
import os
|
||||||
import pytest
|
import pytest
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch, MagicMock
|
||||||
from tests.utils import asyncio_patch
|
from tests.utils import asyncio_patch
|
||||||
|
|
||||||
from gns3server.compute.vpcs import VPCS
|
from gns3server.compute.vpcs import VPCS
|
||||||
@ -41,6 +41,7 @@ async def vpcs(loop, port_manager):
|
|||||||
async def qemu(loop, port_manager):
|
async def qemu(loop, port_manager):
|
||||||
|
|
||||||
Qemu._instance = None
|
Qemu._instance = None
|
||||||
|
Qemu._init_config_disk = MagicMock() # do not create the config.img image
|
||||||
qemu = Qemu.instance()
|
qemu = Qemu.instance()
|
||||||
qemu.port_manager = port_manager
|
qemu.port_manager = port_manager
|
||||||
return qemu
|
return qemu
|
||||||
|
Loading…
Reference in New Issue
Block a user