Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mellanox] [201911] Fix issue: set fan led in certain order causes incorrect physical fan led color #39

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions platform/mellanox/mlnx-platform-api/sonic_platform/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

try:
from sonic_platform_base.fan_base import FanBase

from .led import SharedLed, ComponentFaultyIndicator
from .utils import read_int_from_file, read_str_from_file, write_file
except ImportError as e:
raise ImportError (str(e) + "- required module not found")
Expand Down Expand Up @@ -41,6 +43,10 @@ class Fan(FanBase):
min_cooling_level = 2
MIN_VALID_COOLING_LEVEL = 1
MAX_VALID_COOLING_LEVEL = 10

# Fan drawer leds
fan_drawer_leds = {}

# PSU fan speed vector
PSU_FAN_SPEED = ['0x3c', '0x3c', '0x3c', '0x3c', '0x3c',
'0x3c', '0x3c', '0x46', '0x50', '0x5a', '0x64']
Expand All @@ -50,6 +56,14 @@ def __init__(self, has_fan_dir, fan_index, drawer_index = 1, psu_fan = False, pl
self.index = fan_index + 1
self.drawer_index = drawer_index + 1

if self.drawer_index not in Fan.fan_drawer_leds:
shared_led = SharedLed()
Fan.fan_drawer_leds[self.drawer_index] = shared_led
else:
shared_led = Fan.fan_drawer_leds[self.drawer_index]

self.fault_indicator = ComponentFaultyIndicator(shared_led)

self.is_psu_fan = psu_fan
self.always_presence = False if platform not in platform_with_unplugable_fan else True

Expand Down Expand Up @@ -250,6 +264,13 @@ def _get_led_capability(self):
return cap_list

def set_status_led(self, color):
if self.is_psu_fan:
return False
self.fault_indicator.set_status(color)
target_color = Fan.fan_drawer_leds[self.drawer_index].get_status()
return self._set_status_led(color)

def _set_status_led(self, color):
"""
Set led to expected color

Expand All @@ -264,9 +285,6 @@ def set_status_led(self, color):
if led_cap_list is None:
return False

if self.is_psu_fan:
# PSU fan led status is not able to set
return False
status = False
try:
if color == 'green':
Expand Down
51 changes: 51 additions & 0 deletions platform/mellanox/mlnx-platform-api/sonic_platform/led.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
class Led(object):
STATUS_LED_COLOR_GREEN = 'green'
STATUS_LED_COLOR_GREEN_BLINK = 'green_blink'
STATUS_LED_COLOR_RED = 'red'
STATUS_LED_COLOR_RED_BLINK = 'red_blink'
STATUS_LED_COLOR_ORANGE = 'orange'
STATUS_LED_COLOR_ORANGE_BLINK = 'orange_blink'
STATUS_LED_COLOR_OFF = 'off'


class SharedLed(object):
LED_PRIORITY = {
Led.STATUS_LED_COLOR_RED: 0,
Led.STATUS_LED_COLOR_GREEN: 1
}

def __init__(self):
self._virtual_leds = []
self._target_color = Led.STATUS_LED_COLOR_GREEN

def add_virtual_leds(self, led):
self._virtual_leds.append(led)

def update_status_led(self):
target_color = Led.STATUS_LED_COLOR_GREEN
for virtual_led in self._virtual_leds:
if SharedLed.LED_PRIORITY[virtual_led.get_led_color()] < SharedLed.LED_PRIORITY[target_color]:
target_color = virtual_led.get_led_color()

self._target_color = target_color
return True

def get_status(self):
return self._target_color


class ComponentFaultyIndicator(object):
def __init__(self, shared_led):
self._color = Led.STATUS_LED_COLOR_GREEN
self._shared_led = shared_led
self._shared_led.add_virtual_leds(self)

def set_status(self, color):
self._color = color
return self._shared_led.update_status_led()

def get_led_color(self):
return self._color

def get_status(self):
return self._shared_led.get_status()