[platform]: BFN platform modules update (#3389)
* Fixed initial state for eeprom.py and sfputil.py when thrift server is down * Added transceiver plug-in/out event processing Signed-off-by: Andriy Kokhan <akokhan@barefootnetworks.com>
This commit is contained in:
parent
f92056017e
commit
754c0b1f28
@ -9,6 +9,9 @@ try:
|
||||
import sys
|
||||
import errno
|
||||
import datetime
|
||||
import logging
|
||||
import logging.config
|
||||
import yaml
|
||||
|
||||
sys.path.append(os.path.dirname(__file__))
|
||||
import pltfm_mgr_rpc
|
||||
@ -71,13 +74,17 @@ transport = None
|
||||
pltfm_mgr = None
|
||||
|
||||
EEPROM_SYMLINK = "/var/run/platform/eeprom/syseeprom"
|
||||
|
||||
EEPROM_STATUS = "/var/run/platform/eeprom/status"
|
||||
|
||||
class board(eeprom_tlvinfo.TlvInfoDecoder):
|
||||
RETRIES = 30
|
||||
RETRIES = 3
|
||||
|
||||
def __init__(self, name, path, cpld_root, ro):
|
||||
|
||||
with open(os.path.dirname(__file__) + "/logging.conf", 'r') as f:
|
||||
config_dict = yaml.load(f)
|
||||
logging.config.dictConfig(config_dict)
|
||||
|
||||
if not os.path.exists(os.path.dirname(EEPROM_SYMLINK)):
|
||||
try:
|
||||
os.makedirs(os.path.dirname(EEPROM_SYMLINK))
|
||||
@ -86,19 +93,17 @@ class board(eeprom_tlvinfo.TlvInfoDecoder):
|
||||
raise
|
||||
|
||||
open(EEPROM_SYMLINK, 'a').close()
|
||||
f = open(EEPROM_STATUS, 'w')
|
||||
f.write("initializing..")
|
||||
f.close()
|
||||
|
||||
self.eeprom_path = EEPROM_SYMLINK
|
||||
super(board, self).__init__(self.eeprom_path, 0, '', True)
|
||||
super(board, self).__init__(self.eeprom_path, 0, EEPROM_STATUS, True)
|
||||
|
||||
for attempt in range(self.RETRIES + 1):
|
||||
if not self.eeprom_init():
|
||||
time.sleep(1)
|
||||
else:
|
||||
for attempt in range(self.RETRIES):
|
||||
if self.eeprom_init() or (attempt + 1 >= self.RETRIES):
|
||||
break
|
||||
|
||||
if attempt == self.RETRIES:
|
||||
raise RuntimeError("Could not initialize syseeprom")
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
def thrift_setup(self):
|
||||
global thrift_server, transport, pltfm_mgr
|
||||
@ -119,13 +124,18 @@ class board(eeprom_tlvinfo.TlvInfoDecoder):
|
||||
|
||||
def eeprom_init(self):
|
||||
global pltfm_mgr
|
||||
|
||||
try:
|
||||
self.thrift_setup()
|
||||
eeprom = pltfm_mgr.pltfm_mgr_sys_eeprom_get()
|
||||
self.thrift_teardown()
|
||||
self.thrift_setup()
|
||||
eeprom = pltfm_mgr.pltfm_mgr_sys_eeprom_get()
|
||||
self.thrift_teardown()
|
||||
except:
|
||||
return False
|
||||
|
||||
f = open(EEPROM_STATUS, 'w')
|
||||
f.write("ok")
|
||||
f.close()
|
||||
|
||||
eeprom_params = ""
|
||||
for attr, val in eeprom.__dict__.iteritems():
|
||||
if val is None:
|
||||
|
@ -0,0 +1,17 @@
|
||||
version: 1
|
||||
disable_existing_loggers: False
|
||||
|
||||
formatters:
|
||||
simple:
|
||||
format: '%(asctime)s %(name)-30s %(levelname)-7s %(message)s'
|
||||
|
||||
handlers:
|
||||
file:
|
||||
class: logging.handlers.RotatingFileHandler
|
||||
formatter: simple
|
||||
filename: /var/log/platform.log
|
||||
|
||||
root:
|
||||
level: ERROR
|
||||
handlers:
|
||||
- file
|
@ -34,6 +34,7 @@ class SfpUtil(SfpUtilBase):
|
||||
QSFP_PORT_START = 1
|
||||
QSFP_PORT_END = 0
|
||||
EEPROM_OFFSET = 0
|
||||
QSFP_CHECK_INTERVAL = 4
|
||||
|
||||
@property
|
||||
def port_start(self):
|
||||
@ -56,6 +57,11 @@ class SfpUtil(SfpUtilBase):
|
||||
raise Exception()
|
||||
|
||||
def __init__(self):
|
||||
self.ready = False
|
||||
self.phy_port_dict = {'-1': 'system_not_ready'}
|
||||
self.phy_port_cur_state = {}
|
||||
self.qsfp_interval = self.QSFP_CHECK_INTERVAL
|
||||
|
||||
if not os.path.exists(os.path.dirname(SFP_EEPROM_CACHE)):
|
||||
try:
|
||||
os.makedirs(os.path.dirname(SFP_EEPROM_CACHE))
|
||||
@ -142,12 +148,76 @@ class SfpUtil(SfpUtilBase):
|
||||
self.thrift_teardown()
|
||||
return status
|
||||
|
||||
def check_transceiver_change(self):
|
||||
if not self.ready:
|
||||
return
|
||||
|
||||
self.phy_port_dict = {}
|
||||
|
||||
try:
|
||||
self.thrift_setup()
|
||||
except:
|
||||
return
|
||||
|
||||
# Get presence of each SFP
|
||||
for port in range(self.port_start, self.port_end + 1):
|
||||
try:
|
||||
sfp_resent = pltfm_mgr.pltfm_mgr_qsfp_presence_get(port)
|
||||
except:
|
||||
sfp_resent = False
|
||||
sfp_state = '1' if sfp_resent else '0'
|
||||
|
||||
if port in self.phy_port_cur_state:
|
||||
if self.phy_port_cur_state[port] != sfp_state:
|
||||
self.phy_port_dict[port] = sfp_state
|
||||
else:
|
||||
self.phy_port_dict[port] = sfp_state
|
||||
|
||||
# Update port current state
|
||||
self.phy_port_cur_state[port] = sfp_state
|
||||
|
||||
self.thrift_teardown()
|
||||
|
||||
def get_transceiver_change_event(self, timeout=0):
|
||||
phy_port_dict = {}
|
||||
status = True
|
||||
# TODO: Process transceiver plug-in/out event
|
||||
time.sleep(1)
|
||||
return status, phy_port_dict
|
||||
forever = False
|
||||
if timeout == 0:
|
||||
forever = True
|
||||
elif timeout > 0:
|
||||
timeout = timeout / float(1000) # Convert to secs
|
||||
else:
|
||||
print "get_transceiver_change_event:Invalid timeout value", timeout
|
||||
return False, {}
|
||||
|
||||
while forever or timeout > 0:
|
||||
if not self.ready:
|
||||
try:
|
||||
self.thrift_setup()
|
||||
self.thrift_teardown()
|
||||
except:
|
||||
pass
|
||||
else:
|
||||
self.ready = True
|
||||
self.phy_port_dict = {}
|
||||
break
|
||||
elif self.qsfp_interval == 0:
|
||||
self.qsfp_interval = self.QSFP_CHECK_INTERVAL
|
||||
|
||||
# Process transceiver plug-in/out event
|
||||
self.check_transceiver_change()
|
||||
|
||||
# Break if tranceiver state has changed
|
||||
if bool(self.phy_port_dict):
|
||||
break
|
||||
|
||||
if timeout:
|
||||
timeout -= 1
|
||||
|
||||
if self.qsfp_interval:
|
||||
self.qsfp_interval -= 1
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
return self.ready, self.phy_port_dict
|
||||
|
||||
def _get_port_eeprom_path(self, port_num, devid):
|
||||
eeprom_path = None
|
||||
|
Reference in New Issue
Block a user