@@ -41,6 +41,8 @@ def try_get(callback, default=NOT_AVAILABLE):
41
41
"""
42
42
try :
43
43
ret = callback ()
44
+ if ret is None :
45
+ ret = default
44
46
except NotImplementedError :
45
47
ret = default
46
48
@@ -174,16 +176,19 @@ class FanUpdater(object):
174
176
:return:
175
177
"""
176
178
logger .log_debug ("Start fan updating" )
177
- try :
178
- for index , fan in enumerate ( self . chassis . get_all_fans ()) :
179
+ for index , fan in enumerate ( self . chassis . get_all_fans ()) :
180
+ try :
179
181
self ._refresh_fan_status (fan , index )
182
+ except Exception as e :
183
+ logger .log_warning ('Failed to update FAN status - {}' .format (e ))
180
184
181
- for psu_index , psu in enumerate (self .chassis .get_all_psus ()):
182
- psu_name = try_get (psu .get_name , 'PSU {}' .format (psu_index ))
183
- for fan_index , fan in enumerate (psu .get_all_fans ()):
185
+ for psu_index , psu in enumerate (self .chassis .get_all_psus ()):
186
+ psu_name = try_get (psu .get_name , 'PSU {}' .format (psu_index ))
187
+ for fan_index , fan in enumerate (psu .get_all_fans ()):
188
+ try :
184
189
self ._refresh_fan_status (fan , fan_index , '{} FAN' .format (psu_name ))
185
- except Exception as e :
186
- logger .log_warning ('Failed to update FAN status - {}' .format (e ))
190
+ except Exception as e :
191
+ logger .log_warning ('Failed to update PSU FAN status - {}' .format (e ))
187
192
188
193
logger .log_debug ("End fan updating" )
189
194
@@ -201,10 +206,18 @@ class FanUpdater(object):
201
206
202
207
fan_status = self .fan_status_dict [fan_name ]
203
208
209
+ speed = NOT_AVAILABLE
210
+ speed_tolerance = NOT_AVAILABLE
211
+ speed_target = NOT_AVAILABLE
212
+ fan_fault_status = NOT_AVAILABLE
213
+ fan_direction = NOT_AVAILABLE
204
214
presence = try_get (fan .get_presence , False )
205
- speed = try_get (fan .get_speed )
206
- speed_tolerance = try_get (fan .get_speed_tolerance )
207
- speed_target = try_get (fan .get_target_speed )
215
+ if presence :
216
+ speed = try_get (fan .get_speed )
217
+ speed_tolerance = try_get (fan .get_speed_tolerance )
218
+ speed_target = try_get (fan .get_target_speed )
219
+ fan_fault_status = try_get (fan .get_status , False )
220
+ fan_direction = try_get (fan .get_direction )
208
221
209
222
set_led = False
210
223
if fan_status .set_presence (presence ):
@@ -215,15 +228,15 @@ class FanUpdater(object):
215
228
'the system, potential overheat hazard' .format (fan_name )
216
229
)
217
230
218
- if fan_status .set_under_speed (speed , speed_target , speed_tolerance ):
231
+ if presence and fan_status .set_under_speed (speed , speed_target , speed_tolerance ):
219
232
set_led = True
220
233
log_on_status_changed (not fan_status .under_speed ,
221
234
'Fan under speed warning cleared: {} speed back to normal.' .format (fan_name ),
222
235
'Fan under speed warning: {} current speed={}, target speed={}, tolerance={}.' .
223
236
format (fan_name , speed , speed_target , speed_tolerance )
224
237
)
225
238
226
- if fan_status .set_over_speed (speed , speed_target , speed_tolerance ):
239
+ if presence and fan_status .set_over_speed (speed , speed_target , speed_tolerance ):
227
240
set_led = True
228
241
log_on_status_changed (not fan_status .over_speed ,
229
242
'Fan over speed warning cleared: {} speed back to normal.' .format (fan_name ),
@@ -240,8 +253,8 @@ class FanUpdater(object):
240
253
[('presence' , str (presence )),
241
254
('model' , str (try_get (fan .get_model ))),
242
255
('serial' , str (try_get (fan .get_serial ))),
243
- ('status' , str (try_get ( fan . get_status , False ) )),
244
- ('direction' , str (try_get ( fan . get_direction ) )),
256
+ ('status' , str (fan_fault_status )),
257
+ ('direction' , str (fan_direction )),
245
258
('speed' , str (speed )),
246
259
('speed_tolerance' , str (speed_tolerance )),
247
260
('speed_target' , str (speed_target )),
@@ -378,12 +391,12 @@ class TemperatureUpdater(object):
378
391
Update all temperature information to database
379
392
:return:
380
393
"""
381
- logger .log_debug ("Start temperature updating" )
382
- try :
383
- for index , thermal in enumerate ( self . chassis . get_all_thermals ()) :
394
+ logger .log_debug ("Start temperature updating" )
395
+ for index , thermal in enumerate ( self . chassis . get_all_thermals ()) :
396
+ try :
384
397
self ._refresh_temperature_status (thermal , index )
385
- except Exception as e :
386
- logger .log_warning ('Failed to update thermal status - {}' .format (e ))
398
+ except Exception as e :
399
+ logger .log_warning ('Failed to update thermal status - {}' .format (e ))
387
400
388
401
logger .log_debug ("End temperature updating" )
389
402
@@ -400,26 +413,33 @@ class TemperatureUpdater(object):
400
413
401
414
temperature_status = self .temperature_status_dict [name ]
402
415
416
+ high_threshold = NOT_AVAILABLE
417
+ low_threshold = NOT_AVAILABLE
418
+ high_critical_threshold = NOT_AVAILABLE
419
+ low_critical_threshold = NOT_AVAILABLE
403
420
temperature = try_get (thermal .get_temperature )
404
- temperature_status .set_temperature (name , temperature )
405
- high_threshold = try_get (thermal .get_high_threshold )
406
- low_threshold = try_get (thermal .get_low_threshold )
407
-
421
+ if temperature != NOT_AVAILABLE :
422
+ temperature_status .set_temperature (name , temperature )
423
+ high_threshold = try_get (thermal .get_high_threshold )
424
+ low_threshold = try_get (thermal .get_low_threshold )
425
+ high_critical_threshold = try_get (thermal .get_high_critical_threshold )
426
+ low_critical_threshold = try_get (thermal .get_low_critical_threshold )
427
+
408
428
warning = False
409
- if temperature_status .set_over_temperature (temperature , high_threshold ):
429
+ if temperature != NOT_AVAILABLE and temperature_status .set_over_temperature (temperature , high_threshold ):
410
430
log_on_status_changed (not temperature_status .over_temperature ,
411
- 'High temperature warning: {} current temperature {}C, high threshold {}C' .
412
- format (name , temperature , high_threshold ),
413
431
'High temperature warning cleared: {} temperature restore to {}C, high threshold {}C.' .
432
+ format (name , temperature , high_threshold ),
433
+ 'High temperature warning: {} current temperature {}C, high threshold {}C' .
414
434
format (name , temperature , high_threshold )
415
435
)
416
436
warning = warning | temperature_status .over_temperature
417
437
418
- if temperature_status .set_under_temperature (temperature , low_threshold ):
438
+ if temperature != NOT_AVAILABLE and temperature_status .set_under_temperature (temperature , low_threshold ):
419
439
log_on_status_changed (not temperature_status .under_temperature ,
420
- 'Low temperature warning: {} current temperature {}C, low threshold {}C' .
421
- format (name , temperature , low_threshold ),
422
440
'Low temperature warning cleared: {} temperature restore to {}C, low threshold {}C.' .
441
+ format (name , temperature , low_threshold ),
442
+ 'Low temperature warning: {} current temperature {}C, low threshold {}C' .
423
443
format (name , temperature , low_threshold )
424
444
)
425
445
warning = warning | temperature_status .under_temperature
@@ -429,8 +449,8 @@ class TemperatureUpdater(object):
429
449
('high_threshold' , str (high_threshold )),
430
450
('low_threshold' , str (low_threshold )),
431
451
('warning_status' , str (warning )),
432
- ('critical_high_threshold' , str (try_get ( thermal . get_high_critical_threshold ) )),
433
- ('critical_low_threshold' , str (try_get ( thermal . get_low_critical_threshold ) )),
452
+ ('critical_high_threshold' , str (high_critical_threshold )),
453
+ ('critical_low_threshold' , str (low_critical_threshold )),
434
454
('timestamp' , datetime .now ().strftime ('%Y%m%d %H:%M:%S' ))
435
455
])
436
456
0 commit comments