mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-20 05:05:14 +02:00
Merge branch '3.1' into 3.1
This commit is contained in:
51 files changed
+3155
-183
No files matched your search
@@ -45,6 +45,7 @@ class TestCapabilitiesRoutes:
|
||||
monkeypatch.setattr("gns3server.api.routes.compute.capabilities.probe_iol_tap_support", _no_tap_probe)
|
||||
monkeypatch.setattr("gns3server.api.routes.compute.capabilities.probe_bridge_tap_support", _no_tap_probe)
|
||||
monkeypatch.setattr("gns3server.api.routes.compute.capabilities.probe_vpcs_tap", _no_tap_probe)
|
||||
monkeypatch.setattr("gns3server.api.routes.compute.capabilities.probe_vxlan_support", _no_tap_probe)
|
||||
response = await compute_client.get(app.url_path_for("compute:get_capabilities"))
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert response.json() == {
|
||||
@@ -73,6 +74,7 @@ class TestCapabilitiesRoutes:
|
||||
"ubridge_iol_tap": None,
|
||||
"ubridge_bridge_tap": None,
|
||||
"vpcs_tap": None,
|
||||
"ubridge_vxlan": None,
|
||||
}
|
||||
|
||||
async def test_get_on_gns3vm(self, app: FastAPI, compute_client: AsyncClient, on_gns3vm, monkeypatch) -> None:
|
||||
@@ -85,6 +87,7 @@ class TestCapabilitiesRoutes:
|
||||
monkeypatch.setattr("gns3server.api.routes.compute.capabilities.probe_iol_tap_support", _no_tap_probe)
|
||||
monkeypatch.setattr("gns3server.api.routes.compute.capabilities.probe_bridge_tap_support", _no_tap_probe)
|
||||
monkeypatch.setattr("gns3server.api.routes.compute.capabilities.probe_vpcs_tap", _no_tap_probe)
|
||||
monkeypatch.setattr("gns3server.api.routes.compute.capabilities.probe_vxlan_support", _no_tap_probe)
|
||||
response = await compute_client.get(app.url_path_for("compute:get_capabilities"))
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert response.json() == {
|
||||
@@ -113,6 +116,7 @@ class TestCapabilitiesRoutes:
|
||||
"ubridge_iol_tap": None,
|
||||
"ubridge_bridge_tap": None,
|
||||
"vpcs_tap": None,
|
||||
"ubridge_vxlan": None,
|
||||
}
|
||||
|
||||
async def test_get_reports_ubridge_tc(self, app: FastAPI, compute_client: AsyncClient, monkeypatch) -> None:
|
||||
@@ -199,6 +203,25 @@ class TestCapabilitiesRoutes:
|
||||
monkeypatch.setattr("gns3server.api.routes.compute.capabilities.probe_tap_support", _no_tap_probe)
|
||||
monkeypatch.setattr("gns3server.api.routes.compute.capabilities.probe_iol_tap_support", _no_tap_probe)
|
||||
monkeypatch.setattr("gns3server.api.routes.compute.capabilities.probe_bridge_tap_support", _no_tap_probe)
|
||||
monkeypatch.setattr("gns3server.api.routes.compute.capabilities.probe_vxlan_support", _no_tap_probe)
|
||||
response = await compute_client.get(app.url_path_for("compute:get_capabilities"))
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert response.json()["vpcs_tap"] is True
|
||||
|
||||
async def test_get_reports_ubridge_vxlan(self, app: FastAPI, compute_client: AsyncClient, monkeypatch) -> None:
|
||||
"""
|
||||
The vxlan capability is what makes a cross-compute link tunnel-
|
||||
eligible, so it travels with the other compute capabilities.
|
||||
"""
|
||||
|
||||
async def fake_vxlan_probe():
|
||||
return True
|
||||
|
||||
monkeypatch.setattr("gns3server.api.routes.compute.capabilities.probe_vxlan_support", fake_vxlan_probe)
|
||||
monkeypatch.setattr("gns3server.api.routes.compute.capabilities.probe_tap_support", _no_tap_probe)
|
||||
monkeypatch.setattr("gns3server.api.routes.compute.capabilities.probe_iol_tap_support", _no_tap_probe)
|
||||
monkeypatch.setattr("gns3server.api.routes.compute.capabilities.probe_bridge_tap_support", _no_tap_probe)
|
||||
monkeypatch.setattr("gns3server.api.routes.compute.capabilities.probe_vpcs_tap", _no_tap_probe)
|
||||
response = await compute_client.get(app.url_path_for("compute:get_capabilities"))
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert response.json()["ubridge_vxlan"] is True
|
||||
@@ -19,6 +19,7 @@ import pytest_asyncio
|
||||
from fastapi import FastAPI, status
|
||||
from httpx import AsyncClient
|
||||
|
||||
from gns3server.compute.builtin import Builtin
|
||||
from gns3server.compute.project import Project
|
||||
from tests.utils import asyncio_patch
|
||||
|
||||
@@ -212,3 +213,36 @@ class TestCloudNodesRoutes:
|
||||
# response = await compute_api.get("/projects/{project_id}/cloud/nodes/{node_id}/adapters/0/ports/0/pcap".format(project_id=compute_project.id, node_id=vm["node_id"]))
|
||||
# assert response.status_code == 200
|
||||
#
|
||||
|
||||
async def test_unbridged_connected_tap_update(self, app, compute_client, compute_project):
|
||||
ports = [{"interface": "tap0", "name": "tap0", "port_number": 0, "type": "tap"}]
|
||||
with asyncio_patch("gns3server.compute.builtin.nodes.cloud.Cloud._start_ubridge"):
|
||||
response = await compute_client.post(
|
||||
app.url_path_for("compute:create_cloud", project_id=compute_project.id),
|
||||
json={"name": "Cloud TAP", "ports_mapping": ports},
|
||||
)
|
||||
assert response.status_code == 201
|
||||
data = response.json()
|
||||
node = Builtin.instance().get_node(data["node_id"], project_id=compute_project.id)
|
||||
node.nios[0] = object()
|
||||
response = await compute_client.put(
|
||||
app.url_path_for("compute:update_cloud", project_id=compute_project.id, node_id=node.id),
|
||||
json={"usage": "Updated usage", "ports_mapping": data["ports_mapping"]},
|
||||
)
|
||||
assert response.status_code == 200
|
||||
assert response.json()["usage"] == "Updated usage"
|
||||
|
||||
@pytest.mark.parametrize("name", ["tap-interface-too-long", "tap bad", "/dev/tap0"])
|
||||
async def test_invalid_bridged_tap_rejected_before_save(self, app, compute_client, compute_project, name):
|
||||
with asyncio_patch("gns3server.compute.builtin.nodes.cloud.Cloud._start_ubridge") as start:
|
||||
response = await compute_client.post(
|
||||
app.url_path_for("compute:create_cloud", project_id=compute_project.id),
|
||||
json={
|
||||
"name": "Invalid TAP",
|
||||
"ports_mapping": [
|
||||
{"interface": name, "name": name, "port_number": 0, "type": "tap", "bridge": "virbr0"}
|
||||
],
|
||||
},
|
||||
)
|
||||
assert response.status_code == 422
|
||||
start.assert_not_called()
|
||||
@@ -370,6 +370,36 @@ class TestQemuNodesRoutes:
|
||||
assert response.json()["hdb_disk_image"] == "linux载.img"
|
||||
assert response.json()["ram"] == 1024
|
||||
|
||||
async def test_cdrom_interfaces_update_and_read_back(
|
||||
self, app: FastAPI, compute_client: AsyncClient, qemu_vm: dict
|
||||
) -> None:
|
||||
url = app.url_path_for("compute:update_qemu_node", project_id=qemu_vm["project_id"], node_id=qemu_vm["node_id"])
|
||||
response = await compute_client.put(url, json={"cdrom_interface": "sata", "cdrom2_interface": "sata"})
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert response.json()["cdrom_interface"] == "sata"
|
||||
assert response.json()["cdrom2_interface"] == "sata"
|
||||
response = await compute_client.get(url)
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert response.json()["cdrom_interface"] == "sata"
|
||||
assert response.json()["cdrom2_interface"] == "sata"
|
||||
|
||||
@pytest.mark.parametrize("name", ["cdrom_interface", "cdrom2_interface"])
|
||||
async def test_cdrom_interface_rejection_does_not_partially_update(self, app, compute_client, qemu_vm, name):
|
||||
url = app.url_path_for("compute:update_qemu_node", project_id=qemu_vm["project_id"], node_id=qemu_vm["node_id"])
|
||||
original = (await compute_client.get(url)).json()
|
||||
with patch("gns3server.compute.qemu.qemu_vm.QemuVM.is_running", return_value=True):
|
||||
response = await compute_client.put(url, json={"ram": original["ram"] + 128, name: "sata"})
|
||||
assert response.status_code == status.HTTP_409_CONFLICT
|
||||
saved = (await compute_client.get(url)).json()
|
||||
assert saved["ram"] == original["ram"]
|
||||
assert saved[name] == original[name]
|
||||
|
||||
@pytest.mark.parametrize("name", ["cdrom_interface", "cdrom2_interface"])
|
||||
async def test_cdrom_interface_rejects_null(self, app, compute_client, qemu_vm, name):
|
||||
url = app.url_path_for("compute:update_qemu_node", project_id=qemu_vm["project_id"], node_id=qemu_vm["node_id"])
|
||||
response = await compute_client.put(url, json={name: None})
|
||||
assert response.status_code == status.HTTP_422_UNPROCESSABLE_CONTENT
|
||||
|
||||
async def test_qemu_nio_create_udp(self, app: FastAPI, compute_client: AsyncClient, qemu_vm: dict) -> None:
|
||||
|
||||
params = {"type": "nio_udp", "lport": 4242, "rport": 4343, "rhost": "127.0.0.1"}
|
||||
|
||||
@@ -476,3 +476,40 @@ class TestImageRoutes:
|
||||
assert len(templates) == 1
|
||||
assert templates[0].name == "Empty VM"
|
||||
await templates_repo.delete_template(templates[0].template_id)
|
||||
|
||||
|
||||
class TestIsoImages:
|
||||
async def test_iso_uploads_can_be_used_together_in_a_template(self, app, client, config, images_dir):
|
||||
config.settings.Server.allow_raw_images = False
|
||||
references = []
|
||||
for index, name in enumerate(("installer.ISO", "drivers.iso")):
|
||||
content = bytes(16 * 2048) + b"\x01CD001\x01" + bytes([index]) * 2041
|
||||
response = await client.post(
|
||||
app.url_path_for("upload_image", image_path=name),
|
||||
params={"subdirectory": "installers"} if index == 0 else {},
|
||||
content=content,
|
||||
)
|
||||
assert response.status_code == status.HTTP_201_CREATED, response.text
|
||||
assert response.json()["image_type"] == "qemu"
|
||||
relative = "installers/" + name if index == 0 else name
|
||||
assert response.json()["path"] == os.path.join(images_dir, "QEMU", relative)
|
||||
assert response.json()["reference"] == relative
|
||||
assert Qemu.instance().get_abs_image_path(relative) == response.json()["path"]
|
||||
references.append(relative)
|
||||
|
||||
response = await client.post(
|
||||
app.url_path_for("create_template"),
|
||||
json={
|
||||
"name": "Windows installer with drivers",
|
||||
"template_type": "qemu",
|
||||
"compute_id": "local",
|
||||
"cdrom_image": references[0],
|
||||
"cdrom2_image": references[1],
|
||||
},
|
||||
)
|
||||
assert response.status_code == status.HTTP_201_CREATED, response.text
|
||||
template_id = response.json()["template_id"]
|
||||
response = await client.get(app.url_path_for("get_template", template_id=template_id))
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert response.json()["cdrom_image"] == references[0]
|
||||
assert response.json()["cdrom2_image"] == references[1]
|
||||
@@ -458,7 +458,14 @@ class TestReplayFrameDetail:
|
||||
"end": None,
|
||||
"frame_count": 0,
|
||||
"sources": [
|
||||
{"node_id": "n1", "link_id": link.id, "marker": "icmp", "data_link_type": "DLT_EN10MB", "count": 0}
|
||||
{
|
||||
"node_id": "n1",
|
||||
"link_id": link.id,
|
||||
"marker": "icmp",
|
||||
"data_link_type": "DLT_EN10MB",
|
||||
"count": 0,
|
||||
"error": None,
|
||||
}
|
||||
],
|
||||
"frames": [],
|
||||
}
|
||||
@@ -1112,6 +1112,28 @@ class TestDockerTemplate:
|
||||
|
||||
|
||||
class TestQemuTemplate:
|
||||
async def test_cdrom_interfaces_persist_on_template_update(self, app, client):
|
||||
params = {
|
||||
"name": "SATA installer",
|
||||
"compute_id": "local",
|
||||
"template_type": "qemu",
|
||||
"cdrom_interface": "sata",
|
||||
"cdrom2_interface": "sata",
|
||||
}
|
||||
response = await client.post(app.url_path_for("create_template"), json=params)
|
||||
assert response.status_code == status.HTTP_201_CREATED
|
||||
template_id = response.json()["template_id"]
|
||||
url = app.url_path_for("get_template", template_id=template_id)
|
||||
saved = (await client.get(url)).json()
|
||||
assert saved["cdrom_interface"] == saved["cdrom2_interface"] == "sata"
|
||||
response = await client.put(
|
||||
app.url_path_for("update_template", template_id=template_id), json={"cdrom_interface": "ide"}
|
||||
)
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
saved = (await client.get(url)).json()
|
||||
assert saved["cdrom_interface"] == "ide"
|
||||
assert saved["cdrom2_interface"] == "sata"
|
||||
|
||||
async def test_qemu_template_create(self, app: FastAPI, client: AsyncClient) -> None:
|
||||
|
||||
params = {
|
||||
|
||||
Reference in new issue
Block a user