mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-19 04:35:14 +02:00
refactor: ruff autofixes
This commit is contained in:
455 files changed
+12322
-14762
No files matched your search
+203
-178
@@ -40,11 +40,15 @@ def compute():
|
||||
@pytest.fixture
|
||||
def node(compute, project):
|
||||
|
||||
node = Node(project, compute, "demo",
|
||||
node_id=str(uuid.uuid4()),
|
||||
node_type="vpcs",
|
||||
console_type="vnc",
|
||||
properties={"startup_script": "echo test"})
|
||||
node = Node(
|
||||
project,
|
||||
compute,
|
||||
"demo",
|
||||
node_id=str(uuid.uuid4()),
|
||||
node_type="vpcs",
|
||||
console_type="vnc",
|
||||
properties={"startup_script": "echo test"},
|
||||
)
|
||||
return node
|
||||
|
||||
|
||||
@@ -55,22 +59,29 @@ def test_docker_iol_ports_grouped_in_four_port_units(compute, project):
|
||||
the native IOU node type. Plain docker nodes keep the flat eth naming.
|
||||
"""
|
||||
|
||||
node = Node(project, compute, "iol",
|
||||
node_id=str(uuid.uuid4()),
|
||||
node_type="docker",
|
||||
properties={"adapters": 2, "environment": "GNS3_IOL_RUNNER=1"})
|
||||
node = Node(
|
||||
project,
|
||||
compute,
|
||||
"iol",
|
||||
node_id=str(uuid.uuid4()),
|
||||
node_type="docker",
|
||||
properties={"adapters": 2, "environment": "GNS3_IOL_RUNNER=1"},
|
||||
)
|
||||
ports = node.ports
|
||||
assert [p.asdict()["name"] for p in ports] == [
|
||||
"Ethernet0/0", "Ethernet0/1", "Ethernet0/2", "Ethernet0/3",
|
||||
"Ethernet1/0", "Ethernet1/1", "Ethernet1/2", "Ethernet1/3",
|
||||
"Ethernet0/0",
|
||||
"Ethernet0/1",
|
||||
"Ethernet0/2",
|
||||
"Ethernet0/3",
|
||||
"Ethernet1/0",
|
||||
"Ethernet1/1",
|
||||
"Ethernet1/2",
|
||||
"Ethernet1/3",
|
||||
]
|
||||
assert (ports[5].adapter_number, ports[5].port_number) == (1, 1)
|
||||
assert ports[5].short_name == "e1/1"
|
||||
|
||||
node = Node(project, compute, "web",
|
||||
node_id=str(uuid.uuid4()),
|
||||
node_type="docker",
|
||||
properties={"adapters": 2})
|
||||
node = Node(project, compute, "web", node_id=str(uuid.uuid4()), node_type="docker", properties={"adapters": 2})
|
||||
assert [p.asdict()["name"] for p in node.ports] == ["eth0", "eth1"]
|
||||
|
||||
|
||||
@@ -82,10 +93,14 @@ def test_docker_iol_startup_config_materialized_once(compute, project, monkeypat
|
||||
afterwards the node's configuration lives in its NVRAM on the compute.
|
||||
"""
|
||||
|
||||
node = Node(project, compute, "iol",
|
||||
node_id=str(uuid.uuid4()),
|
||||
node_type="docker",
|
||||
properties={"environment": "GNS3_IOL_RUNNER=1\nGNS3_IOL_STARTUP_CONFIG=my-iol-config.txt"})
|
||||
node = Node(
|
||||
project,
|
||||
compute,
|
||||
"iol",
|
||||
node_id=str(uuid.uuid4()),
|
||||
node_type="docker",
|
||||
properties={"environment": "GNS3_IOL_RUNNER=1\nGNS3_IOL_STARTUP_CONFIG=my-iol-config.txt"},
|
||||
)
|
||||
monkeypatch.setattr(node, "_base_config_file_content", lambda path: "hostname %h\n")
|
||||
|
||||
data = node._node_data()
|
||||
@@ -100,10 +115,14 @@ def test_docker_iol_startup_config_materialized_once(compute, project, monkeypat
|
||||
|
||||
def test_docker_iol_startup_config_missing_file_keeps_knob(compute, project, monkeypatch):
|
||||
|
||||
node = Node(project, compute, "iol",
|
||||
node_id=str(uuid.uuid4()),
|
||||
node_type="docker",
|
||||
properties={"environment": "GNS3_IOL_RUNNER=1\nGNS3_IOL_STARTUP_CONFIG=gone.txt"})
|
||||
node = Node(
|
||||
project,
|
||||
compute,
|
||||
"iol",
|
||||
node_id=str(uuid.uuid4()),
|
||||
node_type="docker",
|
||||
properties={"environment": "GNS3_IOL_RUNNER=1\nGNS3_IOL_STARTUP_CONFIG=gone.txt"},
|
||||
)
|
||||
monkeypatch.setattr(node, "_base_config_file_content", lambda path: None)
|
||||
|
||||
data = node._node_data()
|
||||
@@ -132,23 +151,35 @@ def test_name(compute, project):
|
||||
If node use a name template generate names
|
||||
"""
|
||||
|
||||
node = Node(project, compute, "PC",
|
||||
node_id=str(uuid.uuid4()),
|
||||
node_type="vpcs",
|
||||
console_type="vnc",
|
||||
properties={"startup_script": "echo test"})
|
||||
node = Node(
|
||||
project,
|
||||
compute,
|
||||
"PC",
|
||||
node_id=str(uuid.uuid4()),
|
||||
node_type="vpcs",
|
||||
console_type="vnc",
|
||||
properties={"startup_script": "echo test"},
|
||||
)
|
||||
assert node.name == "PC"
|
||||
node = Node(project, compute, "PC{0}",
|
||||
node_id=str(uuid.uuid4()),
|
||||
node_type="vpcs",
|
||||
console_type="vnc",
|
||||
properties={"startup_script": "echo test"})
|
||||
node = Node(
|
||||
project,
|
||||
compute,
|
||||
"PC{0}",
|
||||
node_id=str(uuid.uuid4()),
|
||||
node_type="vpcs",
|
||||
console_type="vnc",
|
||||
properties={"startup_script": "echo test"},
|
||||
)
|
||||
assert node.name == "PC1"
|
||||
node = Node(project, compute, "PC{0}",
|
||||
node_id=str(uuid.uuid4()),
|
||||
node_type="vpcs",
|
||||
console_type="vnc",
|
||||
properties={"startup_script": "echo test"})
|
||||
node = Node(
|
||||
project,
|
||||
compute,
|
||||
"PC{0}",
|
||||
node_id=str(uuid.uuid4()),
|
||||
node_type="vpcs",
|
||||
console_type="vnc",
|
||||
properties={"startup_script": "echo test"},
|
||||
)
|
||||
assert node.name == "PC2"
|
||||
|
||||
|
||||
@@ -158,10 +189,7 @@ def test_vmname(compute, project):
|
||||
field
|
||||
"""
|
||||
|
||||
node = Node(project, compute, "PC",
|
||||
node_id=str(uuid.uuid4()),
|
||||
node_type="virtualbox",
|
||||
vmname="test")
|
||||
node = Node(project, compute, "PC", node_id=str(uuid.uuid4()), node_type="virtualbox", vmname="test")
|
||||
assert node.properties["vmname"] == "test"
|
||||
|
||||
|
||||
@@ -169,13 +197,9 @@ def test_empty_properties(compute, project):
|
||||
"""
|
||||
Empty properties need to be ignored
|
||||
"""
|
||||
node = Node(project, compute, "PC",
|
||||
node_id=str(uuid.uuid4()),
|
||||
node_type="virtualbox",
|
||||
aa="",
|
||||
bb=None,
|
||||
category=2,
|
||||
cc="xx")
|
||||
node = Node(
|
||||
project, compute, "PC", node_id=str(uuid.uuid4()), node_type="virtualbox", aa="", bb=None, category=2, cc="xx"
|
||||
)
|
||||
assert "aa" not in node.properties
|
||||
assert "bb" not in node.properties
|
||||
assert "cc" in node.properties
|
||||
@@ -188,7 +212,9 @@ async def test_eq(compute, project, node, controller):
|
||||
assert node == Node(project, compute, "demo1", node_id=node.id, node_type="qemu")
|
||||
assert node != "a"
|
||||
assert node != Node(project, compute, "demo2", node_id=str(uuid.uuid4()), node_type="qemu")
|
||||
assert node != Node(Project(str(uuid.uuid4()), controller=controller), compute, "demo3", node_id=node.id, node_type="qemu")
|
||||
assert node != Node(
|
||||
Project(str(uuid.uuid4()), controller=controller), compute, "demo3", node_id=node.id, node_type="qemu"
|
||||
)
|
||||
|
||||
|
||||
def test_json(node, compute):
|
||||
@@ -233,11 +259,11 @@ def test_json(node, compute):
|
||||
"link_type": "ethernet",
|
||||
"name": "Ethernet0",
|
||||
"port_number": 0,
|
||||
"short_name": "e0"
|
||||
"short_name": "e0",
|
||||
}
|
||||
],
|
||||
"missing_image": False,
|
||||
"missing_images": []
|
||||
"missing_images": [],
|
||||
}
|
||||
|
||||
assert node.asdict(topology_dump=True) == {
|
||||
@@ -272,9 +298,7 @@ def test_json(node, compute):
|
||||
|
||||
|
||||
def test_init_without_uuid(project, compute):
|
||||
node = Node(project, compute, "demo",
|
||||
node_type="vpcs",
|
||||
console_type="vnc")
|
||||
node = Node(project, compute, "demo", node_type="vpcs", console_type="vnc")
|
||||
assert node.id is not None
|
||||
|
||||
|
||||
@@ -287,13 +311,7 @@ async def test_create(node, compute):
|
||||
compute.post = AsyncioMagicMock(return_value=response)
|
||||
|
||||
assert await node.create() is True
|
||||
data = {
|
||||
"console": 2048,
|
||||
"console_type": "vnc",
|
||||
"node_id": node.id,
|
||||
"startup_script": "echo test",
|
||||
"name": "demo"
|
||||
}
|
||||
data = {"console": 2048, "console_type": "vnc", "node_id": node.id, "startup_script": "echo test", "name": "demo"}
|
||||
compute.post.assert_called_with("/projects/{}/vpcs/nodes".format(node.project.id), data=data, timeout=1200)
|
||||
assert node._console == 2048
|
||||
assert node._properties == {"startup_script": "echo test"}
|
||||
@@ -319,7 +337,7 @@ async def test_create_image_missing(node, compute):
|
||||
node._upload_missing_image = AsyncioMagicMock(return_value=True)
|
||||
|
||||
assert await node.create() is True
|
||||
#assert node._upload_missing_image.called is True
|
||||
# assert node._upload_missing_image.called is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -330,15 +348,19 @@ async def test_create_image_missing_kept_in_degraded_state(project, compute, tmp
|
||||
"""
|
||||
|
||||
config.settings.Server.images_path = str(tmpdir)
|
||||
node = Node(project, compute, "r1",
|
||||
node_id=str(uuid.uuid4()),
|
||||
node_type="qemu",
|
||||
properties={"hda_disk_image": "missing.qcow2", "ram": 256})
|
||||
node = Node(
|
||||
project,
|
||||
compute,
|
||||
"r1",
|
||||
node_id=str(uuid.uuid4()),
|
||||
node_type="qemu",
|
||||
properties={"hda_disk_image": "missing.qcow2", "ram": 256},
|
||||
)
|
||||
|
||||
async def resp(*args, **kwargs):
|
||||
raise ComputeConflictError(
|
||||
"/projects/{}/qemu/nodes".format(project.id),
|
||||
{"message": "The image is missing", "image": "missing.qcow2", "exception": "ImageMissingError"}
|
||||
{"message": "The image is missing", "image": "missing.qcow2", "exception": "ImageMissingError"},
|
||||
)
|
||||
|
||||
compute.post = AsyncioMagicMock(side_effect=resp)
|
||||
@@ -346,9 +368,7 @@ async def test_create_image_missing_kept_in_degraded_state(project, compute, tmp
|
||||
|
||||
assert await node.create(allow_missing_image=True) is False
|
||||
assert node.missing_image is True
|
||||
assert node.missing_images == [
|
||||
{"property": "hda_disk_image", "image": "missing.qcow2", "image_type": "qemu"}
|
||||
]
|
||||
assert node.missing_images == [{"property": "hda_disk_image", "image": "missing.qcow2", "image_type": "qemu"}]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -359,15 +379,19 @@ async def test_create_image_missing_raises_by_default(project, compute, tmpdir,
|
||||
"""
|
||||
|
||||
config.settings.Server.images_path = str(tmpdir)
|
||||
node = Node(project, compute, "r1",
|
||||
node_id=str(uuid.uuid4()),
|
||||
node_type="qemu",
|
||||
properties={"hda_disk_image": "missing.qcow2", "ram": 256})
|
||||
node = Node(
|
||||
project,
|
||||
compute,
|
||||
"r1",
|
||||
node_id=str(uuid.uuid4()),
|
||||
node_type="qemu",
|
||||
properties={"hda_disk_image": "missing.qcow2", "ram": 256},
|
||||
)
|
||||
|
||||
async def resp(*args, **kwargs):
|
||||
raise ComputeConflictError(
|
||||
"/projects/{}/qemu/nodes".format(project.id),
|
||||
{"message": "The image is missing", "image": "missing.qcow2", "exception": "ImageMissingError"}
|
||||
{"message": "The image is missing", "image": "missing.qcow2", "exception": "ImageMissingError"},
|
||||
)
|
||||
|
||||
compute.post = AsyncioMagicMock(side_effect=resp)
|
||||
@@ -478,15 +502,19 @@ async def test_create_docker_image_missing_after_failed_pull(project, compute):
|
||||
degraded state instead of aborting the project open.
|
||||
"""
|
||||
|
||||
node = Node(project, compute, "web",
|
||||
node_id=str(uuid.uuid4()),
|
||||
node_type="docker",
|
||||
properties={"image": "ghost:latest", "adapters": 1})
|
||||
node = Node(
|
||||
project,
|
||||
compute,
|
||||
"web",
|
||||
node_id=str(uuid.uuid4()),
|
||||
node_type="docker",
|
||||
properties={"image": "ghost:latest", "adapters": 1},
|
||||
)
|
||||
|
||||
async def resp(*args, **kwargs):
|
||||
raise ComputeConflictError(
|
||||
"/projects/{}/docker/nodes".format(project.id),
|
||||
{"message": "The image is missing", "image": "ghost:latest", "exception": "ImageMissingError"}
|
||||
{"message": "The image is missing", "image": "ghost:latest", "exception": "ImageMissingError"},
|
||||
)
|
||||
|
||||
compute.post = AsyncioMagicMock(side_effect=resp)
|
||||
@@ -496,9 +524,7 @@ async def test_create_docker_image_missing_after_failed_pull(project, compute):
|
||||
|
||||
assert await node.create(allow_missing_image=True) is False
|
||||
assert node.missing_image is True
|
||||
assert node.missing_images == [
|
||||
{"property": "image", "image": "ghost:latest", "image_type": "docker"}
|
||||
]
|
||||
assert node.missing_images == [{"property": "image", "image": "ghost:latest", "image_type": "docker"}]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -507,15 +533,19 @@ async def test_create_docker_image_missing_pull_error_raises_by_default(project,
|
||||
Without allow_missing_image a failed Docker pull is still surfaced.
|
||||
"""
|
||||
|
||||
node = Node(project, compute, "web",
|
||||
node_id=str(uuid.uuid4()),
|
||||
node_type="docker",
|
||||
properties={"image": "ghost:latest", "adapters": 1})
|
||||
node = Node(
|
||||
project,
|
||||
compute,
|
||||
"web",
|
||||
node_id=str(uuid.uuid4()),
|
||||
node_type="docker",
|
||||
properties={"image": "ghost:latest", "adapters": 1},
|
||||
)
|
||||
|
||||
async def resp(*args, **kwargs):
|
||||
raise ComputeConflictError(
|
||||
"/projects/{}/docker/nodes".format(project.id),
|
||||
{"message": "The image is missing", "image": "ghost:latest", "exception": "ImageMissingError"}
|
||||
{"message": "The image is missing", "image": "ghost:latest", "exception": "ImageMissingError"},
|
||||
)
|
||||
|
||||
compute.post = AsyncioMagicMock(side_effect=resp)
|
||||
@@ -534,15 +564,19 @@ def test_compute_missing_images_lists_all_unavailable_slots(project, compute, tm
|
||||
"""
|
||||
|
||||
config.settings.Server.images_path = str(tmpdir)
|
||||
node = Node(project, compute, "r1",
|
||||
node_id=str(uuid.uuid4()),
|
||||
node_type="qemu",
|
||||
properties={
|
||||
"hda_disk_image": "present.qcow2",
|
||||
"hdc_disk_image": "missing.qcow2",
|
||||
"initrd": "missing.initrd",
|
||||
"ram": 256,
|
||||
})
|
||||
node = Node(
|
||||
project,
|
||||
compute,
|
||||
"r1",
|
||||
node_id=str(uuid.uuid4()),
|
||||
node_type="qemu",
|
||||
properties={
|
||||
"hda_disk_image": "present.qcow2",
|
||||
"hdc_disk_image": "missing.qcow2",
|
||||
"initrd": "missing.initrd",
|
||||
"ram": 256,
|
||||
},
|
||||
)
|
||||
# make one image available on the controller
|
||||
os.makedirs(os.path.join(str(tmpdir), "QEMU"), exist_ok=True)
|
||||
with open(os.path.join(str(tmpdir), "QEMU", "present.qcow2"), "w") as f:
|
||||
@@ -556,9 +590,7 @@ def test_compute_missing_images_lists_all_unavailable_slots(project, compute, tm
|
||||
@pytest.mark.asyncio
|
||||
async def test_start_missing_image(node):
|
||||
|
||||
node._missing_images = [
|
||||
{"property": "hda_disk_image", "image": "missing.qcow2", "image_type": "qemu"}
|
||||
]
|
||||
node._missing_images = [{"property": "hda_disk_image", "image": "missing.qcow2", "image_type": "qemu"}]
|
||||
with pytest.raises(ControllerError):
|
||||
await node.start()
|
||||
|
||||
@@ -570,9 +602,7 @@ async def test_update_recreates_missing_image_node(project, compute, node):
|
||||
the missing image state.
|
||||
"""
|
||||
|
||||
node._missing_images = [
|
||||
{"property": "image", "image": "missing.image", "image_type": "ios"}
|
||||
]
|
||||
node._missing_images = [{"property": "image", "image": "missing.image", "image_type": "ios"}]
|
||||
response = MagicMock()
|
||||
response.json = {"console": 2048}
|
||||
compute.post = AsyncioMagicMock(return_value=response)
|
||||
@@ -600,9 +630,7 @@ async def test_update_replaces_qemu_linked_clone_backing_image(project, compute)
|
||||
"hda_disk_image_md5sum": "old-checksum",
|
||||
},
|
||||
)
|
||||
qemu_node._missing_images = [
|
||||
{"property": "hda_disk_image", "image": "missing.qcow2", "image_type": "qemu"}
|
||||
]
|
||||
qemu_node._missing_images = [{"property": "hda_disk_image", "image": "missing.qcow2", "image_type": "qemu"}]
|
||||
response = MagicMock()
|
||||
response.json = {"console": 2048}
|
||||
compute.post = AsyncioMagicMock(return_value=response)
|
||||
@@ -627,18 +655,14 @@ async def test_update_replaces_qemu_linked_clone_backing_image(project, compute)
|
||||
async def test_update_missing_image_node_rolls_back_after_create_error(project, compute, node):
|
||||
original_properties = {"image": "missing.image"}
|
||||
node._properties = original_properties.copy()
|
||||
node._missing_images = [
|
||||
{"property": "image", "image": "missing.image", "image_type": "ios"}
|
||||
]
|
||||
node._missing_images = [{"property": "image", "image": "missing.image", "image_type": "ios"}]
|
||||
compute.post = AsyncioMagicMock(side_effect=ControllerError("create failed"))
|
||||
|
||||
with pytest.raises(ControllerError):
|
||||
await node.update(properties={"image": "invalid.image"})
|
||||
|
||||
assert node.properties == original_properties
|
||||
assert node.missing_images == [
|
||||
{"property": "image", "image": "missing.image", "image_type": "ios"}
|
||||
]
|
||||
assert node.missing_images == [{"property": "image", "image": "missing.image", "image_type": "ios"}]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -659,9 +683,7 @@ async def test_start_retries_ready_deferred_links(node, project):
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_stop_missing_image_node_does_not_contact_compute(node, compute):
|
||||
node._missing_images = [
|
||||
{"property": "image", "image": "missing.image", "image_type": "ios"}
|
||||
]
|
||||
node._missing_images = [{"property": "image", "image": "missing.image", "image_type": "ios"}]
|
||||
compute.post = AsyncioMagicMock()
|
||||
|
||||
await node.stop()
|
||||
@@ -673,8 +695,8 @@ async def test_stop_missing_image_node_does_not_contact_compute(node, compute):
|
||||
async def test_create_base_script(node, config, compute, tmpdir):
|
||||
|
||||
config.settings.Server.configs_path = str(tmpdir)
|
||||
with open(str(tmpdir / 'test.txt'), 'w+') as f:
|
||||
f.write('hostname test')
|
||||
with open(str(tmpdir / "test.txt"), "w+") as f:
|
||||
f.write("hostname test")
|
||||
|
||||
node._properties = {"base_script_file": "test.txt"}
|
||||
node._console = 2048
|
||||
@@ -689,7 +711,7 @@ async def test_create_base_script(node, config, compute, tmpdir):
|
||||
"console_type": "vnc",
|
||||
"node_id": node.id,
|
||||
"startup_script": "hostname test",
|
||||
"name": "demo"
|
||||
"name": "demo",
|
||||
}
|
||||
|
||||
compute.post.assert_called_with("/projects/{}/vpcs/nodes".format(node.project.id), data=data, timeout=1200)
|
||||
@@ -713,7 +735,9 @@ def test_symbol(node, symbols_dir):
|
||||
assert node.height == 71
|
||||
assert node.label["x"] is None
|
||||
assert node.label["y"] == -40
|
||||
assert node.label["style"] == None#"font-family: TypeWriter;font-size: 10.0;font-weight: bold;fill: #000000;fill-opacity: 1.0;"
|
||||
assert (
|
||||
node.label["style"] == None
|
||||
) # "font-family: TypeWriter;font-size: 10.0;font-weight: bold;fill: #000000;fill-opacity: 1.0;"
|
||||
|
||||
shutil.copy(os.path.join("gns3server", "symbols", "classic", "cloud.svg"), os.path.join(symbols_dir, "cloud2.svg"))
|
||||
node.symbol = "cloud2.svg"
|
||||
@@ -734,15 +758,14 @@ def test_label_with_default_label_font(node):
|
||||
the correct color
|
||||
"""
|
||||
node.project.controller.settings = {
|
||||
"GraphicsView": {
|
||||
"default_label_color": "#ff0000",
|
||||
"default_label_font": "TypeWriter,10,-1,5,75,0,0,0,0,0"
|
||||
}
|
||||
"GraphicsView": {"default_label_color": "#ff0000", "default_label_font": "TypeWriter,10,-1,5,75,0,0,0,0,0"}
|
||||
}
|
||||
|
||||
node._label = None
|
||||
node.symbol = ":/symbols/dslam.svg"
|
||||
assert node.label["style"] == None #"font-family: TypeWriter;font-size: 10;font-weight: bold;fill: #ff0000;fill-opacity: 1.0;"
|
||||
assert (
|
||||
node.label["style"] == None
|
||||
) # "font-family: TypeWriter;font-size: 10;font-weight: bold;fill: #ff0000;fill-opacity: 1.0;"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -755,17 +778,12 @@ async def test_update(node, compute, project, controller):
|
||||
project.dump = MagicMock()
|
||||
|
||||
await node.update(x=42, console=2048, console_type="vnc", properties={"startup_script": "echo test"}, name="demo")
|
||||
data = {
|
||||
"console": 2048,
|
||||
"console_type": "vnc",
|
||||
"startup_script": "echo test",
|
||||
"name": "demo"
|
||||
}
|
||||
data = {"console": 2048, "console_type": "vnc", "startup_script": "echo test", "name": "demo"}
|
||||
compute.put.assert_called_with("/projects/{}/vpcs/nodes/{}".format(node.project.id, node.id), data=data)
|
||||
assert node._console == 2048
|
||||
assert node.x == 42
|
||||
assert node._properties == {"startup_script": "echo test"}
|
||||
#controller._notification.emit.assert_called_with("node.updated", node.asdict())
|
||||
# controller._notification.emit.assert_called_with("node.updated", node.asdict())
|
||||
assert project.dump.called
|
||||
|
||||
|
||||
@@ -780,12 +798,7 @@ async def test_update_properties(node, compute, controller):
|
||||
controller._notification = AsyncioMagicMock()
|
||||
|
||||
await node.update(x=42, console=2048, console_type="vnc", properties={"startup_script": "hello world"}, name="demo")
|
||||
data = {
|
||||
"console": 2048,
|
||||
"console_type": "vnc",
|
||||
"startup_script": "hello world",
|
||||
"name": "demo"
|
||||
}
|
||||
data = {"console": 2048, "console_type": "vnc", "startup_script": "hello world", "name": "demo"}
|
||||
compute.put.assert_called_with("/projects/{}/vpcs/nodes/{}".format(node.project.id, node.id), data=data)
|
||||
assert node._console == 2048
|
||||
assert node.x == 42
|
||||
@@ -793,9 +806,9 @@ async def test_update_properties(node, compute, controller):
|
||||
|
||||
# The notif should contain the old properties because it's the compute that will emit
|
||||
# the correct info
|
||||
#node_notif = copy.deepcopy(node.asdict())
|
||||
#node_notif["properties"]["startup_script"] = "echo test"
|
||||
#controller._notification.emit.assert_called_with("node.updated", node_notif)
|
||||
# node_notif = copy.deepcopy(node.asdict())
|
||||
# node_notif["properties"]["startup_script"] = "echo test"
|
||||
# controller._notification.emit.assert_called_with("node.updated", node_notif)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -888,8 +901,7 @@ def test_default_credentials_from_template_kwargs(compute, project):
|
||||
default credentials without sending them to the compute.
|
||||
"""
|
||||
|
||||
node = Node(project, compute, "test", node_type="vpcs",
|
||||
default_username="root", default_password="cisco123")
|
||||
node = Node(project, compute, "test", node_type="vpcs", default_username="root", default_password="cisco123")
|
||||
assert node.default_username == "root"
|
||||
assert node.default_password == "cisco123"
|
||||
assert "default_username" not in node.properties
|
||||
@@ -927,18 +939,20 @@ async def test_start(node, compute):
|
||||
@pytest.mark.asyncio
|
||||
async def test_start_iou(compute, project, controller):
|
||||
|
||||
node = Node(project, compute, "demo",
|
||||
node_id=str(uuid.uuid4()),
|
||||
node_type="iou")
|
||||
node = Node(project, compute, "demo", node_id=str(uuid.uuid4()), node_type="iou")
|
||||
compute.post = AsyncioMagicMock()
|
||||
|
||||
# Without licence configured it should raise an error
|
||||
#with pytest.raises(aiohttp.web.HTTPConflict):
|
||||
# with pytest.raises(aiohttp.web.HTTPConflict):
|
||||
# async_run(node.start())
|
||||
|
||||
controller._iou_license_settings = {"license_check": True, "iourc_content": "aa"}
|
||||
await node.start()
|
||||
compute.post.assert_called_with("/projects/{}/iou/nodes/{}/start".format(node.project.id, node.id), timeout=240, data={"license_check": True, "iourc_content": "aa"})
|
||||
compute.post.assert_called_with(
|
||||
"/projects/{}/iou/nodes/{}/start".format(node.project.id, node.id),
|
||||
timeout=240,
|
||||
data={"license_check": True, "iourc_content": "aa"},
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -947,7 +961,9 @@ async def test_stop(node, compute):
|
||||
compute.post = AsyncioMagicMock()
|
||||
|
||||
await node.stop()
|
||||
compute.post.assert_called_with("/projects/{}/vpcs/nodes/{}/stop".format(node.project.id, node.id), timeout=240, dont_connect=True)
|
||||
compute.post.assert_called_with(
|
||||
"/projects/{}/vpcs/nodes/{}/stop".format(node.project.id, node.id), timeout=240, dont_connect=True
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -977,12 +993,7 @@ async def test_create_without_console(node, compute):
|
||||
compute.post = AsyncioMagicMock(return_value=response)
|
||||
|
||||
await node.create()
|
||||
data = {
|
||||
"console_type": "vnc",
|
||||
"node_id": node.id,
|
||||
"startup_script": "echo test",
|
||||
"name": "demo"
|
||||
}
|
||||
data = {"console_type": "vnc", "node_id": node.id, "startup_script": "echo test", "name": "demo"}
|
||||
compute.post.assert_called_with("/projects/{}/vpcs/nodes".format(node.project.id), data=data, timeout=1200)
|
||||
assert node._console == 2048
|
||||
assert node._properties == {"test_value": "success", "startup_script": "echo test"}
|
||||
@@ -1017,7 +1028,9 @@ async def test_dynamips_idle_pc(node, compute):
|
||||
response.json = {"idlepc": "0x60606f54"}
|
||||
compute.get = AsyncioMagicMock(return_value=response)
|
||||
await node.dynamips_auto_idlepc()
|
||||
compute.get.assert_called_with("/projects/{}/dynamips/nodes/{}/auto_idlepc".format(node.project.id, node.id), timeout=240)
|
||||
compute.get.assert_called_with(
|
||||
"/projects/{}/dynamips/nodes/{}/auto_idlepc".format(node.project.id, node.id), timeout=240
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -1028,18 +1041,24 @@ async def test_dynamips_idlepc_proposals(node, compute):
|
||||
response.json = ["0x60606f54", "0x30ff6f37"]
|
||||
compute.get = AsyncioMagicMock(return_value=response)
|
||||
await node.dynamips_idlepc_proposals()
|
||||
compute.get.assert_called_with("/projects/{}/dynamips/nodes/{}/idlepc_proposals".format(node.project.id, node.id), timeout=240)
|
||||
compute.get.assert_called_with(
|
||||
"/projects/{}/dynamips/nodes/{}/idlepc_proposals".format(node.project.id, node.id), timeout=240
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_upload_missing_image(compute, controller, images_dir):
|
||||
|
||||
project = Project(str(uuid.uuid4()), controller=controller)
|
||||
node = Node(project, compute, "demo",
|
||||
node_id=str(uuid.uuid4()),
|
||||
node_type="qemu",
|
||||
properties={"hda_disk_image": "linux.img"})
|
||||
open(os.path.join(images_dir, "linux.img"), 'w+').close()
|
||||
node = Node(
|
||||
project,
|
||||
compute,
|
||||
"demo",
|
||||
node_id=str(uuid.uuid4()),
|
||||
node_type="qemu",
|
||||
properties={"hda_disk_image": "linux.img"},
|
||||
)
|
||||
open(os.path.join(images_dir, "linux.img"), "w+").close()
|
||||
assert await node._upload_missing_image("qemu", "linux.img") is True
|
||||
compute.post.assert_called_with("/qemu/images/linux.img", data=ANY, timeout=None)
|
||||
|
||||
@@ -1048,10 +1067,14 @@ async def test_upload_missing_image(compute, controller, images_dir):
|
||||
async def test_upload_missing_image_from_nested_directory(compute, controller, images_dir):
|
||||
|
||||
project = Project(str(uuid.uuid4()), controller=controller)
|
||||
node = Node(project, compute, "demo",
|
||||
node_id=str(uuid.uuid4()),
|
||||
node_type="qemu",
|
||||
properties={"hda_disk_image": "nested.img"})
|
||||
node = Node(
|
||||
project,
|
||||
compute,
|
||||
"demo",
|
||||
node_id=str(uuid.uuid4()),
|
||||
node_type="qemu",
|
||||
properties={"hda_disk_image": "nested.img"},
|
||||
)
|
||||
nested_dir = os.path.join(images_dir, "vendor")
|
||||
os.makedirs(nested_dir)
|
||||
open(os.path.join(nested_dir, "nested.img"), "w+").close()
|
||||
@@ -1064,10 +1087,9 @@ async def test_upload_missing_image_from_nested_directory(compute, controller, i
|
||||
async def test_sync_missing_docker_image_from_controller_daemon(compute, controller):
|
||||
|
||||
project = Project(str(uuid.uuid4()), controller=controller)
|
||||
node = Node(project, compute, "demo",
|
||||
node_id=str(uuid.uuid4()),
|
||||
node_type="docker",
|
||||
properties={"image": "gns3/frr:latest"})
|
||||
node = Node(
|
||||
project, compute, "demo", node_id=str(uuid.uuid4()), node_type="docker", properties={"image": "gns3/frr:latest"}
|
||||
)
|
||||
|
||||
response = MagicMock()
|
||||
response.content = MagicMock()
|
||||
@@ -1082,10 +1104,9 @@ async def test_sync_missing_docker_image_from_controller_daemon(compute, control
|
||||
async def test_sync_missing_docker_image_pull_fallback(compute, controller):
|
||||
|
||||
project = Project(str(uuid.uuid4()), controller=controller)
|
||||
node = Node(project, compute, "demo",
|
||||
node_id=str(uuid.uuid4()),
|
||||
node_type="docker",
|
||||
properties={"image": "nginx:latest"})
|
||||
node = Node(
|
||||
project, compute, "demo", node_id=str(uuid.uuid4()), node_type="docker", properties={"image": "nginx:latest"}
|
||||
)
|
||||
|
||||
with asyncio_patch("gns3server.compute.docker.Docker.http_query", side_effect=DockerError("404")):
|
||||
assert await node._upload_missing_image("docker", "nginx:latest") is True
|
||||
@@ -1096,10 +1117,14 @@ async def test_sync_missing_docker_image_pull_fallback(compute, controller):
|
||||
async def test_create_docker_node_pins_image_digest(compute, controller):
|
||||
|
||||
project = Project(str(uuid.uuid4()), controller=controller)
|
||||
node = Node(project, compute, "demo",
|
||||
node_id=str(uuid.uuid4()),
|
||||
node_type="docker",
|
||||
properties={"image": "gns3/frr:latest", "adapters": 1})
|
||||
node = Node(
|
||||
project,
|
||||
compute,
|
||||
"demo",
|
||||
node_id=str(uuid.uuid4()),
|
||||
node_type="docker",
|
||||
properties={"image": "gns3/frr:latest", "adapters": 1},
|
||||
)
|
||||
|
||||
response = MagicMock()
|
||||
response.status = 200
|
||||
|
||||
Reference in new issue
Block a user