mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-20 21:25:14 +02:00
refactor: remove platform-specific code for Darwin and Windows. Clean up Qemu options handling
This commit is contained in:
20 files changed
+77
-532
No files matched your search
@@ -171,7 +171,7 @@ async def test_json_without_ports(on_gns3vm, compute_project, manager):
|
||||
}
|
||||
|
||||
|
||||
async def test_kernel_datapath_interfaces_are_hidden(linux_platform, compute_project, manager):
|
||||
async def test_kernel_datapath_interfaces_are_hidden(compute_project, manager):
|
||||
"""
|
||||
Kernel-datapath interfaces (node anchors, cascade veths, VXLAN devices)
|
||||
are neither pre-filled as cloud ports nor listed as host interfaces,
|
||||
@@ -221,7 +221,7 @@ async def test_update_port_mappings(on_gns3vm, compute_project):
|
||||
assert cloud.ports_mapping == ports1
|
||||
|
||||
|
||||
async def test_linux_ethernet_raw_add_nio(linux_platform, compute_project, nio):
|
||||
async def test_linux_ethernet_raw_add_nio(compute_project, nio):
|
||||
ports = [{"interface": "eth0", "name": "eth0", "port_number": 0, "type": "ethernet"}]
|
||||
cloud = Cloud("cloud1", str(uuid.uuid4()), compute_project, MagicMock(), ports=ports)
|
||||
cloud.status = "started"
|
||||
@@ -243,7 +243,7 @@ async def test_linux_ethernet_raw_add_nio(linux_platform, compute_project, nio):
|
||||
)
|
||||
|
||||
|
||||
async def test_linux_ethernet_raw_add_nio_bridge(linux_platform, compute_project, nio):
|
||||
async def test_linux_ethernet_raw_add_nio_bridge(compute_project, nio):
|
||||
"""
|
||||
Bridge can't be connected directly to a cloud we use a tap in the middle
|
||||
"""
|
||||
@@ -275,7 +275,7 @@ async def test_linux_ethernet_raw_add_nio_bridge(linux_platform, compute_project
|
||||
|
||||
@pytest.mark.parametrize("bridge", [None, "virbr0"])
|
||||
@pytest.mark.parametrize("existing_master", [False, True])
|
||||
async def test_tap_bridge_recreated(linux_platform, compute_project, manager, nio, bridge, existing_master):
|
||||
async def test_tap_bridge_recreated(compute_project, manager, nio, bridge, existing_master):
|
||||
ports = [{"interface": "tap0", "name": "tap0", "port_number": 0, "type": "tap"}]
|
||||
if bridge:
|
||||
ports[0]["bridge"] = bridge
|
||||
@@ -302,8 +302,8 @@ async def test_tap_bridge_recreated(linux_platform, compute_project, manager, ni
|
||||
assert attach_call not in send.call_args_list
|
||||
|
||||
|
||||
@pytest.mark.parametrize("failure", ["missing", "not_bridge", "other_master", "invalid_name", "non_linux"])
|
||||
async def test_tap_bridge_validation(linux_platform, compute_project, manager, nio, failure):
|
||||
@pytest.mark.parametrize("failure", ["missing", "not_bridge", "other_master", "invalid_name"])
|
||||
async def test_tap_bridge_validation(compute_project, manager, nio, failure):
|
||||
ports = [{"interface": "tap0", "name": "tap0", "port_number": 0, "type": "tap", "bridge": "virbr0"}]
|
||||
if failure == "invalid_name":
|
||||
ports[0]["interface"] = 'tap0"\nbridge delete all'
|
||||
@@ -314,14 +314,13 @@ async def test_tap_bridge_validation(linux_platform, compute_project, manager, n
|
||||
patch("gns3server.utils.interfaces.is_interface_bridge", return_value=failure != "not_bridge"),
|
||||
patch("gns3server.compute.builtin.nodes.cloud.os.path.exists", return_value=failure == "other_master"),
|
||||
patch("gns3server.compute.builtin.nodes.cloud.os.path.realpath", return_value="/sys/class/net/another0"),
|
||||
patch("gns3server.compute.builtin.nodes.cloud.sys.platform", "darwin" if failure == "non_linux" else "linux"),
|
||||
):
|
||||
with pytest.raises(NodeError):
|
||||
await cloud._add_ubridge_connection(nio, 0)
|
||||
assert not any("add_nio_tap" in c.args[0] or "brctl addif" in c.args[0] for c in send.call_args_list)
|
||||
|
||||
|
||||
async def test_tap_bridge_attachment_failure(linux_platform, compute_project, manager, nio):
|
||||
async def test_tap_bridge_attachment_failure(compute_project, manager, nio):
|
||||
ports = [{"interface": "tap0", "name": "tap0", "port_number": 0, "type": "tap", "bridge": "virbr0"}]
|
||||
cloud = Cloud("cloud1", str(uuid.uuid4()), compute_project, manager, ports=ports)
|
||||
cloud.status = "started"
|
||||
@@ -342,7 +341,7 @@ async def test_tap_bridge_attachment_failure(linux_platform, compute_project, ma
|
||||
assert cloud.status == "stopped"
|
||||
|
||||
|
||||
async def test_cloud_lists_linux_bridges(linux_platform, compute_project, manager):
|
||||
async def test_cloud_lists_linux_bridges(compute_project, manager):
|
||||
cloud = Cloud(
|
||||
"cloud1",
|
||||
str(uuid.uuid4()),
|
||||
@@ -400,7 +399,7 @@ async def test_bridged_tap_name_validation_preserves_legacy_names(name):
|
||||
((1 << 12) | (1 << 13), True, True),
|
||||
],
|
||||
)
|
||||
async def test_bridged_tap_requires_net_admin(linux_platform, tmp_path, caps, legacy_allowed, bridge_allowed):
|
||||
async def test_bridged_tap_requires_net_admin(tmp_path, caps, legacy_allowed, bridge_allowed):
|
||||
executable = tmp_path / "ubridge"
|
||||
executable.write_text("")
|
||||
with (
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import uuid
|
||||
from unittest.mock import MagicMock, patch
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from gns3server.compute.builtin.nodes.nat import Nat
|
||||
|
||||
@@ -40,57 +40,3 @@ def test_json_gns3vm(on_gns3vm, compute_project):
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
def test_json_darwin(darwin_platform, compute_project):
|
||||
|
||||
with patch(
|
||||
"gns3server.utils.interfaces.interfaces",
|
||||
return_value=[
|
||||
{"name": "eth0", "special": False, "type": "ethernet"},
|
||||
{"name": "vmnet8", "special": True, "type": "ethernet"},
|
||||
],
|
||||
):
|
||||
nat = Nat("nat1", str(uuid.uuid4()), compute_project, MagicMock())
|
||||
assert nat.asdict() == {
|
||||
"name": "nat1",
|
||||
"usage": "",
|
||||
"node_id": nat.id,
|
||||
"project_id": compute_project.id,
|
||||
"status": "started",
|
||||
"ports_mapping": [{"interface": "vmnet8", "name": "nat0", "port_number": 0, "type": "ethernet"}],
|
||||
"interfaces": [
|
||||
{
|
||||
"name": "vmnet8",
|
||||
"type": "ethernet",
|
||||
"special": True,
|
||||
"ip_addresses": [],
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
def test_json_windows_with_full_name_of_interface(windows_platform, project):
|
||||
with patch(
|
||||
"gns3server.utils.interfaces.interfaces",
|
||||
return_value=[{"name": "VMware Network Adapter VMnet8", "special": True, "type": "ethernet"}],
|
||||
):
|
||||
nat = Nat("nat1", str(uuid.uuid4()), project, MagicMock())
|
||||
assert nat.asdict() == {
|
||||
"name": "nat1",
|
||||
"usage": "",
|
||||
"node_id": nat.id,
|
||||
"project_id": project.id,
|
||||
"status": "started",
|
||||
"ports_mapping": [
|
||||
{"interface": "VMware Network Adapter VMnet8", "name": "nat0", "port_number": 0, "type": "ethernet"}
|
||||
],
|
||||
"interfaces": [
|
||||
{
|
||||
"name": "VMware Network Adapter VMnet8",
|
||||
"type": "ethernet",
|
||||
"special": True,
|
||||
"ip_addresses": [],
|
||||
},
|
||||
],
|
||||
}
|
||||
Reference in new issue
Block a user