From fcd107fad2f1599be867168c07812169e6990bf1 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Wed, 8 Feb 2023 20:31:49 +0000 Subject: [PATCH 01/25] add changes Signed-off-by: vaibhav-dahiya --- show/muxcable.py | 184 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 184 insertions(+) diff --git a/show/muxcable.py b/show/muxcable.py index b640d32135..e9ffca501a 100644 --- a/show/muxcable.py +++ b/show/muxcable.py @@ -2255,4 +2255,188 @@ def muxdirection(db, port, json_output): if rc_exit == False: sys.exit(EXIT_FAIL) +@muxcable.command() +@click.argument('port', metavar='', 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 queueinfo(db, port, option, json_output): + """Show muxcable debug deump registers information, preagreed by vendors""" + + 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") + delete_all_keys_in_db_table("STATE_DB", "XCVRD_GET_BER_RES") + + if port is not None: + + res_dict = {} + result = {} + param_dict = {} + param_dict["option"] = option + + + res_dict[0] = CONFIG_FAIL + res_dict[1] = "unknown" + + res_dict = update_and_get_response_for_xcvr_cmd( + "get_ber", "status", "True", "XCVRD_GET_BER_CMD", "XCVRD_GET_BER_CMD_ARG", "XCVRD_GET_BER_RSP", port, 100, param_dict, "queue_info") + + if res_dict[1] == "True": + result = get_result(port, res_dict, "fec" , result, "XCVRD_GET_BER_RES") + + + 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") + 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', 'ATTR', 'VALUE'] + res = [[port]+[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='', 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 health(db, port, json_output): + """Show muxcable health information """ + + 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") + + if port is not None: + + res_dict = {} + result = {} + + + res_dict[0] = CONFIG_FAIL + res_dict[1] = "unknown" + + res_dict = update_and_get_response_for_xcvr_cmd( + "get_ber", "status", "True", "XCVRD_GET_BER_CMD", None, "XCVRD_GET_BER_RSP", port, 10, None, "health_check") + + if res_dict[1] == "True": + result = get_result(port, res_dict, "fec" , result, "XCVRD_GET_BER_RES") + + + 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") + + port = platform_sfputil_helper.get_interface_alias(port, db) + + if json_output: + click.echo("{}".format(json.dumps(result, indent=4))) + else: + headers = ['PORT', 'ATTR', 'HEALTH'] + res = [[port]+[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) + +@muxcable.command() +@click.argument('port', metavar='', 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 resetcause(db, port, json_output): + """Show muxcable health information """ + + 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") + + if port is not None: + + res_dict = {} + result = {} + + + res_dict[0] = CONFIG_FAIL + res_dict[1] = "unknown" + + res_dict = update_and_get_response_for_xcvr_cmd( + "get_ber", "status", "True", "XCVRD_GET_BER_CMD", None, "XCVRD_GET_BER_RSP", port, 10, None, "reset_cause") + + if res_dict[1] == "True": + result = get_result(port, res_dict, "fec" , result, "XCVRD_GET_BER_RES") + + + 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") + port = platform_sfputil_helper.get_interface_alias(port, db) + + if json_output: + click.echo("{}".format(json.dumps(result, indent=4))) + else: + headers = ['PORT', 'ATTR', 'RESETCAUSE'] + res = [[port]+[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) + +@muxcable.command() +@click.argument('port', metavar='', 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 operationtime(db, port, json_output): + """Show muxcable operation time """ + + 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") + + if port is not None: + + res_dict = {} + result = {} + + + res_dict[0] = CONFIG_FAIL + res_dict[1] = "unknown" + + res_dict = update_and_get_response_for_xcvr_cmd( + "get_ber", "status", "True", "XCVRD_GET_BER_CMD", None, "XCVRD_GET_BER_RSP", port, 10, None, "operation_time") + + if res_dict[1] == "True": + result = get_result(port, res_dict, "fec" , result, "XCVRD_GET_BER_RES") + + + 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") + + port = platform_sfputil_helper.get_interface_alias(port, db) + + actual_time = result.get("cable") + if actual_time is not None: + time = '{0:02.0f}:{1:02.0f}'.format(*divmod(int(actual_time) * 60, 60)) + result['cable'] = time + + if json_output: + click.echo("{}".format(json.dumps(result, indent=4))) + else: + headers = ['PORT', 'ATTR', 'OPERATION_TIME'] + res = [[port]+[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) From e4cc431773f8d95947ba46f92a82004a60c4b1ba Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Wed, 8 Feb 2023 23:20:42 +0000 Subject: [PATCH 02/25] add UT Signed-off-by: vaibhav-dahiya --- show/muxcable.py | 2 +- tests/muxcable_test.py | 83 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 1 deletion(-) diff --git a/show/muxcable.py b/show/muxcable.py index e9ffca501a..69df5fe990 100644 --- a/show/muxcable.py +++ b/show/muxcable.py @@ -2429,7 +2429,7 @@ def operationtime(db, port, json_output): actual_time = result.get("cable") if actual_time is not None: time = '{0:02.0f}:{1:02.0f}'.format(*divmod(int(actual_time) * 60, 60)) - result['cable'] = time + result['operation_time'] = time if json_output: click.echo("{}".format(json.dumps(result, indent=4))) diff --git a/tests/muxcable_test.py b/tests/muxcable_test.py index 7e4b4b250c..96d89bd150 100644 --- a/tests/muxcable_test.py +++ b/tests/muxcable_test.py @@ -613,6 +613,37 @@ Ethernet0 server_ipv4 10.2.1.1 added added """ + +show_muxcable_operationtime_expected_port_output="""\ +PORT ATTR OPERATION_TIME +--------- -------------- ---------------- +Ethernet0 operation_time 200 +""" + +show_muxcable_health_expected_port_output="""\ +PORT ATTR HEALTH +--------- ------------ -------- +Ethernet0 cable_health True +""" + + +show_muxcable_queueinfo_expected_port_output="""\ +PORT ATTR VALUE +--------- ---------- ------- +Ethernet0 uart_stat1 2 +Ethernet0 uart_stat2 1 +""" + +show_muxcable_resetcause_expected_port_output="""\ +PORT ATTR RESETCAUSE +--------- ----------- ------------- +Ethernet0 reset_cause reboot by xyz +""" + + + + + class TestMuxcable(object): @classmethod def setup_class(cls): @@ -2554,6 +2585,58 @@ def test_show_muxcable_hwmode_muxdirection_port_active(self): assert result.exit_code == 0 assert result.output == show_muxcable_hwmode_muxdirection_active_expected_output_json + + @mock.patch('show.muxcable.delete_all_keys_in_db_table', mock.MagicMock(return_value=0)) + @mock.patch('show.muxcable.update_and_get_response_for_xcvr_cmd', mock.MagicMock(return_value={0: 0, + 1: "True"})) + @mock.patch('show.muxcable.get_result', mock.MagicMock(return_value={"cable_health": "True"})) + def test_show_mux_health(self): + runner = CliRunner() + db = Db() + + result = runner.invoke(show.cli.commands["muxcable"].commands["health"], + ["Ethernet0"], obj=db) + assert result.output == show_muxcable_health_expected_port_output + + + @mock.patch('show.muxcable.delete_all_keys_in_db_table', mock.MagicMock(return_value=0)) + @mock.patch('show.muxcable.update_and_get_response_for_xcvr_cmd', mock.MagicMock(return_value={0: 0, + 1: "True"})) + @mock.patch('show.muxcable.get_result', mock.MagicMock(return_value={"operation_time": "200"})) + def test_show_mux_operation_time(self): + runner = CliRunner() + db = Db() + + result = runner.invoke(show.cli.commands["muxcable"].commands["operationtime"], + ["Ethernet0"], obj=db) + assert result.output == show_muxcable_operationtime_expected_port_output + + @mock.patch('show.muxcable.delete_all_keys_in_db_table', mock.MagicMock(return_value=0)) + @mock.patch('show.muxcable.update_and_get_response_for_xcvr_cmd', mock.MagicMock(return_value={0: 0, + 1: "True"})) + @mock.patch('show.muxcable.get_result', mock.MagicMock(return_value={"uart_stat1": "2", + "uart_stat2": "1"})) + def test_show_mux_queue_info(self): + runner = CliRunner() + db = Db() + + result = runner.invoke(show.cli.commands["muxcable"].commands["queueinfo"], + ["Ethernet0"], obj=db) + assert result.output == show_muxcable_queueinfo_expected_port_output + + + @mock.patch('show.muxcable.delete_all_keys_in_db_table', mock.MagicMock(return_value=0)) + @mock.patch('show.muxcable.update_and_get_response_for_xcvr_cmd', mock.MagicMock(return_value={0: 0, + 1: "True"})) + @mock.patch('show.muxcable.get_result', mock.MagicMock(return_value={"reset_cause": "reboot by xyz"})) + def test_show_mux_resetcause(self): + runner = CliRunner() + db = Db() + + result = runner.invoke(show.cli.commands["muxcable"].commands["resetcause"], + ["Ethernet0"], obj=db) + assert result.output == show_muxcable_resetcause_expected_port_output + @classmethod def teardown_class(cls): os.environ['UTILITIES_UNIT_TESTING'] = "0" From 006451c3f989794e840d7b8d76306835e9d29d6c Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Fri, 10 Feb 2023 18:54:00 +0000 Subject: [PATCH 03/25] fix all Signed-off-by: vaibhav-dahiya --- show/muxcable.py | 81 +++++++++++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 36 deletions(-) diff --git a/show/muxcable.py b/show/muxcable.py index 69df5fe990..f6fb9a7586 100644 --- a/show/muxcable.py +++ b/show/muxcable.py @@ -35,6 +35,11 @@ VENDOR_NAME = "Credo" VENDOR_MODEL_REGEX = re.compile(r"CAC\w{3}321P2P\w{2}MS") +#define table names that interact with Cli +XCVRD_GET_BER_CMD_TABLE = "XCVRD_GET_BER_CMD" +XCVRD_GET_BER_RSP_TABLE = "XCVRD_GET_BER_RSP" +XCVRD_GET_BER_RES_TABLE = "XCVRD_GET_BER_RES" +XCVRD_GET_BER_CMD_ARG_TABLE = "XCVRD_GET_BER_CMD_ARG" def get_asic_index_for_port(port): asic_index = None @@ -410,6 +415,17 @@ def update_and_get_response_for_xcvr_cmd(cmd_name, rsp_name, exp_rsp, cmd_table_ return res_dict +def delete_all_keys_in_db_tables_helper(): + + delete_all_keys_in_db_table("APPL_DB", XCVRD_GET_BER_CMD_TABLE) + delete_all_keys_in_db_table("STATE_DB", XCVRD_GET_BER_RSP_TABLE) + delete_all_keys_in_db_table("STATE_DB", XCVRD_GET_BER_RES_TABLE) + delete_all_keys_in_db_table("APPL_DB", XCVRD_GET_BER_CMD_ARG_TABLE) + + return 0 + + + # 'muxcable' command ("show muxcable") # @@ -2261,13 +2277,10 @@ def muxdirection(db, port, json_output): @click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL, help="display the output in json format") @clicommon.pass_db def queueinfo(db, port, option, json_output): - """Show muxcable debug deump registers information, preagreed by vendors""" + """Show muxcable queue info information, preagreed by vendors""" 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") - delete_all_keys_in_db_table("STATE_DB", "XCVRD_GET_BER_RES") + delete_all_keys_in_db_tables_helper() if port is not None: @@ -2287,10 +2300,7 @@ def queueinfo(db, port, option, json_output): result = get_result(port, res_dict, "fec" , result, "XCVRD_GET_BER_RES") - 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") - delete_all_keys_in_db_table("STATE_DB", "XCVRD_GET_BER_RES") + delete_all_keys_in_db_tables_helper() port = platform_sfputil_helper.get_interface_alias(port, db) if json_output: @@ -2300,7 +2310,7 @@ def queueinfo(db, port, option, json_output): res = [[port]+[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)) + click.echo("Did not get a valid Port for queue info information".format(port)) sys.exit(CONFIG_FAIL) @@ -2309,12 +2319,10 @@ def queueinfo(db, port, option, json_output): @click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL, help="display the output in json format") @clicommon.pass_db def health(db, port, json_output): - """Show muxcable health information """ + """Show muxcable health information as Ok or Not Ok """ 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") + delete_all_keys_in_db_tables_helper() if port is not None: @@ -2332,12 +2340,21 @@ def health(db, port, json_output): result = get_result(port, res_dict, "fec" , result, "XCVRD_GET_BER_RES") - 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") + delete_all_keys_in_db_tables_helper() port = platform_sfputil_helper.get_interface_alias(port, db) + cable_health = result.get("health_check", None) + + if cable_health == "False": + result["health_check"] = "Not Ok" + else if cable_health == "True": + result["health_check"] = "Ok" + else if cable_health is None: + result["health_check"] = "Unknown" + + + if json_output: click.echo("{}".format(json.dumps(result, indent=4))) else: @@ -2345,7 +2362,7 @@ def health(db, port, json_output): res = [[port]+[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)) + click.echo("Did not get a valid Port for cable health status".format(port)) sys.exit(CONFIG_FAIL) @muxcable.command() @@ -2353,12 +2370,10 @@ def health(db, port, json_output): @click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL, help="display the output in json format") @clicommon.pass_db def resetcause(db, port, json_output): - """Show muxcable health information """ + """Show muxcable resetcause information """ 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") + delete_all_keys_in_db_tables_helper() if port is not None: @@ -2376,9 +2391,7 @@ def resetcause(db, port, json_output): result = get_result(port, res_dict, "fec" , result, "XCVRD_GET_BER_RES") - 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") + delete_all_keys_in_db_tables_helper() port = platform_sfputil_helper.get_interface_alias(port, db) @@ -2389,7 +2402,7 @@ def resetcause(db, port, json_output): res = [[port]+[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)) + click.echo("Did not get a valid Port for cable resetcause information".format(port)) sys.exit(CONFIG_FAIL) @muxcable.command() @@ -2397,12 +2410,10 @@ def resetcause(db, port, json_output): @click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL, help="display the output in json format") @clicommon.pass_db def operationtime(db, port, json_output): - """Show muxcable operation time """ + """Show muxcable operation time hh:mm:ss forrmat""" 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") + delete_all_keys_in_db_tables_helper() if port is not None: @@ -2419,14 +2430,12 @@ def operationtime(db, port, json_output): if res_dict[1] == "True": result = get_result(port, res_dict, "fec" , result, "XCVRD_GET_BER_RES") - - 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") + + delete_all_keys_in_db_tables_helper() port = platform_sfputil_helper.get_interface_alias(port, db) - actual_time = result.get("cable") + actual_time = result.get("operation_time", 0) if actual_time is not None: time = '{0:02.0f}:{1:02.0f}'.format(*divmod(int(actual_time) * 60, 60)) result['operation_time'] = time @@ -2438,5 +2447,5 @@ def operationtime(db, port, json_output): res = [[port]+[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)) + click.echo("Did not get a valid Port for operation time".format(port)) sys.exit(CONFIG_FAIL) From db8b12fa125f99a350faeebd72abd55d49ad9337 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Fri, 10 Feb 2023 19:02:56 +0000 Subject: [PATCH 04/25] add all fixes Signed-off-by: vaibhav-dahiya --- show/muxcable.py | 10 +++++++++- tests/muxcable_test.py | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/show/muxcable.py b/show/muxcable.py index f6fb9a7586..734e6c9441 100644 --- a/show/muxcable.py +++ b/show/muxcable.py @@ -2319,7 +2319,15 @@ def queueinfo(db, port, option, json_output): @click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL, help="display the output in json format") @clicommon.pass_db def health(db, port, json_output): - """Show muxcable health information as Ok or Not Ok """ + """Show muxcable health information as Ok or Not Ok""" + + """ + in order to detemine whether the health of the cable is Ok + the following are checked + - the vendor name is correct able to be read + - the FW is correctly loaded for SerDes by reading the appropriate register val + - the Counters for UART are displaying healthy status + i.e Error Counters , retry Counters for UART or internal xfer protocols are below a threshold port = platform_sfputil_helper.get_interface_name(port, db) delete_all_keys_in_db_tables_helper() diff --git a/tests/muxcable_test.py b/tests/muxcable_test.py index 96d89bd150..56ba9505b9 100644 --- a/tests/muxcable_test.py +++ b/tests/muxcable_test.py @@ -623,7 +623,7 @@ show_muxcable_health_expected_port_output="""\ PORT ATTR HEALTH --------- ------------ -------- -Ethernet0 cable_health True +Ethernet0 cable_health Ok """ From bfbebf1a18994daedcf4f5d661e156c3a9b9378f Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Fri, 10 Feb 2023 19:28:08 +0000 Subject: [PATCH 05/25] add more changes Signed-off-by: vaibhav-dahiya --- doc/Command-Reference.md | 71 ++++++++++++++++++++++++++++++++++++++++ show/muxcable.py | 1 + 2 files changed, 72 insertions(+) diff --git a/doc/Command-Reference.md b/doc/Command-Reference.md index 6882e48e65..ca2de413b3 100644 --- a/doc/Command-Reference.md +++ b/doc/Command-Reference.md @@ -5953,6 +5953,77 @@ This command displays the eye info in mv(milli volts) of the port user provides 632 622 ``` + +**show muxcable health ** + +This command displays the hardware health of the Y-cable which are connected to muxcable. The resultant table or json output will show the current hadrware health of the cable as Ok, Not Ok, Unknown. + +- Usage: + ``` + show muxcable health [OPTIONS] [PORT] + ``` + +While displaying the muxcable health, users need to provide the following fields + +- PORT required - Port name should be a valid port +- --json optional - -- option to display the result in json format. By default output will be in tabular format. + + +- Example: + ``` + admin@sonic:~$ show muxcable health Ethernet4 + PORT ATTR HEALTH + --------- ------ -------- + Ethernet4 health Ok + ``` + ``` + admin@sonic:~$ show muxcable health Ethernet4 --json + ``` + ```json + { + "health": "Ok" + } + + ``` + + +**show muxcable queueinfo ** + +This command displays the queue info of the Y-cable which are connected to muxcable. The resultant table or json output will show the queue info in terms transactions for the UART stats in particular currently relevant to the MCU of the cable. + +- Usage: + ``` + show muxcable queueinfo [OPTIONS] [PORT] + ``` + +While displaying the muxcable queueinfo, users need to provide the following fields + +- PORT required - Port name should be a valid port +- --json optional - -- option to display the result in json format. By default output will be in tabular format. + + +- Example: + ``` + admin@sonic:~$ show muxcable queueinfo Ethernet0 + PORT ATTR VALUE + --------- ---------- ------- + Ethernet0 uart_stat1 2 + Ethernet0 uart_stat2 1 + ``` + ``` + admin@sonic:~$ show muxcable health Ethernet4 --json + ``` + ```json + { + "uart_stat1": "2", + "uart_stat2": "1", + + } + ``` + + + + ### Muxcable Config commands diff --git a/show/muxcable.py b/show/muxcable.py index 734e6c9441..cfc3e83bdd 100644 --- a/show/muxcable.py +++ b/show/muxcable.py @@ -2328,6 +2328,7 @@ def health(db, port, json_output): - the FW is correctly loaded for SerDes by reading the appropriate register val - the Counters for UART are displaying healthy status i.e Error Counters , retry Counters for UART or internal xfer protocols are below a threshold + """ port = platform_sfputil_helper.get_interface_name(port, db) delete_all_keys_in_db_tables_helper() From 593abbe745dc467ea86735702545c8e1d7d19b0e Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Fri, 10 Feb 2023 19:39:44 +0000 Subject: [PATCH 06/25] add doc Signed-off-by: vaibhav-dahiya --- doc/Command-Reference.md | 60 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/doc/Command-Reference.md b/doc/Command-Reference.md index ca2de413b3..7969115489 100644 --- a/doc/Command-Reference.md +++ b/doc/Command-Reference.md @@ -6021,7 +6021,67 @@ While displaying the muxcable queueinfo, users need to provide the following fie } ``` +**show muxcable operationtime ** +This command displays the operationtime of the Y-cable which are connected to muxcable. The resultant table or json output will show the current operation time of the cable as `hh:mm:ss` format. + +- Usage: + ``` + show muxcable operationtime [OPTIONS] [PORT] + ``` + +While displaying the muxcable operationtime, users need to provide the following fields + +- PORT required - Port name should be a valid port +- --json optional - -- option to display the result in json format. By default output will be in tabular format. + + +- Example: + ``` + admin@sonic:~$ show muxcable operationtime Ethernet4 + PORT ATTR OPERATION_TIME + --------- -------------- ---------------- + Ethernet4 operation_time 22.22 + ``` + ``` + admin@sonic:~$ show muxcable operationtime Ethernet4 --json + ``` + ```json + { + "operation_time": "22.22" + } + ``` + +**show muxcable resetcause ** + +This command displays the resetcause of the Y-cable which are connected to muxcable. The resultant table or json output will show the most recent reset cause of the cable as string format. + +- Usage: + ``` + show muxcable resetcause [OPTIONS] [PORT] + ``` + +While displaying the muxcable resetcause, users need to provide the following fields + +- PORT required - Port name should be a valid port +- --json optional - -- option to display the result in json format. By default output will be in tabular format. + + +- Example: + ``` + admin@sonic:~$ show muxcable resetcause Ethernet4 + PORT ATTR RESETCAUSE + --------- ----------- ------------ + Ethernet4 reset_cause 0 + ``` + ``` + admin@sonic:~$ show muxcable resetcause Ethernet4 --json + ``` + ```json + { + "reset_cause": "0" + } + ``` ### Muxcable Config commands From 579e8d06f9ba43619e8169032c4e1b606a67fe5b Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Fri, 10 Feb 2023 20:00:35 +0000 Subject: [PATCH 07/25] add bug fix Signed-off-by: vaibhav-dahiya --- show/muxcable.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/show/muxcable.py b/show/muxcable.py index cfc3e83bdd..37c4fe0dab 100644 --- a/show/muxcable.py +++ b/show/muxcable.py @@ -2357,9 +2357,9 @@ def health(db, port, json_output): if cable_health == "False": result["health_check"] = "Not Ok" - else if cable_health == "True": + elif cable_health == "True": result["health_check"] = "Ok" - else if cable_health is None: + else: result["health_check"] = "Unknown" From 9c85ea54908bcd1da9de6f8d39a7899b5b0795cc Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Fri, 10 Feb 2023 20:27:19 +0000 Subject: [PATCH 08/25] add all test fixes Signed-off-by: vaibhav-dahiya --- show/muxcable.py | 8 ++++---- tests/muxcable_test.py | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/show/muxcable.py b/show/muxcable.py index 37c4fe0dab..e11118f530 100644 --- a/show/muxcable.py +++ b/show/muxcable.py @@ -2353,14 +2353,14 @@ def health(db, port, json_output): port = platform_sfputil_helper.get_interface_alias(port, db) - cable_health = result.get("health_check", None) + cable_health = result.get("cable_health", None) if cable_health == "False": - result["health_check"] = "Not Ok" + result["cable_health"] = "Not Ok" elif cable_health == "True": - result["health_check"] = "Ok" + result["cable_health"] = "Ok" else: - result["health_check"] = "Unknown" + result["cable_health"] = "Unknown" diff --git a/tests/muxcable_test.py b/tests/muxcable_test.py index 56ba9505b9..739c0fa97d 100644 --- a/tests/muxcable_test.py +++ b/tests/muxcable_test.py @@ -616,8 +616,9 @@ show_muxcable_operationtime_expected_port_output="""\ PORT ATTR OPERATION_TIME +PORT ATTR OPERATION_TIME --------- -------------- ---------------- -Ethernet0 operation_time 200 +Ethernet0 operation_time 200:00 """ show_muxcable_health_expected_port_output="""\ From d265234c9b262e2fe0dd58882d9fb60eaf631ce7 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Fri, 10 Feb 2023 20:29:45 +0000 Subject: [PATCH 09/25] add Signed-off-by: vaibhav-dahiya --- show/muxcable.py | 8 ++++---- tests/muxcable_test.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/show/muxcable.py b/show/muxcable.py index e11118f530..37c4fe0dab 100644 --- a/show/muxcable.py +++ b/show/muxcable.py @@ -2353,14 +2353,14 @@ def health(db, port, json_output): port = platform_sfputil_helper.get_interface_alias(port, db) - cable_health = result.get("cable_health", None) + cable_health = result.get("health_check", None) if cable_health == "False": - result["cable_health"] = "Not Ok" + result["health_check"] = "Not Ok" elif cable_health == "True": - result["cable_health"] = "Ok" + result["health_check"] = "Ok" else: - result["cable_health"] = "Unknown" + result["health_check"] = "Unknown" diff --git a/tests/muxcable_test.py b/tests/muxcable_test.py index 739c0fa97d..f79161129b 100644 --- a/tests/muxcable_test.py +++ b/tests/muxcable_test.py @@ -624,7 +624,7 @@ show_muxcable_health_expected_port_output="""\ PORT ATTR HEALTH --------- ------------ -------- -Ethernet0 cable_health Ok +Ethernet0 health_check Ok """ From 58daec79e93d631766731a9d36baca3851aefd0f Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Fri, 10 Feb 2023 21:20:51 +0000 Subject: [PATCH 10/25] create better fix Signed-off-by: vaibhav-dahiya --- tests/muxcable_test.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/muxcable_test.py b/tests/muxcable_test.py index f79161129b..d00c57aa66 100644 --- a/tests/muxcable_test.py +++ b/tests/muxcable_test.py @@ -615,7 +615,6 @@ show_muxcable_operationtime_expected_port_output="""\ -PORT ATTR OPERATION_TIME PORT ATTR OPERATION_TIME --------- -------------- ---------------- Ethernet0 operation_time 200:00 @@ -2590,7 +2589,7 @@ def test_show_muxcable_hwmode_muxdirection_port_active(self): @mock.patch('show.muxcable.delete_all_keys_in_db_table', mock.MagicMock(return_value=0)) @mock.patch('show.muxcable.update_and_get_response_for_xcvr_cmd', mock.MagicMock(return_value={0: 0, 1: "True"})) - @mock.patch('show.muxcable.get_result', mock.MagicMock(return_value={"cable_health": "True"})) + @mock.patch('show.muxcable.get_result', mock.MagicMock(return_value={"health_check": "True"})) def test_show_mux_health(self): runner = CliRunner() db = Db() From fb61e87b46f3fa70f851530d7c8ebc31214f0ff0 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Mon, 13 Feb 2023 21:12:58 +0000 Subject: [PATCH 11/25] fix comments Signed-off-by: vaibhav-dahiya --- doc/Command-Reference.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/doc/Command-Reference.md b/doc/Command-Reference.md index 7969115489..e169f200f1 100644 --- a/doc/Command-Reference.md +++ b/doc/Command-Reference.md @@ -5968,6 +5968,15 @@ While displaying the muxcable health, users need to provide the following fields - PORT required - Port name should be a valid port - --json optional - -- option to display the result in json format. By default output will be in tabular format. +-Ok means the cable is healthy + +in order to detemine whether the health of the cable is Ok +the following are checked +- the vendor name is correct able to be read +- the FW is correctly loaded for SerDes by reading the appropriate register val +- the Counters for UART are displaying healthy status + i.e Error Counters , retry Counters for UART or internal xfer protocols are below a threshold + - Example: ``` @@ -6001,6 +6010,10 @@ While displaying the muxcable queueinfo, users need to provide the following fie - PORT required - Port name should be a valid port - --json optional - -- option to display the result in json format. By default output will be in tabular format. +the result will be displayed like this, each item in the dictionary shows the health of the attribute in the queue +``` +"{'VSC': {'r_ptr': 0, 'w_ptr': 0, 'total_count': 0, 'free_count': 0, 'buff_addr': 0, 'node_size': 0}, 'UART1': {'r_ptr': 0, 'w_ptr': 0, 'total_count': 0, 'free_count': 0, 'buff_addr': 209870, 'node_size': 1682183}, 'UART2': {'r_ptr': 13262, 'w_ptr': 3, 'total_count': 0, 'free_count': 0, 'buff_addr': 12, 'node_size': 0} +``` - Example: ``` @@ -6023,7 +6036,7 @@ While displaying the muxcable queueinfo, users need to provide the following fie **show muxcable operationtime ** -This command displays the operationtime of the Y-cable which are connected to muxcable. The resultant table or json output will show the current operation time of the cable as `hh:mm:ss` format. +This command displays the operationtime of the Y-cable which are connected to muxcable. The resultant table or json output will show the current operation time of the cable as `hh:mm:ss` format. Operation time means the time since the last time the start/reset of the cable is done, and the time would be in the format specified - Usage: ``` @@ -6066,6 +6079,10 @@ While displaying the muxcable resetcause, users need to provide the following fi - PORT required - Port name should be a valid port - --json optional - -- option to display the result in json format. By default output will be in tabular format. +Currently the known resetcauses that could be displayed are +- Reset Issue by the ToR +- Cable Powered on/off from the NiC +- Cable reseated from server side - Example: ``` From ba1dec1d16d20af61def7ea771144fe01e60d2df Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Mon, 13 Feb 2023 21:32:04 +0000 Subject: [PATCH 12/25] add all Signed-off-by: vaibhav-dahiya --- doc/Command-Reference.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/Command-Reference.md b/doc/Command-Reference.md index e169f200f1..c030e44665 100644 --- a/doc/Command-Reference.md +++ b/doc/Command-Reference.md @@ -6089,14 +6089,14 @@ Currently the known resetcauses that could be displayed are admin@sonic:~$ show muxcable resetcause Ethernet4 PORT ATTR RESETCAUSE --------- ----------- ------------ - Ethernet4 reset_cause 0 + Ethernet4 reset_cause reset by ToR ``` ``` admin@sonic:~$ show muxcable resetcause Ethernet4 --json ``` ```json { - "reset_cause": "0" + "reset_cause": "reset by ToR" } ``` From 4c1982c6476fec92c40586fdac65b540afd33cfd Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Mon, 13 Feb 2023 22:28:54 +0000 Subject: [PATCH 13/25] add decorator Signed-off-by: vaibhav-dahiya --- show/muxcable.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/show/muxcable.py b/show/muxcable.py index 37c4fe0dab..b7f203a207 100644 --- a/show/muxcable.py +++ b/show/muxcable.py @@ -2271,6 +2271,7 @@ def muxdirection(db, port, json_output): if rc_exit == False: sys.exit(EXIT_FAIL) +@delete_all_keys_in_db_tables_helper() @muxcable.command() @click.argument('port', metavar='', required=True, default=None) @click.argument('option', required=False, default=None) @@ -2280,7 +2281,6 @@ def queueinfo(db, port, option, json_output): """Show muxcable queue info information, preagreed by vendors""" port = platform_sfputil_helper.get_interface_name(port, db) - delete_all_keys_in_db_tables_helper() if port is not None: @@ -2300,7 +2300,6 @@ def queueinfo(db, port, option, json_output): result = get_result(port, res_dict, "fec" , result, "XCVRD_GET_BER_RES") - delete_all_keys_in_db_tables_helper() port = platform_sfputil_helper.get_interface_alias(port, db) if json_output: @@ -2314,6 +2313,7 @@ def queueinfo(db, port, option, json_output): sys.exit(CONFIG_FAIL) +@delete_all_keys_in_db_tables_helper() @muxcable.command() @click.argument('port', metavar='', required=True, default=None) @click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL, help="display the output in json format") @@ -2331,7 +2331,6 @@ def health(db, port, json_output): """ port = platform_sfputil_helper.get_interface_name(port, db) - delete_all_keys_in_db_tables_helper() if port is not None: @@ -2349,7 +2348,6 @@ def health(db, port, json_output): result = get_result(port, res_dict, "fec" , result, "XCVRD_GET_BER_RES") - delete_all_keys_in_db_tables_helper() port = platform_sfputil_helper.get_interface_alias(port, db) @@ -2374,6 +2372,7 @@ def health(db, port, json_output): click.echo("Did not get a valid Port for cable health status".format(port)) sys.exit(CONFIG_FAIL) +@delete_all_keys_in_db_tables_helper() @muxcable.command() @click.argument('port', metavar='', required=True, default=None) @click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL, help="display the output in json format") @@ -2382,7 +2381,6 @@ def resetcause(db, port, json_output): """Show muxcable resetcause information """ port = platform_sfputil_helper.get_interface_name(port, db) - delete_all_keys_in_db_tables_helper() if port is not None: @@ -2400,7 +2398,6 @@ def resetcause(db, port, json_output): result = get_result(port, res_dict, "fec" , result, "XCVRD_GET_BER_RES") - delete_all_keys_in_db_tables_helper() port = platform_sfputil_helper.get_interface_alias(port, db) @@ -2414,6 +2411,7 @@ def resetcause(db, port, json_output): click.echo("Did not get a valid Port for cable resetcause information".format(port)) sys.exit(CONFIG_FAIL) +@delete_all_keys_in_db_tables_helper() @muxcable.command() @click.argument('port', metavar='', required=True, default=None) @click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL, help="display the output in json format") @@ -2422,7 +2420,6 @@ def operationtime(db, port, json_output): """Show muxcable operation time hh:mm:ss forrmat""" port = platform_sfputil_helper.get_interface_name(port, db) - delete_all_keys_in_db_tables_helper() if port is not None: @@ -2440,7 +2437,6 @@ def operationtime(db, port, json_output): result = get_result(port, res_dict, "fec" , result, "XCVRD_GET_BER_RES") - delete_all_keys_in_db_tables_helper() port = platform_sfputil_helper.get_interface_alias(port, db) From a512b4296e5ba27ea021404984da23590a7a81dd Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Mon, 13 Feb 2023 22:56:28 +0000 Subject: [PATCH 14/25] add all Signed-off-by: vaibhav-dahiya --- show/muxcable.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/show/muxcable.py b/show/muxcable.py index b7f203a207..f2bf56f641 100644 --- a/show/muxcable.py +++ b/show/muxcable.py @@ -2271,7 +2271,7 @@ def muxdirection(db, port, json_output): if rc_exit == False: sys.exit(EXIT_FAIL) -@delete_all_keys_in_db_tables_helper() +@delete_all_keys_in_db_tables_helper @muxcable.command() @click.argument('port', metavar='', required=True, default=None) @click.argument('option', required=False, default=None) @@ -2313,7 +2313,7 @@ def queueinfo(db, port, option, json_output): sys.exit(CONFIG_FAIL) -@delete_all_keys_in_db_tables_helper() +@delete_all_keys_in_db_tables_helper @muxcable.command() @click.argument('port', metavar='', required=True, default=None) @click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL, help="display the output in json format") @@ -2372,7 +2372,7 @@ def health(db, port, json_output): click.echo("Did not get a valid Port for cable health status".format(port)) sys.exit(CONFIG_FAIL) -@delete_all_keys_in_db_tables_helper() +@delete_all_keys_in_db_tables_helper @muxcable.command() @click.argument('port', metavar='', required=True, default=None) @click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL, help="display the output in json format") @@ -2411,7 +2411,7 @@ def resetcause(db, port, json_output): click.echo("Did not get a valid Port for cable resetcause information".format(port)) sys.exit(CONFIG_FAIL) -@delete_all_keys_in_db_tables_helper() +@delete_all_keys_in_db_tables_helper @muxcable.command() @click.argument('port', metavar='', required=True, default=None) @click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL, help="display the output in json format") From 64d79fc8175d5ffaa852d648b01d7a5b4a3932a3 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Mon, 13 Feb 2023 23:30:34 +0000 Subject: [PATCH 15/25] fix Signed-off-by: vaibhav-dahiya --- show/muxcable.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/show/muxcable.py b/show/muxcable.py index f2bf56f641..9772fcc8af 100644 --- a/show/muxcable.py +++ b/show/muxcable.py @@ -415,7 +415,7 @@ def update_and_get_response_for_xcvr_cmd(cmd_name, rsp_name, exp_rsp, cmd_table_ return res_dict -def delete_all_keys_in_db_tables_helper(): +def delete_all_keys_in_db_tables_helper(db= None): delete_all_keys_in_db_table("APPL_DB", XCVRD_GET_BER_CMD_TABLE) delete_all_keys_in_db_table("STATE_DB", XCVRD_GET_BER_RSP_TABLE) From 275e670d8ae04876bbb40567380f352cea6b7b6e Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Tue, 14 Feb 2023 23:00:07 +0000 Subject: [PATCH 16/25] add Signed-off-by: vaibhav-dahiya --- show/muxcable.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/show/muxcable.py b/show/muxcable.py index 9772fcc8af..9c6a690fd6 100644 --- a/show/muxcable.py +++ b/show/muxcable.py @@ -2382,6 +2382,12 @@ def resetcause(db, port, json_output): port = platform_sfputil_helper.get_interface_name(port, db) + """ + the reset cause only records NIC MCU reset status. The NIC MCU will automatically broadcast the reset cause status to each TORs, corresponding values returned + return 0 if the last reset is cold reset (ex. HW/SW reset, power reset the cable, or reboot the NIC server) + return 1 if the last reset is warn reset (ex. sudo config mux firmware activate....) + the value is persistent, no clear on read + """ if port is not None: res_dict = {} From b526d6de5aff438d52007df4eb7aa44cc2a05df2 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Wed, 15 Feb 2023 00:16:17 +0000 Subject: [PATCH 17/25] remove some extra code Signed-off-by: vaibhav-dahiya --- show/muxcable.py | 63 ++++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/show/muxcable.py b/show/muxcable.py index 9c6a690fd6..a3a3da1bef 100644 --- a/show/muxcable.py +++ b/show/muxcable.py @@ -281,9 +281,11 @@ def get_result(port, res_dict, cmd ,result, table_name): (status, fvp) = xcvrd_show_fw_res_tbl[asic_index].get(port) res_dir = dict(fvp) + delete_all_keys_in_db_table("STATE_DB", table_name) + return res_dir -def update_and_get_response_for_xcvr_cmd(cmd_name, rsp_name, exp_rsp, cmd_table_name, cmd_arg_table_name, rsp_table_name ,port, cmd_timeout_secs, param_dict= None, arg=None): +def update_and_get_response_for_xcvr_cmd(cmd_name, rsp_name, exp_rsp, cmd_table_name, cmd_arg_table_name, rsp_table_name , res_table_name, port, cmd_timeout_secs, param_dict= None, arg=None): res_dict = {} state_db, appl_db = {}, {} @@ -296,6 +298,8 @@ def update_and_get_response_for_xcvr_cmd(cmd_name, rsp_name, exp_rsp, cmd_table_ time_start = time.time() + delete_all_keys_in_db_tables_helper(cmd_table_name, rsp_table_name, cmd_arg_table_name, res_table_name) + sel = swsscommon.Select() namespaces = multi_asic.get_front_end_namespaces() for namespace in namespaces: @@ -410,17 +414,18 @@ def update_and_get_response_for_xcvr_cmd(cmd_name, rsp_name, exp_rsp, cmd_table_ firmware_rsp_tbl[asic_index]._del(port) break - delete_all_keys_in_db_table("STATE_DB", rsp_table_name) + + delete_all_keys_in_db_tables_helper(cmd_table_name, rsp_table_name, cmd_arg_table_name, None) return res_dict -def delete_all_keys_in_db_tables_helper(db= None): +def delete_all_keys_in_db_tables_helper(cmd_table_name, rsp_table_name, cmd_arg_table_name = None, res_table_name = None): - delete_all_keys_in_db_table("APPL_DB", XCVRD_GET_BER_CMD_TABLE) - delete_all_keys_in_db_table("STATE_DB", XCVRD_GET_BER_RSP_TABLE) - delete_all_keys_in_db_table("STATE_DB", XCVRD_GET_BER_RES_TABLE) - delete_all_keys_in_db_table("APPL_DB", XCVRD_GET_BER_CMD_ARG_TABLE) + delete_all_keys_in_db_table("APPL_DB", cmd_table_name) + delete_all_keys_in_db_table("STATE_DB", rsp_table_name) + if cmd_arg_table is not None: + delete_all_keys_in_db_table("APPL_DB", cmd_arg_table_name) return 0 @@ -942,7 +947,7 @@ def berinfo(db, port, target, json_output): res_dict[1] = "unknown" res_dict = update_and_get_response_for_xcvr_cmd( - "get_ber", "status", "True", "XCVRD_GET_BER_CMD", "XCVRD_GET_BER_CMD_ARG", "XCVRD_GET_BER_RSP", port, 10, param_dict, "ber") + "get_ber", "status", "True", "XCVRD_GET_BER_CMD", "XCVRD_GET_BER_CMD_ARG", "XCVRD_GET_BER_RSP", None, port, 10, param_dict, "ber") if res_dict[1] == "True": result = get_result(port, res_dict, "fec" , result, "XCVRD_GET_BER_RES") @@ -994,7 +999,7 @@ def eyeinfo(db, port, target, json_output): res_dict[1] = "unknown" res_dict = update_and_get_response_for_xcvr_cmd( - "get_ber", "status", "True", "XCVRD_GET_BER_CMD", "XCVRD_GET_BER_CMD_ARG", "XCVRD_GET_BER_RSP", port, 10, param_dict, "eye") + "get_ber", "status", "True", "XCVRD_GET_BER_CMD", "XCVRD_GET_BER_CMD_ARG", "XCVRD_GET_BER_RSP", None, port, 10, param_dict, "eye") if res_dict[1] == "True": result = get_result(port, res_dict, "fec" , result, "XCVRD_GET_BER_RES") @@ -1045,7 +1050,7 @@ def fecstatistics(db, port, target, json_output): res_dict[1] = "unknown" res_dict = update_and_get_response_for_xcvr_cmd( - "get_ber", "status", "True", "XCVRD_GET_BER_CMD", "XCVRD_GET_BER_CMD_ARG", "XCVRD_GET_BER_RSP", port, 10, param_dict, "fec_stats") + "get_ber", "status", "True", "XCVRD_GET_BER_CMD", "XCVRD_GET_BER_CMD_ARG", "XCVRD_GET_BER_RSP", None, port, 10, param_dict, "fec_stats") if res_dict[1] == "True": result = get_result(port, res_dict, "fec" , result, "XCVRD_GET_BER_RES") @@ -1096,7 +1101,7 @@ def pcsstatistics(db, port, target, json_output): res_dict[1] = "unknown" res_dict = update_and_get_response_for_xcvr_cmd( - "get_ber", "status", "True", "XCVRD_GET_BER_CMD", "XCVRD_GET_BER_CMD_ARG", "XCVRD_GET_BER_RSP", port, 10, param_dict, "pcs_stats") + "get_ber", "status", "True", "XCVRD_GET_BER_CMD", "XCVRD_GET_BER_CMD_ARG", "XCVRD_GET_BER_RSP", None, port, 10, param_dict, "pcs_stats") if res_dict[1] == "True": result = get_result(port, res_dict, "fec" , result, "XCVRD_GET_BER_RES") @@ -1145,7 +1150,7 @@ def debugdumpregisters(db, port, option, json_output): res_dict[1] = "unknown" res_dict = update_and_get_response_for_xcvr_cmd( - "get_ber", "status", "True", "XCVRD_GET_BER_CMD", "XCVRD_GET_BER_CMD_ARG", "XCVRD_GET_BER_RSP", port, 100, param_dict, "debug_dump") + "get_ber", "status", "True", "XCVRD_GET_BER_CMD", "XCVRD_GET_BER_CMD_ARG", "XCVRD_GET_BER_RSP", None, port, 100, param_dict, "debug_dump") if res_dict[1] == "True": result = get_result(port, res_dict, "fec" , result, "XCVRD_GET_BER_RES") @@ -1189,7 +1194,7 @@ def alivecablestatus(db, port, json_output): res_dict[1] = "unknown" res_dict = update_and_get_response_for_xcvr_cmd( - "get_ber", "status", "True", "XCVRD_GET_BER_CMD", None, "XCVRD_GET_BER_RSP", port, 10, None, "cable_alive") + "get_ber", "status", "True", "XCVRD_GET_BER_CMD", None, "XCVRD_GET_BER_RSP", None, port, 10, None, "cable_alive") if res_dict[1] == "True": result = get_result(port, res_dict, "fec" , result, "XCVRD_GET_BER_RES") @@ -1261,7 +1266,7 @@ def get_hwmode_mux_direction_port(db, port): if port is not None: res_dict = update_and_get_response_for_xcvr_cmd( - "state", "state", "True", "XCVRD_SHOW_HWMODE_DIR_CMD", "XCVRD_SHOW_HWMODE_DIR_RES", "XCVRD_SHOW_HWMODE_DIR_RSP", port, HWMODE_MUXDIRECTION_TIMEOUT, None, "probe") + "state", "state", "True", "XCVRD_SHOW_HWMODE_DIR_CMD", "XCVRD_SHOW_HWMODE_DIR_RES", "XCVRD_SHOW_HWMODE_DIR_RSP", None, port, HWMODE_MUXDIRECTION_TIMEOUT, None, "probe") result = get_result(port, res_dict, "muxdirection" , result, "XCVRD_SHOW_HWMODE_DIR_RES") @@ -1480,7 +1485,7 @@ def switchmode(db, port): res_dict[0] = CONFIG_FAIL res_dict[1] = "unknown" res_dict = update_and_get_response_for_xcvr_cmd( - "state", "state", "True", "XCVRD_SHOW_HWMODE_SWMODE_CMD", None, "XCVRD_SHOW_HWMODE_SWMODE_RSP", port, 1, None, "probe") + "state", "state", "True", "XCVRD_SHOW_HWMODE_SWMODE_CMD", None, "XCVRD_SHOW_HWMODE_SWMODE_RSP", None, port, 1, None, "probe") body = [] temp_list = [] @@ -1536,7 +1541,7 @@ def switchmode(db, port): res_dict[0] = CONFIG_FAIL res_dict[1] = "unknown" res_dict = update_and_get_response_for_xcvr_cmd( - "state", "state", "True", "XCVRD_SHOW_HWMODE_SWMODE_CMD", None, "XCVRD_SHOW_HWMODE_SWMODE_RSP", port, 1, None, "probe") + "state", "state", "True", "XCVRD_SHOW_HWMODE_SWMODE_CMD", None, "XCVRD_SHOW_HWMODE_SWMODE_RSP", None, port, 1, None, "probe") port = platform_sfputil_helper.get_interface_alias(port, db) temp_list.append(port) temp_list.append(res_dict[1]) @@ -1721,7 +1726,7 @@ def version(db, port, active): mux_info_dict["version_self_next"] = "N/A" res_dict = update_and_get_response_for_xcvr_cmd( - "firmware_version", "status", "True", "XCVRD_SHOW_FW_CMD", None, "XCVRD_SHOW_FW_RSP", port, 20, None, "probe") + "firmware_version", "status", "True", "XCVRD_SHOW_FW_CMD", None, "XCVRD_SHOW_FW_RSP", None, port, 20, None, "probe") if res_dict[1] == "True": mux_info_dict = get_response_for_version(port, mux_info_dict) @@ -1890,7 +1895,7 @@ def event_log(db, port, json_output): res_dict[1] = "unknown" res_dict = update_and_get_response_for_xcvr_cmd( - "show_event", "status", "True", "XCVRD_EVENT_LOG_CMD", None, "XCVRD_EVENT_LOG_RSP", port, 1000, None, "probe") + "show_event", "status", "True", "XCVRD_EVENT_LOG_CMD", None, "XCVRD_EVENT_LOG_RSP", None, port, 1000, None, "probe") if res_dict[1] == "True": result = get_event_logs(port, res_dict, mux_info_dict) @@ -1932,7 +1937,7 @@ def get_fec_anlt_speed(db, port, json_output): res_dict[1] = "unknown" res_dict = update_and_get_response_for_xcvr_cmd( - "get_fec", "status", "True", "XCVRD_GET_FEC_CMD", None, "XCVRD_GET_FEC_RSP", port, 10, None, "probe") + "get_fec", "status", "True", "XCVRD_GET_FEC_CMD", None, "XCVRD_GET_FEC_RSP", None, port, 10, None, "probe") if res_dict[1] == "True": result = get_result(port, res_dict, "fec" , result, "XCVRD_GET_FEC_RES") @@ -2271,7 +2276,6 @@ def muxdirection(db, port, json_output): if rc_exit == False: sys.exit(EXIT_FAIL) -@delete_all_keys_in_db_tables_helper @muxcable.command() @click.argument('port', metavar='', required=True, default=None) @click.argument('option', required=False, default=None) @@ -2294,10 +2298,10 @@ def queueinfo(db, port, option, json_output): res_dict[1] = "unknown" res_dict = update_and_get_response_for_xcvr_cmd( - "get_ber", "status", "True", "XCVRD_GET_BER_CMD", "XCVRD_GET_BER_CMD_ARG", "XCVRD_GET_BER_RSP", port, 100, param_dict, "queue_info") + "get_ber", "status", "True", XCVRD_GET_BER_CMD_TABLE, XCVRD_GET_BER_CMD_ARG_TABLE, XCVRD_GET_BER_RSP_TABLE, XCVRD_GET_BER_RES_TABLE, port, 100, param_dict, "queue_info") if res_dict[1] == "True": - result = get_result(port, res_dict, "fec" , result, "XCVRD_GET_BER_RES") + result = get_result(port, res_dict, "fec" , result, XCVRD_GET_BER_RES_TABLE) port = platform_sfputil_helper.get_interface_alias(port, db) @@ -2313,7 +2317,6 @@ def queueinfo(db, port, option, json_output): sys.exit(CONFIG_FAIL) -@delete_all_keys_in_db_tables_helper @muxcable.command() @click.argument('port', metavar='', required=True, default=None) @click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL, help="display the output in json format") @@ -2342,10 +2345,10 @@ def health(db, port, json_output): res_dict[1] = "unknown" res_dict = update_and_get_response_for_xcvr_cmd( - "get_ber", "status", "True", "XCVRD_GET_BER_CMD", None, "XCVRD_GET_BER_RSP", port, 10, None, "health_check") + "get_ber", "status", "True", XCVRD_GET_BER_CMD_TABLE, None, XCVRD_GET_BER_RSP_TABLE, XCVRD_GET_BER_RES_TABLE, port, 10, None, "health_check") if res_dict[1] == "True": - result = get_result(port, res_dict, "fec" , result, "XCVRD_GET_BER_RES") + result = get_result(port, res_dict, "fec" , result, XCVRD_GET_BER_RES_TABLE) @@ -2372,7 +2375,6 @@ def health(db, port, json_output): click.echo("Did not get a valid Port for cable health status".format(port)) sys.exit(CONFIG_FAIL) -@delete_all_keys_in_db_tables_helper @muxcable.command() @click.argument('port', metavar='', required=True, default=None) @click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL, help="display the output in json format") @@ -2398,10 +2400,10 @@ def resetcause(db, port, json_output): res_dict[1] = "unknown" res_dict = update_and_get_response_for_xcvr_cmd( - "get_ber", "status", "True", "XCVRD_GET_BER_CMD", None, "XCVRD_GET_BER_RSP", port, 10, None, "reset_cause") + "get_ber", "status", "True", XCVRD_GET_BER_CMD_TABLE, None, XCVRD_GET_BER_RSP_TABLE, XCVRD_GET_BER_RES_TABLE, port, 10, None, "reset_cause") if res_dict[1] == "True": - result = get_result(port, res_dict, "fec" , result, "XCVRD_GET_BER_RES") + result = get_result(port, res_dict, "fec" , result, XCVRD_GET_BER_RES_TABLE) @@ -2417,7 +2419,6 @@ def resetcause(db, port, json_output): click.echo("Did not get a valid Port for cable resetcause information".format(port)) sys.exit(CONFIG_FAIL) -@delete_all_keys_in_db_tables_helper @muxcable.command() @click.argument('port', metavar='', required=True, default=None) @click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL, help="display the output in json format") @@ -2437,10 +2438,10 @@ def operationtime(db, port, json_output): res_dict[1] = "unknown" res_dict = update_and_get_response_for_xcvr_cmd( - "get_ber", "status", "True", "XCVRD_GET_BER_CMD", None, "XCVRD_GET_BER_RSP", port, 10, None, "operation_time") + "get_ber", "status", "True", XCVRD_GET_BER_CMD_TABLE, None, XCVRD_GET_BER_RSP_TABLE, XCVRD_GET_BER_RES_TABLE, port, 10, None, "operation_time") if res_dict[1] == "True": - result = get_result(port, res_dict, "fec" , result, "XCVRD_GET_BER_RES") + result = get_result(port, res_dict, "fec" , result, XCVRD_GET_BER_RES_TABLE) From 3f4675b8abcc41d767ebb722ce09cef44a9fc99b Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Fri, 17 Feb 2023 03:19:04 +0000 Subject: [PATCH 18/25] add more logic Signed-off-by: vaibhav-dahiya --- show/muxcable.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/show/muxcable.py b/show/muxcable.py index a3a3da1bef..ac50818754 100644 --- a/show/muxcable.py +++ b/show/muxcable.py @@ -427,6 +427,9 @@ def delete_all_keys_in_db_tables_helper(cmd_table_name, rsp_table_name, cmd_arg_ if cmd_arg_table is not None: delete_all_keys_in_db_table("APPL_DB", cmd_arg_table_name) + if res_table_name is not None: + delete_all_keys_in_db_table("STATE_DB", res_table_name) + return 0 From e66e8b3a7b68a657f7494b2af3ca3a8296ec101b Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Fri, 17 Feb 2023 04:06:50 +0000 Subject: [PATCH 19/25] add Signed-off-by: vaibhav-dahiya --- show/muxcable.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/show/muxcable.py b/show/muxcable.py index ac50818754..7c391656fd 100644 --- a/show/muxcable.py +++ b/show/muxcable.py @@ -424,7 +424,7 @@ def delete_all_keys_in_db_tables_helper(cmd_table_name, rsp_table_name, cmd_arg_ delete_all_keys_in_db_table("APPL_DB", cmd_table_name) delete_all_keys_in_db_table("STATE_DB", rsp_table_name) - if cmd_arg_table is not None: + if cmd_arg_table_name is not None: delete_all_keys_in_db_table("APPL_DB", cmd_arg_table_name) if res_table_name is not None: From aa6b16b87b70c10961818870c3728c7097bf562b Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Fri, 17 Feb 2023 19:25:00 +0000 Subject: [PATCH 20/25] add some changes for comments/more coverage Signed-off-by: vaibhav-dahiya --- doc/Command-Reference.md | 14 +++++++------- tests/muxcable_test.py | 22 ++++++++++++++++++++-- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/doc/Command-Reference.md b/doc/Command-Reference.md index c030e44665..610ef56a71 100644 --- a/doc/Command-Reference.md +++ b/doc/Command-Reference.md @@ -6036,7 +6036,7 @@ the result will be displayed like this, each item in the dictionary shows the he **show muxcable operationtime ** -This command displays the operationtime of the Y-cable which are connected to muxcable. The resultant table or json output will show the current operation time of the cable as `hh:mm:ss` format. Operation time means the time since the last time the start/reset of the cable is done, and the time would be in the format specified +This command displays the operationtime of the Y-cable which are connected to muxcable. The resultant table or json output will show the current operation time of the cable as `hh:mm:ss` format. Operation time means the time since the last time the reseated/reset of the cable is done, and the time would be in the format specified - Usage: ``` @@ -6079,24 +6079,24 @@ While displaying the muxcable resetcause, users need to provide the following fi - PORT required - Port name should be a valid port - --json optional - -- option to display the result in json format. By default output will be in tabular format. -Currently the known resetcauses that could be displayed are -- Reset Issue by the ToR -- Cable Powered on/off from the NiC -- Cable reseated from server side +the reset cause only records NIC MCU reset status. The NIC MCU will automatically broadcast the reset cause status to each TORs, corresponding values returned +return 0 if the last reset is cold reset (ex. HW/SW reset, power reset the cable, or reboot the NIC server) +return 1 if the last reset is warn reset (ex. sudo config mux firmware activate....) +the value is persistent, no clear on read - Example: ``` admin@sonic:~$ show muxcable resetcause Ethernet4 PORT ATTR RESETCAUSE --------- ----------- ------------ - Ethernet4 reset_cause reset by ToR + Ethernet4 reset_cause 0 ``` ``` admin@sonic:~$ show muxcable resetcause Ethernet4 --json ``` ```json { - "reset_cause": "reset by ToR" + "reset_cause": "0" } ``` diff --git a/tests/muxcable_test.py b/tests/muxcable_test.py index d00c57aa66..36a7cf0d70 100644 --- a/tests/muxcable_test.py +++ b/tests/muxcable_test.py @@ -641,8 +641,11 @@ """ - - +show_muxcable_health_expected_port_output_json="""\ +{ + "health_check": "Ok" +} +""" class TestMuxcable(object): @classmethod @@ -2599,6 +2602,21 @@ def test_show_mux_health(self): assert result.output == show_muxcable_health_expected_port_output + @mock.patch('show.muxcable.delete_all_keys_in_db_table', mock.MagicMock(return_value=0)) + @mock.patch('show.muxcable.update_and_get_response_for_xcvr_cmd', mock.MagicMock(return_value={0: 0, + 1: "True"})) + @mock.patch('show.muxcable.get_result', mock.MagicMock(return_value={"health_check": "True"})) + def test_show_mux_health_json(self): + runner = CliRunner() + db = Db() + + result = runner.invoke(show.cli.commands["muxcable"].commands["health"], + ["Ethernet0", "--json"], obj=db) + assert result.output == show_muxcable_health_expected_port_output_json + + + + @mock.patch('show.muxcable.delete_all_keys_in_db_table', mock.MagicMock(return_value=0)) @mock.patch('show.muxcable.update_and_get_response_for_xcvr_cmd', mock.MagicMock(return_value={0: 0, 1: "True"})) From 8bacea5dc43a6329e2139ebd5efa7ed5902f249e Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Fri, 17 Feb 2023 20:52:38 +0000 Subject: [PATCH 21/25] add cov Signed-off-by: vaibhav-dahiya --- tests/muxcable_test.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/muxcable_test.py b/tests/muxcable_test.py index 36a7cf0d70..bbb6b7a077 100644 --- a/tests/muxcable_test.py +++ b/tests/muxcable_test.py @@ -647,6 +647,14 @@ } """ + + +show_muxcable_resetcause_expected_port_output_json="""\ +{ + "reset_cause": "reboot by xyz" +} +""" + class TestMuxcable(object): @classmethod def setup_class(cls): @@ -2655,6 +2663,21 @@ def test_show_mux_resetcause(self): ["Ethernet0"], obj=db) assert result.output == show_muxcable_resetcause_expected_port_output + + + @mock.patch('show.muxcable.delete_all_keys_in_db_table', mock.MagicMock(return_value=0)) + @mock.patch('show.muxcable.update_and_get_response_for_xcvr_cmd', mock.MagicMock(return_value={0: 0, + 1: "True"})) + @mock.patch('show.muxcable.get_result', mock.MagicMock(return_value={"reset_cause": "reboot by xyz"})) + def test_show_mux_resetcause_json(self): + runner = CliRunner() + db = Db() + + result = runner.invoke(show.cli.commands["muxcable"].commands["resetcause"], + ["Ethernet0"], obj=db) + assert result.output == show_muxcable_resetcause_expected_port_output_json + + @classmethod def teardown_class(cls): os.environ['UTILITIES_UNIT_TESTING'] = "0" From e0725995321b90b230a8b280123388b5e0865240 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Fri, 17 Feb 2023 21:58:20 +0000 Subject: [PATCH 22/25] fix Signed-off-by: vaibhav-dahiya --- tests/muxcable_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/muxcable_test.py b/tests/muxcable_test.py index bbb6b7a077..714a69d4a9 100644 --- a/tests/muxcable_test.py +++ b/tests/muxcable_test.py @@ -2674,7 +2674,7 @@ def test_show_mux_resetcause_json(self): db = Db() result = runner.invoke(show.cli.commands["muxcable"].commands["resetcause"], - ["Ethernet0"], obj=db) + ["Ethernet0", "--json"], obj=db) assert result.output == show_muxcable_resetcause_expected_port_output_json From 24eb58a69d70dd30290988e698d606aeba824a63 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Fri, 24 Feb 2023 02:31:29 +0000 Subject: [PATCH 23/25] add all Signed-off-by: vaibhav-dahiya --- doc/Command-Reference.md | 14 +++++++------- show/muxcable.py | 11 ++++++++++- tests/muxcable_test.py | 8 ++++---- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/doc/Command-Reference.md b/doc/Command-Reference.md index 610ef56a71..5112a8340d 100644 --- a/doc/Command-Reference.md +++ b/doc/Command-Reference.md @@ -6024,7 +6024,7 @@ the result will be displayed like this, each item in the dictionary shows the he Ethernet0 uart_stat2 1 ``` ``` - admin@sonic:~$ show muxcable health Ethernet4 --json + admin@sonic:~$ show muxcable queueinfo Ethernet4 --json ``` ```json { @@ -6054,14 +6054,14 @@ While displaying the muxcable operationtime, users need to provide the following admin@sonic:~$ show muxcable operationtime Ethernet4 PORT ATTR OPERATION_TIME --------- -------------- ---------------- - Ethernet4 operation_time 22.22 + Ethernet4 operation_time 00:22:22 ``` ``` admin@sonic:~$ show muxcable operationtime Ethernet4 --json ``` ```json { - "operation_time": "22.22" + "operation_time": "00:22:22" } ``` @@ -6080,8 +6080,8 @@ While displaying the muxcable resetcause, users need to provide the following fi - --json optional - -- option to display the result in json format. By default output will be in tabular format. the reset cause only records NIC MCU reset status. The NIC MCU will automatically broadcast the reset cause status to each TORs, corresponding values returned -return 0 if the last reset is cold reset (ex. HW/SW reset, power reset the cable, or reboot the NIC server) -return 1 if the last reset is warn reset (ex. sudo config mux firmware activate....) +display cold reset if the last reset is cold reset (ex. HW/SW reset, power reset the cable, or reboot the NIC server) +display warm reset if the last reset is warm reset (ex. sudo config mux firmware activate....) the value is persistent, no clear on read - Example: @@ -6089,14 +6089,14 @@ the value is persistent, no clear on read admin@sonic:~$ show muxcable resetcause Ethernet4 PORT ATTR RESETCAUSE --------- ----------- ------------ - Ethernet4 reset_cause 0 + Ethernet4 reset_cause warm reset ``` ``` admin@sonic:~$ show muxcable resetcause Ethernet4 --json ``` ```json { - "reset_cause": "0" + "reset_cause": "warm reset" } ``` diff --git a/show/muxcable.py b/show/muxcable.py index 7c391656fd..87bd4321ab 100644 --- a/show/muxcable.py +++ b/show/muxcable.py @@ -2390,7 +2390,7 @@ def resetcause(db, port, json_output): """ the reset cause only records NIC MCU reset status. The NIC MCU will automatically broadcast the reset cause status to each TORs, corresponding values returned return 0 if the last reset is cold reset (ex. HW/SW reset, power reset the cable, or reboot the NIC server) - return 1 if the last reset is warn reset (ex. sudo config mux firmware activate....) + return 1 if the last reset is warm reset (ex. sudo config mux firmware activate....) the value is persistent, no clear on read """ if port is not None: @@ -2412,6 +2412,15 @@ def resetcause(db, port, json_output): port = platform_sfputil_helper.get_interface_alias(port, db) + reset_cause = result.get("reset_cause", None) + + if cable_health == "0": + result["reset_cause"] = "cold reset" + elif cable_health == "1": + result["reset_cause"] = "warm reset" + else: + result["reset_cause"] = "Unknown" + if json_output: click.echo("{}".format(json.dumps(result, indent=4))) else: diff --git a/tests/muxcable_test.py b/tests/muxcable_test.py index 714a69d4a9..db98c4a108 100644 --- a/tests/muxcable_test.py +++ b/tests/muxcable_test.py @@ -637,7 +637,7 @@ show_muxcable_resetcause_expected_port_output="""\ PORT ATTR RESETCAUSE --------- ----------- ------------- -Ethernet0 reset_cause reboot by xyz +Ethernet0 reset_cause warm reset """ @@ -651,7 +651,7 @@ show_muxcable_resetcause_expected_port_output_json="""\ { - "reset_cause": "reboot by xyz" + "reset_cause": "warm reset" } """ @@ -2654,7 +2654,7 @@ def test_show_mux_queue_info(self): @mock.patch('show.muxcable.delete_all_keys_in_db_table', mock.MagicMock(return_value=0)) @mock.patch('show.muxcable.update_and_get_response_for_xcvr_cmd', mock.MagicMock(return_value={0: 0, 1: "True"})) - @mock.patch('show.muxcable.get_result', mock.MagicMock(return_value={"reset_cause": "reboot by xyz"})) + @mock.patch('show.muxcable.get_result', mock.MagicMock(return_value={"reset_cause": "1"})) def test_show_mux_resetcause(self): runner = CliRunner() db = Db() @@ -2668,7 +2668,7 @@ def test_show_mux_resetcause(self): @mock.patch('show.muxcable.delete_all_keys_in_db_table', mock.MagicMock(return_value=0)) @mock.patch('show.muxcable.update_and_get_response_for_xcvr_cmd', mock.MagicMock(return_value={0: 0, 1: "True"})) - @mock.patch('show.muxcable.get_result', mock.MagicMock(return_value={"reset_cause": "reboot by xyz"})) + @mock.patch('show.muxcable.get_result', mock.MagicMock(return_value={"reset_cause": "1"})) def test_show_mux_resetcause_json(self): runner = CliRunner() db = Db() From 2831060d2f52cbf7c40421f478162d4ca54377c9 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Fri, 24 Feb 2023 03:08:16 +0000 Subject: [PATCH 24/25] add all Signed-off-by: vaibhav-dahiya --- show/muxcable.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/show/muxcable.py b/show/muxcable.py index 87bd4321ab..837e362789 100644 --- a/show/muxcable.py +++ b/show/muxcable.py @@ -2414,9 +2414,9 @@ def resetcause(db, port, json_output): reset_cause = result.get("reset_cause", None) - if cable_health == "0": + if reset_cause == "0": result["reset_cause"] = "cold reset" - elif cable_health == "1": + elif reset_cause == "1": result["reset_cause"] = "warm reset" else: result["reset_cause"] = "Unknown" From c35cab8991dd9a15e273fcd91077ec477760ecb9 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Fri, 24 Feb 2023 03:38:35 +0000 Subject: [PATCH 25/25] add minor fix Signed-off-by: vaibhav-dahiya --- tests/muxcable_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/muxcable_test.py b/tests/muxcable_test.py index db98c4a108..0405b27d87 100644 --- a/tests/muxcable_test.py +++ b/tests/muxcable_test.py @@ -636,7 +636,7 @@ show_muxcable_resetcause_expected_port_output="""\ PORT ATTR RESETCAUSE ---------- ----------- ------------- +--------- ----------- ------------ Ethernet0 reset_cause warm reset """