Skip to content

Commit 01eb4b1

Browse files
authored
[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 <vdahiya@microsoft.com>
1 parent 7744c8d commit 01eb4b1

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

show/muxcable.py

+17-3
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,8 @@ def firmware():
847847

848848
@firmware.command()
849849
@click.argument('port', metavar='<port_name>', required=True, default=None)
850-
def version(port):
850+
@click.option('--active', 'active', required=False, is_flag=True, type=click.BOOL, help="display the firmware version of only active bank within MCU's")
851+
def version(port, active):
851852
"""Show muxcable firmware version"""
852853

853854
port_table_keys = {}
@@ -899,6 +900,7 @@ def version(port):
899900
sys.exit(CONFIG_FAIL)
900901

901902
mux_info_dict = {}
903+
mux_info_active_dict = {}
902904
physical_port = physical_port_list[0]
903905
if per_npu_statedb[asic_index] is not None:
904906
y_cable_asic_table_keys = port_table_keys[asic_index]
@@ -910,12 +912,24 @@ def version(port):
910912
get_firmware_dict(physical_port, 1, "self", mux_info_dict)
911913
get_firmware_dict(physical_port, 2, "peer", mux_info_dict)
912914
get_firmware_dict(physical_port, 0, "nic", mux_info_dict)
913-
click.echo("{}".format(json.dumps(mux_info_dict, indent=4)))
915+
if active is True:
916+
for key in mux_info_dict:
917+
if key.endswith("_active"):
918+
mux_info_active_dict[key] = mux_info_dict[key]
919+
click.echo("{}".format(json.dumps(mux_info_active_dict, indent=4)))
920+
else:
921+
click.echo("{}".format(json.dumps(mux_info_dict, indent=4)))
914922
elif read_side == 2:
915923
get_firmware_dict(physical_port, 2, "self", mux_info_dict)
916924
get_firmware_dict(physical_port, 1, "peer", mux_info_dict)
917925
get_firmware_dict(physical_port, 0, "nic", mux_info_dict)
918-
click.echo("{}".format(json.dumps(mux_info_dict, indent=4)))
926+
if active is True:
927+
for key in mux_info_dict:
928+
if key.endswith("_active"):
929+
mux_info_active_dict[key] = mux_info_dict[key]
930+
click.echo("{}".format(json.dumps(mux_info_active_dict, indent=4)))
931+
else:
932+
click.echo("{}".format(json.dumps(mux_info_dict, indent=4)))
919933
else:
920934
click.echo("Did not get a valid read_side for muxcable".format(port))
921935
sys.exit(CONFIG_FAIL)

tests/muxcable_test.py

+27
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,14 @@
189189
}
190190
"""
191191

192+
show_muxcable_firmware_version_active_expected_output = """\
193+
{
194+
"version_self_active": "0.6MS",
195+
"version_peer_active": "0.6MS",
196+
"version_nic_active": "0.6MS"
197+
}
198+
"""
199+
192200
show_muxcable_metrics_expected_output = """\
193201
PORT EVENT TIME
194202
--------- ---------------------------- ---------------------------
@@ -823,6 +831,25 @@ def test_show_muxcable_metrics_port(self):
823831
assert result.exit_code == 0
824832
assert result.output == show_muxcable_metrics_expected_output_json
825833

834+
@mock.patch('utilities_common.platform_sfputil_helper.get_logical_list', mock.MagicMock(return_value=["Ethernet0", "Ethernet12"]))
835+
@mock.patch('utilities_common.platform_sfputil_helper.get_asic_id_for_logical_port', mock.MagicMock(return_value=0))
836+
@mock.patch('show.muxcable.platform_sfputil', mock.MagicMock(return_value={0: ["Ethernet12", "Ethernet0"]}))
837+
@mock.patch('utilities_common.platform_sfputil_helper.get_physical_to_logical', mock.MagicMock(return_value={0: ["Ethernet12", "Ethernet0"]}))
838+
@mock.patch('utilities_common.platform_sfputil_helper.logical_port_name_to_physical_port_list', mock.MagicMock(return_value=[0]))
839+
@mock.patch('sonic_y_cable.y_cable.check_read_side', mock.MagicMock(return_value=(1)))
840+
@mock.patch('click.confirm', mock.MagicMock(return_value=("y")))
841+
@mock.patch('sonic_y_cable.y_cable.get_firmware_version', mock.MagicMock(return_value={"version_active": "0.6MS",
842+
"version_inactive": "0.6MS",
843+
"version_next": "0.6MS"}))
844+
def test_show_muxcable_firmware_active_version(self):
845+
runner = CliRunner()
846+
db = Db()
847+
848+
result = runner.invoke(show.cli.commands["muxcable"].commands["firmware"].commands["version"], [
849+
"Ethernet0", "--active"], obj=db)
850+
assert result.exit_code == 0
851+
assert result.output == show_muxcable_firmware_version_active_expected_output
852+
826853
@classmethod
827854
def teardown_class(cls):
828855
os.environ['UTILITIES_UNIT_TESTING'] = "0"

0 commit comments

Comments
 (0)