Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
    def test_check_speed_value_available(self):
        fan_status = thermalctld.FanStatus()

        ret = fan_status._check_speed_value_available(30, 32, 5, True)
        assert ret == True
        assert fan_status.log_warning.call_count == 0

        ret = fan_status._check_speed_value_available(
            thermalctld.NOT_AVAILABLE, 32, 105, True)
        assert ret == False
        assert fan_status.log_warning.call_count == 1
        fan_status.log_warning.assert_called_with(
            'Invalid tolerance value: 105')

        # Reset
        fan_status.log_warning.reset_mock()

        ret = fan_status._check_speed_value_available(
            thermalctld.NOT_AVAILABLE, 32, 5, False)
        assert ret == False
        assert fan_status.log_warning.call_count == 0

        ret = fan_status._check_speed_value_available(
            thermalctld.NOT_AVAILABLE, 32, 5, True)
        assert ret == False
        assert fan_status.log_warning.call_count == 1
        fan_status.log_warning.assert_called_with(
            'Fan speed or target_speed or tolerance became unavailable, speed=N/A, target_speed=32, tolerance=5'
        )
Ejemplo n.º 3
0
    def test_set_over_speed(self):
        fan_status = thermalctld.FanStatus()
        ret = fan_status.set_over_speed(thermalctld.NOT_AVAILABLE,
                                        thermalctld.NOT_AVAILABLE,
                                        thermalctld.NOT_AVAILABLE)
        assert not ret

        ret = fan_status.set_over_speed(thermalctld.NOT_AVAILABLE,
                                        thermalctld.NOT_AVAILABLE, 0)
        assert not ret

        ret = fan_status.set_over_speed(thermalctld.NOT_AVAILABLE, 0, 0)
        assert not ret

        ret = fan_status.set_over_speed(0, 0, 0)
        assert not ret

        ret = fan_status.set_over_speed(120, 100, 19)
        assert ret
        assert fan_status.over_speed
        assert not fan_status.is_ok()

        ret = fan_status.set_over_speed(120, 100, 21)
        assert ret
        assert not fan_status.over_speed
        assert fan_status.is_ok()
Ejemplo n.º 4
0
    def test_set_presence(self):
        fan_status = thermalctld.FanStatus()
        ret = fan_status.set_presence(True)
        assert fan_status.presence
        assert not ret

        ret = fan_status.set_presence(False)
        assert not fan_status.presence
        assert ret
Ejemplo n.º 5
0
    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')