def test_get_absence_fan_direction(): fan_drawer = RealDrawer(0, DEVICE_DATA['x86_64-mlnx_msn2700-r0']['fans']) fan = Fan(0, fan_drawer) fan_drawer.get_presence = MagicMock(return_value=False) assert not fan.is_psu_fan assert fan.get_direction() == Fan.FAN_DIRECTION_NOT_APPLICABLE
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
def test_system_fan_set_speed(self, mock_write_file): fan_drawer = RealDrawer(0) fan = Fan(2, fan_drawer, 1) fan.set_speed(60) mock_write_file.assert_called_with(fan.fan_speed_set_path, 153, raise_exception=True)
def test_fan_led(self): fan_drawer = RealDrawer(0) self._verify_fan_led(fan_drawer) fan_drawer = VirtualDrawer(0) self._verify_fan_led(fan_drawer)
def test_fan_drawer_basic(self): # Real drawer fan_drawer = RealDrawer(0) assert fan_drawer.get_index() == 1 assert fan_drawer.get_name() == 'drawer1' utils.read_int_from_file = MagicMock(return_value=1) assert fan_drawer.get_presence() is True utils.read_int_from_file = MagicMock(return_value=0) assert fan_drawer.get_presence() is False assert fan_drawer.get_position_in_parent() == 1 assert fan_drawer.is_replaceable() is True fan_drawer.get_presence = MagicMock(return_value=False) assert fan_drawer.get_direction() == Fan.FAN_DIRECTION_NOT_APPLICABLE fan_drawer.get_presence = MagicMock(return_value=True) assert fan_drawer.get_direction() == Fan.FAN_DIRECTION_EXHAUST utils.read_int_from_file = MagicMock(return_value=1) assert fan_drawer.get_direction() == Fan.FAN_DIRECTION_INTAKE # Invalid fan dir value utils.read_int_from_file = MagicMock(return_value=2) assert fan_drawer.get_direction() == Fan.FAN_DIRECTION_NOT_APPLICABLE utils.read_int_from_file = MagicMock(side_effect=ValueError('')) assert fan_drawer.get_direction() == Fan.FAN_DIRECTION_NOT_APPLICABLE utils.read_int_from_file = MagicMock(side_effect=IOError('')) assert fan_drawer.get_direction() == Fan.FAN_DIRECTION_NOT_APPLICABLE # Virtual drawer fan_drawer = VirtualDrawer(0) assert fan_drawer.get_name() == 'N/A' assert fan_drawer.get_presence() is True assert fan_drawer.is_replaceable() is False
def test_fan_drawer_set_status_led(): fan_drawer = RealDrawer(0, DEVICE_DATA['x86_64-mlnx_msn2700-r0']['fans']) with pytest.raises(Exception): fan_drawer.set_status_led(None, 'Invalid color') with pytest.raises(Exception): fan_drawer.set_status_led(None, Fan.STATUS_LED_COLOR_RED) fan1 = Fan(0, fan_drawer) fan2 = Fan(1, fan_drawer) fan_list = fan_drawer.get_all_fans() fan_list.append(fan1) fan_list.append(fan2) FanLed.set_status = MagicMock() fan1.set_status_led(Fan.STATUS_LED_COLOR_RED) fan_drawer.set_status_led(Fan.STATUS_LED_COLOR_RED) FanLed.set_status.assert_called_with(Fan.STATUS_LED_COLOR_RED) fan2.set_status_led(Fan.STATUS_LED_COLOR_GREEN) fan_drawer.set_status_led(Fan.STATUS_LED_COLOR_GREEN) FanLed.set_status.assert_called_with(Fan.STATUS_LED_COLOR_RED) fan1.set_status_led(Fan.STATUS_LED_COLOR_GREEN) fan_drawer.set_status_led(Fan.STATUS_LED_COLOR_GREEN) FanLed.set_status.assert_called_with(Fan.STATUS_LED_COLOR_GREEN) fan1.set_status_led(Fan.STATUS_LED_COLOR_RED) fan_drawer.set_status_led(Fan.STATUS_LED_COLOR_RED) FanLed.set_status.assert_called_with(Fan.STATUS_LED_COLOR_RED)