From 01eb4b1bbddee93414013657a9366bc66cbb9e5a Mon Sep 17 00:00:00 2001 From: vdahiya12 <67608553+vdahiya12@users.noreply.github.com> Date: Tue, 25 May 2021 11:29:37 -0700 Subject: [PATCH] [show] support for show muxcable firmware version of only active banks (#1629) Signed-off-by: vaibhav-dahiya vdahiya@microsoft.com This PR adds support for an option to display firmware version of muxcable of only active banks. The new output would look like this in case an active flag is passed to the command line admin@STR43-0101-0101-01LT0:~$ show muxcable firmware version Ethernet0 --active { "version_self_active": "0.7MS", "version_peer_active": "0.7MS", "version_nic_active": "0.7MS", } What I did added an option to display active banks only for display muxcable firmware version Signed-off-by: vaibhav-dahiya --- show/muxcable.py | 20 +++++++++++++++++--- tests/muxcable_test.py | 27 +++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/show/muxcable.py b/show/muxcable.py index 425a4f74c549..881f0a894b02 100644 --- a/show/muxcable.py +++ b/show/muxcable.py @@ -847,7 +847,8 @@ def firmware(): @firmware.command() @click.argument('port', metavar='', required=True, default=None) -def version(port): +@click.option('--active', 'active', required=False, is_flag=True, type=click.BOOL, help="display the firmware version of only active bank within MCU's") +def version(port, active): """Show muxcable firmware version""" port_table_keys = {} @@ -899,6 +900,7 @@ def version(port): sys.exit(CONFIG_FAIL) mux_info_dict = {} + mux_info_active_dict = {} physical_port = physical_port_list[0] if per_npu_statedb[asic_index] is not None: y_cable_asic_table_keys = port_table_keys[asic_index] @@ -910,12 +912,24 @@ def version(port): get_firmware_dict(physical_port, 1, "self", mux_info_dict) get_firmware_dict(physical_port, 2, "peer", mux_info_dict) get_firmware_dict(physical_port, 0, "nic", mux_info_dict) - click.echo("{}".format(json.dumps(mux_info_dict, indent=4))) + if active is True: + for key in mux_info_dict: + if key.endswith("_active"): + mux_info_active_dict[key] = mux_info_dict[key] + click.echo("{}".format(json.dumps(mux_info_active_dict, indent=4))) + else: + click.echo("{}".format(json.dumps(mux_info_dict, indent=4))) elif read_side == 2: get_firmware_dict(physical_port, 2, "self", mux_info_dict) get_firmware_dict(physical_port, 1, "peer", mux_info_dict) get_firmware_dict(physical_port, 0, "nic", mux_info_dict) - click.echo("{}".format(json.dumps(mux_info_dict, indent=4))) + if active is True: + for key in mux_info_dict: + if key.endswith("_active"): + mux_info_active_dict[key] = mux_info_dict[key] + click.echo("{}".format(json.dumps(mux_info_active_dict, indent=4))) + else: + click.echo("{}".format(json.dumps(mux_info_dict, indent=4))) else: click.echo("Did not get a valid read_side for muxcable".format(port)) sys.exit(CONFIG_FAIL) diff --git a/tests/muxcable_test.py b/tests/muxcable_test.py index 811a9a7f963d..0385ffeae598 100644 --- a/tests/muxcable_test.py +++ b/tests/muxcable_test.py @@ -189,6 +189,14 @@ } """ +show_muxcable_firmware_version_active_expected_output = """\ +{ + "version_self_active": "0.6MS", + "version_peer_active": "0.6MS", + "version_nic_active": "0.6MS" +} +""" + show_muxcable_metrics_expected_output = """\ PORT EVENT TIME --------- ---------------------------- --------------------------- @@ -823,6 +831,25 @@ def test_show_muxcable_metrics_port(self): assert result.exit_code == 0 assert result.output == show_muxcable_metrics_expected_output_json + @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])) + @mock.patch('sonic_y_cable.y_cable.check_read_side', mock.MagicMock(return_value=(1))) + @mock.patch('click.confirm', mock.MagicMock(return_value=("y"))) + @mock.patch('sonic_y_cable.y_cable.get_firmware_version', mock.MagicMock(return_value={"version_active": "0.6MS", + "version_inactive": "0.6MS", + "version_next": "0.6MS"})) + def test_show_muxcable_firmware_active_version(self): + runner = CliRunner() + db = Db() + + result = runner.invoke(show.cli.commands["muxcable"].commands["firmware"].commands["version"], [ + "Ethernet0", "--active"], obj=db) + assert result.exit_code == 0 + assert result.output == show_muxcable_firmware_version_active_expected_output + @classmethod def teardown_class(cls): os.environ['UTILITIES_UNIT_TESTING'] = "0"