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

[device/alibaba] - Update plugins to latest version #39

Merged
merged 2 commits into from Feb 11, 2019
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
40 changes: 26 additions & 14 deletions device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/fanutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

__author__ = 'Wirut G.<wgetbumr@celestica.com>'
__license__ = "GPL"
__version__ = "0.1.1"
__version__ = "0.1.2"
__status__ = "Development"

import re
import requests
import re


class FanUtil():
Expand Down Expand Up @@ -249,27 +249,35 @@ def get_all(self):

# Set fan FRU data.
fan_fru_dict = dict()
fan_raw_idx = 1
for fan_fru in self.fru_data_list:
if len(fan_fru) == 0:
continue
fru_dict = dict()
fan_key = fan_fru[0].split()
fan_ps = False

if str(fan_key[-1]).lower() == "absent":
fan_idx = int(re.findall('\d+', fan_key[0])[0])
if len(fan_fru) == 0:
fan_idx = fan_raw_idx
fan_pn = "N/A"
fan_sn = "N/A"
else:
fan_idx = int(re.findall('\d+', fan_key[-1])[0])
fan_ps = True
pn = [s for s in fan_fru if "Part" in s]
sn = [s for s in fan_fru if "Serial" in s]
fan_pn = pn[0].split(":")[-1].strip() if len(pn) > 0 else 'N/A'
fan_sn = sn[0].split(":")[-1].strip() if len(sn) > 0 else 'N/A'
fan_key = fan_fru[0].split()
if str(fan_key[-1]).lower() == "absent":
fan_idx = int(re.findall('\d+', fan_key[0])[0])

else:
fan_idx = int(re.findall('\d+', fan_key[-1])[0])
fan_ps = True
pn = [s for s in fan_fru if "Part" in s]
sn = [s for s in fan_fru if "Serial" in s]
fan_pn = pn[0].split(
":")[-1].strip() if len(pn) > 0 else 'N/A'
fan_sn = sn[0].split(
":")[-1].strip() if len(sn) > 0 else 'N/A'

fru_dict["PN"] = "N/A" if not fan_pn or fan_pn == "" else fan_pn
fru_dict["SN"] = "N/A" if not fan_sn or fan_sn == "" else fan_sn
fru_dict["Present"] = fan_ps
fan_fru_dict[fan_idx] = fru_dict
fan_raw_idx += 1

# Set fan sensor data.
for sensor_data in self.sensor_data_list:
Expand All @@ -284,13 +292,17 @@ def get_all(self):
fan_data = sensor_data.get(fan_key)
fan_sp_list = map(int, re.findall(r'\d+', fan_data))
fan_dict["Present"] = fan_fru_dict[f_index]["Present"]
if fan_dict["Present"]:
if fan_dict["Present"] or fan_sp_list[0] > 0:
fan_dict["Present"] = True
fan_dict["Speed"] = fan_sp_list[0]
fan_dict["Running"] = True if fan_dict["Speed"] > 0 else False
fan_dict["LowThd"] = fan_sp_list[1]
fan_dict["HighThd"] = fan_sp_list[2]
fan_dict["PN"] = fan_fru_dict[f_index]["PN"]
fan_dict["SN"] = fan_fru_dict[f_index]["SN"]
fan_dict["AirFlow"] = "FTOB" if "R1241-F9001" in fan_dict["PN"] else "Unknown"
fan_dict["AirFlow"] = "BTOF" if "R1241-F9002" in fan_dict["PN"] else fan_dict["AirFlow"]
fan_dict["Status"] = True if fan_dict["AirFlow"] != "Unknown" else False
fan_name = 'FAN{}_{}'.format(f_index, pos)
all_fan_dict[fan_name] = fan_dict
break
Expand Down
148 changes: 119 additions & 29 deletions device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/fwmgrutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import subprocess
import requests
import os

try:
from sonic_fwmgr.fwgmr_base import FwMgrUtilBase
Expand All @@ -20,6 +21,7 @@ def __init__(self):
self.platform_name = "AS1332h"
self.onie_config_file = "/host/machine.conf"
self.bmc_info_url = "http://240.1.1.1:8080/api/sys/bmc"
self.bmc_raw_command_url = "http://240.1.1.1:8080/api/sys/raw"
self.onie_config_file = "/host/machine.conf"
self.cpldb_version_path = "/sys/devices/platform/%s.cpldb/getreg" % self.platform_name
self.fpga_version_path = "/sys/devices/platform/%s.switchboard/FPGA/getreg" % self.platform_name
Expand All @@ -43,15 +45,15 @@ def get_bmc_version(self):
:returns: version string

"""
bmc_version = "None"
bmc_version = None

bmc_version_key = "OpenBMC Version"
bmc_info_req = requests.get(self.bmc_info_url)
bmc_info_json = bmc_info_req.json()
bmc_info = bmc_info_json.get('Information')
bmc_version = bmc_info.get(bmc_version_key)

return bmc_version
return str(bmc_version)

def get_cpld_version(self):
"""Get CPLD version from SONiC
Expand Down Expand Up @@ -83,9 +85,10 @@ def get_cpld_version(self):
int(CPLD_3[2], 16), int(CPLD_3[3], 16))
CPLD_4 = 'None' if CPLD_4 is 'None' else "{}.{}".format(
int(CPLD_4[2], 16), int(CPLD_4[3], 16))
FAN_CPLD = 'None' if CPLD_4 is None else "{:.1f}".format(float(fan_cpld))
FAN_CPLD = 'None' if CPLD_4 is None else "{:.1f}".format(
float(fan_cpld))

cpld_version_dict={}
cpld_version_dict = {}
cpld_version_dict.update({'CPLD_B': CPLD_B})
cpld_version_dict.update({'CPLD_C': CPLD_C})
cpld_version_dict.update({'CPLD_1': CPLD_1})
Expand All @@ -101,57 +104,144 @@ def get_bios_version(self):
:returns: version string

"""
bios_version='None'
bios_version = None

p=subprocess.Popen(
p = subprocess.Popen(
["sudo", "dmidecode", "-s", "bios-version"], stdout=subprocess.PIPE)
raw_data=str(p.communicate()[0])
raw_data_list=raw_data.split("\n")
bios_version=raw_data_list[0] if len(
raw_data = str(p.communicate()[0])
raw_data_list = raw_data.split("\n")
bios_version = raw_data_list[0] if len(
raw_data_list) == 1 else raw_data_list[-2]

return bios_version
return str(bios_version)

def get_onie_version(self):
"""Get ONiE version from SONiC
:returns: version string

"""
onie_verison='None'
onie_verison = None

onie_version_keys="onie_version"
onie_config_file=open(self.onie_config_file, "r")
onie_version_keys = "onie_version"
onie_config_file = open(self.onie_config_file, "r")
for line in onie_config_file.readlines():
if onie_version_keys in line:
onie_version_raw=line.split('=')
onie_verison=onie_version_raw[1].strip()
onie_version_raw = line.split('=')
onie_verison = onie_version_raw[1].strip()
break
return onie_verison
return str(onie_verison)

def get_pcie_version(self):
"""Get PCiE version from SONiC
:returns: version string
"""Get PCiE version from SONiC
:returns: version dict { "PCIE_FW_LOADER": "2.5", "PCIE_FW": "D102_08" }

"""
cmd="sudo bcmcmd 'pciephy fw version'"
p=subprocess.Popen(
cmd = "sudo bcmcmd 'pciephy fw version'"
p = subprocess.Popen(
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
raw_data, err=p.communicate()
if err is not '':
return 'None'
else:
lines=raw_data.split('\n')
raw_data, err = p.communicate()

pcie_version = dict()
pcie_version["PCIE_FW_LOADER"] = 'None'
pcie_version["PCIE_FW"] = 'None'

if err == '':
lines = raw_data.split('\n')
for line in lines:
if 'PCIe FW loader' in line:
version=line.split(':')[1].strip()
return str(version)
pcie_version["PCIE_FW_LOADER"] = line.split(':')[1].strip()
elif 'PCIe FW version' in line:
pcie_version["PCIE_FW"] = line.split(':')[1].strip()
return pcie_version

def get_fpga_version(self):
"""Get FPGA version from SONiC
:returns: version string

"""
version=self.__get_register_value(self.fpga_version_path, '0x00')
version = self.__get_register_value(self.fpga_version_path, '0x00')
if version is not 'None':
version="{}.{}".format(
version = "{}.{}".format(
int(version[2:][:4], 16), int(version[2:][4:], 16))
return str(version)

def firmware_upgrade(self, fw_type, fw_path, fw_extra=None):
"""
@fw_type MANDATORY, firmware type, should be one of the strings: 'cpld', 'fpga', 'bios', 'bmc'
@fw_path MANDATORY, target firmware file
@fw_extra OPTIONAL, extra information string,

for fw_type 'cpld' and 'fpga': it can be used to indicate specific cpld, such as 'cpld1', 'cpld2', ...
or 'cpld_fan_come_board', etc. If None, upgrade all CPLD/FPGA firmware. for fw_type 'bios' and 'bmc',
value should be one of 'master' or 'slave' or 'both'
"""

if fw_type == 'bmc':

# Copy BMC image file to BMC
scp_command = 'scp ' + \
os.path.abspath(fw_path) + ' root@240.1.1.1:/home/root/'

print "Uploading image to BMC..."
print "Running command : ", scp_command
print "Please enter the BMC password"
p = subprocess.Popen(
scp_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
raw_data, err = p.communicate()

if err != "":
print "Failed"
return False

print "Installing BMC image..."

filename_w_ext = os.path.basename(fw_path)
json_data = dict()
json_data["data"] = "flashcp /home/root/" + \
filename_w_ext + " /dev/mtd5"
json_data["timeout"] = 300

r = requests.post(self.bmc_raw_command_url, json=json_data)
if r.status_code == 200:
print "DONE, Rebooting BMC....."
reboot_dict = dict()
reboot_dict["data"] = "reboot"
r = requests.post(self.bmc_raw_command_url, json=reboot_dict)
else:
print "Failed"
return False

elif fw_type == 'fpga':
command = 'fpga_prog ' + fw_path
print "Running command : ", command
process = subprocess.Popen(
command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

while True:
output = process.stdout.readline()
if output == '' and process.poll() is not None:
break
if output:
print output.strip()
rc = process.poll()
return rc

elif 'cpld' in fw_type:
command = 'ispvm ' + fw_path
if fw_extra is not None:
command = 'ispvm -c ' + \
str(fw_extra) + " " + os.path.abspath(fw_path)
print "Running command : ", command
process = subprocess.Popen(
command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

while True:
output = process.stdout.readline()
if output == '' and process.poll() is not None:
break
if output:
print output.strip()
rc = process.poll()
return rc

return None
20 changes: 19 additions & 1 deletion device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/psuutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

__author__ = 'Wirut G.<wgetbumr@celestica.com>'
__license__ = "GPL"
__version__ = "0.1.2"
__version__ = "0.1.3"
__status__ = "Development"

import requests
Expand Down Expand Up @@ -36,6 +36,15 @@ def request_data(self):
self.psu_info_list = psu_info_json.get('Information')
return self.fru_status_list, self.psu_info_list

def airflow_selector(self, pn):
# Set input type.
return {
"DPS-1100FB": "FTOB",
"DPS-1100AB": "BTOF",
"FSJ026-A20G": "FTOB",
"FSJ038-A20G": "BTOF"
}.get(pn, "Unknown")

def get_num_psus(self):
"""
Retrieves the number of PSUs available on the device
Expand Down Expand Up @@ -213,12 +222,21 @@ def get_all(self):
"Present")).strip() == "Present" else False
psu_pw_status = True if str(fru_status.get(
"Power Status")).strip() == "OK" else False
psu_pw_type = str(fru_status.get(
"Power Type")).strip()
ac_status = True if str(fru_status.get(
"AC Status")).strip().upper() == "OK" else False

psu_status_dict["Present"] = psu_ps_status
if psu_ps_status:
psu_status_dict["PowerStatus"] = psu_pw_status
psu_status_dict["PN"] = psu_info_dict[psu_idx]["PN"]
psu_status_dict["SN"] = psu_info_dict[psu_idx]["SN"]
psu_status_dict["InputType"] = psu_pw_type
psu_status_dict["InputStatus"] = True if psu_pw_status and psu_ps_status else False
psu_status_dict["OutputStatus"] = ac_status
psu_status_dict["AirFlow"] = self.airflow_selector(
psu_status_dict["PN"].split()[0])
all_psu_dict[find_psu[0]] = psu_status_dict

return all_psu_dict
24 changes: 24 additions & 0 deletions device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/sensorutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class SensorUtil():

def __init__(self):
self.sensor_url = "http://240.1.1.1:8080/api/sys/sensors"
self.sys_fruid_url = "http://240.1.1.1:8080/api/sys/fruid/sys"
self.sensor_info_list = None

def request_data(self):
Expand All @@ -21,6 +22,9 @@ def request_data(self):
sensor_data_req = requests.get(self.sensor_url)
sensor_json = sensor_data_req.json()
self.sensor_info_list = sensor_json.get('Information')
sys_fruid_req = requests.get(self.sys_fruid_url)
sys_fruid_json = sys_fruid_req.json()
self.sys_fruid_list = sys_fruid_json.get('Information')
return self.sensor_info_list

def input_type_selector(self, unit):
Expand Down Expand Up @@ -291,6 +295,22 @@ def get_sensor_input_high_threshold(self, sensor_index, input_index):

return sensor_input_high_threshold

def get_sys_airflow(self):
sys_air_flow = "Unknown"
sys_pn_data = [
v.split(":") for v in self.sys_fruid_list if "Product Part Number" in v]

if len(sys_pn_data) == 0:
return sys_air_flow

sys_pn = sys_pn_data[0][1]
if "R1241-F0001" in sys_pn:
sys_air_flow = "FTOB"
elif"R1241-F0002" in sys_pn:
sys_air_flow = "BTOF"

return sys_air_flow

def get_all(self):

all_sensor_dict = dict()
Expand Down Expand Up @@ -336,4 +356,8 @@ def get_all(self):

all_sensor_dict[self.sensor_name].update(sensor_dict)

sensor_dict = dict()
sensor_dict["Sys_AirFlow"] = self.get_sys_airflow()
all_sensor_dict["TEMPERATURE"].update(sensor_dict)

return all_sensor_dict
Loading