[devices]: As7816 64x validate sfputil psuutil (#1466)

This commit is contained in:
Roy Lee 2018-03-07 16:33:33 +08:00 committed by lguohan
parent f250fe745a
commit 763461eeac
3 changed files with 67 additions and 10 deletions

View File

@ -0,0 +1,61 @@
#!/usr/bin/env python
#############################################################################
# Accton
#
# Module contains an implementation of SONiC PSU Base API and
# provides the PSUs status which are available in the platform
#
#############################################################################
import os.path
try:
from sonic_psu.psu_base import PsuBase
except ImportError as e:
raise ImportError (str(e) + "- required module not found")
class PsuUtil(PsuBase):
"""Platform-specific PSUutil class"""
def __init__(self):
PsuBase.__init__(self)
self.psu_path = "/sys/bus/i2c/devices/"
self.psu_presence = "/psu_present"
self.psu_oper_status = "/psu_power_good"
self.psu_mapping = {
1: "10-0053",
2: "9-0050",
}
def get_num_psus(self):
return len(self.psu_mapping)
def get_psu_status(self, index):
if index is None:
return False
status = 0
node = self.psu_path + self.psu_mapping[index]+self.psu_oper_status
try:
with open(node, 'r') as power_status:
status = int(power_status.read())
except IOError:
return False
return status == 1
def get_psu_presence(self, index):
if index is None:
return False
status = 0
node = self.psu_path + self.psu_mapping[index] + self.psu_presence
try:
with open(node, 'r') as presence_status:
status = int(presence_status.read())
except IOError:
return False
return status == 1

View File

@ -94,9 +94,8 @@ class SfpUtil(SfpUtilBase):
# Check for invalid port_num # Check for invalid port_num
if port_num < self._port_start or port_num > self._port_end: if port_num < self._port_start or port_num > self._port_end:
return False return False
path = "/sys/bus/i2c/devices/19-0060/module_reset_{0}"
path = "/sys/bus/i2c/devices/{0}-0050/sfp_port_reset" port_ps = path.format(port_num+1)
port_ps = path.format(self.port_to_i2c_mapping[port_num+1])
try: try:
reg_file = open(port_ps, 'w') reg_file = open(port_ps, 'w')
@ -104,20 +103,17 @@ class SfpUtil(SfpUtilBase):
print "Error: unable to open file: %s" % str(e) print "Error: unable to open file: %s" % str(e)
return False return False
#toggle reset #HW will clear reset after set.
reg_file.seek(0) reg_file.seek(0)
reg_file.write('1') reg_file.write('1')
time.sleep(1)
reg_file.seek(0)
reg_file.write('0')
reg_file.close() reg_file.close()
return True return True
def set_low_power_mode(self, port_nuM, lpmode): def set_low_power_mode(self, port_nuM, lpmode):
raise NotImplementedErro raise NotImplementedError
def get_low_power_mode(self, port_num): def get_low_power_mode(self, port_num):
raise NotImplementedErro raise NotImplementedError
def get_presence(self, port_num): def get_presence(self, port_num):
# Check for invalid port_num # Check for invalid port_num

@ -1 +1 @@
Subproject commit 5c48c84b0f3f5ee8b44f02ff3e0c3d1ad2169066 Subproject commit aaaea8d12838de634fd27e936e4086258933cbac