From 1bf54bcaeb7c14b8a711172e58765e297f5765a5 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Wed, 11 Jan 2017 18:38:28 +0100 Subject: [PATCH] Fix Port labels for docker VMs incorrect --- gns3server/controller/node.py | 4 +++- tests/controller/test_node_port_name.py | 26 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/gns3server/controller/node.py b/gns3server/controller/node.py index dd794858..9b330cf2 100644 --- a/gns3server/controller/node.py +++ b/gns3server/controller/node.py @@ -558,6 +558,9 @@ class Node: elif self._node_type == "dynamips": self._ports = DynamipsPortFactory(self._properties) return + elif self._node_type == "docker": + for adapter_number in range(0, self._properties["adapters"]): + self._ports.append(PortFactory("eth{}".format(adapter_number), 0, adapter_number, 0, "ethernet", short_name="eth{}".format(adapter_number))) elif self._node_type in ("ethernet_switch", "ethernet_hub"): # Basic node we don't want to have adapter number port_number = 0 @@ -573,7 +576,6 @@ class Node: 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) - return def __repr__(self): return "".format(self._node_type, self._name) diff --git a/tests/controller/test_node_port_name.py b/tests/controller/test_node_port_name.py index 36c3c511..8d0ccc64 100644 --- a/tests/controller/test_node_port_name.py +++ b/tests/controller/test_node_port_name.py @@ -80,6 +80,32 @@ def test_list_ports_vpcs(node): ] +def test_list_ports_docker(node): + """ + List port by default + """ + node._node_type = "docker" + node._properties["adapters"] = 2 + assert node.__json__()["ports"] == [ + { + "name": "eth0", + "short_name": "eth0", + "data_link_types": {"Ethernet": "DLT_EN10MB"}, + "port_number": 0, + "adapter_number": 0, + "link_type": "ethernet" + }, + { + "name": "eth1", + "short_name": "eth1", + "data_link_types": {"Ethernet": "DLT_EN10MB"}, + "port_number": 0, + "adapter_number": 1, + "link_type": "ethernet" + } + ] + + def test_list_ports_port_name_format(node): """ Support port name format