1
1
import os
2
2
import sys
3
+ import multiprocessing
3
4
from imp import load_source # TODO: Replace with importlib once we no longer need to support Python 2
4
5
5
6
# TODO: Clean this up once we no longer need to support Python 2
@@ -148,7 +149,7 @@ class TestFanUpdater(object):
148
149
Test cases to cover functionality in FanUpdater class
149
150
"""
150
151
def test_deinit (self ):
151
- fan_updater = thermalctld .FanUpdater (MockChassis ())
152
+ fan_updater = thermalctld .FanUpdater (MockChassis (), multiprocessing . Event () )
152
153
fan_updater .fan_status_dict = {'key1' : 'value1' , 'key2' : 'value2' }
153
154
fan_updater .table ._del = mock .MagicMock ()
154
155
@@ -161,7 +162,7 @@ def test_deinit(self):
161
162
@mock .patch ('thermalctld.update_entity_info' , mock .MagicMock ())
162
163
def test_refresh_fan_drawer_status_fan_drawer_get_name_not_impl (self ):
163
164
# Test case where fan_drawer.get_name is not implemented
164
- fan_updater = thermalctld .FanUpdater (MockChassis ())
165
+ fan_updater = thermalctld .FanUpdater (MockChassis (), multiprocessing . Event () )
165
166
mock_fan_drawer = mock .MagicMock ()
166
167
fan_updater ._refresh_fan_drawer_status (mock_fan_drawer , 1 )
167
168
assert thermalctld .update_entity_info .call_count == 0
@@ -175,7 +176,7 @@ def test_update_fan_with_exception(self):
175
176
fan .make_over_speed ()
176
177
chassis .get_all_fans ().append (fan )
177
178
178
- fan_updater = thermalctld .FanUpdater (chassis )
179
+ fan_updater = thermalctld .FanUpdater (chassis , multiprocessing . Event () )
179
180
fan_updater .update ()
180
181
assert fan .get_status_led () == MockFan .STATUS_LED_COLOR_RED
181
182
assert fan_updater .log_warning .call_count == 1
@@ -192,15 +193,15 @@ def test_set_fan_led_exception(self):
192
193
mock_fan = MockFan ()
193
194
mock_fan .set_status_led = mock .MagicMock (side_effect = NotImplementedError )
194
195
195
- fan_updater = thermalctld .FanUpdater (MockChassis ())
196
+ fan_updater = thermalctld .FanUpdater (MockChassis (), multiprocessing . Event () )
196
197
fan_updater ._set_fan_led (mock_fan_drawer , mock_fan , 'Test Fan' , fan_status )
197
198
assert fan_updater .log_warning .call_count == 1
198
199
fan_updater .log_warning .assert_called_with ('Failed to set status LED for fan Test Fan, set_status_led not implemented' )
199
200
200
201
def test_fan_absent (self ):
201
202
chassis = MockChassis ()
202
203
chassis .make_absent_fan ()
203
- fan_updater = thermalctld .FanUpdater (chassis )
204
+ fan_updater = thermalctld .FanUpdater (chassis , multiprocessing . Event () )
204
205
fan_updater .update ()
205
206
fan_list = chassis .get_all_fans ()
206
207
assert fan_list [0 ].get_status_led () == MockFan .STATUS_LED_COLOR_RED
@@ -224,7 +225,7 @@ def test_fan_absent(self):
224
225
def test_fan_faulty (self ):
225
226
chassis = MockChassis ()
226
227
chassis .make_faulty_fan ()
227
- fan_updater = thermalctld .FanUpdater (chassis )
228
+ fan_updater = thermalctld .FanUpdater (chassis , multiprocessing . Event () )
228
229
fan_updater .update ()
229
230
fan_list = chassis .get_all_fans ()
230
231
assert fan_list [0 ].get_status_led () == MockFan .STATUS_LED_COLOR_RED
@@ -248,7 +249,7 @@ def test_fan_faulty(self):
248
249
def test_fan_under_speed (self ):
249
250
chassis = MockChassis ()
250
251
chassis .make_under_speed_fan ()
251
- fan_updater = thermalctld .FanUpdater (chassis )
252
+ fan_updater = thermalctld .FanUpdater (chassis , multiprocessing . Event () )
252
253
fan_updater .update ()
253
254
fan_list = chassis .get_all_fans ()
254
255
assert fan_list [0 ].get_status_led () == MockFan .STATUS_LED_COLOR_RED
@@ -264,7 +265,7 @@ def test_fan_under_speed(self):
264
265
def test_fan_over_speed (self ):
265
266
chassis = MockChassis ()
266
267
chassis .make_over_speed_fan ()
267
- fan_updater = thermalctld .FanUpdater (chassis )
268
+ fan_updater = thermalctld .FanUpdater (chassis , multiprocessing . Event () )
268
269
fan_updater .update ()
269
270
fan_list = chassis .get_all_fans ()
270
271
assert fan_list [0 ].get_status_led () == MockFan .STATUS_LED_COLOR_RED
@@ -283,7 +284,7 @@ def test_update_psu_fans(self):
283
284
mock_fan = MockFan ()
284
285
psu ._fan_list .append (mock_fan )
285
286
chassis ._psu_list .append (psu )
286
- fan_updater = thermalctld .FanUpdater (chassis )
287
+ fan_updater = thermalctld .FanUpdater (chassis , multiprocessing . Event () )
287
288
fan_updater .update ()
288
289
assert fan_updater .log_warning .call_count == 0
289
290
@@ -331,7 +332,7 @@ def test_insufficient_fan_number():
331
332
chassis = MockChassis ()
332
333
chassis .make_absent_fan ()
333
334
chassis .make_faulty_fan ()
334
- fan_updater = thermalctld .FanUpdater (chassis )
335
+ fan_updater = thermalctld .FanUpdater (chassis , multiprocessing . Event () )
335
336
fan_updater .update ()
336
337
assert fan_updater .log_warning .call_count == 3
337
338
expected_calls = [
@@ -415,19 +416,20 @@ class TestTemperatureUpdater(object):
415
416
"""
416
417
def test_deinit (self ):
417
418
chassis = MockChassis ()
418
- temp_updater = thermalctld .TemperatureUpdater (chassis )
419
+ temp_updater = thermalctld .TemperatureUpdater (chassis , multiprocessing . Event () )
419
420
temp_updater .temperature_status_dict = {'key1' : 'value1' , 'key2' : 'value2' }
420
421
temp_updater .table ._del = mock .MagicMock ()
421
422
422
423
temp_updater .deinit ()
423
424
assert temp_updater .table ._del .call_count == 2
424
425
expected_calls = [mock .call ('key1' ), mock .call ('key2' )]
425
426
temp_updater .table ._del .assert_has_calls (expected_calls , any_order = True )
427
+
426
428
427
429
def test_over_temper (self ):
428
430
chassis = MockChassis ()
429
431
chassis .make_over_temper_thermal ()
430
- temperature_updater = thermalctld .TemperatureUpdater (chassis )
432
+ temperature_updater = thermalctld .TemperatureUpdater (chassis , multiprocessing . Event () )
431
433
temperature_updater .update ()
432
434
thermal_list = chassis .get_all_thermals ()
433
435
assert temperature_updater .log_warning .call_count == 1
@@ -441,7 +443,7 @@ def test_over_temper(self):
441
443
def test_under_temper (self ):
442
444
chassis = MockChassis ()
443
445
chassis .make_under_temper_thermal ()
444
- temperature_updater = thermalctld .TemperatureUpdater (chassis )
446
+ temperature_updater = thermalctld .TemperatureUpdater (chassis , multiprocessing . Event () )
445
447
temperature_updater .update ()
446
448
thermal_list = chassis .get_all_thermals ()
447
449
assert temperature_updater .log_warning .call_count == 1
@@ -458,7 +460,7 @@ def test_update_psu_thermals(self):
458
460
mock_thermal = MockThermal ()
459
461
psu ._thermal_list .append (mock_thermal )
460
462
chassis ._psu_list .append (psu )
461
- temperature_updater = thermalctld .TemperatureUpdater (chassis )
463
+ temperature_updater = thermalctld .TemperatureUpdater (chassis , multiprocessing . Event () )
462
464
temperature_updater .update ()
463
465
assert temperature_updater .log_warning .call_count == 0
464
466
@@ -478,7 +480,7 @@ def test_update_sfp_thermals(self):
478
480
mock_thermal = MockThermal ()
479
481
sfp ._thermal_list .append (mock_thermal )
480
482
chassis ._sfp_list .append (sfp )
481
- temperature_updater = thermalctld .TemperatureUpdater (chassis )
483
+ temperature_updater = thermalctld .TemperatureUpdater (chassis , multiprocessing . Event () )
482
484
temperature_updater .update ()
483
485
assert temperature_updater .log_warning .call_count == 0
484
486
@@ -499,7 +501,7 @@ def test_update_thermal_with_exception(self):
499
501
thermal .make_over_temper ()
500
502
chassis .get_all_thermals ().append (thermal )
501
503
502
- temperature_updater = thermalctld .TemperatureUpdater (chassis )
504
+ temperature_updater = thermalctld .TemperatureUpdater (chassis , multiprocessing . Event () )
503
505
temperature_updater .update ()
504
506
assert temperature_updater .log_warning .call_count == 2
505
507
@@ -524,17 +526,17 @@ def test_updater_thermal_check_modular_chassis():
524
526
chassis = MockChassis ()
525
527
assert chassis .is_modular_chassis () == False
526
528
527
- temperature_updater = thermalctld .TemperatureUpdater (chassis )
529
+ temperature_updater = thermalctld .TemperatureUpdater (chassis , multiprocessing . Event () )
528
530
assert temperature_updater .chassis_table == None
529
531
530
532
chassis .set_modular_chassis (True )
531
533
chassis .set_my_slot (- 1 )
532
- temperature_updater = thermalctld .TemperatureUpdater (chassis )
534
+ temperature_updater = thermalctld .TemperatureUpdater (chassis , multiprocessing . Event () )
533
535
assert temperature_updater .chassis_table == None
534
536
535
537
my_slot = 1
536
538
chassis .set_my_slot (my_slot )
537
- temperature_updater = thermalctld .TemperatureUpdater (chassis )
539
+ temperature_updater = thermalctld .TemperatureUpdater (chassis , multiprocessing . Event () )
538
540
assert temperature_updater .chassis_table != None
539
541
assert temperature_updater .chassis_table .table_name == '{}_{}' .format (TEMPER_INFO_TABLE_NAME , str (my_slot ))
540
542
@@ -547,7 +549,7 @@ def test_updater_thermal_check_chassis_table():
547
549
548
550
chassis .set_modular_chassis (True )
549
551
chassis .set_my_slot (1 )
550
- temperature_updater = thermalctld .TemperatureUpdater (chassis )
552
+ temperature_updater = thermalctld .TemperatureUpdater (chassis , multiprocessing . Event () )
551
553
552
554
temperature_updater .update ()
553
555
assert temperature_updater .chassis_table .get_size () == chassis .get_num_thermals ()
@@ -566,7 +568,7 @@ def test_updater_thermal_check_min_max():
566
568
567
569
chassis .set_modular_chassis (True )
568
570
chassis .set_my_slot (1 )
569
- temperature_updater = thermalctld .TemperatureUpdater (chassis )
571
+ temperature_updater = thermalctld .TemperatureUpdater (chassis , multiprocessing . Event () )
570
572
571
573
temperature_updater .update ()
572
574
slot_dict = temperature_updater .chassis_table .get (thermal .get_name ())
@@ -580,26 +582,30 @@ def test_signal_handler():
580
582
daemon_thermalctld .stop_event .set = mock .MagicMock ()
581
583
daemon_thermalctld .log_info = mock .MagicMock ()
582
584
daemon_thermalctld .log_warning = mock .MagicMock ()
585
+ daemon_thermalctld .thermal_manager .stop = mock .MagicMock ()
583
586
daemon_thermalctld .signal_handler (thermalctld .signal .SIGHUP , None )
584
587
daemon_thermalctld .deinit () # Deinit becuase the test will hang if we assert
585
588
assert daemon_thermalctld .log_info .call_count == 1
586
589
daemon_thermalctld .log_info .assert_called_with ("Caught signal 'SIGHUP' - ignoring..." )
587
590
assert daemon_thermalctld .log_warning .call_count == 0
588
591
assert daemon_thermalctld .stop_event .set .call_count == 0
592
+ assert daemon_thermalctld .thermal_manager .stop .call_count == 0
589
593
assert thermalctld .exit_code == thermalctld .ERR_UNKNOWN
590
594
591
595
# Test SIGINT
592
596
daemon_thermalctld = thermalctld .ThermalControlDaemon ()
593
597
daemon_thermalctld .stop_event .set = mock .MagicMock ()
594
598
daemon_thermalctld .log_info = mock .MagicMock ()
595
599
daemon_thermalctld .log_warning = mock .MagicMock ()
600
+ daemon_thermalctld .thermal_manager .stop = mock .MagicMock ()
596
601
test_signal = thermalctld .signal .SIGINT
597
602
daemon_thermalctld .signal_handler (test_signal , None )
598
603
daemon_thermalctld .deinit () # Deinit becuase the test will hang if we assert
599
604
assert daemon_thermalctld .log_info .call_count == 1
600
605
daemon_thermalctld .log_info .assert_called_with ("Caught signal 'SIGINT' - exiting..." )
601
606
assert daemon_thermalctld .log_warning .call_count == 0
602
607
assert daemon_thermalctld .stop_event .set .call_count == 1
608
+ assert daemon_thermalctld .thermal_manager .stop .call_count == 1
603
609
assert thermalctld .exit_code == (128 + test_signal )
604
610
605
611
# Test SIGTERM
@@ -608,13 +614,15 @@ def test_signal_handler():
608
614
daemon_thermalctld .stop_event .set = mock .MagicMock ()
609
615
daemon_thermalctld .log_info = mock .MagicMock ()
610
616
daemon_thermalctld .log_warning = mock .MagicMock ()
617
+ daemon_thermalctld .thermal_manager .stop = mock .MagicMock ()
611
618
test_signal = thermalctld .signal .SIGTERM
612
619
daemon_thermalctld .signal_handler (test_signal , None )
613
620
daemon_thermalctld .deinit () # Deinit becuase the test will hang if we assert
614
621
assert daemon_thermalctld .log_info .call_count == 1
615
622
daemon_thermalctld .log_info .assert_called_with ("Caught signal 'SIGTERM' - exiting..." )
616
623
assert daemon_thermalctld .log_warning .call_count == 0
617
624
assert daemon_thermalctld .stop_event .set .call_count == 1
625
+ assert daemon_thermalctld .thermal_manager .stop .call_count == 1
618
626
assert thermalctld .exit_code == (128 + test_signal )
619
627
620
628
# Test an unhandled signal
@@ -623,12 +631,14 @@ def test_signal_handler():
623
631
daemon_thermalctld .stop_event .set = mock .MagicMock ()
624
632
daemon_thermalctld .log_info = mock .MagicMock ()
625
633
daemon_thermalctld .log_warning = mock .MagicMock ()
634
+ daemon_thermalctld .thermal_manager .stop = mock .MagicMock ()
626
635
daemon_thermalctld .signal_handler (thermalctld .signal .SIGUSR1 , None )
627
636
daemon_thermalctld .deinit () # Deinit becuase the test will hang if we assert
628
637
assert daemon_thermalctld .log_warning .call_count == 1
629
638
daemon_thermalctld .log_warning .assert_called_with ("Caught unhandled signal 'SIGUSR1' - ignoring..." )
630
639
assert daemon_thermalctld .log_info .call_count == 0
631
640
assert daemon_thermalctld .stop_event .set .call_count == 0
641
+ assert daemon_thermalctld .thermal_manager .stop .call_count == 0
632
642
assert thermalctld .exit_code == thermalctld .ERR_UNKNOWN
633
643
634
644
0 commit comments