mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Revert "Merge branch 'unstable'"
This reverts commit929c337e8b, reversing changes made tob9bc73fd01.
This commit is contained in:
1 parent
d18293ae7c
commit
359abb0286
24 files changed
+217
-677
No files matched your search
@@ -40,7 +40,11 @@ def iou(port_manager):
|
||||
return iou
|
||||
|
||||
|
||||
def test_get_application_id(loop, project, 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
|
||||
vm1_id = str(uuid.uuid4())
|
||||
vm2_id = str(uuid.uuid4())
|
||||
vm3_id = str(uuid.uuid4())
|
||||
@@ -54,7 +58,11 @@ def test_get_application_id(loop, project, iou):
|
||||
assert iou.get_application_id(vm3_id) == 1
|
||||
|
||||
|
||||
def test_get_application_id_multiple_project(loop, iou):
|
||||
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
|
||||
vm1_id = str(uuid.uuid4())
|
||||
vm2_id = str(uuid.uuid4())
|
||||
vm3_id = str(uuid.uuid4())
|
||||
@@ -68,7 +76,11 @@ def test_get_application_id_multiple_project(loop, iou):
|
||||
assert iou.get_application_id(vm3_id) == 3
|
||||
|
||||
|
||||
def test_get_application_id_no_id_available(loop, project, iou):
|
||||
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
|
||||
with pytest.raises(IOUError):
|
||||
for i in range(1, 513):
|
||||
vm_id = str(uuid.uuid4())
|
||||
|
||||
@@ -22,33 +22,33 @@ from unittest.mock import patch
|
||||
|
||||
|
||||
from gns3server.modules.vpcs import VPCS
|
||||
from gns3server.modules.iou import IOU
|
||||
from gns3server.modules.qemu import Qemu
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def vpcs(port_manager):
|
||||
def qemu(port_manager):
|
||||
Qemu._instance = None
|
||||
qemu = Qemu.instance()
|
||||
qemu.port_manager = port_manager
|
||||
return qemu
|
||||
|
||||
|
||||
def test_create_vm_new_topology(loop, project, 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
|
||||
iou = IOU.instance()
|
||||
iou.port_manager = port_manager
|
||||
return iou
|
||||
|
||||
|
||||
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, vpcs):
|
||||
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
|
||||
@@ -57,13 +57,17 @@ def test_create_twice_same_vm_new_topology(loop, project, vpcs):
|
||||
assert len(project.vms) == 1
|
||||
|
||||
|
||||
def test_create_vm_new_topology_without_uuid(loop, project, vpcs):
|
||||
def test_create_vm_new_topology_without_uuid(loop, project, port_manager):
|
||||
|
||||
VPCS._instance = None
|
||||
vpcs = VPCS.instance()
|
||||
vpcs.port_manager = port_manager
|
||||
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, vpcs):
|
||||
def test_create_vm_old_topology(loop, project, tmpdir, port_manager):
|
||||
|
||||
with patch("gns3server.modules.project.Project.is_local", return_value=True):
|
||||
# Create an old topology directory
|
||||
@@ -75,6 +79,9 @@ def test_create_vm_old_topology(loop, project, tmpdir, vpcs):
|
||||
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
|
||||
@@ -86,55 +93,31 @@ def test_create_vm_old_topology(loop, project, tmpdir, vpcs):
|
||||
assert f.read() == "1"
|
||||
|
||||
|
||||
def test_get_abs_image_path(iou, tmpdir):
|
||||
os.makedirs(str(tmpdir / "IOU"))
|
||||
def test_get_abs_image_path(qemu, tmpdir):
|
||||
os.makedirs(str(tmpdir / "QEMU"))
|
||||
path1 = str(tmpdir / "test1.bin")
|
||||
open(path1, 'w+').close()
|
||||
|
||||
path2 = str(tmpdir / "IOU" / "test2.bin")
|
||||
path2 = str(tmpdir / "QEMU" / "test2.bin")
|
||||
open(path2, 'w+').close()
|
||||
|
||||
with patch("gns3server.config.Config.get_section_config", return_value={"images_path": str(tmpdir)}):
|
||||
assert iou.get_abs_image_path(path1) == path1
|
||||
assert iou.get_abs_image_path(path2) == path2
|
||||
assert iou.get_abs_image_path("test2.bin") == path2
|
||||
assert iou.get_abs_image_path("../test1.bin") == path1
|
||||
assert qemu.get_abs_image_path(path1) == path1
|
||||
assert qemu.get_abs_image_path(path2) == path2
|
||||
assert qemu.get_abs_image_path("test2.bin") == path2
|
||||
assert qemu.get_abs_image_path("../test1.bin") == path1
|
||||
|
||||
|
||||
def test_get_relative_image_path(iou, tmpdir):
|
||||
os.makedirs(str(tmpdir / "IOU"))
|
||||
def test_get_relative_image_path(qemu, tmpdir):
|
||||
os.makedirs(str(tmpdir / "QEMU"))
|
||||
path1 = str(tmpdir / "test1.bin")
|
||||
open(path1, 'w+').close()
|
||||
|
||||
path2 = str(tmpdir / "IOU" / "test2.bin")
|
||||
path2 = str(tmpdir / "QEMU" / "test2.bin")
|
||||
open(path2, 'w+').close()
|
||||
|
||||
with patch("gns3server.config.Config.get_section_config", return_value={"images_path": str(tmpdir)}):
|
||||
assert iou.get_relative_image_path(path1) == path1
|
||||
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()) == []
|
||||
assert qemu.get_relative_image_path(path1) == path1
|
||||
assert qemu.get_relative_image_path(path2) == "test2.bin"
|
||||
assert qemu.get_relative_image_path("test2.bin") == "test2.bin"
|
||||
assert qemu.get_relative_image_path("../test1.bin") == path1
|
||||
Reference in new issue
Block a user