def test_fan_faulty(self): chassis = MockChassis() chassis.make_faulty_fan() fan_updater = thermalctld.FanUpdater(chassis) fan_updater.update() fan_list = chassis.get_all_fans() assert fan_list[0].get_status_led() == MockFan.STATUS_LED_COLOR_RED assert fan_updater.log_warning.call_count == 2 expected_calls = [ mock.call('Fan fault warning: FanDrawer 0 fan 1 is broken'), mock.call( 'Insufficient number of working fans warning: 1 fan is not working' ) ] assert fan_updater.log_warning.mock_calls == expected_calls fan_list[0].set_status(True) fan_updater.update() assert fan_list[0].get_status_led() == MockFan.STATUS_LED_COLOR_GREEN assert fan_updater.log_notice.call_count == 2 expected_calls = [ mock.call( 'Fan fault warning cleared: FanDrawer 0 fan 1 is back to normal' ), mock.call( 'Insufficient number of working fans warning cleared: all fans are back to normal' ) ] assert fan_updater.log_notice.mock_calls == expected_calls
def test_refresh_fan_drawer_status_fan_drawer_get_name_not_impl(self): # Test case where fan_drawer.get_name is not implemented fan_updater = thermalctld.FanUpdater(MockChassis(), multiprocessing.Event()) mock_fan_drawer = mock.MagicMock() fan_updater._refresh_fan_drawer_status(mock_fan_drawer, 1) assert thermalctld.update_entity_info.call_count == 0
def test_fan_absent(self): chassis = MockChassis() chassis.make_absent_fan() fan_updater = thermalctld.FanUpdater(chassis) fan_updater.update() fan_list = chassis.get_all_fans() assert fan_list[0].get_status_led() == MockFan.STATUS_LED_COLOR_RED assert fan_updater.log_warning.call_count == 2 expected_calls = [ mock.call( 'Fan removed warning: FanDrawer 0 fan 1 was removed from the system, potential overheat hazard' ), mock.call( 'Insufficient number of working fans warning: 1 fan is not working' ) ] assert fan_updater.log_warning.mock_calls == expected_calls fan_list[0].set_presence(True) fan_updater.update() assert fan_list[0].get_status_led() == MockFan.STATUS_LED_COLOR_GREEN assert fan_updater.log_notice.call_count == 2 expected_calls = [ mock.call( 'Fan removed warning cleared: FanDrawer 0 fan 1 was inserted'), mock.call( 'Insufficient number of working fans warning cleared: all fans are back to normal' ) ] assert fan_updater.log_notice.mock_calls == expected_calls
def test_deinit(self): fan_updater = thermalctld.FanUpdater(MockChassis()) fan_updater.fan_status_dict = {'key1': 'value1', 'key2': 'value2'} fan_updater.table._del = mock.MagicMock() fan_updater.deinit() assert fan_updater.table._del.call_count == 2 expected_calls = [mock.call('key1'), mock.call('key2')] fan_updater.table._del.assert_has_calls(expected_calls, any_order=True)
def test_set_fan_led_exception(self): fan_status = thermalctld.FanStatus() mock_fan_drawer = mock.MagicMock() mock_fan = MockFan() mock_fan.set_status_led = mock.MagicMock(side_effect=NotImplementedError) fan_updater = thermalctld.FanUpdater(MockChassis(), multiprocessing.Event()) fan_updater._set_fan_led(mock_fan_drawer, mock_fan, 'Test Fan', fan_status) assert fan_updater.log_warning.call_count == 1 fan_updater.log_warning.assert_called_with('Failed to set status LED for fan Test Fan, set_status_led not implemented')
def test_insufficient_fan_number(): fan_status1 = thermalctld.FanStatus() fan_status2 = thermalctld.FanStatus() fan_status1.set_presence(False) fan_status2.set_fault_status(False) assert thermalctld.FanStatus.get_bad_fan_count() == 2 assert fan_status1.get_bad_fan_count() == 2 assert fan_status2.get_bad_fan_count() == 2 thermalctld.FanStatus.reset_fan_counter() assert thermalctld.FanStatus.get_bad_fan_count() == 0 assert fan_status1.get_bad_fan_count() == 0 assert fan_status2.get_bad_fan_count() == 0 chassis = MockChassis() chassis.make_absent_fan() chassis.make_faulty_fan() fan_updater = thermalctld.FanUpdater(chassis) fan_updater.update() assert fan_updater.log_warning.call_count == 3 expected_calls = [ mock.call( 'Fan removed warning: FanDrawer 0 fan 1 was removed from the system, potential overheat hazard' ), mock.call('Fan fault warning: FanDrawer 1 fan 1 is broken'), mock.call( 'Insufficient number of working fans warning: 2 fans are not working' ) ] assert fan_updater.log_warning.mock_calls == expected_calls fan_list = chassis.get_all_fans() fan_list[0].set_presence(True) fan_updater.update() assert fan_updater.log_notice.call_count == 1 fan_updater.log_warning.assert_called_with( 'Insufficient number of working fans warning: 1 fan is not working') fan_list[1].set_status(True) fan_updater.update() assert fan_updater.log_notice.call_count == 3 expected_calls = [ mock.call( 'Fan removed warning cleared: FanDrawer 0 fan 1 was inserted'), mock.call( 'Fan fault warning cleared: FanDrawer 1 fan 1 is back to normal'), mock.call( 'Insufficient number of working fans warning cleared: all fans are back to normal' ) ] assert fan_updater.log_notice.mock_calls == expected_calls
def test_fan_over_speed(self): chassis = MockChassis() chassis.make_over_speed_fan() fan_updater = thermalctld.FanUpdater(chassis, multiprocessing.Event()) fan_updater.update() fan_list = chassis.get_all_fans() assert fan_list[0].get_status_led() == MockFan.STATUS_LED_COLOR_RED assert fan_updater.log_warning.call_count == 1 fan_updater.log_warning.assert_called_with('Fan high speed warning: FanDrawer 0 fan 1 target speed=1, current speed=2, tolerance=0') fan_list[0].make_normal_speed() fan_updater.update() assert fan_list[0].get_status_led() == MockFan.STATUS_LED_COLOR_GREEN assert fan_updater.log_notice.call_count == 1 fan_updater.log_notice.assert_called_with('Fan high speed warning cleared: FanDrawer 0 fan 1 speed is back to normal')
def test_update_fan_with_exception(self): chassis = MockChassis() chassis.make_error_fan() fan = MockFan() fan.make_over_speed() chassis.get_all_fans().append(fan) fan_updater = thermalctld.FanUpdater(chassis, multiprocessing.Event()) fan_updater.update() assert fan.get_status_led() == MockFan.STATUS_LED_COLOR_RED assert fan_updater.log_warning.call_count == 1 # TODO: Clean this up once we no longer need to support Python 2 if sys.version_info.major == 3: fan_updater.log_warning.assert_called_with("Failed to update fan status - Exception('Failed to get speed')") else: fan_updater.log_warning.assert_called_with("Failed to update fan status - Exception('Failed to get speed',)")
def test_update_psu_fans(self): chassis = MockChassis() psu = MockPsu() mock_fan = MockFan() psu._fan_list.append(mock_fan) chassis._psu_list.append(psu) fan_updater = thermalctld.FanUpdater(chassis, multiprocessing.Event()) fan_updater.update() assert fan_updater.log_warning.call_count == 0 fan_updater._refresh_fan_status = mock.MagicMock(side_effect=Exception("Test message")) fan_updater.update() assert fan_updater.log_warning.call_count == 1 # TODO: Clean this up once we no longer need to support Python 2 if sys.version_info.major == 3: fan_updater.log_warning.assert_called_with("Failed to update PSU fan status - Exception('Test message')") else: fan_updater.log_warning.assert_called_with("Failed to update PSU fan status - Exception('Test message',)")