From 0ad0815272eb905de008f50a828e154a421d7775 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Sat, 15 Oct 2022 01:05:25 +0000 Subject: [PATCH 01/14] [show][muxcable] add support for show mux firmware version all Signed-off-by: vaibhav-dahiya --- show/muxcable.py | 98 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 96 insertions(+), 2 deletions(-) diff --git a/show/muxcable.py b/show/muxcable.py index e639890ce9..2b87cc0561 100644 --- a/show/muxcable.py +++ b/show/muxcable.py @@ -97,6 +97,45 @@ def check_port_in_mux_cable_table(port): return False + +def get_per_port_firmware(port): + + state_db = {} + muxcable_info_tbl = {} + mux_info_dict = {} + + # Getting all front asic namespace and correspding config and state DB connector + + namespaces = multi_asic.get_front_end_namespaces() + for namespace in namespaces: + asic_id = multi_asic.get_asic_index_from_namespace(namespace) + state_db[asic_id] = db_connect("STATE_DB", namespace) + muxcable_info_tbl[asic_id] = swsscommon.Table(state_db[asic_id], "MUX_CABLE_INFO") + + if platform_sfputil is not None: + asic_index = platform_sfputil_helper.get_asic_id_for_logical_port(port) + + if asic_index is None: + # TODO this import is only for unit test purposes, and should be removed once sonic_platform_base + # is fully mocked + import sonic_platform_base.sonic_sfp.sfputilhelper + asic_index = sonic_platform_base.sonic_sfp.sfputilhelper.SfpUtilHelper().get_asic_id_for_logical_port(port) + if asic_index is None: + click.echo("Got invalid asic index for port {}, cant retrieve mux cable table entries".format(port)) + return False + + (status, fvp) = muxcable_info_tbl[asic_index].get(port) + if status is False : + click.echo("Got invalid status for state DB, cant retrieve mux cable info entries".format(port)) + return False + + res_dir = dict(fvp) + mux_info_dict["version_nic_active"] = res_dir.get("version_nic_active", None) + mux_info_dict["version_peer_active"] = res_dir.get("version_peer_active", None) + mux_info_dict["version_self_active"] = res_dir.get("version_self_active", None) + + return mux_info_dict + def get_response_for_version(port, mux_info_dict): state_db = {} xcvrd_show_fw_res_tbl = {} @@ -1528,7 +1567,7 @@ def version(db, port, active): 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 port is not None: + if port is not None and port != "all": res_dict = {} mux_info_dict, mux_info_active_dict = {}, {} @@ -1561,6 +1600,60 @@ def version(db, port, active): click.echo("{}".format(json.dumps(mux_info_active_dict, indent=4))) else: click.echo("{}".format(json.dumps(mux_info_dict, indent=4))) + + elif port == "all" and port is not None: + + logical_port_list = platform_sfputil_helper.get_logical_list() + + rc_exit = True + print_data = [] + + for port in logical_port_list: + + if platform_sfputil is not None: + physical_port_list = platform_sfputil_helper.logical_port_name_to_physical_port_list(port) + + if not isinstance(physical_port_list, list): + continue + if len(physical_port_list) != 1: + continue + + if not check_port_in_mux_cable_table(port): + continue + + physical_port = physical_port_list[0] + + logical_port_list_for_physical_port = platform_sfputil_helper.get_physical_to_logical() + + logical_port_list_per_port = logical_port_list_for_physical_port.get(physical_port, None) + + """ This check is required for checking whether or not this logical port is the one which is + actually mapped to physical port and by convention it is always the first port. + TODO: this should be removed with more logic to check which logical port maps to actual physical port + being used""" + + if port != logical_port_list_per_port[0]: + continue + + + port = platform_sfputil_helper.get_interface_alias(port, db) + + mux_info = get_per_port_firmware(port) + if not isinstance(mux_info, dict): + mux_info = {} + + for key, val in mux_info.items(): + print_port_data = [] + port = platform_sfputil_helper.get_interface_alias(port, db) + print_port_data.append(port) + print_port_data.append(key) + print_port_data.append(val) + print_data.append(print_port_data) + + headers = ['PORT', 'SIDE', 'VERSION'] + click.echo(tabulate(print_data, headers=headers)) + + sys.exit(CONFIG_SUCCESSFUL) else: port_name = platform_sfputil_helper.get_interface_name(port, db) click.echo("Did not get a valid Port for mux firmware version".format(port_name)) @@ -1640,6 +1733,7 @@ def metrics(db, port, json_output): def event_log(db, port, json_output): """Show muxcable event log """ + click.confirm(('Muxcable at port {} will retreive cable logs from MCU, approx time could be ~2 minutes wait time Continue?'.format(port), abort=True) 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") @@ -1735,7 +1829,7 @@ def packetloss(db, port, json_output): for namespace in namespaces: asic_id = multi_asic.get_asic_index_from_namespace(namespace) - per_npu_statedb[asic_id] = swsscommon.SonicV2Connector(use_unix_socket_path=True, namespace=namespace) + per_npu_statedb[asic_id] = swsscommon.SonicV2Connector(use_unix_socket_path=False, namespace=namespace) per_npu_statedb[asic_id].connect(per_npu_statedb[asic_id].STATE_DB) pckloss_table_keys[asic_id] = per_npu_statedb[asic_id].keys( From a3995039ead411ead6256f7bde05a0ffd7752a45 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Tue, 18 Oct 2022 19:15:42 +0000 Subject: [PATCH 02/14] fix msg Signed-off-by: vaibhav-dahiya --- show/muxcable.py | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/show/muxcable.py b/show/muxcable.py index 2b87cc0561..e190f89288 100644 --- a/show/muxcable.py +++ b/show/muxcable.py @@ -1606,7 +1606,6 @@ def version(db, port, active): logical_port_list = platform_sfputil_helper.get_logical_list() rc_exit = True - print_data = [] for port in logical_port_list: @@ -1638,22 +1637,28 @@ def version(db, port, active): port = platform_sfputil_helper.get_interface_alias(port, db) - mux_info = get_per_port_firmware(port) - if not isinstance(mux_info, dict): - mux_info = {} + mux_info_dict = get_per_port_firmware(port) + if not isinstance(mux_info_dict, dict): + mux_info_dict = {} + rc_exit = False + + mux_info = {} + mux_info_active_dict = {} + if active is True: + for key in mux_info_dict: + if key.endswith("_active"): + mux_info_active_dict[key] = mux_info_dict[key] + mux_info[port] = mux_info_active_dict + click.echo("{}".format(json.dumps(mux_info, indent=4))) + else: + mux_info[port] = mux_info_dict + click.echo("{}".format(json.dumps(mux_info, indent=4))) - for key, val in mux_info.items(): - print_port_data = [] - port = platform_sfputil_helper.get_interface_alias(port, db) - print_port_data.append(port) - print_port_data.append(key) - print_port_data.append(val) - print_data.append(print_port_data) + if rc_exit == False: + sys.exit(EXIT_FAIL) - headers = ['PORT', 'SIDE', 'VERSION'] - click.echo(tabulate(print_data, headers=headers)) + sys.exit(CONFIG_SUCCESSFUL) - sys.exit(CONFIG_SUCCESSFUL) else: port_name = platform_sfputil_helper.get_interface_name(port, db) click.echo("Did not get a valid Port for mux firmware version".format(port_name)) From 818779892518cc3d3c4d43ad330d7573a0ac4362 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Tue, 18 Oct 2022 19:18:32 +0000 Subject: [PATCH 03/14] fix logic 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 e190f89288..efef287bc6 100644 --- a/show/muxcable.py +++ b/show/muxcable.py @@ -131,8 +131,14 @@ def get_per_port_firmware(port): res_dir = dict(fvp) mux_info_dict["version_nic_active"] = res_dir.get("version_nic_active", None) + mux_info_dict["version_nic_inactive"] = res_dir.get("version_nic_inactive", None) + mux_info_dict["version_nic_next"] = res_dir.get("version_nic_next", None) mux_info_dict["version_peer_active"] = res_dir.get("version_peer_active", None) + mux_info_dict["version_peer_inactive"] = res_dir.get("version_peer_inactive", None) + mux_info_dict["version_peer_next"] = res_dir.get("version_peer_next", None) mux_info_dict["version_self_active"] = res_dir.get("version_self_active", None) + mux_info_dict["version_self_inactive"] = res_dir.get("version_self_inactive", None) + mux_info_dict["version_self_next"] = res_dir.get("version_self_next", None) return mux_info_dict From f2572bae6012d396064e9b7aac70027e7945b3da Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Tue, 18 Oct 2022 22:21:22 +0000 Subject: [PATCH 04/14] fix LGTM Signed-off-by: vaibhav-dahiya --- show/muxcable.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/show/muxcable.py b/show/muxcable.py index efef287bc6..c3000c792c 100644 --- a/show/muxcable.py +++ b/show/muxcable.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python3 + import json import sys import time @@ -1744,7 +1746,7 @@ def metrics(db, port, json_output): def event_log(db, port, json_output): """Show muxcable event log """ - click.confirm(('Muxcable at port {} will retreive cable logs from MCU, approx time could be ~2 minutes wait time Continue?'.format(port), abort=True) + click.confirm(('Muxcable at port {} will retreive cable logs from MCU, Caution: approx wait time could be ~2 minutes Continue?'.format(port), abort=True) 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") From 2f16fc8b16f10c82b9d4db7df36693d58418fe1a Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Thu, 20 Oct 2022 21:28:29 +0000 Subject: [PATCH 05/14] fix logic Signed-off-by: vaibhav-dahiya --- show/muxcable.py | 1 - 1 file changed, 1 deletion(-) diff --git a/show/muxcable.py b/show/muxcable.py index c3000c792c..6fcf426f26 100644 --- a/show/muxcable.py +++ b/show/muxcable.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python3 import json import sys From d4f860f3850d527f4d4bd7f12ab6a54544398dd4 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Thu, 20 Oct 2022 21:51:13 +0000 Subject: [PATCH 06/14] indent 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 6fcf426f26..744287fcdf 100644 --- a/show/muxcable.py +++ b/show/muxcable.py @@ -1608,7 +1608,7 @@ def version(db, port, active): else: click.echo("{}".format(json.dumps(mux_info_dict, indent=4))) - elif port == "all" and port is not None: + elif port == "all" and port is not None: logical_port_list = platform_sfputil_helper.get_logical_list() From 222fce8ba6a1780f99074ece964bb98372a2c068 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Thu, 20 Oct 2022 22:34:14 +0000 Subject: [PATCH 07/14] fix tests Signed-off-by: vaibhav-dahiya --- show/muxcable.py | 2 +- tests/muxcable_test.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/show/muxcable.py b/show/muxcable.py index 744287fcdf..537fa12b39 100644 --- a/show/muxcable.py +++ b/show/muxcable.py @@ -1745,7 +1745,7 @@ def metrics(db, port, json_output): def event_log(db, port, json_output): """Show muxcable event log """ - click.confirm(('Muxcable at port {} will retreive cable logs from MCU, Caution: approx wait time could be ~2 minutes Continue?'.format(port), abort=True) + click.confirm(('Muxcable at port {} will retreive cable logs from MCU, Caution: approx wait time could be ~2 minutes Continue?'.format(port)), abort=True) 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") diff --git a/tests/muxcable_test.py b/tests/muxcable_test.py index 965ae91ea8..155aaf5d3a 100644 --- a/tests/muxcable_test.py +++ b/tests/muxcable_test.py @@ -980,6 +980,7 @@ def test_show_mux_fecstatistics(self): assert result.exit_code == 0 + @mock.patch('click.confirm', mock.MagicMock(return_value=("y"))) @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 a62cb96f22826cd8b5d029f318165b5ea00389f9 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Fri, 21 Oct 2022 01:10:29 +0000 Subject: [PATCH 08/14] add UT Signed-off-by: vaibhav-dahiya --- tests/muxcable_test.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/muxcable_test.py b/tests/muxcable_test.py index 155aaf5d3a..8a09dfd39e 100644 --- a/tests/muxcable_test.py +++ b/tests/muxcable_test.py @@ -1429,6 +1429,23 @@ def test_show_muxcable_firmware_version(self): assert result.exit_code == 0 assert result.output == show_muxcable_firmware_version_expected_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('utilities_common.platform_sfputil_helper.get_logical_list', mock.MagicMock(return_value=["Ethernet0", "Ethernet12"])) + @mock.patch('utilities_common.platform_sfputil_helper.get_asic_id_for_logical_port', mock.MagicMock(return_value=0)) + @mock.patch('show.muxcable.platform_sfputil', mock.MagicMock(return_value={0: ["Ethernet12", "Ethernet0"]})) + @mock.patch('utilities_common.platform_sfputil_helper.get_physical_to_logical', mock.MagicMock(return_value={0: ["Ethernet12", "Ethernet0"]})) + @mock.patch('utilities_common.platform_sfputil_helper.logical_port_name_to_physical_port_list', mock.MagicMock(return_value=[0])) + def test_show_muxcable_firmware_version(self): + runner = CliRunner() + db = Db() + + result = runner.invoke(show.cli.commands["muxcable"].commands["firmware"].commands["version"], [ + "all"], obj=db) + assert result.exit_code == 0 + @mock.patch('config.muxcable.delete_all_keys_in_db_table', mock.MagicMock(return_value=0)) @mock.patch('config.muxcable.update_and_get_response_for_xcvr_cmd', mock.MagicMock(return_value={0: 0, 1: "sucess"})) From 91b591a1b302ac1c05adac2e15b48be2f1f8df8c Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Fri, 21 Oct 2022 02:29:46 +0000 Subject: [PATCH 09/14] fix UT Signed-off-by: vaibhav-dahiya --- show/muxcable.py | 12 ++++++------ tests/mock_tables/state_db.json | 24 ++++++++++++++++++++++++ tests/muxcable_test.py | 3 ++- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/show/muxcable.py b/show/muxcable.py index 537fa12b39..ba9ad67344 100644 --- a/show/muxcable.py +++ b/show/muxcable.py @@ -110,7 +110,8 @@ def get_per_port_firmware(port): namespaces = multi_asic.get_front_end_namespaces() for namespace in namespaces: asic_id = multi_asic.get_asic_index_from_namespace(namespace) - state_db[asic_id] = db_connect("STATE_DB", namespace) + state_db[asic_id] = SonicV2Connector(use_unix_socket_path=False, namespace=namespace) + state_db[asic_id].connect(statedb[asic_id].STATE_DB) muxcable_info_tbl[asic_id] = swsscommon.Table(state_db[asic_id], "MUX_CABLE_INFO") if platform_sfputil is not None: @@ -125,12 +126,11 @@ def get_per_port_firmware(port): click.echo("Got invalid asic index for port {}, cant retrieve mux cable table entries".format(port)) return False - (status, fvp) = muxcable_info_tbl[asic_index].get(port) - if status is False : - click.echo("Got invalid status for state DB, cant retrieve mux cable info entries".format(port)) - return False - res_dir = dict(fvp) + muxcable_grpc_dict[asic_index] = per_npu_statedb[asic_index].get_all( + per_npu_statedb[asic_index].STATE_DB, 'MUX_CABLE_INFO|{}'.format(port)) + + res_dir = muxcable_grpc_dict mux_info_dict["version_nic_active"] = res_dir.get("version_nic_active", None) mux_info_dict["version_nic_inactive"] = res_dir.get("version_nic_inactive", None) mux_info_dict["version_nic_next"] = res_dir.get("version_nic_next", None) diff --git a/tests/mock_tables/state_db.json b/tests/mock_tables/state_db.json index 5e66e5b7d7..12afce9372 100644 --- a/tests/mock_tables/state_db.json +++ b/tests/mock_tables/state_db.json @@ -365,6 +365,30 @@ "Name": "CRC-32", "Value": "0xAC518FB3" }, + "MUX_CABLE_INFO|Ethernet0": { + "version_peer_next": "0.1MS", + "version_peer_active": "0.1MS", + "version_peer_inactive": "0.1MS", + "version_nic_next": "0.1MS", + "version_nic_active": "0.1MS", + "version_nic_inactive": "0.1MS", + "version_self_next": "0.1MS", + "version_self_active": "0.1MS", + "version_self_inactive": "0.1MS", + "Value": "AABB" + }, + "MUX_CABLE_INFO|Ethernet12": { + "version_peer_next": "0.1MS", + "version_peer_active": "0.1MS", + "version_peer_inactive": "0.1MS", + "version_nic_next": "0.1MS", + "version_nic_active": "0.1MS", + "version_nic_inactive": "0.1MS", + "version_self_next": "0.1MS", + "version_self_active": "0.1MS", + "version_self_inactive": "0.1MS", + "Value": "AABB" + }, "SWITCH_CAPABILITY|switch": { "MIRROR": "true", "MIRRORV6": "true", diff --git a/tests/muxcable_test.py b/tests/muxcable_test.py index 8a09dfd39e..427f6e0ff4 100644 --- a/tests/muxcable_test.py +++ b/tests/muxcable_test.py @@ -1436,9 +1436,10 @@ def test_show_muxcable_firmware_version(self): @mock.patch('utilities_common.platform_sfputil_helper.get_logical_list', mock.MagicMock(return_value=["Ethernet0", "Ethernet12"])) @mock.patch('utilities_common.platform_sfputil_helper.get_asic_id_for_logical_port', mock.MagicMock(return_value=0)) @mock.patch('show.muxcable.platform_sfputil', mock.MagicMock(return_value={0: ["Ethernet12", "Ethernet0"]})) + @mock.patch('utilities_common.platform_sfputil_helper.get_logical_list', mock.MagicMock(return_value=["Ethernet0", "Ethernet12"])) @mock.patch('utilities_common.platform_sfputil_helper.get_physical_to_logical', mock.MagicMock(return_value={0: ["Ethernet12", "Ethernet0"]})) @mock.patch('utilities_common.platform_sfputil_helper.logical_port_name_to_physical_port_list', mock.MagicMock(return_value=[0])) - def test_show_muxcable_firmware_version(self): + def test_show_muxcable_firmware_version_all(self): runner = CliRunner() db = Db() From f8e3ff8dcd89b0894e12df601f4f398674e4052e Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Fri, 21 Oct 2022 18:14:47 +0000 Subject: [PATCH 10/14] fix UT Signed-off-by: vaibhav-dahiya --- show/muxcable.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/show/muxcable.py b/show/muxcable.py index ba9ad67344..26799c3511 100644 --- a/show/muxcable.py +++ b/show/muxcable.py @@ -104,6 +104,7 @@ def get_per_port_firmware(port): state_db = {} muxcable_info_tbl = {} mux_info_dict = {} + mux_info_full_dict = {} # Getting all front asic namespace and correspding config and state DB connector @@ -111,8 +112,7 @@ def get_per_port_firmware(port): for namespace in namespaces: asic_id = multi_asic.get_asic_index_from_namespace(namespace) state_db[asic_id] = SonicV2Connector(use_unix_socket_path=False, namespace=namespace) - state_db[asic_id].connect(statedb[asic_id].STATE_DB) - muxcable_info_tbl[asic_id] = swsscommon.Table(state_db[asic_id], "MUX_CABLE_INFO") + state_db[asic_id].connect(state_db[asic_id].STATE_DB) if platform_sfputil is not None: asic_index = platform_sfputil_helper.get_asic_id_for_logical_port(port) @@ -127,10 +127,11 @@ def get_per_port_firmware(port): return False - muxcable_grpc_dict[asic_index] = per_npu_statedb[asic_index].get_all( - per_npu_statedb[asic_index].STATE_DB, 'MUX_CABLE_INFO|{}'.format(port)) + mux_info_full_dict[asic_index] = state_db[asic_index].get_all( + state_db[asic_index].STATE_DB, 'MUX_CABLE_INFO|{}'.format(port)) - res_dir = muxcable_grpc_dict + res_dir = {} + res_dir = mux_info_full_dict[asic_index] mux_info_dict["version_nic_active"] = res_dir.get("version_nic_active", None) mux_info_dict["version_nic_inactive"] = res_dir.get("version_nic_inactive", None) mux_info_dict["version_nic_next"] = res_dir.get("version_nic_next", None) From 148eff73b8fccb8195d90a862d935fef9f7b9524 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Fri, 21 Oct 2022 18:39:16 +0000 Subject: [PATCH 11/14] fix LGTM Signed-off-by: vaibhav-dahiya --- show/muxcable.py | 1 - tests/muxcable_test.py | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/show/muxcable.py b/show/muxcable.py index 26799c3511..62a4d8d6c8 100644 --- a/show/muxcable.py +++ b/show/muxcable.py @@ -102,7 +102,6 @@ def check_port_in_mux_cable_table(port): def get_per_port_firmware(port): state_db = {} - muxcable_info_tbl = {} mux_info_dict = {} mux_info_full_dict = {} diff --git a/tests/muxcable_test.py b/tests/muxcable_test.py index 427f6e0ff4..af5db24577 100644 --- a/tests/muxcable_test.py +++ b/tests/muxcable_test.py @@ -1446,6 +1446,26 @@ def test_show_muxcable_firmware_version_all(self): result = runner.invoke(show.cli.commands["muxcable"].commands["firmware"].commands["version"], [ "all"], obj=db) assert result.exit_code == 0 + assert result.output == show_muxcable_firmware_version_expected_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('utilities_common.platform_sfputil_helper.get_logical_list', mock.MagicMock(return_value=["Ethernet0", "Ethernet12"])) + @mock.patch('utilities_common.platform_sfputil_helper.get_asic_id_for_logical_port', mock.MagicMock(return_value=1)) + @mock.patch('show.muxcable.platform_sfputil', mock.MagicMock(return_value={0: ["Ethernet12", "Ethernet0"]})) + @mock.patch('utilities_common.platform_sfputil_helper.get_logical_list', mock.MagicMock(return_value=["Ethernet0", "Ethernet12"])) + @mock.patch('utilities_common.platform_sfputil_helper.get_physical_to_logical', mock.MagicMock(return_value={0: ["Ethernet12", "Ethernet0"]})) + @mock.patch('utilities_common.platform_sfputil_helper.logical_port_name_to_physical_port_list', mock.MagicMock(return_value=[0])) + def test_show_muxcable_firmware_version_all_bad_asic_index(self): + runner = CliRunner() + db = Db() + + result = runner.invoke(show.cli.commands["muxcable"].commands["firmware"].commands["version"], [ + "all"], obj=db) + assert result.exit_code == 1 + @mock.patch('config.muxcable.delete_all_keys_in_db_table', mock.MagicMock(return_value=0)) @mock.patch('config.muxcable.update_and_get_response_for_xcvr_cmd', mock.MagicMock(return_value={0: 0, From 62faf157db5067d15d69224b6cc4f7ed9149eba2 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Fri, 21 Oct 2022 21:48:36 +0000 Subject: [PATCH 12/14] fix test Signed-off-by: vaibhav-dahiya --- tests/mock_tables/state_db.json | 18 +++++++++--------- tests/muxcable_test.py | 21 ++++++++++++++++++++- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/tests/mock_tables/state_db.json b/tests/mock_tables/state_db.json index 12afce9372..a042c3e85f 100644 --- a/tests/mock_tables/state_db.json +++ b/tests/mock_tables/state_db.json @@ -366,15 +366,15 @@ "Value": "0xAC518FB3" }, "MUX_CABLE_INFO|Ethernet0": { - "version_peer_next": "0.1MS", - "version_peer_active": "0.1MS", - "version_peer_inactive": "0.1MS", - "version_nic_next": "0.1MS", - "version_nic_active": "0.1MS", - "version_nic_inactive": "0.1MS", - "version_self_next": "0.1MS", - "version_self_active": "0.1MS", - "version_self_inactive": "0.1MS", + "version_peer_next": "0.2MS", + "version_peer_active": "0.2MS", + "version_peer_inactive": "0.2MS", + "version_nic_next": "0.2MS", + "version_nic_active": "0.2MS", + "version_nic_inactive": "0.2MS", + "version_self_next": "0.2MS", + "version_self_active": "0.2MS", + "version_self_inactive": "0.2MS", "Value": "AABB" }, "MUX_CABLE_INFO|Ethernet12": { diff --git a/tests/muxcable_test.py b/tests/muxcable_test.py index af5db24577..bcbd10f1c1 100644 --- a/tests/muxcable_test.py +++ b/tests/muxcable_test.py @@ -422,6 +422,23 @@ } """ +show_muxcable_firmware_version_all_expected_output = """\ +{ + "Ethernet12": { + "version_nic_active": "0.1MS", + "version_nic_inactive": "0.1MS", + "version_nic_next": "0.1MS", + "version_peer_active": "0.1MS", + "version_peer_inactive": "0.1MS", + "version_peer_next": "0.1MS", + "version_self_active": "0.1MS", + "version_self_inactive": "0.1MS", + "version_self_next": "0.1MS" + } +} +""" + + show_muxcable_firmware_version_active_expected_output = """\ { "version_self_active": "0.6MS", @@ -1446,7 +1463,9 @@ def test_show_muxcable_firmware_version_all(self): result = runner.invoke(show.cli.commands["muxcable"].commands["firmware"].commands["version"], [ "all"], obj=db) assert result.exit_code == 0 - assert result.output == show_muxcable_firmware_version_expected_output + f = open("newfile", "w") + f.write(result.output) + assert result.output == show_muxcable_firmware_version_all_expected_output @mock.patch('show.muxcable.delete_all_keys_in_db_table', mock.MagicMock(return_value=0)) From 2006ead37db516503592331b9bead1cd3581d2f1 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Fri, 21 Oct 2022 22:37:22 +0000 Subject: [PATCH 13/14] fix all Signed-off-by: vaibhav-dahiya --- tests/muxcable_test.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/muxcable_test.py b/tests/muxcable_test.py index bcbd10f1c1..8e6b924c28 100644 --- a/tests/muxcable_test.py +++ b/tests/muxcable_test.py @@ -438,6 +438,17 @@ } """ +show_muxcable_firmware_version_all_active_expected_output = """\ +{ + "Ethernet12": { + "version_nic_active": "0.1MS", + "version_peer_active": "0.1MS", + "version_self_active": "0.1MS" + } +} +""" + + show_muxcable_firmware_version_active_expected_output = """\ { @@ -1468,6 +1479,26 @@ def test_show_muxcable_firmware_version_all(self): assert result.output == show_muxcable_firmware_version_all_expected_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('utilities_common.platform_sfputil_helper.get_logical_list', mock.MagicMock(return_value=["Ethernet0", "Ethernet12"])) + @mock.patch('utilities_common.platform_sfputil_helper.get_asic_id_for_logical_port', mock.MagicMock(return_value=0)) + @mock.patch('show.muxcable.platform_sfputil', mock.MagicMock(return_value={0: ["Ethernet12", "Ethernet0"]})) + @mock.patch('utilities_common.platform_sfputil_helper.get_logical_list', mock.MagicMock(return_value=["Ethernet0", "Ethernet12"])) + @mock.patch('utilities_common.platform_sfputil_helper.get_physical_to_logical', mock.MagicMock(return_value={0: ["Ethernet12", "Ethernet0"]})) + @mock.patch('utilities_common.platform_sfputil_helper.logical_port_name_to_physical_port_list', mock.MagicMock(return_value=[0])) + def test_show_muxcable_firmware_version_all_active(self): + runner = CliRunner() + db = Db() + + result = runner.invoke(show.cli.commands["muxcable"].commands["firmware"].commands["version"], [ + "all", "--active"], obj=db) + assert result.exit_code == 0 + f = open("newfile", "w") + f.write(result.output) + assert result.output == show_muxcable_firmware_version_all_active_expected_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"})) From 0aca10231ef7baf726b7a7604f4d23dbf6b4afbb Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Fri, 21 Oct 2022 23:19:33 +0000 Subject: [PATCH 14/14] fix importing 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 62a4d8d6c8..9e56514c30 100644 --- a/show/muxcable.py +++ b/show/muxcable.py @@ -110,7 +110,7 @@ def get_per_port_firmware(port): namespaces = multi_asic.get_front_end_namespaces() for namespace in namespaces: asic_id = multi_asic.get_asic_index_from_namespace(namespace) - state_db[asic_id] = SonicV2Connector(use_unix_socket_path=False, namespace=namespace) + state_db[asic_id] = swsscommon.SonicV2Connector(use_unix_socket_path=False, namespace=namespace) state_db[asic_id].connect(state_db[asic_id].STATE_DB) if platform_sfputil is not None: