mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-24 17:28:08 +00:00
parent
5d12a91268
commit
da5e3d0e54
@ -42,6 +42,7 @@ class Link:
|
|||||||
self._capture_file_name = None
|
self._capture_file_name = None
|
||||||
self._streaming_pcap = None
|
self._streaming_pcap = None
|
||||||
self._created = False
|
self._created = False
|
||||||
|
self._link_type = "ethernet"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def created(self):
|
def created(self):
|
||||||
@ -56,11 +57,19 @@ class Link:
|
|||||||
Add a node to the link
|
Add a node to the link
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
port = node.get_port(adapter_number, port_number)
|
||||||
|
self._link_type = port.link_type
|
||||||
|
|
||||||
for other_node in self._nodes:
|
for other_node in self._nodes:
|
||||||
if node.node_type in ["nat", "cloud"]:
|
if node.node_type in ["nat", "cloud"]:
|
||||||
if other_node["node"].node_type in ["nat", "cloud"]:
|
if other_node["node"].node_type in ["nat", "cloud"]:
|
||||||
raise aiohttp.web.HTTPConflict(text="It's not allowed to connect a {} to a {}".format(other_node["node"].node_type, node.node_type))
|
raise aiohttp.web.HTTPConflict(text="It's not allowed to connect a {} to a {}".format(other_node["node"].node_type, node.node_type))
|
||||||
|
|
||||||
|
# Check if user is not connecting serial => ethernet
|
||||||
|
other_port = other_node["node"].get_port(other_node["adapter_number"], other_node["port_number"])
|
||||||
|
if port.link_type != other_port.link_type:
|
||||||
|
raise aiohttp.web.HTTPConflict(text="It's not allowed to connect a {} to a {}".format(other_port.link_type, port.link_type))
|
||||||
|
|
||||||
if label is None:
|
if label is None:
|
||||||
label = {
|
label = {
|
||||||
"x": -10,
|
"x": -10,
|
||||||
@ -225,5 +234,6 @@ class Link:
|
|||||||
"project_id": self._project.id,
|
"project_id": self._project.id,
|
||||||
"capturing": self._capturing,
|
"capturing": self._capturing,
|
||||||
"capture_file_name": self._capture_file_name,
|
"capture_file_name": self._capture_file_name,
|
||||||
"capture_file_path": self.capture_file_path
|
"capture_file_path": self.capture_file_path,
|
||||||
|
"link_type": self._link_type
|
||||||
}
|
}
|
||||||
|
@ -70,6 +70,7 @@ class Node:
|
|||||||
self._x = 0
|
self._x = 0
|
||||||
self._y = 0
|
self._y = 0
|
||||||
self._z = 0
|
self._z = 0
|
||||||
|
self._ports = None
|
||||||
self._symbol = None
|
self._symbol = None
|
||||||
if node_type == "iou":
|
if node_type == "iou":
|
||||||
self._port_name_format = "Ethernet{segment0}/{port0}"
|
self._port_name_format = "Ethernet{segment0}/{port0}"
|
||||||
@ -159,6 +160,12 @@ class Node:
|
|||||||
"""
|
"""
|
||||||
return self._compute.host
|
return self._compute.host
|
||||||
|
|
||||||
|
@property
|
||||||
|
def ports(self):
|
||||||
|
if self._ports is None:
|
||||||
|
self._list_ports()
|
||||||
|
return self._ports
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def x(self):
|
def x(self):
|
||||||
return self._x
|
return self._x
|
||||||
@ -303,6 +310,7 @@ class Node:
|
|||||||
else:
|
else:
|
||||||
setattr(self, prop, kwargs[prop])
|
setattr(self, prop, kwargs[prop])
|
||||||
|
|
||||||
|
self._list_ports()
|
||||||
# We send notif only if object has changed
|
# We send notif only if object has changed
|
||||||
if old_json != self.__json__():
|
if old_json != self.__json__():
|
||||||
self.project.controller.notification.emit("node.updated", self.__json__())
|
self.project.controller.notification.emit("node.updated", self.__json__())
|
||||||
@ -333,6 +341,7 @@ class Node:
|
|||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
self._properties[key] = value
|
self._properties[key] = value
|
||||||
|
self._list_ports()
|
||||||
|
|
||||||
def _node_data(self, properties=None):
|
def _node_data(self, properties=None):
|
||||||
"""
|
"""
|
||||||
@ -457,26 +466,38 @@ class Node:
|
|||||||
"""
|
"""
|
||||||
return (yield from self._compute.get("/projects/{}/{}/nodes/{}/idlepc_proposals".format(self._project.id, self._node_type, self._id), timeout=240)).json
|
return (yield from self._compute.get("/projects/{}/{}/nodes/{}/idlepc_proposals".format(self._project.id, self._node_type, self._id), timeout=240)).json
|
||||||
|
|
||||||
|
def get_port(self, adapter_number, port_number):
|
||||||
|
"""
|
||||||
|
Return the port for this adapter_number and port_number
|
||||||
|
or raise an HTTPNotFound
|
||||||
|
"""
|
||||||
|
for port in self.ports:
|
||||||
|
if port.adapter_number == adapter_number and port.port_number == port_number:
|
||||||
|
return port
|
||||||
|
raise aiohttp.web.HTTPNotFound(text="Port {}/{} for {} not found".format(adapter_number, port_number, self.name))
|
||||||
|
|
||||||
def _list_ports(self):
|
def _list_ports(self):
|
||||||
"""
|
"""
|
||||||
Generate the list of port display in the client
|
Generate the list of port display in the client
|
||||||
if the compute has sent a list we return it (use by
|
if the compute has sent a list we return it (use by
|
||||||
node where you can not personnalize the port naming).
|
node where you can not personnalize the port naming).
|
||||||
"""
|
"""
|
||||||
ports = []
|
self._ports = []
|
||||||
# Some special cases
|
# Some special cases
|
||||||
if self._node_type == "atm_switch":
|
if self._node_type == "atm_switch":
|
||||||
for adapter_number in range(0, len(self.properties["mappings"])):
|
for adapter_number in range(0, len(self.properties["mappings"])):
|
||||||
ports.append(PortFactory("ATM{}".format(adapter_number), adapter_number, adapter_number, 0, "atm"))
|
self._ports.append(PortFactory("ATM{}".format(adapter_number), adapter_number, adapter_number, 0, "atm"))
|
||||||
return ports
|
return
|
||||||
elif self._node_type == "frame_relay_switch":
|
elif self._node_type == "frame_relay_switch":
|
||||||
for adapter_number in range(0, len(self.properties["mappings"])):
|
for adapter_number in range(0, len(self.properties["mappings"])):
|
||||||
ports.append(PortFactory("FrameRelay{}".format(adapter_number), adapter_number, adapter_number, 0, "frame_relay"))
|
self._ports.append(PortFactory("FrameRelay{}".format(adapter_number), adapter_number, adapter_number, 0, "frame_relay"))
|
||||||
return ports
|
return
|
||||||
elif self._node_type == "dynamips":
|
elif self._node_type == "dynamips":
|
||||||
return DynamipsPortFactory(self.properties)
|
self._ports = DynamipsPortFactory(self.properties)
|
||||||
|
return
|
||||||
else:
|
else:
|
||||||
return StandardPortFactory(self.properties, self._port_by_adapter, self._first_port_name, self._port_name_format, self._port_segment_size)
|
self._ports = StandardPortFactory(self.properties, self._port_by_adapter, self._first_port_name, self._port_name_format, self._port_segment_size)
|
||||||
|
return
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<gns3server.controller.Node {} {}>".format(self._node_type, self._name)
|
return "<gns3server.controller.Node {} {}>".format(self._node_type, self._name)
|
||||||
@ -533,5 +554,5 @@ class Node:
|
|||||||
"port_name_format": self._port_name_format,
|
"port_name_format": self._port_name_format,
|
||||||
"port_segment_size": self._port_segment_size,
|
"port_segment_size": self._port_segment_size,
|
||||||
"first_port_name": self._first_port_name,
|
"first_port_name": self._first_port_name,
|
||||||
"ports": [port.__json__() for port in self._list_ports()]
|
"ports": [port.__json__() for port in self.ports]
|
||||||
}
|
}
|
||||||
|
@ -19,43 +19,31 @@
|
|||||||
ATM port for ATM link end points.
|
ATM port for ATM link end points.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from .port import Port
|
from .serial_port import SerialPort
|
||||||
|
|
||||||
|
|
||||||
class ATMPort(Port):
|
class ATMPort(SerialPort):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def longNameType():
|
def long_name_type():
|
||||||
"""
|
"""
|
||||||
Returns the long name type for this port.
|
Returns the long name type for this port.
|
||||||
|
|
||||||
:returns: string
|
:returns: string
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return "ATM"
|
return "ATM"
|
||||||
|
|
||||||
@staticmethod
|
@property
|
||||||
def shortNameType():
|
def short_name_type(self):
|
||||||
"""
|
"""
|
||||||
Returns the short name type for this port.
|
Returns the short name type for this port.
|
||||||
|
|
||||||
:returns: string
|
:returns: string
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return "a"
|
return "a"
|
||||||
|
|
||||||
@staticmethod
|
@property
|
||||||
def linkType():
|
def data_link_types(self):
|
||||||
"""
|
|
||||||
Returns the link type to be used to connect this port.
|
|
||||||
|
|
||||||
:returns: string
|
|
||||||
"""
|
|
||||||
|
|
||||||
return "Serial"
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def dataLinkTypes():
|
|
||||||
"""
|
"""
|
||||||
Returns the supported PCAP DLTs.
|
Returns the supported PCAP DLTs.
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ class EthernetPort(Port):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def longNameType():
|
def long_name_type():
|
||||||
"""
|
"""
|
||||||
Returns the long name type for this port.
|
Returns the long name type for this port.
|
||||||
|
|
||||||
@ -39,8 +39,8 @@ class EthernetPort(Port):
|
|||||||
|
|
||||||
return "Ethernet"
|
return "Ethernet"
|
||||||
|
|
||||||
@staticmethod
|
@property
|
||||||
def shortNameType():
|
def short_name_type(self):
|
||||||
"""
|
"""
|
||||||
Returns the short name type for this port.
|
Returns the short name type for this port.
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ from .port import Port
|
|||||||
class FastEthernetPort(Port):
|
class FastEthernetPort(Port):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def longNameType():
|
def long_name_type():
|
||||||
"""
|
"""
|
||||||
Returns the long name type for this port.
|
Returns the long name type for this port.
|
||||||
|
|
||||||
@ -34,8 +34,8 @@ class FastEthernetPort(Port):
|
|||||||
|
|
||||||
return "FastEthernet"
|
return "FastEthernet"
|
||||||
|
|
||||||
@staticmethod
|
@property
|
||||||
def shortNameType():
|
def short_name_type(self):
|
||||||
"""
|
"""
|
||||||
Returns the short name type for this port.
|
Returns the short name type for this port.
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ from .serial_port import SerialPort
|
|||||||
class FrameRelayPort(SerialPort):
|
class FrameRelayPort(SerialPort):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def longNameType():
|
def long_name_type():
|
||||||
"""
|
"""
|
||||||
Returns the long name type for this port.
|
Returns the long name type for this port.
|
||||||
|
|
||||||
@ -34,8 +34,8 @@ class FrameRelayPort(SerialPort):
|
|||||||
|
|
||||||
return "FrameRelay"
|
return "FrameRelay"
|
||||||
|
|
||||||
@staticmethod
|
@property
|
||||||
def dataLinkTypes():
|
def data_link_types(self):
|
||||||
"""
|
"""
|
||||||
Returns the supported PCAP DLTs.
|
Returns the supported PCAP DLTs.
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ from .port import Port
|
|||||||
class GigabitEthernetPort(Port):
|
class GigabitEthernetPort(Port):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def longNameType():
|
def long_name_type():
|
||||||
"""
|
"""
|
||||||
Returns the long name type for this port.
|
Returns the long name type for this port.
|
||||||
|
|
||||||
@ -34,8 +34,8 @@ class GigabitEthernetPort(Port):
|
|||||||
|
|
||||||
return "GigabitEthernet"
|
return "GigabitEthernet"
|
||||||
|
|
||||||
@staticmethod
|
@property
|
||||||
def shortNameType():
|
def short_name_type(self):
|
||||||
"""
|
"""
|
||||||
Returns the short name type for this port.
|
Returns the short name type for this port.
|
||||||
|
|
||||||
|
@ -27,8 +27,16 @@ class Port:
|
|||||||
self._port_number = port_number
|
self._port_number = port_number
|
||||||
self._name = name
|
self._name = name
|
||||||
|
|
||||||
@staticmethod
|
@property
|
||||||
def dataLinkTypes():
|
def adapter_number(self):
|
||||||
|
return self._adapter_number
|
||||||
|
|
||||||
|
@property
|
||||||
|
def port_number(self):
|
||||||
|
return self._port_number
|
||||||
|
|
||||||
|
@property
|
||||||
|
def data_link_types(self):
|
||||||
"""
|
"""
|
||||||
Returns the supported PCAP DLTs.
|
Returns the supported PCAP DLTs.
|
||||||
|
|
||||||
@ -36,16 +44,16 @@ class Port:
|
|||||||
"""
|
"""
|
||||||
return {"Ethernet": "DLT_EN10MB"}
|
return {"Ethernet": "DLT_EN10MB"}
|
||||||
|
|
||||||
@staticmethod
|
@property
|
||||||
def linkType():
|
def link_type(self):
|
||||||
return "Ethernet"
|
return "ethernet"
|
||||||
|
|
||||||
def __json__(self):
|
def __json__(self):
|
||||||
return {
|
return {
|
||||||
"name": self._name,
|
"name": self._name,
|
||||||
"short_name": self.shortNameType() + "{}/{}".format(self._interface_number, self._port_number),
|
"short_name": self.short_name_type + "{}/{}".format(self._interface_number, self._port_number),
|
||||||
"data_link_types": self.dataLinkTypes(),
|
"data_link_types": self.data_link_types,
|
||||||
"port_number": self._port_number,
|
"port_number": self._port_number,
|
||||||
"adapter_number": self._adapter_number,
|
"adapter_number": self._adapter_number,
|
||||||
"link_type": self.linkType().lower()
|
"link_type": self.link_type
|
||||||
}
|
}
|
||||||
|
@ -183,7 +183,7 @@ class DynamipsPortFactory:
|
|||||||
interface_numbers.setdefault(port_class, 0)
|
interface_numbers.setdefault(port_class, 0)
|
||||||
interface_number = interface_numbers[port_class]
|
interface_number = interface_numbers[port_class]
|
||||||
for port_number in range(0, cls.ADAPTER_MATRIX[properties[name]]["nb_ports"]):
|
for port_number in range(0, cls.ADAPTER_MATRIX[properties[name]]["nb_ports"]):
|
||||||
name = "{}{}/{}".format(port_class.longNameType(), interface_number, port_number)
|
name = "{}{}/{}".format(port_class.long_name_type(), interface_number, port_number)
|
||||||
ports.append(port_class(name, interface_number, adapter_number, port_number))
|
ports.append(port_class(name, interface_number, adapter_number, port_number))
|
||||||
interface_numbers[port_class] += 1
|
interface_numbers[port_class] += 1
|
||||||
adapter_number += 1
|
adapter_number += 1
|
||||||
@ -191,7 +191,7 @@ class DynamipsPortFactory:
|
|||||||
port_class = cls.WIC_MATRIX[properties[name]]["port"]
|
port_class = cls.WIC_MATRIX[properties[name]]["port"]
|
||||||
if port_class:
|
if port_class:
|
||||||
for port_number in range(0, cls.WIC_MATRIX[properties[name]]["nb_ports"]):
|
for port_number in range(0, cls.WIC_MATRIX[properties[name]]["nb_ports"]):
|
||||||
name = "{}{}/{}".format(port_class.longNameType(), 0, wic_port_number)
|
name = "{}{}/{}".format(port_class.long_name_type(), 0, wic_port_number)
|
||||||
ports.append(port_class(name, 0, 0, wic_port_number))
|
ports.append(port_class(name, 0, 0, wic_port_number))
|
||||||
wic_port_number += 1
|
wic_port_number += 1
|
||||||
return ports
|
return ports
|
||||||
|
@ -19,43 +19,31 @@
|
|||||||
POS port for Packet over SONET link end points.
|
POS port for Packet over SONET link end points.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from .port import Port
|
from .serial_port import SerialPort
|
||||||
|
|
||||||
|
|
||||||
class POSPort(Port):
|
class POSPort(SerialPort):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def longNameType():
|
def long_name_type():
|
||||||
"""
|
"""
|
||||||
Returns the long name type for this port.
|
Returns the long name type for this port.
|
||||||
|
|
||||||
:returns: string
|
:returns: string
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return "POS"
|
return "POS"
|
||||||
|
|
||||||
@staticmethod
|
@property
|
||||||
def shortNameType():
|
def short_name_type(self):
|
||||||
"""
|
"""
|
||||||
Returns the short name type for this port.
|
Returns the short name type for this port.
|
||||||
|
|
||||||
:returns: string
|
:returns: string
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return "p"
|
return "p"
|
||||||
|
|
||||||
@staticmethod
|
@property
|
||||||
def linkType():
|
def data_link_types(self):
|
||||||
"""
|
|
||||||
Returns the link type to be used to connect this port.
|
|
||||||
|
|
||||||
:returns: string
|
|
||||||
"""
|
|
||||||
|
|
||||||
return "Serial"
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def dataLinkTypes():
|
|
||||||
"""
|
"""
|
||||||
Returns the supported PCAP DLTs.
|
Returns the supported PCAP DLTs.
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ from .port import Port
|
|||||||
class SerialPort(Port):
|
class SerialPort(Port):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def longNameType():
|
def long_name_type():
|
||||||
"""
|
"""
|
||||||
Returns the long name type for this port.
|
Returns the long name type for this port.
|
||||||
|
|
||||||
@ -34,8 +34,8 @@ class SerialPort(Port):
|
|||||||
|
|
||||||
return "Serial"
|
return "Serial"
|
||||||
|
|
||||||
@staticmethod
|
@property
|
||||||
def shortNameType():
|
def short_name_type(self):
|
||||||
"""
|
"""
|
||||||
Returns the short name type for this port.
|
Returns the short name type for this port.
|
||||||
|
|
||||||
@ -44,18 +44,18 @@ class SerialPort(Port):
|
|||||||
|
|
||||||
return "s"
|
return "s"
|
||||||
|
|
||||||
@staticmethod
|
@property
|
||||||
def linkType():
|
def link_type(self):
|
||||||
"""
|
"""
|
||||||
Returns the link type to be used to connect this port.
|
Returns the link type to be used to connect this port.
|
||||||
|
|
||||||
:returns: string
|
:returns: string
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return "Serial"
|
return "serial"
|
||||||
|
|
||||||
@staticmethod
|
@property
|
||||||
def dataLinkTypes():
|
def data_link_types(self):
|
||||||
"""
|
"""
|
||||||
Returns the supported PCAP DLTs.
|
Returns the supported PCAP DLTs.
|
||||||
|
|
||||||
|
@ -75,6 +75,10 @@ LINK_OBJECT_SCHEMA = {
|
|||||||
"capture_file_path": {
|
"capture_file_path": {
|
||||||
"description": "Read only property. The full path of the capture file if capture is running",
|
"description": "Read only property. The full path of the capture file if capture is running",
|
||||||
"type": ["string", "null"]
|
"type": ["string", "null"]
|
||||||
|
},
|
||||||
|
"link_type": {
|
||||||
|
"description": "Type of link",
|
||||||
|
"enum": ["ethernet", "serial"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": ["nodes"],
|
"required": ["nodes"],
|
||||||
|
@ -24,6 +24,8 @@ from unittest.mock import MagicMock
|
|||||||
|
|
||||||
from gns3server.controller.link import Link
|
from gns3server.controller.link import Link
|
||||||
from gns3server.controller.node import Node
|
from gns3server.controller.node import Node
|
||||||
|
from gns3server.controller.ports.ethernet_port import EthernetPort
|
||||||
|
from gns3server.controller.ports.serial_port import SerialPort
|
||||||
from gns3server.controller.compute import Compute
|
from gns3server.controller.compute import Compute
|
||||||
from gns3server.controller.project import Project
|
from gns3server.controller.project import Project
|
||||||
|
|
||||||
@ -43,7 +45,9 @@ def compute():
|
|||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def link(async_run, project, compute):
|
def link(async_run, project, compute):
|
||||||
node1 = Node(project, compute, "node1", node_type="qemu")
|
node1 = Node(project, compute, "node1", node_type="qemu")
|
||||||
|
node1._ports = [EthernetPort("E0", 0, 0, 4)]
|
||||||
node2 = Node(project, compute, "node2", node_type="qemu")
|
node2 = Node(project, compute, "node2", node_type="qemu")
|
||||||
|
node2._ports = [EthernetPort("E0", 0, 1, 3)]
|
||||||
|
|
||||||
link = Link(project)
|
link = Link(project)
|
||||||
link.create = AsyncioMagicMock()
|
link.create = AsyncioMagicMock()
|
||||||
@ -60,6 +64,7 @@ def test_eq(project, link, controller):
|
|||||||
|
|
||||||
def test_add_node(async_run, project, compute):
|
def test_add_node(async_run, project, compute):
|
||||||
node1 = Node(project, compute, "node1", node_type="qemu")
|
node1 = Node(project, compute, "node1", node_type="qemu")
|
||||||
|
node1._ports = [EthernetPort("E0", 0, 0, 4)]
|
||||||
|
|
||||||
link = Link(project)
|
link = Link(project)
|
||||||
link.create = AsyncioMagicMock()
|
link.create = AsyncioMagicMock()
|
||||||
@ -87,6 +92,7 @@ def test_add_node(async_run, project, compute):
|
|||||||
|
|
||||||
# We call link.created only when both side are created
|
# We call link.created only when both side are created
|
||||||
node2 = Node(project, compute, "node2", node_type="qemu")
|
node2 = Node(project, compute, "node2", node_type="qemu")
|
||||||
|
node2._ports = [EthernetPort("E0", 0, 0, 4)]
|
||||||
async_run(link.add_node(node2, 0, 4))
|
async_run(link.add_node(node2, 0, 4))
|
||||||
|
|
||||||
assert link.create.called
|
assert link.create.called
|
||||||
@ -95,7 +101,9 @@ def test_add_node(async_run, project, compute):
|
|||||||
|
|
||||||
def test_add_node_cloud(async_run, project, compute):
|
def test_add_node_cloud(async_run, project, compute):
|
||||||
node1 = Node(project, compute, "node1", node_type="qemu")
|
node1 = Node(project, compute, "node1", node_type="qemu")
|
||||||
|
node1._ports = [EthernetPort("E0", 0, 0, 4)]
|
||||||
node2 = Node(project, compute, "node2", node_type="cloud")
|
node2 = Node(project, compute, "node2", node_type="cloud")
|
||||||
|
node2._ports = [EthernetPort("E0", 0, 0, 4)]
|
||||||
|
|
||||||
link = Link(project)
|
link = Link(project)
|
||||||
link.create = AsyncioMagicMock()
|
link.create = AsyncioMagicMock()
|
||||||
@ -110,7 +118,9 @@ def test_add_node_cloud_to_cloud(async_run, project, compute):
|
|||||||
Cloud to cloud connection is not allowed
|
Cloud to cloud connection is not allowed
|
||||||
"""
|
"""
|
||||||
node1 = Node(project, compute, "node1", node_type="cloud")
|
node1 = Node(project, compute, "node1", node_type="cloud")
|
||||||
|
node1._ports = [EthernetPort("E0", 0, 0, 4)]
|
||||||
node2 = Node(project, compute, "node2", node_type="cloud")
|
node2 = Node(project, compute, "node2", node_type="cloud")
|
||||||
|
node2._ports = [EthernetPort("E0", 0, 0, 4)]
|
||||||
|
|
||||||
link = Link(project)
|
link = Link(project)
|
||||||
link.create = AsyncioMagicMock()
|
link.create = AsyncioMagicMock()
|
||||||
@ -121,9 +131,29 @@ def test_add_node_cloud_to_cloud(async_run, project, compute):
|
|||||||
async_run(link.add_node(node2, 0, 4))
|
async_run(link.add_node(node2, 0, 4))
|
||||||
|
|
||||||
|
|
||||||
def test_json(async_run, project, compute):
|
def test_add_node_serial_to_ethernet(async_run, project, compute):
|
||||||
|
"""
|
||||||
|
Serial to ethernet connection is not allowed
|
||||||
|
"""
|
||||||
node1 = Node(project, compute, "node1", node_type="qemu")
|
node1 = Node(project, compute, "node1", node_type="qemu")
|
||||||
|
node1._ports = [EthernetPort("E0", 0, 0, 4)]
|
||||||
node2 = Node(project, compute, "node2", node_type="qemu")
|
node2 = Node(project, compute, "node2", node_type="qemu")
|
||||||
|
node2._ports = [SerialPort("E0", 0, 0, 4)]
|
||||||
|
|
||||||
|
link = Link(project)
|
||||||
|
link.create = AsyncioMagicMock()
|
||||||
|
link._project.controller.notification.emit = MagicMock()
|
||||||
|
|
||||||
|
async_run(link.add_node(node1, 0, 4))
|
||||||
|
with pytest.raises(aiohttp.web.HTTPConflict):
|
||||||
|
async_run(link.add_node(node2, 0, 4))
|
||||||
|
|
||||||
|
|
||||||
|
def test_json(async_run, project, compute, link):
|
||||||
|
node1 = Node(project, compute, "node1", node_type="qemu")
|
||||||
|
node1._ports = [EthernetPort("E0", 0, 0, 4)]
|
||||||
|
node2 = Node(project, compute, "node2", node_type="qemu")
|
||||||
|
node2._ports = [EthernetPort("E0", 0, 1, 3)]
|
||||||
|
|
||||||
link = Link(project)
|
link = Link(project)
|
||||||
link.create = AsyncioMagicMock()
|
link.create = AsyncioMagicMock()
|
||||||
@ -158,6 +188,7 @@ def test_json(async_run, project, compute):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
"link_type": "ethernet",
|
||||||
"capturing": False,
|
"capturing": False,
|
||||||
"capture_file_name": None,
|
"capture_file_name": None,
|
||||||
"capture_file_path": None
|
"capture_file_path": None
|
||||||
@ -193,6 +224,19 @@ def test_json(async_run, project, compute):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def test_json_serial_link(async_run, project, compute, link):
|
||||||
|
node1 = Node(project, compute, "node1", node_type="qemu")
|
||||||
|
node1._ports = [SerialPort("S0", 0, 0, 4)]
|
||||||
|
node2 = Node(project, compute, "node2", node_type="qemu")
|
||||||
|
node2._ports = [SerialPort("S0", 0, 1, 3)]
|
||||||
|
|
||||||
|
link = Link(project)
|
||||||
|
link.create = AsyncioMagicMock()
|
||||||
|
async_run(link.add_node(node1, 0, 4))
|
||||||
|
async_run(link.add_node(node2, 1, 3))
|
||||||
|
assert link.__json__()["link_type"] == "serial"
|
||||||
|
|
||||||
|
|
||||||
def test_start_streaming_pcap(link, async_run, tmpdir, project):
|
def test_start_streaming_pcap(link, async_run, tmpdir, project):
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def fake_reader():
|
def fake_reader():
|
||||||
@ -212,7 +256,9 @@ def test_start_streaming_pcap(link, async_run, tmpdir, project):
|
|||||||
|
|
||||||
def test_default_capture_file_name(project, compute, async_run):
|
def test_default_capture_file_name(project, compute, async_run):
|
||||||
node1 = Node(project, compute, "Hello@", node_type="qemu")
|
node1 = Node(project, compute, "Hello@", node_type="qemu")
|
||||||
|
node1._ports = [EthernetPort("E0", 0, 0, 4)]
|
||||||
node2 = Node(project, compute, "w0.rld", node_type="qemu")
|
node2 = Node(project, compute, "w0.rld", node_type="qemu")
|
||||||
|
node2._ports = [EthernetPort("E0", 0, 1, 3)]
|
||||||
|
|
||||||
link = Link(project)
|
link = Link(project)
|
||||||
link.create = AsyncioMagicMock()
|
link.create = AsyncioMagicMock()
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import aiohttp
|
||||||
import pytest
|
import pytest
|
||||||
import uuid
|
import uuid
|
||||||
import asyncio
|
import asyncio
|
||||||
@ -420,3 +421,15 @@ def test_update_label(node):
|
|||||||
node.label = {"text": "Wrong", "x": 12}
|
node.label = {"text": "Wrong", "x": 12}
|
||||||
assert node.label["text"] == "Test"
|
assert node.label["text"] == "Test"
|
||||||
assert node.label["x"] == 12
|
assert node.label["x"] == 12
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_port(node):
|
||||||
|
node.properties["adapters"] = 2
|
||||||
|
node._list_ports()
|
||||||
|
port = node.get_port(0, 0)
|
||||||
|
assert port.adapter_number == 0
|
||||||
|
assert port.port_number == 0
|
||||||
|
port = node.get_port(1, 0)
|
||||||
|
assert port.adapter_number == 1
|
||||||
|
with pytest.raises(aiohttp.web.HTTPNotFound):
|
||||||
|
port = node.get_port(42, 0)
|
||||||
|
@ -68,20 +68,25 @@ def test_list_ports_port_name_format(node):
|
|||||||
"""
|
"""
|
||||||
node._first_port_name = None
|
node._first_port_name = None
|
||||||
node._port_name_format = "eth{}"
|
node._port_name_format = "eth{}"
|
||||||
|
node._list_ports()
|
||||||
assert node.__json__()["ports"][0]["name"] == "eth0"
|
assert node.__json__()["ports"][0]["name"] == "eth0"
|
||||||
node._port_name_format = "eth{port0}"
|
node._port_name_format = "eth{port0}"
|
||||||
|
node._list_ports()
|
||||||
assert node.__json__()["ports"][0]["name"] == "eth0"
|
assert node.__json__()["ports"][0]["name"] == "eth0"
|
||||||
node._port_name_format = "eth{port1}"
|
node._port_name_format = "eth{port1}"
|
||||||
|
node._list_ports()
|
||||||
assert node.__json__()["ports"][0]["name"] == "eth1"
|
assert node.__json__()["ports"][0]["name"] == "eth1"
|
||||||
|
|
||||||
node._first_port_name = ""
|
node._first_port_name = ""
|
||||||
node._port_segment_size = 2
|
node._port_segment_size = 2
|
||||||
node._port_name_format = "eth{segment0}/{port0}"
|
node._port_name_format = "eth{segment0}/{port0}"
|
||||||
node.properties["adapters"] = 8
|
node.properties["adapters"] = 8
|
||||||
|
node._list_ports()
|
||||||
assert node.__json__()["ports"][6]["name"] == "eth3/0"
|
assert node.__json__()["ports"][6]["name"] == "eth3/0"
|
||||||
assert node.__json__()["ports"][7]["name"] == "eth3/1"
|
assert node.__json__()["ports"][7]["name"] == "eth3/1"
|
||||||
|
|
||||||
node._first_port_name = "mgnt0"
|
node._first_port_name = "mgnt0"
|
||||||
|
node._list_ports()
|
||||||
assert node.__json__()["ports"][0]["name"] == "mgnt0"
|
assert node.__json__()["ports"][0]["name"] == "mgnt0"
|
||||||
assert node.__json__()["ports"][1]["name"] == "eth0/0"
|
assert node.__json__()["ports"][1]["name"] == "eth0/0"
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ from unittest.mock import patch
|
|||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
from gns3server.controller.project import Project
|
from gns3server.controller.project import Project
|
||||||
|
from gns3server.controller.ports.ethernet_port import EthernetPort
|
||||||
from gns3server.config import Config
|
from gns3server.config import Config
|
||||||
|
|
||||||
|
|
||||||
@ -250,7 +251,9 @@ def test_addLink(async_run, project, controller):
|
|||||||
compute.post = AsyncioMagicMock(return_value=response)
|
compute.post = AsyncioMagicMock(return_value=response)
|
||||||
|
|
||||||
vm1 = async_run(project.add_node(compute, "test1", None, node_type="vpcs", properties={"startup_config": "test.cfg"}))
|
vm1 = async_run(project.add_node(compute, "test1", None, node_type="vpcs", properties={"startup_config": "test.cfg"}))
|
||||||
|
vm1._ports = [EthernetPort("E0", 0, 3, 1)]
|
||||||
vm2 = async_run(project.add_node(compute, "test2", None, node_type="vpcs", properties={"startup_config": "test.cfg"}))
|
vm2 = async_run(project.add_node(compute, "test2", None, node_type="vpcs", properties={"startup_config": "test.cfg"}))
|
||||||
|
vm2._ports = [EthernetPort("E0", 0, 4, 2)]
|
||||||
controller._notification = MagicMock()
|
controller._notification = MagicMock()
|
||||||
link = async_run(project.add_link())
|
link = async_run(project.add_link())
|
||||||
async_run(link.add_node(vm1, 3, 1))
|
async_run(link.add_node(vm1, 3, 1))
|
||||||
|
@ -23,6 +23,7 @@ from tests.utils import asyncio_patch, AsyncioMagicMock
|
|||||||
|
|
||||||
from gns3server.controller.project import Project
|
from gns3server.controller.project import Project
|
||||||
from gns3server.controller.udp_link import UDPLink
|
from gns3server.controller.udp_link import UDPLink
|
||||||
|
from gns3server.controller.ports.ethernet_port import EthernetPort
|
||||||
from gns3server.controller.node import Node
|
from gns3server.controller.node import Node
|
||||||
|
|
||||||
|
|
||||||
@ -36,7 +37,9 @@ def test_create(async_run, project):
|
|||||||
compute2 = MagicMock()
|
compute2 = MagicMock()
|
||||||
|
|
||||||
node1 = Node(project, compute1, "node1", node_type="vpcs")
|
node1 = Node(project, compute1, "node1", node_type="vpcs")
|
||||||
|
node1._ports = [EthernetPort("E0", 0, 0, 4)]
|
||||||
node2 = Node(project, compute2, "node2", node_type="vpcs")
|
node2 = Node(project, compute2, "node2", node_type="vpcs")
|
||||||
|
node2._ports = [EthernetPort("E0", 0, 3, 1)]
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def subnet_callback(compute2):
|
def subnet_callback(compute2):
|
||||||
@ -95,7 +98,9 @@ def test_delete(async_run, project):
|
|||||||
compute2 = MagicMock()
|
compute2 = MagicMock()
|
||||||
|
|
||||||
node1 = Node(project, compute1, "node1", node_type="vpcs")
|
node1 = Node(project, compute1, "node1", node_type="vpcs")
|
||||||
|
node1._ports = [EthernetPort("E0", 0, 0, 4)]
|
||||||
node2 = Node(project, compute2, "node2", node_type="vpcs")
|
node2 = Node(project, compute2, "node2", node_type="vpcs")
|
||||||
|
node2._ports = [EthernetPort("E0", 0, 3, 1)]
|
||||||
|
|
||||||
link = UDPLink(project)
|
link = UDPLink(project)
|
||||||
link.create = AsyncioMagicMock()
|
link.create = AsyncioMagicMock()
|
||||||
@ -117,7 +122,9 @@ def test_choose_capture_side(async_run, project):
|
|||||||
compute2.id = "local"
|
compute2.id = "local"
|
||||||
|
|
||||||
node_vpcs = Node(project, compute1, "node1", node_type="vpcs")
|
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 = Node(project, compute2, "node2", node_type="iou")
|
||||||
|
node_iou._ports = [EthernetPort("E0", 0, 3, 1)]
|
||||||
|
|
||||||
link = UDPLink(project)
|
link = UDPLink(project)
|
||||||
link.create = AsyncioMagicMock()
|
link.create = AsyncioMagicMock()
|
||||||
@ -127,7 +134,9 @@ def test_choose_capture_side(async_run, project):
|
|||||||
assert link._choose_capture_side()["node"] == node_iou
|
assert link._choose_capture_side()["node"] == node_iou
|
||||||
|
|
||||||
node_vpcs = Node(project, compute1, "node3", node_type="vpcs")
|
node_vpcs = Node(project, compute1, "node3", node_type="vpcs")
|
||||||
|
node_vpcs._ports = [EthernetPort("E0", 0, 0, 4)]
|
||||||
node_vpcs2 = Node(project, compute1, "node4", node_type="vpcs")
|
node_vpcs2 = Node(project, compute1, "node4", node_type="vpcs")
|
||||||
|
node_vpcs2._ports = [EthernetPort("E0", 0, 3, 1)]
|
||||||
|
|
||||||
link = UDPLink(project)
|
link = UDPLink(project)
|
||||||
link.create = AsyncioMagicMock()
|
link.create = AsyncioMagicMock()
|
||||||
@ -136,7 +145,9 @@ def test_choose_capture_side(async_run, project):
|
|||||||
|
|
||||||
# Capture should run on the local node
|
# Capture should run on the local node
|
||||||
node_iou = Node(project, compute1, "node5", node_type="iou")
|
node_iou = Node(project, compute1, "node5", node_type="iou")
|
||||||
|
node_iou._ports = [EthernetPort("E0", 0, 0, 4)]
|
||||||
node_iou2 = Node(project, compute2, "node6", node_type="iou")
|
node_iou2 = Node(project, compute2, "node6", node_type="iou")
|
||||||
|
node_iou2._ports = [EthernetPort("E0", 0, 3, 1)]
|
||||||
|
|
||||||
link = UDPLink(project)
|
link = UDPLink(project)
|
||||||
link.create = AsyncioMagicMock()
|
link.create = AsyncioMagicMock()
|
||||||
@ -150,7 +161,9 @@ def test_capture(async_run, project):
|
|||||||
compute1 = MagicMock()
|
compute1 = MagicMock()
|
||||||
|
|
||||||
node_vpcs = Node(project, compute1, "V1", node_type="vpcs")
|
node_vpcs = Node(project, compute1, "V1", node_type="vpcs")
|
||||||
|
node_vpcs._ports = [EthernetPort("E0", 0, 0, 4)]
|
||||||
node_iou = Node(project, compute1, "I1", node_type="iou")
|
node_iou = Node(project, compute1, "I1", node_type="iou")
|
||||||
|
node_iou._ports = [EthernetPort("E0", 0, 3, 1)]
|
||||||
|
|
||||||
link = UDPLink(project)
|
link = UDPLink(project)
|
||||||
link.create = AsyncioMagicMock()
|
link.create = AsyncioMagicMock()
|
||||||
|
@ -31,6 +31,7 @@ from tests.utils import asyncio_patch, AsyncioMagicMock
|
|||||||
|
|
||||||
from gns3server.handlers.api.controller.project_handler import ProjectHandler
|
from gns3server.handlers.api.controller.project_handler import ProjectHandler
|
||||||
from gns3server.controller import Controller
|
from gns3server.controller import Controller
|
||||||
|
from gns3server.controller.ports.ethernet_port import EthernetPort
|
||||||
from gns3server.controller.node import Node
|
from gns3server.controller.node import Node
|
||||||
from gns3server.controller.link import Link
|
from gns3server.controller.link import Link
|
||||||
|
|
||||||
@ -54,7 +55,9 @@ def test_create_link(http_controller, tmpdir, project, compute, async_run):
|
|||||||
compute.post = AsyncioMagicMock(return_value=response)
|
compute.post = AsyncioMagicMock(return_value=response)
|
||||||
|
|
||||||
node1 = async_run(project.add_node(compute, "node1", None, node_type="qemu"))
|
node1 = async_run(project.add_node(compute, "node1", None, node_type="qemu"))
|
||||||
|
node1._ports = [EthernetPort("E0", 0, 0, 3)]
|
||||||
node2 = async_run(project.add_node(compute, "node2", None, node_type="qemu"))
|
node2 = async_run(project.add_node(compute, "node2", None, node_type="qemu"))
|
||||||
|
node2._ports = [EthernetPort("E0", 0, 2, 4)]
|
||||||
|
|
||||||
with asyncio_patch("gns3server.controller.udp_link.UDPLink.create") as mock:
|
with asyncio_patch("gns3server.controller.udp_link.UDPLink.create") as mock:
|
||||||
response = http_controller.post("/projects/{}/links".format(project.id), {
|
response = http_controller.post("/projects/{}/links".format(project.id), {
|
||||||
@ -89,7 +92,9 @@ def test_update_link(http_controller, tmpdir, project, compute, async_run):
|
|||||||
compute.post = AsyncioMagicMock(return_value=response)
|
compute.post = AsyncioMagicMock(return_value=response)
|
||||||
|
|
||||||
node1 = async_run(project.add_node(compute, "node1", None, node_type="qemu"))
|
node1 = async_run(project.add_node(compute, "node1", None, node_type="qemu"))
|
||||||
|
node1._ports = [EthernetPort("E0", 0, 0, 3)]
|
||||||
node2 = async_run(project.add_node(compute, "node2", None, node_type="qemu"))
|
node2 = async_run(project.add_node(compute, "node2", None, node_type="qemu"))
|
||||||
|
node2._ports = [EthernetPort("E0", 0, 2, 4)]
|
||||||
|
|
||||||
with asyncio_patch("gns3server.controller.udp_link.UDPLink.create") as mock:
|
with asyncio_patch("gns3server.controller.udp_link.UDPLink.create") as mock:
|
||||||
response = http_controller.post("/projects/{}/links".format(project.id), {
|
response = http_controller.post("/projects/{}/links".format(project.id), {
|
||||||
@ -142,7 +147,9 @@ def test_list_link(http_controller, tmpdir, project, compute, async_run):
|
|||||||
compute.post = AsyncioMagicMock(return_value=response)
|
compute.post = AsyncioMagicMock(return_value=response)
|
||||||
|
|
||||||
node1 = async_run(project.add_node(compute, "node1", None, node_type="qemu"))
|
node1 = async_run(project.add_node(compute, "node1", None, node_type="qemu"))
|
||||||
|
node1._ports = [EthernetPort("E0", 0, 0, 3)]
|
||||||
node2 = async_run(project.add_node(compute, "node2", None, node_type="qemu"))
|
node2 = async_run(project.add_node(compute, "node2", None, node_type="qemu"))
|
||||||
|
node2._ports = [EthernetPort("E0", 0, 2, 4)]
|
||||||
|
|
||||||
with asyncio_patch("gns3server.controller.udp_link.UDPLink.create") as mock:
|
with asyncio_patch("gns3server.controller.udp_link.UDPLink.create") as mock:
|
||||||
response = http_controller.post("/projects/{}/links".format(project.id), {
|
response = http_controller.post("/projects/{}/links".format(project.id), {
|
||||||
|
Loading…
Reference in New Issue
Block a user