[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
f189986386
commit
ffa974c7f4
@ -20,7 +20,7 @@ class Config(object):
|
|||||||
DEFAULT_LED_CONFIG = {
|
DEFAULT_LED_CONFIG = {
|
||||||
'fault': 'red',
|
'fault': 'red',
|
||||||
'normal': 'green',
|
'normal': 'green',
|
||||||
'booting': 'orange_blink'
|
'booting': 'red'
|
||||||
}
|
}
|
||||||
|
|
||||||
# System health configuration file name
|
# System health configuration file name
|
||||||
|
@ -3,14 +3,13 @@ from .health_checker import HealthChecker
|
|||||||
from .service_checker import ServiceChecker
|
from .service_checker import ServiceChecker
|
||||||
from .hardware_checker import HardwareChecker
|
from .hardware_checker import HardwareChecker
|
||||||
from .user_defined_checker import UserDefinedChecker
|
from .user_defined_checker import UserDefinedChecker
|
||||||
|
from . import utils
|
||||||
|
|
||||||
|
|
||||||
class HealthCheckerManager(object):
|
class HealthCheckerManager(object):
|
||||||
"""
|
"""
|
||||||
Manage all system health checkers and system health configuration.
|
Manage all system health checkers and system health configuration.
|
||||||
"""
|
"""
|
||||||
boot_timeout = None
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._checkers = []
|
self._checkers = []
|
||||||
self.config = Config()
|
self.config = Config()
|
||||||
@ -42,9 +41,7 @@ class HealthCheckerManager(object):
|
|||||||
checker = UserDefinedChecker(udc)
|
checker = UserDefinedChecker(udc)
|
||||||
self._do_check(checker, stats)
|
self._do_check(checker, stats)
|
||||||
|
|
||||||
led_status = 'normal' if HealthChecker.summary == HealthChecker.STATUS_OK else 'fault'
|
self._set_system_led(chassis)
|
||||||
self._set_system_led(chassis, self.config, led_status)
|
|
||||||
|
|
||||||
return stats
|
return stats
|
||||||
|
|
||||||
def _do_check(self, checker, stats):
|
def _do_check(self, checker, stats):
|
||||||
@ -75,10 +72,22 @@ class HealthCheckerManager(object):
|
|||||||
else:
|
else:
|
||||||
stats['Internal'].update(entry)
|
stats['Internal'].update(entry)
|
||||||
|
|
||||||
def _set_system_led(self, chassis, config, status):
|
def _set_system_led(self, chassis):
|
||||||
try:
|
try:
|
||||||
chassis.set_status_led(config.get_led_color(status))
|
chassis.set_status_led(self._get_led_target_color())
|
||||||
except NotImplementedError:
|
except NotImplementedError:
|
||||||
print('chassis.set_status_led is not implemented')
|
print('chassis.set_status_led is not implemented')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print('Failed to set system led due to - {}'.format(repr(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')
|
||||||
|
@ -457,7 +457,7 @@ def test_config():
|
|||||||
|
|
||||||
assert config.get_led_color('fault') == 'red'
|
assert config.get_led_color('fault') == 'red'
|
||||||
assert config.get_led_color('normal') == 'green'
|
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._last_mtime = 1
|
||||||
config._config_file = 'notExistFile'
|
config._config_file = 'notExistFile'
|
||||||
@ -530,10 +530,10 @@ def test_manager(mock_hw_info, mock_service_info, mock_udc_info):
|
|||||||
assert stat['Internal']['UserDefinedChecker - some check']['status'] == 'Not OK'
|
assert stat['Internal']['UserDefinedChecker - some check']['status'] == 'Not OK'
|
||||||
|
|
||||||
chassis.set_status_led.side_effect = NotImplementedError()
|
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()
|
chassis.set_status_led.side_effect = RuntimeError()
|
||||||
manager._set_system_led(chassis, manager.config, 'normal')
|
manager._set_system_led(chassis)
|
||||||
|
|
||||||
def test_utils():
|
def test_utils():
|
||||||
output = utils.run_command(['some', 'invalid', 'command'])
|
output = utils.run_command(['some', 'invalid', 'command'])
|
||||||
@ -600,7 +600,7 @@ def test_get_app_ready_status(mock_config_db, mock_run, mock_docker_client):
|
|||||||
'has_global_scope': 'True',
|
'has_global_scope': 'True',
|
||||||
'has_per_asic_scope': 'False',
|
'has_per_asic_scope': 'False',
|
||||||
'check_up_status': 'True'
|
'check_up_status': 'True'
|
||||||
},
|
},
|
||||||
'snmp': {
|
'snmp': {
|
||||||
'state': 'enabled',
|
'state': 'enabled',
|
||||||
'has_global_scope': 'True',
|
'has_global_scope': 'True',
|
||||||
@ -691,10 +691,10 @@ def test_get_all_system_status_not_ok():
|
|||||||
result = sysmon.get_all_system_status()
|
result = sysmon.get_all_system_status()
|
||||||
print("result:{}".format(result))
|
print("result:{}".format(result))
|
||||||
assert result == 'DOWN'
|
assert result == 'DOWN'
|
||||||
|
|
||||||
def test_post_unit_status():
|
def test_post_unit_status():
|
||||||
sysmon = Sysmonitor()
|
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')
|
result = swsscommon.SonicV2Connector.get_all(MockConnector, 0, 'ALL_SERVICE_STATUS|mock_bgp')
|
||||||
print(result)
|
print(result)
|
||||||
assert result['service_status'] == 'OK'
|
assert result['service_status'] == 'OK'
|
||||||
@ -703,7 +703,7 @@ def test_post_unit_status():
|
|||||||
|
|
||||||
def test_post_system_status():
|
def test_post_system_status():
|
||||||
sysmon = Sysmonitor()
|
sysmon = Sysmonitor()
|
||||||
sysmon.post_system_status("UP")
|
sysmon.post_system_status("UP")
|
||||||
result = swsscommon.SonicV2Connector.get(MockConnector, 0, "SYSTEM_READY|SYSTEM_STATE", 'Status')
|
result = swsscommon.SonicV2Connector.get(MockConnector, 0, "SYSTEM_READY|SYSTEM_STATE", 'Status')
|
||||||
print("post system status result:{}".format(result))
|
print("post system status result:{}".format(result))
|
||||||
assert result == "UP"
|
assert result == "UP"
|
||||||
@ -721,7 +721,7 @@ def test_publish_system_status():
|
|||||||
@patch('health_checker.sysmonitor.Sysmonitor.publish_system_status', test_publish_system_status())
|
@patch('health_checker.sysmonitor.Sysmonitor.publish_system_status', test_publish_system_status())
|
||||||
def test_update_system_status():
|
def test_update_system_status():
|
||||||
sysmon = Sysmonitor()
|
sysmon = Sysmonitor()
|
||||||
sysmon.update_system_status()
|
sysmon.update_system_status()
|
||||||
result = swsscommon.SonicV2Connector.get(MockConnector, 0, "SYSTEM_READY|SYSTEM_STATE", 'Status')
|
result = swsscommon.SonicV2Connector.get(MockConnector, 0, "SYSTEM_READY|SYSTEM_STATE", 'Status')
|
||||||
assert result == "UP"
|
assert result == "UP"
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user