[barefoot] Platform API 2.0 fixups (#5539)
Fixes for bfn platform api Signed-off-by: Volodymyr Boyko <volodymyrx.boiko@intel.com>
This commit is contained in:
parent
8c344095a8
commit
f61ff95e26
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/make -f
|
#!/usr/bin/make -f
|
||||||
|
|
||||||
PLATFORM = x86_64-accton_wedge100bf_32x-r0
|
PLATFORM := x86_64-accton_wedge100bf_32x-r0
|
||||||
PACKAGE_NAME := sonic-platform-modules-bfn-montara
|
PACKAGE_NAME := sonic-platform-modules-bfn-montara
|
||||||
SCRIPT_SRC := $(shell pwd)/scripts
|
SCRIPT_SRC := $(shell pwd)/scripts
|
||||||
CONFIGS_SRC := $(shell pwd)/configs
|
CONFIGS_SRC := $(shell pwd)/configs
|
||||||
@ -22,10 +22,10 @@ override_dh_auto_install:
|
|||||||
cp -r $(SCRIPT_SRC)/* debian/$(PACKAGE_NAME)/usr/local/bin
|
cp -r $(SCRIPT_SRC)/* debian/$(PACKAGE_NAME)/usr/local/bin
|
||||||
dh_installdirs -p$(PACKAGE_NAME) etc/network/interfaces.d/
|
dh_installdirs -p$(PACKAGE_NAME) etc/network/interfaces.d/
|
||||||
cp -r $(CONFIGS_SRC)/network/interfaces.d/* debian/$(PACKAGE_NAME)/etc/network/interfaces.d/
|
cp -r $(CONFIGS_SRC)/network/interfaces.d/* debian/$(PACKAGE_NAME)/etc/network/interfaces.d/
|
||||||
dh_installdirs -p$(PACKAGE_NAME) /usr/share/sonic/device/${PLATFORM}/
|
dh_installdirs -p$(PACKAGE_NAME) usr/share/sonic/device/$(PLATFORM)/
|
||||||
cp -r $(WHEEL_BUILD_DIR)/* debian/$(PACKAGE_NAME)/usr/share/sonic/device/${PLATFORM}/
|
cp -r $(WHEEL_BUILD_DIR)/* debian/$(PACKAGE_NAME)/usr/share/sonic/device/$(PLATFORM)/
|
||||||
dh_installdirs -p$(PACKAGE_NAME) usr/share/sonic/device/${PLATFORM}/plugins
|
dh_installdirs -p$(PACKAGE_NAME) usr/share/sonic/device/$(PLATFORM)/plugins
|
||||||
cp -r $(PLUGINS_DIR)/* debian/$(PACKAGE_NAME)/usr/share/sonic/device/${PLATFORM}/plugins/
|
cp -r $(PLUGINS_DIR)/* debian/$(PACKAGE_NAME)/usr/share/sonic/device/$(PLATFORM)/plugins/
|
||||||
|
|
||||||
override_dh_usrlocal:
|
override_dh_usrlocal:
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ class Chassis(ChassisBase):
|
|||||||
sfp_node = Sfp(index)
|
sfp_node = Sfp(index)
|
||||||
self._sfp_list.append(sfp_node)
|
self._sfp_list.append(sfp_node)
|
||||||
|
|
||||||
for i in range(MAX_PSU):
|
for i in range(1, MAX_PSU + 1):
|
||||||
psu = Psu(i)
|
psu = Psu(i)
|
||||||
self._psu_list.append(psu)
|
self._psu_list.append(psu)
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import time
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import errno
|
import errno
|
||||||
@ -17,7 +16,7 @@ try:
|
|||||||
from sonic_eeprom import eeprom_base
|
from sonic_eeprom import eeprom_base
|
||||||
from sonic_eeprom import eeprom_tlvinfo
|
from sonic_eeprom import eeprom_tlvinfo
|
||||||
|
|
||||||
from .platform_thrift_client import ThriftClient
|
from .platform_thrift_client import thrift_try
|
||||||
except ImportError, e:
|
except ImportError, e:
|
||||||
raise ImportError (str(e) + "- required module not found")
|
raise ImportError (str(e) + "- required module not found")
|
||||||
|
|
||||||
@ -65,8 +64,6 @@ EEPROM_SYMLINK = "/var/run/platform/eeprom/syseeprom"
|
|||||||
EEPROM_STATUS = "/var/run/platform/eeprom/status"
|
EEPROM_STATUS = "/var/run/platform/eeprom/status"
|
||||||
|
|
||||||
class Eeprom(eeprom_tlvinfo.TlvInfoDecoder):
|
class Eeprom(eeprom_tlvinfo.TlvInfoDecoder):
|
||||||
RETRIES = 35
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
with open(os.path.dirname(__file__) + "/logging.conf", 'r') as f:
|
with open(os.path.dirname(__file__) + "/logging.conf", 'r') as f:
|
||||||
@ -88,20 +85,16 @@ class Eeprom(eeprom_tlvinfo.TlvInfoDecoder):
|
|||||||
self.eeprom_path = EEPROM_SYMLINK
|
self.eeprom_path = EEPROM_SYMLINK
|
||||||
super(Eeprom, self).__init__(self.eeprom_path, 0, EEPROM_STATUS, True)
|
super(Eeprom, self).__init__(self.eeprom_path, 0, EEPROM_STATUS, True)
|
||||||
|
|
||||||
for attempt in range(self.RETRIES):
|
def sys_eeprom_get(client):
|
||||||
if self.eeprom_init():
|
return client.pltfm_mgr.pltfm_mgr_sys_eeprom_get()
|
||||||
break
|
|
||||||
if attempt + 1 == self.RETRIES:
|
|
||||||
raise RuntimeError("eeprom.py: Initialization failed")
|
|
||||||
time.sleep(1)
|
|
||||||
|
|
||||||
def eeprom_init(self):
|
|
||||||
try:
|
try:
|
||||||
with ThriftClient() as client:
|
self.eeprom = thrift_try(sys_eeprom_get)
|
||||||
self.eeprom = client.pltfm_mgr.pltfm_mgr_sys_eeprom_get()
|
|
||||||
except Exception:
|
except Exception:
|
||||||
return False
|
raise RuntimeError("eeprom.py: Initialization failed")
|
||||||
|
|
||||||
|
self.eeprom_parse()
|
||||||
|
|
||||||
|
def eeprom_parse(self):
|
||||||
f = open(EEPROM_STATUS, 'w')
|
f = open(EEPROM_STATUS, 'w')
|
||||||
f.write("ok")
|
f.write("ok")
|
||||||
f.close()
|
f.close()
|
||||||
@ -131,9 +124,13 @@ class Eeprom(eeprom_tlvinfo.TlvInfoDecoder):
|
|||||||
eeprom_params += "{0:s}={1:s}".format(elem[1], value)
|
eeprom_params += "{0:s}={1:s}".format(elem[1], value)
|
||||||
|
|
||||||
orig_stdout = sys.stdout
|
orig_stdout = sys.stdout
|
||||||
|
|
||||||
sys.stdout = StringIO()
|
sys.stdout = StringIO()
|
||||||
new_e = eeprom_tlvinfo.TlvInfoDecoder.set_eeprom(self, "", [eeprom_params])
|
try:
|
||||||
sys.stdout = orig_stdout
|
new_e = eeprom_tlvinfo.TlvInfoDecoder.set_eeprom(self, "", [eeprom_params])
|
||||||
|
finally:
|
||||||
|
sys.stdout = orig_stdout
|
||||||
|
|
||||||
eeprom_base.EepromDecoder.write_eeprom(self, new_e)
|
eeprom_base.EepromDecoder.write_eeprom(self, new_e)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
try:
|
try:
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
import importlib
|
import importlib
|
||||||
|
|
||||||
sys.path.append(os.path.dirname(__file__))
|
sys.path.append(os.path.dirname(__file__))
|
||||||
@ -11,6 +12,7 @@ try:
|
|||||||
from thrift.transport import TTransport
|
from thrift.transport import TTransport
|
||||||
from thrift.protocol import TBinaryProtocol
|
from thrift.protocol import TBinaryProtocol
|
||||||
from thrift.protocol import TMultiplexedProtocol
|
from thrift.protocol import TMultiplexedProtocol
|
||||||
|
from thrift.Thrift import TException
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
raise ImportError (str(e) + "- required module not found")
|
raise ImportError (str(e) + "- required module not found")
|
||||||
|
|
||||||
@ -35,3 +37,13 @@ class ThriftClient(object):
|
|||||||
return self.open()
|
return self.open()
|
||||||
def __exit__(self, exc_type, exc_value, tb):
|
def __exit__(self, exc_type, exc_value, tb):
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
|
def thrift_try(func, attempts=35):
|
||||||
|
for attempt in range(attempts):
|
||||||
|
try:
|
||||||
|
with ThriftClient() as client:
|
||||||
|
return func(client)
|
||||||
|
except TException as e:
|
||||||
|
if attempt + 1 == attempts:
|
||||||
|
raise e
|
||||||
|
time.sleep(1)
|
||||||
|
@ -6,7 +6,7 @@ try:
|
|||||||
|
|
||||||
sys.path.append(os.path.dirname(__file__))
|
sys.path.append(os.path.dirname(__file__))
|
||||||
|
|
||||||
from .platform_thrift_client import ThriftClient
|
from .platform_thrift_client import thrift_try
|
||||||
|
|
||||||
from sonic_platform_base.psu_base import PsuBase
|
from sonic_platform_base.psu_base import PsuBase
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
@ -34,9 +34,11 @@ class Psu(PsuBase):
|
|||||||
:param self.index: An integer, 1-based self.index of the PSU of which to query status
|
:param self.index: An integer, 1-based self.index of the PSU of which to query status
|
||||||
:return: Boolean, True if PSU is operating properly, False if PSU is faulty
|
:return: Boolean, True if PSU is operating properly, False if PSU is faulty
|
||||||
"""
|
"""
|
||||||
|
def psu_info_get(client):
|
||||||
|
return client.pltfm_mgr.pltfm_mgr_pwr_supply_info_get(self.index)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with ThriftClient() as client:
|
psu_info = thrift_try(psu_info_get)
|
||||||
psu_info = client.pltfm_mgr.pltfm_mgr_pwr_supply_info_get(self.index)
|
|
||||||
except Exception:
|
except Exception:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -49,9 +51,11 @@ class Psu(PsuBase):
|
|||||||
:param self.index: An integer, 1-based self.index of the PSU of which to query status
|
:param self.index: An integer, 1-based self.index of the PSU of which to query status
|
||||||
:return: Boolean, True if PSU is plugged, False if not
|
:return: Boolean, True if PSU is plugged, False if not
|
||||||
"""
|
"""
|
||||||
|
def psu_present_get(client):
|
||||||
|
return client.pltfm_mgr.pltfm_mgr_pwr_supply_present_get(self.index)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with ThriftClient() as client:
|
status = thrift_try(psu_present_get)
|
||||||
status = client.pltfm_mgr.pltfm_mgr_pwr_supply_present_get(self.index)
|
|
||||||
except Exception:
|
except Exception:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ try:
|
|||||||
sys.path.append(os.path.dirname(__file__))
|
sys.path.append(os.path.dirname(__file__))
|
||||||
|
|
||||||
from .platform_thrift_client import ThriftClient
|
from .platform_thrift_client import ThriftClient
|
||||||
|
from .platform_thrift_client import thrift_try
|
||||||
|
|
||||||
from sonic_platform_base.sfp_base import SfpBase
|
from sonic_platform_base.sfp_base import SfpBase
|
||||||
from sonic_platform_base.sonic_sfp.sfputilbase import SfpUtilBase
|
from sonic_platform_base.sonic_sfp.sfputilbase import SfpUtilBase
|
||||||
@ -65,11 +66,13 @@ class SfpUtil(SfpUtilBase):
|
|||||||
SfpUtilBase.__init__(self)
|
SfpUtilBase.__init__(self)
|
||||||
|
|
||||||
def update_port_info(self):
|
def update_port_info(self):
|
||||||
|
def qsfp_max_port_get(client):
|
||||||
|
return client.pltfm_mgr.pltfm_mgr_qsfp_get_max_port();
|
||||||
|
|
||||||
if self.QSFP_PORT_END == 0:
|
if self.QSFP_PORT_END == 0:
|
||||||
with ThriftClient() as client:
|
self.QSFP_PORT_END = thrift_try(qsfp_max_port_get)
|
||||||
self.QSFP_PORT_END = client.pltfm_mgr.pltfm_mgr_qsfp_get_max_port();
|
self.PORT_END = self.QSFP_PORT_END
|
||||||
self.PORT_END = self.QSFP_PORT_END
|
self.PORTS_IN_BLOCK = self.QSFP_PORT_END
|
||||||
self.PORTS_IN_BLOCK = self.QSFP_PORT_END
|
|
||||||
|
|
||||||
def get_presence(self, port_num):
|
def get_presence(self, port_num):
|
||||||
# Check for invalid port_num
|
# Check for invalid port_num
|
||||||
@ -78,9 +81,11 @@ class SfpUtil(SfpUtilBase):
|
|||||||
|
|
||||||
presence = False
|
presence = False
|
||||||
|
|
||||||
|
def qsfp_presence_get(client):
|
||||||
|
return client.pltfm_mgr.pltfm_mgr_qsfp_presence_get(port_num)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with ThriftClient() as client:
|
presence = thrift_try(qsfp_presence_get)
|
||||||
presence = client.pltfm_mgr.pltfm_mgr_qsfp_presence_get(port_num)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print e.__doc__
|
print e.__doc__
|
||||||
print e.message
|
print e.message
|
||||||
@ -92,8 +97,11 @@ class SfpUtil(SfpUtilBase):
|
|||||||
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
|
||||||
|
|
||||||
with ThriftClient() as client:
|
def qsfp_lpmode_get(client):
|
||||||
lpmode = client.pltfm_mgr.pltfm_mgr_qsfp_lpmode_get(port_num)
|
return client.pltfm_mgr.pltfm_mgr_qsfp_lpmode_get(port_num)
|
||||||
|
|
||||||
|
lpmode = thrift_try(qsfp_lpmode_get)
|
||||||
|
|
||||||
return lpmode
|
return lpmode
|
||||||
|
|
||||||
def set_low_power_mode(self, port_num, lpmode):
|
def set_low_power_mode(self, port_num, lpmode):
|
||||||
@ -101,8 +109,11 @@ class SfpUtil(SfpUtilBase):
|
|||||||
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
|
||||||
|
|
||||||
with ThriftClient() as client:
|
def qsfp_lpmode_set(client):
|
||||||
status = client.pltfm_mgr.pltfm_mgr_qsfp_lpmode_set(port_num, lpmode)
|
return client.pltfm_mgr.pltfm_mgr_qsfp_lpmode_set(port_num, lpmode)
|
||||||
|
|
||||||
|
status = thrift_try(qsfp_lpmode_set)
|
||||||
|
|
||||||
return (status == 0)
|
return (status == 0)
|
||||||
|
|
||||||
def reset(self, port_num):
|
def reset(self, port_num):
|
||||||
@ -110,9 +121,12 @@ class SfpUtil(SfpUtilBase):
|
|||||||
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
|
||||||
|
|
||||||
with ThriftClient() as client:
|
def qsfp_reset(client):
|
||||||
client.pltfm_mgr.pltfm_mgr_qsfp_reset(port_num, True)
|
client.pltfm_mgr.pltfm_mgr_qsfp_reset(port_num, True)
|
||||||
status = client.pltfm_mgr.pltfm_mgr_qsfp_reset(port_num, False)
|
return client.pltfm_mgr.pltfm_mgr_qsfp_reset(port_num, False)
|
||||||
|
|
||||||
|
status = thrift_try(qsfp_reset)
|
||||||
|
|
||||||
return status
|
return status
|
||||||
|
|
||||||
def check_transceiver_change(self):
|
def check_transceiver_change(self):
|
||||||
@ -188,15 +202,16 @@ class SfpUtil(SfpUtilBase):
|
|||||||
def _get_port_eeprom_path(self, port_num, devid):
|
def _get_port_eeprom_path(self, port_num, devid):
|
||||||
eeprom_path = None
|
eeprom_path = None
|
||||||
|
|
||||||
with ThriftClient() as client:
|
def qsfp_info_get(client):
|
||||||
presence = client.pltfm_mgr.pltfm_mgr_qsfp_presence_get(port_num)
|
return client.pltfm_mgr.pltfm_mgr_qsfp_info_get(port_num)
|
||||||
if presence == True:
|
|
||||||
eeprom_cache = open(SFP_EEPROM_CACHE, 'wb')
|
if self.get_presence(port_num):
|
||||||
eeprom_hex = client.pltfm_mgr.pltfm_mgr_qsfp_info_get(port_num)
|
eeprom_hex = thrift_try(qsfp_info_get)
|
||||||
eeprom_raw = bytearray.fromhex(eeprom_hex)
|
eeprom_cache = open(SFP_EEPROM_CACHE, 'wb')
|
||||||
eeprom_cache.write(eeprom_raw)
|
eeprom_raw = bytearray.fromhex(eeprom_hex)
|
||||||
eeprom_cache.close()
|
eeprom_cache.write(eeprom_raw)
|
||||||
eeprom_path = SFP_EEPROM_CACHE
|
eeprom_cache.close()
|
||||||
|
eeprom_path = SFP_EEPROM_CACHE
|
||||||
|
|
||||||
return eeprom_path
|
return eeprom_path
|
||||||
|
|
||||||
|
@ -20,8 +20,6 @@ override_dh_auto_install:
|
|||||||
cp -r $(SCRIPT_SRC)/* debian/$(PACKAGE_NAME)/usr/local/bin
|
cp -r $(SCRIPT_SRC)/* debian/$(PACKAGE_NAME)/usr/local/bin
|
||||||
dh_installdirs -p$(PACKAGE_NAME) etc/network/interfaces.d/
|
dh_installdirs -p$(PACKAGE_NAME) etc/network/interfaces.d/
|
||||||
cp -r $(CONFIGS_SRC)/network/interfaces.d/* debian/$(PACKAGE_NAME)/etc/network/interfaces.d/
|
cp -r $(CONFIGS_SRC)/network/interfaces.d/* debian/$(PACKAGE_NAME)/etc/network/interfaces.d/
|
||||||
dh_installdirs -p$(PACKAGE_NAME) usr/share/sonic/platform/
|
|
||||||
cp -r $(WHEEL_BUILD_DIR)/* debian/$(PACKAGE_NAME)/usr/share/sonic/platform/
|
|
||||||
|
|
||||||
override_dh_usrlocal:
|
override_dh_usrlocal:
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user