1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-24 09:18:08 +00:00

Fix wrong short label for ethernet switch, hub & VPCS

Fix https://github.com/GNS3/gns3-gui/issues/1764
This commit is contained in:
Julien Duponchelle 2017-01-09 16:48:42 +01:00
parent 2de60ba257
commit 58287b3638
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
4 changed files with 38 additions and 8 deletions

View File

@ -558,10 +558,18 @@ class Node:
elif self._node_type == "dynamips":
self._ports = DynamipsPortFactory(self._properties)
return
elif self._node_type in ("cloud", "nat", "ethernet_switch", "ethernet_hub"):
elif self._node_type in ("ethernet_switch", "ethernet_hub"):
# Basic node we don't want to have adapter number
port_number = 0
for port in self._properties["ports_mapping"]:
self._ports.append(PortFactory(port["name"], 0, 0, port_number, "ethernet"))
self._ports.append(PortFactory(port["name"], 0, 0, port_number, "ethernet", short_name="e{}".format(port_number)))
port_number += 1
elif self._node_type in ("vpcs"):
self._ports.append(PortFactory("Ethernet0", 0, 0, 0, "ethernet", short_name="e0"))
elif self._node_type in ("cloud", "nat"):
port_number = 0
for port in self._properties["ports_mapping"]:
self._ports.append(PortFactory(port["name"], 0, 0, port_number, "ethernet", short_name=port["name"]))
port_number += 1
else:
self._ports = StandardPortFactory(self._properties, self._port_by_adapter, self._first_port_name, self._port_name_format, self._port_segment_size)

View File

@ -21,11 +21,12 @@ class Port:
Base class for port objects.
"""
def __init__(self, name, interface_number, adapter_number, port_number):
def __init__(self, name, interface_number, adapter_number, port_number, short_name=None):
self._interface_number = interface_number
self._adapter_number = adapter_number
self._port_number = port_number
self._name = name
self._short_name = short_name
self._link = None
@property
@ -63,7 +64,9 @@ class Port:
@property
def short_name(self):
# If port name format has change we use the port name as the short name (1.X behavior)
if not self._name.startswith(self.long_name_type()):
if self._short_name:
return self._short_name
elif not self._name.startswith(self.long_name_type()):
return self._name
return self.short_name_type + "{}/{}".format(self._interface_number, self._port_number)

View File

@ -128,7 +128,7 @@ def test_json(node, compute):
"link_type": "ethernet",
"name": "Ethernet0",
"port_number": 0,
"short_name": "e0/0"
"short_name": "e0"
}
]
}
@ -465,6 +465,7 @@ def test_update_label(node):
def test_get_port(node):
node._node_type = "qemu"
node._properties["adapters"] = 2
node._list_ports()
port = node.get_port(0, 0)

View File

@ -41,7 +41,7 @@ def project(controller):
def node(compute, project):
node = Node(project, compute, "demo",
node_id=str(uuid.uuid4()),
node_type="vpcs",
node_type="qemu",
console_type="vnc",
properties={"startup_script": "echo test"})
return node
@ -63,6 +63,23 @@ def test_list_ports(node):
]
def test_list_ports_vpcs(node):
"""
List port by default
"""
node._node_type = "vpcs"
assert node.__json__()["ports"] == [
{
"name": "Ethernet0",
"short_name": "e0",
"data_link_types": {"Ethernet": "DLT_EN10MB"},
"port_number": 0,
"adapter_number": 0,
"link_type": "ethernet"
}
]
def test_list_ports_port_name_format(node):
"""
Support port name format
@ -166,7 +183,7 @@ def test_list_ports_ethernet_hub(project, compute):
assert node.__json__()["ports"] == [
{
"name": "Ethernet0",
"short_name": "e0/0",
"short_name": "e0",
"data_link_types": {"Ethernet": "DLT_EN10MB"},
"port_number": 0,
"adapter_number": 0,
@ -174,7 +191,7 @@ def test_list_ports_ethernet_hub(project, compute):
},
{
"name": "Ethernet1",
"short_name": "e0/1",
"short_name": "e1",
"data_link_types": {"Ethernet": "DLT_EN10MB"},
"port_number": 1,
"adapter_number": 0,
@ -554,5 +571,6 @@ def test_list_ports_dynamips(project, compute):
def test_short_name():
# If no customization of port name format return the default short name
assert EthernetPort("Ethernet0", 0, 0, 0).short_name == "e0/0"
assert EthernetPort("Ethernet0", 0, 0, 0, short_name="mgmt").short_name == "mgmt"
# If port name format has change we use the port name as the short name (1.X behavior)
assert EthernetPort("eth0", 0, 0, 0).short_name == "eth0"