Skip to content

Commit

Permalink
fix indent and logic and some naming
Browse files Browse the repository at this point in the history
Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>
  • Loading branch information
vdahiya12 committed Nov 18, 2021
1 parent 6108973 commit 2bc3d3f
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 28 deletions.
53 changes: 48 additions & 5 deletions config/muxcable.py
Original file line number Diff line number Diff line change
Expand Up @@ -980,9 +980,9 @@ def rollback(db, port, fwfile):
@click.argument('target', required=True, metavar='<target> 0 NIC 1 ToR A 2 ToR B 3 Local', type=click.Choice(["0", "1", "2", "3"]))
@clicommon.pass_db
def reset(db, port, target):
"""Enable PRBS mode on a port args port target mode_value lane_mask prbs_direction"""
"""reset a target on the cable 0 NIC 1 ToR A 2 ToR B 3 Local """

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_PRBS_CMD")
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_PRBS_CMD_ARG")
Expand All @@ -1006,6 +1006,7 @@ def reset(db, port, target):
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_PRBS_CMD_ARG")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_CONFIG_PRBS_RSP")

port = platform_sfputil_helper.get_interface_alias(port, db)
if rc == 0:
click.echo("Success in reset port {}".format(port))
else:
Expand All @@ -1016,12 +1017,12 @@ def reset(db, port, target):
@muxcable.command()
@click.argument('port', required=True, default=None)
@click.argument('target', required=True, metavar='<target> 0 NIC 1 ToR A 2 ToR B 3 Local', type=click.Choice(["0", "1", "2", "3"]))
@click.argument('mode', required=True, metavar='<target> 0 disable 1 enable', default=True, type=click.Choice(["0", "1"]))
@click.argument('mode', required=True, metavar='<mode> 0 disable 1 enable', default=True, type=click.Choice(["0", "1"]))
@clicommon.pass_db
def set_anlt(db, port, target, mode):
"""Enable PRBS mode on a port args port target mode_value lane_mask prbs_direction"""
"""Enable anlt mode on a port args port <target> 0 NIC 1 ToR A 2 ToR B 3 Local enable/disable 1/0"""

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_PRBS_CMD")
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_PRBS_CMD_ARG")
Expand All @@ -1047,8 +1048,50 @@ def set_anlt(db, port, target, mode):
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_PRBS_CMD_ARG")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_CONFIG_PRBS_RSP")

port = platform_sfputil_helper.get_interface_alias(port, db)
if rc == 0:
click.echo("Success in anlt enable/disable port {} to {}".format(port, mode))
else:
click.echo("ERR: Unable to set anlt enable/disable port {} to {}".format(port, mode))
sys.exit(CONFIG_FAIL)

@muxcable.command()
@click.argument('port', required=True, default=None)
@click.argument('target', required=True, metavar='<target> 0 NIC 1 ToR A 2 ToR B 3 Local', type=click.Choice(["0", "1", "2", "3"]))
@click.argument('mode', required=True, metavar='<mode> FEC_MODE_NONE 0 FEC_MODE_RS 1 FEC_MODE_FC 2', default=True, type=click.Choice(["0", "1", "2"]))
@clicommon.pass_db
def set_fec(db, port, target, mode):
"""Enable fec mode on a port args port <target> 0 NIC 1 ToR A 2 ToR B 3 Local <mode_value> FEC_MODE_NONE 0 FEC_MODE_RS 1 FEC_MODE_FC 2 """

port = platform_sfputil_helper.get_interface_name(port, db)

delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_PRBS_CMD")
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_PRBS_CMD_ARG")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_CONFIG_PRBS_RSP")

if port is not None:
click.confirm(
('Muxcable at port {} will be changed to enable/disable fec mode {} state; disable traffic Continue?'.format(port, mode)), abort=True)

res_dict = {}
res_dict[0] = CONFIG_FAIL
res_dict[1] = "unknown"
param_dict = {}
param_dict["target"] = target
param_dict["mode"] = mode

res_dict = update_and_get_response_for_xcvr_cmd(
"config_prbs", "status", "True", "XCVRD_CONFIG_PRBS_CMD", "XCVRD_CONFIG_PRBS_CMD_ARG", "XCVRD_CONFIG_PRBS_RSP", port, 30, param_dict, "fec")

rc = res_dict[0]

delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_PRBS_CMD")
delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_PRBS_CMD_ARG")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_CONFIG_PRBS_RSP")

port = platform_sfputil_helper.get_interface_alias(port, db)
if rc == 0:
click.echo("Success in fec enable/disable port {} to {}".format(port, mode))
else:
click.echo("ERR: Unable to set fec enable/disable port {} to {}".format(port, mode))
sys.exit(CONFIG_FAIL)
108 changes: 85 additions & 23 deletions show/muxcable.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,12 +656,13 @@ def config(db, port, json_output):

@muxcable.command()
@click.argument('port', metavar='<port_name>', required=True, default=None)
@click.argument('target', required=True, default=None, type=click.INT)
@click.argument('target', metavar='<target> 0 NIC 1 ToR A 2 ToR B 3 Local', required=True, default=None, type=click.Choice(["0", "1", "2", "3"]))
@click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL, help="display the output in json format")
@clicommon.pass_db
def berinfo(db, port, target):
def berinfo(db, port, target, json_output):
"""Show muxcable BER (bit error rate) information"""

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_GET_BER_CMD")
delete_all_keys_in_db_table("APPL_DB", "XCVRD_GET_BER_CMD_ARG")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_GET_BER_RSP")
Expand Down Expand Up @@ -690,17 +691,26 @@ def berinfo(db, port, target):
delete_all_keys_in_db_table("STATE_DB", "XCVRD_GET_BER_RSP")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_GET_BER_RES")

click.echo("{}".format(json.dumps(result, indent=4)))
port = platform_sfputil_helper.get_interface_alias(port, db)

if json_output:
click.echo("{}".format(json.dumps(result, indent=4)))
else:
headers = ['PORT', 'VALUE']
res = [[key] + [val] for key, val in result.items()]
click.echo(tabulate(res, headers=headers))

else:
click.echo("Did not get a valid Port for ber value".format(port))
sys.exit(CONFIG_FAIL)


@muxcable.command()
@click.argument('port', metavar='<port_name>', required=True, default=None)
@click.argument('target', required=True, default=None, type=click.INT)
@click.argument('target', metavar='<target> 0 NIC 1 ToR A 2 ToR B 3 Local', required=True, default=None, type=click.Choice(["0", "1", "2", "3"]))
@click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL, help="display the output in json format")
@clicommon.pass_db
def eyeinfo(db, port, target):
def eyeinfo(db, port, target, json_output):
"""Show muxcable eye information in mv"""

port = platform_sfputil_helper.get_interface_alias(port, db)
Expand Down Expand Up @@ -731,18 +741,26 @@ def eyeinfo(db, port, target):
delete_all_keys_in_db_table("APPL_DB", "XCVRD_GET_BER_CMD_ARG")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_GET_BER_RSP")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_GET_BER_RES")
port = platform_sfputil_helper.get_interface_alias(port, db)

if json_output:
click.echo("{}".format(json.dumps(result, indent=4)))
else:
headers = ['PORT', 'VALUE']
res = [[key] + [val] for key, val in result.items()]
click.echo(tabulate(res, headers=headers))

click.echo("{}".format(json.dumps(result, indent=4)))
else:
click.echo("Did not get a valid Port for ber value".format(port))
sys.exit(CONFIG_FAIL)


@muxcable.command()
@click.argument('port', metavar='<port_name>', required=True, default=None)
@click.argument('target', required=True, default=None, type=click.INT)
@click.argument('target', metavar='<target> 0 NIC 1 ToR A 2 ToR B 3 Local', required=True, default=None, type=click.Choice(["0", "1", "2", "3"]))
@click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL, help="display the output in json format")
@clicommon.pass_db
def fecstatistics(db, port, target):
def fecstatistics(db, port, target, json_output):
"""Show muxcable fec layer statistics information, target 0 NIC 1 ToR A 2 ToR B"""

port = platform_sfputil_helper.get_interface_alias(port, db)
Expand Down Expand Up @@ -773,18 +791,26 @@ def fecstatistics(db, port, target):
delete_all_keys_in_db_table("APPL_DB", "XCVRD_GET_BER_CMD_ARG")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_GET_BER_RSP")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_GET_BER_RES")
port = platform_sfputil_helper.get_interface_alias(port, db)

if json_output:
click.echo("{}".format(json.dumps(result, indent=4)))
else:
headers = ['PORT', 'VALUE']
res = [[key] + [val] for key, val in result.items()]
click.echo(tabulate(res, headers=headers))

click.echo("{}".format(json.dumps(result, indent=4)))
else:
click.echo("Did not get a valid Port for ber value".format(port))
sys.exit(CONFIG_FAIL)


@muxcable.command()
@click.argument('port', metavar='<port_name>', required=True, default=None)
@click.argument('target', metavar='<target> 0 NIC 1 ToR A 2 ToR B 3 Local', required=True, default=None, type=click.INT)
@click.argument('target', metavar='<target> 0 NIC 1 ToR A 2 ToR B 3 Local', required=True, default=None, type=click.Choice(["0", "1", "2", "3"]))
@click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL, help="display the output in json format")
@clicommon.pass_db
def pcsstatistics(db, port, target):
def pcsstatistics(db, port, target, json_output):
"""Show muxcable pcs layer statistics information"""

port = platform_sfputil_helper.get_interface_alias(port, db)
Expand Down Expand Up @@ -815,6 +841,14 @@ def pcsstatistics(db, port, target):
delete_all_keys_in_db_table("APPL_DB", "XCVRD_GET_BER_CMD_ARG")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_GET_BER_RSP")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_GET_BER_RES")
port = platform_sfputil_helper.get_interface_alias(port, db)

if json_output:
click.echo("{}".format(json.dumps(result, indent=4)))
else:
headers = ['PORT', 'VALUE']
res = [[key] + [val] for key, val in result.items()]
click.echo(tabulate(res, headers=headers))

click.echo("{}".format(json.dumps(result, indent=4)))
else:
Expand All @@ -824,11 +858,12 @@ def pcsstatistics(db, port, target):
@muxcable.command()
@click.argument('port', metavar='<port_name>', required=True, default=None)
@click.argument('option', required=False, default=None)
@click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL, help="display the output in json format")
@clicommon.pass_db
def debugdumpregisters(db, port, option):
def debugdumpregisters(db, port, option, json_output):
"""Show muxcable debug deump registers information, preagreed by vendors"""

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_GET_BER_CMD")
delete_all_keys_in_db_table("APPL_DB", "XCVRD_GET_BER_CMD_ARG")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_GET_BER_RSP")
Expand Down Expand Up @@ -856,19 +891,26 @@ def debugdumpregisters(db, port, option):
delete_all_keys_in_db_table("APPL_DB", "XCVRD_GET_BER_CMD_ARG")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_GET_BER_RSP")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_GET_BER_RES")
port = platform_sfputil_helper.get_interface_alias(port, db)

click.echo("{}".format(json.dumps(result, indent=4)))
if json_output:
click.echo("{}".format(json.dumps(result, indent=4)))
else:
headers = ['PORT', 'VALUE']
res = [[key] + [val] for key, val in result.items()]
click.echo(tabulate(res, headers=headers))
else:
click.echo("Did not get a valid Port for debug dump registers".format(port))
sys.exit(CONFIG_FAIL)

@muxcable.command()
@click.argument('port', metavar='<port_name>', required=True, default=None)
@click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL, help="display the output in json format")
@clicommon.pass_db
def alivecablestatus(db, port):
def alivecablestatus(db, port, json_output):
"""Show muxcable alive information """

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_GET_BER_CMD")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_GET_BER_RSP")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_GET_BER_RES")
Expand All @@ -893,7 +935,14 @@ def alivecablestatus(db, port):
delete_all_keys_in_db_table("STATE_DB", "XCVRD_GET_BER_RSP")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_GET_BER_RES")

click.echo("{}".format(json.dumps(result, indent=4)))
port = platform_sfputil_helper.get_interface_alias(port, db)

if json_output:
click.echo("{}".format(json.dumps(result, indent=4)))
else:
headers = ['PORT', 'VALUE']
res = [[key] + [val] for key, val in result.items()]
click.echo(tabulate(res, headers=headers))
else:
click.echo("Did not get a valid Port for cable alive status".format(port))
sys.exit(CONFIG_FAIL)
Expand Down Expand Up @@ -1374,7 +1423,7 @@ def metrics(db, port, json_output):
def event_log(db, port, json_output):
"""Show muxcable event log <port>"""

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_EVENT_LOG_CMD")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_EVENT_LOG_RSP")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_EVENT_LOG_RES")
Expand All @@ -1397,19 +1446,26 @@ def event_log(db, port, json_output):
delete_all_keys_in_db_table("STATE_DB", "XCVRD_EVENT_LOG_RSP")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_EVENT_LOG_RES")
delete_all_keys_in_db_table("APPL_DB", "XCVRD_EVENT_LOG_CMD")
port = platform_sfputil_helper.get_interface_alias(port, db)

click.echo("{}".format(json.dumps(mux_info_dict, indent=4)))
if json_output:
click.echo("{}".format(json.dumps(result, indent=4)))
else:
headers = ['PORT', 'VALUE']
res = [[key] + [val] for key, val in result.items()]
click.echo(tabulate(res, headers=headers))
else:
click.echo("Did not get a valid Port for event log".format(port))
sys.exit(CONFIG_FAIL)

@muxcable.command()
@click.argument('port', metavar='<port_name>', required=True, default=None)
@click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL, help="display the output in json format")
@clicommon.pass_db
def get_fec_anlt_speed(db, port):
def get_fec_anlt_speed(db, port, json_output):
"""Show muxcable configurations for fec anlt speed <port>"""

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_GET_FEC_CMD")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_GET_FEC_RSP")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_GET_FEC_RES")
Expand All @@ -1433,8 +1489,14 @@ def get_fec_anlt_speed(db, port):
delete_all_keys_in_db_table("APPL_DB", "XCVRD_GET_FEC_CMD")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_GET_FEC_RSP")
delete_all_keys_in_db_table("STATE_DB", "XCVRD_GET_FEC_RES")
port = platform_sfputil_helper.get_interface_name(port, db)

click.echo("{}".format(json.dumps(result, indent=4)))
if json_output:
click.echo("{}".format(json.dumps(result, indent=4)))
else:
headers = ['PORT', 'VALUE']
res = [[key] + [val] for key, val in result.items()]
click.echo(tabulate(res, headers=headers))
else:
click.echo("Did not get a valid Port for fec value speed anlt".format(port))
sys.exit(CONFIG_FAIL)
Expand Down

0 comments on commit 2bc3d3f

Please sign in to comment.