From 59b23684beb79ded282ece5cb1697c2ae7373d5b Mon Sep 17 00:00:00 2001 From: junchao Date: Mon, 17 Jan 2022 09:47:12 +0800 Subject: [PATCH 1/2] Make system health service start early --- show/system_health.py | 232 +++++++++++++++++------------------- tests/system_health_test.py | 33 ++--- 2 files changed, 118 insertions(+), 147 deletions(-) diff --git a/show/system_health.py b/show/system_health.py index 4418c724a5..db999847a4 100644 --- a/show/system_health.py +++ b/show/system_health.py @@ -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 @@ -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""" @@ -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 @@ -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(): @@ -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 @@ -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) + 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)) diff --git a/tests/system_health_test.py b/tests/system_health_test.py index 82e57f7ce3..819b986ca5 100644 --- a/tests/system_health_test.py +++ b/tests/system_health_test.py @@ -24,38 +24,27 @@ def config_file_exists(self): return True class MockerManager(object): - STATE_BOOTING = 'booting' - STATE_RUNNING = 'running' counter = 0 - + def __init__(self): self.config = MockerConfig() def check(self, chassis): if MockerManager.counter == 0: - state = MockerManager.STATE_BOOTING - stats = {} - elif MockerManager.counter == 1: - state = MockerManager.STATE_RUNNING stats = {'Services': {'neighsyncd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'vrfmgrd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'telemetry': {'status': 'Not OK', 'message': 'telemetry is not Running', 'type': 'Process'}, 'dialout_client': {'status': 'OK', 'message': '', 'type': 'Process'}, 'zebra': {'status': 'OK', 'message': '', 'type': 'Process'}, 'rsyslog': {'status': 'OK', 'message': '', 'type': 'Process'}, 'snmpd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'redis_server': {'status': 'OK', 'message': '', 'type': 'Process'}, 'intfmgrd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'orchagent': {'status': 'OK', 'message': '', 'type': 'Process'}, 'vxlanmgrd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'lldpd_monitor': {'status': 'OK', 'message': '', 'type': 'Process'}, 'portsyncd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'var-log': {'status': 'OK', 'message': '', 'type': 'Filesystem'}, 'lldpmgrd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'syncd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'sonic': {'status': 'OK', 'message': '', 'type': 'System'}, 'buffermgrd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'portmgrd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'staticd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'bgpd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'lldp_syncd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'bgpcfgd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'snmp_subagent': {'status': 'Not OK', 'message': 'snmp_subagent is not Running', 'type': 'Process'}, 'root-overlay': {'status': 'OK', 'message': '', 'type': 'Filesystem'}, 'fpmsyncd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'sflowmgrd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'vlanmgrd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'nbrmgrd': {'status': 'OK', 'message': '', 'type': 'Process'}}, 'Hardware': {'psu_1_fan_1': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'psu_2_fan_1': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'PSU 1': {'status': 'OK', 'message': '', 'type': 'PSU'}, 'fan10': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'PSU 2': {'status': 'OK', 'message': '', 'type': 'PSU'}, 'ASIC': {'status': 'OK', 'message': '', 'type': 'ASIC'}, 'fan1': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'fan3': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'fan2': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'fan5': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'fan4': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'fan7': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'fan6': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'fan9': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'fan8': {'status': 'OK', 'message': '', 'type': 'Fan'}}} - elif MockerManager.counter == 2: - state = MockerManager.STATE_RUNNING + elif MockerManager.counter == 1: stats = {'Services': {'neighsyncd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'vrfmgrd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'telemetry': {'status': 'OK', 'message': '', 'type': 'Process'}, 'dialout_client': {'status': 'OK', 'message': '', 'type': 'Process'}, 'zebra': {'status': 'OK', 'message': '', 'type': 'Process'}, 'rsyslog': {'status': 'OK', 'message': '', 'type': 'Process'}, 'snmpd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'redis_server': {'status': 'OK', 'message': '', 'type': 'Process'}, 'intfmgrd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'orchagent': {'status': 'OK', 'message': '', 'type': 'Process'}, 'vxlanmgrd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'lldpd_monitor': {'status': 'OK', 'message': '', 'type': 'Process'}, 'portsyncd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'var-log': {'status': 'OK', 'message': '', 'type': 'Filesystem'}, 'lldpmgrd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'syncd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'sonic': {'status': 'OK', 'message': '', 'type': 'System'}, 'buffermgrd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'portmgrd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'staticd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'bgpd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'lldp_syncd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'bgpcfgd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'snmp_subagent': {'status': 'OK', 'message': '', 'type': 'Process'}, 'root-overlay': {'status': 'OK', 'message': '', 'type': 'Filesystem'}, 'fpmsyncd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'sflowmgrd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'vlanmgrd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'nbrmgrd': {'status': 'OK', 'message': '', 'type': 'Process'}}, 'Hardware': {'psu_1_fan_1': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'psu_2_fan_1': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'PSU 1': {'status': 'OK', 'message': '', 'type': 'PSU'}, 'fan10': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'PSU 2': {'status': 'OK', 'message': '', 'type': 'PSU'}, 'ASIC': {'status': 'OK', 'message': '', 'type': 'ASIC'}, 'fan1': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'fan3': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'fan2': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'fan5': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'fan4': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'fan7': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'fan6': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'fan9': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'fan8': {'status': 'OK', 'message': '', 'type': 'Fan'}}} - elif MockerManager.counter == 3: - state = MockerManager.STATE_RUNNING + elif MockerManager.counter == 2: stats = {'Services': {'neighsyncd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'vrfmgrd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'telemetry': {'status': 'Not OK', 'message': 'telemetry is not Running', 'type': 'Process'}, 'dialout_client': {'status': 'OK', 'message': '', 'type': 'Process'}, 'zebra': {'status': 'OK', 'message': '', 'type': 'Process'}, 'rsyslog': {'status': 'OK', 'message': '', 'type': 'Process'}, 'snmpd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'redis_server': {'status': 'OK', 'message': '', 'type': 'Process'}, 'intfmgrd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'orchagent': {'status': 'OK', 'message': '', 'type': 'Process'}, 'vxlanmgrd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'lldpd_monitor': {'status': 'OK', 'message': '', 'type': 'Process'}, 'portsyncd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'var-log': {'status': 'OK', 'message': '', 'type': 'Filesystem'}, 'lldpmgrd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'syncd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'sonic': {'status': 'OK', 'message': '', 'type': 'System'}, 'buffermgrd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'portmgrd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'staticd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'bgpd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'lldp_syncd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'bgpcfgd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'snmp_subagent': {'status': 'OK', 'message': '', 'type': 'Process'}, 'root-overlay': {'status': 'OK', 'message': '', 'type': 'Filesystem'}, 'fpmsyncd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'sflowmgrd': {'status': 'Not OK', 'message': 'sflowmgrd is not Running', 'type': 'Process'}, 'vlanmgrd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'nbrmgrd': {'status': 'OK', 'message': '', 'type': 'Process'}}, 'Hardware': {'PSU 2': {'status': 'OK', 'message': '', 'type': 'PSU'}, 'psu_1_fan_1': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'psu_2_fan_1': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'fan11': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'fan10': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'fan12': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'ASIC': {'status': 'OK', 'message': '', 'type': 'ASIC'}, 'fan1': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'PSU 1': {'status': 'OK', 'message': '', 'type': 'PSU'}, 'fan3': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'fan2': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'fan5': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'fan4': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'fan7': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'fan6': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'fan9': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'fan8': {'status': 'OK', 'message': '', 'type': 'Fan'}}} - elif MockerManager.counter == 4: - state = MockerManager.STATE_RUNNING + elif MockerManager.counter == 3: stats = {'Services': {'neighsyncd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'vrfmgrd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'telemetry': {'status': 'Not OK', 'message': 'telemetry is not Running', 'type': 'Process'}, 'dialout_client': {'status': 'OK', 'message': '', 'type': 'Process'}, 'zebra': {'status': 'OK', 'message': '', 'type': 'Process'}, 'rsyslog': {'status': 'OK', 'message': '', 'type': 'Process'}, 'snmpd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'redis_server': {'status': 'OK', 'message': '', 'type': 'Process'}, 'intfmgrd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'orchagent': {'status': 'OK', 'message': '', 'type': 'Process'}, 'vxlanmgrd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'lldpd_monitor': {'status': 'OK', 'message': '', 'type': 'Process'}, 'portsyncd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'var-log': {'status': 'OK', 'message': '', 'type': 'Filesystem'}, 'lldpmgrd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'syncd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'sonic': {'status': 'OK', 'message': '', 'type': 'System'}, 'buffermgrd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'portmgrd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'staticd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'bgpd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'lldp_syncd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'bgpcfgd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'snmp_subagent': {'status': 'OK', 'message': '', 'type': 'Process'}, 'root-overlay': {'status': 'OK', 'message': '', 'type': 'Filesystem'}, 'fpmsyncd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'sflowmgrd': {'status': 'Not OK', 'message': 'sflowmgrd is not Running', 'type': 'Process'}, 'vlanmgrd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'nbrmgrd': {'status': 'OK', 'message': '', 'type': 'Process'}}, 'Hardware': {'PSU 2': {'status': 'Not OK', 'message': 'Failed to get voltage minimum threshold data for PSU 2', 'type': 'PSU'}, 'psu_1_fan_1': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'psu_2_fan_1': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'fan11': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'fan10': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'fan12': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'ASIC': {'status': 'OK', 'message': '', 'type': 'ASIC'}, 'fan1': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'PSU 1': {'status': 'Not OK', 'message': 'Failed to get voltage minimum threshold data for PSU 1', 'type': 'PSU'}, 'fan3': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'fan2': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'fan5': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'fan4': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'fan7': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'fan6': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'fan9': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'fan8': {'status': 'OK', 'message': '', 'type': 'Fan'}}} - elif MockerManager.counter == 5: - state = MockerManager.STATE_RUNNING + elif MockerManager.counter == 4: stats = {'Services': {'neighsyncd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'vrfmgrd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'telemetry': {'status': 'Not OK', 'message': 'telemetry is not Running', 'type': 'Process'}, 'dialout_client': {'status': 'OK', 'message': '', 'type': 'Process'}, 'zebra': {'status': 'OK', 'message': '', 'type': 'Process'}, 'rsyslog': {'status': 'OK', 'message': '', 'type': 'Process'}, 'snmpd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'redis_server': {'status': 'OK', 'message': '', 'type': 'Process'}, 'intfmgrd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'orchagent': {'status': 'OK', 'message': '', 'type': 'Process'}, 'vxlanmgrd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'lldpd_monitor': {'status': 'OK', 'message': '', 'type': 'Process'}, 'portsyncd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'var-log': {'status': 'OK', 'message': '', 'type': 'Filesystem'}, 'lldpmgrd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'syncd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'sonic': {'status': 'OK', 'message': '', 'type': 'System'}, 'buffermgrd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'portmgrd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'staticd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'bgpd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'lldp_syncd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'bgpcfgd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'snmp_subagent': {'status': 'OK', 'message': '', 'type': 'Process'}, 'root-overlay': {'status': 'OK', 'message': '', 'type': 'Filesystem'}, 'fpmsyncd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'sflowmgrd': {'status': 'Not OK', 'message': 'sflowmgrd is not Running', 'type': 'Process'}, 'vlanmgrd': {'status': 'OK', 'message': '', 'type': 'Process'}, 'nbrmgrd': {'status': 'OK', 'message': '', 'type': 'Process'}}, 'Hardware': {'PSU 2': {'status': 'OK', 'message': '', 'type': 'PSU'}, 'psu_1_fan_1': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'psu_2_fan_1': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'fan11': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'fan10': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'fan12': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'ASIC': {'status': 'OK', 'message': '', 'type': 'ASIC'}, 'fan1': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'PSU 1': {'status': 'OK', 'message': '', 'type': 'PSU'}, 'fan3': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'fan2': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'fan5': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'fan4': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'fan7': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'fan6': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'fan9': {'status': 'OK', 'message': '', 'type': 'Fan'}, 'fan8': {'status': 'OK', 'message': '', 'type': 'Fan'}}} else: - state = MockerManager.STATE_RUNNING stats = {} MockerManager.counter += 1 - return state, stats + return stats class MockerChassis(object): counter = 0 @@ -86,12 +75,6 @@ def test_health_summary(self): click.echo(result.output) expected = """\ System health configuration file not found, exit... -""" - assert result.output == expected - result = runner.invoke(show.cli.commands["system-health"].commands["summary"]) - click.echo(result.output) - expected = """\ -System is currently booting... """ assert result.output == expected result = runner.invoke(show.cli.commands["system-health"].commands["summary"]) @@ -119,7 +102,7 @@ def test_health_summary(self): Status: OK """ assert result.output == expected - + def test_health_monitor(self): runner = CliRunner() result = runner.invoke(show.cli.commands["system-health"].commands["monitor-list"]) @@ -322,7 +305,7 @@ def test_health_detail(self): psu.voltage Ignored Device """ assert result.output == expected - + @classmethod def teardown_class(cls): print("TEARDOWN") From f466e59c0ddfafd7f0845bf109cb0bcdb7cb57bf Mon Sep 17 00:00:00 2001 From: junchao Date: Mon, 17 Jan 2022 16:22:12 +0800 Subject: [PATCH 2/2] fix unit test issue --- show/system_health.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/show/system_health.py b/show/system_health.py index db999847a4..30d9d74114 100644 --- a/show/system_health.py +++ b/show/system_health.py @@ -197,4 +197,4 @@ def monitor_list(): entry.append(element[1]['status']) entry.append(element[1]['type']) table.append(entry) - click.echo(tabulate(table, header)) + click.echo(tabulate(table, header))