From 5d12a9126837485c60e757c5f1dd06084efe2e8a Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Thu, 15 Sep 2016 11:49:41 +0200 Subject: [PATCH] Fix Serial interface not available for IOU Fix https://github.com/GNS3/gns3-gui/issues/1512 --- gns3server/controller/ports/port_factory.py | 18 +++++++++++----- tests/controller/test_node_port_name.py | 24 ++++++++++----------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/gns3server/controller/ports/port_factory.py b/gns3server/controller/ports/port_factory.py index 58c1c01e..b85ab3bf 100644 --- a/gns3server/controller/ports/port_factory.py +++ b/gns3server/controller/ports/port_factory.py @@ -51,7 +51,7 @@ class StandardPortFactory: """ def __new__(cls, properties, port_by_adapter, first_port_name, port_name_format, port_segment_size): ports = [] - interface_number = segment_number = 0 + adapter_number = interface_number = segment_number = 0 if "serial_adapters" in properties: for adapter_number in range(0, properties["serial_adapters"]): for port_number in range(0, port_by_adapter): @@ -62,22 +62,30 @@ class StandardPortFactory: else: ethernet_adapters = properties.get("adapters", 1) - for adapter_number in range(0, ethernet_adapters): + if len(ports): + adapter_number += 1 + + for adapter_number in range(adapter_number, ethernet_adapters + adapter_number): 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") else: port_name = port_name_format.format( interface_number, segment_number, adapter=adapter_number, **cls._generate_replacement(interface_number, segment_number)) + port = PortFactory(port_name, segment_number, adapter_number, port_number, "ethernet") interface_number += 1 - if port_segment_size and interface_number % port_segment_size == 0: + if port_segment_size: + if interface_number % port_segment_size == 0: + segment_number += 1 + interface_number = 0 + else: segment_number += 1 - interface_number = 0 - ports.append(PortFactory(port_name, adapter_number, adapter_number, port_number, "ethernet")) + ports.append(port) return ports @staticmethod diff --git a/tests/controller/test_node_port_name.py b/tests/controller/test_node_port_name.py index ec43f85a..0e8a855b 100644 --- a/tests/controller/test_node_port_name.py +++ b/tests/controller/test_node_port_name.py @@ -268,7 +268,7 @@ def test_list_ports_iou(compute, project): "short_name": "e0/0", "data_link_types": {"Ethernet": "DLT_EN10MB"}, "port_number": 0, - "adapter_number": 0, + "adapter_number": 2, "link_type": "ethernet" }, { @@ -276,7 +276,7 @@ def test_list_ports_iou(compute, project): "short_name": "e0/1", "data_link_types": {"Ethernet": "DLT_EN10MB"}, "port_number": 1, - "adapter_number": 0, + "adapter_number": 2, "link_type": "ethernet" }, { @@ -284,7 +284,7 @@ def test_list_ports_iou(compute, project): "short_name": "e0/2", "data_link_types": {"Ethernet": "DLT_EN10MB"}, "port_number": 2, - "adapter_number": 0, + "adapter_number": 2, "link_type": "ethernet" }, { @@ -292,7 +292,7 @@ def test_list_ports_iou(compute, project): "short_name": "e0/3", "data_link_types": {"Ethernet": "DLT_EN10MB"}, "port_number": 3, - "adapter_number": 0, + "adapter_number": 2, "link_type": "ethernet" }, { @@ -300,7 +300,7 @@ def test_list_ports_iou(compute, project): "short_name": "e1/0", "data_link_types": {"Ethernet": "DLT_EN10MB"}, "port_number": 0, - "adapter_number": 1, + "adapter_number": 3, "link_type": "ethernet" }, { @@ -308,7 +308,7 @@ def test_list_ports_iou(compute, project): "short_name": "e1/1", "data_link_types": {"Ethernet": "DLT_EN10MB"}, "port_number": 1, - "adapter_number": 1, + "adapter_number": 3, "link_type": "ethernet" }, { @@ -316,7 +316,7 @@ def test_list_ports_iou(compute, project): "short_name": "e1/2", "data_link_types": {"Ethernet": "DLT_EN10MB"}, "port_number": 2, - "adapter_number": 1, + "adapter_number": 3, "link_type": "ethernet" }, { @@ -324,7 +324,7 @@ def test_list_ports_iou(compute, project): "short_name": "e1/3", "data_link_types": {"Ethernet": "DLT_EN10MB"}, "port_number": 3, - "adapter_number": 1, + "adapter_number": 3, "link_type": "ethernet" }, { @@ -332,7 +332,7 @@ def test_list_ports_iou(compute, project): "short_name": "e2/0", "data_link_types": {"Ethernet": "DLT_EN10MB"}, "port_number": 0, - "adapter_number": 2, + "adapter_number": 4, "link_type": "ethernet" }, { @@ -340,7 +340,7 @@ def test_list_ports_iou(compute, project): "short_name": "e2/1", "data_link_types": {"Ethernet": "DLT_EN10MB"}, "port_number": 1, - "adapter_number": 2, + "adapter_number": 4, "link_type": "ethernet" }, { @@ -348,7 +348,7 @@ def test_list_ports_iou(compute, project): "short_name": "e2/2", "data_link_types": {"Ethernet": "DLT_EN10MB"}, "port_number": 2, - "adapter_number": 2, + "adapter_number": 4, "link_type": "ethernet" }, { @@ -356,7 +356,7 @@ def test_list_ports_iou(compute, project): "short_name": "e2/3", "data_link_types": {"Ethernet": "DLT_EN10MB"}, "port_number": 3, - "adapter_number": 2, + "adapter_number": 4, "link_type": "ethernet" } ]