Exemplo n.º 1
0
    def test_system_fan_basic(self):
        fan_drawer = RealDrawer(0)
        fan = Fan(2, fan_drawer, 1)
        assert fan.get_position_in_parent() == 1
        assert fan.is_replaceable() is False
        assert fan.get_speed_tolerance() == 50
        assert fan.get_name() == 'fan3'

        mock_sysfs_content = {
            fan.fan_speed_get_path: 50,
            fan.fan_max_speed_path: 100,
            fan.fan_status_path: 0,
            fan.fan_speed_set_path: 153
        }

        def mock_read_int_from_file(file_path, default=0, raise_exception=False):
            return mock_sysfs_content[file_path]

        utils.read_int_from_file = mock_read_int_from_file
        assert fan.get_speed() == 50
        mock_sysfs_content[fan.fan_speed_get_path] = 101
        assert fan.get_speed() == 100
        mock_sysfs_content[fan.fan_max_speed_path] = 0
        assert fan.get_speed() == 101

        assert fan.get_status() is True
        mock_sysfs_content[fan.fan_status_path] = 1
        assert fan.get_status() is False

        assert fan.get_target_speed() == 60

        fan.fan_drawer.get_direction = MagicMock(return_value=Fan.FAN_DIRECTION_EXHAUST)
        assert fan.get_direction() == Fan.FAN_DIRECTION_EXHAUST
        fan.fan_drawer.get_presence = MagicMock(return_value=True)
        assert fan.get_presence() is True
Exemplo n.º 2
0
    def __init__(self, psu_index, sku):
        global psu_list
        PsuBase.__init__(self)
        # PSU is 1-based on Mellanox platform
        self.index = psu_index + 1
        psu_list.append(self.index)
        self.psu_path = "/var/run/hw-management/"
        psu_oper_status = "thermal/psu{}_pwr_status".format(self.index)
        #psu_oper_status should always be present for all SKUs
        self.psu_oper_status = os.path.join(self.psu_path, psu_oper_status)

        if sku in hwsku_dict_psu:
            filemap = psu_profile_list[hwsku_dict_psu[sku]]
        else:
            filemap = psu_profile_list[0]

        if sku in hwsku_dict_with_unplugable_psu:
            self.always_presence = True
            self.psu_voltage = None
            self.psu_current = None
            self.psu_power = None
            self.psu_presence = None
        else:
            self.always_presence = False
            psu_voltage = filemap[PSU_VOLTAGE].format(self.index)
            psu_voltage = os.path.join(self.psu_path, psu_voltage)
            self.psu_voltage = psu_voltage

            psu_current = filemap[PSU_CURRENT].format(self.index)
            psu_current = os.path.join(self.psu_path, psu_current)
            self.psu_current = psu_current

            psu_power = filemap[PSU_POWER].format(self.index)
            psu_power = os.path.join(self.psu_path, psu_power)
            self.psu_power = psu_power

            psu_presence = "thermal/psu{}_status".format(self.index)
            psu_presence = os.path.join(self.psu_path, psu_presence)
            self.psu_presence = psu_presence

        fan = Fan(sku, psu_index, psu_index, True)
        if fan.get_presence():
            self._fan = fan

        self.psu_green_led_path = "led_psu_green"
        self.psu_red_led_path = "led_psu_red"
        self.psu_orange_led_path = "led_psu_orange"
        self.psu_led_cap_path = "led_psu_capability"
Exemplo n.º 3
0
 def __init__(self, psu_index):
     global psu_list
     PsuBase.__init__(self)
     # PSU is 1-based on Mellanox platform
     self.index = psu_index + 1
     psu_list.append(self.index)
     self.psu_path = "/var/run/hw-management/thermal/"
     self.psu_oper_status = "psu{}_pwr_status".format(self.index)
     self.psu_presence = "psu{}_status".format(self.index)
     if os.path.exists(os.path.join(self.psu_path, self.psu_presence)):
         self.presence_file_exists = True
     else:
         self.presence_file_exists = False
     fan = Fan(psu_index, psu_index, True)
     if fan.get_presence():
         self._fan = fan
Exemplo n.º 4
0
 def __init__(self, psu_index):
     global psu_list
     PsuBase.__init__(self)
     # PSU is 1-based on Mellanox platform
     self.index = psu_index + 1
     psu_list.append(self.index)
     self.psu_path = "/var/run/hw-management/thermal/"
     self.psu_oper_status = "psu{}_pwr_status".format(self.index)
     self.psu_presence = "psu{}_status".format(self.index)
     if os.path.exists(os.path.join(self.psu_path, self.psu_presence)):
         self.presence_file_exists = True
     else:
         self.presence_file_exists = False
     fan = Fan(psu_index, psu_index, True)
     if fan.get_presence():
         self._fan = fan
Exemplo n.º 5
0
def test_get_absence_fan_direction():
    fan = Fan(True, 0, 0)
    fan.get_presence = MagicMock(return_value=False)
    assert fan.fan_dir is not None
    assert not fan.is_psu_fan
    assert fan.get_direction() == Fan.FAN_DIRECTION_NOT_APPLICABLE