[device]: Fix a bug that psuutil cannot access gpio sysfs to get PSU status (#1789)
This commit is contained in:
parent
b745c0bf1b
commit
aaac497370
@ -3,7 +3,8 @@
|
|||||||
# Platform-specific PSU status interface for SONiC
|
# Platform-specific PSU status interface for SONiC
|
||||||
#
|
#
|
||||||
|
|
||||||
import os.path
|
import os
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from sonic_psu.psu_base import PsuBase
|
from sonic_psu.psu_base import PsuBase
|
||||||
@ -18,42 +19,32 @@ class PsuUtil(PsuBase):
|
|||||||
PsuBase.__init__(self)
|
PsuBase.__init__(self)
|
||||||
# DX010 PSU pin mapping
|
# DX010 PSU pin mapping
|
||||||
self.psu = [
|
self.psu = [
|
||||||
{'base':216}, # Reserved
|
{'base': self.get_gpio_base()},
|
||||||
{'abs':27, 'power':22},
|
{'abs':27, 'power':22},
|
||||||
{'abs':28, 'power':25}
|
{'abs':28, 'power':25}
|
||||||
]
|
]
|
||||||
|
|
||||||
def init_psu_gpio(self, pinnum):
|
def get_gpio_base(self):
|
||||||
# export pin, input as default
|
sys_gpio_dir = "/sys/class/gpio"
|
||||||
gpio_base = self.psu[0]['base']
|
for r in os.listdir(sys_gpio_dir):
|
||||||
export_file = "/sys/class/gpio/export"
|
if "gpiochip" in r:
|
||||||
direction_file = '/sys/class/gpio/gpio' + str(gpio_base+pinnum) + '/direction'
|
return int(r[8:],10)
|
||||||
|
return 216 #Reserve
|
||||||
try:
|
|
||||||
with open(export_file, 'w') as fd:
|
|
||||||
fd.write(str(gpio_base+pinnum))
|
|
||||||
except Exception as error:
|
|
||||||
logging.error("Unable to export gpio ", pinnum)
|
|
||||||
|
|
||||||
|
|
||||||
# Get a psu status and presence
|
# Get a psu status and presence
|
||||||
def read_psu_statuses(self, pinnum):
|
def read_psu_statuses(self, pinnum):
|
||||||
sys_gpio_dir = "/sys/class/gpio"
|
sys_gpio_dir = "/sys/class/gpio"
|
||||||
retval = 'ERR'
|
|
||||||
gpio_base = self.psu[0]['base']
|
gpio_base = self.psu[0]['base']
|
||||||
|
|
||||||
gpio_dir = sys_gpio_dir + '/gpio' + str(gpio_base+pinnum)
|
gpio_dir = sys_gpio_dir + '/gpio' + str(gpio_base+pinnum)
|
||||||
gpio_file = gpio_dir + "/value"
|
gpio_file = gpio_dir + "/value"
|
||||||
|
|
||||||
# init gpio
|
|
||||||
if (not os.path.isdir(gpio_dir)):
|
|
||||||
self.init_psu_gpio(pinnum)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(gpio_file, 'r') as fd:
|
with open(gpio_file, 'r') as fd:
|
||||||
retval = fd.read()
|
retval = fd.read()
|
||||||
except Exception as error:
|
except IOError:
|
||||||
logging.error("Unable to open ", gpio_file, "file !")
|
raise IOError("Unable to open " + gpio_file + "file !")
|
||||||
|
|
||||||
retval = retval.rstrip('\r\n')
|
retval = retval.rstrip('\r\n')
|
||||||
return retval
|
return retval
|
||||||
@ -76,11 +67,10 @@ class PsuUtil(PsuBase):
|
|||||||
"""
|
"""
|
||||||
status = 0
|
status = 0
|
||||||
psu_status = self.read_psu_statuses(self.psu[index]['power'])
|
psu_status = self.read_psu_statuses(self.psu[index]['power'])
|
||||||
if (psu_status != 'ERR'):
|
psu_status = int(psu_status, 10)
|
||||||
psu_status = int(psu_status, 10)
|
# Check for PSU status
|
||||||
# Check for PSU status
|
if (psu_status == 1):
|
||||||
if (psu_status == 1):
|
status = 1
|
||||||
status = 1
|
|
||||||
|
|
||||||
return status
|
return status
|
||||||
|
|
||||||
@ -93,10 +83,9 @@ class PsuUtil(PsuBase):
|
|||||||
"""
|
"""
|
||||||
status = 0
|
status = 0
|
||||||
psu_absence = self.read_psu_statuses(self.psu[index]['abs'])
|
psu_absence = self.read_psu_statuses(self.psu[index]['abs'])
|
||||||
if (psu_absence != 'ERR'):
|
psu_absence = (int(psu_absence, 10))
|
||||||
psu_absence = (int(psu_absence, 10))
|
# Check for PSU presence
|
||||||
# Check for PSU presence
|
if (psu_absence == 0):
|
||||||
if (psu_absence == 0):
|
status = 1
|
||||||
status = 1
|
|
||||||
|
|
||||||
return status
|
return status
|
||||||
|
Reference in New Issue
Block a user