Skip to content

Commit

Permalink
Enabling "show system-health dpu" cli alone. The rest of the dpu health
Browse files Browse the repository at this point in the history
is differed for now.
  • Loading branch information
rameshraghupathy committed Sep 4, 2024
1 parent 3ddcc9c commit 95da5c0
Showing 1 changed file with 84 additions and 79 deletions.
163 changes: 84 additions & 79 deletions show/system_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
import click
from tabulate import tabulate
import utilities_common.cli as clicommon
from swsscommon.swsscommon import SonicV2Connector
from natsort import natsorted

DPU_STATE = 'DPU_STATE'
CHASSIS_SERVER = 'redis_chassis.server'
CHASSIS_SERVER_PORT = 6380
CHASSIS_STATE_DB = 13


def get_system_health_status():
Expand Down Expand Up @@ -161,6 +168,82 @@ def sysready_status_detail():
click.echo("Exception: {}".format(str(e)))


def show_module_state(module_name):
chassis_state_db = SonicV2Connector(host=CHASSIS_SERVER, port=CHASSIS_SERVER_PORT)
chassis_state_db.connect(chassis_state_db.CHASSIS_STATE_DB)
key = 'DPU_STATE|'
suffix = '*' if not module_name or not module_name.startswith("DPU") else module_name
key = key + suffix
keys = chassis_state_db.keys(chassis_state_db.CHASSIS_STATE_DB, key)
if not keys:
return

table = []
for dbkey in natsorted(keys):
key_list = dbkey.split('|')
if len(key_list) != 2: # error data in DB, log it and ignore
continue
state_info = chassis_state_db.get_all(chassis_state_db.CHASSIS_STATE_DB, dbkey)
# Determine operational status
# dpu_states = [value for key, value in state_info.items() if key.endswith('_state')]

midplanedown = False
up_cnt = 0
for key, value in state_info.items():
if key.endswith('_state'):
if value.lower() == 'up':
up_cnt = up_cnt + 1
if 'midplane' in key and value.lower() == 'down':
midplanedown = True

if midplanedown:
oper_status = "Offline"
elif up_cnt == 3:
oper_status = "Online"
else:
oper_status = "Partial Online"

for dpustates in range(3):
if dpustates == 0:
row = [key_list[1], state_info.get('id', ''), oper_status, "", "", "", ""]
else:
row = ["", "", "", "", "", "", ""]
for key, value in state_info.items():
if dpustates == 0 and 'midplane' in key:
populate_row(row, key, value, table)
elif dpustates == 1 and 'control' in key:
populate_row(row, key, value, table)
elif dpustates == 2 and 'data' in key:
populate_row(row, key, value, table)

headers = ["Name", "ID", "Oper-Status", "State-Detail", "State-Value", "Time", "Reason"]
click.echo(tabulate(table, headers=headers))


def populate_row(row, key, value, table):
if key.endswith('_state'):
row[3] = key
row[4] = value
if "up" in row[4]:
row[6] = ""
table.append(row)
elif key.endswith('_time'):
row[5] = value
elif key.endswith('_reason'):
if "up" not in row[4]:
row[6] = value


def display_system_health_summary(stat, led):
click.echo("System status summary\n\n System status LED " + led)

@system_health.command()
@click.argument('module_name', required=False)
def dpu(module_name):
"""Show system-health dpu information"""
show_module_state(module_name)


'''
#
# TBD: Uncomment this code in phase:2
Expand All @@ -174,13 +257,7 @@ def sysready_status_detail():
import click
from tabulate import tabulate
import utilities_common.cli as clicommon
from swsscommon.swsscommon import SonicV2Connector
from natsort import natsorted
DPU_STATE = 'DPU_STATE'
CHASSIS_SERVER = 'redis_chassis.server'
CHASSIS_SERVER_PORT = 6380
CHASSIS_STATE_DB = 13
def get_system_health_status():
if os.environ.get("UTILITIES_UNIT_TESTING") == "1":
Expand Down Expand Up @@ -266,72 +343,6 @@ def display_module_health_detail(module_name):
index += 1
def show_module_state(module_name):
chassis_state_db = SonicV2Connector(host=CHASSIS_SERVER, port=CHASSIS_SERVER_PORT)
chassis_state_db.connect(chassis_state_db.CHASSIS_STATE_DB)
key = 'DPU_STATE|'
suffix = '*' if not module_name or not module_name.startswith("DPU") else module_name
key = key + suffix
keys = chassis_state_db.keys(chassis_state_db.CHASSIS_STATE_DB, key)
if not keys:
return
table = []
for dbkey in natsorted(keys):
key_list = dbkey.split('|')
if len(key_list) != 2: # error data in DB, log it and ignore
continue
state_info = chassis_state_db.get_all(chassis_state_db.CHASSIS_STATE_DB, dbkey)
# Determine operational status
# dpu_states = [value for key, value in state_info.items() if key.endswith('_state')]
midplanedown = False
up_cnt = 0
for key, value in state_info.items():
if key.endswith('_state'):
if value.lower() == 'up':
up_cnt = up_cnt + 1
if 'midplane' in key and value.lower() == 'down':
midplanedown = True
if midplanedown:
oper_status = "Offline"
elif up_cnt == 3:
oper_status = "Online"
else:
oper_status = "Partial Online"
for dpustates in range(3):
if dpustates == 0:
row = [key_list[1], state_info.get('id', ''), oper_status, "", "", "", ""]
else:
row = ["", "", "", "", "", "", ""]
for key, value in state_info.items():
if dpustates == 0 and 'midplane' in key:
populate_row(row, key, value, table)
elif dpustates == 1 and 'control' in key:
populate_row(row, key, value, table)
elif dpustates == 2 and 'data' in key:
populate_row(row, key, value, table)
headers = ["Name", "ID", "Oper-Status", "State-Detail", "State-Value", "Time", "Reason"]
click.echo(tabulate(table, headers=headers))
def populate_row(row, key, value, table):
if key.endswith('_state'):
row[3] = key
row[4] = value
if "up" in row[4]:
row[6] = ""
table.append(row)
elif key.endswith('_time'):
row[5] = value
elif key.endswith('_reason'):
if "up" not in row[4]:
row[6] = value
def display_system_health_summary(stat, led):
click.echo("System status summary\n\n System status LED " + led)
services_list = []
Expand Down Expand Up @@ -450,13 +461,6 @@ def monitor_list(module_name):
display_module_health_monitor_list(module_name)
@system_health.command()
@click.argument('module_name', required=False)
def dpu(module_name):
"""Show system-health dpu information"""
show_module_state(module_name)
@system_health.group('sysready-status',invoke_without_command=True)
@click.pass_context
def sysready_status(ctx):
Expand Down Expand Up @@ -487,3 +491,4 @@ def sysready_status_detail():
except Exception as e:
click.echo("Exception: {}".format(str(e)))
'''

0 comments on commit 95da5c0

Please sign in to comment.