[system health daemon] Support PSU power threshold checking (#11864)

This commit is contained in:
Stephen Sun 2022-11-21 23:04:58 +08:00 committed by GitHub
parent a618728d91
commit 7b4032e9ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 0 deletions

View File

@ -239,6 +239,18 @@ class HardwareChecker(HealthChecker):
voltage_min_th,
voltage_max_th))
continue
if not self._ignore_check(config.ignore_devices, 'psu', name, 'power_threshold'):
power_overload = data_dict.get('power_overload', None)
if power_overload == 'True':
try:
power = data_dict['power']
power_critical_threshold = data_dict['power_critical_threshold']
self.set_object_not_ok('PSU', name, 'power of {} ({}w) exceeds threshold ({}w)'.format(name, power, power_critical_threshold))
except KeyError:
self.set_object_not_ok('PSU', name, 'power of {} exceeds threshold but power or power_critical_threshold is invalid'.format(name))
continue
self.set_object_ok('PSU', name)
def reset(self):

View File

@ -362,6 +362,30 @@ def test_hardware_checker():
'voltage': '10',
'voltage_min_threshold': '12',
'voltage_max_threshold': '15',
},
'PSU_INFO|PSU 6': {
'presence': 'True',
'status': 'True',
'temp': '55',
'temp_threshold': '100',
'voltage': '12',
'voltage_min_threshold': '12',
'voltage_max_threshold': '15',
'power_overload': 'True',
'power': '101.0',
'power_critical_threshold': '100.0',
'power_warning_suppress_threshold': '90.0'
},
'PSU_INFO|PSU 7': {
'presence': 'True',
'status': 'True',
'temp': '55',
'temp_threshold': '100',
'voltage': '12',
'voltage_min_threshold': '12',
'voltage_max_threshold': '15',
'power_overload': 'True',
'power': '101.0'
}
})
@ -400,6 +424,14 @@ def test_hardware_checker():
assert 'PSU 5' in checker._info
assert checker._info['PSU 5'][HealthChecker.INFO_FIELD_OBJECT_STATUS] == HealthChecker.STATUS_NOT_OK
assert 'PSU 6' in checker._info
assert checker._info['PSU 6'][HealthChecker.INFO_FIELD_OBJECT_MSG] == 'power of PSU 6 (101.0w) exceeds threshold (100.0w)'
assert checker._info['PSU 6'][HealthChecker.INFO_FIELD_OBJECT_STATUS] == HealthChecker.STATUS_NOT_OK
assert 'PSU 7' in checker._info
assert checker._info['PSU 7'][HealthChecker.INFO_FIELD_OBJECT_STATUS] == HealthChecker.STATUS_NOT_OK
assert checker._info['PSU 7'][HealthChecker.INFO_FIELD_OBJECT_MSG] == 'power of PSU 7 exceeds threshold but power or power_critical_threshold is invalid'
def test_config():
config = Config()