diff --git a/gns3server/controller/gns3vm/__init__.py b/gns3server/controller/gns3vm/__init__.py index 88b3f5da..dec8a8c3 100644 --- a/gns3server/controller/gns3vm/__init__.py +++ b/gns3server/controller/gns3vm/__init__.py @@ -260,6 +260,9 @@ class GNS3VM: """ engine = self.current_engine() if not engine.running: + if self._settings["vmname"] is None: + return + log.info("Start the GNS3 VM") engine.vmname = self._settings["vmname"] engine.ram = self._settings["ram"] diff --git a/tests/controller/test_controller.py b/tests/controller/test_controller.py index d7cac05e..3227c54f 100644 --- a/tests/controller/test_controller.py +++ b/tests/controller/test_controller.py @@ -376,7 +376,8 @@ def test_getProject(controller, async_run): def test_start(controller, async_run): controller.gns3vm.settings = { "enable": False, - "engine": "vmware" + "engine": "vmware", + "vmname": "GNS3 VM" } with asyncio_patch("gns3server.controller.compute.Compute.connect") as mock: async_run(controller.start()) @@ -390,7 +391,8 @@ def test_start_vm(controller, async_run): """ controller.gns3vm.settings = { "enable": True, - "engine": "vmware" + "engine": "vmware", + "vmname": "GNS3 VM" } with asyncio_patch("gns3server.controller.gns3vm.vmware_gns3_vm.VMwareGNS3VM.start") as mock: with asyncio_patch("gns3server.controller.compute.Compute.connect") as mock_connect: @@ -415,7 +417,8 @@ def test_stop_vm(controller, async_run): controller.gns3vm.settings = { "enable": True, "engine": "vmware", - "when_exit": "stop" + "when_exit": "stop", + "vmname": "GNS3 VM" } controller.gns3vm.current_engine().running = True with asyncio_patch("gns3server.controller.gns3vm.vmware_gns3_vm.VMwareGNS3VM.stop") as mock: @@ -430,7 +433,8 @@ def test_suspend_vm(controller, async_run): controller.gns3vm.settings = { "enable": True, "engine": "vmware", - "when_exit": "suspend" + "when_exit": "suspend", + "vmname": "GNS3 VM" } controller.gns3vm.current_engine().running = True with asyncio_patch("gns3server.controller.gns3vm.vmware_gns3_vm.VMwareGNS3VM.suspend") as mock: @@ -445,7 +449,8 @@ def test_keep_vm(controller, async_run): controller.gns3vm.settings = { "enable": True, "engine": "vmware", - "when_exit": "keep" + "when_exit": "keep", + "vmname": "GNS3 VM" } controller.gns3vm.current_engine().running = True with asyncio_patch("gns3server.controller.gns3vm.vmware_gns3_vm.VMwareGNS3VM.suspend") as mock: diff --git a/tests/controller/test_gns3vm.py b/tests/controller/test_gns3vm.py index cbeeded9..d99a558f 100644 --- a/tests/controller/test_gns3vm.py +++ b/tests/controller/test_gns3vm.py @@ -21,6 +21,7 @@ from tests.utils import asyncio_patch, AsyncioMagicMock from gns3server.controller.gns3vm import GNS3VM from gns3server.controller.gns3vm.gns3_vm_error import GNS3VMError + @pytest.fixture def dummy_engine(): engine = AsyncioMagicMock() @@ -65,7 +66,8 @@ def test_update_settings(controller, async_run): vm = GNS3VM(controller) vm.settings = { "enable": True, - "engine": "vmware" + "engine": "vmware", + "vmname": "GNS3 VM" } with asyncio_patch("gns3server.controller.gns3vm.vmware_gns3_vm.VMwareGNS3VM.start"): async_run(vm.auto_start_vm()) @@ -94,4 +96,3 @@ def test_auto_start_with_error(async_run, controller, dummy_gns3vm, dummy_engine async_run(dummy_gns3vm.auto_start_vm()) assert dummy_engine.start.called assert controller.computes["vm"].name == "GNS3 VM (Test VM)" -