|
| 1 | + |
1 | 2 | import json
|
2 | 3 | import sys
|
3 | 4 | import time
|
@@ -97,6 +98,51 @@ def check_port_in_mux_cable_table(port):
|
97 | 98 | return False
|
98 | 99 |
|
99 | 100 |
|
| 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 | + |
100 | 146 | def get_response_for_version(port, mux_info_dict):
|
101 | 147 | state_db = {}
|
102 | 148 | xcvrd_show_fw_res_tbl = {}
|
@@ -1528,7 +1574,7 @@ def version(db, port, active):
|
1528 | 1574 | delete_all_keys_in_db_table("STATE_DB", "XCVRD_SHOW_FW_RSP")
|
1529 | 1575 | delete_all_keys_in_db_table("STATE_DB", "XCVRD_SHOW_FW_RES")
|
1530 | 1576 |
|
1531 |
| - if port is not None: |
| 1577 | + if port is not None and port != "all": |
1532 | 1578 |
|
1533 | 1579 | res_dict = {}
|
1534 | 1580 | mux_info_dict, mux_info_active_dict = {}, {}
|
@@ -1561,6 +1607,65 @@ def version(db, port, active):
|
1561 | 1607 | click.echo("{}".format(json.dumps(mux_info_active_dict, indent=4)))
|
1562 | 1608 | else:
|
1563 | 1609 | 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 | + |
1564 | 1669 | else:
|
1565 | 1670 | port_name = platform_sfputil_helper.get_interface_name(port, db)
|
1566 | 1671 | 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):
|
1640 | 1745 | def event_log(db, port, json_output):
|
1641 | 1746 | """Show muxcable event log <port>"""
|
1642 | 1747 |
|
| 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) |
1643 | 1749 | port = platform_sfputil_helper.get_interface_name(port, db)
|
1644 | 1750 | delete_all_keys_in_db_table("APPL_DB", "XCVRD_EVENT_LOG_CMD")
|
1645 | 1751 | delete_all_keys_in_db_table("STATE_DB", "XCVRD_EVENT_LOG_RSP")
|
@@ -1735,7 +1841,7 @@ def packetloss(db, port, json_output):
|
1735 | 1841 | for namespace in namespaces:
|
1736 | 1842 | asic_id = multi_asic.get_asic_index_from_namespace(namespace)
|
1737 | 1843 |
|
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) |
1739 | 1845 | per_npu_statedb[asic_id].connect(per_npu_statedb[asic_id].STATE_DB)
|
1740 | 1846 |
|
1741 | 1847 | pckloss_table_keys[asic_id] = per_npu_statedb[asic_id].keys(
|
|
0 commit comments