Skip to content

Commit d9af117

Browse files
authored
[show][muxcable] add support for show mux firmware version all (#2441) (#2457)
* [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" } } * remove conflict Signed-off-by: vaibhav-dahiya <[email protected]>
1 parent 7272bf3 commit d9af117

File tree

3 files changed

+221
-3
lines changed

3 files changed

+221
-3
lines changed

show/muxcable.py

Lines changed: 108 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
import json
23
import sys
34
import time
@@ -96,6 +97,51 @@ def check_port_in_mux_cable_table(port):
9697
return False
9798

9899

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

1452-
if port is not None:
1498+
if port is not None and port != "all":
14531499

14541500
res_dict = {}
14551501
mux_info_dict, mux_info_active_dict = {}, {}
@@ -1482,6 +1528,65 @@ def version(db, port, active):
14821528
click.echo("{}".format(json.dumps(mux_info_active_dict, indent=4)))
14831529
else:
14841530
click.echo("{}".format(json.dumps(mux_info_dict, indent=4)))
1531+
1532+
elif port == "all" and port is not None:
1533+
1534+
logical_port_list = platform_sfputil_helper.get_logical_list()
1535+
1536+
rc_exit = True
1537+
1538+
for port in logical_port_list:
1539+
1540+
if platform_sfputil is not None:
1541+
physical_port_list = platform_sfputil_helper.logical_port_name_to_physical_port_list(port)
1542+
1543+
if not isinstance(physical_port_list, list):
1544+
continue
1545+
if len(physical_port_list) != 1:
1546+
continue
1547+
1548+
if not check_port_in_mux_cable_table(port):
1549+
continue
1550+
1551+
physical_port = physical_port_list[0]
1552+
1553+
logical_port_list_for_physical_port = platform_sfputil_helper.get_physical_to_logical()
1554+
1555+
logical_port_list_per_port = logical_port_list_for_physical_port.get(physical_port, None)
1556+
1557+
""" This check is required for checking whether or not this logical port is the one which is
1558+
actually mapped to physical port and by convention it is always the first port.
1559+
TODO: this should be removed with more logic to check which logical port maps to actual physical port
1560+
being used"""
1561+
1562+
if port != logical_port_list_per_port[0]:
1563+
continue
1564+
1565+
1566+
port = platform_sfputil_helper.get_interface_alias(port, db)
1567+
1568+
mux_info_dict = get_per_port_firmware(port)
1569+
if not isinstance(mux_info_dict, dict):
1570+
mux_info_dict = {}
1571+
rc_exit = False
1572+
1573+
mux_info = {}
1574+
mux_info_active_dict = {}
1575+
if active is True:
1576+
for key in mux_info_dict:
1577+
if key.endswith("_active"):
1578+
mux_info_active_dict[key] = mux_info_dict[key]
1579+
mux_info[port] = mux_info_active_dict
1580+
click.echo("{}".format(json.dumps(mux_info, indent=4)))
1581+
else:
1582+
mux_info[port] = mux_info_dict
1583+
click.echo("{}".format(json.dumps(mux_info, indent=4)))
1584+
1585+
if rc_exit == False:
1586+
sys.exit(EXIT_FAIL)
1587+
1588+
sys.exit(CONFIG_SUCCESSFUL)
1589+
14851590
else:
14861591
port_name = platform_sfputil_helper.get_interface_name(port, db)
14871592
click.echo("Did not get a valid Port for mux firmware version".format(port_name))
@@ -1561,6 +1666,7 @@ def metrics(db, port, json_output):
15611666
def event_log(db, port, json_output):
15621667
"""Show muxcable event log <port>"""
15631668

1669+
click.confirm(('Muxcable at port {} will retreive cable logs from MCU, Caution: approx wait time could be ~2 minutes Continue?'.format(port)), abort=True)
15641670
port = platform_sfputil_helper.get_interface_name(port, db)
15651671
delete_all_keys_in_db_table("APPL_DB", "XCVRD_EVENT_LOG_CMD")
15661672
delete_all_keys_in_db_table("STATE_DB", "XCVRD_EVENT_LOG_RSP")
@@ -1656,7 +1762,7 @@ def packetloss(db, port, json_output):
16561762
for namespace in namespaces:
16571763
asic_id = multi_asic.get_asic_index_from_namespace(namespace)
16581764

1659-
per_npu_statedb[asic_id] = swsscommon.SonicV2Connector(use_unix_socket_path=True, namespace=namespace)
1765+
per_npu_statedb[asic_id] = swsscommon.SonicV2Connector(use_unix_socket_path=False, namespace=namespace)
16601766
per_npu_statedb[asic_id].connect(per_npu_statedb[asic_id].STATE_DB)
16611767

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

tests/mock_tables/state_db.json

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,30 @@
166166
"is_replaceable": "False",
167167
"led_status": "green"
168168
},
169-
169+
"MUX_CABLE_INFO|Ethernet0": {
170+
"version_peer_next": "0.2MS",
171+
"version_peer_active": "0.2MS",
172+
"version_peer_inactive": "0.2MS",
173+
"version_nic_next": "0.2MS",
174+
"version_nic_active": "0.2MS",
175+
"version_nic_inactive": "0.2MS",
176+
"version_self_next": "0.2MS",
177+
"version_self_active": "0.2MS",
178+
"version_self_inactive": "0.2MS",
179+
"Value": "AABB"
180+
},
181+
"MUX_CABLE_INFO|Ethernet12": {
182+
"version_peer_next": "0.1MS",
183+
"version_peer_active": "0.1MS",
184+
"version_peer_inactive": "0.1MS",
185+
"version_nic_next": "0.1MS",
186+
"version_nic_active": "0.1MS",
187+
"version_nic_inactive": "0.1MS",
188+
"version_self_next": "0.1MS",
189+
"version_self_active": "0.1MS",
190+
"version_self_inactive": "0.1MS",
191+
"Value": "AABB"
192+
},
170193
"SWITCH_CAPABILITY|switch": {
171194
"MIRROR": "true",
172195
"MIRRORV6": "true",

tests/muxcable_test.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,34 @@
404404
}
405405
"""
406406

407+
show_muxcable_firmware_version_all_expected_output = """\
408+
{
409+
"Ethernet12": {
410+
"version_nic_active": "0.1MS",
411+
"version_nic_inactive": "0.1MS",
412+
"version_nic_next": "0.1MS",
413+
"version_peer_active": "0.1MS",
414+
"version_peer_inactive": "0.1MS",
415+
"version_peer_next": "0.1MS",
416+
"version_self_active": "0.1MS",
417+
"version_self_inactive": "0.1MS",
418+
"version_self_next": "0.1MS"
419+
}
420+
}
421+
"""
422+
423+
show_muxcable_firmware_version_all_active_expected_output = """\
424+
{
425+
"Ethernet12": {
426+
"version_nic_active": "0.1MS",
427+
"version_peer_active": "0.1MS",
428+
"version_self_active": "0.1MS"
429+
}
430+
}
431+
"""
432+
433+
434+
407435
show_muxcable_firmware_version_active_expected_output = """\
408436
{
409437
"version_self_active": "0.6MS",
@@ -920,6 +948,7 @@ def test_show_mux_fecstatistics(self):
920948
assert result.exit_code == 0
921949

922950

951+
@mock.patch('click.confirm', mock.MagicMock(return_value=("y")))
923952
@mock.patch('show.muxcable.delete_all_keys_in_db_table', mock.MagicMock(return_value=0))
924953
@mock.patch('show.muxcable.update_and_get_response_for_xcvr_cmd', mock.MagicMock(return_value={0: 0,
925954
1: "True"}))
@@ -1368,6 +1397,66 @@ def test_show_muxcable_firmware_version(self):
13681397
assert result.exit_code == 0
13691398
assert result.output == show_muxcable_firmware_version_expected_output
13701399

1400+
1401+
@mock.patch('show.muxcable.delete_all_keys_in_db_table', mock.MagicMock(return_value=0))
1402+
@mock.patch('show.muxcable.update_and_get_response_for_xcvr_cmd', mock.MagicMock(return_value={0: 0,
1403+
1: "True"}))
1404+
@mock.patch('utilities_common.platform_sfputil_helper.get_logical_list', mock.MagicMock(return_value=["Ethernet0", "Ethernet12"]))
1405+
@mock.patch('utilities_common.platform_sfputil_helper.get_asic_id_for_logical_port', mock.MagicMock(return_value=0))
1406+
@mock.patch('show.muxcable.platform_sfputil', mock.MagicMock(return_value={0: ["Ethernet12", "Ethernet0"]}))
1407+
@mock.patch('utilities_common.platform_sfputil_helper.get_logical_list', mock.MagicMock(return_value=["Ethernet0", "Ethernet12"]))
1408+
@mock.patch('utilities_common.platform_sfputil_helper.get_physical_to_logical', mock.MagicMock(return_value={0: ["Ethernet12", "Ethernet0"]}))
1409+
@mock.patch('utilities_common.platform_sfputil_helper.logical_port_name_to_physical_port_list', mock.MagicMock(return_value=[0]))
1410+
def test_show_muxcable_firmware_version_all(self):
1411+
runner = CliRunner()
1412+
db = Db()
1413+
1414+
result = runner.invoke(show.cli.commands["muxcable"].commands["firmware"].commands["version"], [
1415+
"all"], obj=db)
1416+
assert result.exit_code == 0
1417+
f = open("newfile", "w")
1418+
f.write(result.output)
1419+
assert result.output == show_muxcable_firmware_version_all_expected_output
1420+
1421+
1422+
@mock.patch('show.muxcable.delete_all_keys_in_db_table', mock.MagicMock(return_value=0))
1423+
@mock.patch('show.muxcable.update_and_get_response_for_xcvr_cmd', mock.MagicMock(return_value={0: 0,
1424+
1: "True"}))
1425+
@mock.patch('utilities_common.platform_sfputil_helper.get_logical_list', mock.MagicMock(return_value=["Ethernet0", "Ethernet12"]))
1426+
@mock.patch('utilities_common.platform_sfputil_helper.get_asic_id_for_logical_port', mock.MagicMock(return_value=0))
1427+
@mock.patch('show.muxcable.platform_sfputil', mock.MagicMock(return_value={0: ["Ethernet12", "Ethernet0"]}))
1428+
@mock.patch('utilities_common.platform_sfputil_helper.get_logical_list', mock.MagicMock(return_value=["Ethernet0", "Ethernet12"]))
1429+
@mock.patch('utilities_common.platform_sfputil_helper.get_physical_to_logical', mock.MagicMock(return_value={0: ["Ethernet12", "Ethernet0"]}))
1430+
@mock.patch('utilities_common.platform_sfputil_helper.logical_port_name_to_physical_port_list', mock.MagicMock(return_value=[0]))
1431+
def test_show_muxcable_firmware_version_all_active(self):
1432+
runner = CliRunner()
1433+
db = Db()
1434+
1435+
result = runner.invoke(show.cli.commands["muxcable"].commands["firmware"].commands["version"], [
1436+
"all", "--active"], obj=db)
1437+
assert result.exit_code == 0
1438+
f = open("newfile", "w")
1439+
f.write(result.output)
1440+
assert result.output == show_muxcable_firmware_version_all_active_expected_output
1441+
1442+
@mock.patch('show.muxcable.delete_all_keys_in_db_table', mock.MagicMock(return_value=0))
1443+
@mock.patch('show.muxcable.update_and_get_response_for_xcvr_cmd', mock.MagicMock(return_value={0: 0,
1444+
1: "True"}))
1445+
@mock.patch('utilities_common.platform_sfputil_helper.get_logical_list', mock.MagicMock(return_value=["Ethernet0", "Ethernet12"]))
1446+
@mock.patch('utilities_common.platform_sfputil_helper.get_asic_id_for_logical_port', mock.MagicMock(return_value=1))
1447+
@mock.patch('show.muxcable.platform_sfputil', mock.MagicMock(return_value={0: ["Ethernet12", "Ethernet0"]}))
1448+
@mock.patch('utilities_common.platform_sfputil_helper.get_logical_list', mock.MagicMock(return_value=["Ethernet0", "Ethernet12"]))
1449+
@mock.patch('utilities_common.platform_sfputil_helper.get_physical_to_logical', mock.MagicMock(return_value={0: ["Ethernet12", "Ethernet0"]}))
1450+
@mock.patch('utilities_common.platform_sfputil_helper.logical_port_name_to_physical_port_list', mock.MagicMock(return_value=[0]))
1451+
def test_show_muxcable_firmware_version_all_bad_asic_index(self):
1452+
runner = CliRunner()
1453+
db = Db()
1454+
1455+
result = runner.invoke(show.cli.commands["muxcable"].commands["firmware"].commands["version"], [
1456+
"all"], obj=db)
1457+
assert result.exit_code == 1
1458+
1459+
13711460
@mock.patch('config.muxcable.delete_all_keys_in_db_table', mock.MagicMock(return_value=0))
13721461
@mock.patch('config.muxcable.update_and_get_response_for_xcvr_cmd', mock.MagicMock(return_value={0: 0,
13731462
1: "sucess"}))

0 commit comments

Comments
 (0)