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

[barefoot] Platform API 2.0 fixups #5539

Merged
merged 3 commits into from
Oct 5, 2020
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/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
SCRIPT_SRC := $(shell pwd)/scripts
CONFIGS_SRC := $(shell pwd)/configs
Expand All @@ -22,10 +22,10 @@ override_dh_auto_install:
cp -r $(SCRIPT_SRC)/* debian/$(PACKAGE_NAME)/usr/local/bin
dh_installdirs -p$(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}/
cp -r $(WHEEL_BUILD_DIR)/* debian/$(PACKAGE_NAME)/usr/share/sonic/device/${PLATFORM}/
dh_installdirs -p$(PACKAGE_NAME) usr/share/sonic/device/${PLATFORM}/plugins
cp -r $(PLUGINS_DIR)/* debian/$(PACKAGE_NAME)/usr/share/sonic/device/${PLATFORM}/plugins/
dh_installdirs -p$(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
cp -r $(PLUGINS_DIR)/* debian/$(PACKAGE_NAME)/usr/share/sonic/device/$(PLATFORM)/plugins/

override_dh_usrlocal:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(self):
sfp_node = Sfp(index)
self._sfp_list.append(sfp_node)

for i in range(MAX_PSU):
for i in range(1, MAX_PSU + 1):
psu = Psu(i)
self._psu_list.append(psu)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


try:
import time
import os
import sys
import errno
Expand All @@ -17,7 +16,7 @@
from sonic_eeprom import eeprom_base
from sonic_eeprom import eeprom_tlvinfo

from .platform_thrift_client import ThriftClient
from .platform_thrift_client import thrift_try
except ImportError, e:
raise ImportError (str(e) + "- required module not found")

Expand Down Expand Up @@ -65,8 +64,6 @@
EEPROM_STATUS = "/var/run/platform/eeprom/status"

class Eeprom(eeprom_tlvinfo.TlvInfoDecoder):
RETRIES = 35

def __init__(self):

with open(os.path.dirname(__file__) + "/logging.conf", 'r') as f:
Expand All @@ -88,20 +85,16 @@ def __init__(self):
self.eeprom_path = EEPROM_SYMLINK
super(Eeprom, self).__init__(self.eeprom_path, 0, EEPROM_STATUS, True)

for attempt in range(self.RETRIES):
if self.eeprom_init():
break
if attempt + 1 == self.RETRIES:
raise RuntimeError("eeprom.py: Initialization failed")
time.sleep(1)

def eeprom_init(self):
def sys_eeprom_get(client):
return client.pltfm_mgr.pltfm_mgr_sys_eeprom_get()
try:
with ThriftClient() as client:
self.eeprom = client.pltfm_mgr.pltfm_mgr_sys_eeprom_get()
self.eeprom = thrift_try(sys_eeprom_get)
except Exception:
return False
raise RuntimeError("eeprom.py: Initialization failed")

self.eeprom_parse()

def eeprom_parse(self):
f = open(EEPROM_STATUS, 'w')
f.write("ok")
f.close()
Expand Down Expand Up @@ -131,9 +124,13 @@ def eeprom_init(self):
eeprom_params += "{0:s}={1:s}".format(elem[1], value)

orig_stdout = sys.stdout

sys.stdout = StringIO()
new_e = eeprom_tlvinfo.TlvInfoDecoder.set_eeprom(self, "", [eeprom_params])
sys.stdout = orig_stdout
try:
new_e = eeprom_tlvinfo.TlvInfoDecoder.set_eeprom(self, "", [eeprom_params])
finally:
sys.stdout = orig_stdout

eeprom_base.EepromDecoder.write_eeprom(self, new_e)

return True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
try:
import os
import sys
import time
import importlib

sys.path.append(os.path.dirname(__file__))
Expand All @@ -11,6 +12,7 @@
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from thrift.protocol import TMultiplexedProtocol
from thrift.Thrift import TException
except ImportError as e:
raise ImportError (str(e) + "- required module not found")

Expand All @@ -35,3 +37,13 @@ def __enter__(self):
return self.open()
def __exit__(self, exc_type, exc_value, tb):
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)
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

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
except ImportError as e:
Expand Down Expand Up @@ -34,9 +34,11 @@ def get_powergood_status(self):
: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
"""
def psu_info_get(client):
return client.pltfm_mgr.pltfm_mgr_pwr_supply_info_get(self.index)

try:
with ThriftClient() as client:
psu_info = client.pltfm_mgr.pltfm_mgr_pwr_supply_info_get(self.index)
psu_info = thrift_try(psu_info_get)
except Exception:
return False

Expand All @@ -49,9 +51,11 @@ def get_presence(self):
: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
"""
def psu_present_get(client):
return client.pltfm_mgr.pltfm_mgr_pwr_supply_present_get(self.index)

try:
with ThriftClient() as client:
status = client.pltfm_mgr.pltfm_mgr_pwr_supply_present_get(self.index)
status = thrift_try(psu_present_get)
except Exception:
return False

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
sys.path.append(os.path.dirname(__file__))

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.sonic_sfp.sfputilbase import SfpUtilBase
Expand Down Expand Up @@ -65,11 +66,13 @@ def __init__(self):
SfpUtilBase.__init__(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:
with ThriftClient() as client:
self.QSFP_PORT_END = client.pltfm_mgr.pltfm_mgr_qsfp_get_max_port();
self.PORT_END = self.QSFP_PORT_END
self.PORTS_IN_BLOCK = self.QSFP_PORT_END
self.QSFP_PORT_END = thrift_try(qsfp_max_port_get)
self.PORT_END = self.QSFP_PORT_END
self.PORTS_IN_BLOCK = self.QSFP_PORT_END

def get_presence(self, port_num):
# Check for invalid port_num
Expand All @@ -78,9 +81,11 @@ def get_presence(self, port_num):

presence = False

def qsfp_presence_get(client):
return client.pltfm_mgr.pltfm_mgr_qsfp_presence_get(port_num)

try:
with ThriftClient() as client:
presence = client.pltfm_mgr.pltfm_mgr_qsfp_presence_get(port_num)
presence = thrift_try(qsfp_presence_get)
except Exception as e:
print e.__doc__
print e.message
Expand All @@ -92,27 +97,36 @@ def get_low_power_mode(self, port_num):
if port_num < self.port_start or port_num > self.port_end:
return False

with ThriftClient() as client:
lpmode = client.pltfm_mgr.pltfm_mgr_qsfp_lpmode_get(port_num)
def qsfp_lpmode_get(client):
return client.pltfm_mgr.pltfm_mgr_qsfp_lpmode_get(port_num)

lpmode = thrift_try(qsfp_lpmode_get)

return lpmode

def set_low_power_mode(self, port_num, lpmode):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
return False

with ThriftClient() as client:
status = client.pltfm_mgr.pltfm_mgr_qsfp_lpmode_set(port_num, lpmode)
def qsfp_lpmode_set(client):
return client.pltfm_mgr.pltfm_mgr_qsfp_lpmode_set(port_num, lpmode)

status = thrift_try(qsfp_lpmode_set)

return (status == 0)

def reset(self, port_num):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
return False

with ThriftClient() as client:
def qsfp_reset(client):
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

def check_transceiver_change(self):
Expand Down Expand Up @@ -188,15 +202,16 @@ def get_transceiver_change_event(self, timeout=0):
def _get_port_eeprom_path(self, port_num, devid):
eeprom_path = None

with ThriftClient() as client:
presence = client.pltfm_mgr.pltfm_mgr_qsfp_presence_get(port_num)
if presence == True:
eeprom_cache = open(SFP_EEPROM_CACHE, 'wb')
eeprom_hex = client.pltfm_mgr.pltfm_mgr_qsfp_info_get(port_num)
eeprom_raw = bytearray.fromhex(eeprom_hex)
eeprom_cache.write(eeprom_raw)
eeprom_cache.close()
eeprom_path = SFP_EEPROM_CACHE
def qsfp_info_get(client):
return client.pltfm_mgr.pltfm_mgr_qsfp_info_get(port_num)

if self.get_presence(port_num):
eeprom_hex = thrift_try(qsfp_info_get)
eeprom_cache = open(SFP_EEPROM_CACHE, 'wb')
eeprom_raw = bytearray.fromhex(eeprom_hex)
eeprom_cache.write(eeprom_raw)
eeprom_cache.close()
eeprom_path = SFP_EEPROM_CACHE

return eeprom_path

Expand Down
2 changes: 0 additions & 2 deletions platform/barefoot/sonic-platform-modules-bfn/debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ override_dh_auto_install:
cp -r $(SCRIPT_SRC)/* debian/$(PACKAGE_NAME)/usr/local/bin
dh_installdirs -p$(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:

Expand Down