2020-03-25 12:54:07 -05:00
|
|
|
import os
|
|
|
|
import sys
|
2020-05-13 12:01:32 -05:00
|
|
|
import pytest
|
2020-03-25 12:54:07 -05:00
|
|
|
from mock import MagicMock
|
2020-05-13 12:01:32 -05:00
|
|
|
from .mock_platform import MockFan
|
2020-03-25 12:54:07 -05:00
|
|
|
|
|
|
|
test_path = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
modules_path = os.path.dirname(test_path)
|
|
|
|
sys.path.insert(0, modules_path)
|
|
|
|
|
|
|
|
from sonic_platform.fan import Fan
|
2020-05-13 12:01:32 -05:00
|
|
|
from sonic_platform.led import FanLed
|
|
|
|
from sonic_platform.fan_drawer import RealDrawer
|
|
|
|
from sonic_platform.device_data import DEVICE_DATA
|
2020-03-25 12:54:07 -05:00
|
|
|
|
|
|
|
|
|
|
|
def test_get_absence_fan_direction():
|
2020-05-13 12:01:32 -05:00
|
|
|
fan_drawer = RealDrawer(0, DEVICE_DATA['x86_64-mlnx_msn2700-r0']['fans'])
|
2020-11-16 20:56:03 -06:00
|
|
|
fan = Fan(0, fan_drawer, 1)
|
2020-05-13 12:01:32 -05:00
|
|
|
fan_drawer.get_presence = MagicMock(return_value=False)
|
|
|
|
|
2020-03-25 12:54:07 -05:00
|
|
|
assert not fan.is_psu_fan
|
|
|
|
assert fan.get_direction() == Fan.FAN_DIRECTION_NOT_APPLICABLE
|
2020-05-13 12:01:32 -05:00
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
2020-11-16 20:56:03 -06:00
|
|
|
fan1 = Fan(0, fan_drawer, 1)
|
|
|
|
fan2 = Fan(1, fan_drawer, 2)
|
2020-05-13 12:01:32 -05:00
|
|
|
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)
|
|
|
|
|