From e5d38811cae6f64d9a149cff68cf2ec99e566d35 Mon Sep 17 00:00:00 2001 From: grossmj Date: Mon, 13 Aug 2018 15:10:21 +0700 Subject: [PATCH 1/2] Fix incorrect short port names in topology summary. Fixes https://github.com/GNS3/gns3-gui/issues/2562 --- gns3server/controller/ports/port.py | 8 ++++---- gns3server/controller/ports/port_factory.py | 6 ++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/gns3server/controller/ports/port.py b/gns3server/controller/ports/port.py index 886973e5..60825b0c 100644 --- a/gns3server/controller/ports/port.py +++ b/gns3server/controller/ports/port.py @@ -63,12 +63,12 @@ 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 port name format has changed we use the port name as the short name (1.X behavior) if self._short_name: return self._short_name - elif not self._name.startswith("{}{}".format(self.long_name_type(), self._interface_number)): - return self._name - return self.short_name_type + "{}/{}".format(self._interface_number, self._port_number) + elif '/' in self._name: + return self.short_name_type + "{}/{}".format(self._interface_number, self._port_number) + return self._name @short_name.setter def short_name(self, val): diff --git a/gns3server/controller/ports/port_factory.py b/gns3server/controller/ports/port_factory.py index 39dac69c..88dfc569 100644 --- a/gns3server/controller/ports/port_factory.py +++ b/gns3server/controller/ports/port_factory.py @@ -64,7 +64,7 @@ class StandardPortFactory: for port_number in range(0, port_by_adapter): if first_port_name and adapter_number == 0: port_name = first_port_name - port = PortFactory(port_name, segment_number, adapter_number, port_number, "ethernet") + port = PortFactory(port_name, segment_number, adapter_number, port_number, "ethernet", short_name=first_port_name) else: try: port_name = port_name_format.format( @@ -190,7 +190,9 @@ class DynamipsPortFactory: if port_class: for port_number in range(0, cls.ADAPTER_MATRIX[properties[name]]["nb_ports"]): name = "{}{}/{}".format(port_class.long_name_type(), adapter_number, port_number) - ports.append(port_class(name, adapter_number, adapter_number, port_number)) + port = port_class(name, adapter_number, adapter_number, port_number) + port.short_name = "{}{}/{}".format(port.short_name_type, adapter_number, port_number) + ports.append(port) adapter_number += 1 elif name.startswith("wic") and properties[name]: port_class = cls.WIC_MATRIX[properties[name]]["port"] From 23e83b730be32710210aca9ff5ad1b80aa298a25 Mon Sep 17 00:00:00 2001 From: grossmj Date: Mon, 13 Aug 2018 15:45:24 +0700 Subject: [PATCH 2/2] Fix some more problems with interface short names. Fixes https://github.com/GNS3/gns3-gui/issues/2562 --- gns3server/controller/ports/port.py | 4 +++- tests/controller/test_node_port_name.py | 9 +++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/gns3server/controller/ports/port.py b/gns3server/controller/ports/port.py index 60825b0c..52b58530 100644 --- a/gns3server/controller/ports/port.py +++ b/gns3server/controller/ports/port.py @@ -67,7 +67,9 @@ class Port: if self._short_name: return self._short_name elif '/' in self._name: - return self.short_name_type + "{}/{}".format(self._interface_number, self._port_number) + return self._name.replace(self.long_name_type(), self.short_name_type) + elif self._name.startswith("{}{}".format(self.long_name_type(), self._interface_number)): + return self.short_name_type + "{}".format(self._interface_number) return self._name @short_name.setter diff --git a/tests/controller/test_node_port_name.py b/tests/controller/test_node_port_name.py index 5da90dc8..55a7a6f2 100644 --- a/tests/controller/test_node_port_name.py +++ b/tests/controller/test_node_port_name.py @@ -54,7 +54,7 @@ def test_list_ports(node): 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, @@ -143,7 +143,7 @@ def test_list_ports_adapters(node): 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, @@ -151,7 +151,7 @@ def test_list_ports_adapters(node): }, { "name": "Ethernet1", - "short_name": "e1/0", + "short_name": "e1", "data_link_types": {"Ethernet": "DLT_EN10MB"}, "port_number": 0, "adapter_number": 1, @@ -596,7 +596,8 @@ 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 == "e0" assert EthernetPort("Ethernet0", 0, 0, 0, short_name="mgmt").short_name == "mgmt" + assert EthernetPort("Ethernet0/0", 0, 0, 0).short_name == "e0/0" # 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"