Skip to content

Commit b3ffe45

Browse files
vdahiya12yxieca
authored andcommitted
[show][muxcable] add support for show mux firmware version all (#2441)
Signed-off-by: vaibhav-dahiya [email protected] This PR adds support for show mux firmware version all as well as adds a click confirmation to process event-log This PR also fixes a permission issue for executing the show mux packetloss command. $show mux firmware version all { "Ethernet116": { "version_nic_active": "1.0MV", "version_nic_inactive": "0.9MS", "version_nic_next": "1.0MV", "version_peer_active": "1.0MV", "version_peer_inactive": "0.9MS", "version_peer_next": "1.0MV", "version_self_active": "1.0MV", "version_self_inactive": "0.9MS", "version_self_next": "1.0MV" } } { "Ethernet120": { "version_nic_active": "1.0MV", "version_nic_inactive": "0.9MS", "version_nic_next": "1.0MV", "version_peer_active": "1.0MV", "version_peer_inactive": "0.9MS", "version_peer_next": "1.0MV", "version_self_active": "1.0MV", "version_self_inactive": "0.9MS", "version_self_next": "1.0MV" } } $ show mux firmware version all --active { "Ethernet116": { "version_nic_active": "1.0MV", "version_peer_active": "1.0MV", "version_self_active": "1.0MV" } } { "Ethernet120": { "version_nic_active": "1.0MV", "version_peer_active": "1.0MV", "version_self_active": "1.0MV" } }
1 parent 7d68534 commit b3ffe45

File tree

3 files changed

+221
-2
lines changed

3 files changed

+221
-2
lines changed

show/muxcable.py

+108-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
import json
23
import sys
34
import time
@@ -97,6 +98,51 @@ def check_port_in_mux_cable_table(port):
9798
return False
9899

99100

101+
102+
def get_per_port_firmware(port):
103+
104+
state_db = {}
105+
mux_info_dict = {}
106+
mux_info_full_dict = {}
107+
108+
# Getting all front asic namespace and correspding config and state DB connector
109+
110+
namespaces = multi_asic.get_front_end_namespaces()
111+
for namespace in namespaces:
112+
asic_id = multi_asic.get_asic_index_from_namespace(namespace)
113+
state_db[asic_id] = swsscommon.SonicV2Connector(use_unix_socket_path=False, namespace=namespace)
114+
state_db[asic_id].connect(state_db[asic_id].STATE_DB)
115+
116+
if platform_sfputil is not None:
117+
asic_index = platform_sfputil_helper.get_asic_id_for_logical_port(port)
118+
119+
if asic_index is None:
120+
# TODO this import is only for unit test purposes, and should be removed once sonic_platform_base
121+
# is fully mocked
122+
import sonic_platform_base.sonic_sfp.sfputilhelper
123+
asic_index = sonic_platform_base.sonic_sfp.sfputilhelper.SfpUtilHelper().get_asic_id_for_logical_port(port)
124+
if asic_index is None:
125+
click.echo("Got invalid asic index for port {}, cant retrieve mux cable table entries".format(port))
126+
return False
127+
128+
129+
mux_info_full_dict[asic_index] = state_db[asic_index].get_all(
130+
state_db[asic_index].STATE_DB, 'MUX_CABLE_INFO|{}'.format(port))
131+
132+
res_dir = {}
133+
res_dir = mux_info_full_dict[asic_index]
134+
mux_info_dict["version_nic_active"] = res_dir.get("version_nic_active", None)
135+
mux_info_dict["version_nic_inactive"] = res_dir.get("version_nic_inactive", None)
136+
mux_info_dict["version_nic_next"] = res_dir.get("version_nic_next", None)
137+
mux_info_dict["version_peer_active"] = res_dir.get("version_peer_active", None)
138+
mux_info_dict["version_peer_inactive"] = res_dir.get("version_peer_inactive", None)
139+
mux_info_dict["version_peer_next"] = res_dir.get("version_peer_next", None)
140+
mux_info_dict["version_self_active"] = res_dir.get("version_self_active", None)
141+
mux_info_dict["version_self_inactive"] = res_dir.get("version_self_inactive", None)
142+
mux_info_dict["version_self_next"] = res_dir.get("version_self_next", None)
143+
144+
return mux_info_dict
145+
100146
def get_response_for_version(port, mux_info_dict):
101147
state_db = {}
102148
xcvrd_show_fw_res_tbl = {}
@@ -1528,7 +1574,7 @@ def version(db, port, active):
15281574
delete_all_keys_in_db_table("STATE_DB", "XCVRD_SHOW_FW_RSP")
15291575
delete_all_keys_in_db_table("STATE_DB", "XCVRD_SHOW_FW_RES")
15301576

1531-
if port is not None:
1577+
if port is not None and port != "all":
15321578

15331579
res_dict = {}
15341580
mux_info_dict, mux_info_active_dict = {}, {}
@@ -1561,6 +1607,65 @@ def version(db, port, active):
15611607
click.echo("{}".format(json.dumps(mux_info_active_dict, indent=4)))
15621608
else:
15631609
click.echo("{}".format(json.dumps(mux_info_dict, indent=4)))
1610+
1611+
elif port == "all" and port is not None:
1612+
1613+
logical_port_list = platform_sfputil_helper.get_logical_list()
1614+
1615+
rc_exit = True
1616+
1617+
for port in logical_port_list:
1618+
1619+
if platform_sfputil is not None:
1620+
physical_port_list = platform_sfputil_helper.logical_port_name_to_physical_port_list(port)
1621+
1622+
if not isinstance(physical_port_list, list):
1623+
continue
1624+
if len(physical_port_list) != 1:
1625+
continue
1626+
1627+
if not check_port_in_mux_cable_table(port):
1628+
continue
1629+
1630+
physical_port = physical_port_list[0]
1631+
1632+
logical_port_list_for_physical_port = platform_sfputil_helper.get_physical_to_logical()
1633+
1634+
logical_port_list_per_port = logical_port_list_for_physical_port.get(physical_port, None)
1635+
1636+
""" This check is required for checking whether or not this logical port is the one which is
1637+
actually mapped to physical port and by convention it is always the first port.
1638+
TODO: this should be removed with more logic to check which logical port maps to actual physical port
1639+
being used"""
1640+
1641+
if port != logical_port_list_per_port[0]:
1642+
continue
1643+
1644+
1645+
port = platform_sfputil_helper.get_interface_alias(port, db)
1646+
1647+
mux_info_dict = get_per_port_firmware(port)
1648+
if not isinstance(mux_info_dict, dict):
1649+
mux_info_dict = {}
1650+
rc_exit = False
1651+
1652+
mux_info = {}
1653+
mux_info_active_dict = {}
1654+
if active is True:
1655+
for key in mux_info_dict:
1656+
if key.endswith("_active"):
1657+
mux_info_active_dict[key] = mux_info_dict[key]
1658+
mux_info[port] = mux_info_active_dict
1659+
click.echo("{}".format(json.dumps(mux_info, indent=4)))
1660+
else:
1661+
mux_info[port] = mux_info_dict
1662+
click.echo("{}".format(json.dumps(mux_info, indent=4)))
1663+
1664+
if rc_exit == False:
1665+
sys.exit(EXIT_FAIL)
1666+
1667+
sys.exit(CONFIG_SUCCESSFUL)
1668+
15641669
else:
15651670
port_name = platform_sfputil_helper.get_interface_name(port, db)
15661671
click.echo("Did not get a valid Port for mux firmware version".format(port_name))
@@ -1640,6 +1745,7 @@ def metrics(db, port, json_output):
16401745
def event_log(db, port, json_output):
16411746
"""Show muxcable event log <port>"""
16421747

1748+
click.confirm(('Muxcable at port {} will retreive cable logs from MCU, Caution: approx wait time could be ~2 minutes Continue?'.format(port)), abort=True)
16431749
port = platform_sfputil_helper.get_interface_name(port, db)
16441750
delete_all_keys_in_db_table("APPL_DB", "XCVRD_EVENT_LOG_CMD")
16451751
delete_all_keys_in_db_table("STATE_DB", "XCVRD_EVENT_LOG_RSP")
@@ -1735,7 +1841,7 @@ def packetloss(db, port, json_output):
17351841
for namespace in namespaces:
17361842
asic_id = multi_asic.get_asic_index_from_namespace(namespace)
17371843

1738-
per_npu_statedb[asic_id] = swsscommon.SonicV2Connector(use_unix_socket_path=True, namespace=namespace)
1844+
per_npu_statedb[asic_id] = swsscommon.SonicV2Connector(use_unix_socket_path=False, namespace=namespace)
17391845
per_npu_statedb[asic_id].connect(per_npu_statedb[asic_id].STATE_DB)
17401846

17411847
pckloss_table_keys[asic_id] = per_npu_statedb[asic_id].keys(

tests/mock_tables/state_db.json

+24
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,30 @@
365365
"Name": "CRC-32",
366366
"Value": "0xAC518FB3"
367367
},
368+
"MUX_CABLE_INFO|Ethernet0": {
369+
"version_peer_next": "0.2MS",
370+
"version_peer_active": "0.2MS",
371+
"version_peer_inactive": "0.2MS",
372+
"version_nic_next": "0.2MS",
373+
"version_nic_active": "0.2MS",
374+
"version_nic_inactive": "0.2MS",
375+
"version_self_next": "0.2MS",
376+
"version_self_active": "0.2MS",
377+
"version_self_inactive": "0.2MS",
378+
"Value": "AABB"
379+
},
380+
"MUX_CABLE_INFO|Ethernet12": {
381+
"version_peer_next": "0.1MS",
382+
"version_peer_active": "0.1MS",
383+
"version_peer_inactive": "0.1MS",
384+
"version_nic_next": "0.1MS",
385+
"version_nic_active": "0.1MS",
386+
"version_nic_inactive": "0.1MS",
387+
"version_self_next": "0.1MS",
388+
"version_self_active": "0.1MS",
389+
"version_self_inactive": "0.1MS",
390+
"Value": "AABB"
391+
},
368392
"SWITCH_CAPABILITY|switch": {
369393
"MIRROR": "true",
370394
"MIRRORV6": "true",

tests/muxcable_test.py

+89
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,34 @@
422422
}
423423
"""
424424

425+
show_muxcable_firmware_version_all_expected_output = """\
426+
{
427+
"Ethernet12": {
428+
"version_nic_active": "0.1MS",
429+
"version_nic_inactive": "0.1MS",
430+
"version_nic_next": "0.1MS",
431+
"version_peer_active": "0.1MS",
432+
"version_peer_inactive": "0.1MS",
433+
"version_peer_next": "0.1MS",
434+
"version_self_active": "0.1MS",
435+
"version_self_inactive": "0.1MS",
436+
"version_self_next": "0.1MS"
437+
}
438+
}
439+
"""
440+
441+
show_muxcable_firmware_version_all_active_expected_output = """\
442+
{
443+
"Ethernet12": {
444+
"version_nic_active": "0.1MS",
445+
"version_peer_active": "0.1MS",
446+
"version_self_active": "0.1MS"
447+
}
448+
}
449+
"""
450+
451+
452+
425453
show_muxcable_firmware_version_active_expected_output = """\
426454
{
427455
"version_self_active": "0.6MS",
@@ -980,6 +1008,7 @@ def test_show_mux_fecstatistics(self):
9801008
assert result.exit_code == 0
9811009

9821010

1011+
@mock.patch('click.confirm', mock.MagicMock(return_value=("y")))
9831012
@mock.patch('show.muxcable.delete_all_keys_in_db_table', mock.MagicMock(return_value=0))
9841013
@mock.patch('show.muxcable.update_and_get_response_for_xcvr_cmd', mock.MagicMock(return_value={0: 0,
9851014
1: "True"}))
@@ -1428,6 +1457,66 @@ def test_show_muxcable_firmware_version(self):
14281457
assert result.exit_code == 0
14291458
assert result.output == show_muxcable_firmware_version_expected_output
14301459

1460+
1461+
@mock.patch('show.muxcable.delete_all_keys_in_db_table', mock.MagicMock(return_value=0))
1462+
@mock.patch('show.muxcable.update_and_get_response_for_xcvr_cmd', mock.MagicMock(return_value={0: 0,
1463+
1: "True"}))
1464+
@mock.patch('utilities_common.platform_sfputil_helper.get_logical_list', mock.MagicMock(return_value=["Ethernet0", "Ethernet12"]))
1465+
@mock.patch('utilities_common.platform_sfputil_helper.get_asic_id_for_logical_port', mock.MagicMock(return_value=0))
1466+
@mock.patch('show.muxcable.platform_sfputil', mock.MagicMock(return_value={0: ["Ethernet12", "Ethernet0"]}))
1467+
@mock.patch('utilities_common.platform_sfputil_helper.get_logical_list', mock.MagicMock(return_value=["Ethernet0", "Ethernet12"]))
1468+
@mock.patch('utilities_common.platform_sfputil_helper.get_physical_to_logical', mock.MagicMock(return_value={0: ["Ethernet12", "Ethernet0"]}))
1469+
@mock.patch('utilities_common.platform_sfputil_helper.logical_port_name_to_physical_port_list', mock.MagicMock(return_value=[0]))
1470+
def test_show_muxcable_firmware_version_all(self):
1471+
runner = CliRunner()
1472+
db = Db()
1473+
1474+
result = runner.invoke(show.cli.commands["muxcable"].commands["firmware"].commands["version"], [
1475+
"all"], obj=db)
1476+
assert result.exit_code == 0
1477+
f = open("newfile", "w")
1478+
f.write(result.output)
1479+
assert result.output == show_muxcable_firmware_version_all_expected_output
1480+
1481+
1482+
@mock.patch('show.muxcable.delete_all_keys_in_db_table', mock.MagicMock(return_value=0))
1483+
@mock.patch('show.muxcable.update_and_get_response_for_xcvr_cmd', mock.MagicMock(return_value={0: 0,
1484+
1: "True"}))
1485+
@mock.patch('utilities_common.platform_sfputil_helper.get_logical_list', mock.MagicMock(return_value=["Ethernet0", "Ethernet12"]))
1486+
@mock.patch('utilities_common.platform_sfputil_helper.get_asic_id_for_logical_port', mock.MagicMock(return_value=0))
1487+
@mock.patch('show.muxcable.platform_sfputil', mock.MagicMock(return_value={0: ["Ethernet12", "Ethernet0"]}))
1488+
@mock.patch('utilities_common.platform_sfputil_helper.get_logical_list', mock.MagicMock(return_value=["Ethernet0", "Ethernet12"]))
1489+
@mock.patch('utilities_common.platform_sfputil_helper.get_physical_to_logical', mock.MagicMock(return_value={0: ["Ethernet12", "Ethernet0"]}))
1490+
@mock.patch('utilities_common.platform_sfputil_helper.logical_port_name_to_physical_port_list', mock.MagicMock(return_value=[0]))
1491+
def test_show_muxcable_firmware_version_all_active(self):
1492+
runner = CliRunner()
1493+
db = Db()
1494+
1495+
result = runner.invoke(show.cli.commands["muxcable"].commands["firmware"].commands["version"], [
1496+
"all", "--active"], obj=db)
1497+
assert result.exit_code == 0
1498+
f = open("newfile", "w")
1499+
f.write(result.output)
1500+
assert result.output == show_muxcable_firmware_version_all_active_expected_output
1501+
1502+
@mock.patch('show.muxcable.delete_all_keys_in_db_table', mock.MagicMock(return_value=0))
1503+
@mock.patch('show.muxcable.update_and_get_response_for_xcvr_cmd', mock.MagicMock(return_value={0: 0,
1504+
1: "True"}))
1505+
@mock.patch('utilities_common.platform_sfputil_helper.get_logical_list', mock.MagicMock(return_value=["Ethernet0", "Ethernet12"]))
1506+
@mock.patch('utilities_common.platform_sfputil_helper.get_asic_id_for_logical_port', mock.MagicMock(return_value=1))
1507+
@mock.patch('show.muxcable.platform_sfputil', mock.MagicMock(return_value={0: ["Ethernet12", "Ethernet0"]}))
1508+
@mock.patch('utilities_common.platform_sfputil_helper.get_logical_list', mock.MagicMock(return_value=["Ethernet0", "Ethernet12"]))
1509+
@mock.patch('utilities_common.platform_sfputil_helper.get_physical_to_logical', mock.MagicMock(return_value={0: ["Ethernet12", "Ethernet0"]}))
1510+
@mock.patch('utilities_common.platform_sfputil_helper.logical_port_name_to_physical_port_list', mock.MagicMock(return_value=[0]))
1511+
def test_show_muxcable_firmware_version_all_bad_asic_index(self):
1512+
runner = CliRunner()
1513+
db = Db()
1514+
1515+
result = runner.invoke(show.cli.commands["muxcable"].commands["firmware"].commands["version"], [
1516+
"all"], obj=db)
1517+
assert result.exit_code == 1
1518+
1519+
14311520
@mock.patch('config.muxcable.delete_all_keys_in_db_table', mock.MagicMock(return_value=0))
14321521
@mock.patch('config.muxcable.update_and_get_response_for_xcvr_cmd', mock.MagicMock(return_value={0: 0,
14331522
1: "sucess"}))

0 commit comments

Comments
 (0)