Skip to content

Commit

Permalink
[muxcable][show] enhance show mux status to show last switchover time (
Browse files Browse the repository at this point in the history
…#2067)

#### What I did
 
Enhance ```show muxcable status``` to show last switchover time as well

sign-off: Jing Zhang zhangjing@microsoft.com

#### Previous command output 
```
~$ show mux status 
PORT         STATUS    HEALTH
-----------  --------  ---------
Ethernet0    standby   unhealthy
Ethernet4    standby   unhealthy
Ethernet8    standby   unhealthy
Ethernet12   standby   unhealthy
Ethernet16   standby   unhealthy
Ethernet20   standby   unhealthy
Ethernet40   standby   unhealthy
Ethernet44   standby   unhealthy
Ethernet48   standby   unhealthy
Ethernet52   standby   unhealthy
Ethernet56   standby   unhealthy
Ethernet60   standby   unhealthy
Ethernet64   standby   unhealthy
Ethernet68   standby   unhealthy
Ethernet72   standby   unhealthy
Ethernet76   standby   unhealthy
Ethernet80   standby   unhealthy
Ethernet84   standby   unhealthy
Ethernet104  standby   unhealthy
Ethernet108  standby   unhealthy
Ethernet112  standby   unhealthy
Ethernet116  standby   unhealthy
Ethernet120  standby   unhealthy
Ethernet124  standby   unhealthy
```
#### New command output 
```
~$ show mux status
PORT         STATUS    HEALTH     LAST_SWITCHOVER_TIME
-----------  --------  ---------  ---------------------------
Ethernet0    standby   unhealthy  2022-Feb-14 16:47:06.813350
Ethernet4    standby   unhealthy  2022-Feb-14 16:47:07.309137
Ethernet8    standby   unhealthy  2022-Feb-14 16:47:07.373696
Ethernet12   standby   unhealthy  2022-Feb-14 16:47:06.430575
Ethernet16   standby   unhealthy  2022-Feb-14 16:47:08.131454
Ethernet20   standby   unhealthy  2022-Feb-14 16:47:07.180982
Ethernet40   standby   unhealthy  2022-Feb-14 16:47:07.335020
Ethernet44   standby   unhealthy  2022-Feb-14 16:47:07.222463
Ethernet48   standby   unhealthy  2022-Feb-14 16:47:07.354632
Ethernet52   standby   unhealthy  2022-Feb-14 16:47:06.826954
Ethernet56   standby   unhealthy  2022-Feb-14 16:47:07.230414
Ethernet60   standby   unhealthy  2022-Feb-14 16:47:07.235581
Ethernet64   standby   unhealthy  2022-Feb-14 16:47:07.315676
Ethernet68   standby   unhealthy  2022-Feb-14 16:47:08.544206
Ethernet72   standby   unhealthy  2022-Feb-14 16:47:07.325918
Ethernet76   standby   unhealthy  2022-Feb-14 16:47:07.368308
Ethernet80   standby   unhealthy  2022-Feb-14 16:47:08.534758
Ethernet84   standby   unhealthy  2022-Feb-14 16:47:07.824009
Ethernet104  standby   unhealthy  2022-Feb-14 16:47:06.814654
Ethernet108  standby   unhealthy  2022-Feb-14 16:47:07.340556
Ethernet112  standby   unhealthy  2022-Feb-14 16:47:07.361900
Ethernet116  standby   unhealthy  2022-Feb-14 16:47:06.820994
Ethernet120  standby   unhealthy  2022-Feb-14 16:47:07.177181
Ethernet124  standby   unhealthy  2022-Feb-14 16:47:06.837251
```
  • Loading branch information
zjswhhh committed Mar 2, 2022
1 parent d440df7 commit f872516
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 27 deletions.
49 changes: 40 additions & 9 deletions show/muxcable.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def get_switch_name(config_db):
sys.exit(STATUS_FAIL)


def create_json_dump_per_port_status(db, port_status_dict, muxcable_info_dict, muxcable_health_dict, asic_index, port):
def create_json_dump_per_port_status(db, port_status_dict, muxcable_info_dict, muxcable_health_dict, muxcable_metrics_dict, asic_index, port):

status_value = get_value_for_key_in_dict(muxcable_info_dict[asic_index], port, "state", "MUX_CABLE_TABLE")
port_name = platform_sfputil_helper.get_interface_alias(port, db)
Expand All @@ -284,18 +284,32 @@ def create_json_dump_per_port_status(db, port_status_dict, muxcable_info_dict, m
health_value = get_value_for_key_in_dict(muxcable_health_dict[asic_index], port, "state", "MUX_LINKMGR_TABLE")
port_status_dict["MUX_CABLE"][port_name]["HEALTH"] = health_value

last_switch_end_time = ""
if "linkmgrd_switch_standby_end" in muxcable_metrics_dict[asic_index]:
last_switch_end_time = muxcable_metrics_dict[asic_index].get("linkmgrd_switch_standby_end")
elif "linkmgrd_switch_active_end" in muxcable_metrics_dict[asic_index]:
last_switch_end_time = muxcable_metrics_dict[asic_index].get("linkmgrd_switch_active_end")
port_status_dict["MUX_CABLE"][port_name]["LAST_SWITCHOVER_TIME"] = last_switch_end_time

def create_table_dump_per_port_status(db, print_data, muxcable_info_dict, muxcable_health_dict, asic_index, port):
def create_table_dump_per_port_status(db, print_data, muxcable_info_dict, muxcable_health_dict, muxcable_metrics_dict, asic_index, port):

print_port_data = []

status_value = get_value_for_key_in_dict(muxcable_info_dict[asic_index], port, "state", "MUX_CABLE_TABLE")
#status_value = get_value_for_key_in_tbl(y_cable_asic_table, port, "status")
health_value = get_value_for_key_in_dict(muxcable_health_dict[asic_index], port, "state", "MUX_LINKMGR_TABLE")

last_switch_end_time = ""
if "linkmgrd_switch_standby_end" in muxcable_metrics_dict[asic_index]:
last_switch_end_time = muxcable_metrics_dict[asic_index].get("linkmgrd_switch_standby_end")
elif "linkmgrd_switch_active_end" in muxcable_metrics_dict[asic_index]:
last_switch_end_time = muxcable_metrics_dict[asic_index].get("linkmgrd_switch_active_end")

port_name = platform_sfputil_helper.get_interface_alias(port, db)
print_port_data.append(port_name)
print_port_data.append(status_value)
print_port_data.append(health_value)
print_port_data.append(last_switch_end_time)
print_data.append(print_port_data)


Expand Down Expand Up @@ -336,9 +350,11 @@ def status(db, port, json_output):

port_table_keys = {}
port_health_table_keys = {}
port_metrics_table_keys = {}
per_npu_statedb = {}
muxcable_info_dict = {}
muxcable_health_dict = {}
muxcable_metrics_dict = {}

# Getting all front asic namespace and correspding config and state DB connector

Expand All @@ -352,6 +368,8 @@ def status(db, port, json_output):
per_npu_statedb[asic_id].STATE_DB, 'MUX_CABLE_TABLE|*')
port_health_table_keys[asic_id] = per_npu_statedb[asic_id].keys(
per_npu_statedb[asic_id].STATE_DB, 'MUX_LINKMGR_TABLE|*')
port_metrics_table_keys[asic_id] = per_npu_statedb[asic_id].keys(
per_npu_statedb[asic_id].STATE_DB, 'MUX_METRICS_TABLE|*')

if port is not None:
asic_index = None
Expand All @@ -371,27 +389,33 @@ def status(db, port, json_output):
per_npu_statedb[asic_index].STATE_DB, 'MUX_CABLE_TABLE|{}'.format(port))
muxcable_health_dict[asic_index] = per_npu_statedb[asic_index].get_all(
per_npu_statedb[asic_index].STATE_DB, 'MUX_LINKMGR_TABLE|{}'.format(port))
muxcable_metrics_dict[asic_index] = per_npu_statedb[asic_index].get_all(
per_npu_statedb[asic_index].STATE_DB, 'MUX_METRICS_TABLE|{}'.format(port))
if muxcable_info_dict[asic_index] is not None:
logical_key = "MUX_CABLE_TABLE|{}".format(port)
logical_health_key = "MUX_LINKMGR_TABLE|{}".format(port)
logical_metrics_key = "MUX_METRICS_TABLE|{}".format(port)
if logical_key in port_table_keys[asic_index] and logical_health_key in port_health_table_keys[asic_index]:

if logical_metrics_key not in port_metrics_table_keys[asic_index]:
muxcable_metrics_dict[asic_index] = {}

if json_output:
port_status_dict = {}
port_status_dict["MUX_CABLE"] = {}

create_json_dump_per_port_status(db, port_status_dict, muxcable_info_dict,
muxcable_health_dict, asic_index, port)
muxcable_health_dict, muxcable_metrics_dict, asic_index, port)

click.echo("{}".format(json.dumps(port_status_dict, indent=4)))
sys.exit(STATUS_SUCCESSFUL)
else:
print_data = []

create_table_dump_per_port_status(db, print_data, muxcable_info_dict,
muxcable_health_dict, asic_index, port)
muxcable_health_dict, muxcable_metrics_dict, asic_index, port)

headers = ['PORT', 'STATUS', 'HEALTH']
headers = ['PORT', 'STATUS', 'HEALTH', 'LAST_SWITCHOVER_TIME']

click.echo(tabulate(print_data, headers=headers))
sys.exit(STATUS_SUCCESSFUL)
Expand All @@ -416,8 +440,12 @@ def status(db, port, json_output):
per_npu_statedb[asic_id].STATE_DB, 'MUX_CABLE_TABLE|{}'.format(port))
muxcable_health_dict[asic_id] = per_npu_statedb[asic_id].get_all(
per_npu_statedb[asic_id].STATE_DB, 'MUX_LINKMGR_TABLE|{}'.format(port))
muxcable_metrics_dict[asic_id] = per_npu_statedb[asic_id].get_all(
per_npu_statedb[asic_id].STATE_DB, 'MUX_METRICS_TABLE|{}'.format(port))
if not muxcable_metrics_dict[asic_id]:
muxcable_metrics_dict[asic_id] = {}
create_json_dump_per_port_status(db, port_status_dict, muxcable_info_dict,
muxcable_health_dict, asic_id, port)
muxcable_health_dict, muxcable_metrics_dict, asic_id, port)

click.echo("{}".format(json.dumps(port_status_dict, indent=4)))
else:
Expand All @@ -430,11 +458,14 @@ def status(db, port, json_output):
per_npu_statedb[asic_id].STATE_DB, 'MUX_LINKMGR_TABLE|{}'.format(port))
muxcable_info_dict[asic_id] = per_npu_statedb[asic_id].get_all(
per_npu_statedb[asic_id].STATE_DB, 'MUX_CABLE_TABLE|{}'.format(port))

muxcable_metrics_dict[asic_id] = per_npu_statedb[asic_id].get_all(
per_npu_statedb[asic_id].STATE_DB, 'MUX_METRICS_TABLE|{}'.format(port))
if not muxcable_metrics_dict[asic_id]:
muxcable_metrics_dict[asic_id] = {}
create_table_dump_per_port_status(db, print_data, muxcable_info_dict,
muxcable_health_dict, asic_id, port)
muxcable_health_dict, muxcable_metrics_dict, asic_id, port)

headers = ['PORT', 'STATUS', 'HEALTH']
headers = ['PORT', 'STATUS', 'HEALTH', 'LAST_SWITCHOVER_TIME']
click.echo(tabulate(print_data, headers=headers))

sys.exit(STATUS_SUCCESSFUL)
Expand Down
48 changes: 30 additions & 18 deletions tests/muxcable_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@


tabular_data_status_output_expected = """\
PORT STATUS HEALTH
---------- -------- ---------
Ethernet0 active healthy
PORT STATUS HEALTH LAST_SWITCHOVER_TIME
---------- -------- --------- ---------------------------
Ethernet0 active healthy 2021-May-13 10:01:15.696728
Ethernet4 standby healthy
Ethernet8 standby unhealthy
Ethernet12 unknown unhealthy
Expand All @@ -36,9 +36,9 @@
"""

tabular_data_status_output_expected_alias = """\
PORT STATUS HEALTH
------ -------- ---------
etp1 active healthy
PORT STATUS HEALTH LAST_SWITCHOVER_TIME
------ -------- --------- ---------------------------
etp1 active healthy 2021-May-13 10:01:15.696728
etp2 standby healthy
etp3 standby unhealthy
etp4 unknown unhealthy
Expand All @@ -51,27 +51,33 @@
"MUX_CABLE": {
"Ethernet0": {
"STATUS": "active",
"HEALTH": "healthy"
"HEALTH": "healthy",
"LAST_SWITCHOVER_TIME": "2021-May-13 10:01:15.696728"
},
"Ethernet4": {
"STATUS": "standby",
"HEALTH": "healthy"
"HEALTH": "healthy",
"LAST_SWITCHOVER_TIME": ""
},
"Ethernet8": {
"STATUS": "standby",
"HEALTH": "unhealthy"
"HEALTH": "unhealthy",
"LAST_SWITCHOVER_TIME": ""
},
"Ethernet12": {
"STATUS": "unknown",
"HEALTH": "unhealthy"
"HEALTH": "unhealthy",
"LAST_SWITCHOVER_TIME": ""
},
"Ethernet16": {
"STATUS": "standby",
"HEALTH": "healthy"
"HEALTH": "healthy",
"LAST_SWITCHOVER_TIME": ""
},
"Ethernet32": {
"STATUS": "active",
"HEALTH": "healthy"
"HEALTH": "healthy",
"LAST_SWITCHOVER_TIME": ""
}
}
}
Expand All @@ -82,27 +88,33 @@
"MUX_CABLE": {
"etp1": {
"STATUS": "active",
"HEALTH": "healthy"
"HEALTH": "healthy",
"LAST_SWITCHOVER_TIME": "2021-May-13 10:01:15.696728"
},
"etp2": {
"STATUS": "standby",
"HEALTH": "healthy"
"HEALTH": "healthy",
"LAST_SWITCHOVER_TIME": ""
},
"etp3": {
"STATUS": "standby",
"HEALTH": "unhealthy"
"HEALTH": "unhealthy",
"LAST_SWITCHOVER_TIME": ""
},
"etp4": {
"STATUS": "unknown",
"HEALTH": "unhealthy"
"HEALTH": "unhealthy",
"LAST_SWITCHOVER_TIME": ""
},
"etp5": {
"STATUS": "standby",
"HEALTH": "healthy"
"HEALTH": "healthy",
"LAST_SWITCHOVER_TIME": ""
},
"etp9": {
"STATUS": "active",
"HEALTH": "healthy"
"HEALTH": "healthy",
"LAST_SWITCHOVER_TIME": ""
}
}
}
Expand Down

0 comments on commit f872516

Please sign in to comment.