Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[muxcable][show] enhance show mux status to show last switchover time #2067

Merged
merged 2 commits into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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