From bd0d04cb89cf8002a7d3a95f8e10483fb0debd3b Mon Sep 17 00:00:00 2001 From: Rodny Molina Date: Fri, 1 Dec 2017 23:38:15 -0800 Subject: [PATCH 1/3] Final code-drop for interface-description and interface-status enhancements. Here i'm adding minor extensions to support "show interface description" command. Please refer to PR#158 for more details: https://github.com/Azure/sonic-utilities/pull/158 --- dockers/docker-orchagent/ports.json.j2 | 1 + src/sonic-config-engine/minigraph.py | 15 +++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/dockers/docker-orchagent/ports.json.j2 b/dockers/docker-orchagent/ports.json.j2 index 48be831025f8..770440036058 100644 --- a/dockers/docker-orchagent/ports.json.j2 +++ b/dockers/docker-orchagent/ports.json.j2 @@ -5,6 +5,7 @@ { "PORT_TABLE:{{ port }}": { "speed": "{{ PORT[port]['speed'] }}" + "description": "{{ PORT[port]['description'] }}" }, "OP": "SET" }{% if not loop.last %},{% endif %} diff --git a/src/sonic-config-engine/minigraph.py b/src/sonic-config-engine/minigraph.py index 826997063349..d5a474a5abb3 100644 --- a/src/sonic-config-engine/minigraph.py +++ b/src/sonic-config-engine/minigraph.py @@ -298,7 +298,8 @@ def parse_meta(meta, hname): return syslog_servers, dhcp_servers, ntp_servers, mgmt_routes, erspan_dst, deployment_id def parse_deviceinfo(meta, hwsku): - ethernet_interfaces = {} + port_speeds = {} + port_descriptions = {} for device_info in meta.findall(str(QName(ns, "DeviceInfo"))): dev_sku = device_info.find(str(QName(ns, "HwSku"))).text if dev_sku == hwsku: @@ -306,8 +307,10 @@ def parse_deviceinfo(meta, hwsku): for interface in interfaces.findall(str(QName(ns1, "EthernetInterface"))): alias = interface.find(str(QName(ns, "InterfaceName"))).text speed = interface.find(str(QName(ns, "Speed"))).text - ethernet_interfaces[port_alias_map.get(alias, alias)] = speed - return ethernet_interfaces + desc = interface.find(str(QName(ns, "Description"))).text + port_speeds[port_alias_map.get(alias, alias)] = speed + port_descriptions[port_alias_map.get(alias, alias)] = desc + return port_speeds, port_descriptions def parse_xml(filename, platform=None, port_config_file=None): root = ET.parse(filename).getroot() @@ -330,6 +333,7 @@ def parse_xml(filename, platform=None, port_config_file=None): devices = None hostname = None port_speeds = {} + port_descriptions = {} syslog_servers = [] dhcp_servers = [] ntp_servers = [] @@ -360,7 +364,7 @@ def parse_xml(filename, platform=None, port_config_file=None): elif child.tag == str(QName(ns, "MetadataDeclaration")): (syslog_servers, dhcp_servers, ntp_servers, mgmt_routes, erspan_dst, deployment_id) = parse_meta(child, hostname) elif child.tag == str(QName(ns, "DeviceInfos")): - port_speeds = parse_deviceinfo(child, hwsku) + (port_speeds, port_descriptions) = parse_deviceinfo(child, hwsku) results = {} results['DEVICE_METADATA'] = {'localhost': { @@ -395,6 +399,9 @@ def parse_xml(filename, platform=None, port_config_file=None): for port_name in port_speeds: ports.setdefault(port_name, {})['speed'] = port_speeds[port_name] + for port_name in port_descriptions: + ports.setdefault(port_name, {})['description'] = port_descriptions[port_name] + results['PORT'] = ports results['PORTCHANNEL'] = pcs results['VLAN'] = vlans From 85a777c983b08fe1b33fecaf574d972e57567d76 Mon Sep 17 00:00:00 2001 From: Rodny Molina Date: Wed, 6 Dec 2017 00:14:52 -0800 Subject: [PATCH 2/3] Add interface-description UT and adjust logic to have 'description' field being optional RB= G=lnos-reviewers R=ntrianta,rjonnadu,rmolina,sfardeen,zxu A= --- src/sonic-config-engine/minigraph.py | 5 +++-- src/sonic-config-engine/tests/simple-sample-graph.xml | 1 + src/sonic-config-engine/tests/test_cfggen.py | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) mode change 100644 => 100755 src/sonic-config-engine/minigraph.py diff --git a/src/sonic-config-engine/minigraph.py b/src/sonic-config-engine/minigraph.py old mode 100644 new mode 100755 index d5a474a5abb3..f33bd11f0b93 --- a/src/sonic-config-engine/minigraph.py +++ b/src/sonic-config-engine/minigraph.py @@ -307,9 +307,10 @@ def parse_deviceinfo(meta, hwsku): for interface in interfaces.findall(str(QName(ns1, "EthernetInterface"))): alias = interface.find(str(QName(ns, "InterfaceName"))).text speed = interface.find(str(QName(ns, "Speed"))).text - desc = interface.find(str(QName(ns, "Description"))).text + desc = interface.find(str(QName(ns, "Description"))) + if desc != None: + port_descriptions[port_alias_map.get(alias, alias)] = desc.text port_speeds[port_alias_map.get(alias, alias)] = speed - port_descriptions[port_alias_map.get(alias, alias)] = desc return port_speeds, port_descriptions def parse_xml(filename, platform=None, port_config_file=None): diff --git a/src/sonic-config-engine/tests/simple-sample-graph.xml b/src/sonic-config-engine/tests/simple-sample-graph.xml index 89f53af83e41..cce833cc950d 100644 --- a/src/sonic-config-engine/tests/simple-sample-graph.xml +++ b/src/sonic-config-engine/tests/simple-sample-graph.xml @@ -243,6 +243,7 @@ 0 0 40000 + Interface description DeviceInterface diff --git a/src/sonic-config-engine/tests/test_cfggen.py b/src/sonic-config-engine/tests/test_cfggen.py index 47cc006f4662..2eee6fe331c8 100644 --- a/src/sonic-config-engine/tests/test_cfggen.py +++ b/src/sonic-config-engine/tests/test_cfggen.py @@ -138,4 +138,4 @@ def test_minigraph_deployment_id(self): def test_minigraph_ethernet_interfaces(self): argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v "PORT[\'Ethernet8\']"' output = self.run_script(argument) - self.assertEqual(output.strip(), "{'alias': 'fortyGigE0/8', 'lanes': '37,38,39,40', 'speed': '40000'}") + self.assertEqual(output.strip(), "{'alias': 'fortyGigE0/8', 'lanes': '37,38,39,40', 'description': 'Interface description', 'speed': '40000'}") From bf097f5908974bf6c91d8673bf781b69d12b4d3d Mon Sep 17 00:00:00 2001 From: Rodny Molina Date: Wed, 6 Dec 2017 09:52:26 -0800 Subject: [PATCH 3/3] Updating reference to sonic-utilities to collect latest changes --- src/sonic-utilities | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sonic-utilities b/src/sonic-utilities index e87bb97760a4..0c0a2f02c32a 160000 --- a/src/sonic-utilities +++ b/src/sonic-utilities @@ -1 +1 @@ -Subproject commit e87bb97760a4cf069da51b2a0da732f7a40f3215 +Subproject commit 0c0a2f02c32a8cafb3020d8248ea829bbc959d4a