1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-25 00:08:11 +00:00

If a VM is already loaded, we return a VM instead of creating it twice

Partial fix for #81
This commit is contained in:
Julien Duponchelle 2015-03-02 15:35:36 +01:00
parent 914ea0326c
commit 66860655b9
2 changed files with 17 additions and 0 deletions

View File

@ -200,6 +200,9 @@ class BaseManager:
:param vm_id: restore a VM identifier
"""
if vm_id in self._vms:
return self._vms[vm_id]
project = ProjectManager.instance().get_project(project_id)
if vm_id and isinstance(vm_id, int):
with (yield from BaseManager._convert_lock):

View File

@ -34,6 +34,20 @@ def test_create_vm_new_topology(loop, project, port_manager):
assert vm in project.vms
def test_create_twice_same_vm_new_topology(loop, project, port_manager):
project._vms = set()
VPCS._instance = None
vpcs = VPCS.instance()
vpcs.port_manager = port_manager
vm_id = str(uuid.uuid4())
vm = loop.run_until_complete(vpcs.create_vm("PC 1", project.id, vm_id, console=2222))
assert vm in project.vms
assert len(project.vms) == 1
vm = loop.run_until_complete(vpcs.create_vm("PC 2", project.id, vm_id, console=2222))
assert len(project.vms) == 1
def test_create_vm_new_topology_without_uuid(loop, project, port_manager):
VPCS._instance = None