mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-06 15:21:13 +02:00
Support bridge in cloud
Nat take advantage of that and the code is more simple. Fix #761
This commit is contained in:
5 files changed
+80
-45
No files matched your search
@@ -152,3 +152,32 @@ def test_linux_ethernet_raw_add_nio(linux_platform, project, async_run, nio):
|
||||
call("bridge add_nio_linux_raw {}-0 \"eth0\"".format(cloud._id)),
|
||||
call("bridge start {}-0".format(cloud._id)),
|
||||
])
|
||||
|
||||
|
||||
def test_linux_ethernet_raw_add_nio_bridge(linux_platform, project, async_run, nio):
|
||||
"""
|
||||
Bridge can't be connected directly to a cloud we use a tap in the middle
|
||||
"""
|
||||
ports = [
|
||||
{
|
||||
"interface": "bridge0",
|
||||
"name": "bridge0",
|
||||
"port_number": 0,
|
||||
"type": "ethernet"
|
||||
}
|
||||
]
|
||||
cloud = Cloud("cloud1", str(uuid.uuid4()), project, MagicMock(), ports=ports)
|
||||
|
||||
with asyncio_patch("gns3server.compute.builtin.nodes.cloud.Cloud._ubridge_send") as ubridge_mock:
|
||||
with patch("gns3server.compute.builtin.nodes.cloud.Cloud._interfaces", return_value=[{"name": "bridge0"}]):
|
||||
with patch("gns3server.utils.interfaces.is_interface_bridge", return_value=True):
|
||||
async_run(cloud.add_nio(nio, 0))
|
||||
|
||||
tap = "gns3tap{}-0".format(cloud._cloud_id)
|
||||
ubridge_mock.assert_has_calls([
|
||||
call("bridge create {}-0".format(cloud._id)),
|
||||
call("bridge add_nio_udp {}-0 4242 127.0.0.1 4343".format(cloud._id)),
|
||||
call("bridge add_nio_tap \"{}-0\" \"{}\"".format(cloud._id, tap)),
|
||||
call("brctl addif \"bridge0\" \"{}\"".format(tap)),
|
||||
call("bridge start {}-0".format(cloud._id)),
|
||||
])
|
||||
@@ -24,12 +24,6 @@ from gns3server.compute.builtin.nodes.nat import Nat
|
||||
from gns3server.compute.vpcs import VPCS
|
||||
|
||||
|
||||
def test_init(on_gns3vm, project):
|
||||
nat1 = Nat("nat1", str(uuid.uuid4()), project, MagicMock())
|
||||
nat2 = Nat("nat2", str(uuid.uuid4()), project, MagicMock())
|
||||
assert nat1.ports_mapping[0]["interface"] != nat2.ports_mapping[0]["interface"]
|
||||
|
||||
|
||||
def test_json(on_gns3vm, project):
|
||||
nat = Nat("nat1", str(uuid.uuid4()), project, MagicMock())
|
||||
assert nat.__json__() == {
|
||||
@@ -39,20 +33,10 @@ def test_json(on_gns3vm, project):
|
||||
"status": "started",
|
||||
"ports_mapping": [
|
||||
{
|
||||
"interface": nat._interface,
|
||||
"interface": "virbr0",
|
||||
"name": "nat0",
|
||||
"port_number": 0,
|
||||
"type": "tap"
|
||||
"type": "ethernet"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
def test_add_nio(on_gns3vm, project, async_run):
|
||||
nio = VPCS.instance().create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
|
||||
nat = Nat("nat1", str(uuid.uuid4()), project, MagicMock())
|
||||
with asyncio_patch("gns3server.compute.builtin.nodes.cloud.Cloud.add_nio") as cloud_add_nio_mock:
|
||||
with asyncio_patch("gns3server.compute.base_node.BaseNode._ubridge_send") as nat_ubridge_send_mock:
|
||||
async_run(nat.add_nio(0, nio))
|
||||
assert cloud_add_nio_mock.called
|
||||
nat_ubridge_send_mock.assert_called_with("brctl addif virbr0 \"{}\"".format(nat._interface))
|
||||
Reference in new issue
Block a user