From 2ba6eac1135e0ddf01cb2d975822303d258c5299 Mon Sep 17 00:00:00 2001 From: grossmj Date: Thu, 13 Aug 2020 17:10:31 +0930 Subject: [PATCH] Fix tests --- gns3server/compute/qemu/__init__.py | 10 ++++------ gns3server/compute/qemu/qemu_vm.py | 20 ++++++++++---------- tests/compute/qemu/test_qemu_vm.py | 1 + tests/compute/test_manager.py | 3 ++- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/gns3server/compute/qemu/__init__.py b/gns3server/compute/qemu/__init__.py index 663ee37f..bca490cc 100644 --- a/gns3server/compute/qemu/__init__.py +++ b/gns3server/compute/qemu/__init__.py @@ -48,6 +48,7 @@ class Qemu(BaseManager): super().__init__() self._guest_cid_lock = asyncio.Lock() + self.config_disk = "config.img" self._init_config_disk() async def create_node(self, *args, **kwargs): @@ -353,12 +354,10 @@ class Qemu(BaseManager): Initialize the default config disk """ - self.config_disk = "config.img" try: self.get_abs_image_path(self.config_disk) - except (NodeError, ImageMissingError) as e: - config_disk_zip = get_resource("compute/qemu/resources/{}.zip" - .format(self.config_disk)) + except (NodeError, ImageMissingError): + config_disk_zip = get_resource("compute/qemu/resources/{}.zip".format(self.config_disk)) if config_disk_zip and os.path.exists(config_disk_zip): directory = self.get_images_directory() try: @@ -366,5 +365,4 @@ class Qemu(BaseManager): except OSError as e: log.warning("Config disk creation: {}".format(e)) else: - log.warning("Config disk: image '{}' missing" - .format(self.config_disk)) + log.warning("Config disk: image '{}' missing".format(self.config_disk)) diff --git a/gns3server/compute/qemu/qemu_vm.py b/gns3server/compute/qemu/qemu_vm.py index 63a99c72..a89076cb 100644 --- a/gns3server/compute/qemu/qemu_vm.py +++ b/gns3server/compute/qemu/qemu_vm.py @@ -131,17 +131,17 @@ class QemuVM(BaseNode): # config disk self.config_disk_name = self.manager.config_disk self.config_disk_image = "" - if not shutil.which("mcopy"): - log.warning("Config disk: 'mtools' are not installed.") - self.config_disk_name = "" - else: - try: - self.config_disk_image = self.manager.get_abs_image_path( - self.config_disk_name) - except (NodeError, ImageMissingError) as e: - log.warning("Config disk: image '{}' missing" - .format(self.config_disk_name)) + if self.config_disk_name: + if not shutil.which("mcopy"): + log.warning("Config disk: 'mtools' are not installed.") self.config_disk_name = "" + else: + try: + self.config_disk_image = self.manager.get_abs_image_path(self.config_disk_name) + except (NodeError, ImageMissingError) as e: + log.warning("Config disk: image '{}' missing" + .format(self.config_disk_name)) + self.config_disk_name = "" log.info('QEMU VM "{name}" [{id}] has been created'.format(name=self._name, id=self._id)) diff --git a/tests/compute/qemu/test_qemu_vm.py b/tests/compute/qemu/test_qemu_vm.py index 7df7df61..6b69ab75 100644 --- a/tests/compute/qemu/test_qemu_vm.py +++ b/tests/compute/qemu/test_qemu_vm.py @@ -337,6 +337,7 @@ def test_set_qemu_path_kvm_binary(vm, fake_qemu_binary): 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("gns3server.compute.qemu.QemuVM._check_qemu_path"): vm = QemuVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", compute_project, manager, platform="x86_64") diff --git a/tests/compute/test_manager.py b/tests/compute/test_manager.py index bceb9e20..e257e763 100644 --- a/tests/compute/test_manager.py +++ b/tests/compute/test_manager.py @@ -18,7 +18,7 @@ import uuid import os import pytest -from unittest.mock import patch +from unittest.mock import patch, MagicMock from tests.utils import asyncio_patch from gns3server.compute.vpcs import VPCS @@ -41,6 +41,7 @@ async def vpcs(loop, port_manager): async def qemu(loop, port_manager): Qemu._instance = None + Qemu._init_config_disk = MagicMock() # do not create the config.img image qemu = Qemu.instance() qemu.port_manager = port_manager return qemu