sonic-buildimage/platform/mellanox/mlnx-platform-api/tests/test_fan_api.py
Junchao-Mellanox b595a6eadf
[Mellanox] Implement new platform API for SONiC physical entity mib extension (#5645)
In order to support SONiC physical entity mib extension, a few new platform API are added to sonic-platform-common, this PR is to provide an mellanox platform implementation for those new APIs.
2020-11-16 18:56:03 -08:00

58 lines
1.9 KiB
Python

import os
import sys
import pytest
from mock import MagicMock
from .mock_platform import MockFan
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
from sonic_platform.led import FanLed
from sonic_platform.fan_drawer import RealDrawer
from sonic_platform.device_data import DEVICE_DATA
def test_get_absence_fan_direction():
fan_drawer = RealDrawer(0, DEVICE_DATA['x86_64-mlnx_msn2700-r0']['fans'])
fan = Fan(0, fan_drawer, 1)
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_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, 1)
fan2 = Fan(1, fan_drawer, 2)
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)