Skip to content

Commit

Permalink
Pep 8 compliance, code cleanup (sonic-net#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
eiendragon authored and lguohan committed Oct 12, 2018
1 parent 5d32cbb commit 3b1f0ef
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions sonic_sfp/sfputilbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
XCVR_DOM_CAPABILITY_OFFSET = 92
XCVR_DOM_CAPABILITY_WIDTH = 1

#definitions of the offset and width for values in DOM info eeprom
# definitions of the offset and width for values in DOM info eeprom
QSFP_DOM_REV_OFFSET = 1
QSFP_DOM_REV_WIDTH = 1
QSFP_TEMPE_OFFSET = 22
Expand All @@ -52,6 +52,7 @@
SFP_CHANNL_MON_OFFSET = 100
SFP_CHANNL_MON_WIDTH = 6


class SfpUtilError(Exception):
"""Base class for exceptions in this module."""
pass
Expand Down Expand Up @@ -290,10 +291,8 @@ def _read_eeprom_devid(self, port_num, devid, offset, num_bytes = 256):
return eeprom_raw

def _is_valid_port(self, port_num):
if port_num >= self.port_start and port_num <= self.port_end:
return True

return False
return port_num == self.port_end

def read_porttab_mappings(self, porttabfile):
logical = []
Expand Down Expand Up @@ -328,7 +327,7 @@ def read_porttab_mappings(self, porttabfile):
continue

# Parsing logic for 'port_config.ini' file
if (parse_fmt_port_config_ini):
if parse_fmt_port_config_ini:
# bcm_port is not explicitly listed in port_config.ini format
# Currently we assume ports are listed in numerical order according to bcm_port
# so we use the port's position in the file (zero-based) as bcm_port
Expand All @@ -350,7 +349,7 @@ def read_porttab_mappings(self, porttabfile):
fp_port_index = portname.split("Ethernet").pop()
fp_port_index = int(fp_port_index.split("s").pop(0))/4

if ((len(self.sfp_ports) > 0) and (fp_port_index not in self.sfp_ports)):
if (len(self.sfp_ports) > 0) and (fp_port_index not in self.sfp_ports):
continue

if first == 1:
Expand Down Expand Up @@ -435,7 +434,7 @@ def read_phytab_mappings(self, phytabfile):
# Some platforms have a list of physical sfp ports
# defined. If such a list exists, check to see if this
# port is blacklisted
if ((len(self.sfp_ports) > 0) and (physical_port not in self.sfp_ports)):
if (len(self.sfp_ports) > 0) and (physical_port not in self.sfp_ports):
continue

if logical_port not in logical:
Expand All @@ -452,13 +451,13 @@ def read_phytab_mappings(self, phytabfile):
# Generate the next physical port number in the series
# and append it to the list
tmp_physical_port_list = phytab_mappings[logical_port]['physicalport']
if (type == "40G/4" and physical_port in tmp_physical_port_list):
if type == "40G/4" and physical_port in tmp_physical_port_list:
# Aha!...ganged port
new_physical_port = tmp_physical_port_list[-1] + 1
else:
new_physical_port = physical_port

if (new_physical_port not in phytab_mappings[logical_port]['physicalport']):
if new_physical_port not in phytab_mappings[logical_port]['physicalport']:
phytab_mappings[logical_port]['physicalport'].append(new_physical_port)
phytab_mappings[logical_port]['phyid'].append(phy_addr)
phytab_mappings[logical_port]['bcmport'] = bcm_port
Expand Down Expand Up @@ -760,8 +759,9 @@ def get_transceiver_dom_info_dict(self, port_num):
dom_channel_monitor_data = {}
qsfp_dom_rev = qsfp_dom_rev_data['data']['dom_rev']['value']
qsfp_tx_power_support = qspf_dom_capability_data['data']['Tx_power_support']['value']
if (qsfp_dom_rev[0:8] != 'SFF-8636' or (qsfp_dom_rev[0:8] == 'SFF-8636' and qsfp_tx_power_support != 'on')):
dom_channel_monitor_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + QSFP_CHANNL_MON_OFFSET), QSFP_CHANNL_MON_WIDTH)
if qsfp_dom_rev[0:8] != 'SFF-8636' or (qsfp_dom_rev[0:8] == 'SFF-8636' and qsfp_tx_power_support != 'on'):
dom_channel_monitor_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom,
(offset + QSFP_CHANNL_MON_OFFSET), QSFP_CHANNL_MON_WIDTH)
if dom_channel_monitor_raw is not None:
dom_channel_monitor_data = sfpd_obj.parse_channel_monitor_params(dom_channel_monitor_raw, 0)
else:
Expand All @@ -772,9 +772,11 @@ def get_transceiver_dom_info_dict(self, port_num):
transceiver_dom_info_dict['tx3power'] = 'N/A'
transceiver_dom_info_dict['tx4power'] = 'N/A'
else:
dom_channel_monitor_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + QSFP_CHANNL_MON_OFFSET), QSFP_CHANNL_MON_WITH_TX_POWER_WIDTH)
dom_channel_monitor_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom,
(offset + QSFP_CHANNL_MON_OFFSET), QSFP_CHANNL_MON_WITH_TX_POWER_WIDTH)
if dom_channel_monitor_raw is not None:
dom_channel_monitor_data = sfpd_obj.parse_channel_monitor_params_with_tx_power(dom_channel_monitor_raw, 0)
dom_channel_monitor_data = \
sfpd_obj.parse_channel_monitor_params_with_tx_power(dom_channel_monitor_raw, 0)
else:
return None

Expand Down Expand Up @@ -816,19 +818,22 @@ def get_transceiver_dom_info_dict(self, port_num):
if sfpd_obj is None:
return None

dom_temperature_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_TEMPE_OFFSET), SFP_TEMPE_WIDTH)
dom_temperature_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom,
(offset + SFP_TEMPE_OFFSET), SFP_TEMPE_WIDTH)
if dom_temperature_raw is not None:
dom_temperature_data = sfpd_obj.parse_temperature(dom_temperature_raw, 0)
else:
return None

dom_voltage_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_VLOT_OFFSET), SFP_VOLT_WIDTH)
dom_voltage_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom,
(offset + SFP_VLOT_OFFSET), SFP_VOLT_WIDTH)
if dom_voltage_raw is not None:
dom_voltage_data = sfpd_obj.parse_voltage(dom_voltage_raw, 0)
else:
return None

dom_channel_monitor_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_CHANNL_MON_OFFSET), SFP_CHANNL_MON_WIDTH)
dom_channel_monitor_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom,
(offset + SFP_CHANNL_MON_OFFSET), SFP_CHANNL_MON_WIDTH)
if dom_channel_monitor_raw is not None:
dom_channel_monitor_data = sfpd_obj.parse_channel_monitor_params(dom_channel_monitor_raw, 0)
else:
Expand Down

0 comments on commit 3b1f0ef

Please sign in to comment.