Skip to content

Commit

Permalink
[system-health] Add fan direction check for system health (#14509)
Browse files Browse the repository at this point in the history
- Why I did it
Add fan direction check to system health, all fans should be in the same direction

- How I did it
Add fan direction check to system health, all fans should be in the same direction

- How to verify it
Manual test
Unit test
Added sonic-mgmt test case to verify
  • Loading branch information
Junchao-Mellanox authored May 10, 2023
1 parent aeaaebb commit 5e89366
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/system-health/health_checker/hardware_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def _check_fan_status(self, config):
1. Check all fans are present
2. Check all fans are in good state
3. Check fan speed is in valid range
4. Check all fans direction are the same
:param config: Health checker configuration
:return:
"""
Expand All @@ -82,6 +83,7 @@ def _check_fan_status(self, config):
self.set_object_not_ok('Fan', 'Fan', 'Failed to get fan information')
return

expect_fan_direction = None
for key in natsorted(keys):
key_list = key.split('|')
if len(key_list) != 2: # error data in DB, log it and ignore
Expand Down Expand Up @@ -133,6 +135,18 @@ def _check_fan_status(self, config):
speed_tolerance))
continue

if not self._ignore_check(config.ignore_devices, 'fan', name, 'direction'):
direction = data_dict.get('direction', 'N/A')
# ignore fan whose direction is not available to avoid too many false alarms
if direction != 'N/A':
if not expect_fan_direction:
# initialize the expect fan direction
expect_fan_direction = (name, direction)
elif direction != expect_fan_direction[1]:
self.set_object_not_ok('Fan', name,
f'{name} direction {direction} is not aligned with {expect_fan_direction[0]} direction {expect_fan_direction[1]}')
continue

status = data_dict.get('status', 'false')
if status.lower() != 'true':
self.set_object_not_ok('Fan', name, '{} is broken'.format(name))
Expand Down
15 changes: 14 additions & 1 deletion src/system-health/tests/test_system_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,8 @@ def test_hardware_checker():
'status': 'True',
'speed': '60',
'speed_target': '60',
'speed_tolerance': '20'
'speed_tolerance': '20',
'direction': 'intake'
},
'FAN_INFO|fan2': {
'presence': 'False',
Expand All @@ -320,6 +321,14 @@ def test_hardware_checker():
'speed': '20',
'speed_target': '60',
'speed_tolerance': '20'
},
'FAN_INFO|fan5': {
'presence': 'True',
'status': 'True',
'speed': '60',
'speed_target': '60',
'speed_tolerance': '20',
'direction': 'exhaust'
}
})

Expand Down Expand Up @@ -415,6 +424,10 @@ def test_hardware_checker():
assert 'fan4' in checker._info
assert checker._info['fan4'][HealthChecker.INFO_FIELD_OBJECT_STATUS] == HealthChecker.STATUS_NOT_OK

assert 'fan5' in checker._info
assert checker._info['fan5'][HealthChecker.INFO_FIELD_OBJECT_STATUS] == HealthChecker.STATUS_NOT_OK
assert checker._info['fan5'][HealthChecker.INFO_FIELD_OBJECT_MSG] == 'fan5 direction exhaust is not aligned with fan1 direction intake'

assert 'PSU 1' in checker._info
assert checker._info['PSU 1'][HealthChecker.INFO_FIELD_OBJECT_STATUS] == HealthChecker.STATUS_OK

Expand Down

0 comments on commit 5e89366

Please sign in to comment.