Skip to content

Commit

Permalink
fix logic to delete keys
Browse files Browse the repository at this point in the history
Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>
  • Loading branch information
vdahiya12 committed Aug 6, 2021
1 parent 9c38a8b commit 7bdd6ef
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 31 deletions.
37 changes: 35 additions & 2 deletions config/muxcable.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,10 @@ def update_and_get_response_for_xcvr_cmd(cmd_name, rsp_name, exp_rsp, cmd_table_

if port_m != port:

click.echo("receive a wrong port response {}".format(port))
res_dict[1] = 'unknown'
res_dict[0] = CONFIG_FAIL
firmware_rsp_tbl[asic_index]._del(port)
break
continue

if fvp_m:

Expand Down Expand Up @@ -434,6 +433,10 @@ def state(db, state, port):
res_dict = update_and_get_response_for_xcvr_cmd("config","result", "True", "XCVRD_CONFIG_HWMODE_DIR_CMD", "XCVRD_CONFIG_HWMODE_DIR_RSP", port, 1, state)

rc = res_dict[0]

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")

if rc == 0:
click.echo("Success in toggling port {} to {}".format(port, state))
else:
Expand Down Expand Up @@ -478,6 +481,9 @@ def state(db, state, port):

rc = res_dict[0]

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")

if rc == 0:
click.echo("Success in toggling port {} to {}".format(port, state))
else:
Expand Down Expand Up @@ -510,6 +516,10 @@ def setswitchmode(db, state, port):


rc = res_dict[0]

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")

if rc == 0:
click.echo("Success in switch muxcable mode port {} to {}".format(port, state))
else:
Expand Down Expand Up @@ -553,6 +563,9 @@ def setswitchmode(db, state, port):

rc = res_dict[0]

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")

if rc == 0:
click.echo("Success in toggling port {} to {}".format(port, state))
else:
Expand Down Expand Up @@ -588,6 +601,10 @@ def download(db, fwfile, port):
res_dict = update_and_get_response_for_xcvr_cmd("download_firmware", "status", "0", "XCVRD_DOWN_FW_CMD", "XCVRD_DOWN_FW_RSP", port, 1000, fwfile)

rc = res_dict[0]

delete_all_keys_in_db_table("STATE_DB", "XCVRD_DOWN_FW_RSP")
delete_all_keys_in_db_table("APPL_DB", "XCVRD_DOWN_FW_CMD")

if rc == 0:
click.echo("Success in downloading firmware port {} {}".format(port, fwfile))
else:
Expand Down Expand Up @@ -632,6 +649,9 @@ def download(db, fwfile, port):

rc = res_dict[0]

delete_all_keys_in_db_table("STATE_DB", "XCVRD_DOWN_FW_RSP")
delete_all_keys_in_db_table("APPL_DB", "XCVRD_DOWN_FW_CMD")

if rc == 0:
click.echo("Success in downloading firmware port {} {}".format(port, fwfile))
else:
Expand Down Expand Up @@ -661,6 +681,10 @@ def activate(db, port, fwfile):
res_dict = update_and_get_response_for_xcvr_cmd("activate_firmware", "status", "0", "XCVRD_ACTI_FW_CMD", "XCVRD_ACTI_FW_RSP", port, 60, fwfile)

rc = res_dict[0]

delete_all_keys_in_db_table("STATE_DB", "XCVRD_ACTI_FW_RSP")
delete_all_keys_in_db_table("APPL_DB", "XCVRD_ACTI_FW_CMD")

if rc == 0:
click.echo("Success in activate firmware port {} fwfile {}".format(port, fwfile))
else:
Expand Down Expand Up @@ -702,6 +726,9 @@ def activate(db, port, fwfile):
res_dict [1] = "unknown"
res_dict = update_and_get_response_for_xcvr_cmd("activate_firmware", "status", "0", "XCVRD_ACTI_FW_CMD", "XCVRD_ACTI_FW_RSP", port, 60, 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")

rc = res_dict[0]

if rc == 0:
Expand Down Expand Up @@ -732,6 +759,9 @@ def rollback(db, port, fwfile):
res_dict [1] = "unknown"
res_dict = update_and_get_response_for_xcvr_cmd("rollback_firmware", "status", "0", "XCVRD_ROLL_FW_CMD", "XCVRD_ROLL_FW_RSP", port, 60, fwfile)

delete_all_keys_in_db_table("STATE_DB", "XCVRD_ROLL_FW_RSP")
delete_all_keys_in_db_table("APPL_DB", "XCVRD_ROLL_FW_CMD")

rc = res_dict[0]
if rc == 0:
click.echo("Success in rollback firmware port {} fwfile {}".format(port, fwfile))
Expand Down Expand Up @@ -774,6 +804,9 @@ def rollback(db, port, fwfile):
res_dict [1] = "unknown"
res_dict = update_and_get_response_for_xcvr_cmd("rollback_firmware", "status", "0", "XCVRD_ROLL_FW_CMD", "XCVRD_ROLL_FW_RSP", port, 60, fwfile)

delete_all_keys_in_db_table("STATE_DB", "XCVRD_ROLL_FW_RSP")
delete_all_keys_in_db_table("APPL_DB", "XCVRD_ROLL_FW_CMD")

rc = res_dict[0]

if rc == 0:
Expand Down
50 changes: 21 additions & 29 deletions show/muxcable.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,10 @@ def update_and_get_response_for_xcvr_cmd(cmd_name, rsp_name, exp_rsp, cmd_table_

if port_m != port:

click.echo("receive a wrong port response {}".format(port))
res_dict[1] = 'unknown'
res_dict[0] = CONFIG_FAIL
firmware_rsp_tbl[asic_index]._del(port)
break
continue

if fvp_m:

Expand Down Expand Up @@ -673,6 +672,10 @@ def muxdirection(db, port):

rc = res_dict[0]
click.echo(tabulate(body, headers=headers))

delete_all_keys_in_db_table("APPL_DB", "XCVRD_SHOW_HWMODE_DIR_CMD")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_SHOW_HWMODE_DIR_RSP")

return rc

else:
Expand Down Expand Up @@ -721,6 +724,9 @@ def muxdirection(db, port):
headers = ['Port', 'Direction']

click.echo(tabulate(body, headers=headers))

delete_all_keys_in_db_table("APPL_DB", "XCVRD_SHOW_HWMODE_DIR_CMD")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_SHOW_HWMODE_DIR_RSP")
if rc_exit == False:
sys.exit(EXIT_FAIL)

Expand Down Expand Up @@ -752,6 +758,10 @@ def switchmode(db, port):

rc = res_dict[0]
click.echo(tabulate(body, headers=headers))

delete_all_keys_in_db_table("APPL_DB", "XCVRD_SHOW_HWMODE_SWMODE_CMD")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_SHOW_HWMODE_SWMODE_RSP")

return rc

else:
Expand Down Expand Up @@ -797,31 +807,16 @@ def switchmode(db, port):
rc_exit = False
body.append(temp_list)

delete_all_keys_in_db_table("APPL_DB", "XCVRD_SHOW_HWMODE_SWMODE_CMD")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_SHOW_HWMODE_SWMODE_RSP")

headers = ['Port', 'Switching']

click.echo(tabulate(body, headers=headers))
if rc_exit == False:
sys.exit(EXIT_FAIL)


@hwmode.command()
@click.argument('port', metavar='<port_name>', required=False, default=None)
@clicommon.pass_db
def get_firmware_dict(physical_port, target, side, mux_info_dict):

import sonic_y_cable.y_cable
result = sonic_y_cable.y_cable.get_firmware_version(physical_port, target)

if result is not None and isinstance(result, dict):
mux_info_dict[("version_{}_active".format(side))] = result.get("version_active", None)
mux_info_dict[("version_{}_inactive".format(side))] = result.get("version_inactive", None)
mux_info_dict[("version_{}_next".format(side))] = result.get("version_next", None)

else:
mux_info_dict[("version_{}_active".format(side))] = "N/A"
mux_info_dict[("version_{}_inactive".format(side))] = "N/A"
mux_info_dict[("version_{}_next".format(side))] = "N/A"


def get_single_port_firmware_version(port, res_dict, mux_info_dict):

Expand Down Expand Up @@ -905,11 +900,10 @@ def get_single_port_firmware_version(port, res_dict, mux_info_dict):

if port_m != port:

click.echo("receive a wrong port response {}".format(port))
res_dict[0] = 'False'
res_dict[1] = EXIT_FAIL
xcvrd_show_fw_rsp_sts_tbl[asic_index]._del(port)
break
continue

if fvp_m:

Expand Down Expand Up @@ -944,13 +938,9 @@ def get_single_port_firmware_version(port, res_dict, mux_info_dict):
xcvrd_show_fw_rsp_sts_tbl[asic_index]._del(port)
break

for namespace in namespaces:
asic_id = multi_asic.get_asic_index_from_namespace(namespace)
state_db[asic_id] = db_connect("STATE_DB", namespace)
xcvrd_show_fw_rsp_sts_tbl[asic_id] = swsscommon.Table(state_db[asic_id], "XCVRD_SHOW_FW_RSP")
xcvrd_show_fw_rsp_sts_tbl_keys[asic_id] = xcvrd_show_fw_rsp_sts_tbl[asic_id].getKeys()
for key in xcvrd_show_fw_rsp_sts_tbl_keys[asic_id]:
xcvrd_show_fw_rsp_sts_tbl[asic_id]._del(key)

delete_all_keys_in_db_table("STATE_DB", "XCVRD_SHOW_FW_RSP")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_SHOW_FW_RES")

return

Expand Down Expand Up @@ -998,6 +988,8 @@ def version(db, port, active):
if res_dict[1] == "True":
mux_info_dict = get_response_for_version(port, mux_info_dict)

delete_all_keys_in_db_table("STATE_DB", "XCVRD_SHOW_FW_RSP")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_SHOW_FW_RES")

if active is True:
for key in mux_info_dict:
Expand Down

0 comments on commit 7bdd6ef

Please sign in to comment.