Skip to content

Commit 5e89366

Browse files
[system-health] Add fan direction check for system health (sonic-net#14509)
- 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
1 parent aeaaebb commit 5e89366

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/system-health/health_checker/hardware_checker.py

+14
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def _check_fan_status(self, config):
7171
1. Check all fans are present
7272
2. Check all fans are in good state
7373
3. Check fan speed is in valid range
74+
4. Check all fans direction are the same
7475
:param config: Health checker configuration
7576
:return:
7677
"""
@@ -82,6 +83,7 @@ def _check_fan_status(self, config):
8283
self.set_object_not_ok('Fan', 'Fan', 'Failed to get fan information')
8384
return
8485

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

138+
if not self._ignore_check(config.ignore_devices, 'fan', name, 'direction'):
139+
direction = data_dict.get('direction', 'N/A')
140+
# ignore fan whose direction is not available to avoid too many false alarms
141+
if direction != 'N/A':
142+
if not expect_fan_direction:
143+
# initialize the expect fan direction
144+
expect_fan_direction = (name, direction)
145+
elif direction != expect_fan_direction[1]:
146+
self.set_object_not_ok('Fan', name,
147+
f'{name} direction {direction} is not aligned with {expect_fan_direction[0]} direction {expect_fan_direction[1]}')
148+
continue
149+
136150
status = data_dict.get('status', 'false')
137151
if status.lower() != 'true':
138152
self.set_object_not_ok('Fan', name, '{} is broken'.format(name))

src/system-health/tests/test_system_health.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,8 @@ def test_hardware_checker():
298298
'status': 'True',
299299
'speed': '60',
300300
'speed_target': '60',
301-
'speed_tolerance': '20'
301+
'speed_tolerance': '20',
302+
'direction': 'intake'
302303
},
303304
'FAN_INFO|fan2': {
304305
'presence': 'False',
@@ -320,6 +321,14 @@ def test_hardware_checker():
320321
'speed': '20',
321322
'speed_target': '60',
322323
'speed_tolerance': '20'
324+
},
325+
'FAN_INFO|fan5': {
326+
'presence': 'True',
327+
'status': 'True',
328+
'speed': '60',
329+
'speed_target': '60',
330+
'speed_tolerance': '20',
331+
'direction': 'exhaust'
323332
}
324333
})
325334

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

427+
assert 'fan5' in checker._info
428+
assert checker._info['fan5'][HealthChecker.INFO_FIELD_OBJECT_STATUS] == HealthChecker.STATUS_NOT_OK
429+
assert checker._info['fan5'][HealthChecker.INFO_FIELD_OBJECT_MSG] == 'fan5 direction exhaust is not aligned with fan1 direction intake'
430+
418431
assert 'PSU 1' in checker._info
419432
assert checker._info['PSU 1'][HealthChecker.INFO_FIELD_OBJECT_STATUS] == HealthChecker.STATUS_OK
420433

0 commit comments

Comments
 (0)