From 984d47f9c8c0c8d6f443114509dccf3eca80d933 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Tue, 20 Jan 2015 22:50:26 +0100 Subject: [PATCH] Test work without vpcs binary --- .travis.yml | 2 +- docs/api/examples/post_vpcs.txt | 2 +- gns3server/modules/port_manager.py | 1 - gns3server/modules/vpcs/vpcs_vm.py | 4 ++-- tests/modules/vpcs/test_vpcs_vm.py | 8 ++++++-- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 59cbebed..2c741583 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ python: before_install: - sudo add-apt-repository ppa:gns3/ppa -y - sudo apt-get update -q - - sudo apt-get install vpcs dynamips + - sudo apt-get install dynamips install: - python setup.py install diff --git a/docs/api/examples/post_vpcs.txt b/docs/api/examples/post_vpcs.txt index 4fdc51cd..9b849f8c 100644 --- a/docs/api/examples/post_vpcs.txt +++ b/docs/api/examples/post_vpcs.txt @@ -20,5 +20,5 @@ X-ROUTE: /vpcs "name": "PC TEST 1", "project_uuid": "a1e920ca-338a-4e9f-b363-aa607b09dd80", "script_file": null, - "uuid": "f598eb3a-67b2-43ab-af37-3c9b1f643cdd" + "uuid": "12171ed6-4234-4ba7-9ef5-db3631a3a2e4" } diff --git a/gns3server/modules/port_manager.py b/gns3server/modules/port_manager.py index 6ffc3309..ad90d92a 100644 --- a/gns3server/modules/port_manager.py +++ b/gns3server/modules/port_manager.py @@ -157,7 +157,6 @@ class PortManager: Get an available TCP console port and reserve it """ - print("FREE") port = self.find_unused_port(self._console_port_range[0], self._console_port_range[1], host=self._console_host, diff --git a/gns3server/modules/vpcs/vpcs_vm.py b/gns3server/modules/vpcs/vpcs_vm.py index 02a20a9b..f947c46a 100644 --- a/gns3server/modules/vpcs/vpcs_vm.py +++ b/gns3server/modules/vpcs/vpcs_vm.py @@ -77,8 +77,6 @@ class VPCSVM(BaseVM): else: self._console = self._manager.port_manager.get_free_console_port() - self._check_requirements() - def __del__(self): self._kill_process() @@ -169,6 +167,8 @@ class VPCSVM(BaseVM): Starts the VPCS process. """ + self._check_requirements() + if not self.is_running(): if not self._ethernet_adapter.get_nio(0): raise VPCSError("This VPCS instance must be connected in order to start") diff --git a/tests/modules/vpcs/test_vpcs_vm.py b/tests/modules/vpcs/test_vpcs_vm.py index 08f80be4..00689b0e 100644 --- a/tests/modules/vpcs/test_vpcs_vm.py +++ b/tests/modules/vpcs/test_vpcs_vm.py @@ -44,21 +44,24 @@ def test_vm(project, manager): @patch("subprocess.check_output", return_value="Welcome to Virtual PC Simulator, version 0.1".encode("utf-8")) -def test_vm_invalid_vpcs_version(project, manager): +def test_vm_invalid_vpcs_version(project, manager, loop): with pytest.raises(VPCSError): vm = VPCSVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager) + loop.run_until_complete(asyncio.async(vm.start())) assert vm.name == "test" assert vm.uuid == "00010203-0405-0607-0809-0a0b0c0d0e0f" @patch("gns3server.config.Config.get_section_config", return_value={"path": "/bin/test_fake"}) -def test_vm_invalid_vpcs_path(project, manager): +def test_vm_invalid_vpcs_path(project, manager, loop): with pytest.raises(VPCSError): vm = VPCSVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager) + loop.run_until_complete(asyncio.async(vm.start())) assert vm.name == "test" assert vm.uuid == "00010203-0405-0607-0809-0a0b0c0d0e0f" +@patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True) def test_start(project, loop, manager): with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()): vm = VPCSVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager) @@ -68,6 +71,7 @@ def test_start(project, loop, manager): assert vm.is_running() +@patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True) def test_stop(project, loop, manager): process = MagicMock() with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):