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

[sonic_platform]: Fixed the failed test case of Seastone-DX010's Fan API. #238

Merged
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
72 changes: 49 additions & 23 deletions device/celestica/x86_64-cel_seastone-r0/platform.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,65 @@
"chassis": {
"name": "Celestica-DX010-C32",
"components": [],
"fans":[
"fans": [],
"fan_drawers": [
{
"name": "FAN-1F"
},
{
"name": "FAN-1R"
},
{
"name": "FAN-2F"
},
{
"name": "FAN-2R"
},
{
"name": "FAN-3F"
},
{
"name": "FAN-3R"
"name": "Drawer1",
"fans": [
{
"name": "FAN-1F"
},
{
"name": "FAN-1R"
}
]
},
{
"name": "FAN-4F"
"name": "Drawer2",
"fans": [
{
"name": "FAN-2F"
},
{
"name": "FAN-2R"
}
]
},
{
"name": "FAN-4R"
"name": "Drawer3",
"fans": [
{
"name": "FAN-3F"
},
{
"name": "FAN-3R"
}
]
},
{
"name": "FAN-5F"
"name": "Drawer4",
"fans": [
{
"name": "FAN-4F"
},
{
"name": "FAN-4R"
}
]
},
{
"name": "FAN-5R"
}
"name": "Drawer5",
"fans": [
{
"name": "FAN-5F"
},
{
"name": "FAN-5R"
}
]
}
],
"fan_drawers": [],

"psus": [
{
"name": "PSU-1"
Expand Down
29 changes: 13 additions & 16 deletions device/celestica/x86_64-cel_seastone-r0/sonic_platform/chassis.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
raise ImportError(str(e) + "- required module not found")

NUM_FAN_TRAY = 5
NUM_FAN = 2
NUM_PSU = 2
NUM_THERMAL = 5
NUM_SFP = 32
Expand All @@ -40,12 +39,10 @@ def __init__(self):
self.__initialize_eeprom()
self.is_host = self._api_helper.is_host()

if not self.is_host:
self.__initialize_fan()
self.__initialize_psu()
self.__initialize_thermals()
else:
self.__initialize_components()
self.__initialize_fan()
self.__initialize_psu()
self.__initialize_thermals()
self.__initialize_components()

def __initialize_sfp(self):
sfputil_helper = SfpUtilHelper()
Expand All @@ -66,11 +63,11 @@ def __initialize_psu(self):
self._psu_list.append(psu)

def __initialize_fan(self):
from sonic_platform.fan import Fan
for fant_index in range(0, NUM_FAN_TRAY):
for fan_index in range(0, NUM_FAN):
fan = Fan(fant_index, fan_index)
self._fan_list.append(fan)
from sonic_platform.fan_drawer import FanDrawer
for i in range(NUM_FAN_TRAY):
fandrawer = FanDrawer(i)
self._fan_drawer_list.append(fandrawer)
self._fan_list.extend(fandrawer._fan_list)

def __initialize_thermals(self):
from sonic_platform.thermal import Thermal
Expand Down Expand Up @@ -253,6 +250,10 @@ def get_watchdog(self):

return self._watchdog

def get_thermal_manager(self):
from .thermal_manager import ThermalManager
return ThermalManager

##############################################################
###################### Device methods ########################
##############################################################
Expand Down Expand Up @@ -297,10 +298,6 @@ def get_status(self):
"""
return True

def get_thermal_manager(self):
from .thermal_manager import ThermalManager
return ThermalManager

def get_position_in_parent(self):
"""
Retrieves 1-based relative physical position in parent device. If the agent cannot determine the parent-relative position
Expand Down
102 changes: 81 additions & 21 deletions device/celestica/x86_64-cel_seastone-r0/sonic_platform/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#
#############################################################################

import json
import math
import os.path

Expand All @@ -25,6 +24,7 @@
EMC2305_FAN_INPUT = "pwm{}"
FAN_NAME_LIST = ["FAN-1F", "FAN-1R", "FAN-2F", "FAN-2R",
"FAN-3F", "FAN-3R", "FAN-4F", "FAN-4R", "FAN-5F", "FAN-5R"]
FAN_SPEED_TOLERANCE = 10
PSU_FAN_MAX_RPM = 11000
PSU_HWMON_PATH = "/sys/bus/i2c/devices/i2c-{0}/{0}-00{1}/hwmon"
PSU_I2C_MAPPING = {
Expand Down Expand Up @@ -82,7 +82,7 @@ def __write_txt_file(self, file_path, value):
try:
with open(file_path, 'w') as fd:
fd.write(str(value))
except:
except Exception:
return False
return True

Expand All @@ -97,7 +97,8 @@ def __search_file_by_name(self, directory, file_name):
def __get_gpio_base(self):
for r in os.listdir(GPIO_DIR):
label_path = os.path.join(GPIO_DIR, r, "label")
if "gpiochip" in r and GPIO_LABEL in self._api_helper.read_txt_file(label_path):
if "gpiochip" in r and GPIO_LABEL in \
self._api_helper.read_txt_file(label_path):
return int(r[8:], 10)
return 216 # Reserve

Expand Down Expand Up @@ -148,7 +149,6 @@ def get_speed(self):
self.psu_hwmon_path, fan_speed_sysfs_name)
fan_speed_rpm = self._api_helper.read_txt_file(
fan_speed_sysfs_path) or 0
fan_speed_raw = float(fan_speed_rpm)/PSU_FAN_MAX_RPM * 100
speed = math.ceil(float(fan_speed_rpm) * 100 / PSU_FAN_MAX_RPM)
elif self.get_presence():
chip = self.emc2305_chip_mapping[self.fan_index]
Expand Down Expand Up @@ -176,7 +176,19 @@ def get_target_speed(self):
0 : when PWM mode is use
pwm : when pwm mode is not use
"""
return 'N/A'
target = NULL_VAL

if not self.is_psu_fan:
chip = self.emc2305_chip_mapping[self.fan_index]
device = chip['device']
fan_index = chip['index_map']
sysfs_path = "%s%s/%s" % (
EMC2305_PATH, device, EMC2305_FAN_PWM)
sysfs_path = sysfs_path.format(fan_index[self.fan_tray_index])
pwm = self._api_helper.read_txt_file(sysfs_path)
target = int(int(pwm) / 255 * 100)

return target

def get_speed_tolerance(self):
"""
Expand All @@ -185,7 +197,7 @@ def get_speed_tolerance(self):
An integer, the percentage of variance from target speed which is
considered tolerable
"""
return 10
return FAN_SPEED_TOLERANCE

def set_speed(self, speed):
"""
Expand Down Expand Up @@ -225,41 +237,68 @@ def set_status_led(self, color):
bool: True if status LED state is set successfully, False if not
"""
set_status_led = False

s1_gpio = self.dx010_fan_gpio[self.fan_tray_index+1]['color']['red']
s2_gpio = self.dx010_fan_gpio[self.fan_tray_index+1]['color']['green']

if not self.is_psu_fan:
s1, s2 = False, False
try:
if color == self.STATUS_LED_COLOR_GREEN:
s1 = self.__set_gpio_value(
self.dx010_fan_gpio[self.fan_tray_index+1]['color']['red'], 1)
s2 = self.__set_gpio_value(
self.dx010_fan_gpio[self.fan_tray_index+1]['color']['green'], 0)
s1 = self.__set_gpio_value(s1_gpio, 1)
s2 = self.__set_gpio_value(s2_gpio, 0)

elif color == self.STATUS_LED_COLOR_RED:
s1 = self.__set_gpio_value(
self.dx010_fan_gpio[self.fan_tray_index+1]['color']['red'], 0)
s2 = self.__set_gpio_value(
self.dx010_fan_gpio[self.fan_tray_index+1]['color']['green'], 1)
s1 = self.__set_gpio_value(s1_gpio, 0)
s2 = self.__set_gpio_value(s2_gpio, 1)

elif color == self.STATUS_LED_COLOR_OFF:
s1 = self.__set_gpio_value(
self.dx010_fan_gpio[self.fan_tray_index+1]['color']['red'], 1)
s2 = self.__set_gpio_value(
self.dx010_fan_gpio[self.fan_tray_index+1]['color']['green'], 1)
s1 = self.__set_gpio_value(s1_gpio, 1)
s2 = self.__set_gpio_value(s2_gpio, 1)

elif color == self.STATUS_LED_COLOR_AMBER:
s1 = self.__set_gpio_value(s1_gpio, 0)
s2 = self.__set_gpio_value(s2_gpio, 0)
else:
s1, s2 = True, True

set_status_led = s1 and s2
return set_status_led

except IOError:
return False

return set_status_led

def get_status_led(self):
"""
Gets the state of the fan status LED
Returns:
A string, one of the predefined STATUS_LED_COLOR_* strings above
"""
s1 = self.__get_gpio_value(
self.dx010_fan_gpio[self.fan_tray_index+1]['color']['red'])
s2 = self.__get_gpio_value(
self.dx010_fan_gpio[self.fan_tray_index+1]['color']['green'])

return {
'10': self.STATUS_LED_COLOR_GREEN,
'01': self.STATUS_LED_COLOR_RED,
'00': self.STATUS_LED_COLOR_AMBER
}.get(s1+s2, self.STATUS_LED_COLOR_OFF)

##############################################################
###################### Device methods ########################
##############################################################

def get_name(self):
"""
Retrieves the name of the device
Returns:
string: The name of the device
"""
fan_name = FAN_NAME_LIST[self.fan_tray_index*2 + self.fan_index] if not self.is_psu_fan else "PSU-{} FAN-{}".format(
self.psu_index+1, self.fan_index+1)
fan_name = FAN_NAME_LIST[self.fan_tray_index*2 + self.fan_index] \
if not self.is_psu_fan \
else "PSU-{} FAN-{}".format(self.psu_index+1, self.fan_index+1)

return fan_name

Expand Down Expand Up @@ -321,3 +360,24 @@ def get_status(self):
status = self._api_helper.read_one_line_file(sysfs_path)

return False if int(status) != 0 else True

def get_position_in_parent(self):
"""
Retrieves 1-based relative physical position in parent device.
If the agent cannot determine the parent-relative position
for some reason, or if the associated value of
entPhysicalContainedIn is'0', then the value '-1' is returned
Returns:
integer: The 1-based relative physical position in parent device
or -1 if cannot determine the position
"""
return (self.fan_tray_index*2 + self.fan_index + 1) \
if not self.is_psu_fan else (self.fan_index+1)

def is_replaceable(self):
"""
Indicate whether this device is replaceable.
Returns:
bool: True if it is replaceable.
"""
return True if not self.is_psu_fan else False
Loading