Skip to content

Commit

Permalink
[show][config] fix the muxcable commands for interface naming mode (#…
Browse files Browse the repository at this point in the history
…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]>
  • Loading branch information
vdahiya12 authored Oct 13, 2021
1 parent 476b3a4 commit 9ab20fd
Show file tree
Hide file tree
Showing 4 changed files with 419 additions and 53 deletions.
47 changes: 35 additions & 12 deletions config/muxcable.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def muxcable():
platform_sfputil = platform_sfputil_helper.platform_sfputil


def lookup_statedb_and_update_configdb(per_npu_statedb, config_db, port, state_cfg_val, port_status_dict):
def lookup_statedb_and_update_configdb(db, per_npu_statedb, config_db, port, state_cfg_val, port_status_dict):

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

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

port_name = platform_sfputil_helper.get_interface_alias(port, db)

if str(state_cfg_val) == str(configdb_state):
port_status_dict[port] = 'OK'
port_status_dict[port_name] = 'OK'
else:
config_db.set_entry("MUX_CABLE", port, {"state": state_cfg_val,
"server_ipv4": ipv4_value, "server_ipv6": ipv6_value})
if (str(state_cfg_val) == 'active' and str(state) != 'active') or (str(state_cfg_val) == 'standby' and str(state) != 'standby'):
port_status_dict[port] = 'INPROGRESS'
port_status_dict[port_name] = 'INPROGRESS'
else:
port_status_dict[port] = 'OK'
port_status_dict[port_name] = 'OK'


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

port = platform_sfputil_helper.get_interface_alias(port, db)
port = platform_sfputil_helper.get_interface_name(port, db)

port_table_keys = {}
y_cable_asic_table_keys = {}
Expand Down Expand Up @@ -292,7 +294,7 @@ def mode(db, state, port, json_output):
if logical_key in y_cable_asic_table_keys:
port_status_dict = {}
lookup_statedb_and_update_configdb(
per_npu_statedb[asic_index], per_npu_configdb[asic_index], port, state, port_status_dict)
db, per_npu_statedb[asic_index], per_npu_configdb[asic_index], port, state, port_status_dict)

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

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

port = platform_sfputil_helper.get_interface_alias(port, db)
port = platform_sfputil_helper.get_interface_name(port, db)

delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_HWMODE_DIR_CMD")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_CONFIG_HWMODE_DIR_RSP")
Expand All @@ -437,6 +439,8 @@ def state(db, state, port):
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_HWMODE_DIR_CMD")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_CONFIG_HWMODE_DIR_RSP")

port = platform_sfputil_helper.get_interface_alias(port, db)

if rc == 0:
click.echo("Success in toggling port {} to {}".format(port, state))
else:
Expand Down Expand Up @@ -484,6 +488,8 @@ def state(db, state, port):
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_HWMODE_DIR_CMD")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_CONFIG_HWMODE_DIR_RSP")

port = platform_sfputil_helper.get_interface_alias(port, db)

if rc == 0:
click.echo("Success in toggling port {} to {}".format(port, state))
else:
Expand All @@ -500,7 +506,7 @@ def state(db, state, port):
def setswitchmode(db, state, port):
"""Configure the muxcable mux switching mode {auto/manual}"""

port = platform_sfputil_helper.get_interface_alias(port, db)
port = platform_sfputil_helper.get_interface_name(port, db)


delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_HWMODE_SWMODE_CMD")
Expand All @@ -520,6 +526,8 @@ def setswitchmode(db, state, port):
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_HWMODE_SWMODE_CMD")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_CONFIG_HWMODE_SWMODE_RSP")

port = platform_sfputil_helper.get_interface_alias(port, db)

if rc == 0:
click.echo("Success in switch muxcable mode port {} to {}".format(port, state))
else:
Expand Down Expand Up @@ -566,6 +574,8 @@ def setswitchmode(db, state, port):
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_HWMODE_SWMODE_CMD")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_CONFIG_HWMODE_SWMODE_RSP")

port = platform_sfputil_helper.get_interface_alias(port, db)

if rc == 0:
click.echo("Success in toggling port {} to {}".format(port, state))
else:
Expand All @@ -588,7 +598,7 @@ def firmware():
def download(db, fwfile, port):
"""Config muxcable firmware download"""

port = platform_sfputil_helper.get_interface_alias(port, db)
port = platform_sfputil_helper.get_interface_name(port, db)

delete_all_keys_in_db_table("STATE_DB", "XCVRD_DOWN_FW_RSP")
delete_all_keys_in_db_table("APPL_DB", "XCVRD_DOWN_FW_CMD")
Expand All @@ -605,6 +615,8 @@ def download(db, fwfile, port):
delete_all_keys_in_db_table("STATE_DB", "XCVRD_DOWN_FW_RSP")
delete_all_keys_in_db_table("APPL_DB", "XCVRD_DOWN_FW_CMD")

port = platform_sfputil_helper.get_interface_alias(port, db)

if rc == 0:
click.echo("Success in downloading firmware port {} {}".format(port, fwfile))
else:
Expand Down Expand Up @@ -652,6 +664,8 @@ def download(db, fwfile, port):
delete_all_keys_in_db_table("STATE_DB", "XCVRD_DOWN_FW_RSP")
delete_all_keys_in_db_table("APPL_DB", "XCVRD_DOWN_FW_CMD")

port = platform_sfputil_helper.get_interface_alias(port, db)

if rc == 0:
click.echo("Success in downloading firmware port {} {}".format(port, fwfile))
else:
Expand All @@ -668,7 +682,7 @@ def download(db, fwfile, port):
def activate(db, port, fwfile):
"""Config muxcable firmware activate"""

port = platform_sfputil_helper.get_interface_alias(port, db)
port = platform_sfputil_helper.get_interface_name(port, db)

delete_all_keys_in_db_table("STATE_DB", "XCVRD_ACTI_FW_RSP")
delete_all_keys_in_db_table("APPL_DB", "XCVRD_ACTI_FW_CMD")
Expand All @@ -685,6 +699,8 @@ def activate(db, port, fwfile):
delete_all_keys_in_db_table("STATE_DB", "XCVRD_ACTI_FW_RSP")
delete_all_keys_in_db_table("APPL_DB", "XCVRD_ACTI_FW_CMD")

port = platform_sfputil_helper.get_interface_alias(port, db)

if rc == 0:
click.echo("Success in activate firmware port {} fwfile {}".format(port, fwfile))
else:
Expand Down Expand Up @@ -731,6 +747,8 @@ def activate(db, port, fwfile):

rc = res_dict[0]

port = platform_sfputil_helper.get_interface_alias(port, db)

if rc == 0:
click.echo("Success in activate firmware port {} fwfile {}".format(port, fwfile))
else:
Expand All @@ -747,7 +765,7 @@ def activate(db, port, fwfile):
def rollback(db, port, fwfile):
"""Config muxcable firmware rollback"""

port = platform_sfputil_helper.get_interface_alias(port, db)
port = platform_sfputil_helper.get_interface_name(port, db)

delete_all_keys_in_db_table("STATE_DB", "XCVRD_ROLL_FW_RSP")
delete_all_keys_in_db_table("APPL_DB", "XCVRD_ROLL_FW_CMD")
Expand All @@ -763,6 +781,9 @@ def rollback(db, port, fwfile):
delete_all_keys_in_db_table("APPL_DB", "XCVRD_ROLL_FW_CMD")

rc = res_dict[0]

port = platform_sfputil_helper.get_interface_alias(port, db)

if rc == 0:
click.echo("Success in rollback firmware port {} fwfile {}".format(port, fwfile))
else:
Expand Down Expand Up @@ -809,6 +830,8 @@ def rollback(db, port, fwfile):

rc = res_dict[0]

port = platform_sfputil_helper.get_interface_alias(port, db)

if rc == 0:
click.echo("Success in rollback firmware port {} fwfile {}".format(port, fwfile))
else:
Expand Down
Loading

0 comments on commit 9ab20fd

Please sign in to comment.