mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Merge pull request #1104 from GNS3/filters_api
Support packet filtering for VPCS
This commit is contained in:
commit
5bdc239064
25 files changed
+527
-270
No files matched your search
@@ -230,6 +230,7 @@ def test_json(async_run, project, compute, link):
|
||||
}
|
||||
}
|
||||
],
|
||||
"filters": {},
|
||||
"link_type": "ethernet",
|
||||
"capturing": False,
|
||||
"capture_file_name": None,
|
||||
@@ -262,7 +263,8 @@ def test_json(async_run, project, compute, link):
|
||||
'style': 'font-size: 10; font-style: Verdana'
|
||||
}
|
||||
}
|
||||
]
|
||||
],
|
||||
"filters": {}
|
||||
}
|
||||
|
||||
|
||||
@@ -348,3 +350,49 @@ def test_delete(async_run, project, compute):
|
||||
|
||||
async_run(link.delete())
|
||||
assert link not in node2.link
|
||||
|
||||
|
||||
def test_update_filters(async_run, project, compute):
|
||||
node1 = Node(project, compute, "node1", node_type="qemu")
|
||||
node1._ports = [EthernetPort("E0", 0, 0, 4)]
|
||||
|
||||
link = Link(project)
|
||||
link.create = AsyncioMagicMock()
|
||||
link._project.controller.notification.emit = MagicMock()
|
||||
project.dump = AsyncioMagicMock()
|
||||
async_run(link.add_node(node1, 0, 4))
|
||||
|
||||
node2 = Node(project, compute, "node2", node_type="qemu")
|
||||
node2._ports = [EthernetPort("E0", 0, 0, 4)]
|
||||
async_run(link.add_node(node2, 0, 4))
|
||||
|
||||
link.update = AsyncioMagicMock()
|
||||
assert link._created
|
||||
async_run(link.update_filters({
|
||||
"packet_loss": ["10"],
|
||||
"delay": ["50", "10"],
|
||||
"frequency_drop": ["0"]
|
||||
}))
|
||||
assert link.filters == {
|
||||
"packet_loss": [10],
|
||||
"delay": [50, 10]
|
||||
}
|
||||
assert link.update.called
|
||||
|
||||
|
||||
def test_available_filters(async_run, project, compute):
|
||||
node1 = Node(project, compute, "node1", node_type="qemu")
|
||||
node1._ports = [EthernetPort("E0", 0, 0, 4)]
|
||||
|
||||
link = Link(project)
|
||||
link.create = AsyncioMagicMock()
|
||||
assert link.available_filters() == []
|
||||
|
||||
# Qemu is not supported should return 0 filters
|
||||
async_run(link.add_node(node1, 0, 4))
|
||||
assert link.available_filters() == []
|
||||
|
||||
node2 = Node(project, compute, "node2", node_type="vpcs")
|
||||
node2._ports = [EthernetPort("E0", 0, 0, 4)]
|
||||
async_run(link.add_node(node2, 0, 4))
|
||||
assert len(link.available_filters()) > 0
|
||||
@@ -617,4 +617,4 @@ def test_add_iou_node_and_check_if_gets_application_id(project, async_run):
|
||||
node = async_run(project.add_node(
|
||||
compute, "test", None, node_type="iou", application_id=333, properties={"startup_config": "test.cfg"}))
|
||||
assert mocked_get_app_id.called
|
||||
assert node.properties['application_id'] == 333
|
||||
assert node.properties['application_id'] == 333
|
||||
@@ -19,7 +19,7 @@ import pytest
|
||||
import asyncio
|
||||
import aiohttp
|
||||
from unittest.mock import MagicMock
|
||||
from tests.utils import asyncio_patch, AsyncioMagicMock
|
||||
from tests.utils import AsyncioMagicMock
|
||||
|
||||
from gns3server.controller.project import Project
|
||||
from gns3server.controller.udp_link import UDPLink
|
||||
@@ -52,6 +52,7 @@ def test_create(async_run, project):
|
||||
|
||||
link = UDPLink(project)
|
||||
async_run(link.add_node(node1, 0, 4))
|
||||
async_run(link.update_filters({"latency": [10]}))
|
||||
|
||||
@asyncio.coroutine
|
||||
def compute1_callback(path, data={}, **kwargs):
|
||||
@@ -83,13 +84,15 @@ def test_create(async_run, project):
|
||||
"lport": 1024,
|
||||
"rhost": "192.168.1.2",
|
||||
"rport": 2048,
|
||||
"type": "nio_udp"
|
||||
"type": "nio_udp",
|
||||
"filters": {"latency": [10]}
|
||||
}, timeout=120)
|
||||
compute2.post.assert_any_call("/projects/{}/vpcs/nodes/{}/adapters/3/ports/1/nio".format(project.id, node2.id), data={
|
||||
"lport": 2048,
|
||||
"rhost": "192.168.1.1",
|
||||
"rport": 1024,
|
||||
"type": "nio_udp"
|
||||
"type": "nio_udp",
|
||||
"filters": {}
|
||||
}, timeout=120)
|
||||
|
||||
|
||||
@@ -147,13 +150,15 @@ def test_create_one_side_failure(async_run, project):
|
||||
"lport": 1024,
|
||||
"rhost": "192.168.1.2",
|
||||
"rport": 2048,
|
||||
"type": "nio_udp"
|
||||
"type": "nio_udp",
|
||||
"filters": {}
|
||||
}, timeout=120)
|
||||
compute2.post.assert_any_call("/projects/{}/vpcs/nodes/{}/adapters/3/ports/1/nio".format(project.id, node2.id), data={
|
||||
"lport": 2048,
|
||||
"rhost": "192.168.1.1",
|
||||
"rport": 1024,
|
||||
"type": "nio_udp"
|
||||
"type": "nio_udp",
|
||||
"filters": {}
|
||||
}, timeout=120)
|
||||
# The link creation has failed we rollback the nio
|
||||
compute1.delete.assert_any_call("/projects/{}/vpcs/nodes/{}/adapters/0/ports/4/nio".format(project.id, node1.id), timeout=120)
|
||||
@@ -302,3 +307,77 @@ def test_node_updated(project, async_run):
|
||||
node_vpcs._status = "stopped"
|
||||
async_run(link.node_updated(node_vpcs))
|
||||
assert link.stop_capture.called
|
||||
|
||||
|
||||
def test_update(async_run, project):
|
||||
compute1 = MagicMock()
|
||||
compute2 = MagicMock()
|
||||
|
||||
node1 = Node(project, compute1, "node1", node_type="vpcs")
|
||||
node1._ports = [EthernetPort("E0", 0, 0, 4)]
|
||||
node2 = Node(project, compute2, "node2", node_type="vpcs")
|
||||
node2._ports = [EthernetPort("E0", 0, 3, 1)]
|
||||
|
||||
@asyncio.coroutine
|
||||
def subnet_callback(compute2):
|
||||
"""
|
||||
Fake subnet callback
|
||||
"""
|
||||
return ("192.168.1.1", "192.168.1.2")
|
||||
|
||||
compute1.get_ip_on_same_subnet.side_effect = subnet_callback
|
||||
|
||||
link = UDPLink(project)
|
||||
async_run(link.add_node(node1, 0, 4))
|
||||
async_run(link.update_filters({"latency": [10]}))
|
||||
|
||||
@asyncio.coroutine
|
||||
def compute1_callback(path, data={}, **kwargs):
|
||||
"""
|
||||
Fake server
|
||||
"""
|
||||
if "/ports/udp" in path:
|
||||
response = MagicMock()
|
||||
response.json = {"udp_port": 1024}
|
||||
return response
|
||||
|
||||
@asyncio.coroutine
|
||||
def compute2_callback(path, data={}, **kwargs):
|
||||
"""
|
||||
Fake server
|
||||
"""
|
||||
if "/ports/udp" in path:
|
||||
response = MagicMock()
|
||||
response.json = {"udp_port": 2048}
|
||||
return response
|
||||
|
||||
compute1.post.side_effect = compute1_callback
|
||||
compute1.host = "example.com"
|
||||
compute2.post.side_effect = compute2_callback
|
||||
compute2.host = "example.org"
|
||||
async_run(link.add_node(node2, 3, 1))
|
||||
|
||||
compute1.post.assert_any_call("/projects/{}/vpcs/nodes/{}/adapters/0/ports/4/nio".format(project.id, node1.id), data={
|
||||
"lport": 1024,
|
||||
"rhost": "192.168.1.2",
|
||||
"rport": 2048,
|
||||
"type": "nio_udp",
|
||||
"filters": {"latency": [10]}
|
||||
}, timeout=120)
|
||||
compute2.post.assert_any_call("/projects/{}/vpcs/nodes/{}/adapters/3/ports/1/nio".format(project.id, node2.id), data={
|
||||
"lport": 2048,
|
||||
"rhost": "192.168.1.1",
|
||||
"rport": 1024,
|
||||
"type": "nio_udp",
|
||||
"filters": {}
|
||||
}, timeout=120)
|
||||
|
||||
assert link.created
|
||||
async_run(link.update_filters({"drop": [5]}))
|
||||
compute1.put.assert_any_call("/projects/{}/vpcs/nodes/{}/adapters/0/ports/4/nio".format(project.id, node1.id), data={
|
||||
"lport": 1024,
|
||||
"rhost": "192.168.1.2",
|
||||
"rport": 2048,
|
||||
"type": "nio_udp",
|
||||
"filters": {"drop": [5]}
|
||||
}, timeout=120)
|
||||
Reference in new issue
Block a user