diff --git a/gns3server/modules/iou/__init__.py b/gns3server/modules/iou/__init__.py index 1a7211e5..3cdddfe7 100644 --- a/gns3server/modules/iou/__init__.py +++ b/gns3server/modules/iou/__init__.py @@ -46,13 +46,14 @@ class IOU(BaseManager): return vm @asyncio.coroutine - def delete_vm(self, vm_id, *args, **kwargs): + def close_vm(self, vm_id, *args, **kwargs): vm = self.get_vm(vm_id) i = self._used_application_ids[vm_id] self._free_application_ids.insert(0, i) del self._used_application_ids[vm_id] - yield from super().delete_vm(vm_id, *args, **kwargs) + yield from super().close_vm(vm_id, *args, **kwargs) + return vm def get_application_id(self, vm_id): """ diff --git a/gns3server/modules/project.py b/gns3server/modules/project.py index 0c622063..a6a48a66 100644 --- a/gns3server/modules/project.py +++ b/gns3server/modules/project.py @@ -274,10 +274,7 @@ class Project: tasks = [] for vm in self._vms: - if asyncio.iscoroutinefunction(vm.close): - tasks.append(asyncio.async(vm.close())) - else: - vm.close() + tasks.append(asyncio.async(vm.manager.close_vm(vm.id))) if tasks: done, _ = yield from asyncio.wait(tasks) diff --git a/gns3server/modules/vpcs/__init__.py b/gns3server/modules/vpcs/__init__.py index 03250c55..bae14fe1 100644 --- a/gns3server/modules/vpcs/__init__.py +++ b/gns3server/modules/vpcs/__init__.py @@ -47,13 +47,14 @@ class VPCS(BaseManager): return vm @asyncio.coroutine - def delete_vm(self, vm_id, *args, **kwargs): + def close_vm(self, vm_id, *args, **kwargs): vm = self.get_vm(vm_id) i = self._used_mac_ids[vm_id] self._free_mac_ids[vm.project.id].insert(0, i) del self._used_mac_ids[vm_id] - yield from super().delete_vm(vm_id, *args, **kwargs) + yield from super().close_vm(vm_id, *args, **kwargs) + return vm def get_mac_id(self, vm_id): """ diff --git a/tests/modules/test_project.py b/tests/modules/test_project.py index a647508c..eb52dcef 100644 --- a/tests/modules/test_project.py +++ b/tests/modules/test_project.py @@ -37,8 +37,9 @@ def manager(port_manager): @pytest.fixture(scope="function") -def vm(project, manager): - return VPCSVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager) +def vm(project, manager, loop): + vm = manager.create_vm("test", project.id, "00010203-0405-0607-0809-0a0b0c0d0e0f") + return loop.run_until_complete(asyncio.async(vm)) def test_affect_uuid(): @@ -180,11 +181,8 @@ def test_project_add_vm(manager): assert len(project.vms) == 1 -def test_project_close(loop, manager): - project = Project() - vm = VPCSVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager) - project.add_vm(vm) - vm.manager._vms = {vm.id: vm} +def test_project_close(loop, vm, project): + with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM.close") as mock: loop.run_until_complete(asyncio.async(project.close())) assert mock.called