Skip to content

Commit f872516

Browse files
authored
[muxcable][show] enhance show mux status to show last switchover time (#2067)
#### What I did Enhance ```show muxcable status``` to show last switchover time as well sign-off: Jing Zhang [email protected] #### 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 ```
1 parent d440df7 commit f872516

File tree

2 files changed

+70
-27
lines changed

2 files changed

+70
-27
lines changed

show/muxcable.py

+40-9
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ def get_switch_name(config_db):
275275
sys.exit(STATUS_FAIL)
276276

277277

278-
def create_json_dump_per_port_status(db, port_status_dict, muxcable_info_dict, muxcable_health_dict, asic_index, port):
278+
def create_json_dump_per_port_status(db, port_status_dict, muxcable_info_dict, muxcable_health_dict, muxcable_metrics_dict, asic_index, port):
279279

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

287+
last_switch_end_time = ""
288+
if "linkmgrd_switch_standby_end" in muxcable_metrics_dict[asic_index]:
289+
last_switch_end_time = muxcable_metrics_dict[asic_index].get("linkmgrd_switch_standby_end")
290+
elif "linkmgrd_switch_active_end" in muxcable_metrics_dict[asic_index]:
291+
last_switch_end_time = muxcable_metrics_dict[asic_index].get("linkmgrd_switch_active_end")
292+
port_status_dict["MUX_CABLE"][port_name]["LAST_SWITCHOVER_TIME"] = last_switch_end_time
287293

288-
def create_table_dump_per_port_status(db, print_data, muxcable_info_dict, muxcable_health_dict, asic_index, port):
294+
def create_table_dump_per_port_status(db, print_data, muxcable_info_dict, muxcable_health_dict, muxcable_metrics_dict, asic_index, port):
289295

290296
print_port_data = []
291297

292298
status_value = get_value_for_key_in_dict(muxcable_info_dict[asic_index], port, "state", "MUX_CABLE_TABLE")
293299
#status_value = get_value_for_key_in_tbl(y_cable_asic_table, port, "status")
294300
health_value = get_value_for_key_in_dict(muxcable_health_dict[asic_index], port, "state", "MUX_LINKMGR_TABLE")
301+
302+
last_switch_end_time = ""
303+
if "linkmgrd_switch_standby_end" in muxcable_metrics_dict[asic_index]:
304+
last_switch_end_time = muxcable_metrics_dict[asic_index].get("linkmgrd_switch_standby_end")
305+
elif "linkmgrd_switch_active_end" in muxcable_metrics_dict[asic_index]:
306+
last_switch_end_time = muxcable_metrics_dict[asic_index].get("linkmgrd_switch_active_end")
307+
295308
port_name = platform_sfputil_helper.get_interface_alias(port, db)
296309
print_port_data.append(port_name)
297310
print_port_data.append(status_value)
298311
print_port_data.append(health_value)
312+
print_port_data.append(last_switch_end_time)
299313
print_data.append(print_port_data)
300314

301315

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

337351
port_table_keys = {}
338352
port_health_table_keys = {}
353+
port_metrics_table_keys = {}
339354
per_npu_statedb = {}
340355
muxcable_info_dict = {}
341356
muxcable_health_dict = {}
357+
muxcable_metrics_dict = {}
342358

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

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

356374
if port is not None:
357375
asic_index = None
@@ -371,27 +389,33 @@ def status(db, port, json_output):
371389
per_npu_statedb[asic_index].STATE_DB, 'MUX_CABLE_TABLE|{}'.format(port))
372390
muxcable_health_dict[asic_index] = per_npu_statedb[asic_index].get_all(
373391
per_npu_statedb[asic_index].STATE_DB, 'MUX_LINKMGR_TABLE|{}'.format(port))
392+
muxcable_metrics_dict[asic_index] = per_npu_statedb[asic_index].get_all(
393+
per_npu_statedb[asic_index].STATE_DB, 'MUX_METRICS_TABLE|{}'.format(port))
374394
if muxcable_info_dict[asic_index] is not None:
375395
logical_key = "MUX_CABLE_TABLE|{}".format(port)
376396
logical_health_key = "MUX_LINKMGR_TABLE|{}".format(port)
397+
logical_metrics_key = "MUX_METRICS_TABLE|{}".format(port)
377398
if logical_key in port_table_keys[asic_index] and logical_health_key in port_health_table_keys[asic_index]:
399+
400+
if logical_metrics_key not in port_metrics_table_keys[asic_index]:
401+
muxcable_metrics_dict[asic_index] = {}
378402

379403
if json_output:
380404
port_status_dict = {}
381405
port_status_dict["MUX_CABLE"] = {}
382406

383407
create_json_dump_per_port_status(db, port_status_dict, muxcable_info_dict,
384-
muxcable_health_dict, asic_index, port)
408+
muxcable_health_dict, muxcable_metrics_dict, asic_index, port)
385409

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

391415
create_table_dump_per_port_status(db, print_data, muxcable_info_dict,
392-
muxcable_health_dict, asic_index, port)
416+
muxcable_health_dict, muxcable_metrics_dict, asic_index, port)
393417

394-
headers = ['PORT', 'STATUS', 'HEALTH']
418+
headers = ['PORT', 'STATUS', 'HEALTH', 'LAST_SWITCHOVER_TIME']
395419

396420
click.echo(tabulate(print_data, headers=headers))
397421
sys.exit(STATUS_SUCCESSFUL)
@@ -416,8 +440,12 @@ def status(db, port, json_output):
416440
per_npu_statedb[asic_id].STATE_DB, 'MUX_CABLE_TABLE|{}'.format(port))
417441
muxcable_health_dict[asic_id] = per_npu_statedb[asic_id].get_all(
418442
per_npu_statedb[asic_id].STATE_DB, 'MUX_LINKMGR_TABLE|{}'.format(port))
443+
muxcable_metrics_dict[asic_id] = per_npu_statedb[asic_id].get_all(
444+
per_npu_statedb[asic_id].STATE_DB, 'MUX_METRICS_TABLE|{}'.format(port))
445+
if not muxcable_metrics_dict[asic_id]:
446+
muxcable_metrics_dict[asic_id] = {}
419447
create_json_dump_per_port_status(db, port_status_dict, muxcable_info_dict,
420-
muxcable_health_dict, asic_id, port)
448+
muxcable_health_dict, muxcable_metrics_dict, asic_id, port)
421449

422450
click.echo("{}".format(json.dumps(port_status_dict, indent=4)))
423451
else:
@@ -430,11 +458,14 @@ def status(db, port, json_output):
430458
per_npu_statedb[asic_id].STATE_DB, 'MUX_LINKMGR_TABLE|{}'.format(port))
431459
muxcable_info_dict[asic_id] = per_npu_statedb[asic_id].get_all(
432460
per_npu_statedb[asic_id].STATE_DB, 'MUX_CABLE_TABLE|{}'.format(port))
433-
461+
muxcable_metrics_dict[asic_id] = per_npu_statedb[asic_id].get_all(
462+
per_npu_statedb[asic_id].STATE_DB, 'MUX_METRICS_TABLE|{}'.format(port))
463+
if not muxcable_metrics_dict[asic_id]:
464+
muxcable_metrics_dict[asic_id] = {}
434465
create_table_dump_per_port_status(db, print_data, muxcable_info_dict,
435-
muxcable_health_dict, asic_id, port)
466+
muxcable_health_dict, muxcable_metrics_dict, asic_id, port)
436467

437-
headers = ['PORT', 'STATUS', 'HEALTH']
468+
headers = ['PORT', 'STATUS', 'HEALTH', 'LAST_SWITCHOVER_TIME']
438469
click.echo(tabulate(print_data, headers=headers))
439470

440471
sys.exit(STATUS_SUCCESSFUL)

tests/muxcable_test.py

+30-18
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525

2626

2727
tabular_data_status_output_expected = """\
28-
PORT STATUS HEALTH
29-
---------- -------- ---------
30-
Ethernet0 active healthy
28+
PORT STATUS HEALTH LAST_SWITCHOVER_TIME
29+
---------- -------- --------- ---------------------------
30+
Ethernet0 active healthy 2021-May-13 10:01:15.696728
3131
Ethernet4 standby healthy
3232
Ethernet8 standby unhealthy
3333
Ethernet12 unknown unhealthy
@@ -36,9 +36,9 @@
3636
"""
3737

3838
tabular_data_status_output_expected_alias = """\
39-
PORT STATUS HEALTH
40-
------ -------- ---------
41-
etp1 active healthy
39+
PORT STATUS HEALTH LAST_SWITCHOVER_TIME
40+
------ -------- --------- ---------------------------
41+
etp1 active healthy 2021-May-13 10:01:15.696728
4242
etp2 standby healthy
4343
etp3 standby unhealthy
4444
etp4 unknown unhealthy
@@ -51,27 +51,33 @@
5151
"MUX_CABLE": {
5252
"Ethernet0": {
5353
"STATUS": "active",
54-
"HEALTH": "healthy"
54+
"HEALTH": "healthy",
55+
"LAST_SWITCHOVER_TIME": "2021-May-13 10:01:15.696728"
5556
},
5657
"Ethernet4": {
5758
"STATUS": "standby",
58-
"HEALTH": "healthy"
59+
"HEALTH": "healthy",
60+
"LAST_SWITCHOVER_TIME": ""
5961
},
6062
"Ethernet8": {
6163
"STATUS": "standby",
62-
"HEALTH": "unhealthy"
64+
"HEALTH": "unhealthy",
65+
"LAST_SWITCHOVER_TIME": ""
6366
},
6467
"Ethernet12": {
6568
"STATUS": "unknown",
66-
"HEALTH": "unhealthy"
69+
"HEALTH": "unhealthy",
70+
"LAST_SWITCHOVER_TIME": ""
6771
},
6872
"Ethernet16": {
6973
"STATUS": "standby",
70-
"HEALTH": "healthy"
74+
"HEALTH": "healthy",
75+
"LAST_SWITCHOVER_TIME": ""
7176
},
7277
"Ethernet32": {
7378
"STATUS": "active",
74-
"HEALTH": "healthy"
79+
"HEALTH": "healthy",
80+
"LAST_SWITCHOVER_TIME": ""
7581
}
7682
}
7783
}
@@ -82,27 +88,33 @@
8288
"MUX_CABLE": {
8389
"etp1": {
8490
"STATUS": "active",
85-
"HEALTH": "healthy"
91+
"HEALTH": "healthy",
92+
"LAST_SWITCHOVER_TIME": "2021-May-13 10:01:15.696728"
8693
},
8794
"etp2": {
8895
"STATUS": "standby",
89-
"HEALTH": "healthy"
96+
"HEALTH": "healthy",
97+
"LAST_SWITCHOVER_TIME": ""
9098
},
9199
"etp3": {
92100
"STATUS": "standby",
93-
"HEALTH": "unhealthy"
101+
"HEALTH": "unhealthy",
102+
"LAST_SWITCHOVER_TIME": ""
94103
},
95104
"etp4": {
96105
"STATUS": "unknown",
97-
"HEALTH": "unhealthy"
106+
"HEALTH": "unhealthy",
107+
"LAST_SWITCHOVER_TIME": ""
98108
},
99109
"etp5": {
100110
"STATUS": "standby",
101-
"HEALTH": "healthy"
111+
"HEALTH": "healthy",
112+
"LAST_SWITCHOVER_TIME": ""
102113
},
103114
"etp9": {
104115
"STATUS": "active",
105-
"HEALTH": "healthy"
116+
"HEALTH": "healthy",
117+
"LAST_SWITCHOVER_TIME": ""
106118
}
107119
}
108120
}

0 commit comments

Comments
 (0)