Skip to content

Commit 3ae87e2

Browse files
Sangita Maitylguohan
authored andcommitted
[dpb|config] Fix the validation logic of breakout mode (sonic-net#1440)
As per latest update in DPB DOC, fixed this bug previously we had string value in "breakout_modes" key so it was not matching the whole string, But after the update via, now "breakout_modes" contain a dictionary where key is the breakout_mode and value is the alias. So we can easily check whether the key is present or not. Signed-off-by: Sangita Maity <[email protected]> Co-authored-by: Guohan Lu <[email protected]>
1 parent 2beab2d commit 3ae87e2

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

config/main.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,8 @@ def _get_breakout_options(ctx, args, incomplete):
114114
else:
115115
breakout_file_input = readJsonFile(breakout_cfg_file)
116116
if interface_name in breakout_file_input[INTF_KEY]:
117-
breakout_mode_list = [v["breakout_modes"] for i, v in breakout_file_input[INTF_KEY].items() if i == interface_name][0]
118-
breakout_mode_options = []
119-
for i in breakout_mode_list.split(','):
120-
breakout_mode_options.append(i)
117+
breakout_mode_options = [mode for i, v in breakout_file_input[INTF_KEY].items() if i == interface_name \
118+
for mode in v["breakout_modes"].keys()]
121119
all_mode_options = [str(c) for c in breakout_mode_options if incomplete in c]
122120
return all_mode_options
123121

@@ -130,7 +128,7 @@ def _validate_interface_mode(ctx, breakout_cfg_file, interface_name, target_brko
130128
return False
131129

132130
# Check whether target breakout mode is available for the user-selected interface or not
133-
if target_brkout_mode not in breakout_file_input[interface_name]["breakout_modes"]:
131+
if target_brkout_mode not in breakout_file_input[interface_name]["breakout_modes"].keys():
134132
click.secho('[ERROR] Target mode {} is not available for the port {}'. format(target_brkout_mode, interface_name), fg='red')
135133
return False
136134

tests/config_dpb_test.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,43 @@
2222
"index": "1,1,1,1",
2323
"lanes": "65,66,67,68",
2424
"alias_at_lanes": "Eth1/1, Eth1/2, Eth1/3, Eth1/4",
25-
"breakout_modes": "1x100G[40G],2x50G,4x25G[10G]"
25+
"breakout_modes": {
26+
"1x100G[40G]": ["Eth1"],
27+
"2x50G": ["Eth1/1", "Eth1/3"],
28+
"4x25G[10G]": ["Eth1/1", "Eth1/2", "Eth1/3", "Eth1/4"]
29+
}
2630
},
2731
"Ethernet4": {
2832
"index": "2,2,2,2",
2933
"lanes": "69,70,71,72",
3034
"alias_at_lanes": "Eth2/1, Eth2/2, Eth2/3, Eth2/4",
31-
"breakout_modes": "1x100G[40G],2x50G,4x25G[10G],1x50G(2)+2x25G(2)"
35+
"breakout_modes": {
36+
"1x100G[40G]": ["Eth2"],
37+
"2x50G": ["Eth2/1", "Eth2/3"],
38+
"4x25G[10G]": ["Eth2/1", "Eth2/2", "Eth2/3", "Eth2/4"],
39+
"1x50G(2)+2x25G(2)": ["Eth2/1", "Eth2/3", "Eth2/4"]
40+
}
3241
},
3342
"Ethernet8": {
3443
"index": "3,3,3,3",
3544
"lanes": "73,74,75,76",
3645
"alias_at_lanes": "Eth3/1, Eth3/2, Eth3/3, Eth3/4",
37-
"breakout_modes": "1x100G[40G],2x50G,4x25G[10G],1x50G(2)+2x25G(2)"
46+
"breakout_modes": {
47+
"1x100G[40G]": ["Eth3"],
48+
"2x50G": ["Eth3/1", "Eth3/3"],
49+
"4x25G[10G]": ["Eth3/1", "Eth3/2", "Eth3/3", "Eth3/4"],
50+
"1x50G(2)+2x25G(2)": ["Eth3/1", "Eth3/3", "Eth3/4"]
51+
}
3852
},
3953
"Ethernet12": {
4054
"index": "4,4,4,4",
4155
"lanes": "77,78,79,80",
4256
"alias_at_lanes": "Eth4/1, Eth4/2, Eth4/3, Eth4/4",
43-
"breakout_modes": "1x100G[40G],2x50G,4x25G[10G]"
57+
"breakout_modes": {
58+
"1x100G[40G]": ["Eth4"],
59+
"2x50G": ["Eth4/1", "Eth4/3"],
60+
"4x25G[10G]": ["Eth4/1", "Eth4/2", "Eth4/3", "Eth4/4"]
61+
}
4462
}
4563
}
4664
}

0 commit comments

Comments
 (0)