Skip to content

Commit

Permalink
Support show system-health
Browse files Browse the repository at this point in the history
  • Loading branch information
Jostar Yang committed Jul 15, 2021
1 parent 314f093 commit 22d32d8
Show file tree
Hide file tree
Showing 8 changed files with 255 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
REBOOT_CAUSE_FILE = "reboot-cause.txt"
PREV_REBOOT_CAUSE_FILE = "previous-reboot-cause.txt"
HOST_CHK_CMD = "docker > /dev/null 2>&1"
SYSLED_FNODE= "/sys/class/leds/accton_as7326_56x_led::diag/brightness"
SYSLED_MODES = {
"0" : "STATUS_LED_COLOR_OFF",
"1" : "STATUS_LED_COLOR_GREEN",
"2" : "STATUS_LED_COLOR_AMBER",
"5" : "STATUS_LED_COLOR_GREEN_BLINK"
}


class Chassis(ChassisBase):
Expand Down Expand Up @@ -94,7 +101,15 @@ def __read_txt_file(self, file_path):
except IOError:
pass
return None


def __write_txt_file(self, file_path, value):
try:
with open(file_path, 'w') as fd:
fd.write(str(value))
except Exception:
return False
return True

def get_name(self):
"""
Retrieves the name of the device
Expand Down Expand Up @@ -213,4 +228,41 @@ def get_sfp(self, index):
except IndexError:
sys.stderr.write("SFP index {} out of range (1-{})\n".format(
index, len(self._sfp_list)))
return sfp
return sfp

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 -1

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


def initizalize_system_led(self):
return True

def get_status_led(self):
val = self.__read_txt_file(SYSLED_FNODE)
return SYSLED_MODES[val] if val in SYSLED_MODES else "UNKNOWN"

def set_status_led(self, color):
mode = None
for key, val in SYSLED_MODES.items():
if val == color:
mode = key
break
if mode is None:
return False
else:
return self.__write_txt_file(SYSLED_FNODE, mode)

Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,56 @@ def install_firmware(self, image_path):
A boolean, True if install successfully, False if not
"""
raise NotImplementedError

def get_presence(self):
"""
Retrieves the presence of the device
Returns:
bool: True if device is present, False if not
"""
return True

def get_model(self):
"""
Retrieves the model number (or part number) of the device
Returns:
string: Model/part number of device
"""
return 'N/A'

def get_serial(self):
"""
Retrieves the serial number of the device
Returns:
string: Serial number of device
"""
return 'N/A'

def get_status(self):
"""
Retrieves the operational status of the device
Returns:
A boolean value, True if device is operating properly, False if not
"""
return 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 -1

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

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self):
self._eeprom_path = "/sys/bus/i2c/devices/0-0056/eeprom"
else:
self._eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom"

super(Tlv, self).__init__(self._eeprom_path, 0, '', True)
self._eeprom = self._load_eeprom()

Expand Down
29 changes: 26 additions & 3 deletions device/accton/x86_64-accton_as7326_56x-r0/sonic_platform/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

FAN_MAX_RPM = 25500
PSU_FAN_MAX_RPM = 25500
SPEED_TOLERANCE = 15
CPLD_I2C_PATH = "/sys/bus/i2c/devices/11-0066/fan"
PSU_I2C_PATH = "/sys/bus/i2c/devices/{}-00{}/"
PSU_HWMON_I2C_MAPPING = {
Expand Down Expand Up @@ -133,7 +134,7 @@ def get_target_speed(self):
0 : when PWM mode is use
pwm : when pwm mode is not use
"""
return False #Not supported
return self.get_speed()

def get_speed_tolerance(self):
"""
Expand All @@ -142,7 +143,7 @@ def get_speed_tolerance(self):
An integer, the percentage of variance from target speed which is
considered tolerable
"""
return False #Not supported
return SPEED_TOLERANCE

def set_speed(self, speed):
"""
Expand Down Expand Up @@ -211,7 +212,7 @@ def get_presence(self):

val = self.__read_txt_file(
CPLD_I2C_PATH + str(self.fan_tray_index + 1) + "_present")
return int(val, 10)
return int(val, 10)==1

def get_status(self):
"""
Expand Down Expand Up @@ -250,3 +251,25 @@ def get_serial(self):
string: Serial number of device
"""
return "N/A"

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+1) \
if not self.is_psu_fan else (self.psu_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

Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,51 @@ def get_name(self):
Returns:
string: The name of the device
"""
return "FanTray{}".format(self.fantrayindex)
return "FanTray{}".format(self.fantrayindex+1)

def get_presence(self):
"""
Retrieves the presence of the device
Returns:
bool: True if device is present, False if not
"""
return self._fan_list[0].get_presence()

def get_model(self):
"""
Retrieves the model number (or part number) of the device
Returns:
string: Model/part number of device
"""
return self._fan_list[0].get_model()

def get_serial(self):
"""
Retrieves the serial number of the device
Returns:
string: Serial number of device
"""
return self._fan_list[0].get_serial()

def get_status(self):
"""
Retrieves the operational status of the device
Returns:
A boolean value, True if device is operating properly, False if not
"""
return self._fan_list[0].get_status()

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.fantrayindex+1)

def is_replaceable(self):
"""
Expand Down
17 changes: 17 additions & 0 deletions device/accton/x86_64-accton_as7326_56x-r0/sonic_platform/psu.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,20 @@ def get_serial(self):
if serial is None:
return "N/A"
return serial

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.index+1

def is_replaceable(self):
"""
Indicate whether this device is replaceable.
Returns:
bool: True if it is replaceable.
"""
return True
17 changes: 17 additions & 0 deletions device/accton/x86_64-accton_as7326_56x-r0/sonic_platform/sfp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1391,3 +1391,20 @@ def get_status(self):
A boolean value, True if device is operating properly, False if not
"""
return self.get_presence() and self.get_transceiver_bulk_status()

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.port_num

def is_replaceable(self):
"""
Indicate whether this device is replaceable.
Returns:
bool: True if it is replaceable.
"""
return True
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
raise ImportError(str(e) + "- required module not found")

PSU_I2C_PATH = "/sys/bus/i2c/devices/{}-00{}/"
PSU_I2C_MAPPING = {
PSU_HWMON_I2C_MAPPING = {
0: {
"bus": 17,
"addr": "59"
Expand Down Expand Up @@ -52,8 +52,8 @@ def __init__(self, thermal_index=0, is_psu=False, psu_index=0):
self.psu_index = psu_index

if self.is_psu:
psu_i2c_bus = PSU_I2C_MAPPING[psu_index]["bus"]
psu_i2c_addr = PSU_I2C_MAPPING[psu_index]["addr"]
psu_i2c_bus = PSU_HWMON_I2C_MAPPING[psu_index]["bus"]
psu_i2c_addr = PSU_HWMON_I2C_MAPPING[psu_index]["addr"]
self.psu_hwmon_path = PSU_I2C_PATH.format(psu_i2c_bus,
psu_i2c_addr)
psu_i2c_bus = PSU_CPLD_I2C_MAPPING[psu_index]["bus"]
Expand Down Expand Up @@ -145,8 +145,11 @@ def set_high_threshold(self, temperature):
Returns:
A boolean, True if threshold is set successfully, False if not
"""
#Not supported
return False
temp_file = "temp{}_max".format(self.ss_index)
temperature = temperature *1000
self.__set_threshold(temp_file, temperature)

return True

def get_name(self):
"""
Expand Down Expand Up @@ -193,3 +196,37 @@ def get_status(self):
return False
else:
return int(raw_txt) != 0

def get_model(self):
"""
Retrieves the model number (or part number) of the device
Returns:
string: Model/part number of device
"""

return "N/A"

def get_serial(self):
"""
Retrieves the serial number of the device
Returns:
string: Serial number of device
"""
return "N/A"

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 -1

def is_replaceable(self):
"""
Retrieves whether thermal module is replaceable
Returns:
A boolean value, True if replaceable, False if not
"""
return False

0 comments on commit 22d32d8

Please sign in to comment.