|
5 | 5 |
|
6 | 6 | import click
|
7 | 7 | import re
|
| 8 | +from natsort import natsorted |
8 | 9 | import utilities_common.cli as clicommon
|
9 | 10 | from sonic_py_common import multi_asic
|
10 | 11 | from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector
|
@@ -1269,3 +1270,82 @@ def telemetry(db, state):
|
1269 | 1270 | else:
|
1270 | 1271 | click.echo("ERR: Unable to set ycabled telemetry state to {}".format(state))
|
1271 | 1272 | sys.exit(CONFIG_FAIL)
|
| 1273 | + |
| 1274 | + |
| 1275 | +# 'muxcable' command ("config muxcable reset-heartbeat-suspend <port|all>") |
| 1276 | +@muxcable.command() |
| 1277 | +@click.argument('port', metavar='<port_name>', required=True, default=None) |
| 1278 | +@clicommon.pass_db |
| 1279 | +def reset_heartbeat_suspend(db, port): |
| 1280 | + """Reset the mux port heartbeat suspend.""" |
| 1281 | + |
| 1282 | + if port is None: |
| 1283 | + click.echo("no port provided") |
| 1284 | + sys.exit(CONFIG_FAIL) |
| 1285 | + |
| 1286 | + port = platform_sfputil_helper.get_interface_name(port, db) |
| 1287 | + asic_index = multi_asic.get_asic_index_from_namespace(EMPTY_NAMESPACE) |
| 1288 | + config_dbs = {} |
| 1289 | + mux_linkmgrd_tables = {} |
| 1290 | + mux_config_tables = {} |
| 1291 | + |
| 1292 | + # Getting all front asic namespace and correspding config DB connector |
| 1293 | + namespaces = multi_asic.get_front_end_namespaces() |
| 1294 | + for namespace in namespaces: |
| 1295 | + asic_index = multi_asic.get_asic_index_from_namespace(namespace) |
| 1296 | + config_dbs[asic_index] = ConfigDBConnector(use_unix_socket_path=True, namespace=namespace) |
| 1297 | + config_dbs[asic_index].connect() |
| 1298 | + mux_linkmgrd_tables[asic_index] = config_dbs[asic_index].get_table("MUX_LINKMGR") |
| 1299 | + mux_config_tables[asic_index] = config_dbs[asic_index].get_table("MUX_CABLE") |
| 1300 | + |
| 1301 | + mux_ports = [] |
| 1302 | + if port == "all": |
| 1303 | + for asic_index, mux_config_table in mux_config_tables.items(): |
| 1304 | + config_db = config_dbs[asic_index] |
| 1305 | + mux_linkmgrd_table = mux_linkmgrd_tables[asic_index] |
| 1306 | + mux_ports = [p for p, c in mux_config_table.items() |
| 1307 | + if c.get("cable_type", "active-standby") == "active-standby"] |
| 1308 | + if mux_ports: |
| 1309 | + # trigger one-shot heartbeat suspend reset |
| 1310 | + config_db.mod_entry("MUX_LINKMGR", "LINK_PROBER", {"reset_suspend_timer": ",".join(mux_ports)}) |
| 1311 | + # restore config db to the original |
| 1312 | + config_db.set_entry("MUX_LINKMGR", "LINK_PROBER", mux_linkmgrd_table.get("LINK_PROBER", None)) |
| 1313 | + else: |
| 1314 | + asic_index = None |
| 1315 | + if platform_sfputil is not None: |
| 1316 | + asic_index = platform_sfputil.get_asic_id_for_logical_port(port) |
| 1317 | + if asic_index is None: |
| 1318 | + # TODO this import is only for unit test purposes, and should be removed once sonic_platform_base |
| 1319 | + # is fully mocked |
| 1320 | + import sonic_platform_base.sonic_sfp.sfputilhelper |
| 1321 | + asic_index = sonic_platform_base.sonic_sfp.sfputilhelper.SfpUtilHelper().get_asic_id_for_logical_port(port) |
| 1322 | + if asic_index is None: |
| 1323 | + click.echo("Got invalid asic index for port {}, can't reset heartbeat suspend".format(port)) |
| 1324 | + sys.exit(CONFIG_FAIL) |
| 1325 | + if asic_index in config_dbs: |
| 1326 | + config_db = config_dbs[asic_index] |
| 1327 | + mux_linkmgrd_table = mux_linkmgrd_tables[asic_index] |
| 1328 | + mux_config_table = mux_config_tables[asic_index] |
| 1329 | + if port not in mux_config_table: |
| 1330 | + click.echo("Got invalid port {}, can't reset heartbeat suspend'".format(port)) |
| 1331 | + sys.exit(CONFIG_FAIL) |
| 1332 | + elif mux_config_table[port].get("cable_type", "active-standby") != "active-standby": |
| 1333 | + click.echo( |
| 1334 | + "Got invalid port {}, can't reset heartbeat suspend on active-active mux port".format(port) |
| 1335 | + ) |
| 1336 | + sys.exit(CONFIG_FAIL) |
| 1337 | + mux_ports.append(port) |
| 1338 | + # trigger one-shot heartbeat suspend reset |
| 1339 | + config_db.mod_entry("MUX_LINKMGR", "LINK_PROBER", {"reset_suspend_timer": port}) |
| 1340 | + # restore config db to the original |
| 1341 | + config_db.set_entry("MUX_LINKMGR", "LINK_PROBER", mux_linkmgrd_table.get("LINK_PROBER", None)) |
| 1342 | + else: |
| 1343 | + click.echo("Got invalid asic index for port {}, can't reset heartbeat suspend'".format(port)) |
| 1344 | + sys.exit(CONFIG_FAIL) |
| 1345 | + |
| 1346 | + if not mux_ports: |
| 1347 | + click.echo("No mux ports found to reset heartbeat suspend") |
| 1348 | + sys.exit(CONFIG_FAIL) |
| 1349 | + |
| 1350 | + mux_ports = natsorted(mux_ports) |
| 1351 | + click.echo("Success in resetting heartbeat suspend for mux ports: {}".format(", ".join(mux_ports))) |
0 commit comments