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"