Skip to content

Commit

Permalink
[show] support for show muxcable firmware version of only active banks (
Browse files Browse the repository at this point in the history
#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>
  • Loading branch information
vdahiya12 authored May 25, 2021
1 parent 7744c8d commit 01eb4b1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
20 changes: 17 additions & 3 deletions show/muxcable.py
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,8 @@ def firmware():

@firmware.command()
@click.argument('port', metavar='<port_name>', 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 = {}
Expand Down Expand Up @@ -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]
Expand All @@ -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)
Expand Down
27 changes: 27 additions & 0 deletions tests/muxcable_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------- ---------------------------- ---------------------------
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 01eb4b1

Please sign in to comment.