Skip to content

Commit 2d54d43

Browse files
authored
[minigraph]: ignore minigraph ports which are not in port_config.ini (#1593)
Signed-off-by: Guohan Lu <[email protected]>
1 parent 622d357 commit 2d54d43

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

src/sonic-config-engine/minigraph.py

+8
Original file line numberDiff line numberDiff line change
@@ -439,10 +439,18 @@ def parse_xml(filename, platform=None, port_config_file=None):
439439
results['PORTCHANNEL_INTERFACE'] = pc_intfs
440440

441441
for port_name in port_speeds:
442+
# ignore port not in port_config.ini
443+
if not ports.has_key(port_name):
444+
continue
445+
442446
ports.setdefault(port_name, {})['speed'] = port_speeds[port_name]
443447
if port_speeds[port_name] == '100000':
444448
ports.setdefault(port_name, {})['fec'] = 'rs'
445449
for port_name in port_descriptions:
450+
# ignore port not in port_config.ini
451+
if not ports.has_key(port_name):
452+
continue
453+
446454
ports.setdefault(port_name, {})['description'] = port_descriptions[port_name]
447455

448456
results['PORT'] = ports

src/sonic-config-engine/tests/simple-sample-graph.xml

+13
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,19 @@
222222
<Priority>0</Priority>
223223
<Speed>10000</Speed>
224224
</a:EthernetInterface>
225+
<a:EthernetInterface>
226+
<ElementType>DeviceInterface</ElementType>
227+
<AlternateSpeeds i:nil="true"/>
228+
<EnableAutoNegotiation>true</EnableAutoNegotiation>
229+
<EnableFlowControl>true</EnableFlowControl>
230+
<Index>1</Index>
231+
<InterfaceName>fortyGigE0/1</InterfaceName>
232+
<InterfaceType i:nil="true"/>
233+
<MultiPortsInterface>false</MultiPortsInterface>
234+
<PortName>0</PortName>
235+
<Priority>0</Priority>
236+
<Speed>10000</Speed>
237+
</a:EthernetInterface>
225238
<a:EthernetInterface>
226239
<ElementType>DeviceInterface</ElementType>
227240
<AlternateSpeeds i:nil="true"/>

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

+37
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,43 @@ def test_minigraph_ethernet_interfaces(self):
153153
output = self.run_script(argument)
154154
self.assertEqual(output.strip(), "{'alias': 'fortyGigE0/12', 'lanes': '33,34,35,36', 'fec': 'rs', 'speed': '100000', 'description': 'Interface description'}")
155155

156+
def test_minigraph_extra_ethernet_interfaces(self):
157+
argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v "PORT"'
158+
output = self.run_script(argument)
159+
self.assertEqual(output.strip(), \
160+
"{'Ethernet8': {'alias': 'fortyGigE0/8', 'lanes': '37,38,39,40', 'description': 'Interface description', 'speed': '40000'}, "
161+
"'Ethernet0': {'alias': 'fortyGigE0/0', 'lanes': '29,30,31,32', 'speed': '10000'}, "
162+
"'Ethernet4': {'alias': 'fortyGigE0/4', 'lanes': '25,26,27,28', 'speed': '25000'}, "
163+
"'Ethernet108': {'alias': 'fortyGigE0/108', 'lanes': '81,82,83,84'}, "
164+
"'Ethernet100': {'alias': 'fortyGigE0/100', 'lanes': '125,126,127,128'}, "
165+
"'Ethernet104': {'alias': 'fortyGigE0/104', 'lanes': '85,86,87,88'}, "
166+
"'Ethernet68': {'alias': 'fortyGigE0/68', 'lanes': '69,70,71,72'}, "
167+
"'Ethernet96': {'alias': 'fortyGigE0/96', 'lanes': '121,122,123,124'}, "
168+
"'Ethernet124': {'alias': 'fortyGigE0/124', 'lanes': '101,102,103,104'}, "
169+
"'Ethernet92': {'alias': 'fortyGigE0/92', 'lanes': '113,114,115,116'}, "
170+
"'Ethernet120': {'alias': 'fortyGigE0/120', 'lanes': '97,98,99,100'}, "
171+
"'Ethernet52': {'alias': 'fortyGigE0/52', 'lanes': '53,54,55,56'}, "
172+
"'Ethernet56': {'alias': 'fortyGigE0/56', 'lanes': '61,62,63,64'}, "
173+
"'Ethernet76': {'alias': 'fortyGigE0/76', 'lanes': '73,74,75,76'}, "
174+
"'Ethernet72': {'alias': 'fortyGigE0/72', 'lanes': '77,78,79,80'}, "
175+
"'Ethernet64': {'alias': 'fortyGigE0/64', 'lanes': '65,66,67,68'}, "
176+
"'Ethernet32': {'alias': 'fortyGigE0/32', 'lanes': '9,10,11,12'}, "
177+
"'Ethernet16': {'alias': 'fortyGigE0/16', 'lanes': '41,42,43,44'}, "
178+
"'Ethernet36': {'alias': 'fortyGigE0/36', 'lanes': '13,14,15,16'}, "
179+
"'Ethernet12': {'alias': 'fortyGigE0/12', 'lanes': '33,34,35,36', 'fec': 'rs', 'speed': '100000', 'description': 'Interface description'}, "
180+
"'Ethernet88': {'alias': 'fortyGigE0/88', 'lanes': '117,118,119,120'}, "
181+
"'Ethernet116': {'alias': 'fortyGigE0/116', 'lanes': '93,94,95,96'}, "
182+
"'Ethernet80': {'alias': 'fortyGigE0/80', 'lanes': '105,106,107,108'}, "
183+
"'Ethernet112': {'alias': 'fortyGigE0/112', 'lanes': '89,90,91,92'}, "
184+
"'Ethernet84': {'alias': 'fortyGigE0/84', 'lanes': '109,110,111,112'}, "
185+
"'Ethernet48': {'alias': 'fortyGigE0/48', 'lanes': '49,50,51,52'}, "
186+
"'Ethernet44': {'alias': 'fortyGigE0/44', 'lanes': '17,18,19,20'}, "
187+
"'Ethernet40': {'alias': 'fortyGigE0/40', 'lanes': '21,22,23,24'}, "
188+
"'Ethernet28': {'alias': 'fortyGigE0/28', 'lanes': '1,2,3,4'}, "
189+
"'Ethernet60': {'alias': 'fortyGigE0/60', 'lanes': '57,58,59,60'}, "
190+
"'Ethernet20': {'alias': 'fortyGigE0/20', 'lanes': '45,46,47,48'}, "
191+
"'Ethernet24': {'alias': 'fortyGigE0/24', 'lanes': '5,6,7,8'}}")
192+
156193
def test_metadata_everflow(self):
157194
argument = '-m "' + self.sample_graph_metadata + '" -p "' + self.port_config + '" -v "MIRROR_SESSION"'
158195
output = self.run_script(argument)

0 commit comments

Comments
 (0)