|
| 1 | + |
1 | 2 | import json
|
2 | 3 | import sys
|
3 | 4 | import time
|
@@ -96,6 +97,51 @@ def check_port_in_mux_cable_table(port):
|
96 | 97 | return False
|
97 | 98 |
|
98 | 99 |
|
| 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 | + |
99 | 145 | def get_response_for_version(port, mux_info_dict):
|
100 | 146 | state_db = {}
|
101 | 147 | xcvrd_show_fw_res_tbl = {}
|
@@ -1449,7 +1495,7 @@ def version(db, port, active):
|
1449 | 1495 | delete_all_keys_in_db_table("STATE_DB", "XCVRD_SHOW_FW_RSP")
|
1450 | 1496 | delete_all_keys_in_db_table("STATE_DB", "XCVRD_SHOW_FW_RES")
|
1451 | 1497 |
|
1452 |
| - if port is not None: |
| 1498 | + if port is not None and port != "all": |
1453 | 1499 |
|
1454 | 1500 | res_dict = {}
|
1455 | 1501 | mux_info_dict, mux_info_active_dict = {}, {}
|
@@ -1482,6 +1528,65 @@ def version(db, port, active):
|
1482 | 1528 | click.echo("{}".format(json.dumps(mux_info_active_dict, indent=4)))
|
1483 | 1529 | else:
|
1484 | 1530 | 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 | + |
1485 | 1590 | else:
|
1486 | 1591 | port_name = platform_sfputil_helper.get_interface_name(port, db)
|
1487 | 1592 | 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):
|
1561 | 1666 | def event_log(db, port, json_output):
|
1562 | 1667 | """Show muxcable event log <port>"""
|
1563 | 1668 |
|
| 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) |
1564 | 1670 | port = platform_sfputil_helper.get_interface_name(port, db)
|
1565 | 1671 | delete_all_keys_in_db_table("APPL_DB", "XCVRD_EVENT_LOG_CMD")
|
1566 | 1672 | delete_all_keys_in_db_table("STATE_DB", "XCVRD_EVENT_LOG_RSP")
|
@@ -1656,7 +1762,7 @@ def packetloss(db, port, json_output):
|
1656 | 1762 | for namespace in namespaces:
|
1657 | 1763 | asic_id = multi_asic.get_asic_index_from_namespace(namespace)
|
1658 | 1764 |
|
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) |
1660 | 1766 | per_npu_statedb[asic_id].connect(per_npu_statedb[asic_id].STATE_DB)
|
1661 | 1767 |
|
1662 | 1768 | pckloss_table_keys[asic_id] = per_npu_statedb[asic_id].keys(
|
|
0 commit comments