2016-03-11 21:13:52 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
2020-06-16 07:29:03 +03:00
|
|
|
# Copyright (C) 2020 GNS3 Technologies Inc.
|
2016-03-11 21:13:52 +02:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
import pytest
|
2016-03-14 18:40:27 +02:00
|
|
|
import aiohttp
|
2016-03-11 21:13:52 +02:00
|
|
|
from unittest.mock import MagicMock
|
2017-06-30 11:22:30 +03:00
|
|
|
from tests.utils import AsyncioMagicMock
|
2016-03-11 21:13:52 +02:00
|
|
|
|
|
|
|
from gns3server.controller.udp_link import UDPLink
|
2016-09-15 15:51:40 +03:00
|
|
|
from gns3server.controller.ports.ethernet_port import EthernetPort
|
2016-05-11 20:35:36 +03:00
|
|
|
from gns3server.controller.node import Node
|
2016-03-11 21:13:52 +02:00
|
|
|
|
|
|
|
|
2020-06-16 07:29:03 +03:00
|
|
|
async def test_create(project):
|
2016-03-11 21:13:52 +02:00
|
|
|
|
2016-04-15 18:57:06 +03:00
|
|
|
compute1 = MagicMock()
|
|
|
|
compute2 = MagicMock()
|
2016-03-11 21:13:52 +02:00
|
|
|
|
2016-06-12 02:31:30 +03:00
|
|
|
node1 = Node(project, compute1, "node1", node_type="vpcs")
|
2016-09-15 15:51:40 +03:00
|
|
|
node1._ports = [EthernetPort("E0", 0, 0, 4)]
|
2016-06-12 02:31:30 +03:00
|
|
|
node2 = Node(project, compute2, "node2", node_type="vpcs")
|
2016-09-15 15:51:40 +03:00
|
|
|
node2._ports = [EthernetPort("E0", 0, 3, 1)]
|
2016-03-11 21:13:52 +02:00
|
|
|
|
2018-10-15 13:05:49 +03:00
|
|
|
async def subnet_callback(compute2):
|
2016-08-25 20:14:29 +03:00
|
|
|
"""
|
|
|
|
Fake subnet callback
|
|
|
|
"""
|
|
|
|
return ("192.168.1.1", "192.168.1.2")
|
|
|
|
|
|
|
|
compute1.get_ip_on_same_subnet.side_effect = subnet_callback
|
|
|
|
|
2016-03-11 21:13:52 +02:00
|
|
|
link = UDPLink(project)
|
2020-06-16 07:29:03 +03:00
|
|
|
await link.add_node(node1, 0, 4)
|
|
|
|
await link.update_filters({"latency": [10]})
|
2016-03-11 21:13:52 +02:00
|
|
|
|
2018-10-15 13:05:49 +03:00
|
|
|
async def compute1_callback(path, data={}, **kwargs):
|
2016-03-11 21:13:52 +02:00
|
|
|
"""
|
|
|
|
Fake server
|
|
|
|
"""
|
|
|
|
if "/ports/udp" in path:
|
|
|
|
response = MagicMock()
|
|
|
|
response.json = {"udp_port": 1024}
|
|
|
|
return response
|
|
|
|
|
2018-10-15 13:05:49 +03:00
|
|
|
async def compute2_callback(path, data={}, **kwargs):
|
2016-03-11 21:13:52 +02:00
|
|
|
"""
|
|
|
|
Fake server
|
|
|
|
"""
|
|
|
|
if "/ports/udp" in path:
|
|
|
|
response = MagicMock()
|
|
|
|
response.json = {"udp_port": 2048}
|
|
|
|
return response
|
|
|
|
|
2016-04-15 18:57:06 +03:00
|
|
|
compute1.post.side_effect = compute1_callback
|
|
|
|
compute1.host = "example.com"
|
|
|
|
compute2.post.side_effect = compute2_callback
|
|
|
|
compute2.host = "example.org"
|
2020-06-16 07:29:03 +03:00
|
|
|
await link.add_node(node2, 3, 1)
|
2016-03-11 21:13:52 +02:00
|
|
|
|
2016-05-11 20:35:36 +03:00
|
|
|
compute1.post.assert_any_call("/projects/{}/vpcs/nodes/{}/adapters/0/ports/4/nio".format(project.id, node1.id), data={
|
2016-03-11 21:13:52 +02:00
|
|
|
"lport": 1024,
|
2016-08-25 20:14:29 +03:00
|
|
|
"rhost": "192.168.1.2",
|
2016-03-11 21:13:52 +02:00
|
|
|
"rport": 2048,
|
2017-06-30 11:22:30 +03:00
|
|
|
"type": "nio_udp",
|
2018-03-19 13:25:56 +02:00
|
|
|
"filters": {"latency": [10]},
|
|
|
|
"suspend": False,
|
2016-11-08 10:54:59 +02:00
|
|
|
}, timeout=120)
|
2020-06-16 07:29:03 +03:00
|
|
|
|
2016-05-11 20:35:36 +03:00
|
|
|
compute2.post.assert_any_call("/projects/{}/vpcs/nodes/{}/adapters/3/ports/1/nio".format(project.id, node2.id), data={
|
2016-03-11 21:13:52 +02:00
|
|
|
"lport": 2048,
|
2016-08-25 20:14:29 +03:00
|
|
|
"rhost": "192.168.1.1",
|
2016-03-11 21:13:52 +02:00
|
|
|
"rport": 1024,
|
2017-06-30 11:22:30 +03:00
|
|
|
"type": "nio_udp",
|
2018-03-19 13:25:56 +02:00
|
|
|
"filters": {},
|
|
|
|
"suspend": False,
|
2016-11-08 10:54:59 +02:00
|
|
|
}, timeout=120)
|
2016-03-14 18:40:27 +02:00
|
|
|
|
|
|
|
|
2020-06-16 07:29:03 +03:00
|
|
|
async def test_create_one_side_failure(project):
|
|
|
|
|
2016-10-27 20:09:27 +03:00
|
|
|
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)]
|
|
|
|
|
2018-10-15 13:05:49 +03:00
|
|
|
async def subnet_callback(compute2):
|
2016-10-27 20:09:27 +03:00
|
|
|
"""
|
|
|
|
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)
|
2020-06-16 07:29:03 +03:00
|
|
|
await link.add_node(node1, 0, 4)
|
2016-10-27 20:09:27 +03:00
|
|
|
|
2018-10-15 13:05:49 +03:00
|
|
|
async def compute1_callback(path, data={}, **kwargs):
|
2016-10-27 20:09:27 +03:00
|
|
|
"""
|
|
|
|
Fake server
|
|
|
|
"""
|
|
|
|
if "/ports/udp" in path:
|
|
|
|
response = MagicMock()
|
|
|
|
response.json = {"udp_port": 1024}
|
|
|
|
return response
|
|
|
|
|
2018-10-15 13:05:49 +03:00
|
|
|
async def compute2_callback(path, data={}, **kwargs):
|
2016-10-27 20:09:27 +03:00
|
|
|
"""
|
|
|
|
Fake server
|
|
|
|
"""
|
|
|
|
if "/ports/udp" in path:
|
|
|
|
response = MagicMock()
|
|
|
|
response.json = {"udp_port": 2048}
|
|
|
|
return response
|
|
|
|
elif "/adapters" in path:
|
|
|
|
raise aiohttp.web.HTTPConflict(text="Error when creating the NIO")
|
|
|
|
|
|
|
|
compute1.post.side_effect = compute1_callback
|
|
|
|
compute1.host = "example.com"
|
|
|
|
compute2.post.side_effect = compute2_callback
|
|
|
|
compute2.host = "example.org"
|
|
|
|
with pytest.raises(aiohttp.web.HTTPConflict):
|
2020-06-16 07:29:03 +03:00
|
|
|
await link.add_node(node2, 3, 1)
|
2016-10-27 20:09:27 +03:00
|
|
|
|
|
|
|
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,
|
2017-06-30 11:22:30 +03:00
|
|
|
"type": "nio_udp",
|
2018-03-19 13:25:56 +02:00
|
|
|
"filters": {},
|
|
|
|
"suspend": False,
|
2016-11-08 10:54:59 +02:00
|
|
|
}, timeout=120)
|
2020-06-16 07:29:03 +03:00
|
|
|
|
2016-10-27 20:09:27 +03:00
|
|
|
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,
|
2017-06-30 11:22:30 +03:00
|
|
|
"type": "nio_udp",
|
2018-03-19 13:25:56 +02:00
|
|
|
"filters": {},
|
|
|
|
"suspend": False,
|
2016-11-08 10:54:59 +02:00
|
|
|
}, timeout=120)
|
2016-10-27 20:09:27 +03:00
|
|
|
# The link creation has failed we rollback the nio
|
2016-11-08 10:54:59 +02:00
|
|
|
compute1.delete.assert_any_call("/projects/{}/vpcs/nodes/{}/adapters/0/ports/4/nio".format(project.id, node1.id), timeout=120)
|
2016-10-27 20:09:27 +03:00
|
|
|
|
|
|
|
|
2020-06-16 07:29:03 +03:00
|
|
|
async def test_delete(project):
|
|
|
|
|
2016-04-15 18:57:06 +03:00
|
|
|
compute1 = MagicMock()
|
|
|
|
compute2 = MagicMock()
|
2016-03-14 18:40:27 +02:00
|
|
|
|
2016-06-12 02:31:30 +03:00
|
|
|
node1 = Node(project, compute1, "node1", node_type="vpcs")
|
2016-09-15 15:51:40 +03:00
|
|
|
node1._ports = [EthernetPort("E0", 0, 0, 4)]
|
2016-06-12 02:31:30 +03:00
|
|
|
node2 = Node(project, compute2, "node2", node_type="vpcs")
|
2016-09-15 15:51:40 +03:00
|
|
|
node2._ports = [EthernetPort("E0", 0, 3, 1)]
|
2016-03-14 18:40:27 +02:00
|
|
|
|
|
|
|
link = UDPLink(project)
|
2016-09-02 15:39:38 +03:00
|
|
|
link.create = AsyncioMagicMock()
|
2020-06-16 07:29:03 +03:00
|
|
|
await link.add_node(node1, 0, 4)
|
|
|
|
await link.add_node(node2, 3, 1)
|
2016-03-14 18:40:27 +02:00
|
|
|
|
2020-06-16 07:29:03 +03:00
|
|
|
await link.delete()
|
2016-03-14 18:40:27 +02:00
|
|
|
|
2016-11-08 10:54:59 +02:00
|
|
|
compute1.delete.assert_any_call("/projects/{}/vpcs/nodes/{}/adapters/0/ports/4/nio".format(project.id, node1.id), timeout=120)
|
|
|
|
compute2.delete.assert_any_call("/projects/{}/vpcs/nodes/{}/adapters/3/ports/1/nio".format(project.id, node2.id), timeout=120)
|
2016-04-21 13:14:09 +03:00
|
|
|
|
|
|
|
|
2020-06-16 07:29:03 +03:00
|
|
|
async def test_choose_capture_side(project):
|
2016-04-21 13:14:09 +03:00
|
|
|
"""
|
|
|
|
The link capture should run on the optimal node
|
|
|
|
"""
|
2020-06-16 07:29:03 +03:00
|
|
|
|
2016-04-21 13:14:09 +03:00
|
|
|
compute1 = MagicMock()
|
|
|
|
compute2 = MagicMock()
|
|
|
|
compute2.id = "local"
|
|
|
|
|
2016-11-22 17:05:00 +02:00
|
|
|
# Capture should run on the local node
|
2016-06-12 02:31:30 +03:00
|
|
|
node_vpcs = Node(project, compute1, "node1", node_type="vpcs")
|
2016-11-22 17:05:00 +02:00
|
|
|
node_vpcs._status = "started"
|
2016-09-15 15:51:40 +03:00
|
|
|
node_vpcs._ports = [EthernetPort("E0", 0, 0, 4)]
|
2016-06-12 02:31:30 +03:00
|
|
|
node_iou = Node(project, compute2, "node2", node_type="iou")
|
2016-11-22 17:05:00 +02:00
|
|
|
node_iou._status = "started"
|
2016-09-15 15:51:40 +03:00
|
|
|
node_iou._ports = [EthernetPort("E0", 0, 3, 1)]
|
2016-04-21 13:14:09 +03:00
|
|
|
|
|
|
|
link = UDPLink(project)
|
2016-09-02 15:39:38 +03:00
|
|
|
link.create = AsyncioMagicMock()
|
2020-06-16 07:29:03 +03:00
|
|
|
await link.add_node(node_vpcs, 0, 4)
|
|
|
|
await link.add_node(node_iou, 3, 1)
|
2016-04-21 13:14:09 +03:00
|
|
|
|
2016-05-11 20:35:36 +03:00
|
|
|
assert link._choose_capture_side()["node"] == node_iou
|
2016-04-21 13:14:09 +03:00
|
|
|
|
2016-11-22 17:05:00 +02:00
|
|
|
# Capture should choose always running node
|
|
|
|
node_iou = Node(project, compute1, "node5", node_type="iou")
|
|
|
|
node_iou._status = "started"
|
|
|
|
node_iou._ports = [EthernetPort("E0", 0, 0, 4)]
|
|
|
|
node_switch = Node(project, compute1, "node6", node_type="ethernet_switch")
|
|
|
|
node_switch._status = "started"
|
|
|
|
node_switch._ports = [EthernetPort("E0", 0, 3, 1)]
|
2016-04-21 13:14:09 +03:00
|
|
|
|
|
|
|
link = UDPLink(project)
|
2016-09-02 15:39:38 +03:00
|
|
|
link.create = AsyncioMagicMock()
|
2020-06-16 07:29:03 +03:00
|
|
|
await link.add_node(node_iou, 0, 4)
|
|
|
|
await link.add_node(node_switch, 3, 1)
|
2016-04-21 13:14:09 +03:00
|
|
|
|
2016-11-22 17:05:00 +02:00
|
|
|
assert link._choose_capture_side()["node"] == node_switch
|
|
|
|
|
|
|
|
# Capture should raise error if node are not started
|
|
|
|
node_vpcs = Node(project, compute1, "node1", node_type="vpcs")
|
|
|
|
node_vpcs._ports = [EthernetPort("E0", 0, 0, 4)]
|
|
|
|
node_iou = Node(project, compute2, "node2", node_type="iou")
|
|
|
|
node_iou._ports = [EthernetPort("E0", 0, 3, 1)]
|
2016-04-21 13:14:09 +03:00
|
|
|
|
|
|
|
link = UDPLink(project)
|
2016-09-02 15:39:38 +03:00
|
|
|
link.create = AsyncioMagicMock()
|
2020-06-16 07:29:03 +03:00
|
|
|
await link.add_node(node_vpcs, 0, 4)
|
|
|
|
await link.add_node(node_iou, 3, 1)
|
2016-04-21 13:14:09 +03:00
|
|
|
|
2016-11-22 17:05:00 +02:00
|
|
|
with pytest.raises(aiohttp.web.HTTPConflict):
|
|
|
|
link._choose_capture_side()
|
|
|
|
# If you start a node you can capture on it
|
|
|
|
node_vpcs._status = "started"
|
|
|
|
assert link._choose_capture_side()["node"] == node_vpcs
|
2016-04-21 13:14:09 +03:00
|
|
|
|
|
|
|
|
2020-06-16 07:29:03 +03:00
|
|
|
async def test_capture(project):
|
2016-04-21 13:14:09 +03:00
|
|
|
compute1 = MagicMock()
|
|
|
|
|
2016-06-12 02:31:30 +03:00
|
|
|
node_vpcs = Node(project, compute1, "V1", node_type="vpcs")
|
2016-11-22 17:05:00 +02:00
|
|
|
node_vpcs._status = "started"
|
2016-09-15 15:51:40 +03:00
|
|
|
node_vpcs._ports = [EthernetPort("E0", 0, 0, 4)]
|
2016-06-12 02:31:30 +03:00
|
|
|
node_iou = Node(project, compute1, "I1", node_type="iou")
|
2016-09-15 15:51:40 +03:00
|
|
|
node_iou._ports = [EthernetPort("E0", 0, 3, 1)]
|
2016-04-21 13:14:09 +03:00
|
|
|
|
|
|
|
link = UDPLink(project)
|
2016-09-02 15:39:38 +03:00
|
|
|
link.create = AsyncioMagicMock()
|
2020-06-16 07:29:03 +03:00
|
|
|
await link.add_node(node_vpcs, 0, 4)
|
|
|
|
await link.add_node(node_iou, 3, 1)
|
2016-04-21 13:14:09 +03:00
|
|
|
|
2020-06-16 07:29:03 +03:00
|
|
|
await link.start_capture()
|
2016-04-21 17:11:42 +03:00
|
|
|
assert link.capturing
|
2016-04-21 13:14:09 +03:00
|
|
|
|
2016-06-23 13:10:18 +03:00
|
|
|
compute1.post.assert_any_call("/projects/{}/vpcs/nodes/{}/adapters/0/ports/4/start_capture".format(project.id, node_vpcs.id), data={
|
2016-04-26 18:10:33 +03:00
|
|
|
"capture_file_name": link.default_capture_file_name(),
|
2016-04-21 13:14:09 +03:00
|
|
|
"data_link_type": "DLT_EN10MB"
|
|
|
|
})
|
|
|
|
|
2020-06-16 07:29:03 +03:00
|
|
|
await link.stop_capture()
|
2016-04-21 17:11:42 +03:00
|
|
|
assert link.capturing is False
|
2016-04-21 13:14:09 +03:00
|
|
|
|
2016-06-23 13:10:18 +03:00
|
|
|
compute1.post.assert_any_call("/projects/{}/vpcs/nodes/{}/adapters/0/ports/4/stop_capture".format(project.id, node_vpcs.id))
|
2016-04-22 17:22:03 +03:00
|
|
|
|
|
|
|
|
2020-06-16 07:29:03 +03:00
|
|
|
async def test_node_updated(project):
|
2016-11-22 17:05:00 +02:00
|
|
|
"""
|
|
|
|
If a node stop when capturing we stop the capture
|
|
|
|
"""
|
2020-06-16 07:29:03 +03:00
|
|
|
|
2016-11-22 17:05:00 +02:00
|
|
|
compute1 = MagicMock()
|
|
|
|
node_vpcs = Node(project, compute1, "V1", node_type="vpcs")
|
|
|
|
node_vpcs._status = "started"
|
|
|
|
|
|
|
|
link = UDPLink(project)
|
|
|
|
link._capture_node = {"node": node_vpcs}
|
|
|
|
link.stop_capture = AsyncioMagicMock()
|
|
|
|
|
2020-06-16 07:29:03 +03:00
|
|
|
await link.node_updated(node_vpcs)
|
2016-11-22 17:05:00 +02:00
|
|
|
assert not link.stop_capture.called
|
|
|
|
|
|
|
|
node_vpcs._status = "stopped"
|
2020-06-16 07:29:03 +03:00
|
|
|
await link.node_updated(node_vpcs)
|
2016-11-22 17:05:00 +02:00
|
|
|
assert link.stop_capture.called
|
2017-06-30 11:22:30 +03:00
|
|
|
|
|
|
|
|
2020-06-16 07:29:03 +03:00
|
|
|
async def test_update(project):
|
|
|
|
|
2017-06-30 11:22:30 +03:00
|
|
|
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)]
|
|
|
|
|
2018-10-15 13:05:49 +03:00
|
|
|
async def subnet_callback(compute2):
|
2017-06-30 11:22:30 +03:00
|
|
|
"""
|
|
|
|
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)
|
2020-06-16 07:29:03 +03:00
|
|
|
await link.add_node(node1, 0, 4)
|
|
|
|
await link.update_filters({"latency": [10]})
|
2017-06-30 11:22:30 +03:00
|
|
|
|
2018-10-15 13:05:49 +03:00
|
|
|
async def compute1_callback(path, data={}, **kwargs):
|
2017-06-30 11:22:30 +03:00
|
|
|
"""
|
|
|
|
Fake server
|
|
|
|
"""
|
|
|
|
if "/ports/udp" in path:
|
|
|
|
response = MagicMock()
|
|
|
|
response.json = {"udp_port": 1024}
|
|
|
|
return response
|
|
|
|
|
2018-10-15 13:05:49 +03:00
|
|
|
async def compute2_callback(path, data={}, **kwargs):
|
2017-06-30 11:22:30 +03:00
|
|
|
"""
|
|
|
|
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"
|
2020-06-16 07:29:03 +03:00
|
|
|
await link.add_node(node2, 3, 1)
|
2017-06-30 11:22:30 +03:00
|
|
|
|
|
|
|
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",
|
2018-03-19 13:25:56 +02:00
|
|
|
"suspend": False,
|
2017-06-30 11:22:30 +03:00
|
|
|
"filters": {"latency": [10]}
|
|
|
|
}, timeout=120)
|
2020-06-16 07:29:03 +03:00
|
|
|
|
2017-06-30 11:22:30 +03:00
|
|
|
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",
|
2018-03-19 13:25:56 +02:00
|
|
|
"suspend": False,
|
2017-06-30 11:22:30 +03:00
|
|
|
"filters": {}
|
|
|
|
}, timeout=120)
|
|
|
|
|
|
|
|
assert link.created
|
2020-06-16 07:29:03 +03:00
|
|
|
await link.update_filters({"drop": [5], "bpf": ["icmp[icmptype] == 8"]})
|
2017-06-30 11:22:30 +03:00
|
|
|
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",
|
2018-03-19 13:25:56 +02:00
|
|
|
"suspend": False,
|
2017-07-11 18:30:29 +03:00
|
|
|
"filters": {
|
|
|
|
"drop": [5],
|
|
|
|
"bpf": ["icmp[icmptype] == 8"]
|
|
|
|
}
|
2017-06-30 11:22:30 +03:00
|
|
|
}, timeout=120)
|
2017-07-19 18:30:25 +03:00
|
|
|
|
|
|
|
|
2020-06-16 07:29:03 +03:00
|
|
|
async def test_update_suspend(project):
|
2017-07-19 18:30:25 +03:00
|
|
|
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)]
|
|
|
|
|
2018-10-15 13:05:49 +03:00
|
|
|
async def subnet_callback(compute2):
|
2017-07-19 18:30:25 +03:00
|
|
|
"""
|
|
|
|
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)
|
2020-06-16 07:29:03 +03:00
|
|
|
await link.add_node(node1, 0, 4)
|
|
|
|
await link.update_filters({"latency": [10]})
|
|
|
|
await link.update_suspend(True)
|
2017-07-19 18:30:25 +03:00
|
|
|
|
2018-10-15 13:05:49 +03:00
|
|
|
async def compute1_callback(path, data={}, **kwargs):
|
2017-07-19 18:30:25 +03:00
|
|
|
"""
|
|
|
|
Fake server
|
|
|
|
"""
|
|
|
|
if "/ports/udp" in path:
|
|
|
|
response = MagicMock()
|
|
|
|
response.json = {"udp_port": 1024}
|
|
|
|
return response
|
|
|
|
|
2018-10-15 13:05:49 +03:00
|
|
|
async def compute2_callback(path, data={}, **kwargs):
|
2017-07-19 18:30:25 +03:00
|
|
|
"""
|
|
|
|
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"
|
2020-06-16 07:29:03 +03:00
|
|
|
await link.add_node(node2, 3, 1)
|
2017-07-19 18:30:25 +03:00
|
|
|
|
|
|
|
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",
|
2018-03-19 13:25:56 +02:00
|
|
|
"filters": {"frequency_drop": [-1]},
|
|
|
|
"suspend": True
|
2017-07-19 18:30:25 +03:00
|
|
|
}, timeout=120)
|
2020-06-16 07:29:03 +03:00
|
|
|
|
2017-07-19 18:30:25 +03:00
|
|
|
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",
|
2018-03-19 13:25:56 +02:00
|
|
|
"filters": {},
|
|
|
|
"suspend": True
|
2017-07-19 18:30:25 +03:00
|
|
|
}, timeout=120)
|