Skip to content

Commit

Permalink
[system-health] Remove booting stage in system health service (sonic-…
Browse files Browse the repository at this point in the history
…net#2022)

- What I did
For SYSTEM READY feature. Currently, there is a booting stage in system health service to indicate that the system is loading SONiC component. This booting stage is no longer needed because SYSTEM READY feature will treat that stage as system "NOT READY".

- How I did it
1. Remove booting stage
2. Adjust unit test cases

- How to verify it
Manual test, Unit test, sonic-mgmt Regression
  • Loading branch information
Junchao-Mellanox authored Jan 27, 2022
1 parent 01dfb9c commit c652ad0
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 148 deletions.
234 changes: 111 additions & 123 deletions show/system_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def summary():
HealthCheckerManager = MockerManager
Chassis = MockerChassis
except Exception:
# Normal run... #
# Normal run... #
if os.geteuid():
click.echo("Root privileges are required for this operation")
return
Expand All @@ -38,44 +38,40 @@ def summary():
click.echo("System health configuration file not found, exit...")
return
chassis = Chassis()
state, stat = manager.check(chassis)
if state == HealthCheckerManager.STATE_BOOTING:
click.echo("System is currently booting...")
return
if state == HealthCheckerManager.STATE_RUNNING:
chassis.initizalize_system_led()
led = chassis.get_status_led()
click.echo("System status summary\n\n System status LED " + led)
services_list = []
fs_list = []
device_list =[]
for category, elements in stat.items():
for element in elements:
if elements[element]['status'] != "OK":
if 'Running' in elements[element]['message']:
services_list.append(element)
elif 'Accessible' in elements[element]['message']:
fs_list.append(element)
else:
device_list.append(elements[element]['message'])
if len(services_list) or len(fs_list):
click.echo(" Services:\n Status: Not OK")
else:
click.echo(" Services:\n Status: OK")
if len(services_list):
services_list_string = str(services_list)
click.echo(" Not Running: " + services_list_string.replace("[", "").replace(']', ""))
if len(fs_list):
fs_list_string = str(fs_list)
click.echo(" Not Accessible: " + fs_list_string.replace("[", "").replace(']', ""))
if len(device_list):
click.echo(" Hardware:\n Status: Not OK")
click.echo(" Reasons: " + device_list.pop())
while len(device_list):
click.echo("\t " + device_list.pop())
else:
click.echo(" Hardware:\n Status: OK")

stat = manager.check(chassis)
chassis.initizalize_system_led()
led = chassis.get_status_led()
click.echo("System status summary\n\n System status LED " + led)
services_list = []
fs_list = []
device_list =[]
for category, elements in stat.items():
for element in elements:
if elements[element]['status'] != "OK":
if 'Running' in elements[element]['message']:
services_list.append(element)
elif 'Accessible' in elements[element]['message']:
fs_list.append(element)
else:
device_list.append(elements[element]['message'])
if len(services_list) or len(fs_list):
click.echo(" Services:\n Status: Not OK")
else:
click.echo(" Services:\n Status: OK")
if len(services_list):
services_list_string = str(services_list)
click.echo(" Not Running: " + services_list_string.replace("[", "").replace(']', ""))
if len(fs_list):
fs_list_string = str(fs_list)
click.echo(" Not Accessible: " + fs_list_string.replace("[", "").replace(']', ""))
if len(device_list):
click.echo(" Hardware:\n Status: Not OK")
click.echo(" Reasons: " + device_list.pop())
while len(device_list):
click.echo("\t " + device_list.pop())
else:
click.echo(" Hardware:\n Status: OK")

@system_health.command()
def detail():
"""Show system-health detail information"""
Expand All @@ -89,7 +85,7 @@ def detail():
HealthCheckerManager = MockerManager
Chassis = MockerChassis
except Exception:
# Normal run... #
# Normal run... #
if os.geteuid():
click.echo("Root privileges are required for this operation")
return
Expand All @@ -101,73 +97,69 @@ def detail():
click.echo("System health configuration file not found, exit...")
return
chassis = Chassis()
state, stat = manager.check(chassis)
if state == HealthCheckerManager.STATE_BOOTING:
click.echo("System is currently booting...")
return
if state == HealthCheckerManager.STATE_RUNNING:
#summary output
chassis.initizalize_system_led()
led = chassis.get_status_led()
click.echo("System status summary\n\n System status LED " + led)
services_list = []
fs_list = []
device_list =[]
for category, elements in stat.items():
for element in elements:
if elements[element]['status'] != "OK":
if 'Running' in elements[element]['message']:
services_list.append(element)
elif 'Accessible' in elements[element]['message']:
fs_list.append(element)
else:
device_list.append(elements[element]['message'])
if len(services_list) or len(fs_list):
click.echo(" Services:\n Status: Not OK")
else:
click.echo(" Services:\n Status: OK")
if len(services_list):
services_list_string = str(services_list)
click.echo(" Not Running: " + services_list_string.replace("[", "").replace(']', ""))
if len(fs_list):
fs_list_string = str(fs_list)
click.echo(" Not Accessible: " + fs_list_string.replace("[", "").replace(']', ""))
if len(device_list):
click.echo(" Hardware:\n Status: Not OK")
click.echo(" Reasons: " + device_list.pop())
while len(device_list):
click.echo("\t " + device_list.pop())
else:
click.echo(" Hardware:\n Status: OK")
stat = manager.check(chassis)
#summary output
chassis.initizalize_system_led()
led = chassis.get_status_led()
click.echo("System status summary\n\n System status LED " + led)
services_list = []
fs_list = []
device_list =[]
for category, elements in stat.items():
for element in elements:
if elements[element]['status'] != "OK":
if 'Running' in elements[element]['message']:
services_list.append(element)
elif 'Accessible' in elements[element]['message']:
fs_list.append(element)
else:
device_list.append(elements[element]['message'])
if len(services_list) or len(fs_list):
click.echo(" Services:\n Status: Not OK")
else:
click.echo(" Services:\n Status: OK")
if len(services_list):
services_list_string = str(services_list)
click.echo(" Not Running: " + services_list_string.replace("[", "").replace(']', ""))
if len(fs_list):
fs_list_string = str(fs_list)
click.echo(" Not Accessible: " + fs_list_string.replace("[", "").replace(']', ""))
if len(device_list):
click.echo(" Hardware:\n Status: Not OK")
click.echo(" Reasons: " + device_list.pop())
while len(device_list):
click.echo("\t " + device_list.pop())
else:
click.echo(" Hardware:\n Status: OK")

click.echo('\nSystem services and devices monitor list\n')
header = ['Name', 'Status', 'Type']
table = []
for category, elements in stat.items():
for element in sorted(elements.items(), key=lambda x: x[1]['status']):
entry = []
entry.append(element[0])
entry.append(element[1]['status'])
entry.append(element[1]['type'])
table.append(entry)
click.echo(tabulate(table, header))
click.echo('\nSystem services and devices ignore list\n')
table = []
if manager.config.ignore_services:
for element in manager.config.ignore_services:
entry = []
entry.append(element)
entry.append("Ignored")
entry.append("Service")
table.append(entry)
if manager.config.ignore_devices:
for element in manager.config.ignore_devices:
entry = []
entry.append(element)
entry.append("Ignored")
entry.append("Device")
table.append(entry)
click.echo(tabulate(table, header))
click.echo('\nSystem services and devices monitor list\n')
header = ['Name', 'Status', 'Type']
table = []
for category, elements in stat.items():
for element in sorted(elements.items(), key=lambda x: x[1]['status']):
entry = []
entry.append(element[0])
entry.append(element[1]['status'])
entry.append(element[1]['type'])
table.append(entry)
click.echo(tabulate(table, header))
click.echo('\nSystem services and devices ignore list\n')
table = []
if manager.config.ignore_services:
for element in manager.config.ignore_services:
entry = []
entry.append(element)
entry.append("Ignored")
entry.append("Service")
table.append(entry)
if manager.config.ignore_devices:
for element in manager.config.ignore_devices:
entry = []
entry.append(element)
entry.append("Ignored")
entry.append("Device")
table.append(entry)
click.echo(tabulate(table, header))

@system_health.command()
def monitor_list():
Expand All @@ -182,7 +174,7 @@ def monitor_list():
HealthCheckerManager = MockerManager
Chassis = MockerChassis
except Exception:
# Normal run... #
# Normal run... #
if os.geteuid():
click.echo("Root privileges are required for this operation")
return
Expand All @@ -194,19 +186,15 @@ def monitor_list():
click.echo("System health configuration file not found, exit...")
return
chassis = Chassis()
state, stat = manager.check(chassis)
if state == HealthCheckerManager.STATE_BOOTING:
click.echo("System is currently booting...")
return
if state == HealthCheckerManager.STATE_RUNNING:
click.echo('\nSystem services and devices monitor list\n')
header = ['Name', 'Status', 'Type']
table = []
for category, elements in stat.items():
for element in sorted(elements.items(), key=lambda x: x[1]['status']):
entry = []
entry.append(element[0])
entry.append(element[1]['status'])
entry.append(element[1]['type'])
table.append(entry)
click.echo(tabulate(table, header))
stat = manager.check(chassis)
click.echo('\nSystem services and devices monitor list\n')
header = ['Name', 'Status', 'Type']
table = []
for category, elements in stat.items():
for element in sorted(elements.items(), key=lambda x: x[1]['status']):
entry = []
entry.append(element[0])
entry.append(element[1]['status'])
entry.append(element[1]['type'])
table.append(entry)
click.echo(tabulate(table, header))
Loading

0 comments on commit c652ad0

Please sign in to comment.