Skip to content

Commit c633170

Browse files
authored
fix portconfig script (sonic-net#50)
Signed-off-by: Sangita Maity <[email protected]>
1 parent d069a71 commit c633170

File tree

2 files changed

+18
-48
lines changed

2 files changed

+18
-48
lines changed

src/sonic-config-engine/portconfig.py

+16-47
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,15 @@ def get_child_ports(interface, breakout_mode, platform_json_file):
213213
alias_at_lanes = port_dict[INTF_KEY][interface]['alias_at_lanes']
214214
lanes = port_dict[INTF_KEY][interface]['lanes']
215215

216+
"""
217+
Example of match_list for some breakout_mode using regex
218+
Breakout Mode -------> Match_list
219+
-----------------------------
220+
2x25G(2)+1x50G(2) ---> [('2', '25G', None, '(2)', '2'), ('1', '50G', None, '(2)', '2')]
221+
1x50G(2)+2x25G(2) ---> [('1', '50G', None, '(2)', '2'), ('2', '25G', None, '(2)', '2')]
222+
1x100G[40G] ---------> [('1', '100G', '[40G]', None, None)]
223+
2x50G ---------------> [('2', '50G', None, None, None)]
224+
"""
216225
# Asymmetric breakout mode
217226
if re.search("\+",breakout_mode) is not None:
218227
breakout_parts = breakout_mode.split("+")
@@ -228,11 +237,11 @@ def get_child_ports(interface, breakout_mode, platform_json_file):
228237
offset = gen_port_config(child_ports, parent_intf_id, index, alias_at_lanes, lanes, k, offset)
229238
return child_ports
230239

231-
def parse_platform_json_file(hwsku_json_file, port_config_file, interface_name=None, target_brkout_mode=None):
240+
def parse_platform_json_file(hwsku_json_file, platform_json_file):
232241
ports = {}
233242
port_alias_map = {}
234243

235-
port_dict = readJson(port_config_file)
244+
port_dict = readJson(platform_json_file)
236245
hwsku_dict = readJson(hwsku_json_file)
237246

238247
if not port_dict:
@@ -246,53 +255,13 @@ def parse_platform_json_file(hwsku_json_file, port_config_file, interface_name=N
246255
for intf in port_dict[INTF_KEY]:
247256
if intf not in hwsku_dict[INTF_KEY]:
248257
raise Exception("{} is not available in hwsku_dict".format(intf))
249-
if str(interface_name) == intf:
250-
brkout_mode = target_brkout_mode
251-
else:
252-
brkout_mode = hwsku_dict[INTF_KEY][intf][BRKOUT_MODE]
253258

254-
index = port_dict[INTF_KEY][intf]['index']
255-
alias_at_lanes = port_dict[INTF_KEY][intf]['alias_at_lanes']
256-
lanes = port_dict[INTF_KEY][intf]['lanes']
259+
# take default_brkout_mode from hwsku.json
260+
brkout_mode = hwsku_dict[INTF_KEY][intf][BRKOUT_MODE]
257261

258-
# if User does not specify brkout_mode, take default_brkout_mode from hwsku.json
259-
if brkout_mode is None:
260-
brkout_mode = hwsku_dict[INTF_KEY][intf][BRKOUT_MODE]
262+
child_ports = get_child_ports(intf, brkout_mode, platform_json_file)
263+
ports.update(child_ports)
261264

262-
# Get match_list for Asymmetric breakout mode
263-
if re.search("\+",brkout_mode) is not None:
264-
brkout_parts = brkout_mode.split("+")
265-
match_list = [re.match(BRKOUT_PATTERN, i).groups() for i in brkout_parts]
266-
267-
# Get match_list for Symmetric breakout mode
268-
else:
269-
match_list = [re.match(BRKOUT_PATTERN, brkout_mode).groups()]
270-
271-
"""
272-
Example of match_list for some breakout_mode using regex
273-
Breakout Mode -------> Match_list
274-
-----------------------------
275-
2x25G(2)+1x50G(2) ---> [('2', '25G', None, '(2)', '2'), ('1', '50G', None, '(2)', '2')]
276-
1x50G(2)+2x25G(2) ---> [('1', '50G', None, '(2)', '2'), ('2', '25G', None, '(2)', '2')]
277-
1x100G[40G] ---------> [('1', '100G', '[40G]', None, None)]
278-
2x50G ---------------> [('2', '50G', None, None, None)]
279-
"""
280-
if match_list is not None:
281-
offset = 0
282-
parent_intf_id = int(re.search("Ethernet(\d+)", intf).group(1))
283-
284-
if interface_name is not None and interface_name == intf:
285-
ports = {}
286-
287-
for k in match_list:
288-
# k is a tuple in "match_list"
289-
offset = gen_port_config(ports, parent_intf_id, index, alias_at_lanes, lanes, k, offset)
290-
brkout_mode = None
291-
292-
if interface_name is not None and interface_name == intf:
293-
return ports
294-
else:
295-
raise Exception("match_list should not be None.")
296265
if not ports:
297266
raise Exception("Ports dictionary is empty")
298267

@@ -323,7 +292,7 @@ def parse_breakout_mode(hwsku_json_file):
323292
if INTF_KEY not in hwsku_dict:
324293
raise Exception("INTF_KEY is not present in hwsku_dict")
325294

326-
for intf in hwsku_dict:
295+
for intf in hwsku_dict[INTF_KEY]:
327296
brkout_table[intf] = {}
328297
brkout_table[intf][CUR_BRKOUT_MODE] = hwsku_dict[INTF_KEY][intf][BRKOUT_MODE]
329298
return brkout_table

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ def test_platform_json_interfaces_keys(self):
4545
argument = '-m "' + self.sample_graph_simple + '" -p "' + self.platform_json + '" -S "' + self.hwsku_json + '" -v "PORT.keys()"'
4646
output = self.run_script(argument)
4747
expected = "['Ethernet8', 'Ethernet9', 'Ethernet36', 'Ethernet98', 'Ethernet0', 'Ethernet6', 'Ethernet4', 'Ethernet109', 'Ethernet108', 'Ethernet18', 'Ethernet100', 'Ethernet34', 'Ethernet104', 'Ethernet106', 'Ethernet94', 'Ethernet126', 'Ethernet96', 'Ethernet124', 'Ethernet90', 'Ethernet91', 'Ethernet92', 'Ethernet93', 'Ethernet50', 'Ethernet51', 'Ethernet52', 'Ethernet53', 'Ethernet54', 'Ethernet99', 'Ethernet56', 'Ethernet113', 'Ethernet76', 'Ethernet74', 'Ethernet39', 'Ethernet72', 'Ethernet73', 'Ethernet70', 'Ethernet71', 'Ethernet32', 'Ethernet33', 'Ethernet16', 'Ethernet111', 'Ethernet10', 'Ethernet11', 'Ethernet12', 'Ethernet13', 'Ethernet58', 'Ethernet19', 'Ethernet59', 'Ethernet38', 'Ethernet78', 'Ethernet68', 'Ethernet14', 'Ethernet89', 'Ethernet88', 'Ethernet118', 'Ethernet119', 'Ethernet116', 'Ethernet114', 'Ethernet80', 'Ethernet112', 'Ethernet86', 'Ethernet110', 'Ethernet84', 'Ethernet31', 'Ethernet49', 'Ethernet48', 'Ethernet46', 'Ethernet30', 'Ethernet29', 'Ethernet40', 'Ethernet120', 'Ethernet28', 'Ethernet66', 'Ethernet60', 'Ethernet64', 'Ethernet44', 'Ethernet20', 'Ethernet79', 'Ethernet69', 'Ethernet24', 'Ethernet26']"
48-
self.assertEqual(output.strip(), expected)
48+
49+
self.assertEqual(sorted(output.strip()), sorted(expected))
4950

5051
# Check specific Interface with it's proper configuration as per platform.json
5152
def test_platform_json_specific_ethernet_interfaces(self):

0 commit comments

Comments
 (0)