API in order to get the list of IOU, Dynamips, Qemu images

This commit is contained in:
Julien Duponchelle committed 2015-04-16 18:32:12 +02:00
1 parent 5a4ffae6a2
commit bca90bc563
14 files changed
+218 -36

No files matched your search

+3 -15
View File
@@ -36,11 +36,7 @@ def iou(port_manager):
return iou
def test_get_application_id(loop, project, port_manager):
# Cleanup the IOU object
IOU._instance = None
iou = IOU.instance()
iou.port_manager = port_manager
def test_get_application_id(loop, project, iou):
vm1_id = str(uuid.uuid4())
vm2_id = str(uuid.uuid4())
vm3_id = str(uuid.uuid4())
@@ -54,11 +50,7 @@ def test_get_application_id(loop, project, port_manager):
assert iou.get_application_id(vm3_id) == 1
def test_get_application_id_multiple_project(loop, port_manager):
# Cleanup the IOU object
IOU._instance = None
iou = IOU.instance()
iou.port_manager = port_manager
def test_get_application_id_multiple_project(loop, iou):
vm1_id = str(uuid.uuid4())
vm2_id = str(uuid.uuid4())
vm3_id = str(uuid.uuid4())
@@ -72,11 +64,7 @@ def test_get_application_id_multiple_project(loop, port_manager):
assert iou.get_application_id(vm3_id) == 3
def test_get_application_id_no_id_available(loop, project, port_manager):
# Cleanup the IOU object
IOU._instance = None
iou = IOU.instance()
iou.port_manager = port_manager
def test_get_application_id_no_id_available(loop, project, iou):
with pytest.raises(IOUError):
for i in range(1, 513):
vm_id = str(uuid.uuid4())
+36 -19
View File
@@ -25,6 +25,14 @@ from gns3server.modules.vpcs import VPCS
from gns3server.modules.iou import IOU
@pytest.fixture(scope="function")
def vpcs(port_manager):
VPCS._instance = None
vpcs = VPCS.instance()
vpcs.port_manager = port_manager
return vpcs
@pytest.fixture(scope="function")
def iou(port_manager):
IOU._instance = None
@@ -33,22 +41,14 @@ def iou(port_manager):
return iou
def test_create_vm_new_topology(loop, project, port_manager):
VPCS._instance = None
vpcs = VPCS.instance()
vpcs.port_manager = port_manager
def test_create_vm_new_topology(loop, project, vpcs):
vm_id = str(uuid.uuid4())
vm = loop.run_until_complete(vpcs.create_vm("PC 1", project.id, vm_id))
assert vm in project.vms
def test_create_twice_same_vm_new_topology(loop, project, port_manager):
def test_create_twice_same_vm_new_topology(loop, project, vpcs):
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
@@ -57,17 +57,13 @@ def test_create_twice_same_vm_new_topology(loop, project, port_manager):
assert len(project.vms) == 1
def test_create_vm_new_topology_without_uuid(loop, project, port_manager):
VPCS._instance = None
vpcs = VPCS.instance()
vpcs.port_manager = port_manager
def test_create_vm_new_topology_without_uuid(loop, project, vpcs):
vm = loop.run_until_complete(vpcs.create_vm("PC 1", project.id, None))
assert vm in project.vms
assert len(vm.id) == 36
def test_create_vm_old_topology(loop, project, tmpdir, port_manager):
def test_create_vm_old_topology(loop, project, tmpdir, vpcs):
with patch("gns3server.modules.project.Project.is_local", return_value=True):
# Create an old topology directory
@@ -79,9 +75,6 @@ def test_create_vm_old_topology(loop, project, tmpdir, port_manager):
with open(os.path.join(vm_dir, "startup.vpc"), "w+") as f:
f.write("1")
VPCS._instance = None
vpcs = VPCS.instance()
vpcs.port_manager = port_manager
vm_id = 1
vm = loop.run_until_complete(vpcs.create_vm("PC 1", project.id, vm_id))
assert len(vm.id) == 36
@@ -121,3 +114,27 @@ def test_get_relative_image_path(iou, tmpdir):
assert iou.get_relative_image_path(path2) == "test2.bin"
assert iou.get_relative_image_path("test2.bin") == "test2.bin"
assert iou.get_relative_image_path("../test1.bin") == path1
def test_list_images(loop, iou, tmpdir):
fake_images = ["a.bin", "b.bin", ".blu.bin"]
for image in fake_images:
with open(str(tmpdir / image), "w+") as f:
f.write("1")
with patch("gns3server.modules.IOU.get_images_directory", return_value=str(tmpdir)):
assert loop.run_until_complete(iou.list_images()) == [
{"filename": "a.bin"},
{"filename": "b.bin"}
]
def test_list_images_empty(loop, iou, tmpdir):
with patch("gns3server.modules.IOU.get_images_directory", return_value=str(tmpdir)):
assert loop.run_until_complete(iou.list_images()) == []
def test_list_images_directory_not_exist(loop, iou):
with patch("gns3server.modules.IOU.get_images_directory", return_value="/bla"):
assert loop.run_until_complete(iou.list_images()) == []