Пример #1
0
    def test_update_thermal_with_exception(self):
        chassis = MockChassis()
        chassis.make_error_thermal()
        thermal = MockThermal()
        thermal.make_over_temper()
        chassis.get_all_thermals().append(thermal)

        temperature_updater = thermalctld.TemperatureUpdater(chassis)
        temperature_updater.update()
        assert temperature_updater.log_warning.call_count == 2

        # TODO: Clean this up once we no longer need to support Python 2
        if sys.version_info.major == 3:
            expected_calls = [
                mock.call(
                    "Failed to update thermal status - Exception('Failed to get temperature')"
                ),
                mock.call(
                    'High temperature warning: chassis 1 Thermal 2 current temperature 3C, high threshold 2C'
                )
            ]
        else:
            expected_calls = [
                mock.call(
                    "Failed to update thermal status - Exception('Failed to get temperature',)"
                ),
                mock.call(
                    'High temperature warning: chassis 1 Thermal 2 current temperature 3C, high threshold 2C'
                )
            ]
        assert temperature_updater.log_warning.mock_calls == expected_calls
Пример #2
0
def test_updater_thermal_check_modular_chassis():
    chassis = MockChassis()
    assert chassis.is_modular_chassis() == False

    temperature_updater = thermalctld.TemperatureUpdater(chassis, multiprocessing.Event())
    assert temperature_updater.chassis_table == None

    chassis.set_modular_chassis(True)
    chassis.set_my_slot(-1)
    temperature_updater = thermalctld.TemperatureUpdater(chassis, multiprocessing.Event())
    assert temperature_updater.chassis_table == None

    my_slot = 1
    chassis.set_my_slot(my_slot)
    temperature_updater = thermalctld.TemperatureUpdater(chassis, multiprocessing.Event())
    assert temperature_updater.chassis_table != None
    assert temperature_updater.chassis_table.table_name == '{}_{}'.format(TEMPER_INFO_TABLE_NAME, str(my_slot))
Пример #3
0
    def test_deinit(self):
        chassis = MockChassis()
        temp_updater = thermalctld.TemperatureUpdater(chassis, multiprocessing.Event())
        temp_updater.temperature_status_dict = {'key1': 'value1', 'key2': 'value2'}
        temp_updater.table._del = mock.MagicMock()

        temp_updater.deinit()
        assert temp_updater.table._del.call_count == 2
        expected_calls = [mock.call('key1'), mock.call('key2')]
        temp_updater.table._del.assert_has_calls(expected_calls, any_order=True)
Пример #4
0
 def test_update_module_thermals(self):
     chassis = MockChassis()
     chassis.make_module_thermal()
     chassis.set_modular_chassis(True)
     temperature_updater = thermalctld.TemperatureUpdater(chassis, multiprocessing.Event())
     temperature_updater.update()
     assert len(temperature_updater.module_thermals) == 3
     
     chassis._module_list = []
     temperature_updater.update()
     assert len(temperature_updater.module_thermals) == 0
Пример #5
0
    def test_under_temper(self):
        chassis = MockChassis()
        chassis.make_under_temper_thermal()
        temperature_updater = thermalctld.TemperatureUpdater(chassis, multiprocessing.Event())
        temperature_updater.update()
        thermal_list = chassis.get_all_thermals()
        assert temperature_updater.log_warning.call_count == 1
        temperature_updater.log_warning.assert_called_with('Low temperature warning: chassis 1 Thermal 1 current temperature 1C, low threshold 2C')

        thermal_list[0].make_normal_temper()
        temperature_updater.update()
        assert temperature_updater.log_notice.call_count == 1
        temperature_updater.log_notice.assert_called_with('Low temperature warning cleared: chassis 1 Thermal 1 temperature restored to 2C, low threshold 1C')
Пример #6
0
def test_updater_thermal_check_min_max():
    chassis = MockChassis()

    thermal = MockThermal(1)
    chassis.get_all_thermals().append(thermal)

    chassis.set_modular_chassis(True)
    chassis.set_my_slot(1)
    temperature_updater = thermalctld.TemperatureUpdater(chassis, multiprocessing.Event())

    temperature_updater.update()
    slot_dict = temperature_updater.chassis_table.get(thermal.get_name())
    assert slot_dict['minimum_temperature'] == str(thermal.get_minimum_recorded())
    assert slot_dict['maximum_temperature'] == str(thermal.get_maximum_recorded())
Пример #7
0
    def test_over_temper(self):
        chassis = MockChassis()
        chassis.make_over_temper_thermal()
        temperature_updater = thermalctld.TemperatureUpdater(chassis)
        temperature_updater.update()
        thermal_list = chassis.get_all_thermals()
        assert temperature_updater.log_warning.call_count == 1
        temperature_updater.log_warning.assert_called_with(
            'High temperature warning: chassis 1 Thermal 1 current temperature 3C, high threshold 2C'
        )

        thermal_list[0].make_normal_temper()
        temperature_updater.update()
        assert temperature_updater.log_notice.call_count == 1
        temperature_updater.log_notice.assert_called_with(
            'High temperature warning cleared: chassis 1 Thermal 1 temperature restored to 2C, high threshold 3C'
        )
Пример #8
0
def test_updater_thermal_check_chassis_table():
    chassis = MockChassis()

    thermal1 = MockThermal()
    chassis.get_all_thermals().append(thermal1)

    chassis.set_modular_chassis(True)
    chassis.set_my_slot(1)
    temperature_updater = thermalctld.TemperatureUpdater(chassis, multiprocessing.Event())

    temperature_updater.update()
    assert temperature_updater.chassis_table.get_size() == chassis.get_num_thermals()

    thermal2 = MockThermal()
    chassis.get_all_thermals().append(thermal2)
    temperature_updater.update()
    assert temperature_updater.chassis_table.get_size() == chassis.get_num_thermals()
Пример #9
0
    def test_update_sfp_thermals(self):
        chassis = MockChassis()
        sfp = MockSfp()
        mock_thermal = MockThermal()
        sfp._thermal_list.append(mock_thermal)
        chassis._sfp_list.append(sfp)
        temperature_updater = thermalctld.TemperatureUpdater(chassis, multiprocessing.Event())
        temperature_updater.update()
        assert temperature_updater.log_warning.call_count == 0

        mock_thermal.get_temperature = mock.MagicMock(side_effect=Exception("Test message"))
        temperature_updater.update()
        assert temperature_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:
            temperature_updater.log_warning.assert_called_with("Failed to update thermal status for SFP 1 Thermal 1 - Exception('Test message')")
        else:
            temperature_updater.log_warning.assert_called_with("Failed to update thermal status for SFP 1 Thermal 1 - Exception('Test message',)")
Пример #10
0
    def test_update_psu_thermals(self):
        chassis = MockChassis()
        psu = MockPsu()
        mock_thermal = MockThermal()
        psu._thermal_list.append(mock_thermal)
        chassis._psu_list.append(psu)
        temperature_updater = thermalctld.TemperatureUpdater(chassis)
        temperature_updater.update()
        assert temperature_updater.log_warning.call_count == 0

        temperature_updater._refresh_temperature_status = mock.MagicMock(
            side_effect=Exception("Test message"))
        temperature_updater.update()
        assert temperature_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:
            temperature_updater.log_warning.assert_called_with(
                "Failed to update thermal status - Exception('Test message')")
        else:
            temperature_updater.log_warning.assert_called_with(
                "Failed to update thermal status - Exception('Test message',)")