Пример #1
0
def test_dynamic_minimum_policy(thermal_manager):
    from sonic_platform.thermal_conditions import MinCoolingLevelChangeCondition
    from sonic_platform.thermal_actions import ChangeMinCoolingLevelAction
    from sonic_platform.thermal_infos import ChassisInfo, FanInfo
    from sonic_platform.thermal import Thermal
    from sonic_platform.fan import Fan
    ThermalManager.initialize()
    assert 'DynamicMinCoolingLevelPolicy' in thermal_manager._policy_dict
    policy = thermal_manager._policy_dict['DynamicMinCoolingLevelPolicy']
    assert MinCoolingLevelChangeCondition in policy.conditions
    assert ChangeMinCoolingLevelAction in policy.actions

    condition = policy.conditions[MinCoolingLevelChangeCondition]
    action = policy.actions[ChangeMinCoolingLevelAction]
    Thermal.check_module_temperature_trustable = MagicMock(
        return_value='trust')
    Thermal.get_min_amb_temperature = MagicMock(return_value=35001)
    assert condition.is_match(None)
    assert MinCoolingLevelChangeCondition.trust_state == 'trust'
    assert MinCoolingLevelChangeCondition.temperature == 35
    assert not condition.is_match(None)

    Thermal.check_module_temperature_trustable = MagicMock(
        return_value='untrust')
    assert condition.is_match(None)
    assert MinCoolingLevelChangeCondition.trust_state == 'untrust'

    Thermal.get_min_amb_temperature = MagicMock(return_value=25999)
    assert condition.is_match(None)
    assert MinCoolingLevelChangeCondition.temperature == 25

    chassis = MockChassis()
    info = ChassisInfo()
    info._chassis = chassis
    fan_info = FanInfo()

    thermal_info_dict = {
        ChassisInfo.INFO_NAME: info,
        FanInfo.INFO_NAME: fan_info
    }
    DeviceDataManager.get_platform_name = MagicMock(return_value=None)
    Fan.get_cooling_level = MagicMock(return_value=5)
    Fan.set_cooling_level = MagicMock()
    action.execute(thermal_info_dict)
    assert Fan.min_cooling_level == 6
    Fan.set_cooling_level.assert_called_with(6, 6)
    Fan.set_cooling_level.call_count = 0

    DeviceDataManager.get_platform_name = MagicMock(
        return_value='x86_64-mlnx_msn2700-r0')
    print('Before execute')
    action.execute(thermal_info_dict)
    assert Fan.min_cooling_level == 3
    Fan.set_cooling_level.assert_called_with(3, 5)
def test_dynamic_minimum_policy(thermal_manager):
    from sonic_platform.thermal_conditions import MinCoolingLevelChangeCondition
    from sonic_platform.thermal_actions import ChangeMinCoolingLevelAction
    from sonic_platform.thermal_infos import ChassisInfo
    from sonic_platform.thermal import Thermal
    from sonic_platform.fan import Fan
    ThermalManager.initialize()
    assert 'DynamicMinCoolingLevelPolicy' in thermal_manager._policy_dict
    policy = thermal_manager._policy_dict['DynamicMinCoolingLevelPolicy']
    assert MinCoolingLevelChangeCondition in policy.conditions
    assert ChangeMinCoolingLevelAction in policy.actions

    condition = policy.conditions[MinCoolingLevelChangeCondition]
    action = policy.actions[ChangeMinCoolingLevelAction]
    Thermal.check_module_temperature_trustable = MagicMock(return_value='trust')
    Thermal.get_air_flow_direction = MagicMock(return_value=('p2c', 35000))
    assert condition.is_match(None)
    assert MinCoolingLevelChangeCondition.trust_state == 'trust'
    assert MinCoolingLevelChangeCondition.air_flow_dir == 'p2c'
    assert MinCoolingLevelChangeCondition.temperature == 35
    assert not condition.is_match(None)

    Thermal.check_module_temperature_trustable = MagicMock(return_value='untrust')
    assert condition.is_match(None)
    assert MinCoolingLevelChangeCondition.trust_state == 'untrust'

    Thermal.get_air_flow_direction = MagicMock(return_value=('c2p', 35000))
    assert condition.is_match(None)
    assert MinCoolingLevelChangeCondition.air_flow_dir == 'c2p'

    Thermal.get_air_flow_direction = MagicMock(return_value=('c2p', 25000))
    assert condition.is_match(None)
    assert MinCoolingLevelChangeCondition.temperature == 25

    chassis = MockChassis()
    chassis.platform_name = 'invalid'
    info = ChassisInfo()
    info._chassis = chassis
    thermal_info_dict = {ChassisInfo.INFO_NAME: info}
    Fan.get_cooling_level = MagicMock(return_value=5)
    Fan.set_cooling_level = MagicMock()
    action.execute(thermal_info_dict)
    assert Fan.min_cooling_level == 6
    Fan.set_cooling_level.assert_called_with(6, 6)
    Fan.set_cooling_level.call_count = 0

    chassis.platform_name = 'x86_64-mlnx_msn2700-r0'
    action.execute(thermal_info_dict)
    assert Fan.min_cooling_level == 4
    Fan.set_cooling_level.assert_called_with(4, 5)