From a3c8201bcc89f930a47209498d1ea914c1530bd1 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Wed, 1 Apr 2015 17:59:58 +0200 Subject: [PATCH] Do not crash if no console port is available for VBox I don't know how user manage to fall in this situation. Fix #127 --- gns3server/modules/virtualbox/virtualbox_vm.py | 2 +- tests/modules/virtualbox/test_virtualbox_manager.py | 4 +++- tests/modules/virtualbox/test_virtualbox_vm.py | 1 - 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/gns3server/modules/virtualbox/virtualbox_vm.py b/gns3server/modules/virtualbox/virtualbox_vm.py index 6d610923..aff3c3bf 100644 --- a/gns3server/modules/virtualbox/virtualbox_vm.py +++ b/gns3server/modules/virtualbox/virtualbox_vm.py @@ -189,7 +189,7 @@ class VirtualBoxVM(BaseVM): # add a guest property to let the VM know about the GNS3 project directory yield from self.manager.execute("guestproperty", ["set", self._vmname, "ProjectDirInGNS3", self.working_dir]) - if self._enable_remote_console: + if self._enable_remote_console and self._console is not None: self._start_remote_console() @asyncio.coroutine diff --git a/tests/modules/virtualbox/test_virtualbox_manager.py b/tests/modules/virtualbox/test_virtualbox_manager.py index 3faf2e0f..f6185bed 100644 --- a/tests/modules/virtualbox/test_virtualbox_manager.py +++ b/tests/modules/virtualbox/test_virtualbox_manager.py @@ -38,12 +38,14 @@ def test_vm_invalid_vboxmanage_path(manager): with pytest.raises(VirtualBoxError): manager.find_vboxmanage() + def test_vm_non_executable_vboxmanage_path(manager): tmpfile = tempfile.NamedTemporaryFile() with patch("gns3server.config.Config.get_section_config", return_value={"vboxmanage_path": tmpfile.name}): with pytest.raises(VirtualBoxError): manager.find_vboxmanage() + def test_vm_invalid_executable_name_vboxmanage_path(manager, tmpdir): path = str(tmpdir / "vpcs") with open(path, "w+") as f: @@ -54,6 +56,7 @@ def test_vm_invalid_executable_name_vboxmanage_path(manager, tmpdir): with pytest.raises(VirtualBoxError): manager.find_vboxmanage() + def test_vboxmanage_path(manager, tmpdir): path = str(tmpdir / "VBoxManage") with open(path, "w+") as f: @@ -62,4 +65,3 @@ def test_vboxmanage_path(manager, tmpdir): tmpfile = tempfile.NamedTemporaryFile() with patch("gns3server.config.Config.get_section_config", return_value={"vboxmanage_path": path}): assert manager.find_vboxmanage() == path - diff --git a/tests/modules/virtualbox/test_virtualbox_vm.py b/tests/modules/virtualbox/test_virtualbox_vm.py index be343170..8b91431e 100644 --- a/tests/modules/virtualbox/test_virtualbox_vm.py +++ b/tests/modules/virtualbox/test_virtualbox_vm.py @@ -54,4 +54,3 @@ def test_vm_invalid_virtualbox_api_version(loop, project, manager): with pytest.raises(VirtualBoxError): vm = VirtualBoxVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager, "test", False) loop.run_until_complete(asyncio.async(vm.create())) -