diff --git a/show/main.py b/show/main.py index ef52535725c..e3dafb492fe 100755 --- a/show/main.py +++ b/show/main.py @@ -3314,18 +3314,30 @@ def system_health(): @system_health.command() def summary(): """Show system-health summary information""" - if os.geteuid(): - click.echo("Root privileges are required for this operation") - return - from health_checker.manager import HealthCheckerManager + # Mock the redis for unit test purposes # + try: + if os.environ["UTILITIES_UNIT_TESTING"] == "1": + modules_path = os.path.join(os.path.dirname(__file__), "..") + sys.path.insert(0, modules_path) + from system_health_test import MockerManager + from system_health_test import MockerChassis + HealthCheckerManager = MockerManager + Chassis = MockerChassis + except: + # Normal run... # + if os.geteuid(): + click.echo("Root privileges are required for this operation") + return + from health_checker.manager import HealthCheckerManager + from sonic_platform.chassis import Chassis + manager = HealthCheckerManager() - state, stat = manager.check() + chassis = Chassis() + state, stat = manager.check(chassis) if state == HealthCheckerManager.STATE_BOOTING: click.echo("System is currently booting...") return if state == HealthCheckerManager.STATE_RUNNING: - from sonic_platform.chassis import Chassis - chassis = Chassis() chassis.initizalize_system_led() led = chassis.get_status_led() fault_counter = 0 @@ -3335,7 +3347,7 @@ def summary(): if elements[element]['status'] != "OK": fault_counter += 1 if fault_counter == 1: - click.echo(category + "\tFault") + click.echo(category + "\tNot OK") click.echo('\t' + elements[element]['message']) if not fault_counter: click.echo(category + "\tOK") @@ -3344,19 +3356,31 @@ def summary(): @system_health.command() def detail(): """Show system-health detail information""" - if os.geteuid(): - click.echo("Root privileges are required for this operation") - return - from health_checker.manager import HealthCheckerManager + # Mock the redis for unit test purposes # + try: + if os.environ["UTILITIES_UNIT_TESTING"] == "1": + modules_path = os.path.join(os.path.dirname(__file__), "..") + sys.path.insert(0, modules_path) + from system_health_test import MockerManager + from system_health_test import MockerChassis + HealthCheckerManager = MockerManager + Chassis = MockerChassis + except: + # Normal run... # + if os.geteuid(): + click.echo("Root privileges are required for this operation") + return + from health_checker.manager import HealthCheckerManager + from sonic_platform.chassis import Chassis + manager = HealthCheckerManager() - state, stat = manager.check() + 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 - from sonic_platform.chassis import Chassis - chassis = Chassis() chassis.initizalize_system_led() led = chassis.get_status_led() fault_counter = 0 @@ -3366,11 +3390,12 @@ def detail(): if elements[element]['status'] != "OK": fault_counter += 1 if fault_counter == 1: - click.echo(category + "\tFault") + click.echo(category + "\tNot OK") click.echo('\t' + elements[element]['message']) if not fault_counter: click.echo(category + "\tOK") fault_counter = 0 + click.echo('\nSystem services and devices monitor list\n----------------------------------------\n') header = ['Name', 'Status', 'Type'] table = [] @@ -3403,12 +3428,26 @@ def detail(): @system_health.command() def monitor_list(): """Show system-health monitored services and devices name list""" - if os.geteuid(): - click.echo("Root privileges are required for this operation") - return - from health_checker.manager import HealthCheckerManager + # Mock the redis for unit test purposes # + try: + if os.environ["UTILITIES_UNIT_TESTING"] == "1": + modules_path = os.path.join(os.path.dirname(__file__), "..") + sys.path.insert(0, modules_path) + from system_health_test import MockerManager + from system_health_test import MockerChassis + HealthCheckerManager = MockerManager + Chassis = MockerChassis + except: + # Normal run... # + if os.geteuid(): + click.echo("Root privileges are required for this operation") + return + from health_checker.manager import HealthCheckerManager + from sonic_platform.chassis import Chassis + manager = HealthCheckerManager() - state, stat = manager.check() + chassis = Chassis() + state, stat = manager.check(chassis) if state == HealthCheckerManager.STATE_BOOTING: click.echo("System is currently booting...") return diff --git a/sonic-utilities-tests/system_health_test.py b/sonic-utilities-tests/system_health_test.py new file mode 100644 index 00000000000..d286e24093c --- /dev/null +++ b/sonic-utilities-tests/system_health_test.py @@ -0,0 +1,106 @@ +#! /usr/bin/python -u + +import sys +import os +from click.testing import CliRunner +import mock_tables.dbconnector + +test_path = os.path.dirname(os.path.abspath(__file__)) +modules_path = os.path.dirname(test_path) +scripts_path = os.path.join(modules_path, "scripts") +sys.path.insert(0, modules_path) + +class MockerConfig(object): + ignore_devices = [] + ignore_services = [] + +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 + 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 + 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 + 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 + 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 + +class MockerChassis(object): + counter = 0 + + def initizalize_system_led(self): + return + + def get_status_led(self): + if not MockerChassis.counter: + MockerChassis.counter += 1 + return "red" + else: + return "green" + +import show.main as show + +class TestHealth(object): + @classmethod + def setup_class(cls): + print("SETUP") + os.environ["PATH"] += os.pathsep + scripts_path + os.environ["UTILITIES_UNIT_TESTING"] = "1" + + def test_health_summary(self): + runner = CliRunner() + result = runner.invoke(show.cli.commands["system-health"].commands["summary"]) + expected = """System is currently booting...\n""" + assert result.output == expected + result = runner.invoke(show.cli.commands["system-health"].commands["summary"]) + expected = """System status summary\n---------------------\nSystem status LED red\n\nServices\tNot OK\n\ttelemetry is not Running\n\tsnmp_subagent is not Running\nHardware\tOK\n""" + assert result.output == expected + result = runner.invoke(show.cli.commands["system-health"].commands["summary"]) + expected = """System status summary\n---------------------\nSystem status LED green\n\nServices\tOK\nHardware\tOK\n""" + assert result.output == expected + + def test_health_monitor(self): + runner = CliRunner() + result = runner.invoke(show.cli.commands["system-health"].commands["monitor-list"]) + expected = """\nSystem services and devices monitor list\n----------------------------------------\n\nName Status Type\n-------------- -------- ----------\nneighsyncd OK Process\nvrfmgrd OK Process\ntelemetry Not OK Process\ndialout_client OK Process\nzebra OK Process\nrsyslog OK Process\nsnmpd OK Process\nredis_server OK Process\nintfmgrd OK Process\norchagent OK Process\nvxlanmgrd OK Process\nlldpd_monitor OK Process\nportsyncd OK Process\nvar-log OK Filesystem\nlldpmgrd OK Process\nsyncd OK Process\nsonic OK System\nbuffermgrd OK Process\nportmgrd OK Process\nstaticd OK Process\nvlanmgrd OK Process\nlldp_syncd OK Process\nbgpcfgd OK Process\nsnmp_subagent OK Process\nroot-overlay OK Filesystem\nfpmsyncd OK Process\nsflowmgrd Not OK Process\nbgpd OK Process\nnbrmgrd OK Process\nfan12 OK Fan\npsu_1_fan_1 OK Fan\npsu_2_fan_1 OK Fan\nfan11 OK Fan\nfan10 OK Fan\nPSU 2 OK PSU\nASIC OK ASIC\nfan1 OK Fan\nPSU 1 OK PSU\nfan3 OK Fan\nfan2 OK Fan\nfan5 OK Fan\nfan4 OK Fan\nfan7 OK Fan\nfan6 OK Fan\nfan9 OK Fan\nfan8 OK Fan\n""" + assert result.output == expected + + def test_health_detail(self): + runner = CliRunner() + result = runner.invoke(show.cli.commands["system-health"].commands["detail"]) + expected = """System status summary\n---------------------\nSystem status LED green\n\nServices\tNot OK\n\ttelemetry is not Running\n\tsflowmgrd is not Running\nHardware\tNot OK\n\tFailed to get voltage minimum threshold data for PSU 2\n\tFailed to get voltage minimum threshold data for PSU 1\n\nSystem services and devices monitor list\n----------------------------------------\n\nName Status Type\n-------------- -------- ----------\nneighsyncd OK Process\nvrfmgrd OK Process\ntelemetry Not OK Process\ndialout_client OK Process\nzebra OK Process\nrsyslog OK Process\nsnmpd OK Process\nredis_server OK Process\nintfmgrd OK Process\norchagent OK Process\nvxlanmgrd OK Process\nlldpd_monitor OK Process\nportsyncd OK Process\nvar-log OK Filesystem\nlldpmgrd OK Process\nsyncd OK Process\nsonic OK System\nbuffermgrd OK Process\nportmgrd OK Process\nstaticd OK Process\nvlanmgrd OK Process\nlldp_syncd OK Process\nbgpcfgd OK Process\nsnmp_subagent OK Process\nroot-overlay OK Filesystem\nfpmsyncd OK Process\nsflowmgrd Not OK Process\nbgpd OK Process\nnbrmgrd OK Process\nfan12 OK Fan\npsu_1_fan_1 OK Fan\npsu_2_fan_1 OK Fan\nfan11 OK Fan\nfan10 OK Fan\nPSU 2 Not OK PSU\nASIC OK ASIC\nfan1 OK Fan\nPSU 1 Not OK PSU\nfan3 OK Fan\nfan2 OK Fan\nfan5 OK Fan\nfan4 OK Fan\nfan7 OK Fan\nfan6 OK Fan\nfan9 OK Fan\nfan8 OK Fan\n\nSystem services and devices ignore list\n---------------------------------------\n\nName Status Type\n------ -------- ------\n""" + assert result.output == expected + MockerConfig.ignore_devices.insert(0, "psu.voltage") + result = runner.invoke(show.cli.commands["system-health"].commands["detail"]) + expected = """System status summary\n---------------------\nSystem status LED green\n\nServices\tNot OK\n\ttelemetry is not Running\n\tsflowmgrd is not Running\nHardware\tOK\n\nSystem services and devices monitor list\n----------------------------------------\n\nName Status Type\n-------------- -------- ----------\nneighsyncd OK Process\nvrfmgrd OK Process\ntelemetry Not OK Process\ndialout_client OK Process\nzebra OK Process\nrsyslog OK Process\nsnmpd OK Process\nredis_server OK Process\nintfmgrd OK Process\norchagent OK Process\nvxlanmgrd OK Process\nlldpd_monitor OK Process\nportsyncd OK Process\nvar-log OK Filesystem\nlldpmgrd OK Process\nsyncd OK Process\nsonic OK System\nbuffermgrd OK Process\nportmgrd OK Process\nstaticd OK Process\nvlanmgrd OK Process\nlldp_syncd OK Process\nbgpcfgd OK Process\nsnmp_subagent OK Process\nroot-overlay OK Filesystem\nfpmsyncd OK Process\nsflowmgrd Not OK Process\nbgpd OK Process\nnbrmgrd OK Process\nfan12 OK Fan\npsu_1_fan_1 OK Fan\npsu_2_fan_1 OK Fan\nfan11 OK Fan\nfan10 OK Fan\nPSU 2 OK PSU\nASIC OK ASIC\nfan1 OK Fan\nPSU 1 OK PSU\nfan3 OK Fan\nfan2 OK Fan\nfan5 OK Fan\nfan4 OK Fan\nfan7 OK Fan\nfan6 OK Fan\nfan9 OK Fan\nfan8 OK Fan\n\nSystem services and devices ignore list\n---------------------------------------\n\nName Status Type\n----------- -------- ------\npsu.voltage Ignore Device\n""" + assert result.output == expected + + @classmethod + def teardown_class(cls): + print("TEARDOWN") + os.environ["PATH"] = os.pathsep.join(os.environ["PATH"].split(os.pathsep)[:-1]) + os.environ["UTILITIES_UNIT_TESTING"] = "0" + \ No newline at end of file