Skip to content

Commit 9ab20fd

Browse files
authored
[show][config] fix the muxcable commands for interface naming mode (sonic-net#1862)
This PR fixes the logic to enable alias port usage with muxcable commands. With this PR the user would be able to use this command sudo config interface_naming_mode alias or export SONIC_CLI_IFACE_MODE=alias in the ~/.bashrc and be able to use the naming convention as defined. How I did it Made the changes in show/muxcable.py and config/muxcable.py basically parse the alias/default port if the mode is alias/default to name with no change in internal logic for commands. and display the output back with alias/default Signed-off-by: vaibhav-dahiya <[email protected]>
1 parent 476b3a4 commit 9ab20fd

File tree

4 files changed

+419
-53
lines changed

4 files changed

+419
-53
lines changed

config/muxcable.py

+35-12
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def muxcable():
219219
platform_sfputil = platform_sfputil_helper.platform_sfputil
220220

221221

222-
def lookup_statedb_and_update_configdb(per_npu_statedb, config_db, port, state_cfg_val, port_status_dict):
222+
def lookup_statedb_and_update_configdb(db, per_npu_statedb, config_db, port, state_cfg_val, port_status_dict):
223223

224224
muxcable_statedb_dict = per_npu_statedb.get_all(per_npu_statedb.STATE_DB, 'MUX_CABLE_TABLE|{}'.format(port))
225225
configdb_state = get_value_for_key_in_config_tbl(config_db, port, "state", "MUX_CABLE")
@@ -228,15 +228,17 @@ def lookup_statedb_and_update_configdb(per_npu_statedb, config_db, port, state_c
228228

229229
state = get_value_for_key_in_dict(muxcable_statedb_dict, port, "state", "MUX_CABLE_TABLE")
230230

231+
port_name = platform_sfputil_helper.get_interface_alias(port, db)
232+
231233
if str(state_cfg_val) == str(configdb_state):
232-
port_status_dict[port] = 'OK'
234+
port_status_dict[port_name] = 'OK'
233235
else:
234236
config_db.set_entry("MUX_CABLE", port, {"state": state_cfg_val,
235237
"server_ipv4": ipv4_value, "server_ipv6": ipv6_value})
236238
if (str(state_cfg_val) == 'active' and str(state) != 'active') or (str(state_cfg_val) == 'standby' and str(state) != 'standby'):
237-
port_status_dict[port] = 'INPROGRESS'
239+
port_status_dict[port_name] = 'INPROGRESS'
238240
else:
239-
port_status_dict[port] = 'OK'
241+
port_status_dict[port_name] = 'OK'
240242

241243

242244
# 'muxcable' command ("config muxcable mode <port|all> active|auto")
@@ -248,7 +250,7 @@ def lookup_statedb_and_update_configdb(per_npu_statedb, config_db, port, state_c
248250
def mode(db, state, port, json_output):
249251
"""Config muxcable mode"""
250252

251-
port = platform_sfputil_helper.get_interface_alias(port, db)
253+
port = platform_sfputil_helper.get_interface_name(port, db)
252254

253255
port_table_keys = {}
254256
y_cable_asic_table_keys = {}
@@ -292,7 +294,7 @@ def mode(db, state, port, json_output):
292294
if logical_key in y_cable_asic_table_keys:
293295
port_status_dict = {}
294296
lookup_statedb_and_update_configdb(
295-
per_npu_statedb[asic_index], per_npu_configdb[asic_index], port, state, port_status_dict)
297+
db, per_npu_statedb[asic_index], per_npu_configdb[asic_index], port, state, port_status_dict)
296298

297299
if json_output:
298300
click.echo("{}".format(json.dumps(port_status_dict, indent=4)))
@@ -318,7 +320,7 @@ def mode(db, state, port, json_output):
318320
for key in port_table_keys[asic_id]:
319321
logical_port = key.split("|")[1]
320322
lookup_statedb_and_update_configdb(
321-
per_npu_statedb[asic_id], per_npu_configdb[asic_id], logical_port, state, port_status_dict)
323+
db, per_npu_statedb[asic_id], per_npu_configdb[asic_id], logical_port, state, port_status_dict)
322324

323325
if json_output:
324326
click.echo("{}".format(json.dumps(port_status_dict, indent=4)))
@@ -419,7 +421,7 @@ def hwmode():
419421
def state(db, state, port):
420422
"""Configure the muxcable mux state {active/standby}"""
421423

422-
port = platform_sfputil_helper.get_interface_alias(port, db)
424+
port = platform_sfputil_helper.get_interface_name(port, db)
423425

424426
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_HWMODE_DIR_CMD")
425427
delete_all_keys_in_db_table("STATE_DB", "XCVRD_CONFIG_HWMODE_DIR_RSP")
@@ -437,6 +439,8 @@ def state(db, state, port):
437439
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_HWMODE_DIR_CMD")
438440
delete_all_keys_in_db_table("STATE_DB", "XCVRD_CONFIG_HWMODE_DIR_RSP")
439441

442+
port = platform_sfputil_helper.get_interface_alias(port, db)
443+
440444
if rc == 0:
441445
click.echo("Success in toggling port {} to {}".format(port, state))
442446
else:
@@ -484,6 +488,8 @@ def state(db, state, port):
484488
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_HWMODE_DIR_CMD")
485489
delete_all_keys_in_db_table("STATE_DB", "XCVRD_CONFIG_HWMODE_DIR_RSP")
486490

491+
port = platform_sfputil_helper.get_interface_alias(port, db)
492+
487493
if rc == 0:
488494
click.echo("Success in toggling port {} to {}".format(port, state))
489495
else:
@@ -500,7 +506,7 @@ def state(db, state, port):
500506
def setswitchmode(db, state, port):
501507
"""Configure the muxcable mux switching mode {auto/manual}"""
502508

503-
port = platform_sfputil_helper.get_interface_alias(port, db)
509+
port = platform_sfputil_helper.get_interface_name(port, db)
504510

505511

506512
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_HWMODE_SWMODE_CMD")
@@ -520,6 +526,8 @@ def setswitchmode(db, state, port):
520526
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_HWMODE_SWMODE_CMD")
521527
delete_all_keys_in_db_table("STATE_DB", "XCVRD_CONFIG_HWMODE_SWMODE_RSP")
522528

529+
port = platform_sfputil_helper.get_interface_alias(port, db)
530+
523531
if rc == 0:
524532
click.echo("Success in switch muxcable mode port {} to {}".format(port, state))
525533
else:
@@ -566,6 +574,8 @@ def setswitchmode(db, state, port):
566574
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_HWMODE_SWMODE_CMD")
567575
delete_all_keys_in_db_table("STATE_DB", "XCVRD_CONFIG_HWMODE_SWMODE_RSP")
568576

577+
port = platform_sfputil_helper.get_interface_alias(port, db)
578+
569579
if rc == 0:
570580
click.echo("Success in toggling port {} to {}".format(port, state))
571581
else:
@@ -588,7 +598,7 @@ def firmware():
588598
def download(db, fwfile, port):
589599
"""Config muxcable firmware download"""
590600

591-
port = platform_sfputil_helper.get_interface_alias(port, db)
601+
port = platform_sfputil_helper.get_interface_name(port, db)
592602

593603
delete_all_keys_in_db_table("STATE_DB", "XCVRD_DOWN_FW_RSP")
594604
delete_all_keys_in_db_table("APPL_DB", "XCVRD_DOWN_FW_CMD")
@@ -605,6 +615,8 @@ def download(db, fwfile, port):
605615
delete_all_keys_in_db_table("STATE_DB", "XCVRD_DOWN_FW_RSP")
606616
delete_all_keys_in_db_table("APPL_DB", "XCVRD_DOWN_FW_CMD")
607617

618+
port = platform_sfputil_helper.get_interface_alias(port, db)
619+
608620
if rc == 0:
609621
click.echo("Success in downloading firmware port {} {}".format(port, fwfile))
610622
else:
@@ -652,6 +664,8 @@ def download(db, fwfile, port):
652664
delete_all_keys_in_db_table("STATE_DB", "XCVRD_DOWN_FW_RSP")
653665
delete_all_keys_in_db_table("APPL_DB", "XCVRD_DOWN_FW_CMD")
654666

667+
port = platform_sfputil_helper.get_interface_alias(port, db)
668+
655669
if rc == 0:
656670
click.echo("Success in downloading firmware port {} {}".format(port, fwfile))
657671
else:
@@ -668,7 +682,7 @@ def download(db, fwfile, port):
668682
def activate(db, port, fwfile):
669683
"""Config muxcable firmware activate"""
670684

671-
port = platform_sfputil_helper.get_interface_alias(port, db)
685+
port = platform_sfputil_helper.get_interface_name(port, db)
672686

673687
delete_all_keys_in_db_table("STATE_DB", "XCVRD_ACTI_FW_RSP")
674688
delete_all_keys_in_db_table("APPL_DB", "XCVRD_ACTI_FW_CMD")
@@ -685,6 +699,8 @@ def activate(db, port, fwfile):
685699
delete_all_keys_in_db_table("STATE_DB", "XCVRD_ACTI_FW_RSP")
686700
delete_all_keys_in_db_table("APPL_DB", "XCVRD_ACTI_FW_CMD")
687701

702+
port = platform_sfputil_helper.get_interface_alias(port, db)
703+
688704
if rc == 0:
689705
click.echo("Success in activate firmware port {} fwfile {}".format(port, fwfile))
690706
else:
@@ -731,6 +747,8 @@ def activate(db, port, fwfile):
731747

732748
rc = res_dict[0]
733749

750+
port = platform_sfputil_helper.get_interface_alias(port, db)
751+
734752
if rc == 0:
735753
click.echo("Success in activate firmware port {} fwfile {}".format(port, fwfile))
736754
else:
@@ -747,7 +765,7 @@ def activate(db, port, fwfile):
747765
def rollback(db, port, fwfile):
748766
"""Config muxcable firmware rollback"""
749767

750-
port = platform_sfputil_helper.get_interface_alias(port, db)
768+
port = platform_sfputil_helper.get_interface_name(port, db)
751769

752770
delete_all_keys_in_db_table("STATE_DB", "XCVRD_ROLL_FW_RSP")
753771
delete_all_keys_in_db_table("APPL_DB", "XCVRD_ROLL_FW_CMD")
@@ -763,6 +781,9 @@ def rollback(db, port, fwfile):
763781
delete_all_keys_in_db_table("APPL_DB", "XCVRD_ROLL_FW_CMD")
764782

765783
rc = res_dict[0]
784+
785+
port = platform_sfputil_helper.get_interface_alias(port, db)
786+
766787
if rc == 0:
767788
click.echo("Success in rollback firmware port {} fwfile {}".format(port, fwfile))
768789
else:
@@ -809,6 +830,8 @@ def rollback(db, port, fwfile):
809830

810831
rc = res_dict[0]
811832

833+
port = platform_sfputil_helper.get_interface_alias(port, db)
834+
812835
if rc == 0:
813836
click.echo("Success in rollback firmware port {} fwfile {}".format(port, fwfile))
814837
else:

0 commit comments

Comments
 (0)