Skip to content

Commit

Permalink
[nba610] LGTM and syntax/code fixes. Removed obsolete script.
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Sapronov <[email protected]>
  • Loading branch information
andrewsapronov committed Apr 22, 2022
1 parent b441d42 commit 6c4a85f
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 287 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def __install_bios_firmware(self, image_path):

if self.index == BIOS_ID_MAPPING_TABLE[temp_bios_id]:
# Write back current_bios no matter what
ret = self.__set_attr_value(BIOS_CS_PATH, str(current_bios_id))
self.__set_attr_value(BIOS_CS_PATH, str(current_bios_id))

return result

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def __get_attr_value(self, filepath):
except OSError as ex:
logger.log_error("Cannot open - {}: {}".format(filepath, repr(ex)))

return retval
##############################################
# Device methods
##############################################
Expand Down Expand Up @@ -88,7 +89,7 @@ def get_presence(self):

attr_rv = self.__get_attr_value(attr_path)
if attr_rv != 'ERR':
if attr_rv == attr_normal or attr_rv == attr_unpowered:
if attr_rv in (attr_normal, attr_unpowered):
presence = True
else:
raise SyntaxError
Expand Down Expand Up @@ -160,7 +161,6 @@ def get_voltage(self):
A float number, the output voltage in volts,
e.g. 12.1
"""
voltage_out = 0.0
attr_path = self.__psu_voltage_out_attr

attr_rv = self.__get_attr_value(attr_path)
Expand All @@ -178,7 +178,6 @@ def get_current(self):
Returns:
A float number, the electric current in amperes, e.g 15.4
"""
current_out = 0.0
attr_path = self.__psu_current_out_attr

attr_rv = self.__get_attr_value(attr_path)
Expand All @@ -196,7 +195,6 @@ def get_power(self):
Returns:
A float number, the power in watts, e.g. 302.6
"""
power_out = 0.0
attr_path = self.__psu_power_out_attr

attr_rv = self.__get_attr_value(attr_path)
Expand All @@ -219,7 +217,7 @@ def get_powergood_status(self):
voltage_out = self.get_voltage()

# Check the voltage out with 12V, plus or minus 20 percentage.
if (VOLTAGE_LOWER_LIMIT <= voltage_out and voltage_out <= VOLTAGE_UPPER_LIMIT):
if VOLTAGE_LOWER_LIMIT <= voltage_out <= VOLTAGE_UPPER_LIMIT:
powergood_status = True

return powergood_status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ class Sfp(SfpBase):
__hwsku = "aurora-610"

__port_to_i2c_mapping = {
0: 10, 1: 11, 2: 12, 3: 13, 4: 14, 5: 15, 6: 16, 7: 17,
8: 18, 9: 19, 10: 20, 11: 21, 12: 22, 13: 23, 14: 24, 15: 25,
0: 10, 1: 11, 2: 12, 3: 13, 4: 14, 5: 15, 6: 16, 7: 17,
8: 18, 9: 19, 10: 20, 11: 21, 12: 22, 13: 23, 14: 24, 15: 25,
16: 26, 17: 27, 18: 28, 19: 29, 20: 30, 21: 31, 22: 32, 23: 33,
24: 34, 25: 35, 26: 36, 27: 37, 28: 38, 29: 39, 30: 40, 31: 41,
32: 42, 33: 43, 34: 44, 35: 45, 36: 46, 37: 47, 38: 48, 39: 49,
Expand All @@ -88,14 +88,17 @@ def __init__(self, index):
def __get_attr_value(self, attr_path):

retval = 'ERR'
if (not os.path.isfile(attr_path)):
if not os.path.isfile(attr_path):
return retval

try:
with open(attr_path, 'r') as fd:
retval = fd.read()
except Exception as error:
logging.error("Unable to open file %s", attr_path)

except FileNotFoundError:
logging.error("File %s not found. Aborting", attr_path)
except OSError as ex:
logging.error("Cannot open - %s: %s", attr_path, repr(ex))

retval = retval.rstrip(' \t\n\r')
return retval
Expand All @@ -106,7 +109,7 @@ def __set_attr_value(self, attr_path, value):
with open(attr_path, 'r+') as reg_file:
reg_file.write(value)
except IOError as e:
logging.error("Error: unable to open file: '%s'" % str(e))
logging.error("Error: unable to open file: '%s'", str(e))
return False

return True
Expand All @@ -119,14 +122,13 @@ def __get_path_to_port_config_file(self):
docker_hwsku_path = '/usr/share/sonic/hwsku'

host_platform_path = "/".join([host_platform_root_path,
self.__platform])
self.__platform])
hwsku_path = "/".join([host_platform_path, self.__hwsku]
) if self.__is_host() else docker_hwsku_path

return "/".join([hwsku_path, "port_config.ini"])

def __read_eeprom_specific_bytes(self, offset, num_bytes):
sysfsfile_eeprom = None
eeprom_raw = []

for i in range(0, num_bytes):
Expand All @@ -140,21 +142,24 @@ def __read_eeprom_specific_bytes(self, offset, num_bytes):
raw_len = len(raw)
for n in range(0, raw_len):
eeprom_raw[n] = hex(ord(raw[n]))[2:].zfill(2)
except:
except FileNotFoundError:
logging.error("File %s not found. Aborting", sysfs_eeprom_path)
return None
except OSError as ex:
logging.error("Cannot open - %s: %s", sysfs_eeprom_path, repr(ex))
return None

return eeprom_raw

def __write_eeprom_specific_bytes(self, offset, buffer):
sysfs_eeprom_path = self.__eeprom_path
sysfsfile_eeprom = None

try:
with open(sysfs_eeprom_path, "r+b") as sysfsfile_eeprom:
sysfsfile_eeprom.seek(offset)
sysfsfile_eeprom.write(buffer[0])
except IOError as e:
logging.error("Error: unable to open file: '%s'" % str(e))
logging.error("Error: unable to open file: '%s'", str(e))
return False

return True
Expand Down Expand Up @@ -212,8 +217,8 @@ def get_presence(self):
attr_path = self.__presence_attr

attr_rv = self.__get_attr_value(attr_path)
if (attr_rv != 'ERR'):
if (int(attr_rv) == 0):
if attr_rv != 'ERR':
if int(attr_rv) == 0:
presence = True
else:
raise SyntaxError
Expand Down Expand Up @@ -305,23 +310,23 @@ def get_transceiver_info(self):
vendor_oui |1*255VCHAR |vendor OUI
========================================================================
"""
transceiver_info_dict_keys = ['type', 'vendor_rev',
'serial', 'manufacturer',
'model', 'connector',
'encoding', 'ext_identifier',
transceiver_info_dict_keys = ['type', 'vendor_rev',
'serial', 'manufacturer',
'model', 'connector',
'encoding', 'ext_identifier',
'ext_rateselect_compliance', 'cable_type',
'cable_length', 'nominal_bit_rate',
'specification_compliance', 'vendor_date',
'cable_length', 'nominal_bit_rate',
'specification_compliance', 'vendor_date',
'vendor_oui']

sfp_cable_length_tup = ('LengthSMFkm-UnitsOfKm', 'LengthSMF(UnitsOf100m)',
sfp_cable_length_tup = ('LengthSMFkm-UnitsOfKm', 'LengthSMF(UnitsOf100m)',
'Length50um(UnitsOf10m)', 'Length62.5um(UnitsOfm)',
'LengthCable(UnitsOfm)', 'LengthOM3(UnitsOf10m)')
'LengthCable(UnitsOfm)', 'LengthOM3(UnitsOf10m)')

sfp_compliance_code_tup = ('10GEthernetComplianceCode', 'InfinibandComplianceCode',
'ESCONComplianceCodes', 'SONETComplianceCodes',
'EthernetComplianceCodes', 'FibreChannelLinkLength',
'FibreChannelTechnology', 'SFP+CableTechnology',
sfp_compliance_code_tup = ('10GEthernetComplianceCode', 'InfinibandComplianceCode',
'ESCONComplianceCodes', 'SONETComplianceCodes',
'EthernetComplianceCodes', 'FibreChannelLinkLength',
'FibreChannelTechnology', 'SFP+CableTechnology',
'FibreChannelTransmissionMedia', 'FibreChannelSpeed')

sfpi_obj = sff8472InterfaceId()
Expand Down Expand Up @@ -429,16 +434,16 @@ def get_transceiver_bulk_status(self):
| |for example, tx2power stands for tx power of channel 2.
========================================================================
"""
transceiver_dom_info_dict_keys = ['rx_los', 'tx_fault',
transceiver_dom_info_dict_keys = ['rx_los', 'tx_fault',
'reset_status', 'power_lpmode',
'tx_disable', 'tx_disable_channel',
'temperature', 'voltage',
'rx1power', 'rx2power',
'rx3power', 'rx4power',
'tx1bias', 'tx2bias',
'tx3bias', 'tx4bias',
'tx1power', 'tx2power',
'tx3power', 'tx4power']
'tx_disable', 'tx_disable_channel',
'temperature', 'voltage',
'rx1power', 'rx2power',
'rx3power', 'rx4power',
'tx1bias', 'tx2bias',
'tx3bias', 'tx4bias',
'tx1power', 'tx2power',
'tx3power', 'tx4power']

sfpd_obj = sff8472Dom()

Expand Down Expand Up @@ -522,11 +527,11 @@ def get_transceiver_threshold_info(self):
txbiaslowwarning |FLOAT |Low Warning Threshold value of tx Bias Current in mA.
========================================================================
"""
transceiver_dom_threshold_info_dict_keys = ['temphighalarm', 'temphighwarning', 'templowalarm', 'templowwarning',
'vcchighalarm', 'vcchighwarning', 'vcclowalarm', 'vcclowwarning',
transceiver_dom_threshold_info_dict_keys = ['temphighalarm', 'temphighwarning', 'templowalarm', 'templowwarning',
'vcchighalarm', 'vcchighwarning', 'vcclowalarm', 'vcclowwarning',
'rxpowerhighalarm', 'rxpowerhighwarning', 'rxpowerlowalarm', 'rxpowerlowwarning',
'txpowerhighalarm', 'txpowerhighwarning', 'txpowerlowalarm', 'txpowerlowwarning',
'txbiashighalarm', 'txbiashighwarning', 'txbiaslowalarm', 'txbiaslowwarning']
'txbiashighalarm', 'txbiashighwarning', 'txbiaslowalarm', 'txbiaslowwarning']

sfpd_obj = sff8472Dom()

Expand Down Expand Up @@ -631,7 +636,6 @@ def get_tx_disable(self):
A Boolean, True if tx_disable is enabled, False if disabled
"""
tx_disable = False
tx_fault = False
status_control_raw = self.__read_eeprom_specific_bytes(
SFP_STATUS_CONTROL_OFFSET, SFP_STATUS_CONTROL_WIDTH)
if status_control_raw:
Expand Down Expand Up @@ -746,10 +750,7 @@ def get_tx_bias(self):
tx_bias_list = []
tx_bias = "N/A"
sfpd_obj = sff8472Dom()
eeprom_ifraw = self.__read_eeprom_specific_bytes(0, DOM_OFFSET)
sfpi_obj = sff8472InterfaceId(eeprom_ifraw)
offset = DOM_OFFSET
offset_xcvr = INFO_OFFSET

if not self.get_presence() or not sfpd_obj:
return []
Expand Down Expand Up @@ -781,10 +782,7 @@ def get_rx_power(self):
rx_power_list = []
rx_power = "N/A"
sfpd_obj = sff8472Dom()
eeprom_ifraw = self.__read_eeprom_specific_bytes(0, DOM_OFFSET)
sfpi_obj = sff8472InterfaceId(eeprom_ifraw)
offset = DOM_OFFSET
offset_xcvr = INFO_OFFSET

if not self.get_presence() or not sfpd_obj:
return []
Expand Down Expand Up @@ -816,10 +814,7 @@ def get_tx_power(self):
tx_power_list = []
tx_power = "N/A"
sfpd_obj = sff8472Dom()
eeprom_ifraw = self.__read_eeprom_specific_bytes(0, DOM_OFFSET)
sfpi_obj = sff8472InterfaceId(eeprom_ifraw)
offset = DOM_OFFSET
offset_xcvr = INFO_OFFSET

if not self.get_presence() or not sfpd_obj:
return []
Expand Down Expand Up @@ -860,7 +855,6 @@ def tx_disable(self, tx_disable):
Returns:
A boolean, True if tx_disable is set successfully, False if not
"""
sysfs_eeprom_path = self.__eeprom_path
status_control_raw = self.__read_eeprom_specific_bytes(
SFP_STATUS_CONTROL_OFFSET, SFP_STATUS_CONTROL_WIDTH)
if status_control_raw is not None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ def _get_wdt(self):
watchdog_device_path = "/dev/{}".format(wdt_main_dev_name)
try:
watchdog = os.open(watchdog_device_path, os.O_RDWR)
except:
except (FileNotFoundError, IOError, OSError):
watchdog = None
except SystemExit:
pass

return watchdog, wdt_main_dev_name

Expand Down
Loading

0 comments on commit 6c4a85f

Please sign in to comment.