[system-health] Led color shall be controlled by configuration when system is booting (#12487)
* [system-health] Led color shall be controlled by configuration when system is booting * Fix unit test issue
This commit is contained in:
parent
7ed1cd0d68
commit
5ea8d0c615
@ -20,7 +20,7 @@ class Config(object):
|
||||
DEFAULT_LED_CONFIG = {
|
||||
'fault': 'red',
|
||||
'normal': 'green',
|
||||
'booting': 'orange_blink'
|
||||
'booting': 'red'
|
||||
}
|
||||
|
||||
# System health configuration file name
|
||||
|
@ -3,14 +3,13 @@ from .health_checker import HealthChecker
|
||||
from .service_checker import ServiceChecker
|
||||
from .hardware_checker import HardwareChecker
|
||||
from .user_defined_checker import UserDefinedChecker
|
||||
from . import utils
|
||||
|
||||
|
||||
class HealthCheckerManager(object):
|
||||
"""
|
||||
Manage all system health checkers and system health configuration.
|
||||
"""
|
||||
boot_timeout = None
|
||||
|
||||
def __init__(self):
|
||||
self._checkers = []
|
||||
self.config = Config()
|
||||
@ -42,9 +41,7 @@ class HealthCheckerManager(object):
|
||||
checker = UserDefinedChecker(udc)
|
||||
self._do_check(checker, stats)
|
||||
|
||||
led_status = 'normal' if HealthChecker.summary == HealthChecker.STATUS_OK else 'fault'
|
||||
self._set_system_led(chassis, self.config, led_status)
|
||||
|
||||
self._set_system_led(chassis)
|
||||
return stats
|
||||
|
||||
def _do_check(self, checker, stats):
|
||||
@ -75,10 +72,22 @@ class HealthCheckerManager(object):
|
||||
else:
|
||||
stats['Internal'].update(entry)
|
||||
|
||||
def _set_system_led(self, chassis, config, status):
|
||||
def _set_system_led(self, chassis):
|
||||
try:
|
||||
chassis.set_status_led(config.get_led_color(status))
|
||||
chassis.set_status_led(self._get_led_target_color())
|
||||
except NotImplementedError:
|
||||
print('chassis.set_status_led is not implemented')
|
||||
except Exception as e:
|
||||
print('Failed to set system led due to - {}'.format(repr(e)))
|
||||
|
||||
def _get_led_target_color(self):
|
||||
"""Get target LED color according to health status and system uptime
|
||||
|
||||
Returns:
|
||||
str: LED color
|
||||
"""
|
||||
if HealthChecker.summary == HealthChecker.STATUS_OK:
|
||||
return self.config.get_led_color('normal')
|
||||
else:
|
||||
uptime = utils.get_uptime()
|
||||
return self.config.get_led_color('booting') if uptime < self.config.get_bootup_timeout() else self.config.get_led_color('fault')
|
||||
|
@ -425,7 +425,7 @@ def test_config():
|
||||
|
||||
assert config.get_led_color('fault') == 'red'
|
||||
assert config.get_led_color('normal') == 'green'
|
||||
assert config.get_led_color('booting') == 'orange_blink'
|
||||
assert config.get_led_color('booting') == 'red'
|
||||
|
||||
config._last_mtime = 1
|
||||
config._config_file = 'notExistFile'
|
||||
@ -498,10 +498,10 @@ def test_manager(mock_hw_info, mock_service_info, mock_udc_info):
|
||||
assert stat['Internal']['UserDefinedChecker - some check']['status'] == 'Not OK'
|
||||
|
||||
chassis.set_status_led.side_effect = NotImplementedError()
|
||||
manager._set_system_led(chassis, manager.config, 'normal')
|
||||
manager._set_system_led(chassis)
|
||||
|
||||
chassis.set_status_led.side_effect = RuntimeError()
|
||||
manager._set_system_led(chassis, manager.config, 'normal')
|
||||
manager._set_system_led(chassis)
|
||||
|
||||
def test_utils():
|
||||
output = utils.run_command('some invalid command')
|
||||
@ -568,7 +568,7 @@ def test_get_app_ready_status(mock_config_db, mock_run, mock_docker_client):
|
||||
'has_global_scope': 'True',
|
||||
'has_per_asic_scope': 'False',
|
||||
'check_up_status': 'True'
|
||||
},
|
||||
},
|
||||
'snmp': {
|
||||
'state': 'enabled',
|
||||
'has_global_scope': 'True',
|
||||
@ -659,10 +659,10 @@ def test_get_all_system_status_not_ok():
|
||||
result = sysmon.get_all_system_status()
|
||||
print("result:{}".format(result))
|
||||
assert result == 'DOWN'
|
||||
|
||||
|
||||
def test_post_unit_status():
|
||||
sysmon = Sysmonitor()
|
||||
sysmon.post_unit_status("mock_bgp", 'OK', 'Down', 'mock reason', '-')
|
||||
sysmon.post_unit_status("mock_bgp", 'OK', 'Down', 'mock reason', '-')
|
||||
result = swsscommon.SonicV2Connector.get_all(MockConnector, 0, 'ALL_SERVICE_STATUS|mock_bgp')
|
||||
print(result)
|
||||
assert result['service_status'] == 'OK'
|
||||
@ -671,7 +671,7 @@ def test_post_unit_status():
|
||||
|
||||
def test_post_system_status():
|
||||
sysmon = Sysmonitor()
|
||||
sysmon.post_system_status("UP")
|
||||
sysmon.post_system_status("UP")
|
||||
result = swsscommon.SonicV2Connector.get(MockConnector, 0, "SYSTEM_READY|SYSTEM_STATE", 'Status')
|
||||
print("post system status result:{}".format(result))
|
||||
assert result == "UP"
|
||||
@ -689,7 +689,7 @@ def test_publish_system_status():
|
||||
@patch('health_checker.sysmonitor.Sysmonitor.publish_system_status', test_publish_system_status())
|
||||
def test_update_system_status():
|
||||
sysmon = Sysmonitor()
|
||||
sysmon.update_system_status()
|
||||
sysmon.update_system_status()
|
||||
result = swsscommon.SonicV2Connector.get(MockConnector, 0, "SYSTEM_READY|SYSTEM_STATE", 'Status')
|
||||
assert result == "UP"
|
||||
|
||||
|
Reference in New Issue
Block a user