Skip to content

Commit 19846be

Browse files
mykolafliat-grozovik
authored andcommitted
[minigraph.py] generate port description for every port (#2395)
* [minigraph.py] generate mandatory default port description Signed-off-by: Mykola Faryma <[email protected]> * use port name as default description * [config-engine] update test exaple output Signed-off-by: Mykola Faryma <[email protected]> * [minigraph.py] use alias/port name as default description instead of neighbor data Signed-off-by: Mykola Faryma <[email protected]>
1 parent 982eddf commit 19846be

File tree

3 files changed

+41
-34
lines changed

3 files changed

+41
-34
lines changed

src/sonic-config-engine/minigraph.py

+6
Original file line numberDiff line numberDiff line change
@@ -530,13 +530,19 @@ def parse_xml(filename, platform=None, port_config_file=None):
530530
if port.get('speed') == '100000':
531531
port['fec'] = 'rs'
532532

533+
# set port description if parsed from deviceinfo
533534
for port_name in port_descriptions:
534535
# ignore port not in port_config.ini
535536
if not ports.has_key(port_name):
536537
continue
537538

538539
ports.setdefault(port_name, {})['description'] = port_descriptions[port_name]
539540

541+
# for the ports w/o description set it to alias, or port name
542+
for port_name, port in ports.items():
543+
if not port.get('description'):
544+
port['description'] = port.get('alias', port_name)
545+
540546
# set default port MTU as 9100
541547
for port in ports.itervalues():
542548
port['mtu'] = '9100'

src/sonic-config-engine/tests/sample_output/ports.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
{
33
"PORT_TABLE:Ethernet0": {
44
"speed": "10000",
5-
"description": ""
5+
"description": "fortyGigE0/0"
66
},
77
"OP": "SET"
88
},
99
{
1010
"PORT_TABLE:Ethernet4": {
1111
"speed": "25000",
12-
"description": ""
12+
"description": "fortyGigE0/4"
1313
},
1414
"OP": "SET"
1515
},

src/sonic-config-engine/tests/test_cfggen.py

+33-32
Original file line numberDiff line numberDiff line change
@@ -177,39 +177,40 @@ def test_minigraph_ethernet_interfaces(self):
177177
def test_minigraph_extra_ethernet_interfaces(self):
178178
argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v "PORT"'
179179
output = self.run_script(argument)
180+
180181
self.assertEqual(output.strip(), \
181-
"{'Ethernet8': {'lanes': '37,38,39,40', 'description': 'Interface description', 'mtu': '9100', 'alias': 'fortyGigE0/8', 'admin_status': 'up', 'speed': '1000'}, "
182-
"'Ethernet0': {'alias': 'fortyGigE0/0', 'admin_status': 'up', 'lanes': '29,30,31,32', 'speed': '10000', 'mtu': '9100'}, "
183-
"'Ethernet4': {'alias': 'fortyGigE0/4', 'admin_status': 'up', 'lanes': '25,26,27,28', 'speed': '25000', 'mtu': '9100'}, "
184-
"'Ethernet108': {'alias': 'fortyGigE0/108', 'lanes': '81,82,83,84', 'mtu': '9100'}, "
185-
"'Ethernet100': {'alias': 'fortyGigE0/100', 'lanes': '125,126,127,128', 'mtu': '9100'}, "
186-
"'Ethernet104': {'alias': 'fortyGigE0/104', 'lanes': '85,86,87,88', 'mtu': '9100'}, "
187-
"'Ethernet68': {'alias': 'fortyGigE0/68', 'lanes': '69,70,71,72', 'mtu': '9100'}, "
188-
"'Ethernet96': {'alias': 'fortyGigE0/96', 'lanes': '121,122,123,124', 'mtu': '9100'}, "
189-
"'Ethernet124': {'alias': 'fortyGigE0/124', 'lanes': '101,102,103,104', 'mtu': '9100'}, "
190-
"'Ethernet92': {'alias': 'fortyGigE0/92', 'lanes': '113,114,115,116', 'mtu': '9100'}, "
191-
"'Ethernet120': {'alias': 'fortyGigE0/120', 'lanes': '97,98,99,100', 'mtu': '9100'}, "
192-
"'Ethernet52': {'alias': 'fortyGigE0/52', 'lanes': '53,54,55,56', 'mtu': '9100'}, "
193-
"'Ethernet56': {'alias': 'fortyGigE0/56', 'lanes': '61,62,63,64', 'mtu': '9100'}, "
194-
"'Ethernet76': {'alias': 'fortyGigE0/76', 'lanes': '73,74,75,76', 'mtu': '9100'}, "
195-
"'Ethernet72': {'alias': 'fortyGigE0/72', 'lanes': '77,78,79,80', 'mtu': '9100'}, "
196-
"'Ethernet64': {'alias': 'fortyGigE0/64', 'lanes': '65,66,67,68', 'mtu': '9100'}, "
197-
"'Ethernet32': {'alias': 'fortyGigE0/32', 'lanes': '9,10,11,12', 'mtu': '9100'}, "
198-
"'Ethernet16': {'alias': 'fortyGigE0/16', 'lanes': '41,42,43,44', 'mtu': '9100'}, "
199-
"'Ethernet36': {'alias': 'fortyGigE0/36', 'lanes': '13,14,15,16', 'mtu': '9100'}, "
200-
"'Ethernet12': {'lanes': '33,34,35,36', 'description': 'Interface description', 'mtu': '9100', 'alias': 'fortyGigE0/12', 'speed': '100000', 'fec': 'rs'}, "
201-
"'Ethernet88': {'alias': 'fortyGigE0/88', 'lanes': '117,118,119,120', 'mtu': '9100'}, "
202-
"'Ethernet116': {'alias': 'fortyGigE0/116', 'lanes': '93,94,95,96', 'mtu': '9100'}, "
203-
"'Ethernet80': {'alias': 'fortyGigE0/80', 'lanes': '105,106,107,108', 'mtu': '9100'}, "
204-
"'Ethernet112': {'alias': 'fortyGigE0/112', 'lanes': '89,90,91,92', 'mtu': '9100'}, "
205-
"'Ethernet84': {'alias': 'fortyGigE0/84', 'lanes': '109,110,111,112', 'mtu': '9100'}, "
206-
"'Ethernet48': {'alias': 'fortyGigE0/48', 'lanes': '49,50,51,52', 'mtu': '9100'}, "
207-
"'Ethernet44': {'alias': 'fortyGigE0/44', 'lanes': '17,18,19,20', 'mtu': '9100'}, "
208-
"'Ethernet40': {'alias': 'fortyGigE0/40', 'lanes': '21,22,23,24', 'mtu': '9100'}, "
209-
"'Ethernet28': {'alias': 'fortyGigE0/28', 'lanes': '1,2,3,4', 'mtu': '9100'}, "
210-
"'Ethernet60': {'alias': 'fortyGigE0/60', 'lanes': '57,58,59,60', 'mtu': '9100'}, "
211-
"'Ethernet20': {'alias': 'fortyGigE0/20', 'lanes': '45,46,47,48', 'mtu': '9100'}, "
212-
"'Ethernet24': {'alias': 'fortyGigE0/24', 'lanes': '5,6,7,8', 'mtu': '9100'}}")
182+
"{'Ethernet8': {'lanes': '37,38,39,40', 'description': 'Interface description', 'mtu': '9100', 'alias': 'fortyGigE0/8', 'admin_status': 'up', 'speed': '1000'}, "
183+
"'Ethernet0': {'lanes': '29,30,31,32', 'description': 'fortyGigE0/0', 'mtu': '9100', 'alias': 'fortyGigE0/0', 'admin_status': 'up', 'speed': '10000'}, "
184+
"'Ethernet4': {'lanes': '25,26,27,28', 'description': 'fortyGigE0/4', 'mtu': '9100', 'alias': 'fortyGigE0/4', 'admin_status': 'up', 'speed': '25000'}, "
185+
"'Ethernet108': {'alias': 'fortyGigE0/108', 'lanes': '81,82,83,84', 'description': 'fortyGigE0/108', 'mtu': '9100'}, "
186+
"'Ethernet100': {'alias': 'fortyGigE0/100', 'lanes': '125,126,127,128', 'description': 'fortyGigE0/100', 'mtu': '9100'}, "
187+
"'Ethernet104': {'alias': 'fortyGigE0/104', 'lanes': '85,86,87,88', 'description': 'fortyGigE0/104', 'mtu': '9100'}, "
188+
"'Ethernet68': {'alias': 'fortyGigE0/68', 'lanes': '69,70,71,72', 'description': 'fortyGigE0/68', 'mtu': '9100'}, "
189+
"'Ethernet96': {'alias': 'fortyGigE0/96', 'lanes': '121,122,123,124', 'description': 'fortyGigE0/96', 'mtu': '9100'}, "
190+
"'Ethernet124': {'alias': 'fortyGigE0/124', 'lanes': '101,102,103,104', 'description': 'fortyGigE0/124', 'mtu': '9100'}, "
191+
"'Ethernet92': {'alias': 'fortyGigE0/92', 'lanes': '113,114,115,116', 'description': 'fortyGigE0/92', 'mtu': '9100'}, "
192+
"'Ethernet120': {'alias': 'fortyGigE0/120', 'lanes': '97,98,99,100', 'description': 'fortyGigE0/120', 'mtu': '9100'}, "
193+
"'Ethernet52': {'alias': 'fortyGigE0/52', 'lanes': '53,54,55,56', 'description': 'fortyGigE0/52', 'mtu': '9100'}, "
194+
"'Ethernet56': {'alias': 'fortyGigE0/56', 'lanes': '61,62,63,64', 'description': 'fortyGigE0/56', 'mtu': '9100'}, "
195+
"'Ethernet76': {'alias': 'fortyGigE0/76', 'lanes': '73,74,75,76', 'description': 'fortyGigE0/76', 'mtu': '9100'}, "
196+
"'Ethernet72': {'alias': 'fortyGigE0/72', 'lanes': '77,78,79,80', 'description': 'fortyGigE0/72', 'mtu': '9100'}, "
197+
"'Ethernet64': {'alias': 'fortyGigE0/64', 'lanes': '65,66,67,68', 'description': 'fortyGigE0/64', 'mtu': '9100'}, "
198+
"'Ethernet32': {'alias': 'fortyGigE0/32', 'lanes': '9,10,11,12', 'description': 'fortyGigE0/32', 'mtu': '9100'}, "
199+
"'Ethernet16': {'alias': 'fortyGigE0/16', 'lanes': '41,42,43,44', 'description': 'fortyGigE0/16', 'mtu': '9100'}, "
200+
"'Ethernet36': {'alias': 'fortyGigE0/36', 'lanes': '13,14,15,16', 'description': 'fortyGigE0/36', 'mtu': '9100'}, "
201+
"'Ethernet12': {'lanes': '33,34,35,36', 'description': 'Interface description', 'mtu': '9100', 'alias': 'fortyGigE0/12', 'speed': '100000', 'fec': 'rs'}, "
202+
"'Ethernet88': {'alias': 'fortyGigE0/88', 'lanes': '117,118,119,120', 'description': 'fortyGigE0/88', 'mtu': '9100'}, "
203+
"'Ethernet116': {'alias': 'fortyGigE0/116', 'lanes': '93,94,95,96', 'description': 'fortyGigE0/116', 'mtu': '9100'}, "
204+
"'Ethernet80': {'alias': 'fortyGigE0/80', 'lanes': '105,106,107,108', 'description': 'fortyGigE0/80', 'mtu': '9100'}, "
205+
"'Ethernet112': {'alias': 'fortyGigE0/112', 'lanes': '89,90,91,92', 'description': 'fortyGigE0/112', 'mtu': '9100'}, "
206+
"'Ethernet84': {'alias': 'fortyGigE0/84', 'lanes': '109,110,111,112', 'description': 'fortyGigE0/84', 'mtu': '9100'}, "
207+
"'Ethernet48': {'alias': 'fortyGigE0/48', 'lanes': '49,50,51,52', 'description': 'fortyGigE0/48', 'mtu': '9100'}, "
208+
"'Ethernet44': {'alias': 'fortyGigE0/44', 'lanes': '17,18,19,20', 'description': 'fortyGigE0/44', 'mtu': '9100'}, "
209+
"'Ethernet40': {'alias': 'fortyGigE0/40', 'lanes': '21,22,23,24', 'description': 'fortyGigE0/40', 'mtu': '9100'}, "
210+
"'Ethernet28': {'alias': 'fortyGigE0/28', 'lanes': '1,2,3,4', 'description': 'fortyGigE0/28', 'mtu': '9100'}, "
211+
"'Ethernet60': {'alias': 'fortyGigE0/60', 'lanes': '57,58,59,60', 'description': 'fortyGigE0/60', 'mtu': '9100'}, "
212+
"'Ethernet20': {'alias': 'fortyGigE0/20', 'lanes': '45,46,47,48', 'description': 'fortyGigE0/20', 'mtu': '9100'}, "
213+
"'Ethernet24': {'alias': 'fortyGigE0/24', 'lanes': '5,6,7,8', 'description': 'fortyGigE0/24', 'mtu': '9100'}}")
213214

214215
def test_metadata_everflow(self):
215216
argument = '-m "' + self.sample_graph_metadata + '" -p "' + self.port_config + '" -v "MIRROR_SESSION"'

0 commit comments

Comments
 (0)