diff --git a/device/accton/x86_64-accton_as4630_54pe-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as4630_54pe-r0/plugins/eeprom.py index 0d7def70fdc0..3d0ff81ca574 100755 --- a/device/accton/x86_64-accton_as4630_54pe-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as4630_54pe-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,11 +8,13 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/accton/x86_64-accton_as4630_54pe-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as4630_54pe-r0/plugins/psuutil.py index a646981334e6..92e08e23afd6 100755 --- a/device/accton/x86_64-accton_as4630_54pe-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as4630_54pe-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Accton # @@ -13,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/accton/x86_64-accton_as4630_54pe-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as4630_54pe-r0/plugins/sfputil.py index 33a2630f1d71..fd660ccdc245 100755 --- a/device/accton/x86_64-accton_as4630_54pe-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as4630_54pe-r0/plugins/sfputil.py @@ -15,6 +15,7 @@ SFP_STATUS_INSERTED = '1' SFP_STATUS_REMOVED = '0' + class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" @@ -31,13 +32,13 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} _port_to_i2c_mapping = { - 49: [18], - 50: [19], - 51: [20], - 52: [21], - 53: [22], - 54: [23], - } + 49: [18], + 50: [19], + 51: [20], + 52: [21], + 53: [22], + 54: [23], + } @property def port_start(self): @@ -49,7 +50,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(self.PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -70,15 +71,15 @@ def get_presence(self, port_num): present_path = self.BASE_CPLD_PATH + "module_present_" + str(port_num) self.__port_to_is_present = present_path - content="0" + content = "0" try: val_file = open(self.__port_to_is_present) content = val_file.readline().rstrip() val_file.close() except IOError as e: - print "Error: unable to access file: %s" % str(e) + print("Error: unable to access file: %s" % str(e)) return False - + if content == "1": return True @@ -108,7 +109,7 @@ def get_low_power_mode(self, port_num): return False except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False finally: if eeprom is not None: @@ -123,7 +124,7 @@ def set_low_power_mode(self, port_num, lpmode): try: eeprom = None if not self.get_presence(port_num): - return False # Port is not present, unable to set the eeprom + return False # Port is not present, unable to set the eeprom # Fill in write buffer # 0x3:Low Power Mode, 0x1:High Power Mode @@ -138,7 +139,7 @@ def set_low_power_mode(self, port_num, lpmode): eeprom.write(buffer[0]) return True except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False finally: if eeprom is not None: @@ -153,21 +154,22 @@ def _get_presence_bitmap(self): bits = [] for x in range(self.port_start, self.port_end+1): - bits.append(str(int(self.get_presence(x)))) + bits.append(str(int(self.get_presence(x)))) rev = "".join(bits[::-1]) - return int(rev,2) + return int(rev, 2) + + data = {'present': 0} - data = {'present':0} def get_transceiver_change_event(self, timeout=0): port_dict = {} if timeout == 0: - cd_ms = sys.maxint + cd_ms = sys.maxsize else: cd_ms = timeout - #poll per second + # poll per second while cd_ms > 0: reg_value = self._get_presence_bitmap changed_ports = self.data['present'] ^ reg_value @@ -177,7 +179,7 @@ def get_transceiver_change_event(self, timeout=0): cd_ms = cd_ms - 1000 if changed_ports != 0: - for port in range (self.port_start, self.port_end+1): + for port in range(self.port_start, self.port_end+1): # Mask off the bit corresponding to our port mask = (1 << (port - self.port_start)) if changed_ports & mask: @@ -192,4 +194,3 @@ def get_transceiver_change_event(self, timeout=0): else: return True, {} return False, {} - diff --git a/device/accton/x86_64-accton_as5712_54x-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as5712_54x-r0/plugins/eeprom.py index 7681caafeef4..951384d5e37d 100644 --- a/device/accton/x86_64-accton_as5712_54x-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as5712_54x-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,14 +8,16 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom" - #Two i2c buses might get flipped order, check them both. + # Two i2c buses might get flipped order, check them both. if not os.path.exists(self.eeprom_path): self.eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/accton/x86_64-accton_as5712_54x-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as5712_54x-r0/plugins/psuutil.py index 841070637b3e..a07aebc96312 100755 --- a/device/accton/x86_64-accton_as5712_54x-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as5712_54x-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Accton # @@ -13,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/accton/x86_64-accton_as5712_54x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as5712_54x-r0/plugins/sfputil.py index b1727f0a79b6..5002d842a15f 100755 --- a/device/accton/x86_64-accton_as5712_54x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as5712_54x-r0/plugins/sfputil.py @@ -12,7 +12,7 @@ raise ImportError("%s - required module not found" % str(e)) -#from xcvrd +# from xcvrd SFP_STATUS_INSERTED = '1' SFP_STATUS_REMOVED = '0' @@ -32,7 +32,7 @@ class SfpUtil(SfpUtilBase): BASE_CPLD3_PATH = "/sys/bus/i2c/devices/{0}-0062/" I2C_BUS_ORDER = -1 - #The sidebands of QSFP is different. + # The sidebands of QSFP is different. qsfp_sb_map = [0, 2, 4, 1, 3, 5] _port_to_is_present = {} @@ -40,61 +40,61 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} _port_to_i2c_mapping = { - 1: [1, 2], - 2: [2, 3], - 3: [3, 4], - 4: [4, 5], - 5: [5, 6], - 6: [6, 7], - 7: [7, 8], - 8: [8, 9], - 9: [9, 10], - 10: [10, 11], - 11: [11, 12], - 12: [12, 13], - 13: [13, 14], - 14: [14, 15], - 15: [15, 16], - 16: [16, 17], - 17: [17, 18], - 18: [18, 19], - 19: [19, 20], - 20: [20, 21], - 21: [21, 22], - 22: [22, 23], - 23: [23, 24], - 24: [24, 25], - 25: [25, 26], - 26: [26, 27], - 27: [27, 28], - 28: [28, 29], - 29: [29, 30], - 30: [30, 31], - 31: [31, 32], - 32: [32, 33], - 33: [33, 34], - 34: [34, 35], - 35: [35, 36], - 36: [36, 37], - 37: [37, 38], - 38: [38, 39], - 39: [39, 40], - 40: [40, 41], - 41: [41, 42], - 42: [42, 43], - 43: [43, 44], - 44: [44, 45], - 45: [45, 46], - 46: [46, 47], - 47: [47, 48], - 48: [48, 49], - 49: [49, 50],#QSFP49 - 50: [51, 52], - 51: [53, 54], - 52: [50, 51], - 53: [52, 53], - 54: [54, 55],#QSFP54 - } + 1: [1, 2], + 2: [2, 3], + 3: [3, 4], + 4: [4, 5], + 5: [5, 6], + 6: [6, 7], + 7: [7, 8], + 8: [8, 9], + 9: [9, 10], + 10: [10, 11], + 11: [11, 12], + 12: [12, 13], + 13: [13, 14], + 14: [14, 15], + 15: [15, 16], + 16: [16, 17], + 17: [17, 18], + 18: [18, 19], + 19: [19, 20], + 20: [20, 21], + 21: [21, 22], + 22: [22, 23], + 23: [23, 24], + 24: [24, 25], + 25: [25, 26], + 26: [26, 27], + 27: [27, 28], + 28: [28, 29], + 29: [29, 30], + 30: [30, 31], + 31: [31, 32], + 32: [32, 33], + 33: [33, 34], + 34: [34, 35], + 35: [35, 36], + 36: [36, 37], + 37: [37, 38], + 38: [38, 39], + 39: [39, 40], + 40: [40, 41], + 41: [41, 42], + 42: [42, 43], + 43: [43, 44], + 44: [44, 45], + 45: [45, 46], + 46: [46, 47], + 47: [47, 48], + 48: [48, 49], + 49: [49, 50], # QSFP49 + 50: [51, 52], + 51: [53, 54], + 52: [50, 51], + 53: [52, 53], + 54: [54, 55], # QSFP54 + } @property def port_start(self): @@ -111,16 +111,16 @@ def qsfp_port_start(self): @property def qsfp_port_end(self): return self.QSFP_PORT_END - + @property def qsfp_ports(self): - return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): return self._port_to_eeprom_mapping - #Two i2c buses might get flipped order, check them both. + # Two i2c buses might get flipped order, check them both. def update_i2c_order(self): if self.I2C_BUS_ORDER < 0: eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom" @@ -129,7 +129,7 @@ def update_i2c_order(self): eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom" if os.path.exists(eeprom_path): self.I2C_BUS_ORDER = 1 - return self.I2C_BUS_ORDER + return self.I2C_BUS_ORDER def get_presence(self, port_num): # Check for invalid port_num @@ -144,15 +144,15 @@ def get_presence(self, port_num): present_path = present_path + "module_present_" + str(port_num) self.__port_to_is_present = present_path - content="0" + content = "0" try: val_file = open(self.__port_to_is_present) content = val_file.readline().rstrip() val_file.close() except IOError as e: - print "Error: unable to access file: %s" % str(e) + print("Error: unable to access file: %s" % str(e)) return False - + if content == "1": return True @@ -167,22 +167,22 @@ def qsfp_sb_remap(self, port_num): def get_low_power_mode_cpld(self, port_num): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False - + order = self.update_i2c_order() lp_mode_path = self.BASE_CPLD3_PATH.format(order) - lp_mode_path = lp_mode_path + "module_lp_mode_" + lp_mode_path = lp_mode_path + "module_lp_mode_" q = self.qsfp_sb_remap(port_num) lp_mode_path = lp_mode_path + str(q) - - content="0" + + content = "0" try: val_file = open(lp_mode_path) content = val_file.readline().rstrip() val_file.close() except IOError as e: - print "Error: unable to access file: %s" % str(e) + print("Error: unable to access file: %s" % str(e)) return False - + if content == "1": return True @@ -191,7 +191,7 @@ def get_low_power_mode_cpld(self, port_num): def get_low_power_mode(self, port_num): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False - + if not self.get_presence(port_num): return self.get_low_power_mode_cpld(port_num) @@ -202,15 +202,15 @@ def get_low_power_mode(self, port_num): eeprom.seek(93) lpmode = ord(eeprom.read(1)) - if not (lpmode & 0x1): # 'Power override' bit is 0 + if not (lpmode & 0x1): # 'Power override' bit is 0 return self.get_low_power_mode_cpld(port_num) else: if ((lpmode & 0x2) == 0x2): - return True # Low Power Mode if "Power set" bit is 1 + return True # Low Power Mode if "Power set" bit is 1 else: - return False # High Power Mode if "Power set" bit is 0 + return False # High Power Mode if "Power set" bit is 0 except IOError as err: - print "Error: unable to open file: %s" % str(err) + print("Error: unable to open file: %s" % str(err)) return False finally: if eeprom is not None: @@ -225,10 +225,10 @@ def set_low_power_mode(self, port_num, lpmode): eeprom = None if not self.get_presence(port_num): - return False # Port is not present, unable to set the eeprom + return False # Port is not present, unable to set the eeprom # Fill in write buffer - regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode + regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode buffer = create_string_buffer(1) buffer[0] = chr(regval) @@ -238,7 +238,7 @@ def set_low_power_mode(self, port_num, lpmode): eeprom.write(buffer[0]) return True except IOError as err: - print "Error: unable to open file: %s" % str(err) + print("Error: unable to open file: %s" % str(err)) return False finally: if eeprom is not None: @@ -248,19 +248,19 @@ def set_low_power_mode(self, port_num, lpmode): def reset(self, port_num): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False - + order = self.update_i2c_order() lp_mode_path = self.BASE_CPLD3_PATH.format(order) - mod_rst_path = lp_mode_path + "module_reset_" + mod_rst_path = lp_mode_path + "module_reset_" q = self.qsfp_sb_remap(port_num) mod_rst_path = mod_rst_path + str(q) try: reg_file = open(mod_rst_path, 'r+', buffering=0) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False - #toggle reset + # toggle reset reg_file.seek(0) reg_file.write('0') time.sleep(1) @@ -271,31 +271,31 @@ def reset(self, port_num): @property def _get_presence_bitmap(self): - nodes = [] + nodes = [] order = self.update_i2c_order() - + present_path = self.BASE_CPLD2_PATH.format(order) nodes.append(present_path + "module_present_all") present_path = self.BASE_CPLD3_PATH.format(order) nodes.append(present_path + "module_present_all") - bitmap = "" - for node in nodes: + bitmap = "" + for node in nodes: try: reg_file = open(node) - + except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False bitmap += reg_file.readline().rstrip() + " " reg_file.close() rev = bitmap.split(" ") rev = "".join(rev[::-1]) - return int(rev,16) - + return int(rev, 16) + + data = {'valid': 0, 'last': 0, 'present': 0} - data = {'valid':0, 'last':0, 'present':0} def get_transceiver_change_event(self, timeout=2000): now = time.time() port_dict = {} @@ -303,8 +303,7 @@ def get_transceiver_change_event(self, timeout=2000): if timeout < 1000: timeout = 1000 - timeout = (timeout) / float(1000) # Convert to secs - + timeout = (timeout) / float(1000) # Convert to secs if now < (self.data['last'] + timeout) and self.data['valid']: return True, {} @@ -312,7 +311,7 @@ def get_transceiver_change_event(self, timeout=2000): reg_value = self._get_presence_bitmap changed_ports = self.data['present'] ^ reg_value if changed_ports: - for port in range (self.port_start, self.port_end+1): + for port in range(self.port_start, self.port_end+1): # Mask off the bit corresponding to our port fp_port = self._port_to_i2c_mapping[port][0] mask = (1 << (fp_port - 1)) @@ -323,7 +322,7 @@ def get_transceiver_change_event(self, timeout=2000): else: port_dict[port] = SFP_STATUS_INSERTED - # Update cache + # Update cache self.data['present'] = reg_value self.data['last'] = now self.data['valid'] = 1 @@ -333,17 +332,12 @@ def get_transceiver_change_event(self, timeout=2000): return True, {} return False, {} - def __init__(self): eeprom_path = self.BASE_OOM_PATH + "eeprom" for x in range(self.port_start, self.port_end+1): self.port_to_eeprom_mapping[x] = eeprom_path.format( self._port_to_i2c_mapping[x][1] - ) + ) SfpUtilBase.__init__(self) - - - - diff --git a/device/accton/x86_64-accton_as5812_54t-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as5812_54t-r0/plugins/eeprom.py index 7681caafeef4..951384d5e37d 100644 --- a/device/accton/x86_64-accton_as5812_54t-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as5812_54t-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,14 +8,16 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom" - #Two i2c buses might get flipped order, check them both. + # Two i2c buses might get flipped order, check them both. if not os.path.exists(self.eeprom_path): self.eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/accton/x86_64-accton_as5812_54t-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as5812_54t-r0/plugins/psuutil.py index cfcd62e5828e..b7a0a2fd66e3 100755 --- a/device/accton/x86_64-accton_as5812_54t-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as5812_54t-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Accton # @@ -13,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/accton/x86_64-accton_as5812_54t-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as5812_54t-r0/plugins/sfputil.py index 44399d1e64ee..38beeaf6ca5e 100755 --- a/device/accton/x86_64-accton_as5812_54t-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as5812_54t-r0/plugins/sfputil.py @@ -10,7 +10,7 @@ except ImportError as e: raise ImportError("%s - required module not found" % str(e)) -#from xcvrd +# from xcvrd SFP_STATUS_INSERTED = '1' SFP_STATUS_REMOVED = '0' @@ -29,9 +29,9 @@ class SfpUtil(SfpUtilBase): BASE_CPLD_PATH = "/sys/bus/i2c/devices/{0}-0060/" I2C_BUS_ORDER = -1 - #The sidebands of QSFP is different. - #present is in-order. - #But lp_mode and reset are not. + # The sidebands of QSFP is different. + # present is in-order. + # But lp_mode and reset are not. qsfp_sb_map = [0, 2, 4, 1, 3, 5] _port_to_is_present = {} @@ -39,13 +39,13 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} _port_to_i2c_mapping = { - 49: [1,4],#QSFP_start - 50: [2,6], - 51: [3,3], - 52: [4,5], - 53: [5,7], - 54: [6,2], - } + 49: [1, 4], # QSFP_start + 50: [2, 6], + 51: [3, 3], + 52: [4, 5], + 53: [5, 7], + 54: [6, 2], + } @property def port_start(self): @@ -62,10 +62,10 @@ def qsfp_port_start(self): @property def qsfp_port_end(self): return self.QSFP_PORT_END - + @property def qsfp_ports(self): - return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -77,10 +77,10 @@ def __init__(self): for x in range(self.port_start, self.port_end+1): self.port_to_eeprom_mapping[x] = eeprom_path.format( self._port_to_i2c_mapping[x][1] - ) + ) SfpUtilBase.__init__(self) - #Two i2c buses might get flipped order, check them both. + # Two i2c buses might get flipped order, check them both. def update_i2c_order(self): if self.I2C_BUS_ORDER < 0: eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom" @@ -89,7 +89,7 @@ def update_i2c_order(self): eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom" if os.path.exists(eeprom_path): self.I2C_BUS_ORDER = 1 - return self.I2C_BUS_ORDER + return self.I2C_BUS_ORDER def get_presence(self, port_num): # Check for invalid port_num @@ -98,18 +98,18 @@ def get_presence(self, port_num): order = self.update_i2c_order() present_path = self.BASE_CPLD_PATH.format(order) - present_path = present_path + "module_present_" + str(port_num) + present_path = present_path + "module_present_" + str(port_num) self.__port_to_is_present = present_path - content="0" + content = "0" try: val_file = open(self.__port_to_is_present) content = val_file.readline().rstrip() val_file.close() except IOError as e: - print "Error: unable to access file: %s" % str(e) + print("Error: unable to access file: %s" % str(e)) return False - + if content == "1": return True @@ -118,21 +118,21 @@ def get_presence(self, port_num): def get_low_power_mode_cpld(self, port_num): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False - + order = self.update_i2c_order() lp_mode_path = self.BASE_CPLD_PATH.format(order) - lp_mode_path = lp_mode_path + "module_lp_mode_" + lp_mode_path = lp_mode_path + "module_lp_mode_" lp_mode_path = lp_mode_path + str(port_num) - - content="0" + + content = "0" try: val_file = open(lp_mode_path) content = val_file.readline().rstrip() val_file.close() except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False - + if content == "1": return True @@ -141,7 +141,7 @@ def get_low_power_mode_cpld(self, port_num): def get_low_power_mode(self, port_num): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False - + if not self.get_presence(port_num): return self.get_low_power_mode_cpld(port_num) @@ -151,15 +151,15 @@ def get_low_power_mode(self, port_num): eeprom.seek(93) lpmode = ord(eeprom.read(1)) - if not (lpmode & 0x1): # 'Power override' bit is 0 + if not (lpmode & 0x1): # 'Power override' bit is 0 return self.get_low_power_mode_cpld(port_num) else: if ((lpmode & 0x2) == 0x2): - return True # Low Power Mode if "Power set" bit is 1 + return True # Low Power Mode if "Power set" bit is 1 else: - return False # High Power Mode if "Power set" bit is 0 + return False # High Power Mode if "Power set" bit is 0 except IOError as err: - print "Error: unable to open file: %s" % str(err) + print("Error: unable to open file: %s" % str(err)) return False finally: if eeprom is not None: @@ -174,10 +174,10 @@ def set_low_power_mode(self, port_num, lpmode): eeprom = None if not self.get_presence(port_num): - return False # Port is not present, unable to set the eeprom + return False # Port is not present, unable to set the eeprom # Fill in write buffer - regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode + regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode buffer = create_string_buffer(1) buffer[0] = chr(regval) @@ -187,7 +187,7 @@ def set_low_power_mode(self, port_num, lpmode): eeprom.write(buffer[0]) return True except IOError as err: - print "Error: unable to open file: %s" % str(err) + print("Error: unable to open file: %s" % str(err)) return False finally: if eeprom is not None: @@ -197,20 +197,20 @@ def set_low_power_mode(self, port_num, lpmode): def reset(self, port_num): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False - + order = self.update_i2c_order() lp_mode_path = self.BASE_CPLD_PATH.format(order) - mod_rst_path = lp_mode_path + "module_reset_" + mod_rst_path = lp_mode_path + "module_reset_" mod_rst_path = mod_rst_path + str(port_num) print(mod_rst_path) - + try: reg_file = open(mod_rst_path, 'r+', buffering=0) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False - #toggle reset + # toggle reset reg_file.seek(0) reg_file.write('1') time.sleep(1) @@ -221,39 +221,39 @@ def reset(self, port_num): @property def _get_presence_bitmap(self): - nodes = [] + nodes = [] order = self.update_i2c_order() - + present_path = self.BASE_CPLD_PATH.format(order) nodes.append(present_path + "module_present_all") - bitmap = "" - for node in nodes: + bitmap = "" + for node in nodes: try: reg_file = open(node) - + except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False bitmap += reg_file.readline().rstrip() + " " reg_file.close() rev = bitmap.split(" ") rev = "".join(rev[::-1]) - return int(rev,16) - + return int(rev, 16) + + data = {'present': 0} - data = {'present':0} def get_transceiver_change_event(self, timeout=2000): port_dict = {} port = 0 if timeout == 0: - cd_ms = sys.maxint + cd_ms = sys.maxsize else: cd_ms = timeout - #poll per second + # poll per second while cd_ms > 0: reg_value = self._get_presence_bitmap changed_ports = self.data['present'] ^ reg_value @@ -263,7 +263,7 @@ def get_transceiver_change_event(self, timeout=2000): cd_ms = cd_ms - 1000 if changed_ports: - for port in range (self.port_start, self.port_end+1): + for port in range(self.port_start, self.port_end+1): # Mask off the bit corresponding to our port fp_port = self._port_to_i2c_mapping[port][0] mask = (1 << (fp_port - 1)) @@ -274,7 +274,7 @@ def get_transceiver_change_event(self, timeout=2000): else: port_dict[port] = SFP_STATUS_INSERTED - # Update cache + # Update cache self.data['present'] = reg_value return True, port_dict diff --git a/device/accton/x86_64-accton_as5812_54x-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as5812_54x-r0/plugins/eeprom.py index 7681caafeef4..951384d5e37d 100644 --- a/device/accton/x86_64-accton_as5812_54x-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as5812_54x-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,14 +8,16 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom" - #Two i2c buses might get flipped order, check them both. + # Two i2c buses might get flipped order, check them both. if not os.path.exists(self.eeprom_path): self.eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/accton/x86_64-accton_as5812_54x-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as5812_54x-r0/plugins/psuutil.py index 841070637b3e..a07aebc96312 100755 --- a/device/accton/x86_64-accton_as5812_54x-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as5812_54x-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Accton # @@ -13,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/accton/x86_64-accton_as5812_54x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as5812_54x-r0/plugins/sfputil.py index 008b2fdd9cf5..be301aea493b 100755 --- a/device/accton/x86_64-accton_as5812_54x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as5812_54x-r0/plugins/sfputil.py @@ -10,7 +10,7 @@ except ImportError as e: raise ImportError("%s - required module not found" % str(e)) -#from xcvrd +# from xcvrd SFP_STATUS_INSERTED = '1' SFP_STATUS_REMOVED = '0' @@ -30,9 +30,9 @@ class SfpUtil(SfpUtilBase): BASE_CPLD3_PATH = "/sys/bus/i2c/devices/{0}-0062/" I2C_BUS_ORDER = -1 - #The sidebands of QSFP is different. - #present is in-order. - #But lp_mode and reset are not. + # The sidebands of QSFP is different. + # present is in-order. + # But lp_mode and reset are not. qsfp_sb_map = [0, 2, 4, 1, 3, 5] _port_to_is_present = {} @@ -40,61 +40,61 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} _port_to_i2c_mapping = { - 1: [1, 2], - 2: [2, 3], - 3: [3, 4], - 4: [4, 5], - 5: [5, 6], - 6: [6, 7], - 7: [7, 8], - 8: [8, 9], - 9: [9, 10], - 10: [10,11], - 11: [11,12], - 12: [12,13], - 13: [13,14], - 14: [14,15], - 15: [15,16], - 16: [16,17], - 17: [17,18], - 18: [18,19], - 19: [19,20], - 20: [20,21], - 21: [21,22], - 22: [22,23], - 23: [23,24], - 24: [24,25], - 25: [25,26], - 26: [26,27], - 27: [27,28], - 28: [28,29], - 29: [29,30], - 30: [30,31], - 31: [31,32], - 32: [32,33], - 33: [33,34], - 34: [34,35], - 35: [35,36], - 36: [36,37], - 37: [37,38], - 38: [38,39], - 39: [39,40], - 40: [40,41], - 41: [41,42], - 42: [42,43], - 43: [43,44], - 44: [44,45], - 45: [45,46], - 46: [46,47], - 47: [47,48], - 48: [48,49], - 49: [49,50],#QSFP_start - 50: [51,52], - 51: [53,54], - 52: [50,51], - 53: [52,53], - 54: [54,55], - } + 1: [1, 2], + 2: [2, 3], + 3: [3, 4], + 4: [4, 5], + 5: [5, 6], + 6: [6, 7], + 7: [7, 8], + 8: [8, 9], + 9: [9, 10], + 10: [10, 11], + 11: [11, 12], + 12: [12, 13], + 13: [13, 14], + 14: [14, 15], + 15: [15, 16], + 16: [16, 17], + 17: [17, 18], + 18: [18, 19], + 19: [19, 20], + 20: [20, 21], + 21: [21, 22], + 22: [22, 23], + 23: [23, 24], + 24: [24, 25], + 25: [25, 26], + 26: [26, 27], + 27: [27, 28], + 28: [28, 29], + 29: [29, 30], + 30: [30, 31], + 31: [31, 32], + 32: [32, 33], + 33: [33, 34], + 34: [34, 35], + 35: [35, 36], + 36: [36, 37], + 37: [37, 38], + 38: [38, 39], + 39: [39, 40], + 40: [40, 41], + 41: [41, 42], + 42: [42, 43], + 43: [43, 44], + 44: [44, 45], + 45: [45, 46], + 46: [46, 47], + 47: [47, 48], + 48: [48, 49], + 49: [49, 50], # QSFP_start + 50: [51, 52], + 51: [53, 54], + 52: [50, 51], + 53: [52, 53], + 54: [54, 55], + } @property def port_start(self): @@ -111,10 +111,10 @@ def qsfp_port_start(self): @property def qsfp_port_end(self): return self.QSFP_PORT_END - + @property def qsfp_ports(self): - return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -126,10 +126,10 @@ def __init__(self): for x in range(self.port_start, self.port_end+1): self.port_to_eeprom_mapping[x] = eeprom_path.format( self._port_to_i2c_mapping[x][1] - ) + ) SfpUtilBase.__init__(self) - #Two i2c buses might get flipped order, check them both. + # Two i2c buses might get flipped order, check them both. def update_i2c_order(self): if self.I2C_BUS_ORDER < 0: eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom" @@ -138,7 +138,7 @@ def update_i2c_order(self): eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom" if os.path.exists(eeprom_path): self.I2C_BUS_ORDER = 1 - return self.I2C_BUS_ORDER + return self.I2C_BUS_ORDER def get_presence(self, port_num): # Check for invalid port_num @@ -147,22 +147,22 @@ def get_presence(self, port_num): order = self.update_i2c_order() if port_num <= 24: - present_path = self.BASE_CPLD2_PATH.format(order) + present_path = self.BASE_CPLD2_PATH.format(order) else: present_path = self.BASE_CPLD3_PATH.format(order) - - present_path = present_path + "module_present_" + str(port_num) + + present_path = present_path + "module_present_" + str(port_num) self.__port_to_is_present = present_path - content="0" + content = "0" try: val_file = open(self.__port_to_is_present) content = val_file.readline().rstrip() val_file.close() except IOError as e: - print "Error: unable to access file: %s" % str(e) + print("Error: unable to access file: %s" % str(e)) return False - + if content == "1": return True @@ -177,22 +177,22 @@ def qsfp_sb_remap(self, port_num): def get_low_power_mode_cpld(self, port_num): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False - + order = self.update_i2c_order() lp_mode_path = self.BASE_CPLD3_PATH.format(order) - lp_mode_path = lp_mode_path + "module_lp_mode_" + lp_mode_path = lp_mode_path + "module_lp_mode_" q = self.qsfp_sb_remap(port_num) lp_mode_path = lp_mode_path + str(q) - + content = "0" try: val_file = open(lp_mode_path) content = val_file.readline().rstrip() val_file.close() except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False - + if content == "1": return True @@ -201,7 +201,7 @@ def get_low_power_mode_cpld(self, port_num): def get_low_power_mode(self, port_num): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False - + if not self.get_presence(port_num): return self.get_low_power_mode_cpld(port_num) @@ -212,15 +212,15 @@ def get_low_power_mode(self, port_num): eeprom.seek(93) lpmode = ord(eeprom.read(1)) - if not (lpmode & 0x1): # 'Power override' bit is 0 + if not (lpmode & 0x1): # 'Power override' bit is 0 return self.get_low_power_mode_cpld(port_num) else: if ((lpmode & 0x2) == 0x2): - return True # Low Power Mode if "Power set" bit is 1 + return True # Low Power Mode if "Power set" bit is 1 else: - return False # High Power Mode if "Power set" bit is 0 + return False # High Power Mode if "Power set" bit is 0 except IOError as err: - print "Error: unable to open file: %s" % str(err) + print("Error: unable to open file: %s" % str(err)) return False finally: if eeprom is not None: @@ -235,10 +235,10 @@ def set_low_power_mode(self, port_num, lpmode): eeprom = None if not self.get_presence(port_num): - return False # Port is not present, unable to set the eeprom + return False # Port is not present, unable to set the eeprom # Fill in write buffer - regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode + regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode buffer = create_string_buffer(1) buffer[0] = chr(regval) @@ -248,7 +248,7 @@ def set_low_power_mode(self, port_num, lpmode): eeprom.write(buffer[0]) return True except IOError as err: - print "Error: unable to open file: %s" % str(err) + print("Error: unable to open file: %s" % str(err)) return False finally: if eeprom is not None: @@ -258,20 +258,20 @@ def set_low_power_mode(self, port_num, lpmode): def reset(self, port_num): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False - + order = self.update_i2c_order() lp_mode_path = self.BASE_CPLD3_PATH.format(order) - mod_rst_path = lp_mode_path + "module_reset_" + mod_rst_path = lp_mode_path + "module_reset_" q = self.qsfp_sb_remap(port_num) mod_rst_path = mod_rst_path + str(q) - + try: reg_file = open(mod_rst_path, 'r+', buffering=0) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False - #toggle reset + # toggle reset reg_file.seek(0) reg_file.write('0') time.sleep(1) @@ -282,31 +282,31 @@ def reset(self, port_num): @property def _get_presence_bitmap(self): - nodes = [] + nodes = [] order = self.update_i2c_order() - + present_path = self.BASE_CPLD2_PATH.format(order) nodes.append(present_path + "module_present_all") present_path = self.BASE_CPLD3_PATH.format(order) nodes.append(present_path + "module_present_all") - bitmap = "" - for node in nodes: + bitmap = "" + for node in nodes: try: reg_file = open(node) - + except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False bitmap += reg_file.readline().rstrip() + " " reg_file.close() rev = bitmap.split(" ") rev = "".join(rev[::-1]) - return int(rev,16) - + return int(rev, 16) + + data = {'valid': 0, 'last': 0, 'present': 0} - data = {'valid':0, 'last':0, 'present':0} def get_transceiver_change_event(self, timeout=2000): now = time.time() port_dict = {} @@ -314,8 +314,7 @@ def get_transceiver_change_event(self, timeout=2000): if timeout < 1000: timeout = 1000 - timeout = (timeout) / float(1000) # Convert to secs - + timeout = (timeout) / float(1000) # Convert to secs if now < (self.data['last'] + timeout) and self.data['valid']: return True, {} @@ -323,7 +322,7 @@ def get_transceiver_change_event(self, timeout=2000): reg_value = self._get_presence_bitmap changed_ports = self.data['present'] ^ reg_value if changed_ports: - for port in range (self.port_start, self.port_end+1): + for port in range(self.port_start, self.port_end+1): # Mask off the bit corresponding to our port fp_port = self._port_to_i2c_mapping[port][0] mask = (1 << (fp_port - 1)) @@ -334,7 +333,7 @@ def get_transceiver_change_event(self, timeout=2000): else: port_dict[port] = SFP_STATUS_INSERTED - # Update cache + # Update cache self.data['present'] = reg_value self.data['last'] = now self.data['valid'] = 1 @@ -343,4 +342,3 @@ def get_transceiver_change_event(self, timeout=2000): else: return True, {} return False, {} - diff --git a/device/accton/x86_64-accton_as5835_54t-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as5835_54t-r0/plugins/eeprom.py index 7681caafeef4..951384d5e37d 100644 --- a/device/accton/x86_64-accton_as5835_54t-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as5835_54t-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,14 +8,16 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom" - #Two i2c buses might get flipped order, check them both. + # Two i2c buses might get flipped order, check them both. if not os.path.exists(self.eeprom_path): self.eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/accton/x86_64-accton_as5835_54t-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as5835_54t-r0/plugins/psuutil.py index c95bc27897dc..b22e01f5e9fc 100644 --- a/device/accton/x86_64-accton_as5835_54t-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as5835_54t-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Accton # @@ -13,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/accton/x86_64-accton_as5835_54t-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as5835_54t-r0/plugins/sfputil.py index 34e8f724ae42..7c7e7f941a1f 100644 --- a/device/accton/x86_64-accton_as5835_54t-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as5835_54t-r0/plugins/sfputil.py @@ -14,6 +14,7 @@ SFP_STATUS_INSERTED = '1' SFP_STATUS_REMOVED = '0' + class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" @@ -23,31 +24,31 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} _port_to_i2c_mapping = { - 49: 28, #QSFP49 - 50: 28, - 51: 28, - 52: 28, - 53: 29, #QSFP50 - 54: 29, - 55: 29, - 56: 29, - 57: 26, #QSFP51 - 58: 26, - 59: 26, - 60: 26, - 61: 30, #QSFP52 - 62: 30, - 63: 30, - 64: 30, - 65: 31, #QSFP53 - 66: 31, - 67: 31, - 68: 31, - 69: 27, #QSFP54 - 70: 27, - 71: 27, - 72: 27, - } + 49: 28, # QSFP49 + 50: 28, + 51: 28, + 52: 28, + 53: 29, # QSFP50 + 54: 29, + 55: 29, + 56: 29, + 57: 26, # QSFP51 + 58: 26, + 59: 26, + 60: 26, + 61: 30, # QSFP52 + 62: 30, + 63: 30, + 64: 30, + 65: 31, # QSFP53 + 66: 31, + 67: 31, + 68: 31, + 69: 27, # QSFP54 + 70: 27, + 71: 27, + 72: 27, + } @property def port_start(self): @@ -64,10 +65,10 @@ def qsfp_port_start(self): @property def qsfp_port_end(self): return self.PORT_END - + @property def qsfp_ports(self): - return range(self.PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -81,9 +82,9 @@ def __init__(self): SfpUtilBase.__init__(self) - # For port 49~54 are QSFP, here presumed they're all split to 4 lanes. - def get_cage_num(self, port_num): + + def get_cage_num(self, port_num): cage_num = port_num if (port_num >= self.PORT_START): cage_num = (port_num - self.PORT_START)/4 @@ -95,51 +96,51 @@ def get_presence(self, port_num): # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False - + cage_num = self.get_cage_num(port_num) path = "/sys/bus/i2c/devices/3-0062/module_present_{0}" port_ps = path.format(cage_num) - content="0" + content = "0" try: val_file = open(port_ps) content = val_file.readline().rstrip() val_file.close() except IOError as e: - print "Error: unable to access file: %s" % str(e) + print("Error: unable to access file: %s" % str(e)) return False - + if content == "1": return True return False - def get_low_power_mode_cpld(self, port_num): + def get_low_power_mode_cpld(self, port_num): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False cage_num = self.get_cage_num(port_num) path = "/sys/bus/i2c/devices/3-0062/module_lpmode_{0}" lp_mode_path = path.format(cage_num) - + try: val_file = open(lp_mode_path) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = val_file.readline().rstrip() val_file.close() - + if content == "1": return True return False - def get_low_power_mode(self, port_num): + def get_low_power_mode(self, port_num): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False - + if not self.get_presence(port_num): return False @@ -150,15 +151,15 @@ def get_low_power_mode(self, port_num): eeprom.seek(93) lpmode = ord(eeprom.read(1)) - if not (lpmode & 0x1): # 'Power override' bit is 0 + if not (lpmode & 0x1): # 'Power override' bit is 0 return self.get_low_power_mode_cpld(port_num) else: if ((lpmode & 0x2) == 0x2): - return True # Low Power Mode if "Power set" bit is 1 + return True # Low Power Mode if "Power set" bit is 1 else: - return False # High Power Mode if "Power set" bit is 0 + return False # High Power Mode if "Power set" bit is 0 except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False finally: if eeprom is not None: @@ -167,16 +168,16 @@ def get_low_power_mode(self, port_num): def set_low_power_mode(self, port_num, lpmode): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: - return False + return False try: eeprom = None if not self.get_presence(port_num): - return False # Port is not present, unable to set the eeprom + return False # Port is not present, unable to set the eeprom # Fill in write buffer - regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode + regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode buffer = create_string_buffer(1) buffer[0] = chr(regval) @@ -186,7 +187,7 @@ def set_low_power_mode(self, port_num, lpmode): eeprom.write(buffer[0]) return True except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False finally: if eeprom is not None: @@ -196,24 +197,24 @@ def set_low_power_mode(self, port_num, lpmode): def reset(self, port_num): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False - + cage_num = self.get_cage_num(port_num) path = "/sys/bus/i2c/devices/3-0062/module_reset_{0}" port_ps = path.format(cage_num) try: reg_file = open(port_ps, mode="w", buffering=0) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False - #toggle reset + # toggle reset reg_file.seek(0) reg_file.write('0') time.sleep(1) reg_file.seek(0) reg_file.write('1') reg_file.close() - + return True @property @@ -223,31 +224,32 @@ def _get_presence_bitmap(self): try: reg_file = open("/sys/bus/i2c/devices/3-0062/module_present_all") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False bitmap += reg_file.readline().rstrip() + " " reg_file.close() rev = bitmap.split(" ") - rev.pop() # Remove the last useless character + rev.pop() # Remove the last useless character # Save port 49-54 into buffer tmp = rev.pop() # Insert port 1-48 - for i in range (0, 6): + for i in range(0, 6): rev.append(hex(0)[2:]) rev[i] = rev[i].zfill(2) # Expand port 49-54 - for i in range (0, 6): - val = (int(tmp,16) >> i) & 0x1 + for i in range(0, 6): + val = (int(tmp, 16) >> i) & 0x1 rev.append(hex(val)[2:]) rev = "".join(rev[::-1]) - return int(rev,16) + return int(rev, 16) + + data = {'valid': 0, 'present': 0} - data = {'valid':0, 'present':0} def get_transceiver_change_event(self, timeout=0): start_time = time.time() @@ -258,17 +260,17 @@ def get_transceiver_change_event(self, timeout=0): if timeout == 0: blocking = True elif timeout > 0: - timeout = timeout / float(1000) # Convert to secs + timeout = timeout / float(1000) # Convert to secs else: - print "get_transceiver_change_event:Invalid timeout value", timeout + print("get_transceiver_change_event:Invalid timeout value", timeout) return False, {} end_time = start_time + timeout if start_time > end_time: - print 'get_transceiver_change_event:' \ - 'time wrap / invalid timeout value', timeout + print('get_transceiver_change_event:' + 'time wrap / invalid timeout value', timeout) - return False, {} # Time wrap or possibly incorrect timeout + return False, {} # Time wrap or possibly incorrect timeout while timeout >= 0: # Check for OIR events and return updated port_dict @@ -276,7 +278,7 @@ def get_transceiver_change_event(self, timeout=0): reg_value = self._get_presence_bitmap changed_ports = self.data['present'] ^ reg_value if changed_ports: - for port in range (self.port_start, self.port_end+1): + for port in range(self.port_start, self.port_end+1): # Mask off the bit corresponding to our port mask = (1 << (port - 1)) if changed_ports & mask: @@ -286,7 +288,7 @@ def get_transceiver_change_event(self, timeout=0): else: port_dict[port] = SFP_STATUS_INSERTED - # Update cache + # Update cache self.data['present'] = reg_value self.data['valid'] = 1 return True, port_dict @@ -296,10 +298,10 @@ def get_transceiver_change_event(self, timeout=0): else: timeout = end_time - time.time() if timeout >= 1: - time.sleep(1) # We poll at 1 second granularity + time.sleep(1) # We poll at 1 second granularity else: if timeout > 0: time.sleep(timeout) return True, {} - print "get_transceiver_change_event: Should not reach here." + print("get_transceiver_change_event: Should not reach here.") return False, {} diff --git a/device/accton/x86_64-accton_as5835_54x-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as5835_54x-r0/plugins/eeprom.py index 7681caafeef4..951384d5e37d 100644 --- a/device/accton/x86_64-accton_as5835_54x-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as5835_54x-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,14 +8,16 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom" - #Two i2c buses might get flipped order, check them both. + # Two i2c buses might get flipped order, check them both. if not os.path.exists(self.eeprom_path): self.eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/accton/x86_64-accton_as5835_54x-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as5835_54x-r0/plugins/psuutil.py index c95bc27897dc..b22e01f5e9fc 100644 --- a/device/accton/x86_64-accton_as5835_54x-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as5835_54x-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Accton # @@ -13,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/accton/x86_64-accton_as5835_54x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as5835_54x-r0/plugins/sfputil.py index 7782f708fccd..b18b15f3e68c 100644 --- a/device/accton/x86_64-accton_as5835_54x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as5835_54x-r0/plugins/sfputil.py @@ -14,6 +14,7 @@ SFP_STATUS_INSERTED = '1' SFP_STATUS_REMOVED = '0' + class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" @@ -30,84 +31,84 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} _cpld_mapping = { - 0: "3-0060", - 1: "3-0061", - 2: "3-0062", - } + 0: "3-0060", + 1: "3-0061", + 2: "3-0062", + } _port_to_i2c_mapping = { - 1: 42, - 2: 43, - 3: 44, - 4: 45, - 5: 46, - 6: 47, - 7: 48, - 8: 49, - 9: 50, - 10: 51, - 11: 52, - 12: 53, - 13: 54, - 14: 55, - 15: 56, - 16: 57, - 17: 58, - 18: 59, - 19: 60, - 20: 61, - 21: 62, - 22: 63, - 23: 64, - 24: 65, - 25: 66, - 26: 67, - 27: 68, - 28: 69, - 29: 70, - 30: 71, - 31: 72, - 32: 73, - 33: 74, - 34: 75, - 35: 76, - 36: 77, - 37: 78, - 38: 79, - 39: 80, - 40: 81, - 41: 82, - 42: 83, - 43: 84, - 44: 85, - 45: 86, - 46: 87, - 47: 88, - 48: 89, - 49: 28, #QSFP49 - 50: 28, - 51: 28, - 52: 28, - 53: 29, #QSFP50 - 54: 29, - 55: 29, - 56: 29, - 57: 26, #QSFP51 - 58: 26, - 59: 26, - 60: 26, - 61: 30, #QSFP52 - 62: 30, - 63: 30, - 64: 30, - 65: 31, #QSFP53 - 66: 31, - 67: 31, - 68: 31, - 69: 27, #QSFP54 - 70: 27, - 71: 27, - 72: 27, - } + 1: 42, + 2: 43, + 3: 44, + 4: 45, + 5: 46, + 6: 47, + 7: 48, + 8: 49, + 9: 50, + 10: 51, + 11: 52, + 12: 53, + 13: 54, + 14: 55, + 15: 56, + 16: 57, + 17: 58, + 18: 59, + 19: 60, + 20: 61, + 21: 62, + 22: 63, + 23: 64, + 24: 65, + 25: 66, + 26: 67, + 27: 68, + 28: 69, + 29: 70, + 30: 71, + 31: 72, + 32: 73, + 33: 74, + 34: 75, + 35: 76, + 36: 77, + 37: 78, + 38: 79, + 39: 80, + 40: 81, + 41: 82, + 42: 83, + 43: 84, + 44: 85, + 45: 86, + 46: 87, + 47: 88, + 48: 89, + 49: 28, # QSFP49 + 50: 28, + 51: 28, + 52: 28, + 53: 29, # QSFP50 + 54: 29, + 55: 29, + 56: 29, + 57: 26, # QSFP51 + 58: 26, + 59: 26, + 60: 26, + 61: 30, # QSFP52 + 62: 30, + 63: 30, + 64: 30, + 65: 31, # QSFP53 + 66: 31, + 67: 31, + 68: 31, + 69: 27, # QSFP54 + 70: 27, + 71: 27, + 72: 27, + } @property def port_start(self): @@ -124,10 +125,10 @@ def qsfp_port_start(self): @property def qsfp_port_end(self): return self.QSFP_PORT_END - + @property def qsfp_ports(self): - return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -141,9 +142,9 @@ def __init__(self): SfpUtilBase.__init__(self) - # For port 49~54 are QSFP, here presumed they're all split to 4 lanes. - def get_cage_num(self, port_num): + + def get_cage_num(self, port_num): cage_num = port_num if (port_num >= self.QSFP_PORT_START): cage_num = (port_num - self.QSFP_PORT_START)/4 @@ -152,14 +153,14 @@ def get_cage_num(self, port_num): return cage_num # For cage 1~38 are at cpld2, others are at cpld3. - def get_cpld_num(self, port_num): + def get_cpld_num(self, port_num): return 1 if (port_num < 39) else 2 def get_presence(self, port_num): # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False - + cage_num = self.get_cage_num(port_num) cpld_i = self.get_cpld_num(port_num) @@ -173,15 +174,15 @@ def get_presence(self, port_num): content = val_file.readline().rstrip() val_file.close() except IOError as e: - print "Error: unable to access file: %s" % str(e) + print("Error: unable to access file: %s" % str(e)) return False - + if content == "1": return True return False - def get_low_power_mode_cpld(self, port_num): + def get_low_power_mode_cpld(self, port_num): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False @@ -191,25 +192,25 @@ def get_low_power_mode_cpld(self, port_num): cpld_ps = self._cpld_mapping[cpld_i] path = "/sys/bus/i2c/devices/{0}/module_lpmode_{1}" lp_mode_path = path.format(cpld_ps, cage_num) - + try: val_file = open(lp_mode_path) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = val_file.readline().rstrip() val_file.close() - + if content == "1": return True return False - def get_low_power_mode(self, port_num): + def get_low_power_mode(self, port_num): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False - + if not self.get_presence(port_num): return False @@ -220,15 +221,15 @@ def get_low_power_mode(self, port_num): eeprom.seek(93) lpmode = ord(eeprom.read(1)) - if not (lpmode & 0x1): # 'Power override' bit is 0 + if not (lpmode & 0x1): # 'Power override' bit is 0 return self.get_low_power_mode_cpld(port_num) else: if ((lpmode & 0x2) == 0x2): - return True # Low Power Mode if "Power set" bit is 1 + return True # Low Power Mode if "Power set" bit is 1 else: - return False # High Power Mode if "Power set" bit is 0 + return False # High Power Mode if "Power set" bit is 0 except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False finally: if eeprom is not None: @@ -237,16 +238,16 @@ def get_low_power_mode(self, port_num): def set_low_power_mode(self, port_num, lpmode): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: - return False + return False try: eeprom = None if not self.get_presence(port_num): - return False # Port is not present, unable to set the eeprom + return False # Port is not present, unable to set the eeprom # Fill in write buffer - regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode + regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode buffer = create_string_buffer(1) buffer[0] = chr(regval) @@ -256,7 +257,7 @@ def set_low_power_mode(self, port_num, lpmode): eeprom.write(buffer[0]) return True except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False finally: if eeprom is not None: @@ -266,7 +267,7 @@ def set_low_power_mode(self, port_num, lpmode): def reset(self, port_num): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False - + cage_num = self.get_cage_num(port_num) cpld_i = self.get_cpld_num(port_num) cpld_ps = self._cpld_mapping[cpld_i] @@ -275,17 +276,17 @@ def reset(self, port_num): try: reg_file = open(port_ps, mode='w', buffering=0) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False - #toggle reset + # toggle reset reg_file.seek(0) reg_file.write('0') time.sleep(1) reg_file.seek(0) reg_file.write('1') reg_file.close() - + return True @property @@ -295,36 +296,37 @@ def _get_presence_bitmap(self): nodes.append("/sys/bus/i2c/devices/3-0062/module_present_all") bitmap = "" - for node in nodes: + for node in nodes: try: reg_file = open(node) - + except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False bitmap += reg_file.readline().rstrip() + " " reg_file.close() rev = bitmap.split(" ") - rev.pop() # Remove the last useless character - + rev.pop() # Remove the last useless character + # Convert bitmap into continuously port order - rev[4] = hex((int(rev[4],16) | ((int(rev[5],16) & 0x3) << 6)))[2:] # Port 33-40 - rev[5] = hex((int(rev[5],16) >> 2) | ((int(rev[6],16) & 0x3) << 6))[2:] # Port 41-48 + rev[4] = hex((int(rev[4], 16) | ((int(rev[5], 16) & 0x3) << 6)))[2:] # Port 33-40 + rev[5] = hex((int(rev[5], 16) >> 2) | ((int(rev[6], 16) & 0x3) << 6))[2:] # Port 41-48 # Expand port 49-54 tmp = rev.pop() - for i in range (2, 8): - val = (int(tmp,16) >> i) & 0x1 + for i in range(2, 8): + val = (int(tmp, 16) >> i) & 0x1 rev.append(hex(val)[2:]) - - for i in range (0,6): + + for i in range(0, 6): rev[i] = rev[i].zfill(2) rev = "".join(rev[::-1]) - return int(rev,16) + return int(rev, 16) + + data = {'valid': 0, 'present': 0} - data = {'valid':0, 'present':0} def get_transceiver_change_event(self, timeout=0): start_time = time.time() @@ -335,17 +337,17 @@ def get_transceiver_change_event(self, timeout=0): if timeout == 0: blocking = True elif timeout > 0: - timeout = timeout / float(1000) # Convert to secs + timeout = timeout / float(1000) # Convert to secs else: - print "get_transceiver_change_event:Invalid timeout value", timeout + print("get_transceiver_change_event:Invalid timeout value", timeout) return False, {} end_time = start_time + timeout if start_time > end_time: - print 'get_transceiver_change_event:' \ - 'time wrap / invalid timeout value', timeout + print('get_transceiver_change_event:' + 'time wrap / invalid timeout value', timeout) - return False, {} # Time wrap or possibly incorrect timeout + return False, {} # Time wrap or possibly incorrect timeout while timeout >= 0: # Check for OIR events and return updated port_dict @@ -353,7 +355,7 @@ def get_transceiver_change_event(self, timeout=0): reg_value = self._get_presence_bitmap changed_ports = self.data['present'] ^ reg_value if changed_ports: - for port in range (self.port_start, self.port_end+1): + for port in range(self.port_start, self.port_end+1): # Mask off the bit corresponding to our port mask = (1 << (port - 1)) if changed_ports & mask: @@ -363,7 +365,7 @@ def get_transceiver_change_event(self, timeout=0): else: port_dict[port] = SFP_STATUS_INSERTED - # Update cache + # Update cache self.data['present'] = reg_value self.data['valid'] = 1 return True, port_dict @@ -373,12 +375,10 @@ def get_transceiver_change_event(self, timeout=0): else: timeout = end_time - time.time() if timeout >= 1: - time.sleep(1) # We poll at 1 second granularity + time.sleep(1) # We poll at 1 second granularity else: if timeout > 0: time.sleep(timeout) return True, {} - print "get_transceiver_change_event: Should not reach here." + print("get_transceiver_change_event: Should not reach here.") return False, {} - - diff --git a/device/accton/x86_64-accton_as6712_32x-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as6712_32x-r0/plugins/eeprom.py index 7681caafeef4..bf7f2e1f3aec 100644 --- a/device/accton/x86_64-accton_as6712_32x-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as6712_32x-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -10,15 +7,16 @@ import sys from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo - import subprocess -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom" - #Two i2c buses might get flipped order, check them both. + # Two i2c buses might get flipped order, check them both. if not os.path.exists(self.eeprom_path): self.eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/accton/x86_64-accton_as6712_32x-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as6712_32x-r0/plugins/psuutil.py index 191654429e6b..110c836004c8 100644 --- a/device/accton/x86_64-accton_as6712_32x-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as6712_32x-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Accton # @@ -13,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/accton/x86_64-accton_as6712_32x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as6712_32x-r0/plugins/sfputil.py index 6889280608fb..28c9010abf56 100644 --- a/device/accton/x86_64-accton_as6712_32x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as6712_32x-r0/plugins/sfputil.py @@ -12,7 +12,7 @@ except ImportError as e: raise ImportError("%s - required module not found" % str(e)) -#from xcvrd +# from xcvrd SFP_STATUS_INSERTED = '1' SFP_STATUS_REMOVED = '0' @@ -36,39 +36,39 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} _port_to_i2c_mapping = { - 1: [1, 2], - 2: [2, 3], - 3: [3, 4], - 4: [4, 5], - 5: [5, 6], - 6: [6, 7], - 7: [7, 8], - 8: [8, 9], - 9: [9, 10], - 10: [10, 11], - 11: [11, 12], - 12: [12, 13], - 13: [13, 14], - 14: [14, 15], - 15: [15, 16], - 16: [16, 17], - 17: [17, 18], - 18: [18, 19], - 19: [19, 20], - 20: [20, 21], - 21: [21, 22], - 22: [22, 23], - 23: [23, 24], - 24: [24, 25], - 25: [25, 26], - 26: [26, 27], - 27: [27, 28], - 28: [28, 29], - 29: [29, 30], - 30: [30, 31], - 31: [31, 32], - 32: [32, 33], - } + 1: [1, 2], + 2: [2, 3], + 3: [3, 4], + 4: [4, 5], + 5: [5, 6], + 6: [6, 7], + 7: [7, 8], + 8: [8, 9], + 9: [9, 10], + 10: [10, 11], + 11: [11, 12], + 12: [12, 13], + 13: [13, 14], + 14: [14, 15], + 15: [15, 16], + 16: [16, 17], + 17: [17, 18], + 18: [18, 19], + 19: [19, 20], + 20: [20, 21], + 21: [21, 22], + 22: [22, 23], + 23: [23, 24], + 24: [24, 25], + 25: [25, 26], + 26: [26, 27], + 27: [27, 28], + 28: [28, 29], + 29: [29, 30], + 30: [30, 31], + 31: [31, 32], + 32: [32, 33], + } @property def port_start(self): @@ -85,10 +85,10 @@ def qsfp_port_start(self): @property def qsfp_port_end(self): return self.QSFP_PORT_END - + @property def qsfp_ports(self): - return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -100,7 +100,7 @@ def __init__(self): for x in range(self.port_start, self.port_end+1): self.port_to_eeprom_mapping[x] = eeprom_path.format( self._port_to_i2c_mapping[x][1] - ) + ) SfpUtilBase.__init__(self) def get_cpld_dev_path(self, port_num): @@ -108,65 +108,64 @@ def get_cpld_dev_path(self, port_num): cpld_num = 0 else: cpld_num = 1 - - #cpld can be at either bus 0 or bus 1. + + # cpld can be at either bus 0 or bus 1. cpld_path = self.I2C_DEV_PATH + str(0) + self.CPLD_ADDRESS[cpld_num] - if not os.path.exists(cpld_path): + if not os.path.exists(cpld_path): cpld_path = self.I2C_DEV_PATH + str(1) + self.CPLD_ADDRESS[cpld_num] return cpld_path - + def get_presence(self, port_num): # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False - cpld_path = self.get_cpld_dev_path(port_num) - present_path = cpld_path + "/module_present_" + present_path = cpld_path + "/module_present_" present_path += str(self._port_to_i2c_mapping[port_num][0]) self.__port_to_is_present = present_path - content="0" + content = "0" try: val_file = open(self.__port_to_is_present) content = val_file.readline().rstrip() val_file.close() except IOError as e: - print "Error: unable to access file: %s" % str(e) + print("Error: unable to access file: %s" % str(e)) return False - + if content == "1": return True return False - def get_low_power_mode_cpld(self, port_num): + def get_low_power_mode_cpld(self, port_num): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False - + cpld_path = self.get_cpld_dev_path(port_num) - _path = cpld_path + "/module_lp_mode_" + _path = cpld_path + "/module_lp_mode_" _path += str(self._port_to_i2c_mapping[port_num][0]) - content="0" + content = "0" try: reg_file = open(_path) content = reg_file.readline().rstrip() reg_file.close() except IOError as e: - print "Error: unable to access file: %s" % str(e) + print("Error: unable to access file: %s" % str(e)) return False - + if content == "1": return True return False - def get_low_power_mode(self, port_num): + def get_low_power_mode(self, port_num): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False - + if not self.get_presence(port_num): return False @@ -177,15 +176,15 @@ def get_low_power_mode(self, port_num): eeprom.seek(93) lpmode = ord(eeprom.read(1)) - if not (lpmode & 0x1): # 'Power override' bit is 0 + if not (lpmode & 0x1): # 'Power override' bit is 0 return self.get_low_power_mode_cpld(port_num) else: if ((lpmode & 0x2) == 0x2): - return True # Low Power Mode if "Power set" bit is 1 + return True # Low Power Mode if "Power set" bit is 1 else: - return False # High Power Mode if "Power set" bit is 0 + return False # High Power Mode if "Power set" bit is 0 except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False finally: if eeprom is not None: @@ -194,16 +193,16 @@ def get_low_power_mode(self, port_num): def set_low_power_mode(self, port_num, lpmode): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: - return False + return False try: eeprom = None if not self.get_presence(port_num): - return False # Port is not present, unable to set the eeprom + return False # Port is not present, unable to set the eeprom # Fill in write buffer - regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode + regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode buffer = create_string_buffer(1) buffer[0] = chr(regval) @@ -213,7 +212,7 @@ def set_low_power_mode(self, port_num, lpmode): eeprom.write(buffer[0]) return True except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False finally: if eeprom is not None: @@ -223,15 +222,15 @@ def set_low_power_mode(self, port_num, lpmode): def reset(self, port_num): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False - + cpld_path = self.get_cpld_dev_path(port_num) - _path = cpld_path + "/module_reset_" + _path = cpld_path + "/module_reset_" _path += str(self._port_to_i2c_mapping[port_num][0]) try: reg_file = open(_path, 'w') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_file.seek(0) @@ -240,7 +239,7 @@ def reset(self, port_num): reg_file.seek(0) reg_file.write('0') reg_file.close() - + return True @property @@ -258,17 +257,17 @@ def get_transceiver_status(self): reg_file = open(node) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False bitmap += reg_file.readline().rstrip() + " " reg_file.close() rev = bitmap.split(" ") rev = "".join(rev[::-1]) - return int(rev,16) + return int(rev, 16) + data = {'valid': 0, 'last': 0, 'present': 0} - data = {'valid':0, 'last':0, 'present':0} def get_transceiver_change_event(self, timeout=2000): now = time.time() port_dict = {} @@ -276,8 +275,7 @@ def get_transceiver_change_event(self, timeout=2000): if timeout < 1000: timeout = 1000 - timeout = (timeout) / float(1000) # Convert to secs - + timeout = (timeout) / float(1000) # Convert to secs if now < (self.data['last'] + timeout) and self.data['valid']: return True, {} @@ -285,7 +283,7 @@ def get_transceiver_change_event(self, timeout=2000): reg_value = self.get_transceiver_status changed_ports = self.data['present'] ^ reg_value if changed_ports: - for port in range (self.port_start, self.port_end+1): + for port in range(self.port_start, self.port_end+1): # Mask off the bit corresponding to our port fp_port = self._port_to_i2c_mapping[port][0] mask = (1 << (fp_port - 1)) @@ -305,5 +303,3 @@ def get_transceiver_change_event(self, timeout=2000): else: return True, {} return False, {} - - diff --git a/device/accton/x86_64-accton_as7116_54x-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as7116_54x-r0/plugins/eeprom.py index 1e7d1046d93d..4241483d68eb 100644 --- a/device/accton/x86_64-accton_as7116_54x-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as7116_54x-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,11 +8,13 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/0-0056/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/accton/x86_64-accton_as7116_54x-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as7116_54x-r0/plugins/psuutil.py index 08fd2648f314..40e7257a6f02 100644 --- a/device/accton/x86_64-accton_as7116_54x-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as7116_54x-r0/plugins/psuutil.py @@ -20,12 +20,12 @@ class PsuUtil(PsuBase): def __init__(self): PsuBase.__init__(self) - - + # Get sysfs attribute + def get_attr_value(self, attr_path): - - retval = 'ERR' + + retval = 'ERR' if (not os.path.isfile(attr_path)): return retval @@ -55,16 +55,16 @@ def get_psu_status(self, index): faulty """ status = 0 - attr_file = 'psu_power_good' - attr_path = self.SYSFS_PSU_DIR[index-1] +'/' + attr_file - + attr_file = 'psu_power_good' + attr_path = self.SYSFS_PSU_DIR[index-1] + '/' + attr_file + attr_value = self.get_attr_value(attr_path) - + if (attr_value != 'ERR'): attr_value = int(attr_value, 16) # Check for PSU status if (attr_value == 1): - status = 1 + status = 1 return status @@ -77,16 +77,15 @@ def get_psu_presence(self, index): """ status = 0 psu_absent = 0 - attr_file ='psu_present' - attr_path = self.SYSFS_PSU_DIR[index-1] +'/' + attr_file - + attr_file = 'psu_present' + attr_path = self.SYSFS_PSU_DIR[index-1] + '/' + attr_file + attr_value = self.get_attr_value(attr_path) if (attr_value != 'ERR'): attr_value = int(attr_value, 16) # Check for PSU presence if (attr_value == 1): - status = 1 + status = 1 return status - diff --git a/device/accton/x86_64-accton_as7116_54x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7116_54x-r0/plugins/sfputil.py index 3562043ad9fc..9f678757f2a8 100644 --- a/device/accton/x86_64-accton_as7116_54x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7116_54x-r0/plugins/sfputil.py @@ -1,14 +1,13 @@ -#!/usr/bin/env python - try: import time - from sonic_sfp.sfputilbase import SfpUtilBase -except ImportError, e: - raise ImportError (str(e) + "- required module not found") + from sonic_sfp.sfputilbase import SfpUtilBase +except ImportError as e: + raise ImportError(str(e) + "- required module not found") SFP_STATUS_INSERTED = '1' SFP_STATUS_REMOVED = '0' + class SfpUtil(SfpUtilBase): """Platform specific SfpUtill class""" @@ -19,63 +18,63 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} _port_to_i2c_mapping = { - 0 : 37, - 1 : 38, - 2 : 39, - 3 : 40, - 4 : 41, - 5 : 42, - 6 : 43, - 7 : 44, - 8 : 45, - 9 : 46, - 10 : 47, - 11 : 48, - 12 : 49, - 13 : 50, - 14 : 51, - 15 : 52, - 16 : 53, - 17 : 54, - 18 : 55, - 19 : 56, - 20 : 57, - 21 : 58, - 22 : 59, - 23 : 60, - 24 : 61, - 25 : 62, - 26 : 63, - 27 : 64, - 28 : 65, - 29 : 66, - 30 : 67, - 31 : 68, - 32 : 69, - 33 : 70, - 34 : 71, - 35 : 72, - 36 : 73, - 37 : 74, - 38 : 75, - 39 : 76, - 40 : 77, - 41 : 78, - 42 : 79, - 43 : 80, - 44 : 81, - 45 : 82, - 46 : 83, - 47 : 84, - 48 : 21, - 49 : 22, - 50 : 23, - 51 : 24, - 52 : 25, - 53 : 26, + 0: 37, + 1: 38, + 2: 39, + 3: 40, + 4: 41, + 5: 42, + 6: 43, + 7: 44, + 8: 45, + 9: 46, + 10: 47, + 11: 48, + 12: 49, + 13: 50, + 14: 51, + 15: 52, + 16: 53, + 17: 54, + 18: 55, + 19: 56, + 20: 57, + 21: 58, + 22: 59, + 23: 60, + 24: 61, + 25: 62, + 26: 63, + 27: 64, + 28: 65, + 29: 66, + 30: 67, + 31: 68, + 32: 69, + 33: 70, + 34: 71, + 35: 72, + 36: 73, + 37: 74, + 38: 75, + 39: 76, + 40: 77, + 41: 78, + 42: 79, + 43: 80, + 44: 81, + 45: 82, + 46: 83, + 47: 84, + 48: 21, + 49: 22, + 50: 23, + 51: 24, + 52: 25, + 53: 26, } - _qsfp_ports = range(_qsfp_port_start, _ports_in_block + 1) + _qsfp_ports = list(range(_qsfp_port_start, _ports_in_block + 1)) _present_status = dict() @@ -83,27 +82,27 @@ def __init__(self): eeprom_path = '/sys/bus/i2c/devices/{0}-0050/sfp_eeprom' for x in range(self._port_start, self._port_end + 1): port_eeprom_path = eeprom_path.format(self._port_to_i2c_mapping[x]) - self._port_to_eeprom_mapping[x] = port_eeprom_path + self._port_to_eeprom_mapping[x] = port_eeprom_path self._present_status[x] = SFP_STATUS_REMOVED - + SfpUtilBase.__init__(self) - + def reset(self, port_num): # Check for invalid port_num if port_num < self._qsfp_port_start or port_num > self._port_end: - print "Error: port %d is not qsfp port" % port_num + print("Error: port %d is not qsfp port" % port_num) return False path = "/sys/bus/i2c/devices/{0}-0050/sfp_port_reset" port_ps = path.format(self._port_to_i2c_mapping[port_num]) - + try: reg_file = open(port_ps, 'w') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False - #toggle reset + # toggle reset reg_file.seek(0) reg_file.write('1') time.sleep(1) @@ -132,14 +131,14 @@ def get_presence(self, port_num): reg_value = reg_file.readline().rstrip() reg_file.close() except IOError as e: - print "Error: unable to access file: %s" % str(e) + print("Error: unable to access file: %s" % str(e)) return False - + if reg_value == '1': return True return False - + def get_transceiver_change_event(self, timeout=0): raise NotImplementedError @@ -155,19 +154,18 @@ def port_end(self): def qsfp_ports(self): return self._qsfp_ports - @property + @property def port_to_eeprom_mapping(self): - return self._port_to_eeprom_mapping + return self._port_to_eeprom_mapping def get_transceiver_change_event(self, timeout=0): ret_present = dict() for phy_port in range(self._port_start, self._port_end + 1): last_present_status = SFP_STATUS_INSERTED if self.get_presence(phy_port) else SFP_STATUS_REMOVED if self._present_status[phy_port] != last_present_status: - ret_present[phy_port] = last_present_status - self._present_status[phy_port] = last_present_status - + ret_present[phy_port] = last_present_status + self._present_status[phy_port] = last_present_status + time.sleep(2) - - return True, ret_present + return True, ret_present diff --git a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/chassis.py b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/chassis.py index 90b05465d27a..86ae121c6c82 100644 --- a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/chassis.py +++ b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/chassis.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # # Module contains an implementation of SONiC Platform Base API and @@ -32,7 +30,7 @@ SFP_PORT_START = 0 QSFP_PORT_START = 48 SFP_PORT_END = 47 -QSFP_PORT_END=53 +QSFP_PORT_END = 53 HOST_REBOOT_CAUSE_PATH = "/host/reboot-cause/" PMON_REBOOT_CAUSE_PATH = "/usr/share/sonic/platform/api_files/reboot-cause/" REBOOT_CAUSE_FILE = "reboot-cause.txt" diff --git a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/component.py b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/component.py index c8f109aa4db9..15d8e9e15e9d 100644 --- a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/component.py +++ b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/component.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Component contains an implementation of SONiC Platform Base API and # provides the components firmware management function @@ -18,6 +16,7 @@ BIOS_VERSION_PATH = "/sys/class/dmi/id/bios_version" + class Component(DeviceBase): """Platform-specific Component class""" @@ -31,7 +30,7 @@ def __run_command(self, command): # Run bash command and print output to stdout try: process = subprocess.Popen( - shlex.split(command), stdout=subprocess.PIPE) + shlex.split(command), universal_newlines=True, stdout=subprocess.PIPE) while True: output = process.stdout.readline() if output == '' and process.poll() is not None: diff --git a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/eeprom.py b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/eeprom.py index 714ac8153e0e..9cdd09106331 100644 --- a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/eeprom.py +++ b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Platform and model specific eeprom subclass, inherits from the base class, # and provides the followings: @@ -11,10 +9,14 @@ import glob import os import sys - import imp import re from array import array - from cStringIO import StringIO + + if sys.version_info.major == 3: + from io import StringIO + else: + from cStringIO import StringIO + from sonic_platform_base.sonic_eeprom import eeprom_dts from sonic_platform_base.sonic_eeprom import eeprom_tlvinfo except ImportError as e: diff --git a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/fan.py b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/fan.py index 54878e3e1baa..421e7727ceeb 100644 --- a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/fan.py +++ b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/fan.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # # Module contains an implementation of SONiC Platform Base API and @@ -21,6 +19,7 @@ "FANTRAY-3", "FANTRAY-4", "FANTRAY-5"] FAN_NAME_LIST = ["front", "rear"] + class Fan(FanBase): """Platform-specific Fan class""" @@ -67,7 +66,7 @@ def get_direction(self): """ direction = self.FAN_DIRECTION_EXHAUST fan_direction_file = (FAN_PATH + - self.fan_direction.format(self.fan_tray_index+1)) + self.fan_direction.format(self.fan_tray_index+1)) raw = self.__read_txt_file(fan_direction_file).strip('\r\n') direction = self.FAN_DIRECTION_INTAKE if str( raw).upper() == "1" else self.FAN_DIRECTION_EXHAUST @@ -84,7 +83,7 @@ def get_speed(self): speed = 0 if self.get_presence(): fan_speed_file = (FAN_PATH + - self.fan_speed_rpm.format(self.fan_tray_index+1,FAN_NAME_LIST[self.fan_index])) + self.fan_speed_rpm.format(self.fan_tray_index+1, FAN_NAME_LIST[self.fan_index])) speed = self.__read_txt_file(fan_speed_file).strip('\r\n') return int(speed) @@ -98,9 +97,9 @@ def get_target_speed(self): """ target = 0 if self.get_presence(): - fan_speed_file=(FAN_PATH + - self.fan_speed_rpm.format(self.fan_tray_index+1, FAN_NAME_LIST[self.fan_index])) - target=self.__read_txt_file(fan_speed_file).strip('\r\n') + fan_speed_file = (FAN_PATH + + self.fan_speed_rpm.format(self.fan_tray_index+1, FAN_NAME_LIST[self.fan_index])) + target = self.__read_txt_file(fan_speed_file).strip('\r\n') return target diff --git a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/platform.py b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/platform.py index 44e03cdadbb3..6e1a90132acc 100644 --- a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/platform.py +++ b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/platform.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Module contains an implementation of SONiC Platform Base API and # provides the platform information @@ -12,6 +10,7 @@ except ImportError as e: raise ImportError(str(e) + "- required module not found") + class Platform(PlatformBase): """Platform-specific Platform class""" diff --git a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/psu.py b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/psu.py index b1c8029dced9..f53b7506bb3e 100644 --- a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/psu.py +++ b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/psu.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # psuutil.py # Platform-specific PSU status interface for SONiC @@ -17,6 +15,7 @@ FAN_MAX_RPM = 9600 PSU_NAME_LIST = ["PSU-0", "PSU-1"] + class Psu(PsuBase): """Platform-specific Psu class""" @@ -27,7 +26,6 @@ def __init__(self): self.index = psu_index PsuBase.__init__(self) - def get_fan(self): """ Retrieves object representing the fan module contained in this PSU @@ -73,8 +71,8 @@ def get_presence(self): Returns: bool: True if PSU is present, False if not """ - attr_file ='psu_present' - attr_path = self.SYSFS_PSU_DIR[self.index-1] +'/' + attr_file + attr_file = 'psu_present' + attr_path = self.SYSFS_PSU_DIR[self.index-1] + '/' + attr_file status = 0 try: with open(attr_path, 'r') as psu_prs: @@ -91,11 +89,11 @@ def get_status(self): A boolean value, True if device is operating properly, False if not """ attr_file = 'psu_power_good' - attr_path = self.SYSFS_PSU_DIR[self.index-1] +'/' + attr_file + attr_path = self.SYSFS_PSU_DIR[self.index-1] + '/' + attr_file status = 0 try: - with open(attr_path, 'r') as power_status: - status = int(power_status.read()) + with open(attr_path, 'r') as power_status: + status = int(power_status.read()) except IOError: return False diff --git a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/sfp.py b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/sfp.py index 63fdb0684405..9d85b96be730 100644 --- a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/sfp.py +++ b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/sfp.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Sfp contains an implementation of SONiC Platform Base API and # provides the sfp device status which are available in the platform @@ -105,6 +103,7 @@ 'Fibre Channel link length/Transmitter Technology', 'Fibre Channel transmission media', 'Fibre Channel Speed') + class Sfp(SfpBase): """Platform-specific Sfp class""" @@ -168,7 +167,7 @@ class Sfp(SfpBase): 52: 25, 53: 26, } - _sfp_port = range(48, PORT_END + 1) + _sfp_port = list(range(48, PORT_END + 1)) RESET_PATH = "/sys/bus/i2c/devices/{}-0050/sfp_port_reset" PRS_PATH = "/sys/bus/i2c/devices/{}-0050/sfp_is_present" @@ -180,7 +179,7 @@ class Sfp(SfpBase): HWSKU = "Accton-AS7116-54X-R0" def __init__(self, sfp_index, sfp_type): - # Init index + # Init index self.index = sfp_index self.port_num = self.index + 1 self.sfp_type = sfp_type diff --git a/device/accton/x86_64-accton_as7212_54x-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as7212_54x-r0/plugins/eeprom.py index 7681caafeef4..951384d5e37d 100755 --- a/device/accton/x86_64-accton_as7212_54x-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as7212_54x-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,14 +8,16 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom" - #Two i2c buses might get flipped order, check them both. + # Two i2c buses might get flipped order, check them both. if not os.path.exists(self.eeprom_path): self.eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/accton/x86_64-accton_as7212_54x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7212_54x-r0/plugins/sfputil.py index 92ba72507285..47e1f9350aff 100755 --- a/device/accton/x86_64-accton_as7212_54x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7212_54x-r0/plugins/sfputil.py @@ -1,10 +1,8 @@ -#!/usr/bin/env python - try: import time from sonic_sfp.sfputilbase import SfpUtilBase -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") class sfputil(SfpUtilBase): @@ -16,41 +14,41 @@ class sfputil(SfpUtilBase): port_to_eeprom_mapping = {} port_to_i2c_mapping = { - 9 : 18, - 10 : 19, - 11 : 20, - 12 : 21, - 1 : 22, - 2 : 23, - 3 : 24, - 4 : 25, - 6 : 26, - 5 : 27, - 8 : 28, - 7 : 29, - 13 : 30, - 14 : 31, - 15 : 32, - 16 : 33, - 17 : 34, - 18 : 35, - 19 : 36, - 20 : 37, - 25 : 38, - 26 : 39, - 27 : 40, - 28 : 41, - 29 : 42, - 30 : 43, - 31 : 44, - 32 : 45, - 21 : 46, - 22 : 47, - 23 : 48, - 24 : 49, + 9: 18, + 10: 19, + 11: 20, + 12: 21, + 1: 22, + 2: 23, + 3: 24, + 4: 25, + 6: 26, + 5: 27, + 8: 28, + 7: 29, + 13: 30, + 14: 31, + 15: 32, + 16: 33, + 17: 34, + 18: 35, + 19: 36, + 20: 37, + 25: 38, + 26: 39, + 27: 40, + 28: 41, + 29: 42, + 30: 43, + 31: 44, + 32: 45, + 21: 46, + 22: 47, + 23: 48, + 24: 49, } - _qsfp_ports = range(0, ports_in_block + 1) + _qsfp_ports = list(range(0, ports_in_block + 1)) def __init__(self): # Override port_to_eeprom_mapping for class initialization @@ -67,14 +65,14 @@ def reset(self, port_num): path = "/sys/bus/i2c/devices/{0}-0050/sfp_port_reset" port_ps = path.format(self.port_to_i2c_mapping[port_num+1]) - + try: reg_file = open(port_ps, 'w') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False - #toggle reset + # toggle reset reg_file.seek(0) reg_file.write('1') time.sleep(1) @@ -88,7 +86,7 @@ def set_low_power_mode(self, port_nuM, lpmode): def get_low_power_mode(self, port_num): raise NotImplementedErro - + def get_presence(self, port_num): # Check for invalid port_num if port_num < self._port_start or port_num > self._port_end: @@ -103,9 +101,9 @@ def get_presence(self, port_num): reg_value = reg_file.readline().rstrip() reg_file.close() except IOError as e: - print "Error: unable to access file: %s" % str(e) + print("Error: unable to access file: %s" % str(e)) return False - + if reg_value == '1': return True @@ -118,14 +116,14 @@ def port_start(self): @property def port_end(self): return self._port_end - + @property def qsfp_ports(self): - return range(0, self.ports_in_block + 1) + return list(range(0, self.ports_in_block + 1)) - @property + @property def port_to_eeprom_mapping(self): - return self._port_to_eeprom_mapping + return self._port_to_eeprom_mapping def get_transceiver_change_event(self): """ diff --git a/device/accton/x86_64-accton_as7312_54x-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as7312_54x-r0/plugins/eeprom.py index 7681caafeef4..951384d5e37d 100644 --- a/device/accton/x86_64-accton_as7312_54x-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as7312_54x-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,14 +8,16 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom" - #Two i2c buses might get flipped order, check them both. + # Two i2c buses might get flipped order, check them both. if not os.path.exists(self.eeprom_path): self.eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/accton/x86_64-accton_as7312_54x-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as7312_54x-r0/plugins/psuutil.py index d73e65bf7981..a47dfcab7e94 100644 --- a/device/accton/x86_64-accton_as7312_54x-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as7312_54x-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Accton # @@ -13,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/accton/x86_64-accton_as7312_54x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7312_54x-r0/plugins/sfputil.py index 52b57e210ebb..7255b2d784e1 100644 --- a/device/accton/x86_64-accton_as7312_54x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7312_54x-r0/plugins/sfputil.py @@ -28,66 +28,66 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} _cpld_mapping = { - 0: "4-0060", - 1: "5-0062", - 2: "6-0064", - } + 0: "4-0060", + 1: "5-0062", + 2: "6-0064", + } _port_to_i2c_mapping = { - 1: 18, - 2: 19, - 3: 20, - 4: 21, - 5: 22, - 6: 23, - 7: 24, - 8: 25, - 9: 26, - 10: 27, - 11: 28, - 12: 29, - 13: 30, - 14: 31, - 15: 32, - 16: 33, - 17: 34, - 18: 35, - 19: 36, - 20: 37, - 21: 38, - 22: 39, - 23: 40, - 24: 41, - 25: 42, - 26: 43, - 27: 44, - 28: 45, - 29: 46, - 30: 47, - 31: 48, - 32: 49, - 33: 50, - 34: 51, - 35: 52, - 36: 53, - 37: 54, - 38: 55, - 39: 56, - 40: 57, - 41: 58, - 42: 59, - 43: 60, - 44: 61, - 45: 62, - 46: 63, - 47: 64, - 48: 65, - 49: 66, #QSFP49 - 50: 67, - 51: 68, - 52: 69, - 53: 70, - 54: 71, #QSFP54 - } + 1: 18, + 2: 19, + 3: 20, + 4: 21, + 5: 22, + 6: 23, + 7: 24, + 8: 25, + 9: 26, + 10: 27, + 11: 28, + 12: 29, + 13: 30, + 14: 31, + 15: 32, + 16: 33, + 17: 34, + 18: 35, + 19: 36, + 20: 37, + 21: 38, + 22: 39, + 23: 40, + 24: 41, + 25: 42, + 26: 43, + 27: 44, + 28: 45, + 29: 46, + 30: 47, + 31: 48, + 32: 49, + 33: 50, + 34: 51, + 35: 52, + 36: 53, + 37: 54, + 38: 55, + 39: 56, + 40: 57, + 41: 58, + 42: 59, + 43: 60, + 44: 61, + 45: 62, + 46: 63, + 47: 64, + 48: 65, + 49: 66, # QSFP49 + 50: 67, + 51: 68, + 52: 69, + 53: 70, + 54: 71, # QSFP54 + } @property def port_start(self): @@ -104,10 +104,10 @@ def qsfp_port_start(self): @property def qsfp_port_end(self): return self.QSFP_PORT_END - + @property def qsfp_ports(self): - return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -121,12 +121,12 @@ def __init__(self): SfpUtilBase.__init__(self) - def get_cpld_num(self, port_num): + def get_cpld_num(self, port_num): cpld_i = 1 if (port_num > 24 and port_num < self.qsfp_port_start): cpld_i = 2 - if (port_num > 52): + if (port_num > 52): cpld_i = 2 return cpld_i @@ -135,7 +135,7 @@ def get_presence(self, port_num): # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False - + cpld_i = self.get_cpld_num(port_num) cpld_ps = self._cpld_mapping[cpld_i] @@ -148,9 +148,9 @@ def get_presence(self, port_num): content = val_file.readline().rstrip() val_file.close() except IOError as e: - print "Error: unable to access file: %s" % str(e) + print("Error: unable to access file: %s" % str(e)) return False - + if content == "1": return True @@ -172,20 +172,21 @@ def get_low_power_mode(self, port_num): lpmode = ord(eeprom.read(1)) if ((lpmode & 0x3) == 0x3): - return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 + return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 else: - return False # High Power Mode if one of the following conditions is matched: - # 1. "Power override" bit is 0 - # 2. "Power override" bit is 1 and "Power set" bit is 0 + # High Power Mode if one of the following conditions is matched: + # 1. "Power override" bit is 0 + # 2. "Power override" bit is 1 and "Power set" bit is 0 + return False except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False finally: if eeprom is not None: eeprom.close() time.sleep(0.01) - def set_low_power_mode(self, port_num, lpmode): + def set_low_power_mode(self, port_num, lpmode): # Check for invalid port_num if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False @@ -194,10 +195,10 @@ def set_low_power_mode(self, port_num, lpmode): eeprom = None if not self.get_presence(port_num): - return False # Port is not present, unable to set the eeprom + return False # Port is not present, unable to set the eeprom # Fill in write buffer - regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode + regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode buffer = create_string_buffer(1) buffer[0] = chr(regval) @@ -207,7 +208,7 @@ def set_low_power_mode(self, port_num, lpmode): eeprom.write(buffer[0]) return True except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False finally: if eeprom is not None: @@ -217,7 +218,7 @@ def set_low_power_mode(self, port_num, lpmode): def reset(self, port_num): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False - + cpld_i = self.get_cpld_num(port_num) cpld_ps = self._cpld_mapping[cpld_i] path = "/sys/bus/i2c/devices/{0}/module_reset_{1}" @@ -225,14 +226,14 @@ def reset(self, port_num): try: reg_file = open(port_ps, 'w') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = '0' reg_file.write(reg_value) reg_file.close() - + return True def get_transceiver_change_event(self): diff --git a/device/accton/x86_64-accton_as7312_54xs-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as7312_54xs-r0/plugins/eeprom.py index 7681caafeef4..951384d5e37d 100644 --- a/device/accton/x86_64-accton_as7312_54xs-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as7312_54xs-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,14 +8,16 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom" - #Two i2c buses might get flipped order, check them both. + # Two i2c buses might get flipped order, check them both. if not os.path.exists(self.eeprom_path): self.eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/accton/x86_64-accton_as7312_54xs-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as7312_54xs-r0/plugins/psuutil.py index d73e65bf7981..a47dfcab7e94 100644 --- a/device/accton/x86_64-accton_as7312_54xs-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as7312_54xs-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Accton # @@ -13,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/accton/x86_64-accton_as7312_54xs-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7312_54xs-r0/plugins/sfputil.py index 90349ff53908..7d700fdaf90e 100644 --- a/device/accton/x86_64-accton_as7312_54xs-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7312_54xs-r0/plugins/sfputil.py @@ -28,66 +28,66 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} _cpld_mapping = { - 0: "4-0060", - 1: "5-0062", - 2: "6-0064", - } + 0: "4-0060", + 1: "5-0062", + 2: "6-0064", + } _port_to_i2c_mapping = { - 1: 18, - 2: 19, - 3: 20, - 4: 21, - 5: 22, - 6: 23, - 7: 24, - 8: 25, - 9: 26, - 10: 27, - 11: 28, - 12: 29, - 13: 30, - 14: 31, - 15: 32, - 16: 33, - 17: 34, - 18: 35, - 19: 36, - 20: 37, - 21: 38, - 22: 39, - 23: 40, - 24: 41, - 25: 42, - 26: 43, - 27: 44, - 28: 45, - 29: 46, - 30: 47, - 31: 48, - 32: 49, - 33: 50, - 34: 51, - 35: 52, - 36: 53, - 37: 54, - 38: 55, - 39: 56, - 40: 57, - 41: 58, - 42: 59, - 43: 60, - 44: 61, - 45: 62, - 46: 63, - 47: 64, - 48: 65, - 49: 66, #QSFP49 - 50: 67, - 51: 68, - 52: 69, - 53: 70, - 54: 71, #QSFP54 - } + 1: 18, + 2: 19, + 3: 20, + 4: 21, + 5: 22, + 6: 23, + 7: 24, + 8: 25, + 9: 26, + 10: 27, + 11: 28, + 12: 29, + 13: 30, + 14: 31, + 15: 32, + 16: 33, + 17: 34, + 18: 35, + 19: 36, + 20: 37, + 21: 38, + 22: 39, + 23: 40, + 24: 41, + 25: 42, + 26: 43, + 27: 44, + 28: 45, + 29: 46, + 30: 47, + 31: 48, + 32: 49, + 33: 50, + 34: 51, + 35: 52, + 36: 53, + 37: 54, + 38: 55, + 39: 56, + 40: 57, + 41: 58, + 42: 59, + 43: 60, + 44: 61, + 45: 62, + 46: 63, + 47: 64, + 48: 65, + 49: 66, # QSFP49 + 50: 67, + 51: 68, + 52: 69, + 53: 70, + 54: 71, # QSFP54 + } @property def port_start(self): @@ -104,10 +104,10 @@ def qsfp_port_start(self): @property def qsfp_port_end(self): return self.QSFP_PORT_END - + @property def qsfp_ports(self): - return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -121,12 +121,12 @@ def __init__(self): SfpUtilBase.__init__(self) - def get_cpld_num(self, port_num): + def get_cpld_num(self, port_num): cpld_i = 1 if (port_num > 24 and port_num < self.qsfp_port_start): cpld_i = 2 - if (port_num > 52): + if (port_num > 52): cpld_i = 2 return cpld_i @@ -135,7 +135,7 @@ def get_presence(self, port_num): # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False - + cpld_i = self.get_cpld_num(port_num) cpld_ps = self._cpld_mapping[cpld_i] @@ -148,7 +148,7 @@ def get_presence(self, port_num): content = val_file.readline().rstrip() val_file.close() except IOError as e: - print "Error: unable to access file: %s" % str(e) + print("Error: unable to access file: %s" % str(e)) return False # content is a string, either "0" or "1" @@ -173,20 +173,21 @@ def get_low_power_mode(self, port_num): lpmode = ord(eeprom.read(1)) if ((lpmode & 0x3) == 0x3): - return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 + return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 else: - return False # High Power Mode if one of the following conditions is matched: - # 1. "Power override" bit is 0 - # 2. "Power override" bit is 1 and "Power set" bit is 0 + # High Power Mode if one of the following conditions is matched: + # 1. "Power override" bit is 0 + # 2. "Power override" bit is 1 and "Power set" bit is 0 + return False except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False finally: if eeprom is not None: eeprom.close() time.sleep(0.01) - def set_low_power_mode(self, port_num, lpmode): + def set_low_power_mode(self, port_num, lpmode): # Check for invalid port_num if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False @@ -195,10 +196,10 @@ def set_low_power_mode(self, port_num, lpmode): eeprom = None if not self.get_presence(port_num): - return False # Port is not present, unable to set the eeprom + return False # Port is not present, unable to set the eeprom # Fill in write buffer - regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode + regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode buffer = create_string_buffer(1) buffer[0] = chr(regval) @@ -208,7 +209,7 @@ def set_low_power_mode(self, port_num, lpmode): eeprom.write(buffer[0]) return True except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False finally: if eeprom is not None: @@ -218,7 +219,7 @@ def set_low_power_mode(self, port_num, lpmode): def reset(self, port_num): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False - + cpld_i = self.get_cpld_num(port_num) cpld_ps = self._cpld_mapping[cpld_i] path = "/sys/bus/i2c/devices/{0}/module_reset_{1}" @@ -226,14 +227,14 @@ def reset(self, port_num): try: reg_file = open(port_ps, 'w') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = '0' reg_file.write(reg_value) reg_file.close() - + return True def get_transceiver_change_event(self): diff --git a/device/accton/x86_64-accton_as7315_27xb-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as7315_27xb-r0/plugins/eeprom.py index 171593068ae5..6f7ad9ef091d 100644 --- a/device/accton/x86_64-accton_as7315_27xb-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as7315_27xb-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,11 +8,13 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/4-0057/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/accton/x86_64-accton_as7315_27xb-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as7315_27xb-r0/plugins/psuutil.py index 7ec16640e5a8..dbc0a1170251 100644 --- a/device/accton/x86_64-accton_as7315_27xb-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as7315_27xb-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Accton # @@ -13,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/accton/x86_64-accton_as7315_27xb-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7315_27xb-r0/plugins/sfputil.py index dc37f5ea360c..1a1b61d1e659 100644 --- a/device/accton/x86_64-accton_as7315_27xb-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7315_27xb-r0/plugins/sfputil.py @@ -12,10 +12,11 @@ except ImportError as e: raise ImportError("%s - required module not found" % str(e)) -#from xcvrd +# from xcvrd SFP_STATUS_REMOVED = '0' SFP_STATUS_INSERTED = '1' + class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" @@ -31,37 +32,37 @@ class SfpUtil(SfpUtilBase): _port_to_lp_mode = {} _port_to_eeprom_mapping = {} - _cpld_mapping = [ "8-0063", "7-0064"] + _cpld_mapping = ["8-0063", "7-0064"] _port_to_i2c_mapping = { - 1: 26, - 2: 27, - 3: 28, - 4: 29, - 5: 30, - 6: 31, - 7: 32, - 8: 33, - 9: 34, - 10: 35, - 11: 36, - 12: 37, - 13: 38, - 14: 39, - 15: 40, - 16: 41, - 17: 42, - 18: 43, - 19: 44, - 20: 45, - 21: 46, - 22: 47, - 23: 48, - 24: 49, - 25: 21, #QSFP - 26: 22, - 27: 23, - } + 1: 26, + 2: 27, + 3: 28, + 4: 29, + 5: 30, + 6: 31, + 7: 32, + 8: 33, + 9: 34, + 10: 35, + 11: 36, + 12: 37, + 13: 38, + 14: 39, + 15: 40, + 16: 41, + 17: 42, + 18: 43, + 19: 44, + 20: 45, + 21: 46, + 22: 47, + 23: 48, + 24: 49, + 25: 21, # QSFP + 26: 22, + 27: 23, + } @property def port_start(self): @@ -78,10 +79,10 @@ def qsfp_port_start(self): @property def qsfp_port_end(self): return self.QSFP_PORT_END - + @property def qsfp_ports(self): - return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -96,7 +97,7 @@ def __init__(self): self.get_transceiver_change_event() SfpUtilBase.__init__(self) - def get_cpld_num(self, port_num): + def get_cpld_num(self, port_num): cpld_i = 0 if (port_num >= self.qsfp_port_start): cpld_i = 1 @@ -107,11 +108,11 @@ def get_presence(self, port_num): # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False - + cpld_i = self.get_cpld_num(port_num) cpld_ps = self._cpld_mapping[cpld_i] path = "/sys/bus/i2c/devices/{0}/present_{1}" - index = ((port_num-1)%24) +1 + index = ((port_num-1) % 24) + 1 port_ps = path.format(cpld_ps, index) content = "0" @@ -120,9 +121,9 @@ def get_presence(self, port_num): content = val_file.readline().rstrip() val_file.close() except IOError as e: - print "Error: unable to access file: %s" % str(e) + print("Error: unable to access file: %s" % str(e)) return False - + if content == "1": return True @@ -144,20 +145,21 @@ def get_low_power_mode(self, port_num): lpmode = ord(eeprom.read(1)) if ((lpmode & 0x3) == 0x3): - return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 + return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 else: - return False # High Power Mode if one of the following conditions is matched: - # 1. "Power override" bit is 0 - # 2. "Power override" bit is 1 and "Power set" bit is 0 + # High Power Mode if one of the following conditions is matched: + # 1. "Power override" bit is 0 + # 2. "Power override" bit is 1 and "Power set" bit is 0 + return False except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False finally: if eeprom is not None: eeprom.close() time.sleep(0.01) - def set_low_power_mode(self, port_num, lpmode): + def set_low_power_mode(self, port_num, lpmode): # Check for invalid port_num if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False @@ -166,10 +168,10 @@ def set_low_power_mode(self, port_num, lpmode): eeprom = None if not self.get_presence(port_num): - return False # Port is not present, unable to set the eeprom + return False # Port is not present, unable to set the eeprom # Fill in write buffer - regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode + regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode buffer = create_string_buffer(1) buffer[0] = chr(regval) @@ -179,7 +181,7 @@ def set_low_power_mode(self, port_num, lpmode): eeprom.write(buffer[0]) return True except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False finally: if eeprom is not None: @@ -187,14 +189,14 @@ def set_low_power_mode(self, port_num, lpmode): time.sleep(0.01) def reset(self, port_num): - raise NotImplementedError + raise NotImplementedError @property def _get_present_bitmap(self): nodes = [] - port_num = [24,3] + port_num = [24, 3] - path = "/sys/bus/i2c/devices/{0}/" + path = "/sys/bus/i2c/devices/{0}/" cpld_path = path.format(self._cpld_mapping[0]) nodes.append((cpld_path + "module_present_all", port_num[0])) cpld_path = path.format(self._cpld_mapping[1]) @@ -206,16 +208,17 @@ def _get_present_bitmap(self): reg_file = open(node[0]) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False cpld_bm = reg_file.readline().rstrip().zfill(node[1]/4) bitmap.append(cpld_bm) reg_file.close() rev = "".join(bitmap[::-1]) - return int(rev,16) + return int(rev, 16) + + data = {'valid': 0, 'last': 0, 'present': 0} - data = {'valid':0, 'last':0, 'present':0} def get_transceiver_change_event(self, timeout=2000): now = time.time() port_dict = {} @@ -223,7 +226,7 @@ def get_transceiver_change_event(self, timeout=2000): if timeout < 1000: timeout = 1000 - timeout = (timeout) / float(1000) # Convert to secs + timeout = (timeout) / float(1000) # Convert to secs if now < (self.data['last'] + timeout) and self.data['valid']: return True, {} @@ -231,7 +234,7 @@ def get_transceiver_change_event(self, timeout=2000): reg_value = self._get_present_bitmap changed_ports = self.data['present'] ^ reg_value if changed_ports: - for port in range (self.port_start, self.port_end+1): + for port in range(self.port_start, self.port_end+1): # Mask off the bit corresponding to our port mask = (1 << (port - 1)) if changed_ports & mask: @@ -249,5 +252,3 @@ def get_transceiver_change_event(self, timeout=2000): else: return True, {} return False, {} - - diff --git a/device/accton/x86_64-accton_as7326_56x-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as7326_56x-r0/plugins/eeprom.py index 1e7d1046d93d..4241483d68eb 100644 --- a/device/accton/x86_64-accton_as7326_56x-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as7326_56x-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,11 +8,13 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/0-0056/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/accton/x86_64-accton_as7326_56x-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as7326_56x-r0/plugins/psuutil.py index a3c30bc478e7..c215bb896772 100644 --- a/device/accton/x86_64-accton_as7326_56x-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as7326_56x-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Accton # @@ -13,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/accton/x86_64-accton_as7326_56x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7326_56x-r0/plugins/sfputil.py index f9e0aae1b2a9..965e876691c8 100644 --- a/device/accton/x86_64-accton_as7326_56x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7326_56x-r0/plugins/sfputil.py @@ -11,10 +11,11 @@ except ImportError as e: raise ImportError("%s - required module not found" % str(e)) -#from xcvrd +# from xcvrd SFP_STATUS_REMOVED = '0' SFP_STATUS_INSERTED = '1' + class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" @@ -31,69 +32,69 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} _cpld_mapping = { - 1: "12-0062", - 2: "18-0060", - 3: "19-0064", - } + 1: "12-0062", + 2: "18-0060", + 3: "19-0064", + } _port_to_i2c_mapping = { - 1: 42, - 2: 41, - 3: 44, - 4: 43, - 5: 47, - 6: 45, - 7: 46, - 8: 50, - 9: 48, - 10: 49, - 11: 52, - 12: 51, - 13: 53, - 14: 56, - 15: 55, - 16: 54, - 17: 58, - 18: 57, - 19: 60, - 20: 59, - 21: 61, - 22: 63, - 23: 62, - 24: 64, - 25: 66, - 26: 68, - 27: 65, - 28: 67, - 29: 69, - 30: 71, - 31: 72, - 32: 70, - 33: 74, - 34: 73, - 35: 76, - 36: 75, - 37: 77, - 38: 79, - 39: 78, - 40: 80, - 41: 81, - 42: 82, - 43: 84, - 44: 85, - 45: 83, - 46: 87, - 47: 88, - 48: 86, - 49: 25,#QSFP49 - 50: 26, - 51: 27, - 52: 28, - 53: 29, - 54: 30, - 55: 31, - 56: 32,#QSFP56 - } + 1: 42, + 2: 41, + 3: 44, + 4: 43, + 5: 47, + 6: 45, + 7: 46, + 8: 50, + 9: 48, + 10: 49, + 11: 52, + 12: 51, + 13: 53, + 14: 56, + 15: 55, + 16: 54, + 17: 58, + 18: 57, + 19: 60, + 20: 59, + 21: 61, + 22: 63, + 23: 62, + 24: 64, + 25: 66, + 26: 68, + 27: 65, + 28: 67, + 29: 69, + 30: 71, + 31: 72, + 32: 70, + 33: 74, + 34: 73, + 35: 76, + 36: 75, + 37: 77, + 38: 79, + 39: 78, + 40: 80, + 41: 81, + 42: 82, + 43: 84, + 44: 85, + 45: 83, + 46: 87, + 47: 88, + 48: 86, + 49: 25, # QSFP49 + 50: 26, + 51: 27, + 52: 28, + 53: 29, + 54: 30, + 55: 31, + 56: 32, # QSFP56 + } @property def port_start(self): @@ -113,7 +114,7 @@ def qsfp_port_end(self): @property def qsfp_ports(self): - return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -145,13 +146,13 @@ def get_presence(self, port_num): path = "/sys/bus/i2c/devices/{0}/module_present_{1}" port_ps = path.format(cpld_ps, port_num) - content="0" + content = "0" try: val_file = open(port_ps) content = val_file.readline().rstrip() val_file.close() except IOError as e: - print "Error: unable to access file: %s" % str(e) + print("Error: unable to access file: %s" % str(e)) return False if content == "1": @@ -175,14 +176,15 @@ def get_low_power_mode(self, port_num): lpmode = ord(eeprom.read(1)) if ((lpmode & 0x3) == 0x3): - return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 + return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 else: - return False # High Power Mode if one of the following conditions is matched: - # 1. "Power override" bit is 0 - # 2. "Power override" bit is 1 and "Power set" bit is 0 + # High Power Mode if one of the following conditions is matched: + # 1. "Power override" bit is 0 + # 2. "Power override" bit is 1 and "Power set" bit is 0 + return False except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False finally: if eeprom is not None: @@ -198,10 +200,10 @@ def set_low_power_mode(self, port_num, lpmode): eeprom = None if not self.get_presence(port_num): - return False # Port is not present, unable to set the eeprom + return False # Port is not present, unable to set the eeprom # Fill in write buffer - regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode + regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode buffer = create_string_buffer(1) buffer[0] = chr(regval) @@ -211,7 +213,7 @@ def set_low_power_mode(self, port_num, lpmode): eeprom.write(buffer[0]) return True except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False finally: if eeprom is not None: @@ -226,28 +228,29 @@ def reset(self, port_num): cpld_ps = self._cpld_mapping[cpld_i] path = "/sys/bus/i2c/devices/{0}/module_reset_{1}" port_ps = path.format(cpld_ps, port_num) - + self.__port_to_mod_rst = port_ps try: reg_file = open(self.__port_to_mod_rst, 'r+', buffering=0) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False - #toggle reset + # toggle reset reg_file.seek(0) reg_file.write('1') time.sleep(1) reg_file.seek(0) reg_file.write('0') reg_file.close() - + return True + @property def _get_present_bitmap(self): nodes = [] rev = [] - port_num = [30,26] + port_num = [30, 26] path = "/sys/bus/i2c/devices/{0}/module_present_all" cpld_i = self.get_cpld_num(self.port_start) @@ -262,7 +265,7 @@ def _get_present_bitmap(self): try: reg_file = open(node[0]) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False bitmap = reg_file.readline().rstrip() bitmap = bin(int(bitmap, 16))[2:].zfill(node[1]) @@ -273,7 +276,8 @@ def _get_present_bitmap(self): bitmaps = hex(int(bitmaps, 2)) return int(bitmaps, 0) - data = {'valid':0, 'last':0, 'present':0} + data = {'valid': 0, 'last': 0, 'present': 0} + def get_transceiver_change_event(self, timeout=2000): now = time.time() port_dict = {} @@ -281,7 +285,7 @@ def get_transceiver_change_event(self, timeout=2000): if timeout < 1000: timeout = 1000 - timeout = (timeout) / float(1000) # Convert to secs + timeout = (timeout) / float(1000) # Convert to secs if now < (self.data['last'] + timeout) and self.data['valid']: return True, {} @@ -289,7 +293,7 @@ def get_transceiver_change_event(self, timeout=2000): reg_value = self._get_present_bitmap changed_ports = self.data['present'] ^ reg_value if changed_ports: - for port in range (self.port_start, self.port_end+1): + for port in range(self.port_start, self.port_end+1): # Mask off the bit corresponding to our port mask = (1 << (port - 1)) if changed_ports & mask: diff --git a/device/accton/x86_64-accton_as7512_32x-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as7512_32x-r0/plugins/eeprom.py index 6e2c0c8bb96f..f2f0703f0a11 100644 --- a/device/accton/x86_64-accton_as7512_32x-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as7512_32x-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Cavium # @@ -10,7 +8,6 @@ ############################################################################# try: - import exceptions import binascii import time import optparse @@ -20,8 +17,9 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/accton/x86_64-accton_as7512_32x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7512_32x-r0/plugins/sfputil.py index a4f405fa6afd..a999ecc24092 100644 --- a/device/accton/x86_64-accton_as7512_32x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7512_32x-r0/plugins/sfputil.py @@ -5,8 +5,8 @@ import string from ctypes import create_string_buffer from sonic_sfp.sfputilbase import SfpUtilBase -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") class SfpUtil(SfpUtilBase): @@ -16,11 +16,10 @@ class SfpUtil(SfpUtilBase): _port_end = 31 ports_in_block = 32 - _port_to_eeprom_mapping = {} - _qsfp_ports = range(0, ports_in_block + 1) - + _qsfp_ports = list(range(0, ports_in_block + 1)) + def __init__(self): # Override port_to_eeprom_mapping for class initialization eeprom_path = '/sys/bus/i2c/devices/{0}-0050/sfp_eeprom' @@ -45,9 +44,9 @@ def get_presence(self, port_num): reg_value = reg_file.readline().rstrip() reg_file.close() except IOError as e: - print "Error: unable to access file: %s" % str(e) + print("Error: unable to access file: %s" % str(e)) return False - + if reg_value == '1': return True @@ -63,7 +62,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(0, self.ports_in_block + 1) + return list(range(0, self.ports_in_block + 1)) @property def port_to_eeprom_mapping(self): @@ -93,20 +92,21 @@ def get_low_power_mode(self, port_num): lpmode = ord(eeprom.read(1)) if ((lpmode & 0x3) == 0x3): - return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 + return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 else: - return False # High Power Mode if one of the following conditions is matched: - # 1. "Power override" bit is 0 - # 2. "Power override" bit is 1 and "Power set" bit is 0 + # High Power Mode if one of the following conditions is matched: + # 1. "Power override" bit is 0 + # 2. "Power override" bit is 1 and "Power set" bit is 0 + return False except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False finally: if eeprom is not None: eeprom.close() time.sleep(0.01) - def set_low_power_mode(self, port_num, 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 @@ -115,10 +115,10 @@ def set_low_power_mode(self, port_num, lpmode): eeprom = None if not self.get_presence(port_num): - return False # Port is not present, unable to set the eeprom + return False # Port is not present, unable to set the eeprom # Fill in write buffer - regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode + regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode buffer = create_string_buffer(1) buffer[0] = chr(regval) @@ -128,9 +128,9 @@ def set_low_power_mode(self, port_num, lpmode): eeprom.write(buffer[0]) return True except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False finally: if eeprom is not None: eeprom.close() - time.sleep(0.01) \ No newline at end of file + time.sleep(0.01) diff --git a/device/accton/x86_64-accton_as7712_32x-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as7712_32x-r0/plugins/eeprom.py index 7681caafeef4..951384d5e37d 100644 --- a/device/accton/x86_64-accton_as7712_32x-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as7712_32x-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,14 +8,16 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom" - #Two i2c buses might get flipped order, check them both. + # Two i2c buses might get flipped order, check them both. if not os.path.exists(self.eeprom_path): self.eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/accton/x86_64-accton_as7712_32x-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as7712_32x-r0/plugins/psuutil.py index d7600a2af4b1..a9133f8adccb 100644 --- a/device/accton/x86_64-accton_as7712_32x-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as7712_32x-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Accton # @@ -13,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/accton/x86_64-accton_as7712_32x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7712_32x-r0/plugins/sfputil.py index 8cfde932e7e3..079a533e4e7d 100644 --- a/device/accton/x86_64-accton_as7712_32x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7712_32x-r0/plugins/sfputil.py @@ -1,14 +1,12 @@ -#!/usr/bin/env python - try: import time import string from ctypes import create_string_buffer - from sonic_sfp.sfputilbase import SfpUtilBase -except ImportError, e: - raise ImportError (str(e) + "- required module not found") + from sonic_sfp.sfputilbase import SfpUtilBase +except ImportError as e: + raise ImportError(str(e) + "- required module not found") -#from xcvrd +# from xcvrd SFP_STATUS_INSERTED = '1' SFP_STATUS_REMOVED = '0' @@ -22,41 +20,41 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} port_to_i2c_mapping = { - 9 : 18, - 10 : 19, - 11 : 20, - 12 : 21, - 1 : 22, - 2 : 23, - 3 : 24, - 4 : 25, - 6 : 26, - 5 : 27, - 8 : 28, - 7 : 29, - 13 : 30, - 14 : 31, - 15 : 32, - 16 : 33, - 17 : 34, - 18 : 35, - 19 : 36, - 20 : 37, - 25 : 38, - 26 : 39, - 27 : 40, - 28 : 41, - 29 : 42, - 30 : 43, - 31 : 44, - 32 : 45, - 21 : 46, - 22 : 47, - 23 : 48, - 24 : 49, + 9: 18, + 10: 19, + 11: 20, + 12: 21, + 1: 22, + 2: 23, + 3: 24, + 4: 25, + 6: 26, + 5: 27, + 8: 28, + 7: 29, + 13: 30, + 14: 31, + 15: 32, + 16: 33, + 17: 34, + 18: 35, + 19: 36, + 20: 37, + 25: 38, + 26: 39, + 27: 40, + 28: 41, + 29: 42, + 30: 43, + 31: 44, + 32: 45, + 21: 46, + 22: 47, + 23: 48, + 24: 49, } - _qsfp_ports = range(0, ports_in_block + 1) + _qsfp_ports = list(range(0, ports_in_block + 1)) def __init__(self): eeprom_path = '/sys/bus/i2c/devices/{0}-0050/eeprom' @@ -72,14 +70,14 @@ def reset(self, port_num): path = "/sys/bus/i2c/devices/4-0060/module_reset_{0}" port_ps = path.format(port_num) - + try: reg_file = open(port_ps, 'w', buffering=0) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False - #toggle reset + # toggle reset reg_file.seek(0) reg_file.write('1') time.sleep(1) @@ -87,7 +85,7 @@ def reset(self, port_num): reg_file.write('0') reg_file.close() return True - + def get_presence(self, port_num): # Check for invalid port_num if port_num < self._port_start or port_num > self._port_end: @@ -102,9 +100,9 @@ def get_presence(self, port_num): reg_value = reg_file.readline().rstrip() reg_file.close() except IOError as e: - print "Error: unable to access file: %s" % str(e) + print("Error: unable to access file: %s" % str(e)) return False - + if reg_value == '1': return True @@ -117,14 +115,14 @@ def port_start(self): @property def port_end(self): return self._port_end - + @property def qsfp_ports(self): - return range(self.port_start, self.ports_in_block + 1) + return list(range(self.port_start, self.ports_in_block + 1)) - @property + @property def port_to_eeprom_mapping(self): - return self._port_to_eeprom_mapping + return self._port_to_eeprom_mapping def get_low_power_mode(self, port_num): # Check for invalid port_num @@ -142,20 +140,21 @@ def get_low_power_mode(self, port_num): lpmode = ord(eeprom.read(1)) if ((lpmode & 0x3) == 0x3): - return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 + return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 else: - return False # High Power Mode if one of the following conditions is matched: - # 1. "Power override" bit is 0 - # 2. "Power override" bit is 1 and "Power set" bit is 0 + # High Power Mode if one of the following conditions is matched: + # 1. "Power override" bit is 0 + # 2. "Power override" bit is 1 and "Power set" bit is 0 + return False except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False finally: if eeprom is not None: eeprom.close() time.sleep(0.01) - def set_low_power_mode(self, port_num, 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 @@ -164,10 +163,10 @@ def set_low_power_mode(self, port_num, lpmode): eeprom = None if not self.get_presence(port_num): - return False # Port is not present, unable to set the eeprom + return False # Port is not present, unable to set the eeprom # Fill in write buffer - regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode + regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode buffer = create_string_buffer(1) buffer[0] = chr(regval) @@ -177,7 +176,7 @@ def set_low_power_mode(self, port_num, lpmode): eeprom.write(buffer[0]) return True except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False finally: if eeprom is not None: @@ -197,16 +196,17 @@ def _get_all_presence(self): reg_file = open(node) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False bitmap += reg_file.readline().rstrip() + " " reg_file.close() rev = bitmap.split(" ") rev = "".join(rev[::-1]) - return int(rev,16) + return int(rev, 16) + + data = {'valid': 0, 'last': 0, 'present': 0} - data = {'valid':0, 'last':0, 'present':0} def get_transceiver_change_event(self, timeout=2000): now = time.time() port_dict = {} @@ -214,7 +214,7 @@ def get_transceiver_change_event(self, timeout=2000): if timeout < 1000: timeout = 1000 - timeout = (timeout) / float(1000) # Convert to secs + timeout = (timeout) / float(1000) # Convert to secs if now < (self.data['last'] + timeout) and self.data['valid']: return True, {} @@ -222,7 +222,7 @@ def get_transceiver_change_event(self, timeout=2000): reg_value = self._get_all_presence changed_ports = self.data['present'] ^ reg_value if changed_ports: - for port in range (self.port_start, self.port_end+1): + for port in range(self.port_start, self.port_end+1): # Mask off the bit corresponding to our port mask = (1 << (port - 1)) if changed_ports & mask: @@ -239,4 +239,3 @@ def get_transceiver_change_event(self, timeout=2000): else: return True, {} return False, {} - diff --git a/device/accton/x86_64-accton_as7716_32x-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as7716_32x-r0/plugins/eeprom.py index c0122e65844a..9e4e9970e9f5 100755 --- a/device/accton/x86_64-accton_as7716_32x-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as7716_32x-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,14 +8,16 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/1-0056/eeprom" - #Two i2c buses might get flipped order, check them both. + # Two i2c buses might get flipped order, check them both. if not os.path.exists(self.eeprom_path): self.eeprom_path = "/sys/bus/i2c/devices/0-0056/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/accton/x86_64-accton_as7716_32x-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as7716_32x-r0/plugins/psuutil.py index d8fddc23550b..5c18e6f51b8e 100755 --- a/device/accton/x86_64-accton_as7716_32x-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as7716_32x-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Accton # @@ -13,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/accton/x86_64-accton_as7716_32x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7716_32x-r0/plugins/sfputil.py index b8e4e8d1317d..7af5098d52f0 100755 --- a/device/accton/x86_64-accton_as7716_32x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7716_32x-r0/plugins/sfputil.py @@ -10,7 +10,7 @@ from sonic_sfp.sfputilbase import SfpUtilBase except ImportError as e: raise ImportError("%s - required module not found" % str(e)) -#from xcvrd +# from xcvrd SFP_STATUS_REMOVED = '0' SFP_STATUS_INSERTED = '1' @@ -21,48 +21,48 @@ class SfpUtil(SfpUtilBase): PORT_START = 1 PORT_END = 32 PORTS_IN_BLOCK = 32 - + BASE_OOM_PATH = "/sys/bus/i2c/devices/{0}-0050/" BASE_CPLD_PATH = "/sys/bus/i2c/devices/11-0060/" - + _port_to_is_present = {} _port_to_lp_mode = {} _port_to_eeprom_mapping = {} _port_to_i2c_mapping = { - 1: 29, - 2: 30, - 3: 31, - 4: 32, - 5: 34, - 6: 33, - 7: 36, - 8: 35, - 9: 25, - 10: 26, - 11: 27, - 12: 28, - 13: 37, - 14: 38, - 15: 39, - 16: 40, - 17: 41, - 18: 42, - 19: 43, - 20: 44, - 21: 53, - 22: 54, - 23: 55, - 24: 56, - 25: 45, - 26: 46, - 27: 47, - 28: 48, - 29: 49, - 30: 50, - 31: 51, - 32: 52, - } + 1: 29, + 2: 30, + 3: 31, + 4: 32, + 5: 34, + 6: 33, + 7: 36, + 8: 35, + 9: 25, + 10: 26, + 11: 27, + 12: 28, + 13: 37, + 14: 38, + 15: 39, + 16: 40, + 17: 41, + 18: 42, + 19: 43, + 20: 44, + 21: 53, + 22: 54, + 23: 55, + 24: 56, + 25: 45, + 26: 46, + 27: 47, + 28: 48, + 29: 49, + 30: 50, + 31: 51, + 32: 52, + } @property def port_start(self): @@ -71,10 +71,10 @@ def port_start(self): @property def port_end(self): return self.PORT_END - + @property def qsfp_ports(self): - return range(self.PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -83,17 +83,17 @@ def port_to_eeprom_mapping(self): def __init__(self): eeprom_path = self.BASE_OOM_PATH + "eeprom" - for x in range(self.port_start, self.port_end+1): + for x in range(self.port_start, self.port_end+1): self.port_to_eeprom_mapping[x] = eeprom_path.format( self._port_to_i2c_mapping[x] - ) + ) SfpUtilBase.__init__(self) def get_presence(self, port_num): # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False - + present_path = self.BASE_CPLD_PATH + "module_present_" + str(port_num) self.__port_to_is_present = present_path @@ -103,9 +103,9 @@ def get_presence(self, port_num): content = val_file.readline().rstrip() val_file.close() except IOError as e: - print "Error: unable to access file: %s" % str(e) + print("Error: unable to access file: %s" % str(e)) return False - + if content == "1": return True @@ -127,20 +127,21 @@ def get_low_power_mode(self, port_num): lpmode = ord(eeprom.read(1)) if ((lpmode & 0x3) == 0x3): - return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 + return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 else: - return False # High Power Mode if one of the following conditions is matched: - # 1. "Power override" bit is 0 - # 2. "Power override" bit is 1 and "Power set" bit is 0 + # High Power Mode if one of the following conditions is matched: + # 1. "Power override" bit is 0 + # 2. "Power override" bit is 1 and "Power set" bit is 0 + return False except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False finally: if eeprom is not None: eeprom.close() time.sleep(0.01) - def set_low_power_mode(self, port_num, 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 @@ -149,10 +150,10 @@ def set_low_power_mode(self, port_num, lpmode): eeprom = None if not self.get_presence(port_num): - return False # Port is not present, unable to set the eeprom + return False # Port is not present, unable to set the eeprom # Fill in write buffer - regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode + regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode buffer = create_string_buffer(1) buffer[0] = chr(regval) @@ -162,7 +163,7 @@ def set_low_power_mode(self, port_num, lpmode): eeprom.write(buffer[0]) return True except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False finally: if eeprom is not None: @@ -172,20 +173,20 @@ def set_low_power_mode(self, port_num, lpmode): def reset(self, port_num): if port_num < self.port_start or port_num > self.port_end: return False - + mod_rst_path = self.BASE_CPLD_PATH + "module_reset_" + str(port_num) self.__port_to_mod_rst = mod_rst_path try: reg_file = open(self.__port_to_mod_rst, 'r+') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = '1' reg_file.write(reg_value) reg_file.close() - + return True @property @@ -199,16 +200,17 @@ def _get_present_bitmap(self): reg_file = open(node) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False bitmap += reg_file.readline().rstrip() + " " reg_file.close() rev = bitmap.split(" ") rev = "".join(rev[::-1]) - return int(rev,16) + return int(rev, 16) + + data = {'valid': 0, 'last': 0, 'present': 0} - data = {'valid':0, 'last':0, 'present':0} def get_transceiver_change_event(self, timeout=2000): now = time.time() port_dict = {} @@ -216,7 +218,7 @@ def get_transceiver_change_event(self, timeout=2000): if timeout < 1000: timeout = 1000 - timeout = (timeout) / float(1000) # Convert to secs + timeout = (timeout) / float(1000) # Convert to secs if now < (self.data['last'] + timeout) and self.data['valid']: return True, {} @@ -224,7 +226,7 @@ def get_transceiver_change_event(self, timeout=2000): reg_value = self._get_present_bitmap changed_ports = self.data['present'] ^ reg_value if changed_ports: - for port in range (self.port_start, self.port_end+1): + for port in range(self.port_start, self.port_end+1): # Mask off the bit corresponding to our port mask = (1 << (port - 1)) if changed_ports & mask: @@ -241,4 +243,3 @@ def get_transceiver_change_event(self, timeout=2000): else: return True, {} return False, {} - diff --git a/device/accton/x86_64-accton_as7716_32xb-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as7716_32xb-r0/plugins/eeprom.py index 6fa5719afbad..0982e699367a 100755 --- a/device/accton/x86_64-accton_as7716_32xb-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as7716_32xb-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,14 +8,16 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/0-0056/eeprom" - #Two i2c buses might get flipped order, check them both. + # Two i2c buses might get flipped order, check them both. if not os.path.exists(self.eeprom_path): self.eeprom_path = "/sys/bus/i2c/devices/0-0056/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/accton/x86_64-accton_as7716_32xb-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as7716_32xb-r0/plugins/psuutil.py index 5a4b0fe83d87..d4815ac85cec 100755 --- a/device/accton/x86_64-accton_as7716_32xb-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as7716_32xb-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Accton # @@ -13,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/accton/x86_64-accton_as7716_32xb-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7716_32xb-r0/plugins/sfputil.py index 8bc5869e6b94..af8b9dd2fa02 100755 --- a/device/accton/x86_64-accton_as7716_32xb-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7716_32xb-r0/plugins/sfputil.py @@ -6,8 +6,8 @@ try: import time import os - import sys, getopt - import commands + import sys + import subprocess from sonic_sfp.sfputilbase import SfpUtilBase except ImportError as e: raise ImportError("%s - required module not found" % str(e)) @@ -19,49 +19,49 @@ class SfpUtil(SfpUtilBase): PORT_START = 0 PORT_END = 31 PORTS_IN_BLOCK = 32 - + BASE_OOM_PATH = "/sys/bus/i2c/devices/{0}-0050/" BASE_CPLD_PATH = "/sys/bus/i2c/devices/0-0060/" BASE_I2C_PATH = "/sys/bus/i2c/devices/" - + _port_to_is_present = {} _port_to_lp_mode = {} _port_to_eeprom_mapping = {} _port_to_i2c_mapping = { - 0: [1, 29], - 1: [2, 30], - 2: [3, 31], - 3: [4, 32], - 4: [5, 34], - 5: [6, 33], - 6: [7, 36], - 7: [8, 35], - 8: [9, 25], - 9: [10, 26], - 10: [11, 27], - 11: [12, 28], - 12: [14, 37], - 13: [15, 38], - 14: [16, 39], - 15: [17, 40], - 16: [18, 41], - 17: [19, 42], - 18: [20, 43], - 19: [21, 44], - 20: [22, 53], - 21: [23, 54], - 22: [24, 55], - 23: [25, 56], - 24: [26, 45], - 25: [27, 46], - 26: [28, 47], - 27: [29, 48], - 28: [30, 49], - 29: [31, 50], - 30: [32, 51], - 31: [33, 52], - } + 0: [1, 29], + 1: [2, 30], + 2: [3, 31], + 3: [4, 32], + 4: [5, 34], + 5: [6, 33], + 6: [7, 36], + 7: [8, 35], + 8: [9, 25], + 9: [10, 26], + 10: [11, 27], + 11: [12, 28], + 12: [14, 37], + 13: [15, 38], + 14: [16, 39], + 15: [17, 40], + 16: [18, 41], + 17: [19, 42], + 18: [20, 43], + 19: [21, 44], + 20: [22, 53], + 21: [23, 54], + 22: [24, 55], + 23: [25, 56], + 24: [26, 45], + 25: [27, 46], + 26: [28, 47], + 27: [29, 48], + 28: [30, 49], + 29: [31, 50], + 30: [32, 51], + 31: [33, 52], + } @property def port_start(self): @@ -70,20 +70,20 @@ def port_start(self): @property def port_end(self): return self.PORT_END - + @property def qsfp_ports(self): - return range(self.PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): return self._port_to_eeprom_mapping - + def get_presence(self, port_num): - # Check for invalid port_num + # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False - + present_path = self.BASE_CPLD_PATH + "module_present_" + str(port_num+1) self.__port_to_is_present = present_path @@ -93,47 +93,45 @@ def get_presence(self, port_num): content = val_file.readline().rstrip() val_file.close() except IOError as e: - print "Error: unable to access file: %s" % str(e) + print("Error: unable to access file: %s" % str(e)) return False - + if content == "1": return True return False def __init__(self): - eeprom_path = self.BASE_I2C_PATH + eeprom_path = self.BASE_I2C_PATH - for x in range(0, self.port_end+1): + for x in range(0, self.port_end+1): self.port_to_eeprom_mapping[x] = eeprom_path.format( self._port_to_i2c_mapping[x][1] - ) - if(x < 9): - if(self.get_presence(x)==1): - self.port_to_eeprom_mapping[x] = self.BASE_I2C_PATH + "0-000" +str(x+1) + "/eeprom" - + ) + if(x < 9): + if(self.get_presence(x) == 1): + self.port_to_eeprom_mapping[x] = self.BASE_I2C_PATH + "0-000" + str(x+1) + "/eeprom" + else: - if(self.get_presence(x)==1): - self.port_to_eeprom_mapping[x] = self.BASE_I2C_PATH + "0-00" +str(x+1)+ "/eeprom" - + if(self.get_presence(x) == 1): + self.port_to_eeprom_mapping[x] = self.BASE_I2C_PATH + "0-00" + str(x+1) + "/eeprom" + SfpUtilBase.__init__(self) - + def get_low_power_mode(self, port_num): + raise NotImplementedError - def get_low_power_mode(self, port_num): - raise NotImplementedError - def set_low_power_mode(self, port_num, lpmode): raise NotImplementedError def reset(self, port_num): if port_num < self.port_start or port_num > self.port_end: return False - - mod_rst_cmd = "ipmitool raw 0x34 0x11 " + str(port_num+1) + " 0x11 0x1" - (status, output) = commands.getstatusoutput (mod_rst_cmd) + + mod_rst_cmd = "ipmitool raw 0x34 0x11 " + str(port_num+1) + " 0x11 0x1" + subprocess.check_output(mod_rst_cmd, universal_newlines=True) return True - + def get_transceiver_change_event(self): """ TODO: This function need to be implemented diff --git a/device/accton/x86_64-accton_as7726_32x-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as7726_32x-r0/plugins/eeprom.py index 68ed5f9466b0..5ff41c3bac24 100755 --- a/device/accton/x86_64-accton_as7726_32x-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as7726_32x-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,14 +8,16 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/0-0056/eeprom" - #Two i2c buses might get flipped order, check them both. + # Two i2c buses might get flipped order, check them both. if not os.path.exists(self.eeprom_path): self.eeprom_path = "/sys/bus/i2c/devices/1-0056/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/accton/x86_64-accton_as7726_32x-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as7726_32x-r0/plugins/psuutil.py index 44fb45662d50..92b453784721 100755 --- a/device/accton/x86_64-accton_as7726_32x-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as7726_32x-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Accton # @@ -13,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/accton/x86_64-accton_as7726_32x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7726_32x-r0/plugins/sfputil.py index f8ef438af954..350c2245fe3b 100755 --- a/device/accton/x86_64-accton_as7726_32x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7726_32x-r0/plugins/sfputil.py @@ -11,61 +11,61 @@ except ImportError as e: raise ImportError("%s - required module not found" % str(e)) -#from xcvrd +# from xcvrd SFP_STATUS_INSERTED = '1' SFP_STATUS_REMOVED = '0' class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" - + PORT_START = 1 - PORT_END = 32 #34 cages actually, but last 2 are not at port_config.ini. + PORT_END = 32 # 34 cages actually, but last 2 are not at port_config.ini. PORTS_IN_BLOCK = 32 - + BASE_OOM_PATH = "/sys/bus/i2c/devices/{0}-0050/" BASE_CPLD_PATH = "/sys/bus/i2c/devices/11-0060/" - + _port_to_is_present = {} _port_to_lp_mode = {} _port_to_eeprom_mapping = {} _port_to_i2c_mapping = { - 1: 21, - 2: 22, - 3: 23, - 4: 24, - 5: 26, - 6: 25, - 7: 28, - 8: 27, - 9: 17, - 10: 18, - 11: 19, - 12: 20, - 13: 29, - 14: 30, - 15: 31, - 16: 32, - 17: 33, - 18: 34, - 19: 35, - 20: 36, - 21: 45, - 22: 46, - 23: 47, - 24: 48, - 25: 37, - 26: 38, - 27: 39, - 28: 40, - 29: 41, - 30: 42, - 31: 43, - 32: 44, - 33: 15, - 34: 16, - } + 1: 21, + 2: 22, + 3: 23, + 4: 24, + 5: 26, + 6: 25, + 7: 28, + 8: 27, + 9: 17, + 10: 18, + 11: 19, + 12: 20, + 13: 29, + 14: 30, + 15: 31, + 16: 32, + 17: 33, + 18: 34, + 19: 35, + 20: 36, + 21: 45, + 22: 46, + 23: 47, + 24: 48, + 25: 37, + 26: 38, + 27: 39, + 28: 40, + 29: 41, + 30: 42, + 31: 43, + 32: 44, + 33: 15, + 34: 16, + } @property def port_start(self): @@ -74,10 +74,10 @@ def port_start(self): @property def port_end(self): return self.PORT_END - + @property def qsfp_ports(self): - return range(self.PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -85,11 +85,11 @@ def port_to_eeprom_mapping(self): def __init__(self): eeprom_path = self.BASE_OOM_PATH + "eeprom" - + for x in range(self.port_start, self.port_end+1): self.port_to_eeprom_mapping[x] = eeprom_path.format( self._port_to_i2c_mapping[x] - ) + ) SfpUtilBase.__init__(self) def get_presence(self, port_num): @@ -100,15 +100,15 @@ def get_presence(self, port_num): present_path = self.BASE_CPLD_PATH + "module_present_" + str(port_num) self.__port_to_is_present = present_path - content="0" + content = "0" try: val_file = open(self.__port_to_is_present) content = val_file.readline().rstrip() val_file.close() except IOError as e: - print "Error: unable to access file: %s" % str(e) + print("Error: unable to access file: %s" % str(e)) return False - + if content == "1": return True @@ -130,20 +130,21 @@ def get_low_power_mode(self, port_num): lpmode = ord(eeprom.read(1)) if ((lpmode & 0x3) == 0x3): - return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 + return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 else: - return False # High Power Mode if one of the following conditions is matched: - # 1. "Power override" bit is 0 - # 2. "Power override" bit is 1 and "Power set" bit is 0 + # High Power Mode if one of the following conditions is matched: + # 1. "Power override" bit is 0 + # 2. "Power override" bit is 1 and "Power set" bit is 0 + return False except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False finally: if eeprom is not None: eeprom.close() time.sleep(0.01) - def set_low_power_mode(self, port_num, 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 @@ -152,10 +153,10 @@ def set_low_power_mode(self, port_num, lpmode): eeprom = None if not self.get_presence(port_num): - return False # Port is not present, unable to set the eeprom + return False # Port is not present, unable to set the eeprom # Fill in write buffer - regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode + regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode buffer = create_string_buffer(1) buffer[0] = chr(regval) @@ -165,7 +166,7 @@ def set_low_power_mode(self, port_num, lpmode): eeprom.write(buffer[0]) return True except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False finally: if eeprom is not None: @@ -175,24 +176,24 @@ def set_low_power_mode(self, port_num, lpmode): def reset(self, port_num): if port_num < self.port_start or port_num > self.port_end: return False - + mod_rst_path = self.BASE_CPLD_PATH + "module_reset_" + str(port_num) - + self.__port_to_mod_rst = mod_rst_path try: reg_file = open(self.__port_to_mod_rst, 'r+', buffering=0) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False - #toggle reset + # toggle reset reg_file.seek(0) reg_file.write('1') time.sleep(1) reg_file.seek(0) reg_file.write('0') reg_file.close() - + return True @property @@ -208,16 +209,17 @@ def get_transceiver_status(self): reg_file = open(node) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False bitmap += reg_file.readline().rstrip() + " " reg_file.close() rev = bitmap.split(" ") rev = "".join(rev[::-1]) - return int(rev,16) + return int(rev, 16) + + data = {'valid': 0, 'last': 0, 'present': 0} - data = {'valid':0, 'last':0, 'present':0} def get_transceiver_change_event(self, timeout=2000): now = time.time() port_dict = {} @@ -225,8 +227,7 @@ def get_transceiver_change_event(self, timeout=2000): if timeout < 1000: timeout = 1000 - timeout = (timeout) / float(1000) # Convert to secs - + timeout = (timeout) / float(1000) # Convert to secs if now < (self.data['last'] + timeout) and self.data['valid']: return True, {} @@ -234,7 +235,7 @@ def get_transceiver_change_event(self, timeout=2000): reg_value = self.get_transceiver_status changed_ports = self.data['present'] ^ reg_value if changed_ports: - for port in range (self.port_start, self.port_end+1): + for port in range(self.port_start, self.port_end+1): # Mask off the bit corresponding to our port fp_port = port mask = (1 << (fp_port - 1)) @@ -253,4 +254,3 @@ def get_transceiver_change_event(self, timeout=2000): else: return True, {} return False, {} - diff --git a/device/accton/x86_64-accton_as7816_64x-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as7816_64x-r0/plugins/eeprom.py index 1e7d1046d93d..4241483d68eb 100644 --- a/device/accton/x86_64-accton_as7816_64x-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as7816_64x-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,11 +8,13 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/0-0056/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/accton/x86_64-accton_as7816_64x-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as7816_64x-r0/plugins/psuutil.py index 707c7c897c82..b05cf3e477ac 100755 --- a/device/accton/x86_64-accton_as7816_64x-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as7816_64x-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Accton # @@ -13,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/accton/x86_64-accton_as7816_64x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7816_64x-r0/plugins/sfputil.py index afb6f0c74147..0520799d385a 100644 --- a/device/accton/x86_64-accton_as7816_64x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7816_64x-r0/plugins/sfputil.py @@ -1,17 +1,16 @@ -#!/usr/bin/env python - try: import time import string from ctypes import create_string_buffer - from sonic_sfp.sfputilbase import SfpUtilBase -except ImportError, e: - raise ImportError (str(e) + "- required module not found") + from sonic_sfp.sfputilbase import SfpUtilBase +except ImportError as e: + raise ImportError(str(e) + "- required module not found") -#from xcvrd +# from xcvrd SFP_STATUS_INSERTED = '1' SFP_STATUS_REMOVED = '0' + class SfpUtil(SfpUtilBase): """Platform specific SfpUtill class""" @@ -21,72 +20,72 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} port_to_i2c_mapping = { - 61 : 25, - 62 : 26, - 63 : 27, - 64 : 28, - 55 : 29, - 56 : 30, - 53 : 31, - 54 : 32, - 9 : 33, - 10 : 34, - 11 : 35, - 12 : 36, - 1 : 37, - 2 : 38, - 3 : 39, - 4 : 40, - 6 : 41, - 5 : 42, - 8 : 43, - 7 : 44, - 13 : 45, - 14 : 46, - 15 : 47, - 16 : 48, - 17 : 49, - 18 : 50, - 19 : 51, - 20 : 52, - 25 : 53, - 26 : 54, - 27 : 55, - 28 : 56, - 29 : 57, - 30 : 58, - 31 : 59, - 32 : 60, - 21 : 61, - 22 : 62, - 23 : 63, - 24 : 64, - 41 : 65, - 42 : 66, - 43 : 67, - 44 : 68, - 33 : 69, - 34 : 70, - 35 : 71, - 36 : 72, - 45 : 73, - 46 : 74, - 47 : 75, - 48 : 76, - 37 : 77, - 38 : 78, - 39 : 79, - 40 : 80, - 57 : 81, - 58 : 82, - 59 : 83, - 60 : 84, - 49 : 85, - 50 : 86, - 51 : 87, - 52 : 88,} - - _qsfp_ports = range(0, ports_in_block + 1) + 61: 25, + 62: 26, + 63: 27, + 64: 28, + 55: 29, + 56: 30, + 53: 31, + 54: 32, + 9: 33, + 10: 34, + 11: 35, + 12: 36, + 1: 37, + 2: 38, + 3: 39, + 4: 40, + 6: 41, + 5: 42, + 8: 43, + 7: 44, + 13: 45, + 14: 46, + 15: 47, + 16: 48, + 17: 49, + 18: 50, + 19: 51, + 20: 52, + 25: 53, + 26: 54, + 27: 55, + 28: 56, + 29: 57, + 30: 58, + 31: 59, + 32: 60, + 21: 61, + 22: 62, + 23: 63, + 24: 64, + 41: 65, + 42: 66, + 43: 67, + 44: 68, + 33: 69, + 34: 70, + 35: 71, + 36: 72, + 45: 73, + 46: 74, + 47: 75, + 48: 76, + 37: 77, + 38: 78, + 39: 79, + 40: 80, + 57: 81, + 58: 82, + 59: 83, + 60: 84, + 49: 85, + 50: 86, + 51: 87, + 52: 88, } + + _qsfp_ports = list(range(0, ports_in_block + 1)) def __init__(self): eeprom_path = '/sys/bus/i2c/devices/{0}-0050/eeprom' @@ -99,21 +98,21 @@ def reset(self, port_num): # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False - path = "/sys/bus/i2c/devices/19-0060/module_reset_{0}" + path = "/sys/bus/i2c/devices/19-0060/module_reset_{0}" port_ps = path.format(port_num) - + try: reg_file = open(port_ps, 'w') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False - #HW will clear reset after set. + # HW will clear reset after set. reg_file.seek(0) reg_file.write('1') reg_file.close() return True - + def get_presence(self, port_num): # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: @@ -121,16 +120,16 @@ def get_presence(self, port_num): path = "/sys/bus/i2c/devices/19-0060/module_present_{0}" port_ps = path.format(port_num) - + reg_value = '0' try: reg_file = open(port_ps) reg_value = reg_file.readline().rstrip() reg_file.close() except IOError as e: - print "Error: unable to access file: %s" % str(e) + print("Error: unable to access file: %s" % str(e)) return False - + if reg_value == '1': return True @@ -143,14 +142,14 @@ def port_start(self): @property def port_end(self): return self._port_end - + @property def qsfp_ports(self): - return range(0, self.ports_in_block + 1) + return list(range(0, self.ports_in_block + 1)) - @property + @property def port_to_eeprom_mapping(self): - return self._port_to_eeprom_mapping + return self._port_to_eeprom_mapping def get_low_power_mode(self, port_num): # Check for invalid port_num @@ -168,20 +167,21 @@ def get_low_power_mode(self, port_num): lpmode = ord(eeprom.read(1)) if ((lpmode & 0x3) == 0x3): - return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 + return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 else: - return False # High Power Mode if one of the following conditions is matched: - # 1. "Power override" bit is 0 - # 2. "Power override" bit is 1 and "Power set" bit is 0 + # High Power Mode if one of the following conditions is matched: + # 1. "Power override" bit is 0 + # 2. "Power override" bit is 1 and "Power set" bit is 0 + return False except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False finally: if eeprom is not None: eeprom.close() time.sleep(0.01) - def set_low_power_mode(self, port_num, 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 @@ -190,10 +190,10 @@ def set_low_power_mode(self, port_num, lpmode): eeprom = None if not self.get_presence(port_num): - return False # Port is not present, unable to set the eeprom + return False # Port is not present, unable to set the eeprom # Fill in write buffer - regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode + regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode buffer = create_string_buffer(1) buffer[0] = chr(regval) @@ -203,7 +203,7 @@ def set_low_power_mode(self, port_num, lpmode): eeprom.write(buffer[0]) return True except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False finally: if eeprom is not None: @@ -223,17 +223,17 @@ def _get_present_bitmap(self): reg_file = open(node) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False bitmap += reg_file.readline().rstrip() + " " reg_file.close() rev = bitmap.split(" ") rev = "".join(rev[::-1]) - return int(rev,16) + return int(rev, 16) + data = {'valid': 0, 'last': 0, 'present': 0} - data = {'valid':0, 'last':0, 'present':0} def get_transceiver_change_event(self, timeout=2000): now = time.time() port_dict = {} @@ -241,7 +241,7 @@ def get_transceiver_change_event(self, timeout=2000): if timeout < 1000: timeout = 1000 - timeout = (timeout) / float(1000) # Convert to secs + timeout = (timeout) / float(1000) # Convert to secs if now < (self.data['last'] + timeout) and self.data['valid']: return True, {} @@ -250,7 +250,7 @@ def get_transceiver_change_event(self, timeout=2000): reg_value = ~reg_value changed_ports = self.data['present'] ^ reg_value if changed_ports: - for port in range (self.port_start, self.port_end+1): + for port in range(self.port_start, self.port_end+1): # Mask off the bit corresponding to our port mask = (1 << (port - 1)) if changed_ports & mask: @@ -267,4 +267,3 @@ def get_transceiver_change_event(self, timeout=2000): else: return True, {} return False, {} - diff --git a/device/accton/x86_64-accton_as9716_32d-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as9716_32d-r0/plugins/eeprom.py index bb125d3c0cbb..9031f2c60ece 100644 --- a/device/accton/x86_64-accton_as9716_32d-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as9716_32d-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,24 +8,26 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + def eeprom_check(): - filepath="/sys/bus/i2c/devices/0-0057/eeprom" + filepath = "/sys/bus/i2c/devices/0-0057/eeprom" if os.path.isfile(filepath): - return 1 #now board, 0x57 + return 1 # now board, 0x57 else: - return 0 #now board, 0x56 - + return 0 # now board, 0x56 + + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): - ret=eeprom_check() - if ret==1: + ret = eeprom_check() + if ret == 1: self.eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom" else: self.eeprom_path = "/sys/bus/i2c/devices/0-0056/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) - diff --git a/device/accton/x86_64-accton_as9716_32d-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as9716_32d-r0/plugins/psuutil.py index 25eceb7428c7..ef49f262dca9 100644 --- a/device/accton/x86_64-accton_as9716_32d-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as9716_32d-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Accton # @@ -13,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/accton/x86_64-accton_as9716_32d-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as9716_32d-r0/plugins/sfputil.py index ea356bc9a328..7b3ca53d4ed4 100755 --- a/device/accton/x86_64-accton_as9716_32d-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as9716_32d-r0/plugins/sfputil.py @@ -6,7 +6,7 @@ try: import time import os - import sys, getopt + import sys from ctypes import create_string_buffer from sonic_sfp.sfputilbase import SfpUtilBase except ImportError as e: @@ -15,55 +15,55 @@ class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" - + PORT_START = 0 PORT_END = 33 PORTS_IN_BLOCK = 34 - + BASE_OOM_PATH = "/sys/bus/i2c/devices/{0}-0050/" BASE_CPLD1_PATH = "/sys/bus/i2c/devices/20-0061/" BASE_CPLD2_PATH = "/sys/bus/i2c/devices/21-0062/" - + _port_to_is_present = {} _port_to_lp_mode = {} _port_to_eeprom_mapping = {} _port_to_i2c_mapping = { - 0: [1, 25], - 1: [2, 26], - 2: [3, 27], - 3: [4, 28], - 4: [5, 29], - 5: [6, 30], - 6: [7, 31], - 7: [8, 32], - 8: [9, 33], - 9: [10, 34], - 10: [11, 35], - 11: [12, 36], - 12: [13, 37], - 13: [14, 38], - 14: [15, 39], - 15: [16, 40], - 16: [17, 41], - 17: [18, 42], - 18: [19, 43], - 19: [20, 44], - 20: [21, 45], - 21: [22, 46], - 22: [23, 47], - 23: [24, 48], - 24: [25, 49], - 25: [26, 50], - 26: [27, 51], - 27: [28, 52], - 28: [29, 53], - 29: [30, 54], - 30: [31, 55], - 31: [32, 56], - 32: [33, 57], - 33: [34, 58], - } + 0: [1, 25], + 1: [2, 26], + 2: [3, 27], + 3: [4, 28], + 4: [5, 29], + 5: [6, 30], + 6: [7, 31], + 7: [8, 32], + 8: [9, 33], + 9: [10, 34], + 10: [11, 35], + 11: [12, 36], + 12: [13, 37], + 13: [14, 38], + 14: [15, 39], + 15: [16, 40], + 16: [17, 41], + 17: [18, 42], + 18: [19, 43], + 19: [20, 44], + 20: [21, 45], + 21: [22, 46], + 22: [23, 47], + 23: [24, 48], + 24: [25, 49], + 25: [26, 50], + 26: [27, 51], + 27: [28, 52], + 28: [29, 53], + 29: [30, 54], + 30: [31, 55], + 31: [32, 56], + 32: [33, 57], + 33: [34, 58], + } @property def port_start(self): @@ -72,10 +72,10 @@ def port_start(self): @property def port_end(self): return self.PORT_END - + @property def qsfp_ports(self): - return range(self.PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -83,11 +83,11 @@ def port_to_eeprom_mapping(self): def __init__(self): eeprom_path = self.BASE_OOM_PATH + "eeprom" - + for x in range(0, self.port_end+1): self.port_to_eeprom_mapping[x] = eeprom_path.format( self._port_to_i2c_mapping[x][1] - ) + ) SfpUtilBase.__init__(self) @@ -95,19 +95,19 @@ def get_presence(self, port_num): # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False - if port_num < 16 : + if port_num < 16: present_path = self.BASE_CPLD1_PATH + "module_present_" + str(port_num+1) else: present_path = self.BASE_CPLD2_PATH + "module_present_" + str(port_num+1) self.__port_to_is_present = present_path - content="0" + content = "0" try: val_file = open(self.__port_to_is_present) content = val_file.readline().rstrip() val_file.close() except IOError as e: - print "Error: unable to access file: %s" % str(e) + print("Error: unable to access file: %s" % str(e)) return False if content == "1": @@ -115,7 +115,7 @@ def get_presence(self, port_num): return False - def get_low_power_mode(self, port_num): + def get_low_power_mode(self, port_num): # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False @@ -131,19 +131,20 @@ def get_low_power_mode(self, port_num): lpmode = ord(eeprom.read(1)) if ((lpmode & 0x3) == 0x3): - return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 + return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 else: - return False # High Power Mode if one of the following conditions is matched: - # 1. "Power override" bit is 0 - # 2. "Power override" bit is 1 and "Power set" bit is 0 + # High Power Mode if one of the following conditions is matched: + # 1. "Power override" bit is 0 + # 2. "Power override" bit is 1 and "Power set" bit is 0 + return False except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False finally: if eeprom is not None: eeprom.close() time.sleep(0.01) - + 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: @@ -153,13 +154,13 @@ def set_low_power_mode(self, port_num, lpmode): eeprom = None if not self.get_presence(port_num): - return False # Port is not present, unable to set the eeprom + return False # Port is not present, unable to set the eeprom # Fill in write buffer - # 0x3:Low Power Mode. "Power override" bit is 1 and "Power set" bit is 1 - # 0x9:High Power Mode. "Power override" bit is 1 ,"Power set" bit is 0 and "High Power Class Enable" bit is 1 - regval = 0x3 if lpmode else 0x9 - + # 0x3:Low Power Mode. "Power override" bit is 1 and "Power set" bit is 1 + # 0x9:High Power Mode. "Power override" bit is 1 ,"Power set" bit is 0 and "High Power Class Enable" bit is 1 + regval = 0x3 if lpmode else 0x9 + buffer = create_string_buffer(1) buffer[0] = chr(regval) @@ -169,7 +170,7 @@ def set_low_power_mode(self, port_num, lpmode): eeprom.write(buffer[0]) return True except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False finally: if eeprom is not None: @@ -179,111 +180,111 @@ def set_low_power_mode(self, port_num, lpmode): def reset(self, port_num): if port_num < self.port_start or port_num > self.port_end: return False - - if port_num < 16 : + + if port_num < 16: mod_rst_path = self.BASE_CPLD1_PATH + "module_reset_" + str(port_num+1) else: mod_rst_path = self.BASE_CPLD2_PATH + "module_reset_" + str(port_num+1) - + self.__port_to_mod_rst = mod_rst_path try: reg_file = open(self.__port_to_mod_rst, 'r+') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = '1' reg_file.write(reg_value) reg_file.close() - + return True - + def get_cpld_interrupt(self): - port_dict={} - for i in range(0,4): - if i==0 or i==1: + port_dict = {} + for i in range(0, 4): + if i == 0 or i == 1: cpld_i2c_path = self.BASE_CPLD1_PATH + "cpld_intr_" + str(i+1) else: - cpld_i2c_path = self.BASE_CPLD2_PATH + "cpld_intr_" +str(i+1) - - start_i=(i*8) - end_i=(i*8+8) + cpld_i2c_path = self.BASE_CPLD2_PATH + "cpld_intr_" + str(i+1) + + start_i = (i*8) + end_i = (i*8+8) try: val_file = open(cpld_i2c_path) except IOError as e: - print "Error: unable to open file: %s" % str(e) - - for k in range (start_i, end_i): - port_dict[k]=0 + print("Error: unable to open file: %s" % str(e)) + + for k in range(start_i, end_i): + port_dict[k] = 0 return port_dict status = val_file.readline().rstrip() val_file.close() - status=status.strip() - status= int(status, 16) - - interrupt_status = ~(status & 0xff) + status = status.strip() + status = int(status, 16) + + interrupt_status = ~(status & 0xff) if interrupt_status: - port_shift=0 - for k in range (start_i, end_i): - if interrupt_status & (0x1< 0: - timeout = timeout / float(1000) # Convert to secs + timeout = timeout / float(1000) # Convert to secs else: - print "get_transceiver_change_event:Invalid timeout value", timeout + print("get_transceiver_change_event:Invalid timeout value", timeout) return False, {} end_time = start_time + timeout if start_time > end_time: - print 'get_transceiver_change_event:' \ - 'time wrap / invalid timeout value', timeout + print('get_transceiver_change_event:' + 'time wrap / invalid timeout value', timeout) + + return False, {} # Time wrap or possibly incorrect timeout - return False, {} # Time wrap or possibly incorrect timeout - - #for i in range(self.port_start, self.port_end+1): + # for i in range(self.port_start, self.port_end+1): # ori_present[i]=self.get_presence(i) - - while timeout >= 0: - change_status=0 - + + while timeout >= 0: + change_status = 0 + port_dict = self.get_cpld_interrupt() - present=0 - for key, value in port_dict.iteritems(): - if value==1: - present=self.get_presence(key) - change_status=1 + present = 0 + for key, value in port_dict.items(): + if value == 1: + present = self.get_presence(key) + change_status = 1 if present: - port_dict[key]='1' + port_dict[key] = '1' else: - port_dict[key]='0' - - if change_status: + port_dict[key] = '0' + + if change_status: return True, port_dict if forever: time.sleep(1) else: timeout = end_time - time.time() if timeout >= 1: - time.sleep(1) # We poll at 1 second granularity + time.sleep(1) # We poll at 1 second granularity else: if timeout > 0: time.sleep(timeout) return True, {} - print "get_evt_change_event: Should not reach here." - return False, {} \ No newline at end of file + print("get_evt_change_event: Should not reach here.") + return False, {} diff --git a/device/accton/x86_64-accton_minipack-r0/plugins/eeprom.py b/device/accton/x86_64-accton_minipack-r0/plugins/eeprom.py index c1ac366fc3fa..3912194484db 100644 --- a/device/accton/x86_64-accton_minipack-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_minipack-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,11 +8,13 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom" super(board, self).__init__(self.eeprom_path, 0x200, '', True) diff --git a/device/accton/x86_64-accton_minipack-r0/plugins/led_control.py b/device/accton/x86_64-accton_minipack-r0/plugins/led_control.py index 26e2a7f7c8a2..a11a31062367 100755 --- a/device/accton/x86_64-accton_minipack-r0/plugins/led_control.py +++ b/device/accton/x86_64-accton_minipack-r0/plugins/led_control.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python -# # led_control.py # # Platform-specific LED control functionality for SONiC @@ -17,19 +15,18 @@ from socket import * from select import * from minipack.pimutil import PimUtil -except ImportError, e: +except ImportError as e: raise ImportError(str(e) + " - required module not found") class LedControl(LedControlBase): """Platform specific LED control class""" SONIC_PORT_NAME_PREFIX = "Ethernet" - - + def __init__(self): - pim=PimUtil() + pim = PimUtil() pim.init_pim_fpga() - + def _port_name_to_index(self, port_name): # Strip "Ethernet" off port name if not port_name.startswith(self.SONIC_PORT_NAME_PREFIX): @@ -37,23 +34,22 @@ def _port_name_to_index(self, port_name): port_idx = int(port_name[len(self.SONIC_PORT_NAME_PREFIX):]) return port_idx - + def _port_state_to_mode(self, port_idx, state): if state == "up": - return 1, 4 #port linkup, led is green + return 1, 4 # port linkup, led is green else: - return 0, 0 #port linkdown, led is off + return 0, 0 # port linkdown, led is off def port_link_state_change(self, portname, state): - pim=PimUtil() + pim = PimUtil() port_idx = self._port_name_to_index(portname) new_control, led_mode = self._port_state_to_mode(port_idx, state) - color, control=pim.get_port_led(port_idx) - - if color==led_mode: - if control==new_control: + color, control = pim.get_port_led(port_idx) + + if color == led_mode: + if control == new_control: return - - pim.set_port_led(port_idx, led_mode, new_control)#port linkup, led is green - #port linkdown, led is off + pim.set_port_led(port_idx, led_mode, new_control) # port linkup, led is green + # port linkdown, led is off diff --git a/device/accton/x86_64-accton_minipack-r0/plugins/psuutil.py b/device/accton/x86_64-accton_minipack-r0/plugins/psuutil.py index 99e1bbae9377..2a8bd232db44 100644 --- a/device/accton/x86_64-accton_minipack-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_minipack-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Accton # @@ -13,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/accton/x86_64-accton_minipack-r0/plugins/sfputil.py b/device/accton/x86_64-accton_minipack-r0/plugins/sfputil.py index 6f62d8ed4c07..85dc5f81f5ac 100755 --- a/device/accton/x86_64-accton_minipack-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_minipack-r0/plugins/sfputil.py @@ -7,20 +7,20 @@ import time from sonic_sfp.sfputilbase import SfpUtilBase import os - import sys, getopt - from minipack.pimutil import PimUtil + import sys + from minipack.pimutil import PimUtil except ImportError as e: raise ImportError("%s - required module not found" % str(e)) class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" - + PORT_START = 0 PORT_END = 128 - + LOCAL_OOM_PATH = "/usr/local/bin/minipack_qsfp/port%d_eeprom" - + _port_to_is_present = {} _port_to_lp_mode = {} @@ -33,10 +33,10 @@ def port_start(self): @property def port_end(self): return self.PORT_END - + @property def qsfp_ports(self): - return range(self.PORT_START, self.PORT_END + 1) + return list(range(self.PORT_START, self.PORT_END + 1)) @property def port_to_eeprom_mapping(self): @@ -47,100 +47,99 @@ def sfp_map(self, index): base = ((port-1)/8*8) + 10 index = (port - 1) % 8 index = 7 - index - if (index%2): - index = index -1 + if (index % 2): + index = index - 1 else: - index = index +1 + index = index + 1 bus = base + index return bus - def __init__(self): - for x in range(0, self.port_end): - self.port_to_eeprom_mapping[x] = self.LOCAL_OOM_PATH %x + for x in range(0, self.port_end): + self.port_to_eeprom_mapping[x] = self.LOCAL_OOM_PATH % x SfpUtilBase.__init__(self) - pim=PimUtil() + pim = PimUtil() pim.init_pim_fpga() - + def __del__(self): - self.value=0 + self.value = 0 def get_presence(self, port_num): # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False - pim=PimUtil() - status=pim.get_qsfp_presence(port_num) + pim = PimUtil() + status = pim.get_qsfp_presence(port_num) return status - - def get_low_power_mode(self, port_num): + + def get_low_power_mode(self, port_num): if port_num < self.port_start or port_num > self.port_end: return False - pim=PimUtil() + pim = PimUtil() return pim.get_low_power_mode(port_num) - + def set_low_power_mode(self, port_num, lpmode): if port_num < self.port_start or port_num > self.port_end: return False - pim=PimUtil() - pim.set_low_power_mode(port_num, lpmode) - return True + pim = PimUtil() + pim.set_low_power_mode(port_num, lpmode) + return True def reset(self, port_num): if port_num < self.port_start or port_num > self.port_end: return False - pim=PimUtil() + pim = PimUtil() pim.reset(port_num) - return True - + return True + def get_transceiver_change_event(self, timeout=0): - pim=PimUtil() + pim = PimUtil() start_time = time.time() port_dict = {} forever = False - + if timeout == 0: forever = True elif timeout > 0: - timeout = timeout / float(1000) # Convert to secs + timeout = timeout / float(1000) # Convert to secs else: - print "get_transceiver_change_event:Invalid timeout value", timeout + print("get_transceiver_change_event:Invalid timeout value", timeout) return False, {} end_time = start_time + timeout if start_time > end_time: - print 'get_transceiver_change_event:' \ - 'time wrap / invalid timeout value', timeout + print('get_transceiver_change_event:' + 'time wrap / invalid timeout value', timeout) + + return False, {} # Time wrap or possibly incorrect timeout - return False, {} # Time wrap or possibly incorrect timeout - - while timeout >= 0: - change_status=0 + while timeout >= 0: + change_status = 0 port_dict = pim.get_qsfp_interrupt() - present=0 - for key, value in port_dict.iteritems(): - if value==1: - present=self.get_presence(key) - change_status=1 + present = 0 + for key, value in port_dict.items(): + if value == 1: + present = self.get_presence(key) + change_status = 1 if present: - port_dict[key]='1' + port_dict[key] = '1' else: - port_dict[key]='0' - - if change_status: + port_dict[key] = '0' + + if change_status: return True, port_dict if forever: time.sleep(1) else: timeout = end_time - time.time() if timeout >= 1: - time.sleep(1) # We poll at 1 second granularity + time.sleep(1) # We poll at 1 second granularity else: if timeout > 0: time.sleep(timeout) return True, {} - print "get_evt_change_event: Should not reach here." + print("get_evt_change_event: Should not reach here.") return False, {} diff --git a/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/eeprom.py b/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/eeprom.py index c0122e65844a..9e4e9970e9f5 100644 --- a/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/eeprom.py +++ b/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,14 +8,16 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/1-0056/eeprom" - #Two i2c buses might get flipped order, check them both. + # Two i2c buses might get flipped order, check them both. if not os.path.exists(self.eeprom_path): self.eeprom_path = "/sys/bus/i2c/devices/0-0056/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/led_control.py b/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/led_control.py index bab96d69dc47..4da72e7f7a04 100644 --- a/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/led_control.py +++ b/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/led_control.py @@ -1,22 +1,19 @@ -#!/usr/bin/env python -# -# led_control.py -# # Platform-specific LED control functionality for SONiC # # try: # from sonic_led.led_control_base import LedControlBase # import swsssdk -# except ImportError, e: +# except ImportError as e: # raise ImportError (str(e) + " - required module not found") import time + class LedControlBase(object): -# __metaclass__ = abc.ABCMeta + # __metaclass__ = abc.ABCMeta -# @abc.abstractmethod + # @abc.abstractmethod def port_link_state_change(self, port, state): """ Called when port link state changes. Update port link state LED here. @@ -26,6 +23,7 @@ def port_link_state_change(self, port, state): """ return + ### Zion specified ### read_fan_fault = 0 is_fan_all_OK = 0 @@ -35,126 +33,128 @@ def port_link_state_change(self, port, state): is_reset_button_push = 0 ########################## + def sysled_task(): while True: system_led_check() time.sleep(5) - + ### Zion specified ### + + def system_led_check(): - global read_fan_fault, read_power_status, is_fan_all_OK, is_power_all_OK, is_thermal_high, is_reset_button_push - is_fan_all_OK = 1 - is_power_all_OK = 0 - is_thermal_high = 0 - is_reset_button_push = 0 - with open("/sys/bus/i2c/devices/1-005e/fan1_fault", "r") as f1: - read_fan_fault = f1.read() - with open("/sys/bus/i2c/devices/9-005f/fan1_led", "w") as f11: - if str(read_fan_fault) == str("1\n"): - is_fan_all_OK = 0 - f11.write("4") - else: - f11.write("1") - with open("/sys/bus/i2c/devices/1-005e/fan2_fault", "r") as f1: - read_fan_fault = f1.read() - with open("/sys/bus/i2c/devices/9-005f/fan2_led", "w") as f11: - if str(read_fan_fault) == str("1\n"): - is_fan_all_OK = 0 - f11.write("4") - else: - f11.write("1") - with open("/sys/bus/i2c/devices/1-005e/fan3_fault", "r") as f1: - read_fan_fault = f1.read() - with open("/sys/bus/i2c/devices/9-005f/fan3_led", "w") as f11: - if str(read_fan_fault) == str("1\n"): - is_fan_all_OK = 0 - f11.write("4") - else: - f11.write("1") - with open("/sys/bus/i2c/devices/1-005e/fan4_fault", "r") as f1: - read_fan_fault = f1.read() - with open("/sys/bus/i2c/devices/9-005f/fan4_led", "w") as f11: - if str(read_fan_fault) == str("1\n"): - is_fan_all_OK = 0 - f11.write("4") - else: - f11.write("1") - with open("/sys/bus/i2c/devices/1-005e/fan5_fault", "r") as f1: - read_fan_fault = f1.read() - with open("/sys/bus/i2c/devices/9-005f/fan5_led", "w") as f11: - if str(read_fan_fault) == str("1\n"): - is_fan_all_OK = 0 - f11.write("4") - else: - f11.write("1") - with open("/sys/bus/i2c/devices/1-005e/fan6_fault", "r") as f1: - read_fan_fault = f1.read() - with open("/sys/bus/i2c/devices/9-005f/fan6_led", "w") as f11: - if str(read_fan_fault) == str("1\n"): - is_fan_all_OK = 0 - f11.write("4") - else: - f11.write("1") - - - with open("/sys/bus/i2c/devices/1-005e/psu1_power_good", "r") as f1: - read_power_status = f1.read() - with open("/sys/bus/i2c/devices/9-005f/sys_pwr", "w") as f11: - if str(read_power_status) == str("1\n"): - f11.write("1") - else: - f11.write("4") - with open("/sys/bus/i2c/devices/1-005e/psu1_present", "r") as f1: - read_power_status = f1.read() - with open("/sys/bus/i2c/devices/9-005f/sys_pwr", "w") as f11: - if str(read_power_status) == str("1\n"): - is_power_all_OK = is_power_all_OK + 1 - f11.write("1") - else: - f11.write("4") - with open("/sys/bus/i2c/devices/1-005e/psu2_power_good", "r") as f1: - read_power_status = f1.read() - with open("/sys/bus/i2c/devices/9-005f/sys_pwr", "w") as f11: - if str(read_power_status) == str("1\n"): - f11.write("1") - else: - f11.write("4") - with open("/sys/bus/i2c/devices/1-005e/psu2_present", "r") as f1: - read_power_status = f1.read() - with open("/sys/bus/i2c/devices/9-005f/sys_pwr", "w") as f11: - if str(read_power_status) == str("1\n"): - is_power_all_OK = is_power_all_OK + 1 - f11.write("1") - else: - f11.write("4") - - - with open("/sys/bus/i2c/devices/9-005f/swi_ctrl", "r") as f5: - is_reset_button_push = f5.read() - if str(is_reset_button_push) == "1\n": - is_reset_button_push = 1 - else: - is_reset_button_push = 0 - - with open("/sys/bus/i2c/devices/4-004d/hwmon/hwmon3/temp1_input", "r") as f3: - is_thermal_high = f3.read() - if int(is_thermal_high) >= 70000: - is_thermal_high = 1 - else: - is_thermal_high = 0 - - with open("/sys/bus/i2c/devices/9-005f/sys_status", "w") as f2: - if is_reset_button_push == 1: - f2.write("3") - elif is_fan_all_OK == 0 or is_power_all_OK == 0 or is_thermal_high == 1: - f2.write("4") - else: - f2.write("1") - - return + global read_fan_fault, read_power_status, is_fan_all_OK, is_power_all_OK, is_thermal_high, is_reset_button_push + + is_fan_all_OK = 1 + is_power_all_OK = 0 + is_thermal_high = 0 + is_reset_button_push = 0 + with open("/sys/bus/i2c/devices/1-005e/fan1_fault", "r") as f1: + read_fan_fault = f1.read() + with open("/sys/bus/i2c/devices/9-005f/fan1_led", "w") as f11: + if str(read_fan_fault) == str("1\n"): + is_fan_all_OK = 0 + f11.write("4") + else: + f11.write("1") + with open("/sys/bus/i2c/devices/1-005e/fan2_fault", "r") as f1: + read_fan_fault = f1.read() + with open("/sys/bus/i2c/devices/9-005f/fan2_led", "w") as f11: + if str(read_fan_fault) == str("1\n"): + is_fan_all_OK = 0 + f11.write("4") + else: + f11.write("1") + with open("/sys/bus/i2c/devices/1-005e/fan3_fault", "r") as f1: + read_fan_fault = f1.read() + with open("/sys/bus/i2c/devices/9-005f/fan3_led", "w") as f11: + if str(read_fan_fault) == str("1\n"): + is_fan_all_OK = 0 + f11.write("4") + else: + f11.write("1") + with open("/sys/bus/i2c/devices/1-005e/fan4_fault", "r") as f1: + read_fan_fault = f1.read() + with open("/sys/bus/i2c/devices/9-005f/fan4_led", "w") as f11: + if str(read_fan_fault) == str("1\n"): + is_fan_all_OK = 0 + f11.write("4") + else: + f11.write("1") + with open("/sys/bus/i2c/devices/1-005e/fan5_fault", "r") as f1: + read_fan_fault = f1.read() + with open("/sys/bus/i2c/devices/9-005f/fan5_led", "w") as f11: + if str(read_fan_fault) == str("1\n"): + is_fan_all_OK = 0 + f11.write("4") + else: + f11.write("1") + with open("/sys/bus/i2c/devices/1-005e/fan6_fault", "r") as f1: + read_fan_fault = f1.read() + with open("/sys/bus/i2c/devices/9-005f/fan6_led", "w") as f11: + if str(read_fan_fault) == str("1\n"): + is_fan_all_OK = 0 + f11.write("4") + else: + f11.write("1") + + with open("/sys/bus/i2c/devices/1-005e/psu1_power_good", "r") as f1: + read_power_status = f1.read() + with open("/sys/bus/i2c/devices/9-005f/sys_pwr", "w") as f11: + if str(read_power_status) == str("1\n"): + f11.write("1") + else: + f11.write("4") + with open("/sys/bus/i2c/devices/1-005e/psu1_present", "r") as f1: + read_power_status = f1.read() + with open("/sys/bus/i2c/devices/9-005f/sys_pwr", "w") as f11: + if str(read_power_status) == str("1\n"): + is_power_all_OK = is_power_all_OK + 1 + f11.write("1") + else: + f11.write("4") + with open("/sys/bus/i2c/devices/1-005e/psu2_power_good", "r") as f1: + read_power_status = f1.read() + with open("/sys/bus/i2c/devices/9-005f/sys_pwr", "w") as f11: + if str(read_power_status) == str("1\n"): + f11.write("1") + else: + f11.write("4") + with open("/sys/bus/i2c/devices/1-005e/psu2_present", "r") as f1: + read_power_status = f1.read() + with open("/sys/bus/i2c/devices/9-005f/sys_pwr", "w") as f11: + if str(read_power_status) == str("1\n"): + is_power_all_OK = is_power_all_OK + 1 + f11.write("1") + else: + f11.write("4") + + with open("/sys/bus/i2c/devices/9-005f/swi_ctrl", "r") as f5: + is_reset_button_push = f5.read() + if str(is_reset_button_push) == "1\n": + is_reset_button_push = 1 + else: + is_reset_button_push = 0 + + with open("/sys/bus/i2c/devices/4-004d/hwmon/hwmon3/temp1_input", "r") as f3: + is_thermal_high = f3.read() + if int(is_thermal_high) >= 70000: + is_thermal_high = 1 + else: + is_thermal_high = 0 + + with open("/sys/bus/i2c/devices/9-005f/sys_status", "w") as f2: + if is_reset_button_push == 1: + f2.write("3") + elif is_fan_all_OK == 0 or is_power_all_OK == 0 or is_thermal_high == 1: + f2.write("4") + else: + f2.write("1") + + return ########## - - + + class LedControl(LedControlBase): """Platform specific LED control class""" PORT_TABLE_PREFIX = "PORT_TABLE:" @@ -184,17 +184,18 @@ def _port_name_to_qsfp_index(self, port_name): swss = swsssdk.SonicV2Connector() swss.connect(swss.APPL_DB) - lanes = swss.get(swss.APPL_DB, self.PORT_TABLE_PREFIX + port_name, 'lanes') + lanes = swss.get( + swss.APPL_DB, self.PORT_TABLE_PREFIX + port_name, 'lanes') # SONiC port nums are 0-based and increment by 4 # Arista QSFP indices are 1-based and increment by 1 - return (((sonic_port_num/4) + 1), sonic_port_num%4, len(lanes.split(','))) - + return (((sonic_port_num/4) + 1), sonic_port_num % 4, len(lanes.split(','))) # Concrete implementation of port_link_state_change() method + def port_link_state_change_bk(self, port, state): qsfp_index, lane_index, lanes = self._port_name_to_qsfp_index(port) - + # Ignore invalid QSFP indices if qsfp_index <= 0 or lanes <= 0 or lanes > 4: return @@ -203,9 +204,11 @@ def port_link_state_change_bk(self, port, state): # whereas indices 25-32 are not breakout-capable, and only have one if qsfp_index <= self.QSFP_BREAKOUT_END_IDX: # assuming 40G, then we need to control four lanes - led_sysfs_paths = [ self.LED_SYSFS_PATH_BREAKOUT_CAPABLE.format(qsfp_index, i) for i in range(lane_index + 1, lane_index + 1 + lanes) ] + led_sysfs_paths = [self.LED_SYSFS_PATH_BREAKOUT_CAPABLE.format( + qsfp_index, i) for i in range(lane_index + 1, lane_index + 1 + lanes)] else: - led_sysfs_paths = [ self.LED_SYSFS_PATH_NO_BREAKOUT.format(qsfp_index) ] + led_sysfs_paths = [ + self.LED_SYSFS_PATH_NO_BREAKOUT.format(qsfp_index)] for led_sysfs_path in led_sysfs_paths: led_file = open(led_sysfs_path, "w") @@ -240,7 +243,7 @@ def __init__(self): f.write("1") with open("/sys/bus/i2c/devices/9-005f/fan6_led", "w") as f: f.write("1") - sysled_task() + sysled_task() # Initialize: Turn all front panel QSFP LEDs off # # for qsfp_index in range(self.QSFP_BREAKOUT_START_IDX, self.QSFP_BREAKOUT_END_IDX + 1): diff --git a/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/psuutil.py b/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/psuutil.py index 7a3b87f24d2d..d189349b5d0e 100644 --- a/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/psuutil.py +++ b/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Alphanetworks # @@ -13,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/sfputil.py b/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/sfputil.py index 9e502578f153..09679eed8c3b 100644 --- a/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/sfputil.py +++ b/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/sfputil.py @@ -1,10 +1,8 @@ -#!/usr/bin/env python - try: import time - from sonic_sfp.sfputilbase import SfpUtilBase -except ImportError, e: - raise ImportError (str(e) + "- required module not found") + from sonic_sfp.sfputilbase import SfpUtilBase +except ImportError as e: + raise ImportError(str(e) + "- required module not found") class SfpUtil(SfpUtilBase): @@ -16,17 +14,18 @@ class SfpUtil(SfpUtilBase): port_to_eeprom = {} port_to_i2cbus_mapping = { - 1 : 14, - 2 : 15, - 3 : 16, - 4 : 17, + 1: 14, + 2: 15, + 3: 16, + 4: 17, } eeprom_path = "/sys/bus/i2c/devices/{0}-005f/sfp{1}_eeprom" port_reset_path = "/sys/bus/i2c/devices/{0}-005f/sfp{1}_port_reset" present_path = "/sys/bus/i2c/devices/{0}-005f/sfp{1}_is_present" - _qsfp_ports = range(first_port, port_num + 1) + _qsfp_ports = list(range(first_port, port_num + 1)) + @property def port_start(self): return self.first_port @@ -37,11 +36,11 @@ def port_end(self): @property def qsfp_ports(self): - return range(self.first_port, self.port_num + 1) + return list(range(self.first_port, self.port_num + 1)) - @property + @property def port_to_eeprom_mapping(self): - return self.port_to_eeprom + return self.port_to_eeprom def get_transceiver_change_event(self): """ @@ -68,11 +67,11 @@ def reset(self, port_num): i2c_index = (port_num / 8) + 1 path = self.port_reset_path port_path = path.format(self.port_to_i2cbus_mapping[i2c_index], (index + 1)) - + try: reg_file = open(port_path, 'w') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # reset @@ -90,7 +89,7 @@ def set_low_power_mode(self, port_nuM, lpmode): def get_low_power_mode(self, port_num): raise NotImplementedError - + def get_presence(self, port_num): # Check for invalid port_num if port_num < self.first_port or port_num > self.last_port: @@ -101,11 +100,10 @@ def get_presence(self, port_num): path = self.present_path port_path = path.format(self.port_to_i2cbus_mapping[i2c_index], (index + 1)) - try: reg_file = open(port_path) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_file.readline().rstrip() @@ -113,4 +111,3 @@ def get_presence(self, port_num): return True return False - diff --git a/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/eeprom.py b/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/eeprom.py index c0122e65844a..9e4e9970e9f5 100644 --- a/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/eeprom.py +++ b/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,14 +8,16 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/1-0056/eeprom" - #Two i2c buses might get flipped order, check them both. + # Two i2c buses might get flipped order, check them both. if not os.path.exists(self.eeprom_path): self.eeprom_path = "/sys/bus/i2c/devices/0-0056/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/led_control.py b/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/led_control.py index 457b1d750b28..53cc43c6cce3 100644 --- a/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/led_control.py +++ b/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/led_control.py @@ -1,22 +1,21 @@ -#!/usr/bin/env python -# # led_control.py -# +# # Platform-specific LED control functionality for SONiC # # try: # from sonic_led.led_control_base import LedControlBase # import swsssdk -# except ImportError, e: +# except ImportError as e: # raise ImportError (str(e) + " - required module not found") import time + class LedControlBase(object): -# __metaclass__ = abc.ABCMeta + # __metaclass__ = abc.ABCMeta -# @abc.abstractmethod + # @abc.abstractmethod def port_link_state_change(self, port, state): """ Called when port link state changes. Update port link state LED here. @@ -26,6 +25,7 @@ def port_link_state_change(self, port, state): """ return + ### Goreme specified ### read_fan_fault = 0 is_fan_all_OK = 0 @@ -35,91 +35,93 @@ def port_link_state_change(self, port, state): is_reset_button_push = 0 ########################## + def sysled_task(): while True: system_led_check() time.sleep(5) - -########## Goreme System LED checking + +# Goreme System LED checking + + def system_led_check(): - global read_fan_fault, read_power_status, is_fan_all_OK, is_power_all_OK, is_thermal_high, is_reset_button_push - is_fan_all_OK = 1 - is_power_all_OK = 0 - is_thermal_high = 0 - is_reset_button_push = 0 - with open("/sys/bus/i2c/devices/0-005e/fan1_fault", "r") as f1: - read_fan_fault = f1.read() - if str(read_fan_fault) == str("1\n"): - is_fan_all_OK = 0 - with open("/sys/bus/i2c/devices/0-005e/fan2_fault", "r") as f1: - read_fan_fault = f1.read() - if str(read_fan_fault) == str("1\n"): - is_fan_all_OK = 0 - with open("/sys/bus/i2c/devices/0-005e/fan3_fault", "r") as f1: - read_fan_fault = f1.read() - if str(read_fan_fault) == str("1\n"): - is_fan_all_OK = 0 - with open("/sys/bus/i2c/devices/0-005e/fan4_fault", "r") as f1: - read_fan_fault = f1.read() - if str(read_fan_fault) == str("1\n"): - is_fan_all_OK = 0 - - with open("/sys/bus/i2c/devices/8-005f/fan1_led", "w") as f11: - if int(is_fan_all_OK) == 1: - f11.write("1") - else: - f11.write("4") - - - with open("/sys/bus/i2c/devices/0-005e/psu1_power_good", "r") as f1: - read_power_status = f1.read() - if str(read_power_status) != str("1\n"): - is_power_all_OK = -10 - with open("/sys/bus/i2c/devices/0-005e/psu1_present", "r") as f1: - read_power_status = f1.read() - if str(read_power_status) == str("1\n"): - is_power_all_OK = is_power_all_OK + 1 - with open("/sys/bus/i2c/devices/0-005e/psu2_power_good", "r") as f1: - read_power_status = f1.read() - if str(read_power_status) != str("1\n"): - is_power_all_OK = -10 - with open("/sys/bus/i2c/devices/0-005e/psu2_present", "r") as f1: - read_power_status = f1.read() - if str(read_power_status) == str("1\n"): - is_power_all_OK = is_power_all_OK + 1 - - with open("/sys/bus/i2c/devices/8-005f/sys_pwr", "w") as f11: - if int(is_power_all_OK) > 0: - f11.write("1") - else: - f11.write("4") - - - with open("/sys/bus/i2c/devices/8-005f/swi_ctrl", "r") as f5: - is_reset_button_push = f5.read() - if str(is_reset_button_push) == "1\n": - is_reset_button_push = 1 - else: - is_reset_button_push = 0 - - with open("/sys/bus/i2c/devices/3-004d/hwmon/hwmon2/temp1_input", "r") as f3: - is_thermal_high = f3.read() - if int(is_thermal_high) >= 70000: - is_thermal_high = 1 - else: - is_thermal_high = 0 - - with open("/sys/bus/i2c/devices/8-005f/sys_status", "w") as f2: - if is_reset_button_push == 1: - f2.write("3") - elif is_fan_all_OK == 0 or is_power_all_OK == 0 or is_thermal_high == 1: - f2.write("4") - else: - f2.write("1") - - return + global read_fan_fault, read_power_status, is_fan_all_OK, is_power_all_OK, is_thermal_high, is_reset_button_push + is_fan_all_OK = 1 + is_power_all_OK = 0 + is_thermal_high = 0 + is_reset_button_push = 0 + with open("/sys/bus/i2c/devices/0-005e/fan1_fault", "r") as f1: + read_fan_fault = f1.read() + if str(read_fan_fault) == str("1\n"): + is_fan_all_OK = 0 + with open("/sys/bus/i2c/devices/0-005e/fan2_fault", "r") as f1: + read_fan_fault = f1.read() + if str(read_fan_fault) == str("1\n"): + is_fan_all_OK = 0 + with open("/sys/bus/i2c/devices/0-005e/fan3_fault", "r") as f1: + read_fan_fault = f1.read() + if str(read_fan_fault) == str("1\n"): + is_fan_all_OK = 0 + with open("/sys/bus/i2c/devices/0-005e/fan4_fault", "r") as f1: + read_fan_fault = f1.read() + if str(read_fan_fault) == str("1\n"): + is_fan_all_OK = 0 + + with open("/sys/bus/i2c/devices/8-005f/fan1_led", "w") as f11: + if int(is_fan_all_OK) == 1: + f11.write("1") + else: + f11.write("4") + + with open("/sys/bus/i2c/devices/0-005e/psu1_power_good", "r") as f1: + read_power_status = f1.read() + if str(read_power_status) != str("1\n"): + is_power_all_OK = -10 + with open("/sys/bus/i2c/devices/0-005e/psu1_present", "r") as f1: + read_power_status = f1.read() + if str(read_power_status) == str("1\n"): + is_power_all_OK = is_power_all_OK + 1 + with open("/sys/bus/i2c/devices/0-005e/psu2_power_good", "r") as f1: + read_power_status = f1.read() + if str(read_power_status) != str("1\n"): + is_power_all_OK = -10 + with open("/sys/bus/i2c/devices/0-005e/psu2_present", "r") as f1: + read_power_status = f1.read() + if str(read_power_status) == str("1\n"): + is_power_all_OK = is_power_all_OK + 1 + + with open("/sys/bus/i2c/devices/8-005f/sys_pwr", "w") as f11: + if int(is_power_all_OK) > 0: + f11.write("1") + else: + f11.write("4") + + with open("/sys/bus/i2c/devices/8-005f/swi_ctrl", "r") as f5: + is_reset_button_push = f5.read() + if str(is_reset_button_push) == "1\n": + is_reset_button_push = 1 + else: + is_reset_button_push = 0 + + with open("/sys/bus/i2c/devices/3-004d/hwmon/hwmon2/temp1_input", "r") as f3: + is_thermal_high = f3.read() + if int(is_thermal_high) >= 70000: + is_thermal_high = 1 + else: + is_thermal_high = 0 + + with open("/sys/bus/i2c/devices/8-005f/sys_status", "w") as f2: + if is_reset_button_push == 1: + f2.write("3") + elif is_fan_all_OK == 0 or is_power_all_OK == 0 or is_thermal_high == 1: + f2.write("4") + else: + f2.write("1") + + return ########## - + + class LedControl(LedControlBase): """Platform specific LED control class""" PORT_TABLE_PREFIX = "PORT_TABLE:" @@ -149,18 +151,18 @@ def _port_name_to_qsfp_index(self, port_name): swss = swsssdk.SonicV2Connector() swss.connect(swss.APPL_DB) - lanes = swss.get(swss.APPL_DB, self.PORT_TABLE_PREFIX + port_name, 'lanes') + lanes = swss.get( + swss.APPL_DB, self.PORT_TABLE_PREFIX + port_name, 'lanes') # SONiC port nums are 0-based and increment by 4 # Arista QSFP indices are 1-based and increment by 1 - return (((sonic_port_num/4) + 1), sonic_port_num%4, len(lanes.split(','))) - - + return (((sonic_port_num/4) + 1), sonic_port_num % 4, len(lanes.split(','))) # Concrete implementation of port_link_state_change() method + def port_link_state_change_bk(self, port, state): qsfp_index, lane_index, lanes = self._port_name_to_qsfp_index(port) - + # Ignore invalid QSFP indices if qsfp_index <= 0 or lanes <= 0 or lanes > 4: return @@ -169,9 +171,11 @@ def port_link_state_change_bk(self, port, state): # whereas indices 25-32 are not breakout-capable, and only have one if qsfp_index <= self.QSFP_BREAKOUT_END_IDX: # assuming 40G, then we need to control four lanes - led_sysfs_paths = [ self.LED_SYSFS_PATH_BREAKOUT_CAPABLE.format(qsfp_index, i) for i in range(lane_index + 1, lane_index + 1 + lanes) ] + led_sysfs_paths = [self.LED_SYSFS_PATH_BREAKOUT_CAPABLE.format( + qsfp_index, i) for i in range(lane_index + 1, lane_index + 1 + lanes)] else: - led_sysfs_paths = [ self.LED_SYSFS_PATH_NO_BREAKOUT.format(qsfp_index) ] + led_sysfs_paths = [ + self.LED_SYSFS_PATH_NO_BREAKOUT.format(qsfp_index)] for led_sysfs_path in led_sysfs_paths: led_file = open(led_sysfs_path, "w") @@ -202,7 +206,7 @@ def __init__(self): f.write("1") with open("/sys/bus/i2c/devices/8-005f/fan4_led", "w") as f: f.write("1") - sysled_task() + sysled_task() # Initialize: Turn all front panel QSFP LEDs off # # for qsfp_index in range(self.QSFP_BREAKOUT_START_IDX, self.QSFP_BREAKOUT_END_IDX + 1): diff --git a/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/psuutil.py b/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/psuutil.py index 7a3b87f24d2d..d189349b5d0e 100644 --- a/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/psuutil.py +++ b/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Alphanetworks # @@ -13,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/sfputil.py b/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/sfputil.py index cc3cd4e8611d..e2c2aae496cc 100644 --- a/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/sfputil.py +++ b/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/sfputil.py @@ -1,10 +1,8 @@ -#!/usr/bin/env python - try: import time - from sonic_sfp.sfputilbase import SfpUtilBase -except ImportError, e: - raise ImportError (str(e) + "- required module not found") + from sonic_sfp.sfputilbase import SfpUtilBase +except ImportError as e: + raise ImportError(str(e) + "- required module not found") class SfpUtil(SfpUtilBase): @@ -16,11 +14,11 @@ class SfpUtil(SfpUtilBase): port_to_eeprom = {} port_to_i2cbus_mapping = { - 1 : 13, - 2 : 14, - 3 : 15, - 4 : 16, - 5 : 23, + 1: 13, + 2: 14, + 3: 15, + 4: 16, + 5: 23, } eeprom_path_1 = "/sys/bus/i2c/devices/{0}-0020/sfp{1}_eeprom" @@ -30,7 +28,7 @@ class SfpUtil(SfpUtilBase): present_path_1 = "/sys/bus/i2c/devices/{0}-0020/sfp{1}_is_present" present_path = "/sys/bus/i2c/devices/{0}-005f/sfp{1}_is_present" - _qsfp_ports = range(first_port, port_num) + _qsfp_ports = list(range(first_port, port_num)) @property def port_start(self): @@ -42,11 +40,11 @@ def port_end(self): @property def qsfp_ports(self): - return range(self.first_port, self.port_num + 1) + return list(range(self.first_port, self.port_num + 1)) - @property + @property def port_to_eeprom_mapping(self): - return self.port_to_eeprom + return self.port_to_eeprom def get_transceiver_change_event(self): """ @@ -79,12 +77,12 @@ def reset(self, port_num): else: path = self.port_reset_path port_path = path.format(self.port_to_i2cbus_mapping[cpld_index], index) - + try: reg_file = open(port_path, 'w') except IOError as e: if cpld_index < 5: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # reset @@ -102,7 +100,7 @@ def set_low_power_mode(self, port_nuM, lpmode): def get_low_power_mode(self, port_num): raise NotImplementedError - + def get_presence(self, port_num): # Check for invalid port_num if port_num < self.first_port or port_num > self.last_port: @@ -116,12 +114,11 @@ def get_presence(self, port_num): path = self.present_path port_path = path.format(self.port_to_i2cbus_mapping[cpld_index], index) - try: reg_file = open(port_path) except IOError as e: if cpld_index < 5: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_file.readline().rstrip() @@ -129,4 +126,3 @@ def get_presence(self, port_num): return True return False - diff --git a/device/arista/x86_64-arista_common/platform_reboot b/device/arista/x86_64-arista_common/platform_reboot index b8b1a5d7bfe5..1c3f954c03cc 100755 --- a/device/arista/x86_64-arista_common/platform_reboot +++ b/device/arista/x86_64-arista_common/platform_reboot @@ -1,11 +1,13 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import arista.platforms from arista.utils.sonic_reboot import reboot + def main(): - # reboot the system - reboot() + # reboot the system + reboot() + if __name__ == "__main__": - main() + main() diff --git a/device/arista/x86_64-arista_common/plugins/eeprom.py b/device/arista/x86_64-arista_common/plugins/eeprom.py index 5c0286979056..3cc5a6b13c59 100644 --- a/device/arista/x86_64-arista_common/plugins/eeprom.py +++ b/device/arista/x86_64-arista_common/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # # Arista eeprom processing for SONiC # Uses the arista driver library to obtain the TlvInfoDecoder diff --git a/device/arista/x86_64-arista_common/plugins/led_control.py b/device/arista/x86_64-arista_common/plugins/led_control.py index febb04ad1616..8ea9f70a8604 100644 --- a/device/arista/x86_64-arista_common/plugins/led_control.py +++ b/device/arista/x86_64-arista_common/plugins/led_control.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # # Arista LED controls for SONiC # diff --git a/device/arista/x86_64-arista_common/plugins/psuutil.py b/device/arista/x86_64-arista_common/plugins/psuutil.py index 46ec6b32e2e4..14755365257b 100644 --- a/device/arista/x86_64-arista_common/plugins/psuutil.py +++ b/device/arista/x86_64-arista_common/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # # Arista PSU interface for SONiC # diff --git a/device/arista/x86_64-arista_common/plugins/sfputil.py b/device/arista/x86_64-arista_common/plugins/sfputil.py index 5e02eef69aef..4c99ad533f27 100644 --- a/device/arista/x86_64-arista_common/plugins/sfputil.py +++ b/device/arista/x86_64-arista_common/plugins/sfputil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # # Arista SFP transceiver interface for SONiC # diff --git a/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/eeprom.py b/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/eeprom.py index 937cc003f60e..b94fab471b95 100644 --- a/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/eeprom.py +++ b/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/eeprom.py @@ -1,6 +1,3 @@ -#!/usr/bin/python - - try: import importlib import time @@ -23,52 +20,63 @@ from thrift.protocol import TMultiplexedProtocol from argparse import ArgumentParser - from cStringIO import StringIO + + if sys.version_info.major == 3: + from io import StringIO + else: + from cStringIO import StringIO + from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + + +if sys.version_info.major == 3: + STRING_TYPE = str +else: + STRING_TYPE = basestring eeprom_default_dict = { - "prod_name" : ("Product Name", "0x21", 12), - "odm_pcba_part_num" : ("Part Number", "0x22", 13), - "prod_ser_num" : ("Serial Number", "0x23", 12), - "ext_mac_addr" : ("Extended MAC Address Base", "0x24", 12), - "sys_mfg_date" : ("System Manufacturing Date", "0x25", 4), - "prod_ver" : ("Product Version", "0x26", 1), - "ext_mac_addr_size" : ("Extende MAC Address Size", "0x2A", 2), - "sys_mfger" : ("Manufacturer", "0x2B", 8) + "prod_name": ("Product Name", "0x21", 12), + "odm_pcba_part_num": ("Part Number", "0x22", 13), + "prod_ser_num": ("Serial Number", "0x23", 12), + "ext_mac_addr": ("Extended MAC Address Base", "0x24", 12), + "sys_mfg_date": ("System Manufacturing Date", "0x25", 4), + "prod_ver": ("Product Version", "0x26", 1), + "ext_mac_addr_size": ("Extende MAC Address Size", "0x2A", 2), + "sys_mfger": ("Manufacturer", "0x2B", 8) } -eeprom_dict = { "version" : ("Version", None, 0), - "pcb_mfger" : ("PCB Manufacturer", "0x01", 8), - "prod_ser_num" : ("Serial Number", "0x23", 12), - "bfn_pcba_part_num" : ("Switch PCBA Part Number", "0x02", 12), - "odm_pcba_part_num" : ("Part Number", "0x22", 13), - "bfn_pcbb_part_num" : ("Switch PCBB Part Number", "0x04", 12), - "sys_asm_part_num" : ("System Assembly Part Number", "0x05", 12), - "prod_state" : ("Product Production State", "0x06", 1), - "location" : ("EEPROM Location of Fabric", "0x07", 8), - "ext_mac_addr_size" : ("Extende MAC Address Size", "0x08", 2), - "sys_mfg_date" : ("System Manufacturing Date", "0x25", 4), - "prod_name" : ("Product Name", "0x21", 12), - "prod_ver" : ("Product Version", "0x26", 1), - "prod_part_num" : ("Product Part Number", "0x09", 8), - "sys_mfger" : ("Manufacturer", "0x2B", 8), - "assembled_at" : ("Assembled at", "0x08", 8), - "prod_ast_tag" : ("Product Asset Tag", "0x09", 12), - "loc_mac_addr" : ("Local MAC address", "0x0A", 12), - "odm_pcba_ser_num" : ("ODM PBCA Serial Number", "0x0B", 12), - "ext_mac_addr" : ("Extended MAC Address Base", "0x0C", 12), - "prod_sub_ver" : ("Product Sub Version", "0x0D", 1) - } - -product_dict = { "Montara" : "Wedge100BF-32X-O-AC-F-BF", - "Lower MAV" : "Wedge100BF-65X-O-AC-F-BF", - "Upper MAV" : "Wedge100BF-65X-O-AC-F-BF" +eeprom_dict = {"version": ("Version", None, 0), + "pcb_mfger": ("PCB Manufacturer", "0x01", 8), + "prod_ser_num": ("Serial Number", "0x23", 12), + "bfn_pcba_part_num": ("Switch PCBA Part Number", "0x02", 12), + "odm_pcba_part_num": ("Part Number", "0x22", 13), + "bfn_pcbb_part_num": ("Switch PCBB Part Number", "0x04", 12), + "sys_asm_part_num": ("System Assembly Part Number", "0x05", 12), + "prod_state": ("Product Production State", "0x06", 1), + "location": ("EEPROM Location of Fabric", "0x07", 8), + "ext_mac_addr_size": ("Extende MAC Address Size", "0x08", 2), + "sys_mfg_date": ("System Manufacturing Date", "0x25", 4), + "prod_name": ("Product Name", "0x21", 12), + "prod_ver": ("Product Version", "0x26", 1), + "prod_part_num": ("Product Part Number", "0x09", 8), + "sys_mfger": ("Manufacturer", "0x2B", 8), + "assembled_at": ("Assembled at", "0x08", 8), + "prod_ast_tag": ("Product Asset Tag", "0x09", 12), + "loc_mac_addr": ("Local MAC address", "0x0A", 12), + "odm_pcba_ser_num": ("ODM PBCA Serial Number", "0x0B", 12), + "ext_mac_addr": ("Extended MAC Address Base", "0x0C", 12), + "prod_sub_ver": ("Product Sub Version", "0x0D", 1) } +product_dict = {"Montara": "Wedge100BF-32X-O-AC-F-BF", + "Lower MAV": "Wedge100BF-65X-O-AC-F-BF", + "Upper MAV": "Wedge100BF-65X-O-AC-F-BF" + } + thrift_server = 'localhost' transport = None pltfm_mgr = None @@ -76,6 +84,7 @@ EEPROM_SYMLINK = "/var/run/platform/eeprom/syseeprom" EEPROM_STATUS = "/var/run/platform/eeprom/status" + class board(eeprom_tlvinfo.TlvInfoDecoder): RETRIES = 35 @@ -114,8 +123,10 @@ def thrift_setup(self): transport = TTransport.TBufferedTransport(transport) bprotocol = TBinaryProtocol.TBinaryProtocol(transport) - pltfm_mgr_client_module = importlib.import_module(".".join(["pltfm_mgr_rpc", "pltfm_mgr_rpc"])) - pltfm_mgr_protocol = TMultiplexedProtocol.TMultiplexedProtocol(bprotocol, "pltfm_mgr_rpc") + pltfm_mgr_client_module = importlib.import_module( + ".".join(["pltfm_mgr_rpc", "pltfm_mgr_rpc"])) + pltfm_mgr_protocol = TMultiplexedProtocol.TMultiplexedProtocol( + bprotocol, "pltfm_mgr_rpc") pltfm_mgr = pltfm_mgr_client_module.Client(pltfm_mgr_protocol) transport.open() @@ -139,7 +150,7 @@ def eeprom_init(self): f.close() eeprom_params = "" - for attr, val in eeprom.__dict__.iteritems(): + for attr, val in eeprom.__dict__.items(): if val is None: continue @@ -147,13 +158,14 @@ def eeprom_init(self): if elem is None: continue - if isinstance(val, basestring): + if isinstance(val, STRING_TYPE): value = val.replace('\0', '') else: value = str(val) if attr == "sys_mfg_date": - value = datetime.datetime.strptime(value, '%m-%d-%y').strftime('%m/%d/%Y 00:00:00') + value = datetime.datetime.strptime( + value, '%m-%d-%y').strftime('%m/%d/%Y 00:00:00') product = product_dict.get(value) if product is not None: @@ -164,9 +176,9 @@ def eeprom_init(self): orig_stdout = sys.stdout sys.stdout = StringIO() - new_e = eeprom_tlvinfo.TlvInfoDecoder.set_eeprom(self, "", [eeprom_params]) + new_e = eeprom_tlvinfo.TlvInfoDecoder.set_eeprom( + self, "", [eeprom_params]) sys.stdout = orig_stdout eeprom_base.EepromDecoder.write_eeprom(self, new_e) return True - diff --git a/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/pltfm_mgr_rpc/pltfm_mgr_rpc.py b/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/pltfm_mgr_rpc/pltfm_mgr_rpc.py index b256b6285fc3..8f5b89e4312a 100644 --- a/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/pltfm_mgr_rpc/pltfm_mgr_rpc.py +++ b/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/pltfm_mgr_rpc/pltfm_mgr_rpc.py @@ -177,7 +177,8 @@ def recv_pltfm_mgr_sys_tmp_get(self): return result.success if result.ouch is not None: raise result.ouch - raise TApplicationException(TApplicationException.MISSING_RESULT, "pltfm_mgr_sys_tmp_get failed: unknown result") + raise TApplicationException(TApplicationException.MISSING_RESULT, + "pltfm_mgr_sys_tmp_get failed: unknown result") def pltfm_mgr_sys_eeprom_get(self): self.send_pltfm_mgr_sys_eeprom_get() @@ -205,7 +206,8 @@ def recv_pltfm_mgr_sys_eeprom_get(self): return result.success if result.ouch is not None: raise result.ouch - raise TApplicationException(TApplicationException.MISSING_RESULT, "pltfm_mgr_sys_eeprom_get failed: unknown result") + raise TApplicationException(TApplicationException.MISSING_RESULT, + "pltfm_mgr_sys_eeprom_get failed: unknown result") def pltfm_mgr_pwr_supply_present_get(self, ps_num): """ @@ -238,7 +240,8 @@ def recv_pltfm_mgr_pwr_supply_present_get(self): return result.success if result.ouch is not None: raise result.ouch - raise TApplicationException(TApplicationException.MISSING_RESULT, "pltfm_mgr_pwr_supply_present_get failed: unknown result") + raise TApplicationException(TApplicationException.MISSING_RESULT, + "pltfm_mgr_pwr_supply_present_get failed: unknown result") def pltfm_mgr_pwr_supply_info_get(self, ps_num): """ @@ -271,7 +274,8 @@ def recv_pltfm_mgr_pwr_supply_info_get(self): return result.success if result.ouch is not None: raise result.ouch - raise TApplicationException(TApplicationException.MISSING_RESULT, "pltfm_mgr_pwr_supply_info_get failed: unknown result") + raise TApplicationException(TApplicationException.MISSING_RESULT, + "pltfm_mgr_pwr_supply_info_get failed: unknown result") def pltfm_mgr_pwr_rail_info_get(self, ps_num): """ @@ -304,7 +308,8 @@ def recv_pltfm_mgr_pwr_rail_info_get(self): return result.success if result.ouch is not None: raise result.ouch - raise TApplicationException(TApplicationException.MISSING_RESULT, "pltfm_mgr_pwr_rail_info_get failed: unknown result") + raise TApplicationException(TApplicationException.MISSING_RESULT, + "pltfm_mgr_pwr_rail_info_get failed: unknown result") def pltfm_mgr_fan_speed_set(self, fan_num, percent): """ @@ -339,7 +344,8 @@ def recv_pltfm_mgr_fan_speed_set(self): return result.success if result.ouch is not None: raise result.ouch - raise TApplicationException(TApplicationException.MISSING_RESULT, "pltfm_mgr_fan_speed_set failed: unknown result") + raise TApplicationException(TApplicationException.MISSING_RESULT, + "pltfm_mgr_fan_speed_set failed: unknown result") def pltfm_mgr_fan_info_get(self, fan_num): """ @@ -372,7 +378,8 @@ def recv_pltfm_mgr_fan_info_get(self): return result.success if result.ouch is not None: raise result.ouch - raise TApplicationException(TApplicationException.MISSING_RESULT, "pltfm_mgr_fan_info_get failed: unknown result") + raise TApplicationException(TApplicationException.MISSING_RESULT, + "pltfm_mgr_fan_info_get failed: unknown result") def pltfm_mgr_qsfp_presence_get(self, port_num): """ @@ -405,7 +412,8 @@ def recv_pltfm_mgr_qsfp_presence_get(self): return result.success if result.ouch is not None: raise result.ouch - raise TApplicationException(TApplicationException.MISSING_RESULT, "pltfm_mgr_qsfp_presence_get failed: unknown result") + raise TApplicationException(TApplicationException.MISSING_RESULT, + "pltfm_mgr_qsfp_presence_get failed: unknown result") def pltfm_mgr_qsfp_info_get(self, port_num): """ @@ -438,7 +446,8 @@ def recv_pltfm_mgr_qsfp_info_get(self): return result.success if result.ouch is not None: raise result.ouch - raise TApplicationException(TApplicationException.MISSING_RESULT, "pltfm_mgr_qsfp_info_get failed: unknown result") + raise TApplicationException(TApplicationException.MISSING_RESULT, + "pltfm_mgr_qsfp_info_get failed: unknown result") def pltfm_mgr_qsfp_get_max_port(self): self.send_pltfm_mgr_qsfp_get_max_port() @@ -466,7 +475,8 @@ def recv_pltfm_mgr_qsfp_get_max_port(self): return result.success if result.ouch is not None: raise result.ouch - raise TApplicationException(TApplicationException.MISSING_RESULT, "pltfm_mgr_qsfp_get_max_port failed: unknown result") + raise TApplicationException(TApplicationException.MISSING_RESULT, + "pltfm_mgr_qsfp_get_max_port failed: unknown result") def pltfm_mgr_qsfp_reset(self, port_num, reset): """ @@ -534,7 +544,8 @@ def recv_pltfm_mgr_qsfp_lpmode_get(self): return result.success if result.ouch is not None: raise result.ouch - raise TApplicationException(TApplicationException.MISSING_RESULT, "pltfm_mgr_qsfp_lpmode_get failed: unknown result") + raise TApplicationException(TApplicationException.MISSING_RESULT, + "pltfm_mgr_qsfp_lpmode_get failed: unknown result") def pltfm_mgr_qsfp_lpmode_set(self, port_num, lpmode): """ @@ -569,7 +580,8 @@ def recv_pltfm_mgr_qsfp_lpmode_set(self): return result.success if result.ouch is not None: raise result.ouch - raise TApplicationException(TApplicationException.MISSING_RESULT, "pltfm_mgr_qsfp_lpmode_set failed: unknown result") + raise TApplicationException(TApplicationException.MISSING_RESULT, + "pltfm_mgr_qsfp_lpmode_set failed: unknown result") def pltfm_mgr_sensor_info_get(self, options): """ @@ -602,7 +614,8 @@ def recv_pltfm_mgr_sensor_info_get(self): return result.success if result.ouch is not None: raise result.ouch - raise TApplicationException(TApplicationException.MISSING_RESULT, "pltfm_mgr_sensor_info_get failed: unknown result") + raise TApplicationException(TApplicationException.MISSING_RESULT, + "pltfm_mgr_sensor_info_get failed: unknown result") class Processor(Iface, TProcessor): @@ -1020,7 +1033,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -1079,7 +1092,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -1121,7 +1134,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -1194,7 +1207,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -1236,7 +1249,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -1309,7 +1322,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -1369,7 +1382,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -1441,7 +1454,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -1501,7 +1514,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -1574,7 +1587,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -1634,7 +1647,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -1707,7 +1720,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -1779,7 +1792,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -1851,7 +1864,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -1911,7 +1924,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -1984,7 +1997,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -2044,7 +2057,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -2116,7 +2129,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -2176,7 +2189,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -2213,7 +2226,8 @@ def read(self, iprot): break if fid == 0: if ftype == TType.STRING: - self.success = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + self.success = iprot.readString().decode( + 'utf-8') if sys.version_info[0] == 2 else iprot.readString() else: iprot.skip(ftype) elif fid == 1: @@ -2248,7 +2262,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -2290,7 +2304,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -2362,7 +2376,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -2434,7 +2448,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -2506,7 +2520,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -2566,7 +2580,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -2638,7 +2652,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -2710,7 +2724,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -2782,7 +2796,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -2817,7 +2831,8 @@ def read(self, iprot): break if fid == 1: if ftype == TType.STRING: - self.options = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + self.options = iprot.readString().decode( + 'utf-8') if sys.version_info[0] == 2 else iprot.readString() else: iprot.skip(ftype) else: @@ -2842,7 +2857,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -2879,7 +2894,8 @@ def read(self, iprot): break if fid == 0: if ftype == TType.STRING: - self.success = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + self.success = iprot.readString().decode( + 'utf-8') if sys.version_info[0] == 2 else iprot.readString() else: iprot.skip(ftype) elif fid == 1: @@ -2914,7 +2930,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): diff --git a/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/pltfm_mgr_rpc/ttypes.py b/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/pltfm_mgr_rpc/ttypes.py index ce03e14f8691..1f88c3c1f94f 100644 --- a/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/pltfm_mgr_rpc/ttypes.py +++ b/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/pltfm_mgr_rpc/ttypes.py @@ -171,7 +171,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -274,37 +274,44 @@ def read(self, iprot): iprot.skip(ftype) elif fid == 2: if ftype == TType.STRING: - self.prod_name = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + self.prod_name = iprot.readString().decode( + 'utf-8') if sys.version_info[0] == 2 else iprot.readString() else: iprot.skip(ftype) elif fid == 3: if ftype == TType.STRING: - self.prod_part_num = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + self.prod_part_num = iprot.readString().decode( + 'utf-8') if sys.version_info[0] == 2 else iprot.readString() else: iprot.skip(ftype) elif fid == 4: if ftype == TType.STRING: - self.sys_asm_part_num = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + self.sys_asm_part_num = iprot.readString().decode( + 'utf-8') if sys.version_info[0] == 2 else iprot.readString() else: iprot.skip(ftype) elif fid == 5: if ftype == TType.STRING: - self.bfn_pcba_part_num = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + self.bfn_pcba_part_num = iprot.readString().decode( + 'utf-8') if sys.version_info[0] == 2 else iprot.readString() else: iprot.skip(ftype) elif fid == 6: if ftype == TType.STRING: - self.bfn_pcbb_part_num = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + self.bfn_pcbb_part_num = iprot.readString().decode( + 'utf-8') if sys.version_info[0] == 2 else iprot.readString() else: iprot.skip(ftype) elif fid == 7: if ftype == TType.STRING: - self.odm_pcba_part_num = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + self.odm_pcba_part_num = iprot.readString().decode( + 'utf-8') if sys.version_info[0] == 2 else iprot.readString() else: iprot.skip(ftype) elif fid == 8: if ftype == TType.STRING: - self.odm_pcba_ser_num = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + self.odm_pcba_ser_num = iprot.readString().decode( + 'utf-8') if sys.version_info[0] == 2 else iprot.readString() else: iprot.skip(ftype) elif fid == 9: @@ -324,42 +331,50 @@ def read(self, iprot): iprot.skip(ftype) elif fid == 12: if ftype == TType.STRING: - self.prod_ser_num = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + self.prod_ser_num = iprot.readString().decode( + 'utf-8') if sys.version_info[0] == 2 else iprot.readString() else: iprot.skip(ftype) elif fid == 13: if ftype == TType.STRING: - self.prod_ast_tag = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + self.prod_ast_tag = iprot.readString().decode( + 'utf-8') if sys.version_info[0] == 2 else iprot.readString() else: iprot.skip(ftype) elif fid == 14: if ftype == TType.STRING: - self.sys_mfger = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + self.sys_mfger = iprot.readString().decode( + 'utf-8') if sys.version_info[0] == 2 else iprot.readString() else: iprot.skip(ftype) elif fid == 15: if ftype == TType.STRING: - self.sys_mfg_date = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + self.sys_mfg_date = iprot.readString().decode( + 'utf-8') if sys.version_info[0] == 2 else iprot.readString() else: iprot.skip(ftype) elif fid == 16: if ftype == TType.STRING: - self.pcb_mfger = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + self.pcb_mfger = iprot.readString().decode( + 'utf-8') if sys.version_info[0] == 2 else iprot.readString() else: iprot.skip(ftype) elif fid == 17: if ftype == TType.STRING: - self.assembled_at = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + self.assembled_at = iprot.readString().decode( + 'utf-8') if sys.version_info[0] == 2 else iprot.readString() else: iprot.skip(ftype) elif fid == 18: if ftype == TType.STRING: - self.loc_mac_addr = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + self.loc_mac_addr = iprot.readString().decode( + 'utf-8') if sys.version_info[0] == 2 else iprot.readString() else: iprot.skip(ftype) elif fid == 19: if ftype == TType.STRING: - self.ext_mac_addr = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + self.ext_mac_addr = iprot.readString().decode( + 'utf-8') if sys.version_info[0] == 2 else iprot.readString() else: iprot.skip(ftype) elif fid == 20: @@ -369,7 +384,8 @@ def read(self, iprot): iprot.skip(ftype) elif fid == 21: if ftype == TType.STRING: - self.location = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + self.location = iprot.readString().decode( + 'utf-8') if sys.version_info[0] == 2 else iprot.readString() else: iprot.skip(ftype) elif fid == 22: @@ -401,23 +417,28 @@ def write(self, oprot): oprot.writeFieldEnd() if self.sys_asm_part_num is not None: oprot.writeFieldBegin('sys_asm_part_num', TType.STRING, 4) - oprot.writeString(self.sys_asm_part_num.encode('utf-8') if sys.version_info[0] == 2 else self.sys_asm_part_num) + oprot.writeString(self.sys_asm_part_num.encode('utf-8') + if sys.version_info[0] == 2 else self.sys_asm_part_num) oprot.writeFieldEnd() if self.bfn_pcba_part_num is not None: oprot.writeFieldBegin('bfn_pcba_part_num', TType.STRING, 5) - oprot.writeString(self.bfn_pcba_part_num.encode('utf-8') if sys.version_info[0] == 2 else self.bfn_pcba_part_num) + oprot.writeString(self.bfn_pcba_part_num.encode('utf-8') + if sys.version_info[0] == 2 else self.bfn_pcba_part_num) oprot.writeFieldEnd() if self.bfn_pcbb_part_num is not None: oprot.writeFieldBegin('bfn_pcbb_part_num', TType.STRING, 6) - oprot.writeString(self.bfn_pcbb_part_num.encode('utf-8') if sys.version_info[0] == 2 else self.bfn_pcbb_part_num) + oprot.writeString(self.bfn_pcbb_part_num.encode('utf-8') + if sys.version_info[0] == 2 else self.bfn_pcbb_part_num) oprot.writeFieldEnd() if self.odm_pcba_part_num is not None: oprot.writeFieldBegin('odm_pcba_part_num', TType.STRING, 7) - oprot.writeString(self.odm_pcba_part_num.encode('utf-8') if sys.version_info[0] == 2 else self.odm_pcba_part_num) + oprot.writeString(self.odm_pcba_part_num.encode('utf-8') + if sys.version_info[0] == 2 else self.odm_pcba_part_num) oprot.writeFieldEnd() if self.odm_pcba_ser_num is not None: oprot.writeFieldBegin('odm_pcba_ser_num', TType.STRING, 8) - oprot.writeString(self.odm_pcba_ser_num.encode('utf-8') if sys.version_info[0] == 2 else self.odm_pcba_ser_num) + oprot.writeString(self.odm_pcba_ser_num.encode('utf-8') + if sys.version_info[0] == 2 else self.odm_pcba_ser_num) oprot.writeFieldEnd() if self.prod_state is not None: oprot.writeFieldBegin('prod_state', TType.I16, 9) @@ -483,7 +504,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -651,7 +672,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -891,7 +912,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -987,7 +1008,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -1050,7 +1071,7 @@ def __str__(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): diff --git a/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/psuutil.py b/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/psuutil.py index 2c0e2fdb224e..0ef5162d282c 100644 --- a/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/psuutil.py +++ b/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - try: import os import sys @@ -16,12 +14,13 @@ from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") thrift_server = 'localhost' transport = None pltfm_mgr = None + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" @@ -35,8 +34,10 @@ def thrift_setup(self): transport = TTransport.TBufferedTransport(transport) bprotocol = TBinaryProtocol.TBinaryProtocol(transport) - pltfm_mgr_client_module = importlib.import_module(".".join(["pltfm_mgr_rpc", "pltfm_mgr_rpc"])) - pltfm_mgr_protocol = TMultiplexedProtocol.TMultiplexedProtocol(bprotocol, "pltfm_mgr_rpc") + pltfm_mgr_client_module = importlib.import_module( + ".".join(["pltfm_mgr_rpc", "pltfm_mgr_rpc"])) + pltfm_mgr_protocol = TMultiplexedProtocol.TMultiplexedProtocol( + bprotocol, "pltfm_mgr_rpc") pltfm_mgr = pltfm_mgr_client_module.Client(pltfm_mgr_protocol) transport.open() @@ -65,9 +66,9 @@ def get_psu_status(self, index): global pltfm_mgr try: - self.thrift_setup() - psu_info = pltfm_mgr.pltfm_mgr_pwr_supply_info_get(index) - self.thrift_teardown() + self.thrift_setup() + psu_info = pltfm_mgr.pltfm_mgr_pwr_supply_info_get(index) + self.thrift_teardown() except: return False @@ -86,11 +87,10 @@ def get_psu_presence(self, index): global pltfm_mgr try: - self.thrift_setup() - status = pltfm_mgr.pltfm_mgr_pwr_supply_present_get(index) - self.thrift_teardown() + self.thrift_setup() + status = pltfm_mgr.pltfm_mgr_pwr_supply_present_get(index) + self.thrift_teardown() except: return False return status - diff --git a/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/sfputil.py b/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/sfputil.py index 00ab0f94ec1a..47d875432cc5 100644 --- a/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/sfputil.py +++ b/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/sfputil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - try: import os import sys @@ -17,7 +15,7 @@ from sonic_sfp.sfputilbase import SfpUtilBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") thrift_server = 'localhost' transport = None @@ -25,6 +23,7 @@ SFP_EEPROM_CACHE = "/var/run/platform/sfp/cache" + class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" @@ -51,12 +50,12 @@ def port_end(self): @property def qsfp_ports(self): self.update_port_info() - return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): - print "dependency on sysfs has been removed" - raise Exception() + print("dependency on sysfs has been removed") + raise Exception() def __init__(self): self.ready = False @@ -80,7 +79,7 @@ def update_port_info(self): if self.QSFP_PORT_END == 0: self.thrift_setup() - self.QSFP_PORT_END = pltfm_mgr.pltfm_mgr_qsfp_get_max_port(); + self.QSFP_PORT_END = pltfm_mgr.pltfm_mgr_qsfp_get_max_port() self.PORT_END = self.QSFP_PORT_END self.PORTS_IN_BLOCK = self.QSFP_PORT_END self.thrift_teardown() @@ -127,8 +126,8 @@ def get_presence(self, port_num): presence = pltfm_mgr.pltfm_mgr_qsfp_presence_get(port_num) self.thrift_teardown() except Exception as e: - print e.__doc__ - print e.message + print(e.__doc__) + print(e.message) return presence @@ -198,9 +197,9 @@ def get_transceiver_change_event(self, timeout=0): if timeout == 0: forever = True elif timeout > 0: - timeout = timeout / float(1000) # Convert to secs + timeout = timeout / float(1000) # Convert to secs else: - print "get_transceiver_change_event:Invalid timeout value", timeout + print("get_transceiver_change_event:Invalid timeout value", timeout) return False, {} while forever or timeout > 0: @@ -249,4 +248,3 @@ def _get_port_eeprom_path(self, port_num, devid): self.thrift_teardown() return eeprom_path - diff --git a/device/broadcom/x86_64-bcm_xlr-r0/plugins/eeprom.py b/device/broadcom/x86_64-bcm_xlr-r0/plugins/eeprom.py index 25ea4849f7d5..0a4e11155711 100644 --- a/device/broadcom/x86_64-bcm_xlr-r0/plugins/eeprom.py +++ b/device/broadcom/x86_64-bcm_xlr-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Broadcom XLR/GTS 'eeprom' support # @@ -16,8 +14,8 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): @@ -25,7 +23,7 @@ class board(eeprom_tlvinfo.TlvInfoDecoder): def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/usr/share/sonic/platform/sys_eeprom.bin" if os.path.isfile(self.eeprom_path) is False: - self.eeprom_path = "/usr/share/sonic/device/x86_64-bcm_xlr-r0/sys_eeprom.bin" + self.eeprom_path = "/usr/share/sonic/device/x86_64-bcm_xlr-r0/sys_eeprom.bin" super(board, self).__init__(self.eeprom_path, 0, '', False, True) def serial_number_str(self, e): diff --git a/device/broadcom/x86_64-bcm_xlr-r0/plugins/psuutil.py b/device/broadcom/x86_64-bcm_xlr-r0/plugins/psuutil.py index 5cfdda1578b9..fefc3c3494e5 100644 --- a/device/broadcom/x86_64-bcm_xlr-r0/plugins/psuutil.py +++ b/device/broadcom/x86_64-bcm_xlr-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - import os.path try: diff --git a/device/broadcom/x86_64-bcm_xlr-r0/plugins/sfputil.py b/device/broadcom/x86_64-bcm_xlr-r0/plugins/sfputil.py index 3dc25793ba4a..f526706f5dd4 100644 --- a/device/broadcom/x86_64-bcm_xlr-r0/plugins/sfputil.py +++ b/device/broadcom/x86_64-bcm_xlr-r0/plugins/sfputil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - try: import time import os diff --git a/device/celestica/x86_64-cel_e1031-r0/plugins/eeprom.py b/device/celestica/x86_64-cel_e1031-r0/plugins/eeprom.py index 6577631c8908..4728d562cc7a 100644 --- a/device/celestica/x86_64-cel_e1031-r0/plugins/eeprom.py +++ b/device/celestica/x86_64-cel_e1031-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica Haliburton # @@ -11,8 +9,8 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): @@ -20,4 +18,3 @@ class board(eeprom_tlvinfo.TlvInfoDecoder): def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/class/i2c-adapter/i2c-2/2-0050/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) - diff --git a/device/celestica/x86_64-cel_e1031-r0/plugins/psuutil.py b/device/celestica/x86_64-cel_e1031-r0/plugins/psuutil.py index 71b8d4ad3c59..8e019efbebcd 100644 --- a/device/celestica/x86_64-cel_e1031-r0/plugins/psuutil.py +++ b/device/celestica/x86_64-cel_e1031-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - import os.path try: diff --git a/device/celestica/x86_64-cel_e1031-r0/plugins/sfputil.py b/device/celestica/x86_64-cel_e1031-r0/plugins/sfputil.py index 9cbec7127261..d65f2cf3f54f 100644 --- a/device/celestica/x86_64-cel_e1031-r0/plugins/sfputil.py +++ b/device/celestica/x86_64-cel_e1031-r0/plugins/sfputil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - try: import time import os @@ -15,15 +13,15 @@ class SfpUtil(SfpUtilBase): PORT_START = 1 PORT_END = 52 port_to_i2c_mapping = { - 1: None, - 2: None, - 3: None, - 4: None, - 5: None, - 6: None, - 7: None, - 8: None, - 9: None, + 1: None, + 2: None, + 3: None, + 4: None, + 5: None, + 6: None, + 7: None, + 8: None, + 9: None, 10: None, 11: None, 12: None, @@ -69,7 +67,7 @@ class SfpUtil(SfpUtilBase): 52: 16 } _port_to_eeprom_mapping = {} - _sfp_port = range(49, PORT_END + 1) + _sfp_port = list(range(49, PORT_END + 1)) @property def port_start(self): @@ -95,7 +93,6 @@ def __init__(self): self.port_to_eeprom_mapping[x] = port_eeprom_path SfpUtilBase.__init__(self) - def get_presence(self, port_num): sfp_modabs_path = '/sys/devices/platform/e1031.smc/SFP/sfp_modabs' @@ -129,7 +126,7 @@ def get_transceiver_change_event(self, timeout=0): try: # We get notified when there is an SCI interrupt from GPIO SUS7 fd = open("/sys/devices/platform/hlx-ich.0/sci_int_gpio_sus7", "r") - fd.read() + fd.read() epoll.register(fd.fileno(), select.EPOLLIN & select.EPOLLET) events = epoll.poll(timeout=timeout_sec if timeout != 0 else -1) @@ -139,18 +136,18 @@ def get_transceiver_change_event(self, timeout=0): with open(modabs_interrupt_path, 'r') as port_changes: changes = int(port_changes.read(), 16) for port_num in self._sfp_port: - change = (changes >> ( port_num - 49)) & 1 + change = (changes >> (port_num - 49)) & 1 if change == 1: port_dict[str(port_num)] = str(int(self.get_presence(port_num))) found_flag = 1 - + if not found_flag: return False, {} return True, port_dict - + finally: fd.close() epoll.close() - return False, {} \ No newline at end of file + return False, {} diff --git a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/chassis.py b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/chassis.py index 42a81748a44a..40c4bb4ef73b 100644 --- a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/chassis.py +++ b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/chassis.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # diff --git a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/component.py b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/component.py index fe34bc45c670..7fdfc8756a4d 100644 --- a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/component.py +++ b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/component.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # @@ -43,7 +41,7 @@ def __run_command(self, command): # Run bash command and print output to stdout try: process = subprocess.Popen( - shlex.split(command), stdout=subprocess.PIPE) + shlex.split(command), universal_newlines=True, stdout=subprocess.PIPE) while True: output = process.stdout.readline() if output == '' and process.poll() is not None: @@ -68,7 +66,7 @@ def get_register_value(self, register): # Retrieves the cpld register value cmd = "echo {1} > {0}; cat {0}".format(GETREG_PATH, register) p = subprocess.Popen( - cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + cmd, shell=True, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) raw_data, err = p.communicate() if err is not '': return None diff --git a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/eeprom.py b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/eeprom.py index 20f3db111f66..0058fccfa0ca 100644 --- a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/eeprom.py +++ b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica Haliburton # @@ -13,13 +11,17 @@ import glob import os import sys - import imp import re from array import array - from cStringIO import StringIO + + if sys.version_info.major == 3: + from io import StringIO + else: + from cStringIO import StringIO + from sonic_platform_base.sonic_eeprom import eeprom_dts from sonic_platform_base.sonic_eeprom import eeprom_tlvinfo -except ImportError, e: +except ImportError as e: raise ImportError(str(e) + "- required module not found") CACHE_ROOT = '/var/cache/sonic/decode-syseeprom' diff --git a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/fan.py b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/fan.py index 2c5bc5c0c45c..18cf513800aa 100644 --- a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/fan.py +++ b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/fan.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # diff --git a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/platform.py b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/platform.py index a632de87e742..7d98ec9f7cdf 100644 --- a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/platform.py +++ b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/platform.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # diff --git a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/psu.py b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/psu.py index 9777bb6fea64..52e71a2480d0 100644 --- a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/psu.py +++ b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/psu.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # @@ -84,7 +82,7 @@ def get_voltage(self): if vout_label_path: dir_name = os.path.dirname(vout_label_path) basename = os.path.basename(vout_label_path) - in_num = filter(str.isdigit, basename) + in_num = list(filter(str.isdigit, basename)) vout_path = os.path.join( dir_name, voltage_name.format(in_num)) vout_val = self.__read_txt_file(vout_path) @@ -107,7 +105,7 @@ def get_current(self): if curr_label_path: dir_name = os.path.dirname(curr_label_path) basename = os.path.basename(curr_label_path) - cur_num = filter(str.isdigit, basename) + cur_num = list(filter(str.isdigit, basename)) cur_path = os.path.join( dir_name, current_name.format(cur_num)) cur_val = self.__read_txt_file(cur_path) @@ -130,7 +128,7 @@ def get_power(self): if pw_label_path: dir_name = os.path.dirname(pw_label_path) basename = os.path.basename(pw_label_path) - pw_num = filter(str.isdigit, basename) + pw_num = list(filter(str.isdigit, basename)) pw_path = os.path.join( dir_name, current_name.format(pw_num)) pw_val = self.__read_txt_file(pw_path) diff --git a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/sfp.py b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/sfp.py index 5932b30c326e..608111d7e2fd 100644 --- a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/sfp.py +++ b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/sfp.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # @@ -81,7 +79,7 @@ class Sfp(SfpBase): 51: 17, 52: 16 } - _sfp_port = range(49, PORT_END + 1) + _sfp_port = list(range(49, PORT_END + 1)) PRS_PATH = "/sys/devices/platform/e1031.smc/SFP/sfp_modabs" PLATFORM_ROOT_PATH = '/usr/share/sonic/device' PMON_HWSKU_PATH = '/usr/share/sonic/hwsku' diff --git a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/thermal.py b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/thermal.py index 6c37f3b7ce88..157f49a7c3e2 100644 --- a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/thermal.py +++ b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/thermal.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # diff --git a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/watchdog.py b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/watchdog.py index b539bc06f618..882285251784 100644 --- a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/watchdog.py +++ b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/watchdog.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # diff --git a/device/celestica/x86_64-cel_midstone-r0/plugins/eeprom.py b/device/celestica/x86_64-cel_midstone-r0/plugins/eeprom.py index 86e7f1b2af15..c8b593a15003 100755 --- a/device/celestica/x86_64-cel_midstone-r0/plugins/eeprom.py +++ b/device/celestica/x86_64-cel_midstone-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica Midstone-200i # @@ -11,8 +9,8 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/celestica/x86_64-cel_midstone-r0/plugins/psuutil.py b/device/celestica/x86_64-cel_midstone-r0/plugins/psuutil.py index 4e6c5eec5d85..0c93576e1fba 100644 --- a/device/celestica/x86_64-cel_midstone-r0/plugins/psuutil.py +++ b/device/celestica/x86_64-cel_midstone-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # @@ -14,7 +12,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" @@ -44,7 +43,6 @@ def get_psu_status(self, index): status = 1 return status == 1 - def get_psu_presence(self, index): """ Retrieves the presence status of power supply unit (PSU) defined @@ -58,4 +56,3 @@ def get_psu_presence(self, index): status = 1 return status == 1 - diff --git a/device/celestica/x86_64-cel_midstone-r0/plugins/sfputil.py b/device/celestica/x86_64-cel_midstone-r0/plugins/sfputil.py index 4d2a444c198b..8b3b06ff00ef 100755 --- a/device/celestica/x86_64-cel_midstone-r0/plugins/sfputil.py +++ b/device/celestica/x86_64-cel_midstone-r0/plugins/sfputil.py @@ -32,7 +32,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(self.QSFP_PORT_START, self.QSFP_PORT_END+1) + return list(range(self.QSFP_PORT_START, self.QSFP_PORT_END+1)) @property def port_to_eeprom_mapping(self): @@ -59,7 +59,7 @@ def get_presence(self, port_num): try: reg_file = open("/sys/devices/platform/ms200i_cpld/qsfp_modprs") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -90,7 +90,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open("/sys/devices/platform/ms200i_cpld/qsfp_lpmode") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) content = reg_file.readline().rstrip() @@ -120,7 +120,7 @@ def set_low_power_mode(self, port_num, lpmode): try: reg_file = open("/sys/devices/platform/ms200i_cpld/qsfp_lpmode", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -162,7 +162,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -194,7 +194,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_value | mask diff --git a/device/celestica/x86_64-cel_seastone-r0/plugins/eeprom.py b/device/celestica/x86_64-cel_seastone-r0/plugins/eeprom.py index 29f01a07fc73..bba16943966a 100644 --- a/device/celestica/x86_64-cel_seastone-r0/plugins/eeprom.py +++ b/device/celestica/x86_64-cel_seastone-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica DX010 # @@ -11,8 +9,8 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): @@ -20,4 +18,3 @@ class board(eeprom_tlvinfo.TlvInfoDecoder): def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/class/i2c-adapter/i2c-12/12-0050/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) - diff --git a/device/celestica/x86_64-cel_seastone-r0/plugins/sfputil.py b/device/celestica/x86_64-cel_seastone-r0/plugins/sfputil.py index c361659b0f17..ca960dd8136d 100644 --- a/device/celestica/x86_64-cel_seastone-r0/plugins/sfputil.py +++ b/device/celestica/x86_64-cel_seastone-r0/plugins/sfputil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python -# # Platform-specific SFP transceiver interface for SONiC # @@ -29,7 +27,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(self.PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -54,7 +52,7 @@ def get_presence(self, port_num): try: reg_file = open("/sys/devices/platform/dx010_cpld/qsfp_modprs", "r") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -85,7 +83,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open("/sys/devices/platform/dx010_cpld/qsfp_lpmode", "r") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -116,7 +114,7 @@ def set_low_power_mode(self, port_num, lpmode): try: reg_file = open("/sys/devices/platform/dx010_cpld/qsfp_lpmode", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -156,7 +154,7 @@ def reset(self, port_num): try: reg_file = open("/sys/devices/platform/dx010_cpld/qsfp_reset", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -190,7 +188,7 @@ def reset(self, port_num): try: reg_file = open("/sys/devices/platform/dx010_cpld/qsfp_reset", "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_value | mask diff --git a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/__init__.py b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/__init__.py index 7b86fa12b515..db1748e44d2c 100644 --- a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/__init__.py +++ b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/__init__.py @@ -1,2 +1,2 @@ -import chassis -import platform +from . import chassis +from . import platform diff --git a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/chassis.py b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/chassis.py index 4bd9d0851b5a..5466d629fb2f 100644 --- a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/chassis.py +++ b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/chassis.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # @@ -11,7 +9,7 @@ try: import sys from sonic_platform_base.chassis_base import ChassisBase - from helper import APIHelper + from .helper import APIHelper except ImportError as e: raise ImportError(str(e) + "- required module not found") diff --git a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/component.py b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/component.py index e51cd639a2ef..2833bf4d1cc5 100644 --- a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/component.py +++ b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/component.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # @@ -14,7 +12,7 @@ try: from sonic_platform_base.component_base import ComponentBase - from helper import APIHelper + from .helper import APIHelper except ImportError as e: raise ImportError(str(e) + "- required module not found") @@ -56,7 +54,7 @@ def get_register_value(self, register): # Retrieves the cpld register value cmd = "echo {1} > {0}; cat {0}".format(GETREG_PATH, register) p = subprocess.Popen( - cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + cmd, shell=True, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) raw_data, err = p.communicate() if err is not '': return None diff --git a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/eeprom.py b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/eeprom.py index dffda1a3c050..b2b4a8122590 100644 --- a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/eeprom.py +++ b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica Seastone-DX010 # @@ -13,13 +11,17 @@ import glob import os import sys - import imp import re from array import array - from cStringIO import StringIO + + if sys.version_info.major == 3: + from io import StringIO + else: + from cStringIO import StringIO + from sonic_platform_base.sonic_eeprom import eeprom_dts from sonic_platform_base.sonic_eeprom import eeprom_tlvinfo -except ImportError, e: +except ImportError as e: raise ImportError(str(e) + "- required module not found") CACHE_ROOT = '/var/cache/sonic/decode-syseeprom' diff --git a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/fan.py b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/fan.py index c38b57f83cd9..10875ee30753 100644 --- a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/fan.py +++ b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/fan.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # @@ -14,7 +12,7 @@ try: from sonic_platform_base.fan_base import FanBase - from helper import APIHelper + from .helper import APIHelper except ImportError as e: raise ImportError(str(e) + "- required module not found") diff --git a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/helper.py b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/helper.py index 04149ae514f6..140c62c08666 100644 --- a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/helper.py +++ b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/helper.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - import os import struct import subprocess @@ -37,7 +35,7 @@ def run_command(self, cmd): result = "" try: p = subprocess.Popen( - cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + cmd, shell=True, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) raw_data, err = p.communicate() if err == '': result = raw_data.strip() @@ -89,7 +87,7 @@ def ipmi_raw(self, netfn, cmd): try: cmd = "ipmitool raw {} {}".format(str(netfn), str(cmd)) p = subprocess.Popen( - cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + cmd, shell=True, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) raw_data, err = p.communicate() if err == '': result = raw_data.strip() @@ -107,7 +105,7 @@ def ipmi_fru_id(self, id, key=None): id)) if not key else "ipmitool fru print {0} | grep '{1}' ".format(str(id), str(key)) p = subprocess.Popen( - cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + cmd, shell=True, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) raw_data, err = p.communicate() if err == '': result = raw_data.strip() @@ -124,7 +122,7 @@ def ipmi_set_ss_thres(self, id, threshold_key, value): cmd = "ipmitool sensor thresh '{}' {} {}".format( str(id), str(threshold_key), str(value)) p = subprocess.Popen( - cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + cmd, shell=True, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) raw_data, err = p.communicate() if err == '': result = raw_data.strip() diff --git a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/platform.py b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/platform.py index a632de87e742..7d98ec9f7cdf 100644 --- a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/platform.py +++ b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/platform.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # diff --git a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/psu.py b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/psu.py index d34c130dd4be..7080081ceff1 100644 --- a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/psu.py +++ b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/psu.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # @@ -14,7 +12,7 @@ try: from sonic_platform_base.psu_base import PsuBase from sonic_platform.fan import Fan - from helper import APIHelper + from .helper import APIHelper except ImportError as e: raise ImportError(str(e) + "- required module not found") @@ -94,7 +92,7 @@ def get_voltage(self): if vout_label_path: dir_name = os.path.dirname(vout_label_path) basename = os.path.basename(vout_label_path) - in_num = filter(str.isdigit, basename) + in_num = list(filter(str.isdigit, basename)) vout_path = os.path.join( dir_name, voltage_name.format(in_num)) vout_val = self._api_helper.read_txt_file(vout_path) @@ -117,7 +115,7 @@ def get_current(self): if curr_label_path: dir_name = os.path.dirname(curr_label_path) basename = os.path.basename(curr_label_path) - cur_num = filter(str.isdigit, basename) + cur_num = list(filter(str.isdigit, basename)) cur_path = os.path.join( dir_name, current_name.format(cur_num)) cur_val = self._api_helper.read_txt_file(cur_path) @@ -140,7 +138,7 @@ def get_power(self): if pw_label_path: dir_name = os.path.dirname(pw_label_path) basename = os.path.basename(pw_label_path) - pw_num = filter(str.isdigit, basename) + pw_num = list(filter(str.isdigit, basename)) pw_path = os.path.join( dir_name, current_name.format(pw_num)) pw_val = self._api_helper.read_txt_file(pw_path) diff --git a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/sfp.py b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/sfp.py index 3e84bd7c41c2..4c0a645714af 100644 --- a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/sfp.py +++ b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/sfp.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # @@ -20,7 +18,7 @@ from sonic_platform_base.sonic_sfp.sff8436 import sff8436Dom from sonic_platform_base.sonic_sfp.inf8628 import inf8628InterfaceId from sonic_platform_base.sonic_sfp.sfputilhelper import SfpUtilHelper - from helper import APIHelper + from .helper import APIHelper except ImportError as e: raise ImportError(str(e) + "- required module not found") @@ -532,7 +530,6 @@ def get_transceiver_info(self): transceiver_info_dict['ext_identifier'] = sfp_interface_bulk_data['data']['Extended Identifier']['value'] transceiver_info_dict['ext_rateselect_compliance'] = sfp_interface_bulk_data['data']['RateIdentifier']['value'] - if self.sfp_type == QSFP_TYPE: for key in qsfp_cable_length_tup: if key in sfp_interface_bulk_data['data']: diff --git a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/thermal.py b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/thermal.py index 18c2bd30c03e..9e891b65e405 100644 --- a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/thermal.py +++ b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/thermal.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # @@ -14,7 +12,7 @@ try: from sonic_platform_base.thermal_base import ThermalBase - from helper import APIHelper + from .helper import APIHelper except ImportError as e: raise ImportError(str(e) + "- required module not found") diff --git a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/watchdog.py b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/watchdog.py index e410a940ee7e..31bb911d2401 100644 --- a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/watchdog.py +++ b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/watchdog.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # @@ -13,7 +11,7 @@ try: from sonic_platform_base.watchdog_base import WatchdogBase - from helper import APIHelper + from .helper import APIHelper except ImportError as e: raise ImportError(str(e) + "- required module not found") diff --git a/device/celestica/x86_64-cel_seastone_2-r0/plugins/eeprom.py b/device/celestica/x86_64-cel_seastone_2-r0/plugins/eeprom.py index 2ae540870c41..93290ebf82bf 100644 --- a/device/celestica/x86_64-cel_seastone_2-r0/plugins/eeprom.py +++ b/device/celestica/x86_64-cel_seastone_2-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica Seastone2 # @@ -11,8 +9,8 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): @@ -20,4 +18,3 @@ class board(eeprom_tlvinfo.TlvInfoDecoder): def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/class/i2c-adapter/i2c-0/0-0056/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) - diff --git a/device/celestica/x86_64-cel_seastone_2-r0/plugins/psuutil.py b/device/celestica/x86_64-cel_seastone_2-r0/plugins/psuutil.py index f315e875542c..cc5461ccb5d4 100644 --- a/device/celestica/x86_64-cel_seastone_2-r0/plugins/psuutil.py +++ b/device/celestica/x86_64-cel_seastone_2-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - import os.path import subprocess import sys @@ -8,7 +6,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" @@ -18,21 +17,21 @@ def __init__(self): PsuBase.__init__(self) def run_command(self, command): - proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE) + proc = subprocess.Popen(command, shell=True, universal_newlines=True, stdout=subprocess.PIPE) (out, err) = proc.communicate() if proc.returncode != 0: sys.exit(proc.returncode) - + return out - + def find_value(self, grep_string): result = re.search(".+\| (0x\d{2})\d{2}\|.+", grep_string) if result: return result.group(1) else: return result - + def get_num_psus(self): """ Retrieves the number of PSUs available on the device @@ -51,9 +50,9 @@ def get_psu_status(self, index): return False grep_key = "PSUL_Status" if index == 1 else "PSUR_Status" - grep_string = self.run_command(self.ipmi_sensor + ' | grep '+ grep_key) + grep_string = self.run_command(self.ipmi_sensor + ' | grep ' + grep_key) status_byte = self.find_value(grep_string) - + if status_byte is None: return False @@ -75,13 +74,13 @@ def get_psu_presence(self, index): return False grep_key = "PSUL_Status" if index == 1 else "PSUR_Status" - grep_string = self.run_command(self.ipmi_sensor + ' | grep '+ grep_key) + grep_string = self.run_command(self.ipmi_sensor + ' | grep ' + grep_key) status_byte = self.find_value(grep_string) - + if status_byte is None: return False - - presence = ( int(status_byte, 16) >> 0 ) & 1 + + presence = (int(status_byte, 16) >> 0) & 1 if presence: return True else: diff --git a/device/celestica/x86_64-cel_seastone_2-r0/plugins/sfputil.py b/device/celestica/x86_64-cel_seastone_2-r0/plugins/sfputil.py index db3ca9976e32..6f05527621fe 100755 --- a/device/celestica/x86_64-cel_seastone_2-r0/plugins/sfputil.py +++ b/device/celestica/x86_64-cel_seastone_2-r0/plugins/sfputil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python -# # Platform-specific SFP transceiver interface for SONiC # @@ -35,7 +33,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(self.QSFP_PORT_START, self.QSFP_PORT_END + 1) + return list(range(self.QSFP_PORT_START, self.QSFP_PORT_END + 1)) @property def port_to_eeprom_mapping(self): @@ -73,7 +71,7 @@ def __init__(self): def get_presence(self, port_num): # Check for invalid port_num - if port_num not in range(self.port_start, self.port_end + 1): + if port_num not in list(range(self.port_start, self.port_end + 1)): return False # Get path for access port presence status @@ -87,7 +85,7 @@ def get_presence(self, port_num): content = reg_file.readline().rstrip() reg_value = int(content) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # Module present is active low @@ -106,7 +104,7 @@ def get_low_power_mode(self, port_num): reg_file = open( "/".join([self.PORT_INFO_PATH, port_name, "qsfp_lpmode"]), "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # Read status @@ -128,7 +126,7 @@ def set_low_power_mode(self, port_num, lpmode): reg_file = open( "/".join([self.PORT_INFO_PATH, port_name, "qsfp_lpmode"]), "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = hex(lpmode) @@ -149,7 +147,7 @@ def reset(self, port_num): reg_file = open( "/".join([self.PORT_INFO_PATH, port_name, "qsfp_reset"]), "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # Convert our register value back to a hex string and write back @@ -165,7 +163,7 @@ def reset(self, port_num): reg_file = open( "/".join([self.PORT_INFO_PATH, port_name, "qsfp_reset"]), "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_file.seek(0) @@ -179,4 +177,3 @@ def get_transceiver_change_event(self, timeout=0): TBD: When the feature request. """ raise NotImplementedError - diff --git a/device/celestica/x86_64-cel_seastone_2-r0/sonic_platform_config/event.py b/device/celestica/x86_64-cel_seastone_2-r0/sonic_platform_config/event.py index 0153d29418f2..ed3b78cf7fd6 100644 --- a/device/celestica/x86_64-cel_seastone_2-r0/sonic_platform_config/event.py +++ b/device/celestica/x86_64-cel_seastone_2-r0/sonic_platform_config/event.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica Seastone2 # diff --git a/device/celestica/x86_64-cel_seastone_2-r0/sonic_platform_config/watchdog.py b/device/celestica/x86_64-cel_seastone_2-r0/sonic_platform_config/watchdog.py index 70eae5b95b3b..cc87c3d6b32a 100644 --- a/device/celestica/x86_64-cel_seastone_2-r0/sonic_platform_config/watchdog.py +++ b/device/celestica/x86_64-cel_seastone_2-r0/sonic_platform_config/watchdog.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica Seastone2 # diff --git a/device/celestica/x86_64-cel_silverstone-r0/plugins/eeprom.py b/device/celestica/x86_64-cel_silverstone-r0/plugins/eeprom.py index 34c50a6ce31f..012196b0dd4c 100644 --- a/device/celestica/x86_64-cel_silverstone-r0/plugins/eeprom.py +++ b/device/celestica/x86_64-cel_silverstone-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica Silverstone # @@ -11,8 +9,8 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): @@ -20,4 +18,3 @@ class board(eeprom_tlvinfo.TlvInfoDecoder): def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/class/i2c-adapter/i2c-0/0-0056/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) - diff --git a/device/celestica/x86_64-cel_silverstone-r0/plugins/psuutil.py b/device/celestica/x86_64-cel_silverstone-r0/plugins/psuutil.py index d5e197e82d2b..ca75ad98334c 100644 --- a/device/celestica/x86_64-cel_silverstone-r0/plugins/psuutil.py +++ b/device/celestica/x86_64-cel_silverstone-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - import os.path import subprocess import sys @@ -8,7 +6,7 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class PsuUtil(PsuBase): @@ -21,21 +19,21 @@ def __init__(self): PsuBase.__init__(self) def run_command(self, command): - proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE) + proc = subprocess.Popen(command, shell=True, universal_newlines=True, stdout=subprocess.PIPE) (out, err) = proc.communicate() if proc.returncode != 0: sys.exit(proc.returncode) - + return out - + def find_value(self, in_string): result = re.search("^.+ ([0-9a-f]{2}) .+$", in_string) if result: return result.group(1) else: return result - + def get_num_psus(self): """ Retrieves the number of PSUs available on the device @@ -56,7 +54,7 @@ def get_psu_status(self, index): psu_id = self.psu1_id if index == 1 else self.psu2_id res_string = self.run_command(self.ipmi_raw + ' ' + psu_id) status_byte = self.find_value(res_string) - + if status_byte is None: return False @@ -80,12 +78,12 @@ def get_psu_presence(self, index): psu_id = self.psu1_id if index == 1 else self.psu2_id res_string = self.run_command(self.ipmi_raw + ' ' + psu_id) status_byte = self.find_value(res_string) - + if status_byte is None: return False - - presence = ( int(status_byte, 16) >> 0 ) & 1 + + presence = (int(status_byte, 16) >> 0) & 1 if presence: return True else: - return False \ No newline at end of file + return False diff --git a/device/celestica/x86_64-cel_silverstone-r0/plugins/sfputil.py b/device/celestica/x86_64-cel_silverstone-r0/plugins/sfputil.py index 33b761b9397a..c089b42c3638 100755 --- a/device/celestica/x86_64-cel_silverstone-r0/plugins/sfputil.py +++ b/device/celestica/x86_64-cel_silverstone-r0/plugins/sfputil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python -# # Platform-specific SFP transceiver interface for SONiC # This plugin supports QSFP-DD, QSFP and SFP. @@ -41,7 +39,7 @@ def qsfp_ports(self): @property def osfp_ports(self): - return range(self.OSFP_PORT_START, self.OSFP_PORT_END + 1) + return list(range(self.OSFP_PORT_START, self.OSFP_PORT_END + 1)) @property def port_to_eeprom_mapping(self): @@ -78,7 +76,7 @@ def __init__(self): def get_presence(self, port_num): # Check for invalid port_num - if port_num not in range(self.port_start, self.port_end + 1): + if port_num not in list(range(self.port_start, self.port_end + 1)): return False # Get path for access port presence status @@ -92,7 +90,7 @@ def get_presence(self, port_num): content = reg_file.readline().rstrip() reg_value = int(content) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # Module present is active low @@ -111,7 +109,7 @@ def get_low_power_mode(self, port_num): reg_file = open("/".join([self.PORT_INFO_PATH, port_name, "qsfp_lpmode"])) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # Read status @@ -133,7 +131,7 @@ def set_low_power_mode(self, port_num, lpmode): reg_file = open("/".join([self.PORT_INFO_PATH, port_name, "qsfp_lpmode"]), "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = hex(lpmode) @@ -154,7 +152,7 @@ def reset(self, port_num): reg_file = open("/".join([self.PORT_INFO_PATH, port_name, "qsfp_reset"]), "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # Convert our register value back to a hex string and write back @@ -170,7 +168,7 @@ def reset(self, port_num): reg_file = open( "/".join([self.PORT_INFO_PATH, port_name, "qsfp_reset"]), "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_file.seek(0) diff --git a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/chassis.py b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/chassis.py index 21a3ff2a9173..b6f77cbd3dc9 100644 --- a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/chassis.py +++ b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/chassis.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # @@ -22,7 +20,7 @@ from sonic_platform.sfp import Sfp from sonic_platform.psu import Psu from sonic_platform.thermal import Thermal - from helper import APIHelper + from .helper import APIHelper except ImportError as e: raise ImportError(str(e) + "- required module not found") @@ -65,7 +63,6 @@ def __init__(self): thermal = Thermal(index) self._thermal_list.append(thermal) - def get_base_mac(self): """ Retrieves the base MAC address for the chassis diff --git a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/component.py b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/component.py index 737908b5b50e..bbbb9f1d458d 100644 --- a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/component.py +++ b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/component.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # @@ -13,7 +11,7 @@ try: from sonic_platform_base.component_base import ComponentBase - from helper import APIHelper + from .helper import APIHelper except ImportError as e: raise ImportError(str(e) + "- required module not found") diff --git a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/eeprom.py b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/eeprom.py index dd0c9332b54e..cf3f1a98de20 100644 --- a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/eeprom.py +++ b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica Silverstone # @@ -13,13 +11,17 @@ import glob import os import sys - import imp import re from array import array - from cStringIO import StringIO + + if sys.version_info.major == 3: + from io import StringIO + else: + from cStringIO import StringIO + from sonic_platform_base.sonic_eeprom import eeprom_dts from sonic_platform_base.sonic_eeprom import eeprom_tlvinfo -except ImportError, e: +except ImportError as e: raise ImportError(str(e) + "- required module not found") CACHE_ROOT = '/var/cache/sonic/decode-syseeprom' @@ -27,12 +29,14 @@ TLV_EEPROM_I2C_BUS = 0 TLV_EEPROM_I2C_ADDR = 56 + class Tlv(eeprom_tlvinfo.TlvInfoDecoder): EEPROM_DECODE_HEADLINES = 6 def __init__(self): - self._eeprom_path = "/sys/class/i2c-adapter/i2c-{0}/{0}-00{1}/eeprom".format(TLV_EEPROM_I2C_BUS, TLV_EEPROM_I2C_ADDR) + self._eeprom_path = "/sys/class/i2c-adapter/i2c-{0}/{0}-00{1}/eeprom".format( + TLV_EEPROM_I2C_BUS, TLV_EEPROM_I2C_ADDR) super(Tlv, self).__init__(self._eeprom_path, 0, '', True) self._eeprom = self._load_eeprom() diff --git a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/fan.py b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/fan.py index d1b36effc1ac..1055aee68fc7 100644 --- a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/fan.py +++ b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/fan.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # @@ -14,7 +12,7 @@ try: from sonic_platform_base.fan_base import FanBase - from helper import APIHelper + from .helper import APIHelper except ImportError as e: raise ImportError(str(e) + "- required module not found") @@ -150,7 +148,7 @@ def set_speed(self, speed): # register = 22 32 42 52 62 72 82 if self.is_psu_fan: - ## TODO + # TODO return False speed_hex = hex(int(float(speed)/100 * 255)) diff --git a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/helper.py b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/helper.py index 82f0eea6b448..144d9e154348 100644 --- a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/helper.py +++ b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/helper.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - import os import struct import subprocess @@ -35,7 +33,7 @@ def run_command(self, cmd): result = "" try: p = subprocess.Popen( - cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + cmd, shell=True, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) raw_data, err = p.communicate() if err == '': result = raw_data.strip() @@ -65,7 +63,7 @@ def ipmi_raw(self, netfn, cmd): try: cmd = "ipmitool raw {} {}".format(str(netfn), str(cmd)) p = subprocess.Popen( - cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + cmd, shell=True, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) raw_data, err = p.communicate() if err == '': result = raw_data.strip() @@ -83,7 +81,7 @@ def ipmi_fru_id(self, id, key=None): id)) if not key else "ipmitool fru print {0} | grep '{1}' ".format(str(id), str(key)) p = subprocess.Popen( - cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + cmd, shell=True, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) raw_data, err = p.communicate() if err == '': result = raw_data.strip() @@ -99,7 +97,7 @@ def ipmi_set_ss_thres(self, id, threshold_key, value): try: cmd = "ipmitool sensor thresh '{}' {} {}".format(str(id), str(threshold_key), str(value)) p = subprocess.Popen( - cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + cmd, shell=True, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) raw_data, err = p.communicate() if err == '': result = raw_data.strip() diff --git a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/platform.py b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/platform.py index a632de87e742..7d98ec9f7cdf 100644 --- a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/platform.py +++ b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/platform.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # diff --git a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/psu.py b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/psu.py index c5d2270d2657..9ad0f1dc9392 100644 --- a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/psu.py +++ b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/psu.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # @@ -15,7 +13,7 @@ try: from sonic_platform_base.psu_base import PsuBase - from helper import APIHelper + from .helper import APIHelper from sonic_platform.fan import Fan except ImportError as e: raise ImportError(str(e) + "- required module not found") @@ -238,6 +236,6 @@ def get_status(self): if status: failure_detected = (int(status_byte, 16) >> 1) & 1 input_lost = (int(status_byte, 16) >> 3) & 1 - psu_status = False if (input_lost or failure_detected) else True + psu_status = False if (input_lost or failure_detected) else True return psu_status diff --git a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/sfp.py b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/sfp.py index c0187033b889..b04b49ca4382 100644 --- a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/sfp.py +++ b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/sfp.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # diff --git a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/thermal.py b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/thermal.py index e3138e6bb897..9ecf12218d50 100644 --- a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/thermal.py +++ b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/thermal.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # @@ -14,7 +12,7 @@ try: from sonic_platform_base.thermal_base import ThermalBase - from helper import APIHelper + from .helper import APIHelper except ImportError as e: raise ImportError(str(e) + "- required module not found") @@ -47,20 +45,21 @@ def __init__(self, thermal_index): self.sensor_id = self.THERMAL_LIST[self.index][0] self.sensor_des = self.THERMAL_LIST[self.index][1] self.sensor_reading_addr = self.THERMAL_LIST[self.index][2] + def __set_threshold(self, key, value): - print(key, value) + print('{} {}'.format(key, value)) def get_temperature(self): """ Retrieves current temperature reading from thermal Returns: A float number of current temperature in Celsius up to nearest thousandth - of one degree Celsius, e.g. 30.125 + of one degree Celsius, e.g. 30.125 """ temperature = 0.0 status, raw_ss_read = self._api_helper.ipmi_raw( IPMI_SENSOR_NETFN, IPMI_SS_READ_CMD.format(self.sensor_reading_addr)) - if status and len(raw_ss_read.split()) > 0: + if status and len(raw_ss_read.split()) > 0: ss_read = raw_ss_read.split()[0] temperature = float(int(ss_read, 16)) return temperature @@ -75,7 +74,7 @@ def get_high_threshold(self): high_threshold = 0.0 status, raw_up_thres_read = self._api_helper.ipmi_raw( IPMI_SENSOR_NETFN, IPMI_SS_THRESHOLD_CMD.format(self.sensor_reading_addr)) - if status and len(raw_up_thres_read.split()) > 6: + if status and len(raw_up_thres_read.split()) > 6: ss_read = raw_up_thres_read.split()[4] high_threshold = float(int(ss_read, 16)) return high_threshold @@ -92,8 +91,8 @@ def get_low_threshold(self): def set_high_threshold(self, temperature): """ Sets the high threshold temperature of thermal - Args : - temperature: A float number up to nearest thousandth of one degree Celsius, + Args : + temperature: A float number up to nearest thousandth of one degree Celsius, e.g. 30.125 Returns: A boolean, True if threshold is set successfully, False if not @@ -104,7 +103,7 @@ def set_high_threshold(self, temperature): def set_low_threshold(self, temperature): """ Sets the low threshold temperature of thermal - Args : + Args : temperature: A float number up to nearest thousandth of one degree Celsius, e.g. 30.125 Returns: @@ -150,4 +149,4 @@ def get_status(self): Returns: A boolean value, True if device is operating properly, False if not """ - return self.get_presence() \ No newline at end of file + return self.get_presence() diff --git a/device/centec/arm64-centec_e530_24x2c-r0/plugins/eeprom.py b/device/centec/arm64-centec_e530_24x2c-r0/plugins/eeprom.py index 3d0c220d2421..afea818be079 100644 --- a/device/centec/arm64-centec_e530_24x2c-r0/plugins/eeprom.py +++ b/device/centec/arm64-centec_e530_24x2c-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Centec E550-24X8Y2C # @@ -11,8 +9,8 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/centec/arm64-centec_e530_24x2c-r0/plugins/led_control.py b/device/centec/arm64-centec_e530_24x2c-r0/plugins/led_control.py index e8ba30134c2f..627cf03ddad4 100644 --- a/device/centec/arm64-centec_e530_24x2c-r0/plugins/led_control.py +++ b/device/centec/arm64-centec_e530_24x2c-r0/plugins/led_control.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # # led_control.py # @@ -10,7 +9,7 @@ import syslog from socket import * from select import * -except ImportError, e: +except ImportError as e: raise ImportError(str(e) + " - required module not found") @@ -23,7 +22,6 @@ def DBG_PRINT(str): class LedControl(LedControlBase): """Platform specific LED control class""" - # Helper method to map SONiC port name to index def _port_name_to_index(self, port_name): # Strip "Ethernet" off port name @@ -73,8 +71,8 @@ def _initDefaultConfig(self): DBG_PRINT("init led done") - # Concrete implementation of port_link_state_change() method + def port_link_state_change(self, portname, state): port_idx = self._port_name_to_index(portname) ledMode = self._port_state_to_mode(port_idx, state) @@ -87,8 +85,8 @@ def port_link_state_change(self, portname, state): self._port_led_mode_update(port_idx, ledMode) DBG_PRINT("update {} led mode from {} to {}".format(portname, saveMode, ledMode)) - # Constructor + def __init__(self): self.SONIC_PORT_NAME_PREFIX = "Ethernet" self.LED_MODE_UP = [11, 11] diff --git a/device/centec/arm64-centec_e530_24x2c-r0/plugins/psuutil.py b/device/centec/arm64-centec_e530_24x2c-r0/plugins/psuutil.py index 1e83c12c1131..3a83f406d990 100644 --- a/device/centec/arm64-centec_e530_24x2c-r0/plugins/psuutil.py +++ b/device/centec/arm64-centec_e530_24x2c-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Centec # @@ -11,7 +9,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/centec/arm64-centec_e530_24x2c-r0/plugins/sfputil.py b/device/centec/arm64-centec_e530_24x2c-r0/plugins/sfputil.py index 8404fcfcf180..c5c0dc8e16e0 100644 --- a/device/centec/arm64-centec_e530_24x2c-r0/plugins/sfputil.py +++ b/device/centec/arm64-centec_e530_24x2c-r0/plugins/sfputil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # sfputil.py # # Platform-specific SFP transceiver interface for SONiC @@ -15,11 +13,13 @@ def DBG_PRINT(str): - print str + "\n" + print(str + "\n") + SFP_STATUS_INSERTED = '1' SFP_STATUS_REMOVED = '0' + class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" @@ -37,7 +37,7 @@ def sfp_base(self): @property def qsfp_ports(self): - return range(25, self.PORTS_IN_BLOCK + 1) + return list(range(25, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -62,30 +62,30 @@ def get_eeprom_data(self, port): return ret # todo - #def _get_port_eeprom_path(self, port_num, devid): + # def _get_port_eeprom_path(self, port_num, devid): # pass def __init__(self): self.SONIC_PORT_NAME_PREFIX = "Ethernet" self.PORT_START = 1 self.PORT_END = 26 - self.SFP_BASE = 1 + self.SFP_BASE = 1 self.PORTS_IN_BLOCK = 26 self.logical = [] self.physical_to_logical = {} self.logical_to_physical = {} - self.eeprom_mapping = {} self.f_sfp_present = "/sys/class/sfp/sfp{}/sfp_presence" self.f_sfp_enable = "/sys/class/sfp/sfp{}/sfp_enable" - for x in range(self.port_start, self.sfp_base): + for x in range(self.port_start, self.sfp_base): self.eeprom_mapping[x] = None for x in range(self.sfp_base, self.port_end + 1): - self.eeprom_mapping[x] = "/sys/class/sfp/sfp{}/sfp_eeprom".format(x - self.sfp_base + 1) + self.eeprom_mapping[x] = "/sys/class/sfp/sfp{}/sfp_eeprom".format( + x - self.sfp_base + 1) self.presence = {} for x in range(self.sfp_base, self.port_end + 1): - self.presence[x] = False; + self.presence[x] = False SfpUtilBase.__init__(self) @@ -127,20 +127,20 @@ def reset(self, port_num): return False - def read_porttab_mappings(self, porttabfile): for x in range(self.sfp_base, self.port_end + 1): self.logical_to_physical['Ethernet' + str(x)] = [x] self.physical_to_logical[x] = ['Ethernet' + str(x)] - data = {'valid':0, 'last':0} + data = {'valid': 0, 'last': 0} + def get_transceiver_change_event(self, timeout=2000): now = time.time() port_dict = {} if timeout < 1000: timeout = 1000 - timeout = (timeout) / float(1000) # Convert to secs + timeout = (timeout) / float(1000) # Convert to secs if now < (self.data['last'] + timeout) and self.data['valid']: return True, {} diff --git a/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/eeprom.py b/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/eeprom.py index 3d0c220d2421..afea818be079 100644 --- a/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/eeprom.py +++ b/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Centec E550-24X8Y2C # @@ -11,8 +9,8 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/led_control.py b/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/led_control.py index edbdb8a02df2..eb567de89c22 100644 --- a/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/led_control.py +++ b/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/led_control.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python -# # led_control.py # # Platform-specific LED control functionality for SONiC @@ -10,7 +8,7 @@ import syslog from socket import * from select import * -except ImportError, e: +except ImportError as e: raise ImportError(str(e) + " - required module not found") @@ -23,7 +21,6 @@ def DBG_PRINT(str): class LedControl(LedControlBase): """Platform specific LED control class""" - # Helper method to map SONiC port name to index def _port_name_to_index(self, port_name): # Strip "Ethernet" off port name @@ -73,8 +70,8 @@ def _initDefaultConfig(self): DBG_PRINT("init led done") - # Concrete implementation of port_link_state_change() method + def port_link_state_change(self, portname, state): port_idx = self._port_name_to_index(portname) ledMode = self._port_state_to_mode(port_idx, state) @@ -87,8 +84,8 @@ def port_link_state_change(self, portname, state): self._port_led_mode_update(port_idx, ledMode) DBG_PRINT("update {} led mode from {} to {}".format(portname, saveMode, ledMode)) - # Constructor + def __init__(self): self.SONIC_PORT_NAME_PREFIX = "Ethernet" self.LED_MODE_UP = [2, 11] diff --git a/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/psuutil.py b/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/psuutil.py index 1e83c12c1131..3a83f406d990 100644 --- a/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/psuutil.py +++ b/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Centec # @@ -11,7 +9,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/sfputil.py b/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/sfputil.py index 3426dcf12be1..f7094828eafb 100644 --- a/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/sfputil.py +++ b/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/sfputil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # sfputil.py # # Platform-specific SFP transceiver interface for SONiC @@ -15,7 +13,7 @@ def DBG_PRINT(str): - print str + "\n" + print(str + "\n") class SfpUtil(SfpUtilBase): @@ -68,26 +66,27 @@ def get_eeprom_data(self, port): return ret # todo - #def _get_port_eeprom_path(self, port_num, devid): + # def _get_port_eeprom_path(self, port_num, devid): # pass def __init__(self): self.SONIC_PORT_NAME_PREFIX = "Ethernet" self.PORT_START = 1 self.PORT_END = 52 - self.SFP_BASE = 49 + self.SFP_BASE = 49 self.PORTS_IN_BLOCK = 52 self.eeprom_mapping = {} self.f_sfp_present = "/sys/class/sfp/sfp{}/sfp_presence" self.f_sfp_enable = "/sys/class/sfp/sfp{}/sfp_enable" - for x in range(self.port_start, self.sfp_base): + for x in range(self.port_start, self.sfp_base): self.eeprom_mapping[x] = None for x in range(self.sfp_base, self.port_end + 1): - self.eeprom_mapping[x] = "/sys/class/sfp/sfp{}/sfp_eeprom".format(x - self.sfp_base + 1) + self.eeprom_mapping[x] = "/sys/class/sfp/sfp{}/sfp_eeprom".format( + x - self.sfp_base + 1) self.presence = {} for x in range(self.sfp_base, self.port_end + 1): - self.presence[x] = False; + self.presence[x] = False SfpUtilBase.__init__(self) diff --git a/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/eeprom.py b/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/eeprom.py index 3fd55c63d8b7..63854d994cf1 100644 --- a/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/eeprom.py +++ b/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Centec E582-48X6Q # @@ -10,7 +8,6 @@ ############################################################################# try: - import exceptions import binascii import time import optparse @@ -20,8 +17,8 @@ import subprocess from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/led_control.py b/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/led_control.py index 4459096cb011..48a4d8d04eae 100644 --- a/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/led_control.py +++ b/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/led_control.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python -# # led_control.py # # Platform-specific LED control functionality for SONiC @@ -16,7 +14,7 @@ import syslog from socket import * from select import * -except ImportError, e: +except ImportError as e: raise ImportError(str(e) + " - required module not found") @@ -25,6 +23,7 @@ def DBG_PRINT(str): syslog.syslog(syslog.LOG_INFO, str) syslog.closelog() + class LedControl(LedControlBase): """Platform specific LED control class""" SONIC_PORT_NAME_PREFIX = "Ethernet" @@ -53,7 +52,8 @@ def _initPanelLed(self): data = struct.pack('=HHHBB30B', 0, 3, 32, 30, 0, *[x[0] for x in self.led_mapping[21:51]]) self.udpClient.sendto(data, ('localhost', 8101)) - data = struct.pack('=HHHBB28B', 0, 3, 30, 28, 1, *[x[0] for x in (self.led_mapping[1:21]+self.led_mapping[51:59])]) + data = struct.pack('=HHHBB28B', 0, 3, 30, 28, 1, *[x[0] + for x in (self.led_mapping[1:21]+self.led_mapping[51:59])]) self.udpClient.sendto(data, ('localhost', 8101)) data = struct.pack('=HHHB', 0, 5, 1, 1) @@ -96,8 +96,8 @@ def _initDefaultConfig(self): DBG_PRINT("init led done") - # Helper method to map SONiC port name to index + def _port_name_to_index(self, port_name): # Strip "Ethernet" off port name if not port_name.startswith(self.SONIC_PORT_NAME_PREFIX): @@ -136,13 +136,20 @@ def port_link_state_change(self, portname, state): def __init__(self): # [macid, ctlid, defaultmode] self.led_mapping = [(0, 0, 0)] # resv - self.led_mapping.extend([(27, 1, 7), (25, 1, 7), (24, 1, 7), (22, 1, 7), (21, 1, 7), (19, 1, 7), (18, 1, 7), (16, 1, 7)]) # panel port 1~8 - self.led_mapping.extend([(15, 1, 7), (13, 1, 7), (12, 1, 7), (10, 1, 7), (9, 1, 7), (8, 1, 7), (7, 1, 7), (5, 1, 7)]) # panel port 9~16 - self.led_mapping.extend([(4, 1, 7), (2, 1, 7), (1, 1, 7), (0, 1, 7), (0, 0, 7), (1, 0, 7), (3, 0, 7), (2, 0, 7)]) # panel port 17~24 - self.led_mapping.extend([(4, 0, 7), (5, 0, 7), (6, 0, 7), (7, 0, 7), (8, 0, 7), (9, 0, 7), (10, 0, 7), (12, 0, 7)]) # panel port 25~32 - self.led_mapping.extend([(13, 0, 7), (15, 0, 7), (16, 0, 7), (18, 0, 7), (19, 0, 7), (21, 0, 7), (22, 0, 7), (24, 0, 7)]) # panel port 33~40 - self.led_mapping.extend([(25, 0, 7), (27, 0, 7), (28, 0, 7), (30, 0, 7), (31, 0, 7), (33, 0, 7), (34, 0, 7), (48, 0, 7)]) # panel port 41~48 - self.led_mapping.extend([(36, 0, 2), (52, 0, 2), (52, 1, 2), (36, 1, 2), (48, 1, 2), (32, 1, 2)]) # panel port 49~54 + self.led_mapping.extend([(27, 1, 7), (25, 1, 7), (24, 1, 7), (22, 1, 7), (21, 1, 7), + (19, 1, 7), (18, 1, 7), (16, 1, 7)]) # panel port 1~8 + self.led_mapping.extend([(15, 1, 7), (13, 1, 7), (12, 1, 7), (10, 1, 7), (9, 1, 7), + (8, 1, 7), (7, 1, 7), (5, 1, 7)]) # panel port 9~16 + self.led_mapping.extend([(4, 1, 7), (2, 1, 7), (1, 1, 7), (0, 1, 7), (0, 0, 7), + (1, 0, 7), (3, 0, 7), (2, 0, 7)]) # panel port 17~24 + self.led_mapping.extend([(4, 0, 7), (5, 0, 7), (6, 0, 7), (7, 0, 7), (8, 0, 7), + (9, 0, 7), (10, 0, 7), (12, 0, 7)]) # panel port 25~32 + self.led_mapping.extend([(13, 0, 7), (15, 0, 7), (16, 0, 7), (18, 0, 7), (19, 0, 7), + (21, 0, 7), (22, 0, 7), (24, 0, 7)]) # panel port 33~40 + self.led_mapping.extend([(25, 0, 7), (27, 0, 7), (28, 0, 7), (30, 0, 7), (31, 0, 7), + (33, 0, 7), (34, 0, 7), (48, 0, 7)]) # panel port 41~48 + self.led_mapping.extend([(36, 0, 2), (52, 0, 2), (52, 1, 2), (36, 1, 2), (48, 1, 2), + (32, 1, 2)]) # panel port 49~54 self.led_mapping.extend([(11, 1, 2), (11, 1, 2), (11, 1, 2), (11, 1, 2), (11, 1, 2), (11, 1, 2)]) self.f_led = "/sys/class/leds/{}/brightness" @@ -150,4 +157,3 @@ def __init__(self): self.udpClient = socket(AF_INET, SOCK_DGRAM) self._initDefaultConfig() - diff --git a/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/psuutil.py b/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/psuutil.py index 6505318ed948..f38f0cdd0a2e 100644 --- a/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/psuutil.py +++ b/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Centec # @@ -13,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/sfputil.py b/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/sfputil.py index 4d4b3f3e5558..4e94646db772 100644 --- a/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/sfputil.py +++ b/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/sfputil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # sfputil.py # # Platform-specific SFP transceiver interface for SONiC @@ -18,9 +16,8 @@ raise ImportError("%s - required module not found" % str(e)) - def DBG_PRINT(str): - print str + "\n" + print(str + "\n") class SfpUtil(SfpUtilBase): @@ -40,7 +37,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(49, self.PORTS_IN_BLOCK + 1) + return list(range(49, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -62,17 +59,17 @@ def get_eeprom_data(self, port): offset = (128 if port in self.qsfp_ports else 0) r_sel = [self.udpClient] req = struct.pack('=HHHBBHIBBBBI', - 0, 9, 16, # lchip/msgtype/msglen - ctlid, # uint8 ctl_id - devid, # uint8 slave_dev_id - 0x50, # uint16 dev_addr - (1< /dev/null 2>&1") + p = os.popen(self.psu_presence.format(index + Base_bus_number) + "> /dev/null 2>&1") if p.readline() != None: status = 1 p.close() except IOError: return False return status == 1 - - diff --git a/device/centec/x86_64-ew_es6220_x48q2h4-r0/plugins/sfputil.py b/device/centec/x86_64-ew_es6220_x48q2h4-r0/plugins/sfputil.py index 5ac85e067618..103b3cd5630b 100644 --- a/device/centec/x86_64-ew_es6220_x48q2h4-r0/plugins/sfputil.py +++ b/device/centec/x86_64-ew_es6220_x48q2h4-r0/plugins/sfputil.py @@ -32,7 +32,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(0, self.PORTS_IN_BLOCK + 1) + return list(range(0, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -42,37 +42,39 @@ def __init__(self): eeprom_path = "/sys/class/i2c-adapter/i2c-{0}/{0}-0050/eeprom" for x in range(0, self.port_end + 1): - self._port_to_eeprom_mapping[x] = eeprom_path.format(x + self.EEPROM_OFFSET) + self._port_to_eeprom_mapping[x] = eeprom_path.format( + x + self.EEPROM_OFFSET) SfpUtilBase.__init__(self) def get_presence(self, port_name): - #modify by zhw to get sfp presence + # modify by zhw to get sfp presence # Check for invalid port_num port_num = int(port_name[8:]) - + if port_num < (self.port_start+1) or port_num > (self.port_end+1): return False - - #cpld info from "CPLD Register for es5800A2.2(V1.1)" - cpld_map = {0: '0x82', 1: '0x83', 2: '0x84', 3: '0x85', 4: '0x86', 5: '0x87', 6: '0x8E'} + + # cpld info from "CPLD Register for es5800A2.2(V1.1)" + cpld_map = {0: '0x82', 1: '0x83', 2: '0x84', + 3: '0x85', 4: '0x86', 5: '0x87', 6: '0x8E'} cpld_key = (port_num - 1)/8 - cpld_mask = (1 << (port_num - 1)%8) - - #use i2cget cmd to get cpld data + cpld_mask = (1 << (port_num - 1) % 8) + + # use i2cget cmd to get cpld data output = os.popen('i2cdetect -l | grep CP') bus_num = output.read()[4] cmd = "i2cget -y "+bus_num+" 0x5 "+cpld_map[cpld_key] - tmp = os.popen(cmd).read().replace("\n", "") - cpld_value = int(tmp, 16) + tmp = os.popen(cmd).read().replace("\n", "") + cpld_value = int(tmp, 16) if cpld_value & cpld_mask == 0: return True else: return False - + def get_low_power_mode(self, port_num): - ''' + ''' # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False @@ -93,7 +95,7 @@ def get_low_power_mode(self, port_num): # LPMode is active high if reg_value & mask == 0: return False - ''' + ''' return False def set_low_power_mode(self, port_num, lpmode): @@ -102,9 +104,10 @@ def set_low_power_mode(self, port_num, lpmode): return False try: - reg_file = open("/sys/devices/platform/dell-s6000-cpld.0/qsfp_lpmode", "r+") + reg_file = open( + "/sys/devices/platform/dell-s6000-cpld.0/qsfp_lpmode", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -140,7 +143,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -166,7 +169,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_value | mask @@ -183,5 +186,3 @@ def get_transceiver_change_event(self): on this platform. """ raise NotImplementedError - - diff --git a/device/cig/x86_64-cig_cs5435_54p-r0/plugins/eeprom.py b/device/cig/x86_64-cig_cs5435_54p-r0/plugins/eeprom.py index 5019b9c40a9a..ae5a8385d96c 100755 --- a/device/cig/x86_64-cig_cs5435_54p-r0/plugins/eeprom.py +++ b/device/cig/x86_64-cig_cs5435_54p-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,11 +8,13 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/7-0057/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/cig/x86_64-cig_cs5435_54p-r0/plugins/psuutil.py b/device/cig/x86_64-cig_cs5435_54p-r0/plugins/psuutil.py index 70d50e6c3458..442026775a5e 100755 --- a/device/cig/x86_64-cig_cs5435_54p-r0/plugins/psuutil.py +++ b/device/cig/x86_64-cig_cs5435_54p-r0/plugins/psuutil.py @@ -22,8 +22,8 @@ class PsuUtil(PsuBase): def __init__(self): PsuBase.__init__(self) - # Get sysfs attribute + def get_attr_value(self, attr_path): retval = 'ERR' @@ -57,7 +57,7 @@ def get_psu_status(self, index): """ status = 0 attr_file = 'psu_power_good' - attr_path = self.SYSFS_PSU_DIR[index-1] +'/' + attr_file + attr_path = self.SYSFS_PSU_DIR[index-1] + '/' + attr_file attr_value = self.get_attr_value(attr_path) @@ -65,7 +65,7 @@ def get_psu_status(self, index): attr_value = int(attr_value, 16) # Check for PSU status if (attr_value == 1): - status = 1 + status = 1 return status @@ -78,8 +78,8 @@ def get_psu_presence(self, index): """ status = 0 psu_absent = 0 - attr_file ='psu_present' - attr_path = self.SYSFS_PSU_DIR[index-1] +'/' + attr_file + attr_file = 'psu_present' + attr_path = self.SYSFS_PSU_DIR[index-1] + '/' + attr_file attr_value = self.get_attr_value(attr_path) @@ -87,7 +87,6 @@ def get_psu_presence(self, index): attr_value = int(attr_value, 16) # Check for PSU presence if (attr_value == 1): - status = 1 + status = 1 return status - diff --git a/device/cig/x86_64-cig_cs5435_54p-r0/plugins/sfputil.py b/device/cig/x86_64-cig_cs5435_54p-r0/plugins/sfputil.py index 2863b80c9950..2d6827300457 100755 --- a/device/cig/x86_64-cig_cs5435_54p-r0/plugins/sfputil.py +++ b/device/cig/x86_64-cig_cs5435_54p-r0/plugins/sfputil.py @@ -1,10 +1,8 @@ -#!/usr/bin/env python - try: import time from sonic_sfp.sfputilbase import SfpUtilBase -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") class SfpUtil(SfpUtilBase): @@ -19,63 +17,63 @@ class SfpUtil(SfpUtilBase): _global_port_pres_dict = {} _port_to_i2c_mapping = { - 1 : 8, - 2 : 9, - 3 : 10, - 4 : 11, - 5 : 12, - 6 : 13, - 7 : 14, - 8 : 15, - 9 : 16, + 1: 8, + 2: 9, + 3: 10, + 4: 11, + 5: 12, + 6: 13, + 7: 14, + 8: 15, + 9: 16, 10: 17, - 11 : 18, - 12 : 19, - 13 : 20, - 14 : 21, - 15 : 22, - 16 : 23, - 17 : 24, - 18 : 25, - 19 : 26, - 20 : 27, - 21 : 28, - 22 : 29, - 23 : 30, - 24 : 31, - 25 : 32, - 26 : 33, - 27 : 34, - 28 : 35, - 29 : 36, - 30 : 37, - 31 : 38, - 32 : 39, - 33 : 40, - 34 : 41, - 35 : 42, - 36 : 43, - 37 : 44, - 38 : 45, - 39 : 46, - 40 : 47, - 41 : 48, - 42 : 49, - 43 : 50, - 44 : 51, - 45 : 52, - 46 : 53, - 47 : 54, - 48 : 55, - 49 : 56, - 50 : 57, - 51 : 60, - 52 : 61, - 53 : 62, - 54 : 63, + 11: 18, + 12: 19, + 13: 20, + 14: 21, + 15: 22, + 16: 23, + 17: 24, + 18: 25, + 19: 26, + 20: 27, + 21: 28, + 22: 29, + 23: 30, + 24: 31, + 25: 32, + 26: 33, + 27: 34, + 28: 35, + 29: 36, + 30: 37, + 31: 38, + 32: 39, + 33: 40, + 34: 41, + 35: 42, + 36: 43, + 37: 44, + 38: 45, + 39: 46, + 40: 47, + 41: 48, + 42: 49, + 43: 50, + 44: 51, + 45: 52, + 46: 53, + 47: 54, + 48: 55, + 49: 56, + 50: 57, + 51: 60, + 52: 61, + 53: 62, + 54: 63, } - _qsfp_ports = range(_qsfp_port_start, _ports_in_block + 1) + _qsfp_ports = list(range(_qsfp_port_start, _ports_in_block + 1)) def get_presence(self, port_num): # Check for invalid port_num @@ -85,11 +83,10 @@ def get_presence(self, port_num): path = "/sys/bus/i2c/devices/{0}-0050/sfp_is_present" port_ps = path.format(self._port_to_i2c_mapping[port_num]) - try: reg_file = open(port_ps) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False try: @@ -100,7 +97,7 @@ def get_presence(self, port_num): try: reg_value = reg_file.readline().rstrip() except IOError as e: - print "Error:try again to read file failed: %s %s" % (str(e), port_ps) + print("Error:try again to read file failed: %s %s" % (str(e), port_ps)) reg_file.close() return False @@ -118,7 +115,6 @@ def init_global_port_presence(self): for port_num in range(self.port_start, (self.port_end + 1)): self._global_port_pres_dict[port_num] = '0' - def __init__(self): eeprom_path = '/sys/bus/i2c/devices/{0}-0050/sfp_eeprom' for x in range(self._port_start, self._port_end + 1): @@ -139,10 +135,10 @@ def reset(self, port_num): try: reg_file = open(port_ps, 'w') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False - #toggle reset + # toggle reset reg_file.seek(0) reg_file.write('1') time.sleep(1) @@ -158,15 +154,15 @@ def set_low_power_mode(self, port_num, lpmode): pre_value = self.get_presence(port_num) if pre_value == False: - return False + return False path = "/sys/bus/i2c/devices/{0}-0050/sfp_lpmode" port_ps = path.format(self._port_to_i2c_mapping[port_num]) try: - reg_file = open(port_ps,'w') + reg_file = open(port_ps, 'w') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_file.seek(0) @@ -179,7 +175,6 @@ def set_low_power_mode(self, port_num, lpmode): return True - def get_low_power_mode(self, port_num): # Check for invalid port_num @@ -196,13 +191,13 @@ def get_low_power_mode(self, port_num): try: reg_file = open(port_ps) except IOError as e: - print "Error: unable to open file:%s %s" % (str(e), port_ps) + print("Error: unable to open file:%s %s" % (str(e), port_ps)) return False try: reg_value = reg_file.readline().rstrip() except IOError as e: - print "Error: unable to open file:%s %s" % (str(e), port_ps) + print("Error: unable to open file:%s %s" % (str(e), port_ps)) reg_file.close() return False @@ -232,7 +227,6 @@ def get_transceiver_change_event(self): time.sleep(0.5) - @property def port_start(self): return self._port_start @@ -247,4 +241,4 @@ def qsfp_ports(self): @property def port_to_eeprom_mapping(self): - return self._port_to_eeprom_mapping + return self._port_to_eeprom_mapping diff --git a/device/cig/x86_64-cig_cs6436_54p-r0/plugins/eeprom.py b/device/cig/x86_64-cig_cs6436_54p-r0/plugins/eeprom.py index 5019b9c40a9a..c068c04dac6d 100755 --- a/device/cig/x86_64-cig_cs6436_54p-r0/plugins/eeprom.py +++ b/device/cig/x86_64-cig_cs6436_54p-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -10,12 +7,13 @@ import sys from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo - import subprocess -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/7-0057/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/cig/x86_64-cig_cs6436_54p-r0/plugins/psuutil.py b/device/cig/x86_64-cig_cs6436_54p-r0/plugins/psuutil.py index 70d50e6c3458..442026775a5e 100755 --- a/device/cig/x86_64-cig_cs6436_54p-r0/plugins/psuutil.py +++ b/device/cig/x86_64-cig_cs6436_54p-r0/plugins/psuutil.py @@ -22,8 +22,8 @@ class PsuUtil(PsuBase): def __init__(self): PsuBase.__init__(self) - # Get sysfs attribute + def get_attr_value(self, attr_path): retval = 'ERR' @@ -57,7 +57,7 @@ def get_psu_status(self, index): """ status = 0 attr_file = 'psu_power_good' - attr_path = self.SYSFS_PSU_DIR[index-1] +'/' + attr_file + attr_path = self.SYSFS_PSU_DIR[index-1] + '/' + attr_file attr_value = self.get_attr_value(attr_path) @@ -65,7 +65,7 @@ def get_psu_status(self, index): attr_value = int(attr_value, 16) # Check for PSU status if (attr_value == 1): - status = 1 + status = 1 return status @@ -78,8 +78,8 @@ def get_psu_presence(self, index): """ status = 0 psu_absent = 0 - attr_file ='psu_present' - attr_path = self.SYSFS_PSU_DIR[index-1] +'/' + attr_file + attr_file = 'psu_present' + attr_path = self.SYSFS_PSU_DIR[index-1] + '/' + attr_file attr_value = self.get_attr_value(attr_path) @@ -87,7 +87,6 @@ def get_psu_presence(self, index): attr_value = int(attr_value, 16) # Check for PSU presence if (attr_value == 1): - status = 1 + status = 1 return status - diff --git a/device/cig/x86_64-cig_cs6436_54p-r0/plugins/sfputil.py b/device/cig/x86_64-cig_cs6436_54p-r0/plugins/sfputil.py index 2863b80c9950..2d6827300457 100755 --- a/device/cig/x86_64-cig_cs6436_54p-r0/plugins/sfputil.py +++ b/device/cig/x86_64-cig_cs6436_54p-r0/plugins/sfputil.py @@ -1,10 +1,8 @@ -#!/usr/bin/env python - try: import time from sonic_sfp.sfputilbase import SfpUtilBase -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") class SfpUtil(SfpUtilBase): @@ -19,63 +17,63 @@ class SfpUtil(SfpUtilBase): _global_port_pres_dict = {} _port_to_i2c_mapping = { - 1 : 8, - 2 : 9, - 3 : 10, - 4 : 11, - 5 : 12, - 6 : 13, - 7 : 14, - 8 : 15, - 9 : 16, + 1: 8, + 2: 9, + 3: 10, + 4: 11, + 5: 12, + 6: 13, + 7: 14, + 8: 15, + 9: 16, 10: 17, - 11 : 18, - 12 : 19, - 13 : 20, - 14 : 21, - 15 : 22, - 16 : 23, - 17 : 24, - 18 : 25, - 19 : 26, - 20 : 27, - 21 : 28, - 22 : 29, - 23 : 30, - 24 : 31, - 25 : 32, - 26 : 33, - 27 : 34, - 28 : 35, - 29 : 36, - 30 : 37, - 31 : 38, - 32 : 39, - 33 : 40, - 34 : 41, - 35 : 42, - 36 : 43, - 37 : 44, - 38 : 45, - 39 : 46, - 40 : 47, - 41 : 48, - 42 : 49, - 43 : 50, - 44 : 51, - 45 : 52, - 46 : 53, - 47 : 54, - 48 : 55, - 49 : 56, - 50 : 57, - 51 : 60, - 52 : 61, - 53 : 62, - 54 : 63, + 11: 18, + 12: 19, + 13: 20, + 14: 21, + 15: 22, + 16: 23, + 17: 24, + 18: 25, + 19: 26, + 20: 27, + 21: 28, + 22: 29, + 23: 30, + 24: 31, + 25: 32, + 26: 33, + 27: 34, + 28: 35, + 29: 36, + 30: 37, + 31: 38, + 32: 39, + 33: 40, + 34: 41, + 35: 42, + 36: 43, + 37: 44, + 38: 45, + 39: 46, + 40: 47, + 41: 48, + 42: 49, + 43: 50, + 44: 51, + 45: 52, + 46: 53, + 47: 54, + 48: 55, + 49: 56, + 50: 57, + 51: 60, + 52: 61, + 53: 62, + 54: 63, } - _qsfp_ports = range(_qsfp_port_start, _ports_in_block + 1) + _qsfp_ports = list(range(_qsfp_port_start, _ports_in_block + 1)) def get_presence(self, port_num): # Check for invalid port_num @@ -85,11 +83,10 @@ def get_presence(self, port_num): path = "/sys/bus/i2c/devices/{0}-0050/sfp_is_present" port_ps = path.format(self._port_to_i2c_mapping[port_num]) - try: reg_file = open(port_ps) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False try: @@ -100,7 +97,7 @@ def get_presence(self, port_num): try: reg_value = reg_file.readline().rstrip() except IOError as e: - print "Error:try again to read file failed: %s %s" % (str(e), port_ps) + print("Error:try again to read file failed: %s %s" % (str(e), port_ps)) reg_file.close() return False @@ -118,7 +115,6 @@ def init_global_port_presence(self): for port_num in range(self.port_start, (self.port_end + 1)): self._global_port_pres_dict[port_num] = '0' - def __init__(self): eeprom_path = '/sys/bus/i2c/devices/{0}-0050/sfp_eeprom' for x in range(self._port_start, self._port_end + 1): @@ -139,10 +135,10 @@ def reset(self, port_num): try: reg_file = open(port_ps, 'w') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False - #toggle reset + # toggle reset reg_file.seek(0) reg_file.write('1') time.sleep(1) @@ -158,15 +154,15 @@ def set_low_power_mode(self, port_num, lpmode): pre_value = self.get_presence(port_num) if pre_value == False: - return False + return False path = "/sys/bus/i2c/devices/{0}-0050/sfp_lpmode" port_ps = path.format(self._port_to_i2c_mapping[port_num]) try: - reg_file = open(port_ps,'w') + reg_file = open(port_ps, 'w') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_file.seek(0) @@ -179,7 +175,6 @@ def set_low_power_mode(self, port_num, lpmode): return True - def get_low_power_mode(self, port_num): # Check for invalid port_num @@ -196,13 +191,13 @@ def get_low_power_mode(self, port_num): try: reg_file = open(port_ps) except IOError as e: - print "Error: unable to open file:%s %s" % (str(e), port_ps) + print("Error: unable to open file:%s %s" % (str(e), port_ps)) return False try: reg_value = reg_file.readline().rstrip() except IOError as e: - print "Error: unable to open file:%s %s" % (str(e), port_ps) + print("Error: unable to open file:%s %s" % (str(e), port_ps)) reg_file.close() return False @@ -232,7 +227,6 @@ def get_transceiver_change_event(self): time.sleep(0.5) - @property def port_start(self): return self._port_start @@ -247,4 +241,4 @@ def qsfp_ports(self): @property def port_to_eeprom_mapping(self): - return self._port_to_eeprom_mapping + return self._port_to_eeprom_mapping diff --git a/device/cig/x86_64-cig_cs6436_56p-r0/plugins/eeprom.py b/device/cig/x86_64-cig_cs6436_56p-r0/plugins/eeprom.py index 5019b9c40a9a..ae5a8385d96c 100755 --- a/device/cig/x86_64-cig_cs6436_56p-r0/plugins/eeprom.py +++ b/device/cig/x86_64-cig_cs6436_56p-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,11 +8,13 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/7-0057/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/cig/x86_64-cig_cs6436_56p-r0/plugins/psuutil.py b/device/cig/x86_64-cig_cs6436_56p-r0/plugins/psuutil.py index 70d50e6c3458..442026775a5e 100755 --- a/device/cig/x86_64-cig_cs6436_56p-r0/plugins/psuutil.py +++ b/device/cig/x86_64-cig_cs6436_56p-r0/plugins/psuutil.py @@ -22,8 +22,8 @@ class PsuUtil(PsuBase): def __init__(self): PsuBase.__init__(self) - # Get sysfs attribute + def get_attr_value(self, attr_path): retval = 'ERR' @@ -57,7 +57,7 @@ def get_psu_status(self, index): """ status = 0 attr_file = 'psu_power_good' - attr_path = self.SYSFS_PSU_DIR[index-1] +'/' + attr_file + attr_path = self.SYSFS_PSU_DIR[index-1] + '/' + attr_file attr_value = self.get_attr_value(attr_path) @@ -65,7 +65,7 @@ def get_psu_status(self, index): attr_value = int(attr_value, 16) # Check for PSU status if (attr_value == 1): - status = 1 + status = 1 return status @@ -78,8 +78,8 @@ def get_psu_presence(self, index): """ status = 0 psu_absent = 0 - attr_file ='psu_present' - attr_path = self.SYSFS_PSU_DIR[index-1] +'/' + attr_file + attr_file = 'psu_present' + attr_path = self.SYSFS_PSU_DIR[index-1] + '/' + attr_file attr_value = self.get_attr_value(attr_path) @@ -87,7 +87,6 @@ def get_psu_presence(self, index): attr_value = int(attr_value, 16) # Check for PSU presence if (attr_value == 1): - status = 1 + status = 1 return status - diff --git a/device/cig/x86_64-cig_cs6436_56p-r0/plugins/sfputil.py b/device/cig/x86_64-cig_cs6436_56p-r0/plugins/sfputil.py index 1e15c0e886f7..9c31083f5c23 100755 --- a/device/cig/x86_64-cig_cs6436_56p-r0/plugins/sfputil.py +++ b/device/cig/x86_64-cig_cs6436_56p-r0/plugins/sfputil.py @@ -1,10 +1,8 @@ -#!/usr/bin/env python - try: import time from sonic_sfp.sfputilbase import SfpUtilBase -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") class SfpUtil(SfpUtilBase): @@ -17,68 +15,68 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} _global_port_pres_dict = {} - + _port_to_i2c_mapping = { - 1 : 8, - 2 : 9, - 3 : 10, - 4 : 11, - 5 : 12, - 6 : 13, - 7 : 14, - 8 : 15, - 9 : 16, + 1: 8, + 2: 9, + 3: 10, + 4: 11, + 5: 12, + 6: 13, + 7: 14, + 8: 15, + 9: 16, 10: 17, - 11 : 18, - 12 : 19, - 13 : 20, - 14 : 21, - 15 : 22, - 16 : 23, - 17 : 24, - 18 : 25, - 19 : 26, - 20 : 27, - 21 : 28, - 22 : 29, - 23 : 30, - 24 : 31, - 25 : 32, - 26 : 33, - 27 : 34, - 28 : 35, - 29 : 36, - 30 : 37, - 31 : 38, - 32 : 39, - 33 : 40, - 34 : 41, - 35 : 42, - 36 : 43, - 37 : 44, - 38 : 45, - 39 : 46, - 40 : 47, - 41 : 48, - 42 : 49, - 43 : 50, - 44 : 51, - 45 : 52, - 46 : 53, - 47 : 54, - 48 : 55, - 49 : 56, - 50 : 57, - 51 : 58, - 52 : 59, - 53 : 60, - 54 : 61, - 55 : 62, - 56 : 63, + 11: 18, + 12: 19, + 13: 20, + 14: 21, + 15: 22, + 16: 23, + 17: 24, + 18: 25, + 19: 26, + 20: 27, + 21: 28, + 22: 29, + 23: 30, + 24: 31, + 25: 32, + 26: 33, + 27: 34, + 28: 35, + 29: 36, + 30: 37, + 31: 38, + 32: 39, + 33: 40, + 34: 41, + 35: 42, + 36: 43, + 37: 44, + 38: 45, + 39: 46, + 40: 47, + 41: 48, + 42: 49, + 43: 50, + 44: 51, + 45: 52, + 46: 53, + 47: 54, + 48: 55, + 49: 56, + 50: 57, + 51: 58, + 52: 59, + 53: 60, + 54: 61, + 55: 62, + 56: 63, } - _qsfp_ports = range(_qsfp_port_start, _ports_in_block + 1) - + _qsfp_ports = list(range(_qsfp_port_start, _ports_in_block + 1)) + def get_presence(self, port_num): # Check for invalid port_num if port_num < self._port_start or port_num > self._port_end: @@ -87,29 +85,28 @@ def get_presence(self, port_num): path = "/sys/bus/i2c/devices/{0}-0050/sfp_is_present" port_ps = path.format(self._port_to_i2c_mapping[port_num]) - try: reg_file = open(port_ps) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False try: reg_value = reg_file.readline().rstrip() except IOError as e: time.sleep(1) - + try: reg_value = reg_file.readline().rstrip() except IOError as e: - print "Error:try again to read file failed: %s %s" % (str(e), port_ps) + print("Error:try again to read file failed: %s %s" % (str(e), port_ps)) reg_file.close() return False reg_file.close() if reg_value == '1': return True - + reg_file.close() if reg_value == '1': return True @@ -120,13 +117,12 @@ def init_global_port_presence(self): for port_num in range(self.port_start, (self.port_end + 1)): self._global_port_pres_dict[port_num] = '0' - def __init__(self): eeprom_path = '/sys/bus/i2c/devices/{0}-0050/sfp_eeprom' for x in range(self._port_start, self._port_end + 1): port_eeprom_path = eeprom_path.format(self._port_to_i2c_mapping[x]) self._port_to_eeprom_mapping[x] = port_eeprom_path - + self.init_global_port_presence() SfpUtilBase.__init__(self) @@ -137,14 +133,14 @@ def reset(self, port_num): path = "/sys/bus/i2c/devices/{0}-0050/sfp_port_reset" port_ps = path.format(self._port_to_i2c_mapping[port_num]) - + try: reg_file = open(port_ps, 'w') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False - #toggle reset + # toggle reset reg_file.seek(0) reg_file.write('1') time.sleep(1) @@ -152,23 +148,23 @@ def reset(self, port_num): reg_file.write('0') reg_file.close() return True - + def set_low_power_mode(self, port_num, lpmode): # Check for invalid port_num if port_num < self._qsfp_port_start or port_num > self._port_end: return False - pre_value = self.get_presence(port_num) + pre_value = self.get_presence(port_num) if pre_value == False: - return False - + return False + path = "/sys/bus/i2c/devices/{0}-0050/sfp_lpmode" port_ps = path.format(self._port_to_i2c_mapping[port_num]) - + try: - reg_file = open(port_ps,'w') + reg_file = open(port_ps, 'w') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_file.seek(0) @@ -181,40 +177,39 @@ def set_low_power_mode(self, port_num, lpmode): return True - def get_low_power_mode(self, port_num): # Check for invalid port_num if port_num < self._qsfp_port_start or port_num > self._port_end: return False - - pre_value = self.get_presence(port_num) + + pre_value = self.get_presence(port_num) if pre_value == False: return False - + path = "/sys/bus/i2c/devices/{0}-0050/sfp_lpmode" port_ps = path.format(self._port_to_i2c_mapping[port_num]) - + try: reg_file = open(port_ps) except IOError as e: - print "Error: unable to open file:%s %s" % (str(e), port_ps) + print("Error: unable to open file:%s %s" % (str(e), port_ps)) return False try: reg_value = reg_file.readline().rstrip() except IOError as e: - print "Error: unable to open file:%s %s" % (str(e), port_ps) - reg_file.close() + print("Error: unable to open file:%s %s" % (str(e), port_ps)) + reg_file.close() return False - + reg_file.close() if reg_value == '1': return True return False - + def get_transceiver_change_event(self): port_dict = {} while True: @@ -234,7 +229,6 @@ def get_transceiver_change_event(self): time.sleep(0.5) - @property def port_start(self): return self._port_start @@ -247,6 +241,6 @@ def port_end(self): def qsfp_ports(self): return self._qsfp_ports - @property + @property def port_to_eeprom_mapping(self): - return self._port_to_eeprom_mapping + return self._port_to_eeprom_mapping diff --git a/device/common/pddf/plugins/eeprom.py b/device/common/pddf/plugins/eeprom.py index 7671c50bd345..cf7215e0c9ac 100755 --- a/device/common/pddf/plugins/eeprom.py +++ b/device/common/pddf/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - try: import os import sys @@ -8,12 +6,13 @@ import pddfparse #from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): global pddf_obj global plugin_data @@ -24,4 +23,3 @@ def __init__(self, name, path, cpld_root, ro): # system EEPROM always has device name EEPROM1 self.eeprom_path = pddf_obj.get_path("EEPROM1", "eeprom") super(board, self).__init__(self.eeprom_path, 0, '', True) - diff --git a/device/common/pddf/plugins/fanutil.py b/device/common/pddf/plugins/fanutil.py index 2701fa5f2326..f34c260035e8 100755 --- a/device/common/pddf/plugins/fanutil.py +++ b/device/common/pddf/plugins/fanutil.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - - -# Sample pddf_fanutil file +# Sample pddf_fanutil file # All the supported FAN SysFS aattributes are #- fan_present #- fan_direction @@ -21,7 +18,8 @@ try: from sonic_fan.fan_base import FanBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class FanUtil(FanBase): """PDDF generic FAN util class""" @@ -36,18 +34,18 @@ def __init__(self): pddf_obj = pddfparse.PddfParse() self.platform = pddf_obj.get_platform() - self.num_fans = (self.platform['num_fantrays'] * self.platform['num_fans_pertray'] ) + self.num_fans = (self.platform['num_fantrays'] * self.platform['num_fans_pertray']) def get_num_fans(self): return self.num_fans def get_presence(self, idx): # 1 based fan index - if idx<1 or idx>self.num_fans: - print "Invalid fan index %d\n"%idx + if idx < 1 or idx > self.num_fans: + print("Invalid fan index %d\n" % idx) return False - attr_name = "fan"+ str(idx) +"_present" + attr_name = "fan" + str(idx) + "_present" output = pddf_obj.get_attr_name_output("FAN-CTRL", attr_name) if not output: return False @@ -66,8 +64,8 @@ def get_presence(self, idx): def get_status(self, idx): # 1 based fan index - if idx<1 or idx>self.num_fans: - print "Invalid fan index %d\n"%idx + if idx < 1 or idx > self.num_fans: + print("Invalid fan index %d\n" % idx) return False speed = self.get_speed(idx) @@ -76,8 +74,8 @@ def get_status(self, idx): def get_direction(self, idx): # 1 based fan index - if idx<1 or idx>self.num_fans: - print "Invalid fan index %d\n"%idx + if idx < 1 or idx > self.num_fans: + print("Invalid fan index %d\n" % idx) return None attr = "fan" + str(idx) + "_direction" @@ -91,7 +89,6 @@ def get_direction(self, idx): val = val.rstrip() vmap = plugin_data['FAN']['direction'][mode]['valmap'] - if val in vmap: direction = vmap[val] else: @@ -100,7 +97,7 @@ def get_direction(self, idx): return direction def get_directions(self): - num_fan = self.get_num_fan(); + num_fan = self.get_num_fan() for i in range(1, num_fan+1): attr = "fan" + str(i) + "_direction" @@ -116,14 +113,14 @@ def get_directions(self): direction = vmap[str(val)] - print "FAN-%d direction is %s"%(i, direction) + print("FAN-%d direction is %s" % (i, direction)) return 0 def get_speed(self, idx): # 1 based fan index - if idx<1 or idx>self.num_fans: - print "Invalid fan index %d\n"%idx + if idx < 1 or idx > self.num_fans: + print("Invalid fan index %d\n" % idx) return 0 attr = "fan" + str(idx) + "_input" @@ -142,7 +139,7 @@ def get_speed(self, idx): return rpm_speed def get_speeds(self): - num_fan = self.get_num_fan(); + num_fan = self.get_num_fan() ret = "FAN_INDEX\t\tRPM\n" for i in range(1, num_fan+1): @@ -159,23 +156,23 @@ def get_speeds(self): else: frpm = int(val) - ret += "FAN-%d\t\t\t%d\n"%(i, frpm) + ret += "FAN-%d\t\t\t%d\n" % (i, frpm) return ret def set_speed(self, val): - if val<0 or val>100: - print "Error: Invalid speed %d. Please provide a valid speed percentage"%val + if val < 0 or val > 100: + print("Error: Invalid speed %d. Please provide a valid speed percentage" % val) return False - + num_fan = self.num_fans if 'duty_cycle_to_pwm' not in plugin_data['FAN']: - print "Setting fan speed is not allowed !" + print("Setting fan speed is not allowed !") return False else: duty_cycle_to_pwm = eval(plugin_data['FAN']['duty_cycle_to_pwm']) pwm = duty_cycle_to_pwm(val) - print "New Speed: %d%% - PWM value to be set is %d\n"%(val,pwm) + print("New Speed: %d%% - PWM value to be set is %d\n" % (val, pwm)) for i in range(1, num_fan+1): attr = "fan" + str(i) + "_pwm" diff --git a/device/common/pddf/plugins/ledutil.py b/device/common/pddf/plugins/ledutil.py index adbfe9cc62e1..5f9e2e99dbfa 100755 --- a/device/common/pddf/plugins/ledutil.py +++ b/device/common/pddf/plugins/ledutil.py @@ -1,58 +1,59 @@ -#!/usr/bin/env python - import sys sys.path.append('/usr/share/sonic/platform/plugins') import pddfparse + class LedUtil: color_map = { - "STATUS_LED_COLOR_GREEN" : "on", - "STATUS_LED_COLOR_RED" : "faulty", - "STATUS_LED_COLOR_OFF" : "off" + "STATUS_LED_COLOR_GREEN": "on", + "STATUS_LED_COLOR_RED": "faulty", + "STATUS_LED_COLOR_OFF": "off" } def __init__(self): global pddf_obj pddf_obj = pddfparse.PddfParse() - self.path="pddf/devices/led" - self.cur_state_path="pddf/devices/led/cur_state" + self.path = "pddf/devices/led" + self.cur_state_path = "pddf/devices/led/cur_state" def set_status_led(self, led_device_name, color, color_state="SOLID"): - if (not led_device_name in pddf_obj.data.keys()): - status="ERROR: " + led_device_name + " is not configured" - return (status) + if (not led_device_name in list(pddf_obj.data.keys())): + status = "ERROR: " + led_device_name + " is not configured" + return (status) - if (not color in self.color_map.keys()): - status="ERROR: Invalid color" - return (status) + if (not color in list(self.color_map.keys())): + status = "ERROR: Invalid color" + return (status) - index=pddf_obj.data[led_device_name]['dev_attr']['index'] + index = pddf_obj.data[led_device_name]['dev_attr']['index'] pddf_obj.create_attr('device_name', led_device_name, self.path) pddf_obj.create_attr('index', index, self.path) - pddf_obj.create_attr('color', self.color_map[color], self.cur_state_path) + pddf_obj.create_attr( + 'color', self.color_map[color], self.cur_state_path) pddf_obj.create_attr('color_state', color_state, self.cur_state_path) pddf_obj.create_attr('dev_ops', 'set_status', self.path) - return ("Executed") + return ("Executed") def get_status_led(self, led_device_name): - if (not led_device_name in pddf_obj.data.keys()): - status="ERROR: " + led_device_name + " is not configured" - return (status) + if (not led_device_name in list(pddf_obj.data.keys())): + status = "ERROR: " + led_device_name + " is not configured" + return (status) - index=pddf_obj.data[led_device_name]['dev_attr']['index'] + index = pddf_obj.data[led_device_name]['dev_attr']['index'] pddf_obj.create_attr('device_name', led_device_name, self.path) pddf_obj.create_attr('index', index, self.path) pddf_obj.create_attr('dev_ops', 'get_status', self.path) - color_f="/sys/kernel/" + self.cur_state_path +"/color" - color_state_f="/sys/kernel/" + self.cur_state_path +"/color_state" + color_f = "/sys/kernel/" + self.cur_state_path + "/color" + color_state_f = "/sys/kernel/" + self.cur_state_path + "/color_state" try: - with open(color_f, 'r') as f: - color = f.read().strip("\r\n") - with open(color_state_f, 'r') as f: - color_state = f.read().strip("\r\n") + with open(color_f, 'r') as f: + color = f.read().strip("\r\n") + with open(color_state_f, 'r') as f: + color_state = f.read().strip("\r\n") except IOError: - status="ERROR :" + color_f + " open failed" - return (status) - status = "%s-%s:\t%s %s\n"%(led_device_name, index, color, color_state) - return (status) + status = "ERROR :" + color_f + " open failed" + return (status) + status = "%s-%s:\t%s %s\n" % (led_device_name, + index, color, color_state) + return (status) diff --git a/device/common/pddf/plugins/psuutil.py b/device/common/pddf/plugins/psuutil.py index 01cf4b126ee1..dccb1ac1a155 100755 --- a/device/common/pddf/plugins/psuutil.py +++ b/device/common/pddf/plugins/psuutil.py @@ -1,8 +1,7 @@ -#!/usr/bin/env python # -# Sample pddf_psuutil file +# Sample pddf_psuutil file # -# All the supported PSU SysFS aattributes are +# All the supported PSU SysFS aattributes are #- psu_present #- psu_model_name #- psu_power_good @@ -24,7 +23,7 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class PsuUtil(PsuBase): @@ -47,7 +46,7 @@ def get_psu_status(self, index): if index is None: return False - device = "PSU" + "%d"%index + device = "PSU" + "%d" % index output = pddf_obj.get_attr_name_output(device, "psu_power_good") if not output: return False @@ -68,7 +67,7 @@ def get_psu_presence(self, index): return False status = 0 - device = "PSU" + "%d"%index + device = "PSU" + "%d" % index output = pddf_obj.get_attr_name_output(device, "psu_present") if not output: return False @@ -87,17 +86,17 @@ def get_powergood_status(self, idx): if idx is None: return False - if idx<1 or idx>self.platform['num_psus']: - print "Invalid index %d\n"%idx + if idx < 1 or idx > self.platform['num_psus']: + print("Invalid index %d\n" % idx) return False - device = "PSU"+"%d"%(idx) + device = "PSU"+"%d" % (idx) output = pddf_obj.get_attr_name_output(device, "psu_power_good") if not output: return False mode = output['mode'] - status = output ['status'] + status = output['status'] vmap = plugin_data['PSU']['psu_power_good'][mode]['valmap'] @@ -110,11 +109,11 @@ def get_model(self, idx): if idx is None: return None - if idx<1 or idx>self.platform['num_psus']: - print "Invalid index %d\n"%idx + if idx < 1 or idx > self.platform['num_psus']: + print("Invalid index %d\n" % idx) return None - device = "PSU"+"%d"%(idx) + device = "PSU"+"%d" % (idx) output = pddf_obj.get_attr_name_output(device, "psu_model_name") if not output: return None @@ -131,11 +130,11 @@ def get_mfr_id(self, idx): if idx is None: return None - if idx<1 or idx>self.platform['num_psus']: - print "Invalid index %d\n"%idx + if idx < 1 or idx > self.platform['num_psus']: + print("Invalid index %d\n" % idx) return None - device = "PSU"+"%d"%(idx) + device = "PSU"+"%d" % (idx) output = pddf_obj.get_attr_name_output(device, "psu_mfr_id") if not output: return None @@ -148,11 +147,11 @@ def get_serial(self, idx): if idx is None: return None - if idx<1 or idx>self.platform['num_psus']: - print "Invalid index %d\n"%idx + if idx < 1 or idx > self.platform['num_psus']: + print("Invalid index %d\n" % idx) return None - device = "PSU"+"%d"%(idx) + device = "PSU"+"%d" % (idx) output = pddf_obj.get_attr_name_output(device, "psu_serial_num") if not output: return None @@ -165,11 +164,11 @@ def get_direction(self, idx): if idx is None: return None - if idx<1 or idx>self.platform['num_psus']: - print "Invalid index %d\n"%idx + if idx < 1 or idx > self.platform['num_psus']: + print("Invalid index %d\n" % idx) return None - device = "PSU"+"%d"%(idx) + device = "PSU"+"%d" % (idx) output = pddf_obj.get_attr_name_output(device, "psu_fan_dir") if not output: return None @@ -189,11 +188,11 @@ def get_output_voltage(self, idx): if idx is None: return 0.0 - if idx<1 or idx>self.platform['num_psus']: - print "Invalid index %d\n"%idx + if idx < 1 or idx > self.platform['num_psus']: + print("Invalid index %d\n" % idx) return 0.0 - device = "PSU"+"%d"%(idx) + device = "PSU"+"%d" % (idx) output = pddf_obj.get_attr_name_output(device, "psu_v_out") if not output: return 0.0 @@ -207,11 +206,11 @@ def get_output_current(self, idx): if idx is None: return 0.0 - if idx<1 or idx>self.platform['num_psus']: - print "Invalid index %d\n"%idx + if idx < 1 or idx > self.platform['num_psus']: + print("Invalid index %d\n" % idx) return 0.0 - device = "PSU"+"%d"%(idx) + device = "PSU"+"%d" % (idx) output = pddf_obj.get_attr_name_output(device, "psu_i_out") if not output: return 0.0 @@ -225,11 +224,11 @@ def get_output_power(self, idx): if idx is None: return 0.0 - if idx<1 or idx>self.platform['num_psus']: - print "Invalid index %d\n"%idx + if idx < 1 or idx > self.platform['num_psus']: + print("Invalid index %d\n" % idx) return 0.0 - device = "PSU"+"%d"%(idx) + device = "PSU"+"%d" % (idx) output = pddf_obj.get_attr_name_output(device, "psu_p_out") if not output: return 0.0 @@ -243,16 +242,15 @@ def get_fan_rpm(self, idx, fan_idx): if idx is None or fan_idx is None: return 0 - if idx<1 or idx>self.platform['num_psus']: - print "Invalid index %d\n"%idx + if idx < 1 or idx > self.platform['num_psus']: + print("Invalid index %d\n" % idx) return 0 - - device = "PSU"+"%d"%(idx) + device = "PSU"+"%d" % (idx) num_fans = pddf_obj.get_num_psu_fans(device) - if fan_idx<1 or fan_idx>num_fans: - print "Invalid PSU-fan index %d\n"%fan_idx + if fan_idx < 1 or fan_idx > num_fans: + print("Invalid PSU-fan index %d\n" % fan_idx) return 0 output = pddf_obj.get_attr_name_output(device, "psu_fan"+str(fan_idx)+"_speed_rpm") @@ -265,7 +263,7 @@ def get_fan_rpm(self, idx, fan_idx): return 0 else: speed = int(output['status']) - + return speed def dump_sysfs(self): diff --git a/device/common/pddf/plugins/sfputil.py b/device/common/pddf/plugins/sfputil.py index 394aff1c42be..1ca925610822 100755 --- a/device/common/pddf/plugins/sfputil.py +++ b/device/common/pddf/plugins/sfputil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - import os.path import sys sys.path.append('/usr/share/sonic/platform/plugins') @@ -10,8 +8,9 @@ import time from ctypes import create_string_buffer from sonic_sfp.sfputilbase import SfpUtilBase -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + class SfpUtil(SfpUtilBase): """Platform generic PDDF SfpUtil class""" @@ -36,8 +35,8 @@ def __init__(self): self._port_end = self.get_num_ports() for port_num in range(self._port_start, self._port_end): - device = "PORT" + "%d"%(port_num+1) - port_eeprom_path = pddf_obj.get_path(device,"eeprom") + device = "PORT" + "%d" % (port_num+1) + port_eeprom_path = pddf_obj.get_path(device, "eeprom") self._port_to_eeprom_mapping[port_num] = port_eeprom_path port_type = pddf_obj.get_device_type(device) self._port_to_type_mapping[port_num] = port_type @@ -56,7 +55,7 @@ def get_presence(self, port_num): if port_num < self._port_start or port_num > self._port_end: return False - device = "PORT" + "%d"%(port_num+1) + device = "PORT" + "%d" % (port_num+1) output = pddf_obj.get_attr_name_output(device, 'xcvr_present') if not output: return False @@ -105,15 +104,15 @@ def reset(self, port_num): if port_num < self._port_start or port_num > self._port_end: return False - device = "PORT" + "%d"%(port_num+1) - port_ps = pddf_obj.get_path(device,"xcvr_reset") + device = "PORT" + "%d" % (port_num+1) + port_ps = pddf_obj.get_path(device, "xcvr_reset") if port_ps is None: return False try: reg_file = open(port_ps, 'w') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False try: @@ -135,31 +134,32 @@ def get_low_power_mode(self, port_num): if not self.get_presence(port_num): return False - device = "PORT" + "%d"%(port_num+1) + device = "PORT" + "%d" % (port_num+1) output = pddf_obj.get_attr_name_output(device, 'xcvr_lpmode') if not output: if port_num not in self.qsfp_ports: - return False # Read from eeprom only for QSFP ports + return False # Read from eeprom only for QSFP ports try: eeprom = None eeprom = open(self.port_to_eeprom_mapping[port_num], "rb") # check for valid connector type eeprom.seek(2) ctype = eeprom.read(1) - if ctype in ['21','23']: + if ctype in ['21', '23']: return False eeprom.seek(93) lpmode = ord(eeprom.read(1)) - + if ((lpmode & 0x3) == 0x3): - return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 + return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 else: - return False # High Power Mode if one of the following conditions is matched: - # 1. "Power override" bit is 0 - # 2. "Power override" bit is 1 and "Power set" bit is 0 + # High Power Mode if one of the following conditions is matched: + # 1. "Power override" bit is 0 + # 2. "Power override" bit is 1 and "Power set" bit is 0 + return False except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False finally: if eeprom is not None: @@ -180,33 +180,33 @@ def set_low_power_mode(self, port_num, lpmode): return False if not self.get_presence(port_num): - return False # Port is not present, unable to set the eeprom + return False # Port is not present, unable to set the eeprom - device = "PORT" + "%d"%(port_num+1) - port_ps = pddf_obj.get_path(device,"xcvr_lpmode") + device = "PORT" + "%d" % (port_num+1) + port_ps = pddf_obj.get_path(device, "xcvr_lpmode") if port_ps is None: if port_num not in self.qsfp_ports: - return False # Write to eeprom only for QSFP ports + return False # Write to eeprom only for QSFP ports try: eeprom = None eeprom = open(self.port_to_eeprom_mapping[port_num], "r+b") # check for valid connector type eeprom.seek(2) ctype = eeprom.read(1) - if ctype in ['21','23']: + if ctype in ['21', '23']: return False # Fill in write buffer - regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode + regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode buffer = create_string_buffer(1) buffer[0] = chr(regval) - + # Write to eeprom eeprom.seek(93) eeprom.write(buffer[0]) return True except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False finally: if eeprom is not None: @@ -232,6 +232,5 @@ def get_transceiver_change_event(self): """ raise NotImplementedError - def dump_sysfs(self): return pddf_obj.cli_dump_dsysfs('xcvr') diff --git a/device/common/pddf/plugins/sysstatutil.py b/device/common/pddf/plugins/sysstatutil.py index e8b3e8008652..af4dd5915361 100755 --- a/device/common/pddf/plugins/sysstatutil.py +++ b/device/common/pddf/plugins/sysstatutil.py @@ -1,13 +1,13 @@ -#!/usr/bin/env python - import os.path import sys sys.path.append('/usr/share/sonic/platform/plugins') import pddfparse import json + class SYSStatusUtil(): """Platform-specific SYSStatus class""" + def __init__(self): global pddf_obj global plugin_data @@ -18,68 +18,65 @@ def __init__(self): def get_board_info(self): device = "SYSSTATUS" - node = pddf_obj.get_path(device,"board_info") + node = pddf_obj.get_path(device, "board_info") if node is None: return False try: with open(node, 'r') as f: status = f.read() - print "board_info : %s" %status + print("board_info : %s" % status) except IOError: return False def get_cpld_versio(self): device = "SYSSTATUS" - node = pddf_obj.get_path(device,"cpld1_version") + node = pddf_obj.get_path(device, "cpld1_version") if node is None: return False try: with open(node, 'r') as f: status = f.read() - print "cpld1_version : %s" %status + print("cpld1_version : %s" % status) except IOError: return False def get_power_module_status(self): - device = "SYSSTATUS" - node = pddf_obj.get_path(device,"power_module_status") - if node is None: - return False - try: - with open(node, 'r') as f: - status = f.read() - print "power_module_status : %s" %status - except IOError: - return False - + device = "SYSSTATUS" + node = pddf_obj.get_path(device, "power_module_status") + if node is None: + return False + try: + with open(node, 'r') as f: + status = f.read() + print("power_module_status : %s" % status) + except IOError: + return False def get_system_reset_status(self): device = "SYSSTATUS" - for i in range(1,8): - node = pddf_obj.get_path(device,"system_reset"+str(i)) - if node is None: - return False - try: - with open(node, 'r') as f: - status = f.read() - print "system_reset%s : %s" %(i, status) - except IOError: - print "system_reset%s not supported" %i - + for i in range(1, 8): + node = pddf_obj.get_path(device, "system_reset"+str(i)) + if node is None: + return False + try: + with open(node, 'r') as f: + status = f.read() + print("system_reset%s : %s" % (i, status)) + except IOError: + print("system_reset%s not supported" % i) def get_misc_status(self): device = "SYSSTATUS" - for i in range(1,3): - node = pddf_obj.get_path(device,"misc"+str(i)) - if node is None: - return False - try: - with open(node, 'r') as f: - status = f.read() - print "misc%s : %s" %(i, status) - except IOError: - print "system_reset%s not supported" %i - + for i in range(1, 3): + node = pddf_obj.get_path(device, "misc"+str(i)) + if node is None: + return False + try: + with open(node, 'r') as f: + status = f.read() + print("misc%s : %s" % (i, status)) + except IOError: + print("system_reset%s not supported" % i) def dump_sysfs(self): return pddf_obj.cli_dump_dsysfs('sys-status') diff --git a/device/common/pddf/plugins/thermalutil.py b/device/common/pddf/plugins/thermalutil.py index ebf29608a46a..6aef47b7e924 100755 --- a/device/common/pddf/plugins/thermalutil.py +++ b/device/common/pddf/plugins/thermalutil.py @@ -1,11 +1,10 @@ -#!/usr/bin/env python - import os.path import sys import json sys.path.append('/usr/share/sonic/platform/plugins') import pddfparse + class ThermalUtil: def __init__(self): global pddf_obj @@ -15,24 +14,25 @@ def __init__(self): pddf_obj = pddfparse.PddfParse() self.platform = pddf_obj.get_platform() - self.num_thermals = self.platform['num_temps'] - self.info=[] + self.num_thermals = self.platform['num_temps'] + self.info = [] def get_num_thermals(self): return (self.num_thermals) def get_thermal_info(self): - list=[] + list = [] pddf_obj.get_device_list(list, "TEMP_SENSOR") list.sort() for dev in list: - data={} - device_name = dev['dev_info']['device_name'] + data = {} + device_name = dev['dev_info']['device_name'] topo_info = dev['i2c']['topo_info'] - label="%s-i2c-%d-%x" % (topo_info['dev_type'], int(topo_info['parent_bus'], 0), int(topo_info['dev_addr'], 0)) + label = "%s-i2c-%d-%x" % (topo_info['dev_type'], + int(topo_info['parent_bus'], 0), int(topo_info['dev_addr'], 0)) attr_list = dev['i2c']['attr_list'] - data['device_name']=device_name - data['label']=label + data['device_name'] = device_name + data['label'] = label for attr in attr_list: attr_name = attr['attr_name'] node = pddf_obj.get_path(device_name, attr_name) @@ -43,32 +43,33 @@ def get_thermal_info(self): attr_value = int(f.read()) except IOError: return False - data[attr_name] = attr_value/float(1000) + data[attr_name] = attr_value/float(1000) self.info.append(data) def show_thermal_temp_values(self, idx): - if idx<1 or idx>self.num_thermals: - print "Invalid temperature sensor idx %d"%idx + if idx < 1 or idx > self.num_thermals: + print("Invalid temperature sensor idx %d" % idx) return None self.get_thermal_info() - thermal_name = "TEMP"+"%d"%idx - label="" - value="" + thermal_name = "TEMP"+"%d" % idx + label = "" + value = "" for temp in self.info: - if thermal_name==temp['device_name']: + if thermal_name == temp['device_name']: label = temp['label'] - value = "temp1\t %+.1f C (high = %+.1f C, hyst = %+.1f C)" % (temp['temp1_input'], temp['temp1_max'], temp['temp1_max_hyst']) + value = "temp1\t %+.1f C (high = %+.1f C, hyst = %+.1f C)" % ( + temp['temp1_input'], temp['temp1_max'], temp['temp1_max_hyst']) else: continue return (label, value) - def show_temp_values(self): + def show_temp_values(self): self.get_thermal_info() for temp in self.info: - print temp['label'] - print "temp1\t %+.1f C (high = %+.1f C, hyst = %+.1f C)" % (temp['temp1_input'], temp['temp1_max'], temp['temp1_max_hyst']) - + print(temp['label']) + print("temp1\t %+.1f C (high = %+.1f C, hyst = %+.1f C)" % + (temp['temp1_input'], temp['temp1_max'], temp['temp1_max_hyst'])) def dump_sysfs(self): return pddf_obj.cli_dump_dsysfs('temp-sensors') diff --git a/device/dell/x86_64-dell_s6000_s1220-r0/platform_reboot b/device/dell/x86_64-dell_s6000_s1220-r0/platform_reboot index dc6e3d517a84..d973f4f810e1 100755 --- a/device/dell/x86_64-dell_s6000_s1220-r0/platform_reboot +++ b/device/dell/x86_64-dell_s6000_s1220-r0/platform_reboot @@ -1,23 +1,25 @@ -#!/usr/bin/python +#!/usr/bin/python3 + import sys import os import struct NVRAM_RES = '/dev/nvram' -COLD_RESET = 0xE # Cold Reset -WARM_RESET = 0x6 # Warm Reset +COLD_RESET = 0xE # Cold Reset +WARM_RESET = 0x6 # Warm Reset + def io_reg_write(resource, offset, val): fd = os.open(resource, os.O_RDWR) if(fd < 0): - print 'file open failed %s" % resource' + print('file open failed %s" % resource') return if(os.lseek(fd, offset, os.SEEK_SET) != offset): - print 'lseek failed on %s' % resource + print('lseek failed on %s' % resource) return ret = os.write(fd, struct.pack('B', val)) if(ret != 1): - print 'write failed %d' % ret + print('write failed %d' % ret) return os.close(fd) @@ -27,18 +29,21 @@ def power_reset(val): p.write(str(int(val)) + '\n') p.flush() -def gpio_direction(pin,direction): + +def gpio_direction(pin, direction): kernpath = '/sys/class/gpio/gpio'+str(pin)+'/direction' with open(('kernpath'), 'w') as p: p.write(str(direction) + '\n') p.flush() -def gpio_set(pin,value): + +def gpio_set(pin, value): kernpath = '/sys/class/gpio/gpio'+str(pin)+'/value' with open(('kernpath'), 'w') as p: p.write(str(int(value)) + '\n') p.flush() + def gpio_export(value): with open('/sys/class/gpio/export', 'w') as p: p.write(str(int(value)) + '\n') @@ -49,8 +54,8 @@ if __name__ == "__main__": io_reg_write(NVRAM_RES, 0x49, COLD_RESET) if not os.path.isdir("/sys/class/gpio/gpio10"): gpio_export(10) - gpio_direction("10","out") - #Toggle GPIO10 pin (to reset MUX) - gpio_set("10",1) - gpio_set("10",0) + gpio_direction("10", "out") + # Toggle GPIO10 pin (to reset MUX) + gpio_set("10", 1) + gpio_set("10", 0) power_reset(1) diff --git a/device/dell/x86_64-dell_s6000_s1220-r0/plugins/eeprom.py b/device/dell/x86_64-dell_s6000_s1220-r0/plugins/eeprom.py index 10364c2c9f8e..dc16fde7d770 100644 --- a/device/dell/x86_64-dell_s6000_s1220-r0/plugins/eeprom.py +++ b/device/dell/x86_64-dell_s6000_s1220-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Dell S6000 # diff --git a/device/dell/x86_64-dell_s6000_s1220-r0/plugins/psuutil.py b/device/dell/x86_64-dell_s6000_s1220-r0/plugins/psuutil.py index 537605f3975b..16318bca8162 100644 --- a/device/dell/x86_64-dell_s6000_s1220-r0/plugins/psuutil.py +++ b/device/dell/x86_64-dell_s6000_s1220-r0/plugins/psuutil.py @@ -21,7 +21,7 @@ def __init__(self): def get_cpld_register(self, reg_name): cpld_dir = "/sys/devices/platform/dell-s6000-cpld.0" retval = 'ERR' - reg_file = cpld_dir +'/' + reg_name + reg_file = cpld_dir + '/' + reg_name if (not os.path.isfile(reg_file)): return retval diff --git a/device/dell/x86_64-dell_s6000_s1220-r0/plugins/sfputil.py b/device/dell/x86_64-dell_s6000_s1220-r0/plugins/sfputil.py index b27bf4bc22ea..f03415cbc7ea 100644 --- a/device/dell/x86_64-dell_s6000_s1220-r0/plugins/sfputil.py +++ b/device/dell/x86_64-dell_s6000_s1220-r0/plugins/sfputil.py @@ -33,7 +33,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(0, self.PORTS_IN_BLOCK + 1) + return list(range(0, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -46,7 +46,7 @@ def get_transceiver_status(self): reg_file = open("/sys/devices/platform/dell-s6000-cpld.0/qsfp_modprs") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -55,7 +55,6 @@ def get_transceiver_status(self): return int(content, 16) - def __init__(self): eeprom_path = "/sys/class/i2c-adapter/i2c-{0}/{0}-0050/eeprom" @@ -76,7 +75,7 @@ def get_presence(self, port_num): try: reg_file = open("/sys/devices/platform/dell-s6000-cpld.0/qsfp_modprs") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -101,7 +100,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open("/sys/devices/platform/dell-s6000-cpld.0/qsfp_lpmode") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) content = reg_file.readline().rstrip() @@ -125,7 +124,7 @@ def set_low_power_mode(self, port_num, lpmode): try: reg_file = open("/sys/devices/platform/dell-s6000-cpld.0/qsfp_lpmode", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -161,7 +160,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -187,7 +186,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_value | mask @@ -207,17 +206,17 @@ def get_transceiver_change_event(self, timeout=0): if timeout == 0: forever = True elif timeout > 0: - timeout = timeout / float(1000) # Convert to secs + timeout = timeout / float(1000) # Convert to secs else: - print "get_transceiver_change_event:Invalid timeout value", timeout + print("get_transceiver_change_event:Invalid timeout value", timeout) return False, {} end_time = start_time + timeout if start_time > end_time: - print 'get_transceiver_change_event:' \ - 'time wrap / invalid timeout value', timeout + print('get_transceiver_change_event:' + 'time wrap / invalid timeout value', timeout) - return False, {} # Time wrap or possibly incorrect timeout + return False, {} # Time wrap or possibly incorrect timeout while timeout >= 0: # Check for OIR events and return updated port_dict @@ -247,10 +246,10 @@ def get_transceiver_change_event(self, timeout=0): else: timeout = end_time - time.time() if timeout >= 1: - time.sleep(1) # We poll at 1 second granularity + time.sleep(1) # We poll at 1 second granularity else: if timeout > 0: time.sleep(timeout) return True, {} - print "get_transceiver_change_event: Should not reach here." + print("get_transceiver_change_event: Should not reach here.") return False, {} diff --git a/device/dell/x86_64-dell_s6100_c2538-r0/plugins/eeprom.py b/device/dell/x86_64-dell_s6100_c2538-r0/plugins/eeprom.py index 46706fe5c9aa..e77f08fe873d 100644 --- a/device/dell/x86_64-dell_s6100_c2538-r0/plugins/eeprom.py +++ b/device/dell/x86_64-dell_s6100_c2538-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Dell S6100 # @@ -30,4 +28,4 @@ def serial_number_str(self, e): # 'results' is a list containing 3 elements, type (int), length (int), # and value (string) of the requested TLV - return results[2] + return results[2] diff --git a/device/dell/x86_64-dell_s6100_c2538-r0/plugins/psuutil.py b/device/dell/x86_64-dell_s6100_c2538-r0/plugins/psuutil.py index 2f3673801526..a29d45f939bf 100644 --- a/device/dell/x86_64-dell_s6100_c2538-r0/plugins/psuutil.py +++ b/device/dell/x86_64-dell_s6100_c2538-r0/plugins/psuutil.py @@ -14,6 +14,7 @@ HWMON_DIR = "/sys/devices/platform/SMF.512/hwmon/" HWMON_NODE = os.listdir(HWMON_DIR)[0] + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" @@ -26,7 +27,7 @@ def get_pmc_register(self, reg_name): retval = 'ERR' mb_reg_file = mailbox_dir+'/' + reg_name if (not os.path.isfile(mb_reg_file)): - logging.error(mb_reg_file, "not found !") + logging.error(mb_reg_file + " not found !") return retval try: @@ -60,7 +61,7 @@ def get_psu_status(self, index): psu_status = int(psu_status, 16) # Check for PSU statuse if (~psu_status & 0b1000) or (psu_status & 0b0100): - status = 1 + status = 1 return status @@ -77,6 +78,6 @@ def get_psu_presence(self, index): psu_presence = int(psu_presence, 16) # Check for PSU presence if (~psu_presence & 0b1): - status = 1 + status = 1 return status diff --git a/device/dell/x86_64-dell_s6100_c2538-r0/plugins/sfputil.py b/device/dell/x86_64-dell_s6100_c2538-r0/plugins/sfputil.py index ff4426ba10c2..a6a7cce72f56 100644 --- a/device/dell/x86_64-dell_s6100_c2538-r0/plugins/sfputil.py +++ b/device/dell/x86_64-dell_s6100_c2538-r0/plugins/sfputil.py @@ -31,70 +31,70 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} _port_to_i2c_mapping = { - 0: [6, 18, 34, 50, 66], - 1: [6, 19, 35, 51, 67], - 2: [6, 20, 36, 52, 68], - 3: [6, 21, 37, 53, 69], - 4: [6, 22, 38, 54, 70], - 5: [6, 23, 39, 55, 71], - 6: [6, 24, 40, 56, 72], - 7: [6, 25, 41, 57, 73], - 8: [6, 26, 42, 58, 74], - 9: [6, 27, 43, 59, 75], - 10: [6, 28, 44, 60, 76], - 11: [6, 29, 45, 61, 77], - 12: [6, 30, 46, 62, 78], - 13: [6, 31, 47, 63, 79], - 14: [6, 32, 48, 64, 80], - 15: [6, 33, 49, 65, 81], - 16: [8, 18, 34, 50, 66], - 17: [8, 19, 35, 51, 67], - 18: [8, 20, 36, 52, 68], - 19: [8, 21, 37, 53, 69], - 20: [8, 22, 38, 54, 70], - 21: [8, 23, 39, 55, 71], - 22: [8, 24, 40, 56, 72], - 23: [8, 25, 41, 57, 73], - 24: [8, 26, 42, 58, 74], - 25: [8, 27, 43, 59, 75], - 26: [8, 28, 44, 60, 76], - 27: [8, 29, 45, 61, 77], - 28: [8, 30, 46, 62, 78], - 29: [8, 31, 47, 63, 79], - 30: [8, 32, 48, 64, 80], - 31: [8, 33, 49, 65, 81], - 32: [7, 18, 34, 50, 66], - 33: [7, 19, 35, 51, 67], - 34: [7, 20, 36, 52, 68], - 35: [7, 21, 37, 53, 69], - 36: [7, 22, 38, 54, 70], - 37: [7, 23, 39, 55, 71], - 38: [7, 24, 40, 56, 72], - 39: [7, 25, 41, 57, 73], - 40: [7, 26, 42, 58, 74], - 41: [7, 27, 43, 59, 75], - 42: [7, 28, 44, 60, 76], - 43: [7, 29, 45, 61, 77], - 44: [7, 30, 46, 62, 78], - 45: [7, 31, 47, 63, 79], - 46: [7, 32, 48, 64, 80], - 47: [7, 33, 49, 65, 81], - 48: [9, 18, 34, 50, 66], - 49: [9, 19, 35, 51, 67], - 50: [9, 20, 36, 52, 68], - 51: [9, 21, 37, 53, 69], - 52: [9, 22, 38, 54, 70], - 53: [9, 23, 39, 55, 71], - 54: [9, 24, 40, 56, 72], - 55: [9, 25, 41, 57, 73], - 56: [9, 26, 42, 58, 74], - 57: [9, 27, 43, 59, 75], - 58: [9, 28, 44, 60, 76], - 59: [9, 29, 45, 61, 77], - 60: [9, 30, 46, 62, 78], - 61: [9, 31, 47, 63, 79], - 62: [9, 32, 48, 64, 80], - 63: [9, 33, 49, 65, 81] + 0: [6, 18, 34, 50, 66], + 1: [6, 19, 35, 51, 67], + 2: [6, 20, 36, 52, 68], + 3: [6, 21, 37, 53, 69], + 4: [6, 22, 38, 54, 70], + 5: [6, 23, 39, 55, 71], + 6: [6, 24, 40, 56, 72], + 7: [6, 25, 41, 57, 73], + 8: [6, 26, 42, 58, 74], + 9: [6, 27, 43, 59, 75], + 10: [6, 28, 44, 60, 76], + 11: [6, 29, 45, 61, 77], + 12: [6, 30, 46, 62, 78], + 13: [6, 31, 47, 63, 79], + 14: [6, 32, 48, 64, 80], + 15: [6, 33, 49, 65, 81], + 16: [8, 18, 34, 50, 66], + 17: [8, 19, 35, 51, 67], + 18: [8, 20, 36, 52, 68], + 19: [8, 21, 37, 53, 69], + 20: [8, 22, 38, 54, 70], + 21: [8, 23, 39, 55, 71], + 22: [8, 24, 40, 56, 72], + 23: [8, 25, 41, 57, 73], + 24: [8, 26, 42, 58, 74], + 25: [8, 27, 43, 59, 75], + 26: [8, 28, 44, 60, 76], + 27: [8, 29, 45, 61, 77], + 28: [8, 30, 46, 62, 78], + 29: [8, 31, 47, 63, 79], + 30: [8, 32, 48, 64, 80], + 31: [8, 33, 49, 65, 81], + 32: [7, 18, 34, 50, 66], + 33: [7, 19, 35, 51, 67], + 34: [7, 20, 36, 52, 68], + 35: [7, 21, 37, 53, 69], + 36: [7, 22, 38, 54, 70], + 37: [7, 23, 39, 55, 71], + 38: [7, 24, 40, 56, 72], + 39: [7, 25, 41, 57, 73], + 40: [7, 26, 42, 58, 74], + 41: [7, 27, 43, 59, 75], + 42: [7, 28, 44, 60, 76], + 43: [7, 29, 45, 61, 77], + 44: [7, 30, 46, 62, 78], + 45: [7, 31, 47, 63, 79], + 46: [7, 32, 48, 64, 80], + 47: [7, 33, 49, 65, 81], + 48: [9, 18, 34, 50, 66], + 49: [9, 19, 35, 51, 67], + 50: [9, 20, 36, 52, 68], + 51: [9, 21, 37, 53, 69], + 52: [9, 22, 38, 54, 70], + 53: [9, 23, 39, 55, 71], + 54: [9, 24, 40, 56, 72], + 55: [9, 25, 41, 57, 73], + 56: [9, 26, 42, 58, 74], + 57: [9, 27, 43, 59, 75], + 58: [9, 28, 44, 60, 76], + 59: [9, 29, 45, 61, 77], + 60: [9, 30, 46, 62, 78], + 61: [9, 31, 47, 63, 79], + 62: [9, 32, 48, 64, 80], + 63: [9, 33, 49, 65, 81] } IOM_1_PORT_START = 0 @@ -125,7 +125,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(0, self.PORTS_IN_BLOCK + 1) + return list(range(0, self.PORTS_IN_BLOCK + 1)) @property def iom1_port_start(self): @@ -172,69 +172,69 @@ def __init__(self): global port_to_eeprom_path for port_num in range(0, self.port_end + 1): - if port_num >= self.iom1_port_start and port_num <=\ - self.iom1_port_end: - assigned = 0 - # i2c-6 - for x in range(1, 5): - port_to_eeprom_path = eeprom_path.format( - self.port_to_i2c_mapping[port_num][0], - self.port_to_i2c_mapping[port_num][x]) - if (os.path.isfile(port_to_eeprom_path)): - self.port_to_eeprom_mapping[port_num] =\ - port_to_eeprom_path - assigned = 1 - elif (not assigned): - self.port_to_eeprom_mapping[port_num] =\ - "No IOM" - - elif(port_num >= self.iom2_port_start and - port_num <= self.iom2_port_end): - assigned = 0 - # i2c-8 - for x in range(1, 5): - port_to_eeprom_path = eeprom_path.format( - self.port_to_i2c_mapping[port_num][0], - self.port_to_i2c_mapping[port_num][x]) - if (os.path.isfile(port_to_eeprom_path)): - self.port_to_eeprom_mapping[port_num] =\ - port_to_eeprom_path - assigned = 1 - elif (not assigned): - self.port_to_eeprom_mapping[port_num] =\ - "No IOM" - - elif(port_num >= self.iom3_port_start and port_num <= - self.iom3_port_end): - assigned = 0 - # i2c-7 - for x in range(1, 5): - port_to_eeprom_path = eeprom_path.format( - self.port_to_i2c_mapping[port_num][0], - self.port_to_i2c_mapping[port_num][x]) - if (os.path.isfile(port_to_eeprom_path)): - self.port_to_eeprom_mapping[port_num] =\ - port_to_eeprom_path - assigned = 1 - elif (not assigned): - self.port_to_eeprom_mapping[port_num] =\ - "No IOM" - - elif(port_num >= self.iom4_port_start and port_num <= - self.iom4_port_end): - assigned = 0 - # i2c-9 - for x in range(1, 5): - port_to_eeprom_path = eeprom_path.format( - self.port_to_i2c_mapping[port_num][0], - self.port_to_i2c_mapping[port_num][x]) - if (os.path.isfile(port_to_eeprom_path)): - self.port_to_eeprom_mapping[port_num] =\ - port_to_eeprom_path - assigned = 1 - elif (not assigned): - self.port_to_eeprom_mapping[port_num] =\ - "No IOM" + if port_num >= self.iom1_port_start and port_num <=\ + self.iom1_port_end: + assigned = 0 + # i2c-6 + for x in range(1, 5): + port_to_eeprom_path = eeprom_path.format( + self.port_to_i2c_mapping[port_num][0], + self.port_to_i2c_mapping[port_num][x]) + if (os.path.isfile(port_to_eeprom_path)): + self.port_to_eeprom_mapping[port_num] =\ + port_to_eeprom_path + assigned = 1 + elif (not assigned): + self.port_to_eeprom_mapping[port_num] =\ + "No IOM" + + elif(port_num >= self.iom2_port_start and + port_num <= self.iom2_port_end): + assigned = 0 + # i2c-8 + for x in range(1, 5): + port_to_eeprom_path = eeprom_path.format( + self.port_to_i2c_mapping[port_num][0], + self.port_to_i2c_mapping[port_num][x]) + if (os.path.isfile(port_to_eeprom_path)): + self.port_to_eeprom_mapping[port_num] =\ + port_to_eeprom_path + assigned = 1 + elif (not assigned): + self.port_to_eeprom_mapping[port_num] =\ + "No IOM" + + elif(port_num >= self.iom3_port_start and port_num <= + self.iom3_port_end): + assigned = 0 + # i2c-7 + for x in range(1, 5): + port_to_eeprom_path = eeprom_path.format( + self.port_to_i2c_mapping[port_num][0], + self.port_to_i2c_mapping[port_num][x]) + if (os.path.isfile(port_to_eeprom_path)): + self.port_to_eeprom_mapping[port_num] =\ + port_to_eeprom_path + assigned = 1 + elif (not assigned): + self.port_to_eeprom_mapping[port_num] =\ + "No IOM" + + elif(port_num >= self.iom4_port_start and port_num <= + self.iom4_port_end): + assigned = 0 + # i2c-9 + for x in range(1, 5): + port_to_eeprom_path = eeprom_path.format( + self.port_to_i2c_mapping[port_num][0], + self.port_to_i2c_mapping[port_num][x]) + if (os.path.isfile(port_to_eeprom_path)): + self.port_to_eeprom_mapping[port_num] =\ + port_to_eeprom_path + assigned = 1 + elif (not assigned): + self.port_to_eeprom_mapping[port_num] =\ + "No IOM" SfpUtilBase.__init__(self) @@ -267,11 +267,11 @@ def get_presence(self, port_num): i2c_line = 17 try: - qsfp_path = self.BASE_VAL_PATH.format(i2c_line)+"qsfp_modprs" - reg_file = open(qsfp_path, "r") + qsfp_path = self.BASE_VAL_PATH.format(i2c_line)+"qsfp_modprs" + reg_file = open(qsfp_path, "r") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -316,11 +316,11 @@ def get_low_power_mode(self, port_num): i2c_line = 17 try: - qsfp_path = self.BASE_VAL_PATH.format(i2c_line)+"qsfp_lpmode" - reg_file = open(qsfp_path, "r") + qsfp_path = self.BASE_VAL_PATH.format(i2c_line)+"qsfp_lpmode" + reg_file = open(qsfp_path, "r") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -365,11 +365,11 @@ def set_low_power_mode(self, port_num, lpmode): i2c_line = 17 try: - qsfp_path = self.BASE_VAL_PATH.format(i2c_line)+"qsfp_lpmode" - reg_file = open(qsfp_path, "r+") + qsfp_path = self.BASE_VAL_PATH.format(i2c_line)+"qsfp_lpmode" + reg_file = open(qsfp_path, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -426,11 +426,11 @@ def reset(self, port_num): i2c_line = 17 try: - qsfp_path = self.BASE_VAL_PATH.format(i2c_line)+"qsfp_lpmode" - reg_file = open(qsfp_path, "r+") + qsfp_path = self.BASE_VAL_PATH.format(i2c_line)+"qsfp_lpmode" + reg_file = open(qsfp_path, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -465,11 +465,11 @@ def reset(self, port_num): # Flip the bit back high and write back to the register to take port # out of reset try: - qsfp_path = self.BASE_VAL_PATH.format(i2c_line)+"qsfp_lpmode" - reg_file = open(qsfp_path, "w") + qsfp_path = self.BASE_VAL_PATH.format(i2c_line)+"qsfp_lpmode" + reg_file = open(qsfp_path, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_value | mask @@ -480,158 +480,157 @@ def reset(self, port_num): return True def get_register(self, reg_file): - retval = 'ERR' + retval = 'ERR' - if (not os.path.isfile(reg_file)): - print reg_file, 'not found !' - return retval + if (not os.path.isfile(reg_file)): + print(reg_file + ' not found !') + return retval - try: - with open(reg_file, 'r') as fd: - retval = fd.read() - except Exception as error: - logging.error("Unable to open ", reg_file, "file !") + try: + with open(reg_file, 'r') as fd: + retval = fd.read() + except Exception as error: + logging.error("Unable to open ", reg_file, "file !") - retval = retval.rstrip('\r\n') - retval = retval.lstrip(" ") - return retval + retval = retval.rstrip('\r\n') + retval = retval.lstrip(" ") + return retval def check_interrupts(self, port_dict): - retval = 0 - is_port_dict_updated = False - - # Read the QSFP ABS interrupt & status registers - cpld2_abs_int = self.get_register( - "/sys/class/i2c-adapter/i2c-14/14-003e/qsfp_abs_int") - cpld2_abs_sta = self.get_register( - "/sys/class/i2c-adapter/i2c-14/14-003e/qsfp_abs_sta") - cpld3_abs_int = self.get_register( - "/sys/class/i2c-adapter/i2c-15/15-003e/qsfp_abs_int") - cpld3_abs_sta = self.get_register( - "/sys/class/i2c-adapter/i2c-15/15-003e/qsfp_abs_sta") - cpld4_abs_int = self.get_register( - "/sys/class/i2c-adapter/i2c-16/16-003e/qsfp_abs_int") - cpld4_abs_sta = self.get_register( - "/sys/class/i2c-adapter/i2c-16/16-003e/qsfp_abs_sta") - cpld5_abs_int = self.get_register( - "/sys/class/i2c-adapter/i2c-17/17-003e/qsfp_abs_int") - cpld5_abs_sta = self.get_register( - "/sys/class/i2c-adapter/i2c-17/17-003e/qsfp_abs_sta") - - if (cpld2_abs_int == 'ERR' or cpld2_abs_sta == 'ERR' or - cpld3_abs_int == 'ERR' or cpld3_abs_sta == 'ERR' or - cpld4_abs_int == 'ERR' or cpld4_abs_sta == 'ERR' or - cpld5_abs_int == 'ERR' or cpld5_abs_sta == 'ERR'): - return -1 - - # If IOM is not present, interrupt will return 'read error' - # Handle the scenario gracefully - if (cpld2_abs_int == 'read error'): - cpld2_abs_int = "0x0" - cpld2_abs_sta = "0x0" - if (cpld3_abs_int == 'read error'): - cpld3_abs_int = "0x0" - cpld3_abs_sta = "0x0" - if (cpld4_abs_int == 'read error'): - cpld4_abs_int = "0x0" - cpld4_abs_sta = "0x0" - if (cpld5_abs_int == 'read error'): - cpld5_abs_int = "0x0" - cpld5_abs_sta = "0x0" - - cpld2_abs_int = int(cpld2_abs_int, 16) - cpld2_abs_sta = int(cpld2_abs_sta, 16) - cpld3_abs_int = int(cpld3_abs_int, 16) - cpld3_abs_sta = int(cpld3_abs_sta, 16) - cpld4_abs_int = int(cpld4_abs_int, 16) - cpld4_abs_sta = int(cpld4_abs_sta, 16) - cpld5_abs_int = int(cpld5_abs_int, 16) - cpld5_abs_sta = int(cpld5_abs_sta, 16) - - # Make it contiguous - interrupt_reg = (cpld2_abs_int & 0xffff) | \ - ((cpld4_abs_int & 0xffff) << 16) | \ - ((cpld3_abs_int & 0xffff) << 32) | \ - ((cpld5_abs_int & 0xffff) << 48) - status_reg = (cpld2_abs_sta & 0xffff) | \ - ((cpld4_abs_sta & 0xffff) << 16) | \ - ((cpld3_abs_sta & 0xffff) << 32) | \ - ((cpld5_abs_sta & 0xffff) << 48) - - port = self.port_start - while port <= self.port_end: - if interrupt_reg & (1 << port): - # update only if atleast one port has generated - # interrupt - is_port_dict_updated = True - if status_reg & (1 << port): - # status reg 1 => optics is removed - port_dict[port] = '0' - else: - # status reg 0 => optics is inserted - port_dict[port] = '1' - port += 1 - return retval, is_port_dict_updated + retval = 0 + is_port_dict_updated = False + + # Read the QSFP ABS interrupt & status registers + cpld2_abs_int = self.get_register( + "/sys/class/i2c-adapter/i2c-14/14-003e/qsfp_abs_int") + cpld2_abs_sta = self.get_register( + "/sys/class/i2c-adapter/i2c-14/14-003e/qsfp_abs_sta") + cpld3_abs_int = self.get_register( + "/sys/class/i2c-adapter/i2c-15/15-003e/qsfp_abs_int") + cpld3_abs_sta = self.get_register( + "/sys/class/i2c-adapter/i2c-15/15-003e/qsfp_abs_sta") + cpld4_abs_int = self.get_register( + "/sys/class/i2c-adapter/i2c-16/16-003e/qsfp_abs_int") + cpld4_abs_sta = self.get_register( + "/sys/class/i2c-adapter/i2c-16/16-003e/qsfp_abs_sta") + cpld5_abs_int = self.get_register( + "/sys/class/i2c-adapter/i2c-17/17-003e/qsfp_abs_int") + cpld5_abs_sta = self.get_register( + "/sys/class/i2c-adapter/i2c-17/17-003e/qsfp_abs_sta") + + if (cpld2_abs_int == 'ERR' or cpld2_abs_sta == 'ERR' or + cpld3_abs_int == 'ERR' or cpld3_abs_sta == 'ERR' or + cpld4_abs_int == 'ERR' or cpld4_abs_sta == 'ERR' or + cpld5_abs_int == 'ERR' or cpld5_abs_sta == 'ERR'): + return -1 + + # If IOM is not present, interrupt will return 'read error' + # Handle the scenario gracefully + if (cpld2_abs_int == 'read error'): + cpld2_abs_int = "0x0" + cpld2_abs_sta = "0x0" + if (cpld3_abs_int == 'read error'): + cpld3_abs_int = "0x0" + cpld3_abs_sta = "0x0" + if (cpld4_abs_int == 'read error'): + cpld4_abs_int = "0x0" + cpld4_abs_sta = "0x0" + if (cpld5_abs_int == 'read error'): + cpld5_abs_int = "0x0" + cpld5_abs_sta = "0x0" + + cpld2_abs_int = int(cpld2_abs_int, 16) + cpld2_abs_sta = int(cpld2_abs_sta, 16) + cpld3_abs_int = int(cpld3_abs_int, 16) + cpld3_abs_sta = int(cpld3_abs_sta, 16) + cpld4_abs_int = int(cpld4_abs_int, 16) + cpld4_abs_sta = int(cpld4_abs_sta, 16) + cpld5_abs_int = int(cpld5_abs_int, 16) + cpld5_abs_sta = int(cpld5_abs_sta, 16) + + # Make it contiguous + interrupt_reg = (cpld2_abs_int & 0xffff) | \ + ((cpld4_abs_int & 0xffff) << 16) | \ + ((cpld3_abs_int & 0xffff) << 32) | \ + ((cpld5_abs_int & 0xffff) << 48) + status_reg = (cpld2_abs_sta & 0xffff) | \ + ((cpld4_abs_sta & 0xffff) << 16) | \ + ((cpld3_abs_sta & 0xffff) << 32) | \ + ((cpld5_abs_sta & 0xffff) << 48) + + port = self.port_start + while port <= self.port_end: + if interrupt_reg & (1 << port): + # update only if atleast one port has generated + # interrupt + is_port_dict_updated = True + if status_reg & (1 << port): + # status reg 1 => optics is removed + port_dict[port] = '0' + else: + # status reg 0 => optics is inserted + port_dict[port] = '1' + port += 1 + return retval, is_port_dict_updated def get_transceiver_change_event(self, timeout=0): - port_dict = {} - try: - # We get notified when there is an SCI interrupt from GPIO SUS6 - # Open the sysfs file and register the epoll object - self.oir_fd = open(self.OIR_FD_PATH, "r") - if self.oir_fd != -1: - # Do a dummy read before epoll register - self.oir_fd.read() - self.epoll = select.epoll() - self.epoll.register(self.oir_fd.fileno(), - select.EPOLLIN & select.EPOLLET) - else: - print("get_transceiver_change_event : unable to create fd") - return False, {} + port_dict = {} + try: + # We get notified when there is an SCI interrupt from GPIO SUS6 + # Open the sysfs file and register the epoll object + self.oir_fd = open(self.OIR_FD_PATH, "r") + if self.oir_fd != -1: + # Do a dummy read before epoll register + self.oir_fd.read() + self.epoll = select.epoll() + self.epoll.register(self.oir_fd.fileno(), + select.EPOLLIN & select.EPOLLET) + else: + print("get_transceiver_change_event : unable to create fd") + return False, {} - # Check for missed interrupts by invoking self.check_interrupts - # which will update the port_dict. - while True: - interrupt_count_start = self.get_register(self.OIR_FD_PATH) + # Check for missed interrupts by invoking self.check_interrupts + # which will update the port_dict. + while True: + interrupt_count_start = self.get_register(self.OIR_FD_PATH) - retval, is_port_dict_updated = \ - self.check_interrupts(port_dict) - if ((retval == 0) and (is_port_dict_updated is True)): - return True, port_dict + retval, is_port_dict_updated = \ + self.check_interrupts(port_dict) + if ((retval == 0) and (is_port_dict_updated is True)): + return True, port_dict - interrupt_count_end = self.get_register(self.OIR_FD_PATH) + interrupt_count_end = self.get_register(self.OIR_FD_PATH) - if (interrupt_count_start == 'ERR' or - interrupt_count_end == 'ERR'): - print("get_transceiver_change_event : \ + if (interrupt_count_start == 'ERR' or + interrupt_count_end == 'ERR'): + print("get_transceiver_change_event : \ unable to retrive interrupt count") - break - - # check_interrupts() itself may take upto 100s of msecs. - # We detect a missed interrupt based on the count - if interrupt_count_start == interrupt_count_end: - break - - # Block until an xcvr is inserted or removed with timeout = -1 - events = self.epoll.poll( - timeout=timeout if timeout != 0 else -1) - if events: - # check interrupts and return the port_dict - retval, is_port_dict_updated = \ - self.check_interrupts(port_dict) - if (retval != 0): - return False, {} - - return True, port_dict - except: - return False, {} - finally: - if self.oir_fd != -1: - self.epoll.unregister(self.oir_fd.fileno()) - self.epoll.close() - self.oir_fd.close() - self.oir_fd = -1 - self.epoll = -1 + break + + # check_interrupts() itself may take upto 100s of msecs. + # We detect a missed interrupt based on the count + if interrupt_count_start == interrupt_count_end: + break + + # Block until an xcvr is inserted or removed with timeout = -1 + events = self.epoll.poll( + timeout=timeout if timeout != 0 else -1) + if events: + # check interrupts and return the port_dict + retval, is_port_dict_updated = \ + self.check_interrupts(port_dict) + if (retval != 0): + return False, {} + return True, port_dict + except: return False, {} - + finally: + if self.oir_fd != -1: + self.epoll.unregister(self.oir_fd.fileno()) + self.epoll.close() + self.oir_fd.close() + self.oir_fd = -1 + self.epoll = -1 + + return False, {} diff --git a/device/dell/x86_64-dell_z9100_c2538-r0/plugins/eeprom.py b/device/dell/x86_64-dell_z9100_c2538-r0/plugins/eeprom.py index d447748ad114..eca797ee7637 100644 --- a/device/dell/x86_64-dell_z9100_c2538-r0/plugins/eeprom.py +++ b/device/dell/x86_64-dell_z9100_c2538-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Dell Z9100 # diff --git a/device/dell/x86_64-dell_z9100_c2538-r0/plugins/psuutil.py b/device/dell/x86_64-dell_z9100_c2538-r0/plugins/psuutil.py index f96fac6f46cf..d6eed4a5a7c1 100644 --- a/device/dell/x86_64-dell_z9100_c2538-r0/plugins/psuutil.py +++ b/device/dell/x86_64-dell_z9100_c2538-r0/plugins/psuutil.py @@ -14,6 +14,7 @@ HWMON_DIR = "/sys/devices/platform/SMF.512/hwmon/" HWMON_NODE = os.listdir(HWMON_DIR)[0] + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" @@ -26,7 +27,7 @@ def get_pmc_register(self, reg_name): retval = 'ERR' mb_reg_file = mailbox_dir+'/' + reg_name if (not os.path.isfile(mb_reg_file)): - logging.error(mb_reg_file, "not found !") + logging.error(mb_reg_file + " not found !") return retval try: @@ -60,7 +61,7 @@ def get_psu_status(self, index): psu_status = int(psu_status, 16) # Check for PSU statuse if (~psu_status & 0b1000) or (psu_status & 0b0100): - status = 1 + status = 1 return status @@ -77,6 +78,6 @@ def get_psu_presence(self, index): psu_presence = int(psu_presence, 16) # Check for PSU presence if (~psu_presence & 0b1): - status = 1 + status = 1 return status diff --git a/device/dell/x86_64-dell_z9100_c2538-r0/plugins/sfputil.py b/device/dell/x86_64-dell_z9100_c2538-r0/plugins/sfputil.py index 98c01216902d..16b5192522e3 100644 --- a/device/dell/x86_64-dell_z9100_c2538-r0/plugins/sfputil.py +++ b/device/dell/x86_64-dell_z9100_c2538-r0/plugins/sfputil.py @@ -33,40 +33,40 @@ class SfpUtil(SfpUtilBase): epoll = -1 _port_to_eeprom_mapping = {} _port_to_i2c_mapping = { - 0: [0, 00], # Dummy Entry - 1: [9, 18], - 2: [9, 19], - 3: [9, 20], - 4: [9, 21], - 5: [9, 22], - 6: [9, 23], - 7: [9, 24], - 8: [9, 25], - 9: [8, 26], - 10: [8, 27], - 11: [8, 28], - 12: [8, 29], - 13: [8, 31], # reordered - 14: [8, 30], - 15: [8, 33], # reordered - 16: [8, 32], - 17: [7, 34], - 18: [7, 35], - 19: [7, 36], - 20: [7, 37], - 21: [7, 38], - 22: [7, 39], - 23: [7, 40], - 24: [7, 41], - 25: [6, 42], - 26: [6, 43], - 27: [6, 44], - 28: [6, 45], - 29: [6, 46], - 30: [6, 47], - 31: [6, 48], - 32: [6, 49] - } + 0: [0, 00], # Dummy Entry + 1: [9, 18], + 2: [9, 19], + 3: [9, 20], + 4: [9, 21], + 5: [9, 22], + 6: [9, 23], + 7: [9, 24], + 8: [9, 25], + 9: [8, 26], + 10: [8, 27], + 11: [8, 28], + 12: [8, 29], + 13: [8, 31], # reordered + 14: [8, 30], + 15: [8, 33], # reordered + 16: [8, 32], + 17: [7, 34], + 18: [7, 35], + 19: [7, 36], + 20: [7, 37], + 21: [7, 38], + 22: [7, 39], + 23: [7, 40], + 24: [7, 41], + 25: [6, 42], + 26: [6, 43], + 27: [6, 44], + 28: [6, 45], + 29: [6, 46], + 30: [6, 47], + 31: [6, 48], + 32: [6, 49] + } @property def port_start(self): @@ -78,7 +78,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(self.PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.PORT_START, self.PORTS_IN_BLOCK + 1)) @property def iom1_port_start(self): @@ -124,9 +124,9 @@ def __init__(self): def __del__(self): if self.oir_fd != -1: - self.epoll.unregister(self.oir_fd.fileno()) - self.epoll.close() - self.oir_fd.close() + self.epoll.unregister(self.oir_fd.fileno()) + self.epoll.close() + self.oir_fd.close() def normalize_port(self, port_num): # Check for invalid port_num @@ -153,7 +153,6 @@ def normalize_port(self, port_num): return i2c_line, port_num - def get_presence(self, port_num): i2c_line, port_num = self.normalize_port(port_num) @@ -165,7 +164,7 @@ def get_presence(self, port_num): reg_file = open(qsfp_path, "r") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -193,11 +192,11 @@ def get_low_power_mode(self, port_num): return False try: - qsfp_path = self.BASE_VAL_PATH.format(i2c_line)+"qsfp_lpmode" - reg_file = open(qsfp_path, "r") + qsfp_path = self.BASE_VAL_PATH.format(i2c_line)+"qsfp_lpmode" + reg_file = open(qsfp_path, "r") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -225,12 +224,11 @@ def set_low_power_mode(self, port_num, lpmode): return False try: - qsfp_path = self.BASE_VAL_PATH.format(i2c_line)+"qsfp_lpmode" - reg_file = open(qsfp_path, "r+") - + qsfp_path = self.BASE_VAL_PATH.format(i2c_line)+"qsfp_lpmode" + reg_file = open(qsfp_path, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -266,11 +264,11 @@ def reset(self, port_num): return False try: - qsfp_path = self.BASE_VAL_PATH.format(i2c_line)+"qsfp_lpmode" - reg_file = open(qsfp_path, "r+") + qsfp_path = self.BASE_VAL_PATH.format(i2c_line)+"qsfp_lpmode" + reg_file = open(qsfp_path, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -295,11 +293,11 @@ def reset(self, port_num): # Flip the bit back high and write back to the register to take # port out of reset try: - qsfp_path = self.BASE_VAL_PATH.format(i2c_line)+"qsfp_lpmode" - reg_file = open(qsfp_path, "w+") + qsfp_path = self.BASE_VAL_PATH.format(i2c_line)+"qsfp_lpmode" + reg_file = open(qsfp_path, "w+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_value | mask @@ -310,133 +308,132 @@ def reset(self, port_num): return True def get_register(self, reg_file): - retval = 'ERR' + retval = 'ERR' - if (not os.path.isfile(reg_file)): - print reg_file, 'not found !' - return retval + if (not os.path.isfile(reg_file)): + print(reg_file + ' not found !') + return retval - try: - with open(reg_file, 'r') as fd: - retval = fd.read() - except Exception as error: - logging.error("Unable to open ", reg_file, "file !") + try: + with open(reg_file, 'r') as fd: + retval = fd.read() + except Exception as error: + logging.error("Unable to open ", reg_file, "file !") - retval = retval.rstrip('\r\n') - retval = retval.lstrip(" ") - return retval + retval = retval.rstrip('\r\n') + retval = retval.lstrip(" ") + return retval def check_interrupts(self, port_dict): - retval = 0 - is_port_dict_updated = False - # Read the QSFP ABS interrupt & status registers - cpld2_abs_int = self.get_register( - "/sys/class/i2c-adapter/i2c-14/14-003e/qsfp_abs_int") - cpld2_abs_sta = self.get_register( - "/sys/class/i2c-adapter/i2c-14/14-003e/qsfp_abs_sta") - cpld3_abs_int = self.get_register( - "/sys/class/i2c-adapter/i2c-15/15-003e/qsfp_abs_int") - cpld3_abs_sta = self.get_register( - "/sys/class/i2c-adapter/i2c-15/15-003e/qsfp_abs_sta") - cpld4_abs_int = self.get_register( - "/sys/class/i2c-adapter/i2c-16/16-003e/qsfp_abs_int") - cpld4_abs_sta = self.get_register( - "/sys/class/i2c-adapter/i2c-16/16-003e/qsfp_abs_sta") - - if (cpld2_abs_int == 'ERR' or cpld2_abs_sta == 'ERR' or - cpld3_abs_int == 'ERR' or cpld3_abs_sta == 'ERR' or - cpld4_abs_int == 'ERR' or cpld4_abs_sta == 'ERR'): - return -1 - - cpld2_abs_int = int(cpld2_abs_int, 16) - cpld2_abs_sta = int(cpld2_abs_sta, 16) - cpld3_abs_int = int(cpld3_abs_int, 16) - cpld3_abs_sta = int(cpld3_abs_sta, 16) - cpld4_abs_int = int(cpld4_abs_int, 16) - cpld4_abs_sta = int(cpld4_abs_sta, 16) - - # Make it contiguous (discard reserved bits) - interrupt_reg = (cpld2_abs_int & 0xfff) |\ - ((cpld3_abs_int & 0x3ff) << 12) |\ - ((cpld4_abs_int & 0x3ff) << 22) - status_reg = (cpld2_abs_sta & 0xfff) |\ - ((cpld3_abs_sta & 0x3ff) << 12) |\ - ((cpld4_abs_sta & 0x3ff) << 22) - - port = self.port_start - while port <= self.port_end: - if interrupt_reg & (1 << (port-1)): - # update only if atleast one port has generated - # interrupt - is_port_dict_updated = True - if status_reg & (1 << (port-1)): - # status reg 1 => optics is removed - port_dict[port] = '0' - else: - # status reg 0 => optics is inserted - port_dict[port] = '1' - port += 1 - return retval, is_port_dict_updated + retval = 0 + is_port_dict_updated = False + # Read the QSFP ABS interrupt & status registers + cpld2_abs_int = self.get_register( + "/sys/class/i2c-adapter/i2c-14/14-003e/qsfp_abs_int") + cpld2_abs_sta = self.get_register( + "/sys/class/i2c-adapter/i2c-14/14-003e/qsfp_abs_sta") + cpld3_abs_int = self.get_register( + "/sys/class/i2c-adapter/i2c-15/15-003e/qsfp_abs_int") + cpld3_abs_sta = self.get_register( + "/sys/class/i2c-adapter/i2c-15/15-003e/qsfp_abs_sta") + cpld4_abs_int = self.get_register( + "/sys/class/i2c-adapter/i2c-16/16-003e/qsfp_abs_int") + cpld4_abs_sta = self.get_register( + "/sys/class/i2c-adapter/i2c-16/16-003e/qsfp_abs_sta") + + if (cpld2_abs_int == 'ERR' or cpld2_abs_sta == 'ERR' or + cpld3_abs_int == 'ERR' or cpld3_abs_sta == 'ERR' or + cpld4_abs_int == 'ERR' or cpld4_abs_sta == 'ERR'): + return -1 + + cpld2_abs_int = int(cpld2_abs_int, 16) + cpld2_abs_sta = int(cpld2_abs_sta, 16) + cpld3_abs_int = int(cpld3_abs_int, 16) + cpld3_abs_sta = int(cpld3_abs_sta, 16) + cpld4_abs_int = int(cpld4_abs_int, 16) + cpld4_abs_sta = int(cpld4_abs_sta, 16) + + # Make it contiguous (discard reserved bits) + interrupt_reg = (cpld2_abs_int & 0xfff) |\ + ((cpld3_abs_int & 0x3ff) << 12) |\ + ((cpld4_abs_int & 0x3ff) << 22) + status_reg = (cpld2_abs_sta & 0xfff) |\ + ((cpld3_abs_sta & 0x3ff) << 12) |\ + ((cpld4_abs_sta & 0x3ff) << 22) + + port = self.port_start + while port <= self.port_end: + if interrupt_reg & (1 << (port-1)): + # update only if atleast one port has generated + # interrupt + is_port_dict_updated = True + if status_reg & (1 << (port-1)): + # status reg 1 => optics is removed + port_dict[port] = '0' + else: + # status reg 0 => optics is inserted + port_dict[port] = '1' + port += 1 + return retval, is_port_dict_updated def get_transceiver_change_event(self, timeout=0): - port_dict = {} - try: - # We get notified when there is an SCI interrupt from GPIO SUS6 - # Open the sysfs file and register the epoll object - self.oir_fd = open(self.OIR_FD_PATH, "r") - if self.oir_fd != -1: - # Do a dummy read before epoll register - self.oir_fd.read() - self.epoll = select.epoll() - self.epoll.register(self.oir_fd.fileno(), - select.EPOLLIN & select.EPOLLET) - else: - print("get_transceiver_change_event : unable to create fd") - return False, {} + port_dict = {} + try: + # We get notified when there is an SCI interrupt from GPIO SUS6 + # Open the sysfs file and register the epoll object + self.oir_fd = open(self.OIR_FD_PATH, "r") + if self.oir_fd != -1: + # Do a dummy read before epoll register + self.oir_fd.read() + self.epoll = select.epoll() + self.epoll.register(self.oir_fd.fileno(), + select.EPOLLIN & select.EPOLLET) + else: + print("get_transceiver_change_event : unable to create fd") + return False, {} - # Check for missed interrupts by invoking self.check_interrupts - # which will update the port_dict. - while True: - interrupt_count_start = self.get_register(self.OIR_FD_PATH) + # Check for missed interrupts by invoking self.check_interrupts + # which will update the port_dict. + while True: + interrupt_count_start = self.get_register(self.OIR_FD_PATH) - retval, is_port_dict_updated = \ - self.check_interrupts(port_dict) - if ((retval == 0) and (is_port_dict_updated is True)): - return True, port_dict + retval, is_port_dict_updated = \ + self.check_interrupts(port_dict) + if ((retval == 0) and (is_port_dict_updated is True)): + return True, port_dict - interrupt_count_end = self.get_register(self.OIR_FD_PATH) + interrupt_count_end = self.get_register(self.OIR_FD_PATH) - if (interrupt_count_start == 'ERR' or - interrupt_count_end == 'ERR'): - print("get_transceiver_change_event : \ + if (interrupt_count_start == 'ERR' or + interrupt_count_end == 'ERR'): + print("get_transceiver_change_event : \ unable to retrive interrupt count") - break - - # check_interrupts() itself may take upto 100s of msecs. - # We detect a missed interrupt based on the count - if interrupt_count_start == interrupt_count_end: - break - - # Block until an xcvr is inserted or removed with timeout = -1 - events = self.epoll.poll( - timeout=timeout if timeout != 0 else -1) - if events: - # check interrupts and return the port_dict - retval, is_port_dict_updated = \ - self.check_interrupts(port_dict) - if (retval != 0): - return False, {} - - return True, port_dict - except: - return False, {} - finally: - if self.oir_fd != -1: - self.epoll.unregister(self.oir_fd.fileno()) - self.epoll.close() - self.oir_fd.close() - self.oir_fd = -1 - self.epoll = -1 + break + + # check_interrupts() itself may take upto 100s of msecs. + # We detect a missed interrupt based on the count + if interrupt_count_start == interrupt_count_end: + break + + # Block until an xcvr is inserted or removed with timeout = -1 + events = self.epoll.poll( + timeout=timeout if timeout != 0 else -1) + if events: + # check interrupts and return the port_dict + retval, is_port_dict_updated = \ + self.check_interrupts(port_dict) + if (retval != 0): + return False, {} + return True, port_dict + except: return False, {} + finally: + if self.oir_fd != -1: + self.epoll.unregister(self.oir_fd.fileno()) + self.epoll.close() + self.oir_fd.close() + self.oir_fd = -1 + self.epoll = -1 + return False, {} diff --git a/device/dell/x86_64-dellemc_s5232f_c3538-r0/plugins/eeprom.py b/device/dell/x86_64-dellemc_s5232f_c3538-r0/plugins/eeprom.py index 18e3b61318db..2374ceb790c5 100644 --- a/device/dell/x86_64-dellemc_s5232f_c3538-r0/plugins/eeprom.py +++ b/device/dell/x86_64-dellemc_s5232f_c3538-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # DellEMC S5232f # diff --git a/device/dell/x86_64-dellemc_s5232f_c3538-r0/plugins/psuutil.py b/device/dell/x86_64-dellemc_s5232f_c3538-r0/plugins/psuutil.py index c3e2a6d73bd0..27042e3122b4 100644 --- a/device/dell/x86_64-dellemc_s5232f_c3538-r0/plugins/psuutil.py +++ b/device/dell/x86_64-dellemc_s5232f_c3538-r0/plugins/psuutil.py @@ -6,9 +6,13 @@ import os.path import logging -import commands import sys +if sys.version_info[0] < 3: + import commands +else: + import subprocess as commands + S5232F_MAX_PSUS = 2 IPMI_PSU1_DATA = "docker exec -it pmon ipmitool raw 0x04 0x2d 0x31 | awk '{print substr($0,9,1)}'" @@ -47,15 +51,15 @@ def get_pmc_register(self, reg_name): ipmi_cmd_2 = IPMI_PSU1_DATA dockerenv = self.isDockerEnv() if dockerenv == True: - if index == 1: - status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA_DOCKER) - elif index == 2: - status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA_DOCKER) + if index == 1: + status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA_DOCKER) + elif index == 2: + status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA_DOCKER) else: - if index == 1: - status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA) - elif index == 2: - status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA) + if index == 1: + status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA) + elif index == 2: + status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA) if status: logging.error('Failed to execute ipmitool') @@ -87,15 +91,15 @@ def get_psu_status(self, index): ret_status = 1 dockerenv = self.isDockerEnv() if dockerenv == True: - if index == 1: - ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA_DOCKER) - elif index == 2: - ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA_DOCKER) + if index == 1: + ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA_DOCKER) + elif index == 2: + ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA_DOCKER) else: - if index == 1: - ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA) - elif index == 2: - ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA) + if index == 1: + ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA) + elif index == 2: + ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA) if ret_status: logging.error('Failed to execute ipmitool : ') @@ -115,15 +119,15 @@ def get_psu_presence(self, index): ret_status = 1 dockerenv = self.isDockerEnv() if dockerenv == True: - if index == 1: - ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA_DOCKER) - elif index == 2: - ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA_DOCKER) + if index == 1: + ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA_DOCKER) + elif index == 2: + ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA_DOCKER) else: - if index == 1: - ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA) - elif index == 2: - ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA) + if index == 1: + ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA) + elif index == 2: + ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA) if ret_status: logging.error('Failed to execute ipmitool : ') diff --git a/device/dell/x86_64-dellemc_s5232f_c3538-r0/plugins/sfputil.py b/device/dell/x86_64-dellemc_s5232f_c3538-r0/plugins/sfputil.py index b5b1408ef9b1..f53e8e944d1e 100644 --- a/device/dell/x86_64-dellemc_s5232f_c3538-r0/plugins/sfputil.py +++ b/device/dell/x86_64-dellemc_s5232f_c3538-r0/plugins/sfputil.py @@ -45,11 +45,12 @@ XCVR_DOM_CAPABILITY_OFFSET = 92 XCVR_DOM_CAPABILITY_WIDTH = 1 + class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" PORT_START = 1 - PORT_END = 34 + PORT_END = 34 PORTS_IN_BLOCK = 32 BASE_RES_PATH = "/sys/bus/pci/devices/0000:04:00.0/resource0" @@ -68,7 +69,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(self.PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -76,8 +77,8 @@ def port_to_eeprom_mapping(self): def pci_mem_read(self, mm, offset): mm.seek(offset) - read_data_stream=mm.read(4) - reg_val=struct.unpack('I',read_data_stream) + read_data_stream = mm.read(4) + reg_val = struct.unpack('I', read_data_stream) mem_val = str(reg_val)[1:-2] # print "reg_val read:%x"%reg_val return mem_val @@ -85,7 +86,7 @@ def pci_mem_read(self, mm, offset): def pci_mem_write(self, mm, offset, data): mm.seek(offset) # print "data to write:%x"%data - mm.write(struct.pack('I',data)) + mm.write(struct.pack('I', data)) def pci_set_value(self, resource, val, offset): fd = open(resource, O_RDWR) @@ -102,7 +103,7 @@ def pci_get_value(self, resource, offset): mm.close() close(fd) return val - + def init_global_port_presence(self): for port_num in range(self.port_start, (self.port_end + 1)): presence = self.get_presence(port_num) @@ -110,17 +111,17 @@ def init_global_port_presence(self): self._global_port_pres_dict[port_num] = '1' else: self._global_port_pres_dict[port_num] = '0' - + def __init__(self): eeprom_path = "/sys/class/i2c-adapter/i2c-{0}/{0}-0050/eeprom" for x in range(self.port_start, self.port_end + 1): - port_num = x + 1 + port_num = x + 1 self.port_to_eeprom_mapping[x] = eeprom_path.format( - port_num) + port_num) port_num = 0 self.init_global_port_presence() - + SfpUtilBase.__init__(self) def get_presence(self, port_num): @@ -129,13 +130,13 @@ def get_presence(self, port_num): return False # Port offset starts with 0x4004 - port_offset = 16388 + ((port_num-1) * 16) + port_offset = 16388 + ((port_num-1) * 16) + + status = self.pci_get_value(self.BASE_RES_PATH, port_offset) + reg_value = int(status) - status = self.pci_get_value(self.BASE_RES_PATH, port_offset) - reg_value = int(status) - # Absence of status throws error - if (reg_value == "" ): + if (reg_value == ""): return False # Mask off 4th bit for presence @@ -143,8 +144,7 @@ def get_presence(self, port_num): # Mask off 1st bit for presence 33,34 if (port_num > 32): - mask = (1 << 0) - + mask = (1 << 0) # ModPrsL is active low if reg_value & mask == 0: @@ -158,14 +158,14 @@ def get_low_power_mode(self, port_num): if port_num < self.port_start or port_num > self.port_end: return False - # Port offset starts with 0x4000 - port_offset = 16384 + ((port_num-1) * 16) + # Port offset starts with 0x4000 + port_offset = 16384 + ((port_num-1) * 16) - status = self.pci_get_value(self.BASE_RES_PATH, port_offset) - reg_value = int(status) + status = self.pci_get_value(self.BASE_RES_PATH, port_offset) + reg_value = int(status) # Absence of status throws error - if (reg_value == "" ): + if (reg_value == ""): return False # Mask off 4th bit for presence @@ -183,44 +183,44 @@ def set_low_power_mode(self, port_num, lpmode): if port_num < self.port_start or port_num > self.port_end: return False - # Port offset starts with 0x4000 - port_offset = 16384 + ((port_num-1) * 16) + # Port offset starts with 0x4000 + port_offset = 16384 + ((port_num-1) * 16) - status = self.pci_get_value(self.BASE_RES_PATH, port_offset) - reg_value = int(status) + status = self.pci_get_value(self.BASE_RES_PATH, port_offset) + reg_value = int(status) # Absence of status throws error - if (reg_value == "" ): + if (reg_value == ""): return False # Mask off 6th bit for lpmode mask = (1 << 6) - - # LPMode is active high; set or clear the bit accordingly + + # LPMode is active high; set or clear the bit accordingly if lpmode is True: reg_value = reg_value | mask else: reg_value = reg_value & ~mask # Convert our register value back to a hex string and write back - status = self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset) + status = self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset) return True def reset(self, port_num): - # Check for invalid port_num + # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False - # Port offset starts with 0x4000 - port_offset = 16384 + ((port_num-1) * 16) + # Port offset starts with 0x4000 + port_offset = 16384 + ((port_num-1) * 16) - status = self.pci_get_value(self.BASE_RES_PATH, port_offset) - reg_value = int(status) + status = self.pci_get_value(self.BASE_RES_PATH, port_offset) + reg_value = int(status) # Absence of status throws error - if (reg_value == "" ): + if (reg_value == ""): return False # Mask off 4th bit for presence @@ -229,16 +229,16 @@ def reset(self, port_num): # ResetL is active low reg_value = reg_value & ~mask - # Convert our register value back to a hex string and write back - status = self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset) + # Convert our register value back to a hex string and write back + status = self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset) # Sleep 1 second to allow it to settle time.sleep(1) reg_value = reg_value | mask - # Convert our register value back to a hex string and write back - status = self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset) + # Convert our register value back to a hex string and write back + status = self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset) return True @@ -268,9 +268,8 @@ def get_transceiver_change_event(self, timeout=0): if elapsed_time_ms > timeout: break time.sleep(sleep_time) - - return True, port_dict + return True, port_dict def get_transceiver_dom_info_dict(self, port_num): transceiver_dom_info_dict = {} @@ -280,13 +279,14 @@ def get_transceiver_dom_info_dict(self, port_num): 'tx1bias', 'tx2bias', 'tx3bias', 'tx4bias', 'tx1power', 'tx2power', 'tx3power', 'tx4power', - ] + ] transceiver_dom_info_dict = dict.fromkeys(dom_info_dict_keys, 'N/A') if port_num in self.qsfp_ports: offset = 0 offset_xcvr = 128 - file_path = self._get_port_eeprom_path(port_num, self.IDENTITY_EEPROM_ADDR) + file_path = self._get_port_eeprom_path( + port_num, self.IDENTITY_EEPROM_ADDR) if not self._sfp_eeprom_present(file_path, 0): return None @@ -308,27 +308,34 @@ def get_transceiver_dom_info_dict(self, port_num): # TODO: in the future when decided to migrate to support SFF-8636 instead of SFF-8436, # need to add more code for determining the capability and version compliance # in SFF-8636 dom capability definitions evolving with the versions. - qsfp_dom_capability_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset_xcvr + XCVR_DOM_CAPABILITY_OFFSET), XCVR_DOM_CAPABILITY_WIDTH) + qsfp_dom_capability_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset_xcvr + XCVR_DOM_CAPABILITY_OFFSET), XCVR_DOM_CAPABILITY_WIDTH) if qsfp_dom_capability_raw is not None: - qspf_dom_capability_data = sfpi_obj.parse_qsfp_dom_capability(qsfp_dom_capability_raw, 0) + qspf_dom_capability_data = sfpi_obj.parse_qsfp_dom_capability( + qsfp_dom_capability_raw, 0) else: return transceiver_dom_info_dict - dom_temperature_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + QSFP_TEMPE_OFFSET), QSFP_TEMPE_WIDTH) + dom_temperature_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + QSFP_TEMPE_OFFSET), QSFP_TEMPE_WIDTH) if dom_temperature_raw is not None: - dom_temperature_data = sfpd_obj.parse_temperature(dom_temperature_raw, 0) + dom_temperature_data = sfpd_obj.parse_temperature( + dom_temperature_raw, 0) else: return transceiver_dom_info_dict - dom_voltage_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + QSFP_VOLT_OFFSET), QSFP_VOLT_WIDTH) + dom_voltage_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + QSFP_VOLT_OFFSET), QSFP_VOLT_WIDTH) if dom_voltage_raw is not None: dom_voltage_data = sfpd_obj.parse_voltage(dom_voltage_raw, 0) else: return transceiver_dom_info_dict - qsfp_dom_rev_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + QSFP_DOM_REV_OFFSET), QSFP_DOM_REV_WIDTH) + qsfp_dom_rev_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + QSFP_DOM_REV_OFFSET), QSFP_DOM_REV_WIDTH) if qsfp_dom_rev_raw is not None: - qsfp_dom_rev_data = sfpd_obj.parse_sfp_dom_rev(qsfp_dom_rev_raw, 0) + qsfp_dom_rev_data = sfpd_obj.parse_sfp_dom_rev( + qsfp_dom_rev_raw, 0) else: return transceiver_dom_info_dict @@ -341,9 +348,11 @@ def get_transceiver_dom_info_dict(self, port_num): 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) + 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) + dom_channel_monitor_data = sfpd_obj.parse_channel_monitor_params( + dom_channel_monitor_raw, 0) else: return transceiver_dom_info_dict @@ -352,9 +361,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 @@ -381,47 +392,50 @@ def get_transceiver_dom_info_dict(self, port_num): transceiver_dom_info_dict['tx4bias'] = dom_channel_monitor_data['data']['TX4Bias']['value'] else: - offset = 256 - file_path = self._get_port_eeprom_path(port_num, self.DOM_EEPROM_ADDR) - if not self._sfp_eeprom_present(file_path, 0): - return None + offset = 256 + file_path = self._get_port_eeprom_path( + port_num, self.DOM_EEPROM_ADDR) + if not self._sfp_eeprom_present(file_path, 0): + return None try: - sysfsfile_eeprom = io.open(file_path,"rb",0) + sysfsfile_eeprom = io.open(file_path, "rb", 0) except IOError: - print("Error: reading sysfs file %s" % file_path) - return None - - sfpd_obj = sff8472Dom(None,1) + print("Error: reading sysfs file %s" % file_path) + return None + + sfpd_obj = sff8472Dom(None, 1) if sfpd_obj is None: return transceiver_dom_info_dict - 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) + dom_temperature_data = sfpd_obj.parse_temperature( + dom_temperature_raw, 0) else: - return transceiver_dom_info_dict + return transceiver_dom_info_dict - dom_voltage_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_VOLT_OFFSET), - SFP_VOLT_WIDTH) + dom_voltage_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_VOLT_OFFSET), + SFP_VOLT_WIDTH) if dom_voltage_raw is not None: - dom_voltage_data = sfpd_obj.parse_voltage(dom_voltage_raw, 0) - else: - return transceiver_dom_info_dict + dom_voltage_data = sfpd_obj.parse_voltage(dom_voltage_raw, 0) + else: + return transceiver_dom_info_dict - dom_channel_monitor_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_MODULE_THRESHOLD_OFFSET), - SFP_MODULE_THRESHOLD_WIDTH) + dom_channel_monitor_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_MODULE_THRESHOLD_OFFSET), + SFP_MODULE_THRESHOLD_WIDTH) if dom_channel_monitor_raw is not None: - dom_channel_monitor_data = sfpd_obj.parse_channel_monitor_params(dom_channel_monitor_raw, 0) + dom_channel_monitor_data = sfpd_obj.parse_channel_monitor_params( + dom_channel_monitor_raw, 0) else: - return transceiver_dom_info_dict + return transceiver_dom_info_dict try: - sysfsfile_eeprom.close() + sysfsfile_eeprom.close() except IOError: - print("Error: closing sysfs file %s" % file_path) - return None + print("Error: closing sysfs file %s" % file_path) + return None transceiver_dom_info_dict['temperature'] = dom_temperature_data['data']['Temperature']['value'] transceiver_dom_info_dict['voltage'] = dom_voltage_data['data']['Vcc']['value'] @@ -438,8 +452,8 @@ def get_transceiver_dom_info_dict(self, port_num): transceiver_dom_info_dict['tx3power'] = 'N/A' transceiver_dom_info_dict['tx4power'] = 'N/A' - return transceiver_dom_info_dict - + return transceiver_dom_info_dict + def get_transceiver_dom_threshold_info_dict(self, port_num): transceiver_dom_threshold_info_dict = {} dom_info_dict_keys = ['temphighalarm', 'temphighwarning', @@ -452,11 +466,13 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): 'txpowerlowalarm', 'txpowerlowwarning', 'txbiashighalarm', 'txbiashighwarning', 'txbiaslowalarm', 'txbiaslowwarning' - ] - transceiver_dom_threshold_info_dict = dict.fromkeys(dom_info_dict_keys, 'N/A') + ] + transceiver_dom_threshold_info_dict = dict.fromkeys( + dom_info_dict_keys, 'N/A') if port_num in self.qsfp_ports: - file_path = self._get_port_eeprom_path(port_num, self.IDENTITY_EEPROM_ADDR) + file_path = self._get_port_eeprom_path( + port_num, self.IDENTITY_EEPROM_ADDR) if not self._sfp_eeprom_present(file_path, 0): return None @@ -474,20 +490,22 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): # Revert offset back to 0 once data is retrieved offset = 384 dom_module_threshold_raw = self._read_eeprom_specific_bytes( - sysfsfile_eeprom, - (offset + QSFP_MODULE_THRESHOLD_OFFSET), - QSFP_MODULE_THRESHOLD_WIDTH) + sysfsfile_eeprom, + (offset + QSFP_MODULE_THRESHOLD_OFFSET), + QSFP_MODULE_THRESHOLD_WIDTH) if dom_module_threshold_raw is not None: - dom_module_threshold_data = sfpd_obj.parse_module_threshold_values(dom_module_threshold_raw, 0) + dom_module_threshold_data = sfpd_obj.parse_module_threshold_values( + dom_module_threshold_raw, 0) else: return transceiver_dom_threshold_info_dict dom_channel_threshold_raw = self._read_eeprom_specific_bytes( - sysfsfile_eeprom, - (offset + QSFP_CHANNL_THRESHOLD_OFFSET), - QSFP_CHANNL_THRESHOLD_WIDTH) + sysfsfile_eeprom, + (offset + QSFP_CHANNL_THRESHOLD_OFFSET), + QSFP_CHANNL_THRESHOLD_WIDTH) if dom_channel_threshold_raw is not None: - dom_channel_threshold_data = sfpd_obj.parse_channel_threshold_values(dom_channel_threshold_raw, 0) + dom_channel_threshold_data = sfpd_obj.parse_channel_threshold_values( + dom_channel_threshold_raw, 0) else: return transceiver_dom_threshold_info_dict @@ -517,25 +535,27 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): else: offset = 256 - file_path = self._get_port_eeprom_path(port_num, self.DOM_EEPROM_ADDR) + file_path = self._get_port_eeprom_path( + port_num, self.DOM_EEPROM_ADDR) if not self._sfp_eeprom_present(file_path, 0): return None try: - sysfsfile_eeprom = io.open(file_path,"rb",0) + sysfsfile_eeprom = io.open(file_path, "rb", 0) except IOError: print("Error: reading sysfs file %s" % file_path) return None - - sfpd_obj = sff8472Dom(None,1) + + sfpd_obj = sff8472Dom(None, 1) if sfpd_obj is None: return transceiver_dom_threshold_info_dict - - dom_module_threshold_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, - (offset + SFP_MODULE_THRESHOLD_OFFSET), SFP_MODULE_THRESHOLD_WIDTH) - + + dom_module_threshold_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, + (offset + SFP_MODULE_THRESHOLD_OFFSET), SFP_MODULE_THRESHOLD_WIDTH) + if dom_module_threshold_raw is not None: - dom_module_threshold_data = sfpd_obj.parse_alarm_warning_threshold(dom_module_threshold_raw, 0) + dom_module_threshold_data = sfpd_obj.parse_alarm_warning_threshold( + dom_module_threshold_raw, 0) else: return transceiver_dom_threshold_info_dict @@ -545,14 +565,15 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): print("Error: closing sysfs file %s" % file_path) return None - #Threshold Data + # Threshold Data transceiver_dom_threshold_info_dict['temphighalarm'] = dom_module_threshold_data['data']['TempHighAlarm']['value'] transceiver_dom_threshold_info_dict['templowalarm'] = dom_module_threshold_data['data']['TempLowAlarm']['value'] transceiver_dom_threshold_info_dict['temphighwarning'] = dom_module_threshold_data['data']['TempHighWarning']['value'] transceiver_dom_threshold_info_dict['templowwarning'] = dom_module_threshold_data['data']['TempLowWarning']['value'] transceiver_dom_threshold_info_dict['vcchighalarm'] = dom_module_threshold_data['data']['VoltageHighAlarm']['value'] transceiver_dom_threshold_info_dict['vcclowalarm'] = dom_module_threshold_data['data']['VoltageLowAlarm']['value'] - transceiver_dom_threshold_info_dict['vcchighwarning'] = dom_module_threshold_data['data']['VoltageHighWarning']['value'] + transceiver_dom_threshold_info_dict['vcchighwarning'] = dom_module_threshold_data[ + 'data']['VoltageHighWarning']['value'] transceiver_dom_threshold_info_dict['vcclowwarning'] = dom_module_threshold_data['data']['VoltageLowWarning']['value'] transceiver_dom_threshold_info_dict['txbiashighalarm'] = dom_module_threshold_data['data']['BiasHighAlarm']['value'] transceiver_dom_threshold_info_dict['txbiaslowalarm'] = dom_module_threshold_data['data']['BiasLowAlarm']['value'] @@ -566,5 +587,5 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): transceiver_dom_threshold_info_dict['rxpowerlowalarm'] = dom_module_threshold_data['data']['RXPowerLowAlarm']['value'] transceiver_dom_threshold_info_dict['rxpowerhighwarning'] = dom_module_threshold_data['data']['RXPowerHighWarning']['value'] transceiver_dom_threshold_info_dict['rxpowerlowwarning'] = dom_module_threshold_data['data']['RXPowerLowWarning']['value'] - + return transceiver_dom_threshold_info_dict diff --git a/device/dell/x86_64-dellemc_s5248f_c3538-r0/plugins/eeprom.py b/device/dell/x86_64-dellemc_s5248f_c3538-r0/plugins/eeprom.py index 8b115e20c3a0..dc7eeb330215 100644 --- a/device/dell/x86_64-dellemc_s5248f_c3538-r0/plugins/eeprom.py +++ b/device/dell/x86_64-dellemc_s5248f_c3538-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # DellEMC S5248f # diff --git a/device/dell/x86_64-dellemc_s5248f_c3538-r0/plugins/psuutil.py b/device/dell/x86_64-dellemc_s5248f_c3538-r0/plugins/psuutil.py index 8004697d7c0a..9cd186611486 100644 --- a/device/dell/x86_64-dellemc_s5248f_c3538-r0/plugins/psuutil.py +++ b/device/dell/x86_64-dellemc_s5248f_c3538-r0/plugins/psuutil.py @@ -6,9 +6,13 @@ import os.path import logging -import commands import sys +if sys.version_info[0] < 3: + import commands +else: + import subprocess as commands + S5248F_MAX_PSUS = 2 IPMI_PSU_DATA = "docker exec -it pmon ipmitool sdr list" @@ -102,6 +106,5 @@ def get_psu_presence(self, index): if (psu_status != 'ERR'): # Check for PSU presence if (psu_status == 0x00): - status = 1 + status = 1 return status - diff --git a/device/dell/x86_64-dellemc_s5248f_c3538-r0/plugins/sfputil.py b/device/dell/x86_64-dellemc_s5248f_c3538-r0/plugins/sfputil.py index d9417fef8fbd..2b941d028968 100644 --- a/device/dell/x86_64-dellemc_s5248f_c3538-r0/plugins/sfputil.py +++ b/device/dell/x86_64-dellemc_s5248f_c3538-r0/plugins/sfputil.py @@ -21,7 +21,7 @@ except ImportError as e: raise ImportError("%s - required module not found" % str(e)) -#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 @@ -48,6 +48,7 @@ XCVR_DOM_CAPABILITY_OFFSET = 92 XCVR_DOM_CAPABILITY_WIDTH = 1 + class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" @@ -58,68 +59,67 @@ class SfpUtil(SfpUtilBase): BASE_RES_PATH = "/sys/bus/pci/devices/0000:04:00.0/resource0" _port_to_i2c_mapping = { - 1: 2, - 2: 3, - 3: 4, - 4: 5, - 5: 6, - 6: 7, - 7: 8, - 8: 9, - 9: 10, - 10: 11, - 11: 12, - 12: 13, - 13: 14, - 14: 15, - 15: 16, - 16: 17, - 17: 18, - 18: 19, - 19: 20, - 20: 21, - 21: 22, - 22: 23, - 23: 24, - 24: 25, - 25: 26, - 26: 27, - 27: 28, - 28: 29, - 29: 30, - 30: 31, - 31: 32, - 32: 33, - 33: 34, - 34: 35, - 35: 36, - 36: 37, - 37: 38, - 38: 39, - 39: 40, - 40: 41, - 41: 42, - 42: 43, - 43: 44, - 44: 45, - 45: 46, - 46: 47, - 47: 48, - 48: 49, - # DD + QSFP28 - 49: 50, - 50: 50, - 51: 51, - 52: 51, - 53: 52, - 54: 53, - 55: 54, - 56: 55, - } + 1: 2, + 2: 3, + 3: 4, + 4: 5, + 5: 6, + 6: 7, + 7: 8, + 8: 9, + 9: 10, + 10: 11, + 11: 12, + 12: 13, + 13: 14, + 14: 15, + 15: 16, + 16: 17, + 17: 18, + 18: 19, + 19: 20, + 20: 21, + 21: 22, + 22: 23, + 23: 24, + 24: 25, + 25: 26, + 26: 27, + 27: 28, + 28: 29, + 29: 30, + 30: 31, + 31: 32, + 32: 33, + 33: 34, + 34: 35, + 35: 36, + 36: 37, + 37: 38, + 38: 39, + 39: 40, + 40: 41, + 41: 42, + 42: 43, + 43: 44, + 44: 45, + 45: 46, + 46: 47, + 47: 48, + 48: 49, + # DD + QSFP28 + 49: 50, + 50: 50, + 51: 51, + 52: 51, + 53: 52, + 54: 53, + 55: 54, + 56: 55, + } _port_to_eeprom_mapping = {} - _global_port_pres_dict = {} @property @@ -132,7 +132,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(49, self.PORTS_IN_BLOCK + 1) + return list(range(49, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -140,8 +140,8 @@ def port_to_eeprom_mapping(self): def pci_mem_read(self, mm, offset): mm.seek(offset) - read_data_stream=mm.read(4) - reg_val=struct.unpack('I',read_data_stream) + read_data_stream = mm.read(4) + reg_val = struct.unpack('I', read_data_stream) mem_val = str(reg_val)[1:-2] # print "reg_val read:%x"%reg_val return mem_val @@ -149,7 +149,7 @@ def pci_mem_read(self, mm, offset): def pci_mem_write(self, mm, offset, data): mm.seek(offset) # print "data to write:%x"%data - mm.write(struct.pack('I',data)) + mm.write(struct.pack('I', data)) def pci_set_value(self, resource, val, offset): fd = open(resource, O_RDWR) @@ -166,7 +166,7 @@ def pci_get_value(self, resource, offset): mm.close() close(fd) return val - + def init_global_port_presence(self): for port_num in range(self.port_start, (self.port_end + 1)): presence = self.get_presence(port_num) @@ -174,13 +174,13 @@ def init_global_port_presence(self): self._global_port_pres_dict[port_num] = '1' else: self._global_port_pres_dict[port_num] = '0' - + def __init__(self): eeprom_path = "/sys/class/i2c-adapter/i2c-{0}/{0}-0050/eeprom" for x in range(self.port_start, self.port_end + 1): self.port_to_eeprom_mapping[x] = eeprom_path.format( - self._port_to_i2c_mapping[x]) + self._port_to_i2c_mapping[x]) self.init_global_port_presence() SfpUtilBase.__init__(self) @@ -190,13 +190,13 @@ def get_presence(self, port_num): return False # Port offset starts with 0x4004 - port_offset = 16388 + ((port_num-1) * 16) + port_offset = 16388 + ((port_num-1) * 16) + + status = self.pci_get_value(self.BASE_RES_PATH, port_offset) + reg_value = int(status) - status = self.pci_get_value(self.BASE_RES_PATH, port_offset) - reg_value = int(status) - # Absence of status throws error - if (reg_value == "" ): + if (reg_value == ""): return False # Mask off bit for presence @@ -204,7 +204,6 @@ def get_presence(self, port_num): if (port_num > 48): mask = (1 << 4) - # ModPrsL is active low if reg_value & mask == 0: return True @@ -217,14 +216,14 @@ def get_low_power_mode(self, port_num): if port_num < self.port_start or port_num > self.port_end: return False - # Port offset starts with 0x4000 - port_offset = 16384 + ((port_num-1) * 16) + # Port offset starts with 0x4000 + port_offset = 16384 + ((port_num-1) * 16) - status = self.pci_get_value(self.BASE_RES_PATH, port_offset) - reg_value = int(status) + status = self.pci_get_value(self.BASE_RES_PATH, port_offset) + reg_value = int(status) # Absence of status throws error - if (reg_value == "" ): + if (reg_value == ""): return False # Mask off 4th bit for presence @@ -242,44 +241,44 @@ def set_low_power_mode(self, port_num, lpmode): if port_num < self.port_start or port_num > self.port_end: return False - # Port offset starts with 0x4000 - port_offset = 16384 + ((port_num-1) * 16) + # Port offset starts with 0x4000 + port_offset = 16384 + ((port_num-1) * 16) - status = self.pci_get_value(self.BASE_RES_PATH, port_offset) - reg_value = int(status) + status = self.pci_get_value(self.BASE_RES_PATH, port_offset) + reg_value = int(status) # Absence of status throws error - if (reg_value == "" ): + if (reg_value == ""): return False # Mask off 6th bit for lpmode mask = (1 << 6) - - # LPMode is active high; set or clear the bit accordingly + + # LPMode is active high; set or clear the bit accordingly if lpmode is True: reg_value = reg_value | mask else: reg_value = reg_value & ~mask # Convert our register value back to a hex string and write back - status = self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset) + status = self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset) return True def reset(self, port_num): - # Check for invalid port_num + # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False - # Port offset starts with 0x4000 - port_offset = 16384 + ((port_num-1) * 16) + # Port offset starts with 0x4000 + port_offset = 16384 + ((port_num-1) * 16) - status = self.pci_get_value(self.BASE_RES_PATH, port_offset) - reg_value = int(status) + status = self.pci_get_value(self.BASE_RES_PATH, port_offset) + reg_value = int(status) # Absence of status throws error - if (reg_value == "" ): + if (reg_value == ""): return False # Mask off 4th bit for presence @@ -288,16 +287,16 @@ def reset(self, port_num): # ResetL is active low reg_value = reg_value & ~mask - # Convert our register value back to a hex string and write back - status = self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset) + # Convert our register value back to a hex string and write back + status = self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset) # Sleep 1 second to allow it to settle time.sleep(1) reg_value = reg_value | mask - # Convert our register value back to a hex string and write back - status = self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset) + # Convert our register value back to a hex string and write back + status = self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset) return True @@ -318,7 +317,7 @@ def get_transceiver_change_event(self, timeout=0): return True, port_dict time.sleep(0.5) - + def get_transceiver_dom_info_dict(self, port_num): transceiver_dom_info_dict = {} @@ -327,13 +326,14 @@ def get_transceiver_dom_info_dict(self, port_num): 'tx1bias', 'tx2bias', 'tx3bias', 'tx4bias', 'tx1power', 'tx2power', 'tx3power', 'tx4power', - ] + ] transceiver_dom_info_dict = dict.fromkeys(dom_info_dict_keys, 'N/A') if port_num in self.qsfp_ports: offset = 0 offset_xcvr = 128 - file_path = self._get_port_eeprom_path(port_num, self.IDENTITY_EEPROM_ADDR) + file_path = self._get_port_eeprom_path( + port_num, self.IDENTITY_EEPROM_ADDR) if not self._sfp_eeprom_present(file_path, 0): return None @@ -355,27 +355,34 @@ def get_transceiver_dom_info_dict(self, port_num): # TODO: in the future when decided to migrate to support SFF-8636 instead of SFF-8436, # need to add more code for determining the capability and version compliance # in SFF-8636 dom capability definitions evolving with the versions. - qsfp_dom_capability_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset_xcvr + XCVR_DOM_CAPABILITY_OFFSET), XCVR_DOM_CAPABILITY_WIDTH) + qsfp_dom_capability_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset_xcvr + XCVR_DOM_CAPABILITY_OFFSET), XCVR_DOM_CAPABILITY_WIDTH) if qsfp_dom_capability_raw is not None: - qspf_dom_capability_data = sfpi_obj.parse_qsfp_dom_capability(qsfp_dom_capability_raw, 0) + qspf_dom_capability_data = sfpi_obj.parse_qsfp_dom_capability( + qsfp_dom_capability_raw, 0) else: return transceiver_dom_info_dict - dom_temperature_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + QSFP_TEMPE_OFFSET), QSFP_TEMPE_WIDTH) + dom_temperature_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + QSFP_TEMPE_OFFSET), QSFP_TEMPE_WIDTH) if dom_temperature_raw is not None: - dom_temperature_data = sfpd_obj.parse_temperature(dom_temperature_raw, 0) + dom_temperature_data = sfpd_obj.parse_temperature( + dom_temperature_raw, 0) else: return transceiver_dom_info_dict - dom_voltage_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + QSFP_VOLT_OFFSET), QSFP_VOLT_WIDTH) + dom_voltage_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + QSFP_VOLT_OFFSET), QSFP_VOLT_WIDTH) if dom_voltage_raw is not None: dom_voltage_data = sfpd_obj.parse_voltage(dom_voltage_raw, 0) else: return transceiver_dom_info_dict - qsfp_dom_rev_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + QSFP_DOM_REV_OFFSET), QSFP_DOM_REV_WIDTH) + qsfp_dom_rev_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + QSFP_DOM_REV_OFFSET), QSFP_DOM_REV_WIDTH) if qsfp_dom_rev_raw is not None: - qsfp_dom_rev_data = sfpd_obj.parse_sfp_dom_rev(qsfp_dom_rev_raw, 0) + qsfp_dom_rev_data = sfpd_obj.parse_sfp_dom_rev( + qsfp_dom_rev_raw, 0) else: return transceiver_dom_info_dict @@ -388,9 +395,11 @@ def get_transceiver_dom_info_dict(self, port_num): 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) + 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) + dom_channel_monitor_data = sfpd_obj.parse_channel_monitor_params( + dom_channel_monitor_raw, 0) else: return transceiver_dom_info_dict @@ -399,9 +408,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 @@ -428,48 +439,51 @@ def get_transceiver_dom_info_dict(self, port_num): transceiver_dom_info_dict['tx4bias'] = dom_channel_monitor_data['data']['TX4Bias']['value'] else: - offset = 256 - file_path = self._get_port_eeprom_path(port_num, self.DOM_EEPROM_ADDR) - if not self._sfp_eeprom_present(file_path, 0): - return None + offset = 256 + file_path = self._get_port_eeprom_path( + port_num, self.DOM_EEPROM_ADDR) + if not self._sfp_eeprom_present(file_path, 0): + return None try: - sysfsfile_eeprom = io.open(file_path,"rb",0) + sysfsfile_eeprom = io.open(file_path, "rb", 0) except IOError: - print("Error: reading sysfs file %s" % file_path) - return None - - sfpd_obj = sff8472Dom(None,1) + print("Error: reading sysfs file %s" % file_path) + return None + + sfpd_obj = sff8472Dom(None, 1) if sfpd_obj is None: return transceiver_dom_info_dict dom_temperature_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_TEMPE_OFFSET), - SFP_TEMPE_WIDTH) - + SFP_TEMPE_WIDTH) + if dom_temperature_raw is not None: - dom_temperature_data = sfpd_obj.parse_temperature(dom_temperature_raw, 0) + dom_temperature_data = sfpd_obj.parse_temperature( + dom_temperature_raw, 0) else: return transceiver_dom_info_dict - dom_voltage_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_VOLT_OFFSET), - SFP_VOLT_WIDTH) + dom_voltage_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_VOLT_OFFSET), + SFP_VOLT_WIDTH) if dom_voltage_raw is not None: - dom_voltage_data = sfpd_obj.parse_voltage(dom_voltage_raw, 0) - else: - return transceiver_dom_info_dict + dom_voltage_data = sfpd_obj.parse_voltage(dom_voltage_raw, 0) + else: + return transceiver_dom_info_dict - dom_channel_monitor_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_MODULE_THRESHOLD_OFFSET), - SFP_MODULE_THRESHOLD_WIDTH) + dom_channel_monitor_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_MODULE_THRESHOLD_OFFSET), + SFP_MODULE_THRESHOLD_WIDTH) if dom_channel_monitor_raw is not None: - dom_channel_monitor_data = sfpd_obj.parse_channel_monitor_params(dom_channel_monitor_raw, 0) + dom_channel_monitor_data = sfpd_obj.parse_channel_monitor_params( + dom_channel_monitor_raw, 0) else: - return transceiver_dom_info_dict + return transceiver_dom_info_dict try: - sysfsfile_eeprom.close() + sysfsfile_eeprom.close() except IOError: - print("Error: closing sysfs file %s" % file_path) - return None + print("Error: closing sysfs file %s" % file_path) + return None transceiver_dom_info_dict['temperature'] = dom_temperature_data['data']['Temperature']['value'] transceiver_dom_info_dict['voltage'] = dom_voltage_data['data']['Vcc']['value'] @@ -486,8 +500,8 @@ def get_transceiver_dom_info_dict(self, port_num): transceiver_dom_info_dict['tx3power'] = 'N/A' transceiver_dom_info_dict['tx4power'] = 'N/A' - return transceiver_dom_info_dict - + return transceiver_dom_info_dict + def get_transceiver_dom_threshold_info_dict(self, port_num): transceiver_dom_threshold_info_dict = {} dom_info_dict_keys = ['temphighalarm', 'temphighwarning', @@ -500,11 +514,13 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): 'txpowerlowalarm', 'txpowerlowwarning', 'txbiashighalarm', 'txbiashighwarning', 'txbiaslowalarm', 'txbiaslowwarning' - ] - transceiver_dom_threshold_info_dict = dict.fromkeys(dom_info_dict_keys, 'N/A') + ] + transceiver_dom_threshold_info_dict = dict.fromkeys( + dom_info_dict_keys, 'N/A') if port_num in self.qsfp_ports: - file_path = self._get_port_eeprom_path(port_num, self.IDENTITY_EEPROM_ADDR) + file_path = self._get_port_eeprom_path( + port_num, self.IDENTITY_EEPROM_ADDR) if not self._sfp_eeprom_present(file_path, 0): return None @@ -522,20 +538,22 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): # Revert offset back to 0 once data is retrieved offset = 384 dom_module_threshold_raw = self._read_eeprom_specific_bytes( - sysfsfile_eeprom, - (offset + QSFP_MODULE_THRESHOLD_OFFSET), - QSFP_MODULE_THRESHOLD_WIDTH) + sysfsfile_eeprom, + (offset + QSFP_MODULE_THRESHOLD_OFFSET), + QSFP_MODULE_THRESHOLD_WIDTH) if dom_module_threshold_raw is not None: - dom_module_threshold_data = sfpd_obj.parse_module_threshold_values(dom_module_threshold_raw, 0) + dom_module_threshold_data = sfpd_obj.parse_module_threshold_values( + dom_module_threshold_raw, 0) else: return transceiver_dom_threshold_info_dict dom_channel_threshold_raw = self._read_eeprom_specific_bytes( - sysfsfile_eeprom, - (offset + QSFP_CHANNL_THRESHOLD_OFFSET), - QSFP_CHANNL_THRESHOLD_WIDTH) + sysfsfile_eeprom, + (offset + QSFP_CHANNL_THRESHOLD_OFFSET), + QSFP_CHANNL_THRESHOLD_WIDTH) if dom_channel_threshold_raw is not None: - dom_channel_threshold_data = sfpd_obj.parse_channel_threshold_values(dom_channel_threshold_raw, 0) + dom_channel_threshold_data = sfpd_obj.parse_channel_threshold_values( + dom_channel_threshold_raw, 0) else: return transceiver_dom_threshold_info_dict @@ -565,25 +583,27 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): else: offset = 256 - file_path = self._get_port_eeprom_path(port_num, self.DOM_EEPROM_ADDR) + file_path = self._get_port_eeprom_path( + port_num, self.DOM_EEPROM_ADDR) if not self._sfp_eeprom_present(file_path, 0): return None try: - sysfsfile_eeprom = io.open(file_path,"rb",0) + sysfsfile_eeprom = io.open(file_path, "rb", 0) except IOError: print("Error: reading sysfs file %s" % file_path) return None - - sfpd_obj = sff8472Dom(None,1) + + sfpd_obj = sff8472Dom(None, 1) if sfpd_obj is None: return transceiver_dom_threshold_info_dict - - dom_module_threshold_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, - (offset + SFP_MODULE_THRESHOLD_OFFSET), SFP_MODULE_THRESHOLD_WIDTH) - + + dom_module_threshold_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, + (offset + SFP_MODULE_THRESHOLD_OFFSET), SFP_MODULE_THRESHOLD_WIDTH) + if dom_module_threshold_raw is not None: - dom_module_threshold_data = sfpd_obj.parse_alarm_warning_threshold(dom_module_threshold_raw, 0) + dom_module_threshold_data = sfpd_obj.parse_alarm_warning_threshold( + dom_module_threshold_raw, 0) else: return transceiver_dom_threshold_info_dict @@ -593,7 +613,7 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): print("Error: closing sysfs file %s" % file_path) return None - #Threshold Data + # Threshold Data transceiver_dom_threshold_info_dict['temphighalarm'] = dom_module_threshold_data['data']['TempHighAlarm']['value'] transceiver_dom_threshold_info_dict['templowalarm'] = dom_module_threshold_data['data']['TempLowAlarm']['value'] transceiver_dom_threshold_info_dict['temphighwarning'] = dom_module_threshold_data['data']['TempHighWarning']['value'] @@ -614,5 +634,5 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): transceiver_dom_threshold_info_dict['rxpowerlowalarm'] = dom_module_threshold_data['data']['RXPowerLowAlarm']['value'] transceiver_dom_threshold_info_dict['rxpowerhighwarning'] = dom_module_threshold_data['data']['RXPowerHighWarning']['value'] transceiver_dom_threshold_info_dict['rxpowerlowwarning'] = dom_module_threshold_data['data']['RXPowerLowWarning']['value'] - + return transceiver_dom_threshold_info_dict diff --git a/device/dell/x86_64-dellemc_s5296f_c3538-r0/plugins/eeprom.py b/device/dell/x86_64-dellemc_s5296f_c3538-r0/plugins/eeprom.py index da50f1f851f9..e4ee56138a77 100644 --- a/device/dell/x86_64-dellemc_s5296f_c3538-r0/plugins/eeprom.py +++ b/device/dell/x86_64-dellemc_s5296f_c3538-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # DellEMC S5296f # @@ -13,8 +11,8 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/dell/x86_64-dellemc_s5296f_c3538-r0/plugins/psuutil.py b/device/dell/x86_64-dellemc_s5296f_c3538-r0/plugins/psuutil.py index eedadc516825..8a7b53a626bf 100644 --- a/device/dell/x86_64-dellemc_s5296f_c3538-r0/plugins/psuutil.py +++ b/device/dell/x86_64-dellemc_s5296f_c3538-r0/plugins/psuutil.py @@ -5,9 +5,13 @@ import logging -import commands import sys +if sys.version_info[0] < 3: + import commands +else: + import subprocess as commands + S5296F_MAX_PSUS = 2 IPMI_PSU_DATA = "docker exec -it pmon ipmitool sdr list" @@ -93,6 +97,6 @@ def get_psu_presence(self, index): :param index: An integer, index of the PSU of which to query status :return: Boolean, True if PSU is plugged, False if not """ - cmd_status, psu_status = commands.getstatusoutput('ipmitool raw 0x04 0x2d ' + hex(0x30 + index) + " | awk '{print substr($0,9,1)}'") + cmd_status, psu_status = commands.getstatusoutput( + 'ipmitool raw 0x04 0x2d ' + hex(0x30 + index) + " | awk '{print substr($0,9,1)}'") return 1 if psu_status == '1' else 0 - diff --git a/device/dell/x86_64-dellemc_s5296f_c3538-r0/plugins/sfputil.py b/device/dell/x86_64-dellemc_s5296f_c3538-r0/plugins/sfputil.py index a2e459478f05..8b4ab0dcae1a 100644 --- a/device/dell/x86_64-dellemc_s5296f_c3538-r0/plugins/sfputil.py +++ b/device/dell/x86_64-dellemc_s5296f_c3538-r0/plugins/sfputil.py @@ -19,7 +19,7 @@ raise ImportError("%s - required module not found" % str(e)) -#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 @@ -58,7 +58,6 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} - _global_port_pres_dict = {} @property @@ -71,7 +70,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(97, self.PORTS_IN_BLOCK + 1) + return list(range(97, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -79,8 +78,8 @@ def port_to_eeprom_mapping(self): def pci_mem_read(self, mm, offset): mm.seek(offset) - read_data_stream=mm.read(4) - reg_val=struct.unpack('I',read_data_stream) + read_data_stream = mm.read(4) + reg_val = struct.unpack('I', read_data_stream) mem_val = str(reg_val)[1:-2] # print "reg_val read:%x"%reg_val return mem_val @@ -88,7 +87,7 @@ def pci_mem_read(self, mm, offset): def pci_mem_write(self, mm, offset, data): mm.seek(offset) # print "data to write:%x"%data - mm.write(struct.pack('I',data)) + mm.write(struct.pack('I', data)) def pci_set_value(self, resource, val, offset): fd = open(resource, O_RDWR) @@ -105,7 +104,7 @@ def pci_get_value(self, resource, offset): mm.close() close(fd) return val - + def init_global_port_presence(self): for port_num in range(self.port_start, (self.port_end + 1)): presence = self.get_presence(port_num) @@ -113,7 +112,7 @@ def init_global_port_presence(self): self._global_port_pres_dict[port_num] = '1' else: self._global_port_pres_dict[port_num] = '0' - + def __init__(self): eeprom_path = "/sys/class/i2c-adapter/i2c-{0}/{0}-0050/eeprom" @@ -128,13 +127,13 @@ def get_presence(self, port_num): return False # Port offset starts with 0x4004 - port_offset = 16388 + ((port_num-1) * 16) + port_offset = 16388 + ((port_num-1) * 16) + + status = self.pci_get_value(self.BASE_RES_PATH, port_offset) + reg_value = int(status) - status = self.pci_get_value(self.BASE_RES_PATH, port_offset) - reg_value = int(status) - # Absence of status throws error - if (reg_value == "" ): + if (reg_value == ""): return False # Mask off bit for presence @@ -154,14 +153,14 @@ def get_low_power_mode(self, port_num): if port_num < self.port_start or port_num > self.port_end: return False - # Port offset starts with 0x4000 - port_offset = 16384 + ((port_num-1) * 16) + # Port offset starts with 0x4000 + port_offset = 16384 + ((port_num-1) * 16) - status = self.pci_get_value(self.BASE_RES_PATH, port_offset) - reg_value = int(status) + status = self.pci_get_value(self.BASE_RES_PATH, port_offset) + reg_value = int(status) # Absence of status throws error - if (reg_value == "" ): + if (reg_value == ""): return False # Mask off 4th bit for presence @@ -179,44 +178,44 @@ def set_low_power_mode(self, port_num, lpmode): if port_num < self.port_start or port_num > self.port_end: return False - # Port offset starts with 0x4000 - port_offset = 16384 + ((port_num-1) * 16) + # Port offset starts with 0x4000 + port_offset = 16384 + ((port_num-1) * 16) - status = self.pci_get_value(self.BASE_RES_PATH, port_offset) - reg_value = int(status) + status = self.pci_get_value(self.BASE_RES_PATH, port_offset) + reg_value = int(status) # Absence of status throws error - if (reg_value == "" ): + if (reg_value == ""): return False # Mask off 4th bit for presence mask = (1 << 6) - - # LPMode is active high; set or clear the bit accordingly + + # LPMode is active high; set or clear the bit accordingly if lpmode is True: reg_value = reg_value | mask else: reg_value = reg_value & ~mask # Convert our register value back to a hex string and write back - self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset) + self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset) return True def reset(self, port_num): - # Check for invalid port_num + # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False - # Port offset starts with 0x4000 - port_offset = 16384 + ((port_num-1) * 16) + # Port offset starts with 0x4000 + port_offset = 16384 + ((port_num-1) * 16) - status = self.pci_get_value(self.BASE_RES_PATH, port_offset) - reg_value = int(status) + status = self.pci_get_value(self.BASE_RES_PATH, port_offset) + reg_value = int(status) # Absence of status throws error - if (reg_value == "" ): + if (reg_value == ""): return False # Mask off 4th bit for presence @@ -225,16 +224,16 @@ def reset(self, port_num): # ResetL is active low reg_value = reg_value & ~mask - # Convert our register value back to a hex string and write back - self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset) + # Convert our register value back to a hex string and write back + self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset) # Sleep 1 second to allow it to settle time.sleep(1) reg_value = reg_value | mask - # Convert our register value back to a hex string and write back - self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset) + # Convert our register value back to a hex string and write back + self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset) return True @@ -264,9 +263,8 @@ def get_transceiver_change_event(self, timeout=0): if elapsed_time_ms > timeout: break time.sleep(sleep_time) - - return True, port_dict + return True, port_dict def get_transceiver_dom_info_dict(self, port_num): transceiver_dom_info_dict = {} @@ -276,11 +274,11 @@ def get_transceiver_dom_info_dict(self, port_num): 'tx1bias', 'tx2bias', 'tx3bias', 'tx4bias', 'tx1power', 'tx2power', 'tx3power', 'tx4power', - ] + ] transceiver_dom_info_dict = dict.fromkeys(dom_info_dict_keys, 'N/A') - if port_num in self.qsfp_ports: - offset = 0 + if port_num in self.qsfp_ports: + offset = 0 offset_xcvr = 128 file_path = self._get_port_eeprom_path(port_num, self.IDENTITY_EEPROM_ADDR) if not self._sfp_eeprom_present(file_path, 0): @@ -304,25 +302,29 @@ def get_transceiver_dom_info_dict(self, port_num): # TODO: in the future when decided to migrate to support SFF-8636 instead of SFF-8436, # need to add more code for determining the capability and version compliance # in SFF-8636 dom capability definitions evolving with the versions. - qsfp_dom_capability_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset_xcvr + XCVR_DOM_CAPABILITY_OFFSET), XCVR_DOM_CAPABILITY_WIDTH) + qsfp_dom_capability_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset_xcvr + XCVR_DOM_CAPABILITY_OFFSET), XCVR_DOM_CAPABILITY_WIDTH) if qsfp_dom_capability_raw is not None: qspf_dom_capability_data = sfpi_obj.parse_qsfp_dom_capability(qsfp_dom_capability_raw, 0) else: return transceiver_dom_info_dict - dom_temperature_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + QSFP_TEMPE_OFFSET), QSFP_TEMPE_WIDTH) - if dom_temperature_raw is not None: + dom_temperature_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + QSFP_TEMPE_OFFSET), QSFP_TEMPE_WIDTH) + if dom_temperature_raw is not None: dom_temperature_data = sfpd_obj.parse_temperature(dom_temperature_raw, 0) else: return transceiver_dom_info_dict - dom_voltage_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + QSFP_VOLT_OFFSET), QSFP_VOLT_WIDTH) + dom_voltage_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + QSFP_VOLT_OFFSET), QSFP_VOLT_WIDTH) if dom_voltage_raw is not None: dom_voltage_data = sfpd_obj.parse_voltage(dom_voltage_raw, 0) else: return transceiver_dom_info_dict - qsfp_dom_rev_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + QSFP_DOM_REV_OFFSET), QSFP_DOM_REV_WIDTH) + qsfp_dom_rev_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + QSFP_DOM_REV_OFFSET), QSFP_DOM_REV_WIDTH) if qsfp_dom_rev_raw is not None: qsfp_dom_rev_data = sfpd_obj.parse_sfp_dom_rev(qsfp_dom_rev_raw, 0) else: @@ -337,17 +339,18 @@ def get_transceiver_dom_info_dict(self, port_num): 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) + 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: return transceiver_dom_info_dict - transceiver_dom_info_dict['tx1power'] = 'N/A' + transceiver_dom_info_dict['tx1power'] = 'N/A' transceiver_dom_info_dict['tx2power'] = 'N/A' transceiver_dom_info_dict['tx3power'] = 'N/A' transceiver_dom_info_dict['tx4power'] = 'N/A' - try: + try: sysfsfile_eeprom.close() except IOError: print("Error: closing sysfs file %s" % file_path) @@ -365,46 +368,46 @@ def get_transceiver_dom_info_dict(self, port_num): transceiver_dom_info_dict['tx4bias'] = dom_channel_monitor_data['data']['TX4Bias']['value'] else: - offset = 256 - file_path = self._get_port_eeprom_path(port_num, self.DOM_EEPROM_ADDR) - if not self._sfp_eeprom_present(file_path, 0): - return None + offset = 256 + file_path = self._get_port_eeprom_path(port_num, self.DOM_EEPROM_ADDR) + if not self._sfp_eeprom_present(file_path, 0): + return None try: - sysfsfile_eeprom = io.open(file_path,"rb",0) + sysfsfile_eeprom = io.open(file_path, "rb", 0) except IOError: - print("Error: reading sysfs file %s" % file_path) - return None - - sfpd_obj = sff8472Dom(None,1) + print("Error: reading sysfs file %s" % file_path) + return None + + sfpd_obj = sff8472Dom(None, 1) 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 transceiver_dom_info_dict + return transceiver_dom_info_dict - dom_voltage_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_VOLT_OFFSET), - SFP_VOLT_WIDTH) + dom_voltage_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_VOLT_OFFSET), + SFP_VOLT_WIDTH) if dom_voltage_raw is not None: - dom_voltage_data = sfpd_obj.parse_voltage(dom_voltage_raw, 0) - else: - return transceiver_dom_info_dict + dom_voltage_data = sfpd_obj.parse_voltage(dom_voltage_raw, 0) + else: + return transceiver_dom_info_dict - dom_channel_monitor_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_MODULE_THRESHOLD_OFFSET), - SFP_MODULE_THRESHOLD_WIDTH) + dom_channel_monitor_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_MODULE_THRESHOLD_OFFSET), + SFP_MODULE_THRESHOLD_WIDTH) if dom_channel_monitor_raw is not None: - dom_channel_monitor_data = sfpd_obj.parse_channel_monitor_params(dom_channel_monitor_raw, 0) + dom_channel_monitor_data = sfpd_obj.parse_channel_monitor_params(dom_channel_monitor_raw, 0) else: - return transceiver_dom_info_dict + return transceiver_dom_info_dict try: - sysfsfile_eeprom.close() + sysfsfile_eeprom.close() except IOError: - print("Error: closing sysfs file %s" % file_path) - return None + print("Error: closing sysfs file %s" % file_path) + return None transceiver_dom_info_dict['temperature'] = dom_temperature_data['data']['Temperature']['value'] transceiver_dom_info_dict['voltage'] = dom_voltage_data['data']['Vcc']['value'] @@ -421,8 +424,8 @@ def get_transceiver_dom_info_dict(self, port_num): transceiver_dom_info_dict['tx3power'] = 'N/A' transceiver_dom_info_dict['tx4power'] = 'N/A' - return transceiver_dom_info_dict - + return transceiver_dom_info_dict + def get_transceiver_dom_threshold_info_dict(self, port_num): transceiver_dom_threshold_info_dict = {} dom_info_dict_keys = ['temphighalarm', 'temphighwarning', @@ -435,11 +438,11 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): 'txpowerlowalarm', 'txpowerlowwarning', 'txbiashighalarm', 'txbiashighwarning', 'txbiaslowalarm', 'txbiaslowwarning' - ] + ] transceiver_dom_threshold_info_dict = dict.fromkeys(dom_info_dict_keys, 'N/A') if port_num in self.qsfp_ports: - file_path = self._get_port_eeprom_path(port_num, self.IDENTITY_EEPROM_ADDR) + file_path = self._get_port_eeprom_path(port_num, self.IDENTITY_EEPROM_ADDR) if not self._sfp_eeprom_present(file_path, 0): return None @@ -457,18 +460,18 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): # Revert offset back to 0 once data is retrieved offset = 384 dom_module_threshold_raw = self._read_eeprom_specific_bytes( - sysfsfile_eeprom, - (offset + QSFP_MODULE_THRESHOLD_OFFSET), - QSFP_MODULE_THRESHOLD_WIDTH) + sysfsfile_eeprom, + (offset + QSFP_MODULE_THRESHOLD_OFFSET), + QSFP_MODULE_THRESHOLD_WIDTH) if dom_module_threshold_raw is not None: dom_module_threshold_data = sfpd_obj.parse_module_threshold_values(dom_module_threshold_raw, 0) else: return transceiver_dom_threshold_info_dict dom_channel_threshold_raw = self._read_eeprom_specific_bytes( - sysfsfile_eeprom, - (offset + QSFP_CHANNL_THRESHOLD_OFFSET), - QSFP_CHANNL_THRESHOLD_WIDTH) + sysfsfile_eeprom, + (offset + QSFP_CHANNL_THRESHOLD_OFFSET), + QSFP_CHANNL_THRESHOLD_WIDTH) if dom_channel_threshold_raw is not None: dom_channel_threshold_data = sfpd_obj.parse_channel_threshold_values(dom_channel_threshold_raw, 0) else: @@ -505,18 +508,18 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): return None try: - sysfsfile_eeprom = io.open(file_path,"rb",0) + sysfsfile_eeprom = io.open(file_path, "rb", 0) except IOError: print("Error: reading sysfs file %s" % file_path) return None - - sfpd_obj = sff8472Dom(None,1) + + sfpd_obj = sff8472Dom(None, 1) if sfpd_obj is None: return transceiver_dom_threshold_info_dict - - dom_module_threshold_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, - (offset + SFP_MODULE_THRESHOLD_OFFSET), SFP_MODULE_THRESHOLD_WIDTH) - + + dom_module_threshold_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, + (offset + SFP_MODULE_THRESHOLD_OFFSET), SFP_MODULE_THRESHOLD_WIDTH) + if dom_module_threshold_raw is not None: dom_module_threshold_data = sfpd_obj.parse_alarm_warning_threshold(dom_module_threshold_raw, 0) else: @@ -528,7 +531,7 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): print("Error: closing sysfs file %s" % file_path) return None - #Threshold Data + # Threshold Data transceiver_dom_threshold_info_dict['temphighalarm'] = dom_module_threshold_data['data']['TempHighAlarm']['value'] transceiver_dom_threshold_info_dict['templowalarm'] = dom_module_threshold_data['data']['TempLowAlarm']['value'] transceiver_dom_threshold_info_dict['temphighwarning'] = dom_module_threshold_data['data']['TempHighWarning']['value'] @@ -549,6 +552,5 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): transceiver_dom_threshold_info_dict['rxpowerlowalarm'] = dom_module_threshold_data['data']['RXPowerLowAlarm']['value'] transceiver_dom_threshold_info_dict['rxpowerhighwarning'] = dom_module_threshold_data['data']['RXPowerHighWarning']['value'] transceiver_dom_threshold_info_dict['rxpowerlowwarning'] = dom_module_threshold_data['data']['RXPowerLowWarning']['value'] - + return transceiver_dom_threshold_info_dict - diff --git a/device/dell/x86_64-dellemc_z9264f_c3538-r0/plugins/eeprom.py b/device/dell/x86_64-dellemc_z9264f_c3538-r0/plugins/eeprom.py index e8284f686b1e..a38a0395d5b3 100644 --- a/device/dell/x86_64-dellemc_z9264f_c3538-r0/plugins/eeprom.py +++ b/device/dell/x86_64-dellemc_z9264f_c3538-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # DellEMC Z9264f # @@ -20,7 +18,7 @@ class board(eeprom_tlvinfo.TlvInfoDecoder): def __init__(self, name, path, cpld_root, ro): self.eeprom_path = None - for b in (0,1): + for b in (0, 1): f = '/sys/class/i2c-adapter/i2c-{0}/{0}-0050/eeprom'.format(b) if os.path.exists(f): self.eeprom_path = f diff --git a/device/dell/x86_64-dellemc_z9264f_c3538-r0/plugins/psuutil.py b/device/dell/x86_64-dellemc_z9264f_c3538-r0/plugins/psuutil.py index c72a2d6675b3..3a58afda8df4 100644 --- a/device/dell/x86_64-dellemc_z9264f_c3538-r0/plugins/psuutil.py +++ b/device/dell/x86_64-dellemc_z9264f_c3538-r0/plugins/psuutil.py @@ -6,9 +6,13 @@ import os.path import logging -import commands import sys +if sys.version_info[0] < 3: + import commands +else: + import subprocess as commands + Z9264F_MAX_PSUS = 2 IPMI_PSU_DATA = "docker exec -it pmon ipmitool sdr list" @@ -102,6 +106,5 @@ def get_psu_presence(self, index): if (psu_status != 'ERR'): # Check for PSU presence if (psu_status): - status = 1 + status = 1 return status - diff --git a/device/dell/x86_64-dellemc_z9264f_c3538-r0/plugins/sfputil.py b/device/dell/x86_64-dellemc_z9264f_c3538-r0/plugins/sfputil.py index 6aa18d85e2e7..5b01882762af 100644 --- a/device/dell/x86_64-dellemc_z9264f_c3538-r0/plugins/sfputil.py +++ b/device/dell/x86_64-dellemc_z9264f_c3538-r0/plugins/sfputil.py @@ -21,7 +21,7 @@ except ImportError as e: raise ImportError("%s - required module not found" % str(e)) -#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 @@ -50,6 +50,7 @@ XCVR_DOM_CAPABILITY_OFFSET = 92 XCVR_DOM_CAPABILITY_WIDTH = 1 + class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" @@ -77,7 +78,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(self.PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -150,7 +151,7 @@ def get_presence(self, port_num): # Mask off 1st bit for presence 65,66 if (port_num > 64): - mask = (1 << 0) + mask = (1 << 0) # ModPrsL is active low if reg_value & mask == 0: return True @@ -248,96 +249,96 @@ def reset(self, port_num): return True def get_register(self, reg_file): - retval = 'ERR' - if (not path.isfile(reg_file)): - print reg_file, 'not found !' - return retval + retval = 'ERR' + if (not path.isfile(reg_file)): + print(reg_file + ' not found !') + return retval - try: - with fdopen(open(reg_file, O_RDONLY)) as fd: - retval = fd.read() - except Exception as error: - logging.error("Unable to open ", reg_file, "file !") + try: + with fdopen(open(reg_file, O_RDONLY)) as fd: + retval = fd.read() + except Exception as error: + logging.error("Unable to open ", reg_file, "file !") - retval = retval.rstrip('\r\n') - retval = retval.lstrip(" ") - return retval + retval = retval.rstrip('\r\n') + retval = retval.lstrip(" ") + return retval def check_interrupts(self, port_dict): - retval = 0 - is_port_dict_updated = False - for port_num in range(self.port_start, (self.port_end + 1)): - presence = self.get_presence(port_num) - if(presence and self._global_port_pres_dict[port_num] == '0'): - is_port_dict_updated = True - self._global_port_pres_dict[port_num] = '1' - port_dict[port_num] = '1' - elif(not presence and - self._global_port_pres_dict[port_num] == '1'): - is_port_dict_updated = True - self._global_port_pres_dict[port_num] = '0' - port_dict[port_num] = '0' - return retval, is_port_dict_updated + retval = 0 + is_port_dict_updated = False + for port_num in range(self.port_start, (self.port_end + 1)): + presence = self.get_presence(port_num) + if(presence and self._global_port_pres_dict[port_num] == '0'): + is_port_dict_updated = True + self._global_port_pres_dict[port_num] = '1' + port_dict[port_num] = '1' + elif(not presence and + self._global_port_pres_dict[port_num] == '1'): + is_port_dict_updated = True + self._global_port_pres_dict[port_num] = '0' + port_dict[port_num] = '0' + return retval, is_port_dict_updated def get_transceiver_change_event(self, timeout=0): - port_dict = {} - try: - # We get notified when there is a MSI interrupt (vector 4/5)CVR - # Open the sysfs file and register the epoll object - self.oir_fd = fdopen(open(self.OIR_FD_PATH, O_RDONLY)) - if self.oir_fd != -1: - # Do a dummy read before epoll register - self.oir_fd.read() - self.epoll = select.epoll() - self.epoll.register( - self.oir_fd.fileno(), select.EPOLLIN & select.EPOLLET) - else: - print("get_transceiver_change_event : unable to create fd") - return False, {} + port_dict = {} + try: + # We get notified when there is a MSI interrupt (vector 4/5)CVR + # Open the sysfs file and register the epoll object + self.oir_fd = fdopen(open(self.OIR_FD_PATH, O_RDONLY)) + if self.oir_fd != -1: + # Do a dummy read before epoll register + self.oir_fd.read() + self.epoll = select.epoll() + self.epoll.register( + self.oir_fd.fileno(), select.EPOLLIN & select.EPOLLET) + else: + print("get_transceiver_change_event : unable to create fd") + return False, {} - # Check for missed interrupts by invoking self.check_interrupts - # which will update the port_dict. - while True: - interrupt_count_start = self.get_register(self.OIR_FD_PATH) - retval, is_port_dict_updated = \ - self.check_interrupts(port_dict) - if ((retval == 0) and (is_port_dict_updated is True)): - return True, port_dict - interrupt_count_end = self.get_register(self.OIR_FD_PATH) - if (interrupt_count_start == 'ERR' or - interrupt_count_end == 'ERR'): - print("get_transceiver_change_event : \ + # Check for missed interrupts by invoking self.check_interrupts + # which will update the port_dict. + while True: + interrupt_count_start = self.get_register(self.OIR_FD_PATH) + retval, is_port_dict_updated = \ + self.check_interrupts(port_dict) + if ((retval == 0) and (is_port_dict_updated is True)): + return True, port_dict + interrupt_count_end = self.get_register(self.OIR_FD_PATH) + if (interrupt_count_start == 'ERR' or + interrupt_count_end == 'ERR'): + print("get_transceiver_change_event : \ unable to retrive interrupt count") - break - - # check_interrupts() itself may take upto 100s of msecs. - # We detect a missed interrupt based on the count - if interrupt_count_start == interrupt_count_end: - break - - # Block until an xcvr is inserted or removed with timeout = -1 - events = self.epoll.poll( - timeout=timeout if timeout != 0 else -1) - if events: - # check interrupts and return the port_dict - retval, is_port_dict_updated = \ - self.check_interrupts(port_dict) - if (retval != 0): - return False, {} - - return True, port_dict - except: - return False, {} - finally: - if self.oir_fd != -1: - self.epoll.unregister(self.oir_fd.fileno()) - self.epoll.close() - self.oir_fd.close() - self.oir_fd = -1 - self.epoll = -1 + break + + # check_interrupts() itself may take upto 100s of msecs. + # We detect a missed interrupt based on the count + if interrupt_count_start == interrupt_count_end: + break + + # Block until an xcvr is inserted or removed with timeout = -1 + events = self.epoll.poll( + timeout=timeout if timeout != 0 else -1) + if events: + # check interrupts and return the port_dict + retval, is_port_dict_updated = \ + self.check_interrupts(port_dict) + if (retval != 0): + return False, {} + return True, port_dict + except: return False, {} - + finally: + if self.oir_fd != -1: + self.epoll.unregister(self.oir_fd.fileno()) + self.epoll.close() + self.oir_fd.close() + self.oir_fd = -1 + self.epoll = -1 + + return False, {} + def get_transceiver_dom_info_dict(self, port_num): transceiver_dom_info_dict = {} @@ -346,7 +347,7 @@ def get_transceiver_dom_info_dict(self, port_num): 'tx1bias', 'tx2bias', 'tx3bias', 'tx4bias', 'tx1power', 'tx2power', 'tx3power', 'tx4power', - ] + ] transceiver_dom_info_dict = dict.fromkeys(dom_info_dict_keys, 'N/A') if port_num in self.qsfp_ports: @@ -374,25 +375,29 @@ def get_transceiver_dom_info_dict(self, port_num): # TODO: in the future when decided to migrate to support SFF-8636 instead of SFF-8436, # need to add more code for determining the capability and version compliance # in SFF-8636 dom capability definitions evolving with the versions. - qsfp_dom_capability_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset_xcvr + XCVR_DOM_CAPABILITY_OFFSET), XCVR_DOM_CAPABILITY_WIDTH) + qsfp_dom_capability_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset_xcvr + XCVR_DOM_CAPABILITY_OFFSET), XCVR_DOM_CAPABILITY_WIDTH) if qsfp_dom_capability_raw is not None: qspf_dom_capability_data = sfpi_obj.parse_qsfp_dom_capability(qsfp_dom_capability_raw, 0) else: return transceiver_dom_info_dict - dom_temperature_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + QSFP_TEMPE_OFFSET), QSFP_TEMPE_WIDTH) + dom_temperature_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + QSFP_TEMPE_OFFSET), QSFP_TEMPE_WIDTH) if dom_temperature_raw is not None: dom_temperature_data = sfpd_obj.parse_temperature(dom_temperature_raw, 0) else: return transceiver_dom_info_dict - dom_voltage_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + QSFP_VOLT_OFFSET), QSFP_VOLT_WIDTH) + dom_voltage_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + QSFP_VOLT_OFFSET), QSFP_VOLT_WIDTH) if dom_voltage_raw is not None: dom_voltage_data = sfpd_obj.parse_voltage(dom_voltage_raw, 0) else: return transceiver_dom_info_dict - qsfp_dom_rev_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + QSFP_DOM_REV_OFFSET), QSFP_DOM_REV_WIDTH) + qsfp_dom_rev_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + QSFP_DOM_REV_OFFSET), QSFP_DOM_REV_WIDTH) if qsfp_dom_rev_raw is not None: qsfp_dom_rev_data = sfpd_obj.parse_sfp_dom_rev(qsfp_dom_rev_raw, 0) else: @@ -407,7 +412,8 @@ def get_transceiver_dom_info_dict(self, port_num): 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) + 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: @@ -418,9 +424,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 @@ -453,16 +461,16 @@ def get_transceiver_dom_info_dict(self, port_num): return None try: - sysfsfile_eeprom = io.open(file_path,"rb",0) + sysfsfile_eeprom = io.open(file_path, "rb", 0) except IOError: print("Error: reading sysfs file %s" % file_path) return None - sfpd_obj = sff8472Dom(None,1) + sfpd_obj = sff8472Dom(None, 1) if sfpd_obj is None: return None dom_temperature_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_TEMPE_OFFSET), - SFP_TEMPE_WIDTH) + SFP_TEMPE_WIDTH) if dom_temperature_raw is not None: dom_temperature_data = sfpd_obj.parse_temperature(dom_temperature_raw, 0) @@ -470,7 +478,7 @@ def get_transceiver_dom_info_dict(self, port_num): return transceiver_dom_info_dict dom_voltage_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_VOLT_OFFSET), - SFP_VOLT_WIDTH) + SFP_VOLT_WIDTH) if dom_voltage_raw is not None: dom_voltage_data = sfpd_obj.parse_voltage(dom_voltage_raw, 0) @@ -519,7 +527,7 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): 'txpowerlowalarm', 'txpowerlowwarning', 'txbiashighalarm', 'txbiashighwarning', 'txbiaslowalarm', 'txbiaslowwarning' - ] + ] transceiver_dom_threshold_info_dict = dict.fromkeys(dom_info_dict_keys, 'N/A') if port_num in self.qsfp_ports: @@ -541,18 +549,18 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): # Revert offset back to 0 once data is retrieved offset = 384 dom_module_threshold_raw = self._read_eeprom_specific_bytes( - sysfsfile_eeprom, - (offset + QSFP_MODULE_THRESHOLD_OFFSET), - QSFP_MODULE_THRESHOLD_WIDTH) + sysfsfile_eeprom, + (offset + QSFP_MODULE_THRESHOLD_OFFSET), + QSFP_MODULE_THRESHOLD_WIDTH) if dom_module_threshold_raw is not None: dom_module_threshold_data = sfpd_obj.parse_module_threshold_values(dom_module_threshold_raw, 0) else: return transceiver_dom_threshold_info_dict dom_channel_threshold_raw = self._read_eeprom_specific_bytes( - sysfsfile_eeprom, - (offset + QSFP_CHANNL_THRESHOLD_OFFSET), - QSFP_CHANNL_THRESHOLD_WIDTH) + sysfsfile_eeprom, + (offset + QSFP_CHANNL_THRESHOLD_OFFSET), + QSFP_CHANNL_THRESHOLD_WIDTH) if dom_channel_threshold_raw is not None: dom_channel_threshold_data = sfpd_obj.parse_channel_threshold_values(dom_channel_threshold_raw, 0) else: @@ -589,18 +597,18 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): return None try: - sysfsfile_eeprom = io.open(file_path,"rb",0) + sysfsfile_eeprom = io.open(file_path, "rb", 0) except IOError: print("Error: reading sysfs file %s" % file_path) return None - - sfpd_obj = sff8472Dom(None,1) + + sfpd_obj = sff8472Dom(None, 1) if sfpd_obj is None: return transceiver_dom_threshold_info_dict - - dom_module_threshold_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, - (offset + SFP_MODULE_THRESHOLD_OFFSET), SFP_MODULE_THRESHOLD_WIDTH) - + + dom_module_threshold_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, + (offset + SFP_MODULE_THRESHOLD_OFFSET), SFP_MODULE_THRESHOLD_WIDTH) + if dom_module_threshold_raw is not None: dom_module_threshold_data = sfpd_obj.parse_alarm_warning_threshold(dom_module_threshold_raw, 0) else: @@ -612,7 +620,7 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): print("Error: closing sysfs file %s" % file_path) return None - #Threshold Data + # Threshold Data transceiver_dom_threshold_info_dict['temphighalarm'] = dom_module_threshold_data['data']['TempHighAlarm']['value'] transceiver_dom_threshold_info_dict['templowalarm'] = dom_module_threshold_data['data']['TempLowAlarm']['value'] transceiver_dom_threshold_info_dict['temphighwarning'] = dom_module_threshold_data['data']['TempHighWarning']['value'] @@ -633,5 +641,5 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): transceiver_dom_threshold_info_dict['rxpowerlowalarm'] = dom_module_threshold_data['data']['RXPowerLowAlarm']['value'] transceiver_dom_threshold_info_dict['rxpowerhighwarning'] = dom_module_threshold_data['data']['RXPowerHighWarning']['value'] transceiver_dom_threshold_info_dict['rxpowerlowwarning'] = dom_module_threshold_data['data']['RXPowerLowWarning']['value'] - + return transceiver_dom_threshold_info_dict diff --git a/device/dell/x86_64-dellemc_z9332f_d1508-r0/plugins/eeprom.py b/device/dell/x86_64-dellemc_z9332f_d1508-r0/plugins/eeprom.py index 2400b0f4153c..a346f1957be4 100644 --- a/device/dell/x86_64-dellemc_z9332f_d1508-r0/plugins/eeprom.py +++ b/device/dell/x86_64-dellemc_z9332f_d1508-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # DellEMC Z9332f # diff --git a/device/dell/x86_64-dellemc_z9332f_d1508-r0/plugins/psuutil.py b/device/dell/x86_64-dellemc_z9332f_d1508-r0/plugins/psuutil.py index b2c373de358f..435f9b2929ec 100644 --- a/device/dell/x86_64-dellemc_z9332f_d1508-r0/plugins/psuutil.py +++ b/device/dell/x86_64-dellemc_z9332f_d1508-r0/plugins/psuutil.py @@ -6,9 +6,13 @@ import os.path import logging -import commands import sys +if sys.version_info[0] < 3: + import commands +else: + import subprocess as commands + Z9332F_MAX_PSUS = 2 IPMI_PSU1_DATA = "docker exec -it pmon ipmitool raw 0x04 0x2d 0x2f | awk '{print substr($0,9,1)}'" @@ -50,15 +54,15 @@ def get_pmc_register(self, reg_name): ipmi_cmd_2 = IPMI_PSU1_DATA dockerenv = self.isDockerEnv() if dockerenv == True: - if index == 1: - status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA_DOCKER) - elif index == 2: - status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA_DOCKER) + if index == 1: + status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA_DOCKER) + elif index == 2: + status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA_DOCKER) else: - if index == 1: - status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA) - elif index == 2: - status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA) + if index == 1: + status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA) + elif index == 2: + status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA) if status: logging.error('Failed to execute ipmitool') @@ -102,25 +106,24 @@ def get_psu_presence(self, index): ipmi_dev_node = "/dev/pmi0" dockerenv = self.isDockerEnv() if dockerenv == True: - if index == 1: - status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA_DOCKER) - elif index == 2: - status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA_DOCKER) + if index == 1: + status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA_DOCKER) + elif index == 2: + status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA_DOCKER) else: - if index == 1: - status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA) - elif index == 2: - ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA) + if index == 1: + status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA) + elif index == 2: + ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA) - #if ret_status: - # print ipmi_sdr_list - # logging.error('Failed to execute ipmitool') - # sys.exit(0) + # if ret_status: + # print ipmi_sdr_list + # logging.error('Failed to execute ipmitool') + # sys.exit(0) psu_status = ipmi_sdr_list if psu_status == '1': - status = 1 + status = 1 return status - diff --git a/device/dell/x86_64-dellemc_z9332f_d1508-r0/plugins/sfputil.py b/device/dell/x86_64-dellemc_z9332f_d1508-r0/plugins/sfputil.py index 1ea6af1f8d26..d037fd9273dd 100644 --- a/device/dell/x86_64-dellemc_z9332f_d1508-r0/plugins/sfputil.py +++ b/device/dell/x86_64-dellemc_z9332f_d1508-r0/plugins/sfputil.py @@ -16,59 +16,56 @@ except ImportError as e: raise ImportError("%s - required module not found" % str(e)) -#from xcvrd +# from xcvrd SFP_STATUS_REMOVED = '0' SFP_STATUS_INSERTED = '1' - - - class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" PORT_START = 1 - PORT_END = 34 - PORTS_IN_BLOCK = 34 + PORT_END = 34 + PORTS_IN_BLOCK = 34 BASE_RES_PATH = "/sys/bus/pci/devices/0000:09:00.0/resource0" _port_to_i2c_mapping = { - 1: 10, - 2: 11, - 3: 12, - 4: 13, - 5: 14, - 6: 15, - 7: 16, - 8: 17, - 9: 18, - 10: 19, - 11: 20, - 12: 21, - 13: 22, - 14: 23, - 15: 24, - 16: 25, - 17: 26, - 18: 27, - 19: 28, - 20: 29, - 21: 30, - 22: 31, - 23: 32, - 24: 33, - 25: 34, - 26: 35, - 27: 36, - 28: 37, - 29: 38, - 30: 39, - 31: 40, - 32: 41, - 33: 1, - 34: 2, - } + 1: 10, + 2: 11, + 3: 12, + 4: 13, + 5: 14, + 6: 15, + 7: 16, + 8: 17, + 9: 18, + 10: 19, + 11: 20, + 12: 21, + 13: 22, + 14: 23, + 15: 24, + 16: 25, + 17: 26, + 18: 27, + 19: 28, + 20: 29, + 21: 30, + 22: 31, + 23: 32, + 24: 33, + 25: 34, + 26: 35, + 27: 36, + 28: 37, + 29: 38, + 30: 39, + 31: 40, + 32: 41, + 33: 1, + 34: 2, + } _port_to_eeprom_mapping = {} @@ -84,7 +81,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(self.PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -128,27 +125,26 @@ def init_global_port_presence(self): self._global_port_pres_dict[port_num] = '0' def mod_pres(self): - port_pres_mask =0 + port_pres_mask = 0 for port_num in range(self.port_start, (self.port_end + 1)): presence = self.get_presence(port_num) if(presence): self._global_port_pres_dict[port_num] = '1' - port_val = (1 << (port_num -1)) + port_val = (1 << (port_num - 1)) port_pres_mask = (port_pres_mask | port_val) else: self._global_port_pres_dict[port_num] = '0' - port_val = ~(1 << (port_num -1)) + port_val = ~(1 << (port_num - 1)) port_pres_mask = (port_pres_mask & port_val) return port_pres_mask - def __init__(self): eeprom_path = "/sys/class/i2c-adapter/i2c-{0}/{0}-0050/eeprom" for x in range(self.port_start, self.port_end + 1): self.port_to_eeprom_mapping[x] = eeprom_path.format( - self._port_to_i2c_mapping[x]) + self._port_to_i2c_mapping[x]) self.init_global_port_presence() SfpUtilBase.__init__(self) @@ -172,7 +168,7 @@ def get_presence(self, port_num): # Mask off 1st bit for presence 33,34 if (port_num > 32): - mask = (1 << 0) + mask = (1 << 0) # ModPrsL is active low if reg_value & mask == 0: @@ -271,21 +267,21 @@ def reset(self, port_num): return True def get_register(self, reg_file): - retval = 'ERR' - if (not path.isfile(reg_file)): - print reg_file, 'not found !' - return retval - - try: - with fdopen(open(reg_file, O_RDONLY)) as fd: - retval = fd.read() - except Exception as error: - logging.error("Unable to open ", reg_file, "file !") - - retval = retval.rstrip('\r\n') - retval = retval.lstrip(" ") + retval = 'ERR' + if (not path.isfile(reg_file)): + print(reg_file + ' not found !') return retval + try: + with fdopen(open(reg_file, O_RDONLY)) as fd: + retval = fd.read() + except Exception as error: + logging.error("Unable to open ", reg_file, "file !") + + retval = retval.rstrip('\r\n') + retval = retval.lstrip(" ") + return retval + def get_transceiver_change_event(self): port_dict = {} while True: @@ -303,5 +299,3 @@ def get_transceiver_change_event(self): return True, port_dict time.sleep(0.5) - - diff --git a/device/delta/x86_64-delta_ag5648-r0/plugins/eeprom.py b/device/delta/x86_64-delta_ag5648-r0/plugins/eeprom.py index 786e1fdc85e3..bd9bbb755f39 100644 --- a/device/delta/x86_64-delta_ag5648-r0/plugins/eeprom.py +++ b/device/delta/x86_64-delta_ag5648-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Mellanox # @@ -10,7 +8,6 @@ ############################################################################# try: - import exceptions import binascii import time import optparse @@ -20,13 +17,14 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 def __init__(self, name, path, cpld_root, ro): - self.eeprom_path = "/sys/devices/pci0000:00/0000:00:13.0/i2c-1/i2c-2/2-0053/eeprom" - super(board, self).__init__(self.eeprom_path, 0, '', True) + self.eeprom_path = "/sys/devices/pci0000:00/0000:00:13.0/i2c-1/i2c-2/2-0053/eeprom" + super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/delta/x86_64-delta_ag5648-r0/plugins/psuutil.py b/device/delta/x86_64-delta_ag5648-r0/plugins/psuutil.py index 0d17ff05681a..8aa080166f8a 100644 --- a/device/delta/x86_64-delta_ag5648-r0/plugins/psuutil.py +++ b/device/delta/x86_64-delta_ag5648-r0/plugins/psuutil.py @@ -3,7 +3,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" @@ -15,7 +16,6 @@ def __init__(self): self.psu_oper_status = "in1_input" self.psu_presence = "i2cget -y 6 0x{} 0x00" - def get_num_psus(self): """ Retrieves the number of PSUs available on the device @@ -31,7 +31,7 @@ def get_psu_status(self, index): status = 0 try: with open(self.psu_path.format(index + Base_bus_number) + self.psu_oper_status, 'r') as power_status: - if int(power_status.read()) == 0 : + if int(power_status.read()) == 0: return False else: status = 1 @@ -45,12 +45,10 @@ def get_psu_presence(self, index): Base_bus_number = 49 status = 0 try: - p = os.popen(self.psu_presence.format(index + Base_bus_number)+ "> /dev/null 2>&1") + p = os.popen(self.psu_presence.format(index + Base_bus_number) + "> /dev/null 2>&1") if p.readline() != None: status = 1 p.close() except IOError: return False return status == 1 - - diff --git a/device/delta/x86_64-delta_ag5648-r0/plugins/sfputil.py b/device/delta/x86_64-delta_ag5648-r0/plugins/sfputil.py index 864977414251..5fc426340818 100644 --- a/device/delta/x86_64-delta_ag5648-r0/plugins/sfputil.py +++ b/device/delta/x86_64-delta_ag5648-r0/plugins/sfputil.py @@ -25,6 +25,7 @@ class SfpUtil(SfpUtilBase): @property def port_start(self): return self.PORT_START + @property def port_start_qsfp(self): return self.PORT_START_QSFP @@ -35,7 +36,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(0, self.PORTS_IN_BLOCK + 1) + return list(range(0, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -45,7 +46,7 @@ def __init__(self): eeprom_path = "/sys/class/i2c-adapter/i2c-{0}/{0}-0050/eeprom" for x in range(0, self.port_end + 1): - if x > self.port_start_qsfp -1 and x < self.port_end + 1: + if x > self.port_start_qsfp - 1 and x < self.port_end + 1: self.get_response(x) self._port_to_eeprom_mapping[x] = eeprom_path.format(x + self.EEPROM_OFFSET) SfpUtilBase.__init__(self) @@ -58,12 +59,12 @@ def get_response(self, port_num): try: reg_file = open("/sys/devices/platform/delta-ag5648-cpld.0/sfp_response", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False - # set the bit corresponding to our port - mask = (port_num + 1) % 8 - 1 - mask = 1 << mask + # set the bit corresponding to our port + mask = (port_num + 1) % 8 - 1 + mask = 1 << mask # Convert our register value back to a hex string and write back content = hex(mask) @@ -81,7 +82,7 @@ def get_presence(self, port_num): try: reg_file = open("/sys/devices/platform/delta-ag5648-cpld.0/sfp_present") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -106,7 +107,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open("/sys/devices/platform/delta-ag5648-cpld.0/sfp_lpmode") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) content = reg_file.readline().rstrip() @@ -130,7 +131,7 @@ def set_low_power_mode(self, port_num, lpmode): try: reg_file = open("/sys/devices/platform/delta-ag5648-cpld.0/sfp_lpmode", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -166,7 +167,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -192,7 +193,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_value | mask diff --git a/device/delta/x86_64-delta_ag9032v1-r0/plugins/eeprom.py b/device/delta/x86_64-delta_ag9032v1-r0/plugins/eeprom.py index 786e1fdc85e3..bd9bbb755f39 100644 --- a/device/delta/x86_64-delta_ag9032v1-r0/plugins/eeprom.py +++ b/device/delta/x86_64-delta_ag9032v1-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Mellanox # @@ -10,7 +8,6 @@ ############################################################################# try: - import exceptions import binascii import time import optparse @@ -20,13 +17,14 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 def __init__(self, name, path, cpld_root, ro): - self.eeprom_path = "/sys/devices/pci0000:00/0000:00:13.0/i2c-1/i2c-2/2-0053/eeprom" - super(board, self).__init__(self.eeprom_path, 0, '', True) + self.eeprom_path = "/sys/devices/pci0000:00/0000:00:13.0/i2c-1/i2c-2/2-0053/eeprom" + super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/delta/x86_64-delta_ag9032v1-r0/plugins/psuutil.py b/device/delta/x86_64-delta_ag9032v1-r0/plugins/psuutil.py index 4b370d9a7443..391efbd2401f 100644 --- a/device/delta/x86_64-delta_ag9032v1-r0/plugins/psuutil.py +++ b/device/delta/x86_64-delta_ag9032v1-r0/plugins/psuutil.py @@ -3,7 +3,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" @@ -15,7 +16,6 @@ def __init__(self): self.psu_oper_status = "in1_input" self.psu_presence = "i2cget -y {} 0x50 0x00" - def get_num_psus(self): """ Retrieves the number of PSUs available on the device @@ -29,10 +29,10 @@ def get_psu_status(self, index): return False Base_bus_number = 39 status = 0 - #index from 1, psu attribute bus from 40 + # index from 1, psu attribute bus from 40 try: with open(self.psu_path.format(index + Base_bus_number) + self.psu_oper_status, 'r') as power_status: - if int(power_status.read()) == 0 : + if int(power_status.read()) == 0: return False else: status = 1 @@ -46,12 +46,10 @@ def get_psu_presence(self, index): Base_bus_number = 39 status = 0 try: - p = os.popen(self.psu_presence.format(index + Base_bus_number)+ "> /dev/null 2>&1") + p = os.popen(self.psu_presence.format(index + Base_bus_number) + "> /dev/null 2>&1") if p.readline() != None: status = 1 p.close() except IOError: return False return status == 1 - - diff --git a/device/delta/x86_64-delta_ag9032v1-r0/plugins/sfputil.py b/device/delta/x86_64-delta_ag9032v1-r0/plugins/sfputil.py index 748e2b6643f4..c620540d2911 100644 --- a/device/delta/x86_64-delta_ag9032v1-r0/plugins/sfputil.py +++ b/device/delta/x86_64-delta_ag9032v1-r0/plugins/sfputil.py @@ -31,7 +31,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(0, self.PORTS_IN_BLOCK + 1) + return list(range(0, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -53,7 +53,7 @@ def get_presence(self, port_num): try: reg_file = open("/sys/devices/platform/delta-ag9032v1-swpld.0/sfp_present") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -78,7 +78,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open("/sys/devices/platform/delta-ag9032v1-swpld.0/sfp_lpmode") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) content = reg_file.readline().rstrip() @@ -102,7 +102,7 @@ def set_low_power_mode(self, port_num, lpmode): try: reg_file = open("/sys/devices/platform/delta-ag9032v1-swpld.0/sfp_lpmode", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -138,7 +138,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -164,7 +164,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_value | mask diff --git a/device/delta/x86_64-delta_ag9032v2a-r0/plugins/eeprom.py b/device/delta/x86_64-delta_ag9032v2a-r0/plugins/eeprom.py index fc741c11e9ea..9d55c090d57b 100644 --- a/device/delta/x86_64-delta_ag9032v2a-r0/plugins/eeprom.py +++ b/device/delta/x86_64-delta_ag9032v2a-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Mellanox # @@ -10,7 +8,6 @@ ############################################################################# try: - import exceptions import binascii import time import optparse @@ -20,13 +17,14 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 def __init__(self, name, path, cpld_root, ro): - self.eeprom_path = "/sys/devices/pci0000:00/0000:00:1f.3/i2c-0/i2c-1/1-0053/eeprom" - super(board, self).__init__(self.eeprom_path, 0, '', True) + self.eeprom_path = "/sys/devices/pci0000:00/0000:00:1f.3/i2c-0/i2c-1/1-0053/eeprom" + super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/delta/x86_64-delta_ag9032v2a-r0/plugins/psuutil.py b/device/delta/x86_64-delta_ag9032v2a-r0/plugins/psuutil.py index 93936664c1c5..06655c07a416 100644 --- a/device/delta/x86_64-delta_ag9032v2a-r0/plugins/psuutil.py +++ b/device/delta/x86_64-delta_ag9032v2a-r0/plugins/psuutil.py @@ -9,7 +9,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" @@ -52,7 +53,6 @@ def get_psu_status(self, index): return False return status == 1 - def get_psu_presence(self, index): """ Retrieves the presence status of power supply unit (PSU) defined @@ -72,14 +72,13 @@ def get_psu_presence(self, index): if index == 1: mask = (1 << 7) if reg_value & mask == 0x80: - return False + return False else: mask = (1 << 3) if reg_value & mask == 0x08: - return False + return False status = 1 p.close() except IOError: return False return status == 1 - diff --git a/device/delta/x86_64-delta_ag9032v2a-r0/plugins/sfputil.py b/device/delta/x86_64-delta_ag9032v2a-r0/plugins/sfputil.py index 9abaa8cf01c1..ace5d9f3736b 100644 --- a/device/delta/x86_64-delta_ag9032v2a-r0/plugins/sfputil.py +++ b/device/delta/x86_64-delta_ag9032v2a-r0/plugins/sfputil.py @@ -31,7 +31,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(0, self.PORT_END - self.PORT_START + 1) + return list(range(0, self.PORT_END - self.PORT_START + 1)) @property def port_to_eeprom_mapping(self): @@ -53,7 +53,7 @@ def get_presence(self, port_num): try: reg_file = open("/sys/devices/platform/delta-ag9032v2a-swpld1.0/sfp_is_present") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -78,7 +78,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open("/sys/devices/platform/delta-ag9032v2a-swpld1.0/qsfp_lpmode") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) content = reg_file.readline().rstrip() @@ -102,7 +102,7 @@ def set_low_power_mode(self, port_num, lpmode): try: reg_file = open("/sys/devices/platform/delta-ag9032v2a-swpld1.0/qsfp_lpmode", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -138,7 +138,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -164,7 +164,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_value | mask diff --git a/device/delta/x86_64-delta_ag9064-r0/plugins/eeprom.py b/device/delta/x86_64-delta_ag9064-r0/plugins/eeprom.py index e4048ed302de..9a3ea5737684 100644 --- a/device/delta/x86_64-delta_ag9064-r0/plugins/eeprom.py +++ b/device/delta/x86_64-delta_ag9064-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Mellanox # @@ -10,7 +8,6 @@ ############################################################################# try: - import exceptions import binascii import time import optparse @@ -20,13 +17,14 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 def __init__(self, name, path, cpld_root, ro): - self.eeprom_path = "/sys/devices/pci0000:00/0000:00:1f.3/i2c-0/0-0056/eeprom" - super(board, self).__init__(self.eeprom_path, 0, '', True) + self.eeprom_path = "/sys/devices/pci0000:00/0000:00:1f.3/i2c-0/0-0056/eeprom" + super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/delta/x86_64-delta_ag9064-r0/plugins/psuutil.py b/device/delta/x86_64-delta_ag9064-r0/plugins/psuutil.py index 2a2bd1eea6a2..43f7bb6acb3c 100644 --- a/device/delta/x86_64-delta_ag9064-r0/plugins/psuutil.py +++ b/device/delta/x86_64-delta_ag9064-r0/plugins/psuutil.py @@ -9,7 +9,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" @@ -44,15 +45,13 @@ def get_psu_status(self, index): content = p.readline().rstrip() reg_value = int(content) if reg_value != 0: - return False + return False status = 1 p.close() except IOError: return False return status == 1 - - def get_psu_presence(self, index): """ Retrieves the presence status of power supply unit (PSU) defined @@ -75,4 +74,3 @@ def get_psu_presence(self, index): except IOError: return False return status == 1 - diff --git a/device/delta/x86_64-delta_ag9064-r0/plugins/sfputil.py b/device/delta/x86_64-delta_ag9064-r0/plugins/sfputil.py index 8b1b1aea1d82..f86fac5f2af2 100644 --- a/device/delta/x86_64-delta_ag9064-r0/plugins/sfputil.py +++ b/device/delta/x86_64-delta_ag9064-r0/plugins/sfputil.py @@ -31,7 +31,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(0, self.PORTS_IN_BLOCK + 1) + return list(range(0, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -53,7 +53,7 @@ def get_presence(self, port_num): try: reg_file = open("/sys/devices/platform/delta-ag9064-cpld.0/qsfp_present") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -78,7 +78,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open("/sys/devices/platform/delta-ag9064-cpld.0/qsfp_lpmode") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) content = reg_file.readline().rstrip() @@ -102,7 +102,7 @@ def set_low_power_mode(self, port_num, lpmode): try: reg_file = open("/sys/devices/platform/delta-ag9064-cpld.0/qsfp_lpmode", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -138,7 +138,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -164,7 +164,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_value | mask diff --git a/device/delta/x86_64-delta_agc032-r0/plugins/eeprom.py b/device/delta/x86_64-delta_agc032-r0/plugins/eeprom.py index 631adbfc6bbd..c252fd69f678 100644 --- a/device/delta/x86_64-delta_agc032-r0/plugins/eeprom.py +++ b/device/delta/x86_64-delta_agc032-r0/plugins/eeprom.py @@ -1,12 +1,12 @@ -#!/usr/bin/env python - try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/devices/pci0000:00/0000:00:1f.3/i2c-0/0-0053/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/delta/x86_64-delta_agc032-r0/plugins/psuutil.py b/device/delta/x86_64-delta_agc032-r0/plugins/psuutil.py index 0636417def1f..0cb47cad1bf9 100644 --- a/device/delta/x86_64-delta_agc032-r0/plugins/psuutil.py +++ b/device/delta/x86_64-delta_agc032-r0/plugins/psuutil.py @@ -3,7 +3,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" @@ -16,7 +17,6 @@ def __init__(self): self.psu_oper_status2 = "in2_input" self.psu_presence = "i2cget -y {} 0x50 0x00" - def get_num_psus(self): """ Retrieves the number of PSUs available on the device @@ -30,14 +30,14 @@ def get_psu_status(self, index): return False Base_bus_number = 0 status = 0 - #index from 1, psu attribute bus from 40 + # index from 1, psu attribute bus from 40 try: with open(self.psu_path.format(index + Base_bus_number) + self.psu_oper_status, 'r') as power_status: - if int(power_status.read()) == 0 : + if int(power_status.read()) == 0: return False else: with open(self.psu_path.format(index + Base_bus_number) + self.psu_oper_status2, 'r') as power_status2: - if int(power_status2.read()) == 0 : + if int(power_status2.read()) == 0: return False else: status = 1 @@ -51,12 +51,10 @@ def get_psu_presence(self, index): Base_bus_number = 0 status = 0 try: - p = os.popen(self.psu_presence.format(index + Base_bus_number)+ "> /dev/null 2>&1") + p = os.popen(self.psu_presence.format(index + Base_bus_number) + "> /dev/null 2>&1") if p.readline() != None: status = 1 p.close() except IOError: return False return status == 1 - - diff --git a/device/delta/x86_64-delta_agc032-r0/plugins/sfputil.py b/device/delta/x86_64-delta_agc032-r0/plugins/sfputil.py index a448d4101939..e9b02c6c77c6 100644 --- a/device/delta/x86_64-delta_agc032-r0/plugins/sfputil.py +++ b/device/delta/x86_64-delta_agc032-r0/plugins/sfputil.py @@ -13,6 +13,7 @@ except ImportError as e: raise ImportError("%s - required module not found" % str(e)) + class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" @@ -36,7 +37,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(0, self.PORTS_IN_BLOCK) + return list(range(0, self.PORTS_IN_BLOCK)) @property def port_to_eeprom_mapping(self): @@ -58,7 +59,7 @@ def get_presence(self, port_num): port = (str(port_num + 1)).zfill(2) # SWPLD2 for port 1~16, SWPLD3 for port 17~34 - if port_num < 16: + if port_num < 16: present_path = "SWPLD2/qsfp_p{}_modprs".format(port) elif port_num < self.PORTS_IN_BLOCK: present_path = "SWPLD3/qsfp_p{}_modprs".format(port) @@ -70,7 +71,7 @@ def get_presence(self, port_num): if int(present.readline()) == 0: return True except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False return False @@ -87,14 +88,14 @@ def get_low_power_mode(self, port_num): if port_num < 16: lpmode_path = "SWPLD2/qsfp_p{}_lpmode".format(port) else: - lpmode_path = "SWPLD3/qsfp_p{}_lpmode".format(port) + lpmode_path = "SWPLD3/qsfp_p{}_lpmode".format(port) try: with open("/sys/devices/platform/delta-agc032-swpld.0/" + lpmode_path, 'r') as lpmode: if int(lpmode.readline()) == 1: return True except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False return False @@ -111,12 +112,12 @@ def set_low_power_mode(self, port_num, lpmode): if port_num < 16: lpmode_path = "SWPLD2/qsfp_p{}_lpmode".format(port) else: - lpmode_path = "SWPLD3/qsfp_p{}_lpmode".format(port) + lpmode_path = "SWPLD3/qsfp_p{}_lpmode".format(port) try: file = open("/sys/devices/platform/delta-agc032-swpld.0/" + lpmode_path, 'r+') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False file.seek(0) @@ -143,12 +144,12 @@ def reset(self, port_num): if port_num < 16: reset_path = "SWPLD2/qsfp_p{}_rst".format(port) else: - reset_path = "SWPLD3/qsfp_p{}_rst".format(port) + reset_path = "SWPLD3/qsfp_p{}_rst".format(port) try: file = open("/sys/devices/platform/delta-agc032-swpld.0/" + reset_path, 'r+') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False file.seek(0) @@ -162,7 +163,7 @@ def reset(self, port_num): try: file = open("/sys/devices/platform/delta-agc032-swpld.0/" + reset_path, 'r+') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False file.seek(0) @@ -177,7 +178,7 @@ def get_eeprom_dict(self, port_num): try: file = open("/sys/devices/platform/delta-agc032-cpupld.0/cpu_i2c_mux_sel", 'r+') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # Switch CPLD to FRONT-PORT EEPROM MUX @@ -191,7 +192,7 @@ def get_eeprom_dict(self, port_num): try: file = open("/sys/devices/platform/delta-agc032-cpupld.0/cpu_i2c_mux_sel", 'r+') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # Switch CPLD to FRONT-PORT EEPROM MUX diff --git a/device/delta/x86_64-delta_et-6248brb-r0/plugins/eeprom.py b/device/delta/x86_64-delta_et-6248brb-r0/plugins/eeprom.py index 11c9285f47db..3b4b15ee543b 100644 --- a/device/delta/x86_64-delta_et-6248brb-r0/plugins/eeprom.py +++ b/device/delta/x86_64-delta_et-6248brb-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Mellanox # @@ -10,7 +8,6 @@ ############################################################################# try: - import exceptions import binascii import time import optparse @@ -20,13 +17,14 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 def __init__(self, name, path, cpld_root, ro): - self.eeprom_path = "/sys/devices/pci0000:00/0000:00:13.0/i2c-1/1-0054/eeprom" - super(board, self).__init__(self.eeprom_path, 0, '', True) + self.eeprom_path = "/sys/devices/pci0000:00/0000:00:13.0/i2c-1/1-0054/eeprom" + super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/delta/x86_64-delta_et-6248brb-r0/plugins/psuutil.py b/device/delta/x86_64-delta_et-6248brb-r0/plugins/psuutil.py index 99e8f1d17dd8..c6ec180bfc06 100644 --- a/device/delta/x86_64-delta_et-6248brb-r0/plugins/psuutil.py +++ b/device/delta/x86_64-delta_et-6248brb-r0/plugins/psuutil.py @@ -3,7 +3,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" @@ -15,7 +16,6 @@ def __init__(self): self.psu_oper_status = "in1_input" self.psu_presence = "/sys/devices/platform/delta-et6248brb-gpio.0/PSU/psu{}_pres" - def get_num_psus(self): """ Retrieves the number of PSUs available on the device @@ -31,7 +31,7 @@ def get_psu_status(self, index): try: reg_file = open(self.psu_path.format(index)) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False if int(reg_file.readline()) == 1: @@ -46,7 +46,7 @@ def get_psu_presence(self, index): try: reg_file = open(self.psu_presence.format(index)) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False if int(reg_file.readline()) == 0: diff --git a/device/delta/x86_64-delta_et-6248brb-r0/plugins/sfputil.py b/device/delta/x86_64-delta_et-6248brb-r0/plugins/sfputil.py index 84a3bfc3dac0..c8d30d3beeeb 100644 --- a/device/delta/x86_64-delta_et-6248brb-r0/plugins/sfputil.py +++ b/device/delta/x86_64-delta_et-6248brb-r0/plugins/sfputil.py @@ -31,7 +31,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(0) + return list(range(0)) @property def port_to_eeprom_mapping(self): @@ -52,13 +52,13 @@ def get_presence(self, port_num): # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False - + presence_path = "/sys/devices/platform/delta-et6248brb-gpio.0/SFP/sfp_mod_p{}" try: reg_file = open(presence_path.format(port_num - 47)) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False if int(reg_file.readline()) == 0: diff --git a/device/delta/x86_64-delta_et-c032if-r0/plugins/eeprom.py b/device/delta/x86_64-delta_et-c032if-r0/plugins/eeprom.py index 1a624414637c..23376fcd7236 100644 --- a/device/delta/x86_64-delta_et-c032if-r0/plugins/eeprom.py +++ b/device/delta/x86_64-delta_et-c032if-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Mellanox # @@ -10,7 +8,6 @@ ############################################################################# try: - import exceptions import binascii import time import optparse @@ -20,13 +17,14 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 def __init__(self, name, path, cpld_root, ro): - self.eeprom_path = "/sys/devices/pci0000:00/0000:00:1f.3/i2c-0/i2c-10/10-0053/eeprom" - super(board, self).__init__(self.eeprom_path, 0, '', True) + self.eeprom_path = "/sys/devices/pci0000:00/0000:00:1f.3/i2c-0/i2c-10/10-0053/eeprom" + super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/delta/x86_64-delta_et-c032if-r0/plugins/psuutil.py b/device/delta/x86_64-delta_et-c032if-r0/plugins/psuutil.py index 80383aaffddf..4eb3bb87db80 100644 --- a/device/delta/x86_64-delta_et-c032if-r0/plugins/psuutil.py +++ b/device/delta/x86_64-delta_et-c032if-r0/plugins/psuutil.py @@ -9,7 +9,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" @@ -44,15 +45,13 @@ def get_psu_status(self, index): reg_value = int(content, 16) mask = (1 << (8 - index)) if reg_value & mask == 0: - return False + return False status = 1 p.close() except IOError: return False return status == 1 - - def get_psu_presence(self, index): """ Retrieves the presence status of power supply unit (PSU) defined @@ -75,4 +74,3 @@ def get_psu_presence(self, index): except IOError: return False return status == 1 - diff --git a/device/delta/x86_64-delta_et-c032if-r0/plugins/sfputil.py b/device/delta/x86_64-delta_et-c032if-r0/plugins/sfputil.py index 4802c3a8f0ce..25b1ba3abdeb 100644 --- a/device/delta/x86_64-delta_et-c032if-r0/plugins/sfputil.py +++ b/device/delta/x86_64-delta_et-c032if-r0/plugins/sfputil.py @@ -16,7 +16,7 @@ class SfpUtil(SfpUtilBase): PORT_START = 0 PORT_START_SFP = 32 - PORT_END = 33 + PORT_END = 33 PORTS_IN_BLOCK = 34 EEPROM_OFFSET = 1 @@ -38,7 +38,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(0, self.PORTS_IN_BLOCK + 1) + return list(range(0, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -51,7 +51,7 @@ def get_transceiver_status(self): reg_file = open("/sys/devices/platform/delta-et-c032if-cpld.0/sfp_is_present") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -60,7 +60,6 @@ def get_transceiver_status(self): return int(content, 16) - def __init__(self): eeprom_path = "/sys/kernel/sfp/eeprom_sfp_{0}" @@ -78,7 +77,7 @@ def get_presence(self, port_num): try: reg_file = open("/sys/devices/platform/delta-et-c032if-cpld.0/sfp_is_present") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -103,7 +102,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open("/sys/devices/platform/delta-et-c032if-cpld.0/sfp_lp_mode") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) content = reg_file.readline().rstrip() @@ -127,7 +126,7 @@ def set_low_power_mode(self, port_num, lpmode): try: reg_file = open("/sys/devices/platform/delta-et-c032if-cpld.0/sfp_lp_mode", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -163,7 +162,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -189,7 +188,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_value | mask @@ -207,17 +206,17 @@ def get_transceiver_change_event(self, timeout=0): if timeout == 0: forever = True elif timeout > 0: - timeout = timeout / float(1000) # Convert to secs + timeout = timeout / float(1000) # Convert to secs else: - print "get_transceiver_change_event:Invalid timeout value", timeout + print("get_transceiver_change_event:Invalid timeout value", timeout) return False, {} end_time = start_time + timeout if start_time > end_time: - print 'get_transceiver_change_event:' \ - 'time wrap / invalid timeout value', timeout + print('get_transceiver_change_event:' + 'time wrap / invalid timeout value', timeout) - return False, {} # Time wrap or possibly incorrect timeout + return False, {} # Time wrap or possibly incorrect timeout while timeout >= 0: # Check for OIR events and return updated port_dict reg_value = self.get_transceiver_status @@ -246,10 +245,10 @@ def get_transceiver_change_event(self, timeout=0): else: timeout = end_time - time.time() if timeout >= 1: - time.sleep(1) # We poll at 1 second granularity + time.sleep(1) # We poll at 1 second granularity else: if timeout > 0: time.sleep(timeout) return True, {} - print "get_transceiver_change_event: Should not reach here." + print("get_transceiver_change_event: Should not reach here.") return False, {} diff --git a/device/ingrasys/x86_64-ingrasys_s8810_32q-r0/plugins/eeprom.py b/device/ingrasys/x86_64-ingrasys_s8810_32q-r0/plugins/eeprom.py index 4f919ccd7273..8f9ee7d9989b 100644 --- a/device/ingrasys/x86_64-ingrasys_s8810_32q-r0/plugins/eeprom.py +++ b/device/ingrasys/x86_64-ingrasys_s8810_32q-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Ingrasys S8810-32Q # @@ -11,8 +9,8 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/ingrasys/x86_64-ingrasys_s8810_32q-r0/plugins/psuutil.py b/device/ingrasys/x86_64-ingrasys_s8810_32q-r0/plugins/psuutil.py index 7e69360b0402..fcf9136d25db 100644 --- a/device/ingrasys/x86_64-ingrasys_s8810_32q-r0/plugins/psuutil.py +++ b/device/ingrasys/x86_64-ingrasys_s8810_32q-r0/plugins/psuutil.py @@ -20,12 +20,12 @@ class PsuUtil(PsuBase): def __init__(self): PsuBase.__init__(self) - - + # Get sysfs attribute + def get_attr_value(self, attr_path): - - retval = 'ERR' + + retval = 'ERR' if (not os.path.isfile(attr_path)): return retval @@ -55,16 +55,16 @@ def get_psu_status(self, index): faulty """ status = 0 - attr_file = 'psu_pg' - attr_path = self.SYSFS_PSU_DIR[index-1] +'/' + attr_file - + attr_file = 'psu_pg' + attr_path = self.SYSFS_PSU_DIR[index-1] + '/' + attr_file + attr_value = self.get_attr_value(attr_path) - + if (attr_value != 'ERR'): attr_value = int(attr_value, 16) # Check for PSU status if (attr_value == 1): - status = 1 + status = 1 return status @@ -77,16 +77,15 @@ def get_psu_presence(self, index): """ status = 0 psu_absent = 0 - attr_file ='psu_abs' - attr_path = self.SYSFS_PSU_DIR[index-1] +'/' + attr_file - + attr_file = 'psu_abs' + attr_path = self.SYSFS_PSU_DIR[index-1] + '/' + attr_file + attr_value = self.get_attr_value(attr_path) if (attr_value != 'ERR'): attr_value = int(attr_value, 16) # Check for PSU presence if (attr_value == 0): - status = 1 + status = 1 return status - diff --git a/device/ingrasys/x86_64-ingrasys_s8810_32q-r0/plugins/sfputil.py b/device/ingrasys/x86_64-ingrasys_s8810_32q-r0/plugins/sfputil.py index 8d195f644e18..c1afbdf0738d 100644 --- a/device/ingrasys/x86_64-ingrasys_s8810_32q-r0/plugins/sfputil.py +++ b/device/ingrasys/x86_64-ingrasys_s8810_32q-r0/plugins/sfputil.py @@ -26,7 +26,7 @@ class SfpUtil(SfpUtilBase): LP_GPIO_BASE = 160 RST_GPIO_BASE = 128 GPIO_OFFSET = 0 - + BASE_DIR_PATH = "/sys/class/gpio/gpio{0}/direction" BASE_VAL_PATH = "/sys/class/gpio/gpio{0}/value" @@ -42,7 +42,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(0, self.PORTS_IN_BLOCK + 1) + return list(range(0, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -55,11 +55,11 @@ def set_gpio_offset(self): for d in os.listdir(sys_gpio_dir): if "gpiochip" in d: try: - gpiochip_no = int(d[8:],10) + gpiochip_no = int(d[8:], 10) except ValueError as e: - print "Error: %s" % str(e) + print("Error: %s" % str(e)) if gpiochip_no > 255: - self.GPIO_OFFSET=256 + self.GPIO_OFFSET = 256 return True return True @@ -89,10 +89,10 @@ def get_presence(self, port_num): try: abs_device_file = self.BASE_VAL_PATH.format( - port_num + self.ABS_GPIO_BASE) + port_num + self.ABS_GPIO_BASE) val_file = open(abs_device_file) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = val_file.readline().rstrip() @@ -110,14 +110,14 @@ def get_low_power_mode(self, port_num): try: lpmode_val_device_file = self.BASE_VAL_PATH.format( - port_num + self.LP_GPIO_BASE) + port_num + self.LP_GPIO_BASE) val_file = open(lpmode_val_device_file) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False - + content = val_file.readline().rstrip() - + # content is a string, either "0" or "1" if content == "1": return True @@ -131,12 +131,12 @@ def set_low_power_mode(self, port_num, lpmode): try: lpmode_val_device_file = self.BASE_VAL_PATH.format( - port_num + self.LP_GPIO_BASE) + port_num + self.LP_GPIO_BASE) val_file = open(lpmode_val_device_file, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False - + val_file.write("1" if lpmode is True else "0") val_file.close() @@ -146,29 +146,29 @@ def reset(self, port_num): # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False - + try: reset_val_device_file = self.BASE_VAL_PATH.format( - port_num + self.RST_GPIO_BASE) + port_num + self.RST_GPIO_BASE) val_file = open(reset_val_device_file, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False - + val_file.write("1") val_file.close() - + # Sleep 1 second to allow it to settle time.sleep(1) - + try: reset_val_device_file = self.BASE_VAL_PATH.format( - port_num + self.RST_GPIO_BASE) + port_num + self.RST_GPIO_BASE) val_file = open(reset_val_device_file, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False - + val_file.write("0") val_file.close() diff --git a/device/ingrasys/x86_64-ingrasys_s8900_54xc-r0/plugins/eeprom.py b/device/ingrasys/x86_64-ingrasys_s8900_54xc-r0/plugins/eeprom.py index 414ff38221bf..fcfaf8a27947 100644 --- a/device/ingrasys/x86_64-ingrasys_s8900_54xc-r0/plugins/eeprom.py +++ b/device/ingrasys/x86_64-ingrasys_s8900_54xc-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Dell Z9100 # @@ -11,8 +9,8 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/ingrasys/x86_64-ingrasys_s8900_54xc-r0/plugins/psuutil.py b/device/ingrasys/x86_64-ingrasys_s8900_54xc-r0/plugins/psuutil.py index 4f226c69fff3..ef45a0c91727 100644 --- a/device/ingrasys/x86_64-ingrasys_s8900_54xc-r0/plugins/psuutil.py +++ b/device/ingrasys/x86_64-ingrasys_s8900_54xc-r0/plugins/psuutil.py @@ -19,12 +19,12 @@ class PsuUtil(PsuBase): def __init__(self): PsuBase.__init__(self) - - + # Get sysfs attribute + def get_attr_value(self, attr_path): - - retval = 'ERR' + + retval = 'ERR' if (not os.path.isfile(attr_path)): return retval @@ -54,17 +54,17 @@ def get_psu_status(self, index): faulty """ status = 0 - mask = [ 0x08, 0x10 ] - attr_file = 'cpld_pw_good' - attr_path = self.PSU_CPLD_DIR +'/'+ attr_file - + mask = [0x08, 0x10] + attr_file = 'cpld_pw_good' + attr_path = self.PSU_CPLD_DIR + '/' + attr_file + attr_value = self.get_attr_value(attr_path) - + if (attr_value != 'ERR'): attr_value = int(attr_value, 16) # Check for PSU status if (attr_value & mask[index-1]): - status = 1 + status = 1 return status @@ -76,17 +76,16 @@ def get_psu_presence(self, index): :return: Boolean, True if PSU is plugged, False if not """ status = 0 - mask = [ 0x01, 0x02 ] - attr_file ='cpld_pw_abs' - attr_path = self.PSU_CPLD_DIR +'/'+ attr_file - + mask = [0x01, 0x02] + attr_file = 'cpld_pw_abs' + attr_path = self.PSU_CPLD_DIR + '/' + attr_file + attr_value = self.get_attr_value(attr_path) if (attr_value != 'ERR'): attr_value = int(attr_value, 16) # Check for PSU presence if (~attr_value & mask[index-1]): - status = 1 + status = 1 return status - diff --git a/device/ingrasys/x86_64-ingrasys_s8900_54xc-r0/plugins/sfputil.py b/device/ingrasys/x86_64-ingrasys_s8900_54xc-r0/plugins/sfputil.py index 586e6e189743..c7a4dfa471b6 100644 --- a/device/ingrasys/x86_64-ingrasys_s8900_54xc-r0/plugins/sfputil.py +++ b/device/ingrasys/x86_64-ingrasys_s8900_54xc-r0/plugins/sfputil.py @@ -20,7 +20,7 @@ class SfpUtil(SfpUtilBase): QSFP_PORT_START = 48 PORTS_IN_BLOCK = 54 GPIO_OFFSET = 0 - + BASE_DIR_PATH = "/sys/class/gpio/gpio{0}/direction" BASE_VAL_PATH = "/sys/class/gpio/gpio{0}/value" @@ -100,7 +100,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -113,11 +113,11 @@ def set_gpio_offset(self): for d in os.listdir(sys_gpio_dir): if "gpiochip" in d: try: - gpiochip_no = int(d[8:],10) + gpiochip_no = int(d[8:], 10) except ValueError as e: - print "Error: %s" % str(e) + print("Error: %s" % str(e)) if gpiochip_no > 255: - self.GPIO_OFFSET=256 + self.GPIO_OFFSET = 256 return True return True @@ -179,7 +179,7 @@ def init_abs_to_gpio_mapping(self): 53: 245+self.GPIO_OFFSET } return True - + def init_lpmode_to_gpio_mapping(self): self.lpmode_to_gpio_mapping = { 48: 224+self.GPIO_OFFSET, @@ -190,7 +190,7 @@ def init_lpmode_to_gpio_mapping(self): 53: 229+self.GPIO_OFFSET } return True - + def init_reset_to_gpio_mapping(self): self.reset_to_gpio_mapping = { 48: 208+self.GPIO_OFFSET, @@ -225,10 +225,10 @@ def get_presence(self, port_num): try: abs_device_file = self.BASE_VAL_PATH.format( - self.abs_to_gpio_mapping[port_num]) + self.abs_to_gpio_mapping[port_num]) val_file = open(abs_device_file) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = val_file.readline().rstrip() @@ -246,14 +246,14 @@ def get_low_power_mode(self, port_num): try: lpmode_val_device_file = self.BASE_VAL_PATH.format( - self.lpmode_to_gpio_mapping[port_num]) + self.lpmode_to_gpio_mapping[port_num]) val_file = open(lpmode_val_device_file) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False - + content = val_file.readline().rstrip() - + # content is a string, either "0" or "1" if content == "1": return True @@ -267,12 +267,12 @@ def set_low_power_mode(self, port_num, lpmode): try: lpmode_val_device_file = self.BASE_VAL_PATH.format( - self.lpmode_to_gpio_mapping[port_num]) + self.lpmode_to_gpio_mapping[port_num]) val_file = open(lpmode_val_device_file, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False - + val_file.write("1" if lpmode is True else "0") val_file.close() @@ -281,32 +281,32 @@ def set_low_power_mode(self, port_num, lpmode): def reset(self, port_num): # Check for invalid port_num if port_num < self.qsfp_port_start or port_num > self.port_end: - print "Error: unable to reset non-QSFP module: port %s" % str(port_num) + print("Error: unable to reset non-QSFP module: port %s" % str(port_num)) return False - + try: - print "port %s" % str(port_num) + print("port %s" % str(port_num)) reset_val_device_file = self.BASE_VAL_PATH.format( - self.reset_to_gpio_mapping[port_num]) + self.reset_to_gpio_mapping[port_num]) val_file = open(reset_val_device_file, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False - + val_file.write("1") val_file.close() - + # Sleep 1 second to allow it to settle time.sleep(1) - + try: reset_val_device_file = self.BASE_VAL_PATH.format( - self.reset_to_gpio_mapping[port_num]) + self.reset_to_gpio_mapping[port_num]) val_file = open(reset_val_device_file, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False - + val_file.write("0") val_file.close() diff --git a/device/ingrasys/x86_64-ingrasys_s8900_64xc-r0/plugins/eeprom.py b/device/ingrasys/x86_64-ingrasys_s8900_64xc-r0/plugins/eeprom.py index 1b8de3f16bca..1737549081a6 100644 --- a/device/ingrasys/x86_64-ingrasys_s8900_64xc-r0/plugins/eeprom.py +++ b/device/ingrasys/x86_64-ingrasys_s8900_64xc-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Ingrasys S8900-64XC # @@ -11,8 +9,8 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/ingrasys/x86_64-ingrasys_s8900_64xc-r0/plugins/psuutil.py b/device/ingrasys/x86_64-ingrasys_s8900_64xc-r0/plugins/psuutil.py index 3af5423daebd..e97e3193fd64 100644 --- a/device/ingrasys/x86_64-ingrasys_s8900_64xc-r0/plugins/psuutil.py +++ b/device/ingrasys/x86_64-ingrasys_s8900_64xc-r0/plugins/psuutil.py @@ -19,12 +19,12 @@ class PsuUtil(PsuBase): def __init__(self): PsuBase.__init__(self) - - + # Get sysfs attribute + def get_attr_value(self, attr_path): - - retval = 'ERR' + + retval = 'ERR' if (not os.path.isfile(attr_path)): return retval @@ -54,17 +54,17 @@ def get_psu_status(self, index): faulty """ status = 0 - mask = [ 0x04, 0x08 ] - attr_file = 'cpld_pw_good' - attr_path = self.PSU_CPLD_DIR +'/'+ attr_file - + mask = [0x04, 0x08] + attr_file = 'cpld_pw_good' + attr_path = self.PSU_CPLD_DIR + '/' + attr_file + attr_value = self.get_attr_value(attr_path) - + if (attr_value != 'ERR'): attr_value = int(attr_value, 16) # Check for PSU status if (attr_value & mask[index-1]): - status = 1 + status = 1 return status @@ -76,17 +76,16 @@ def get_psu_presence(self, index): :return: Boolean, True if PSU is plugged, False if not """ status = 0 - mask = [ 0x01, 0x02 ] - attr_file ='cpld_pw_abs' - attr_path = self.PSU_CPLD_DIR +'/'+ attr_file - + mask = [0x01, 0x02] + attr_file = 'cpld_pw_abs' + attr_path = self.PSU_CPLD_DIR + '/' + attr_file + attr_value = self.get_attr_value(attr_path) if (attr_value != 'ERR'): attr_value = int(attr_value, 16) # Check for PSU presence if (~attr_value & mask[index-1]): - status = 1 + status = 1 return status - diff --git a/device/ingrasys/x86_64-ingrasys_s8900_64xc-r0/plugins/sfputil.py b/device/ingrasys/x86_64-ingrasys_s8900_64xc-r0/plugins/sfputil.py index 26355bf441e6..cc2c01d3bd33 100644 --- a/device/ingrasys/x86_64-ingrasys_s8900_64xc-r0/plugins/sfputil.py +++ b/device/ingrasys/x86_64-ingrasys_s8900_64xc-r0/plugins/sfputil.py @@ -16,6 +16,7 @@ cpld_addr = '0x33' mux_reg = '0x4A' + class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" @@ -26,70 +27,70 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} port_to_i2c_mapping = { - 0: [2,1], - 1: [2,2], - 2: [2,3], - 3: [2,4], - 4: [2,5], - 5: [2,6], - 6: [2,7], - 7: [2,8], - 8: [2,9], - 9: [2,10], - 10: [2,11], - 11: [2,12], - 12: [2,13], - 13: [2,14], - 14: [2,15], - 15: [2,16], - 16: [2,17], - 17: [2,18], - 18: [2,19], - 19: [2,20], - 20: [2,21], - 21: [2,22], - 22: [2,23], - 23: [2,24], - 24: [3,25], - 25: [3,26], - 26: [3,27], - 27: [3,28], - 28: [3,29], - 29: [3,30], - 30: [3,31], - 31: [3,32], - 32: [3,33], - 33: [3,34], - 34: [3,35], - 35: [3,36], - 36: [3,37], - 37: [3,38], - 38: [3,39], - 39: [3,40], - 40: [3,41], - 41: [3,42], - 42: [3,43], - 43: [3,44], - 44: [3,45], - 45: [3,46], - 46: [3,47], - 47: [3,48], - 48: [4,49], - 49: [4,50], - 50: [4,51], - 51: [4,52], - 52: [4,53], - 53: [4,54], - 54: [4,55], - 55: [4,56], - 56: [4,57], - 57: [4,58], - 58: [4,59], - 59: [4,60], - 60: [4,61], - 61: [4,62], - 62: [4,63], - 63: [4,64] + 0: [2, 1], + 1: [2, 2], + 2: [2, 3], + 3: [2, 4], + 4: [2, 5], + 5: [2, 6], + 6: [2, 7], + 7: [2, 8], + 8: [2, 9], + 9: [2, 10], + 10: [2, 11], + 11: [2, 12], + 12: [2, 13], + 13: [2, 14], + 14: [2, 15], + 15: [2, 16], + 16: [2, 17], + 17: [2, 18], + 18: [2, 19], + 19: [2, 20], + 20: [2, 21], + 21: [2, 22], + 22: [2, 23], + 23: [2, 24], + 24: [3, 25], + 25: [3, 26], + 26: [3, 27], + 27: [3, 28], + 28: [3, 29], + 29: [3, 30], + 30: [3, 31], + 31: [3, 32], + 32: [3, 33], + 33: [3, 34], + 34: [3, 35], + 35: [3, 36], + 36: [3, 37], + 37: [3, 38], + 38: [3, 39], + 39: [3, 40], + 40: [3, 41], + 41: [3, 42], + 42: [3, 43], + 43: [3, 44], + 44: [3, 45], + 45: [3, 46], + 46: [3, 47], + 47: [3, 48], + 48: [4, 49], + 49: [4, 50], + 50: [4, 51], + 51: [4, 52], + 52: [4, 53], + 53: [4, 54], + 54: [4, 55], + 55: [4, 56], + 56: [4, 57], + 57: [4, 58], + 58: [4, 59], + 59: [4, 60], + 60: [4, 61], + 61: [4, 62], + 62: [4, 63], + 63: [4, 64] } @property @@ -102,7 +103,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -133,7 +134,7 @@ def get_presence(self, port_num): try: reg_file = open("/sys/devices/platform/ingrasys-s8900-64xc-cpld.0/qsfp_modprs") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -158,7 +159,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open("/sys/devices/platform/ingrasys-s8900-64xc-cpld.0/qsfp_lpmode") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -167,7 +168,7 @@ def get_low_power_mode(self, port_num): reg_value = int(content, 16) # Mask off the bit corresponding to our port - mask = (1 << (port_num - self.qsfp_port_start) ) + mask = (1 << (port_num - self.qsfp_port_start)) # LPMode is active high if reg_value & mask == 0: @@ -183,7 +184,7 @@ def set_low_power_mode(self, port_num, lpmode): try: reg_file = open("/sys/devices/platform/ingrasys-s8900-64xc-cpld.0/qsfp_lpmode", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -192,7 +193,7 @@ def set_low_power_mode(self, port_num, lpmode): reg_value = int(content, 16) # Mask off the bit corresponding to our port - mask = (1 << (port_num - self.qsfp_port_start) ) + mask = (1 << (port_num - self.qsfp_port_start)) # LPMode is active high; set or clear the bit accordingly if lpmode is True: @@ -219,7 +220,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -245,7 +246,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_value | mask diff --git a/device/ingrasys/x86_64-ingrasys_s9100-r0/plugins/eeprom.py b/device/ingrasys/x86_64-ingrasys_s9100-r0/plugins/eeprom.py index 83bf65a389bd..1c23602fcb5a 100644 --- a/device/ingrasys/x86_64-ingrasys_s9100-r0/plugins/eeprom.py +++ b/device/ingrasys/x86_64-ingrasys_s9100-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Ingrasys S9100 # @@ -11,8 +9,8 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/ingrasys/x86_64-ingrasys_s9100-r0/plugins/psuutil.py b/device/ingrasys/x86_64-ingrasys_s9100-r0/plugins/psuutil.py index 4f226c69fff3..ef45a0c91727 100644 --- a/device/ingrasys/x86_64-ingrasys_s9100-r0/plugins/psuutil.py +++ b/device/ingrasys/x86_64-ingrasys_s9100-r0/plugins/psuutil.py @@ -19,12 +19,12 @@ class PsuUtil(PsuBase): def __init__(self): PsuBase.__init__(self) - - + # Get sysfs attribute + def get_attr_value(self, attr_path): - - retval = 'ERR' + + retval = 'ERR' if (not os.path.isfile(attr_path)): return retval @@ -54,17 +54,17 @@ def get_psu_status(self, index): faulty """ status = 0 - mask = [ 0x08, 0x10 ] - attr_file = 'cpld_pw_good' - attr_path = self.PSU_CPLD_DIR +'/'+ attr_file - + mask = [0x08, 0x10] + attr_file = 'cpld_pw_good' + attr_path = self.PSU_CPLD_DIR + '/' + attr_file + attr_value = self.get_attr_value(attr_path) - + if (attr_value != 'ERR'): attr_value = int(attr_value, 16) # Check for PSU status if (attr_value & mask[index-1]): - status = 1 + status = 1 return status @@ -76,17 +76,16 @@ def get_psu_presence(self, index): :return: Boolean, True if PSU is plugged, False if not """ status = 0 - mask = [ 0x01, 0x02 ] - attr_file ='cpld_pw_abs' - attr_path = self.PSU_CPLD_DIR +'/'+ attr_file - + mask = [0x01, 0x02] + attr_file = 'cpld_pw_abs' + attr_path = self.PSU_CPLD_DIR + '/' + attr_file + attr_value = self.get_attr_value(attr_path) if (attr_value != 'ERR'): attr_value = int(attr_value, 16) # Check for PSU presence if (~attr_value & mask[index-1]): - status = 1 + status = 1 return status - diff --git a/device/ingrasys/x86_64-ingrasys_s9100-r0/plugins/sfputil.py b/device/ingrasys/x86_64-ingrasys_s9100-r0/plugins/sfputil.py index 849bd13d94d3..f2da8544202c 100644 --- a/device/ingrasys/x86_64-ingrasys_s9100-r0/plugins/sfputil.py +++ b/device/ingrasys/x86_64-ingrasys_s9100-r0/plugins/sfputil.py @@ -73,7 +73,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(0, self.PORTS_IN_BLOCK + 1) + return list(range(0, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -86,11 +86,11 @@ def set_gpio_offset(self): for d in os.listdir(sys_gpio_dir): if "gpiochip" in d: try: - gpiochip_no = int(d[8:],10) + gpiochip_no = int(d[8:], 10) except ValueError as e: - print "Error: %s" % str(e) + print("Error: %s" % str(e)) if gpiochip_no > 255: - self.GPIO_OFFSET=256 + self.GPIO_OFFSET = 256 return True return True @@ -228,10 +228,10 @@ def get_presence(self, port_num): try: abs_device_file = self.BASE_VAL_PATH.format( - self.abs_to_gpio_mapping[port_num]) + self.abs_to_gpio_mapping[port_num]) val_file = open(abs_device_file) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = val_file.readline().rstrip() @@ -250,10 +250,10 @@ def get_low_power_mode(self, port_num): try: lpmode_val_device_file = self.BASE_VAL_PATH.format( - self.lpmode_to_gpio_mapping[port_num]) + self.lpmode_to_gpio_mapping[port_num]) val_file = open(lpmode_val_device_file) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = val_file.readline().rstrip() @@ -272,10 +272,10 @@ def set_low_power_mode(self, port_num, lpmode): try: lpmode_val_device_file = self.BASE_VAL_PATH.format( - self.lpmode_to_gpio_mapping[port_num]) + self.lpmode_to_gpio_mapping[port_num]) val_file = open(lpmode_val_device_file, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False val_file.write("1" if lpmode is True else "0") @@ -290,10 +290,10 @@ def reset(self, port_num): try: reset_val_device_file = self.BASE_VAL_PATH.format( - self.reset_to_gpio_mapping[port_num]) + self.reset_to_gpio_mapping[port_num]) val_file = open(reset_val_device_file, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False val_file.write("1") @@ -304,10 +304,10 @@ def reset(self, port_num): try: reset_val_device_file = self.BASE_VAL_PATH.format( - self.reset_to_gpio_mapping[port_num]) + self.reset_to_gpio_mapping[port_num]) val_file = open(reset_val_device_file, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False val_file.write("0") diff --git a/device/ingrasys/x86_64-ingrasys_s9130_32x-r0/plugins/eeprom.py b/device/ingrasys/x86_64-ingrasys_s9130_32x-r0/plugins/eeprom.py index 71ce941f1abb..7496ebe21ada 100644 --- a/device/ingrasys/x86_64-ingrasys_s9130_32x-r0/plugins/eeprom.py +++ b/device/ingrasys/x86_64-ingrasys_s9130_32x-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Ingrasys S9130-32X # @@ -11,8 +9,8 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/ingrasys/x86_64-ingrasys_s9130_32x-r0/plugins/psuutil.py b/device/ingrasys/x86_64-ingrasys_s9130_32x-r0/plugins/psuutil.py index 4a029c15b1a6..37e2173aa9d2 100644 --- a/device/ingrasys/x86_64-ingrasys_s9130_32x-r0/plugins/psuutil.py +++ b/device/ingrasys/x86_64-ingrasys_s9130_32x-r0/plugins/psuutil.py @@ -20,12 +20,12 @@ class PsuUtil(PsuBase): def __init__(self): PsuBase.__init__(self) - - + # Get sysfs attribute + def get_attr_value(self, attr_path): - - retval = 'ERR' + + retval = 'ERR' if (not os.path.isfile(attr_path)): return retval @@ -55,16 +55,16 @@ def get_psu_status(self, index): faulty """ status = 0 - attr_file = 'psu_pg' - attr_path = self.SYSFS_PSU_DIR[index-1] +'/' + attr_file - + attr_file = 'psu_pg' + attr_path = self.SYSFS_PSU_DIR[index-1] + '/' + attr_file + attr_value = self.get_attr_value(attr_path) - + if (attr_value != 'ERR'): attr_value = int(attr_value, 16) # Check for PSU status if (attr_value == 1): - status = 1 + status = 1 return status @@ -77,16 +77,15 @@ def get_psu_presence(self, index): """ status = 0 psu_absent = 0 - attr_file ='psu_abs' - attr_path = self.SYSFS_PSU_DIR[index-1] +'/' + attr_file - + attr_file = 'psu_abs' + attr_path = self.SYSFS_PSU_DIR[index-1] + '/' + attr_file + attr_value = self.get_attr_value(attr_path) if (attr_value != 'ERR'): attr_value = int(attr_value, 16) # Check for PSU presence if (attr_value == 0): - status = 1 + status = 1 return status - diff --git a/device/ingrasys/x86_64-ingrasys_s9130_32x-r0/plugins/sfputil.py b/device/ingrasys/x86_64-ingrasys_s9130_32x-r0/plugins/sfputil.py index 4827ad3bfa80..260c759c7993 100644 --- a/device/ingrasys/x86_64-ingrasys_s9130_32x-r0/plugins/sfputil.py +++ b/device/ingrasys/x86_64-ingrasys_s9130_32x-r0/plugins/sfputil.py @@ -41,7 +41,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(0, self.PORTS_IN_BLOCK + 1) + return list(range(0, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -49,16 +49,16 @@ def port_to_eeprom_mapping(self): def set_gpio_offset(self): sys_gpio_dir = "/sys/class/gpio" - self.GPIO_OFFSET = 0 - gpiochip_no = 0 + self.GPIO_OFFSET = 0 + gpiochip_no = 0 for d in os.listdir(sys_gpio_dir): if "gpiochip" in d: try: - gpiochip_no = int(d[8:],10) + gpiochip_no = int(d[8:], 10) except ValueError as e: - print "Error: %s" % str(e) + print("Error: %s" % str(e)) if gpiochip_no > 255: - self.GPIO_OFFSET=256 + self.GPIO_OFFSET = 256 return True return True @@ -92,14 +92,14 @@ def get_presence(self, port_num): # open corrsponding gpio file try: if port_num <= 15: - gpio_base = self.ABS_GPIO_BASE_0_15 - else : - gpio_base = self.ABS_GPIO_BASE_16_31 + gpio_base = self.ABS_GPIO_BASE_0_15 + else: + gpio_base = self.ABS_GPIO_BASE_16_31 gpio_index = gpio_base + (port_num % 16) gpio_file_path = self.GPIO_VAL_PATH.format(gpio_index) gpio_file = open(gpio_file_path) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # content is a string containing the gpio value @@ -121,13 +121,13 @@ def get_low_power_mode(self, port_num): try: if port_num <= 15: gpio_base = self.LP_MODE_GPIO_BASE_0_15 - else : + else: gpio_base = self.LP_MODE_GPIO_BASE_16_31 gpio_index = gpio_base + (port_num % 16) gpio_file_path = self.GPIO_VAL_PATH.format(gpio_index) gpio_file = open(gpio_file_path) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # content is a string containing the gpio value @@ -148,13 +148,13 @@ def set_low_power_mode(self, port_num, lpmode): try: if port_num <= 15: gpio_base = self.LP_MODE_GPIO_BASE_0_15 - else : + else: gpio_base = self.LP_MODE_GPIO_BASE_16_31 gpio_index = gpio_base + (port_num % 16) gpio_file_path = self.GPIO_VAL_PATH.format(gpio_index) gpio_file = open(gpio_file_path, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # the gpio pin is ACTIVE_HIGH @@ -179,13 +179,13 @@ def reset(self, port_num): try: if port_num <= 15: gpio_base = self.RST_GPIO_BASE_0_15 - else : + else: gpio_base = self.RST_GPIO_BASE_16_31 gpio_index = gpio_base + (port_num % 16) gpio_file_path = self.GPIO_VAL_PATH.format(gpio_index) gpio_file = open(gpio_file_path, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # set the gpio to take port into reset @@ -203,13 +203,13 @@ def reset(self, port_num): try: gpio_file = open(gpio_file_path, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # set gpio back low to take port out of reset # the gpio pin is ACTIVE_LOW but reversed gpio_val = "0" - # write value to gpio + # write value to gpio gpio_file.seek(0) gpio_file.write(gpio_val) gpio_file.close() diff --git a/device/ingrasys/x86_64-ingrasys_s9180_32x-r0/plugins/eeprom.py b/device/ingrasys/x86_64-ingrasys_s9180_32x-r0/plugins/eeprom.py index d1270eeffbf6..f3fb959c2d01 100644 --- a/device/ingrasys/x86_64-ingrasys_s9180_32x-r0/plugins/eeprom.py +++ b/device/ingrasys/x86_64-ingrasys_s9180_32x-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Ingrasys S9180-32X # @@ -11,8 +9,8 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/ingrasys/x86_64-ingrasys_s9180_32x-r0/plugins/psuutil.py b/device/ingrasys/x86_64-ingrasys_s9180_32x-r0/plugins/psuutil.py index 25cdfb031882..3ac4fa48afd0 100644 --- a/device/ingrasys/x86_64-ingrasys_s9180_32x-r0/plugins/psuutil.py +++ b/device/ingrasys/x86_64-ingrasys_s9180_32x-r0/plugins/psuutil.py @@ -20,16 +20,16 @@ class PsuUtil(PsuBase): def set_gpio_offset(self): sys_gpio_dir = "/sys/class/gpio" - self.GPIO_OFFSET = 0 - gpiochip_no = 0 + self.GPIO_OFFSET = 0 + gpiochip_no = 0 for d in os.listdir(sys_gpio_dir): if "gpiochip" in d: try: - gpiochip_no = int(d[8:],10) + gpiochip_no = int(d[8:], 10) except ValueError as e: - print "Error: %s" % str(e) + print("Error: %s" % str(e)) if gpiochip_no > 255: - self.GPIO_OFFSET=256 + self.GPIO_OFFSET = 256 return True return True @@ -37,8 +37,8 @@ def __init__(self): self.set_gpio_offset() PsuBase.__init__(self) - # Get sysfs attribute + def get_attr_value(self, attr_path): retval = 'ERR' @@ -71,7 +71,7 @@ def get_psu_status(self, index): faulty """ status = 0 - gpio_path = [ 'gpio'+str(99+self.GPIO_OFFSET)+'/value', 'gpio'+str(96+self.GPIO_OFFSET)+'/value' ] + gpio_path = ['gpio'+str(99+self.GPIO_OFFSET)+'/value', 'gpio'+str(96+self.GPIO_OFFSET)+'/value'] attr_path = self.SYS_GPIO_DIR + gpio_path[index-1] attr_value = self.get_attr_value(attr_path) @@ -80,7 +80,7 @@ def get_psu_status(self, index): attr_value = int(attr_value, 10) # Check for PSU status if (attr_value == 1): - status = 1 + status = 1 return status @@ -92,7 +92,7 @@ def get_psu_presence(self, index): :return: Boolean, True if PSU is plugged, False if not """ status = 0 - gpio_path = [ 'gpio'+str(100+self.GPIO_OFFSET)+'/value', 'gpio'+str(97+self.GPIO_OFFSET)+'/value' ] + gpio_path = ['gpio'+str(100+self.GPIO_OFFSET)+'/value', 'gpio'+str(97+self.GPIO_OFFSET)+'/value'] attr_path = self.SYS_GPIO_DIR + gpio_path[index-1] attr_value = self.get_attr_value(attr_path) @@ -101,7 +101,6 @@ def get_psu_presence(self, index): attr_value = int(attr_value, 10) # Check for PSU status if (attr_value == 1): - status = 1 + status = 1 return status - diff --git a/device/ingrasys/x86_64-ingrasys_s9180_32x-r0/plugins/sfputil.py b/device/ingrasys/x86_64-ingrasys_s9180_32x-r0/plugins/sfputil.py index 00c5e10e0b0d..c061fcabd23a 100644 --- a/device/ingrasys/x86_64-ingrasys_s9180_32x-r0/plugins/sfputil.py +++ b/device/ingrasys/x86_64-ingrasys_s9180_32x-r0/plugins/sfputil.py @@ -76,11 +76,12 @@ def port_end(self): @property def qsfp_ports(self): - return range(0, self.PORTS_IN_BLOCK + 1) + return list(range(0, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): return self._port_to_eeprom_mapping + @property def sfp_port_start(self): return self.SFP_PORT_START @@ -92,11 +93,11 @@ def set_gpio_offset(self): for d in os.listdir(sys_gpio_dir): if "gpiochip" in d: try: - gpiochip_no = int(d[8:],10) + gpiochip_no = int(d[8:], 10) except ValueError as e: - print "Error: %s" % str(e) + print("Error: %s" % str(e)) if gpiochip_no > 255: - self.GPIO_OFFSET=256 + self.GPIO_OFFSET = 256 return True return True @@ -172,12 +173,12 @@ def init_lpmode_to_gpio_mapping(self): 28: 157+self.GPIO_OFFSET, 29: 156+self.GPIO_OFFSET, 30: 159+self.GPIO_OFFSET, - 31: 158+self.GPIO_OFFSET + 31: 158+self.GPIO_OFFSET } return True def init_reset_to_gpio_mapping(self): - self.reset_to_gpio_mapping = { + self.reset_to_gpio_mapping = { 0: 129+self.GPIO_OFFSET, 1: 128+self.GPIO_OFFSET, 2: 131+self.GPIO_OFFSET, @@ -209,7 +210,7 @@ def init_reset_to_gpio_mapping(self): 28: 125+self.GPIO_OFFSET, 29: 124+self.GPIO_OFFSET, 30: 127+self.GPIO_OFFSET, - 31: 126+self.GPIO_OFFSET + 31: 126+self.GPIO_OFFSET } return True @@ -236,10 +237,10 @@ def get_presence(self, port_num): try: abs_device_file = self.BASE_VAL_PATH.format( - self.abs_to_gpio_mapping[port_num]) + self.abs_to_gpio_mapping[port_num]) val_file = open(abs_device_file) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = val_file.readline().rstrip() @@ -253,15 +254,15 @@ def get_presence(self, port_num): def get_low_power_mode(self, port_num): # Check for invalid port_num - if port_num < self.port_start or port_num > self.sfp_port_start: # TBD + if port_num < self.port_start or port_num > self.sfp_port_start: # TBD return False try: lpmode_val_device_file = self.BASE_VAL_PATH.format( - self.lpmode_to_gpio_mapping[port_num]) + self.lpmode_to_gpio_mapping[port_num]) val_file = open(lpmode_val_device_file) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = val_file.readline().rstrip() @@ -275,15 +276,15 @@ def get_low_power_mode(self, port_num): def set_low_power_mode(self, port_num, lpmode): # Check for invalid port_num - if port_num < self.port_start or port_num > self.sfp_port_start: # TBD + if port_num < self.port_start or port_num > self.sfp_port_start: # TBD return False try: lpmode_val_device_file = self.BASE_VAL_PATH.format( - self.lpmode_to_gpio_mapping[port_num]) + self.lpmode_to_gpio_mapping[port_num]) val_file = open(lpmode_val_device_file, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False val_file.write("1" if lpmode is True else "0") @@ -293,15 +294,15 @@ def set_low_power_mode(self, port_num, lpmode): def reset(self, port_num): # Check for invalid port_num - if port_num < self.port_start or port_num > self.sfp_port_start: # TBD + if port_num < self.port_start or port_num > self.sfp_port_start: # TBD return False try: reset_val_device_file = self.BASE_VAL_PATH.format( - self.reset_to_gpio_mapping[port_num]) + self.reset_to_gpio_mapping[port_num]) val_file = open(reset_val_device_file, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False val_file.write("1") @@ -312,10 +313,10 @@ def reset(self, port_num): try: reset_val_device_file = self.BASE_VAL_PATH.format( - self.reset_to_gpio_mapping[port_num]) + self.reset_to_gpio_mapping[port_num]) val_file = open(reset_val_device_file, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False val_file.write("0") diff --git a/device/ingrasys/x86_64-ingrasys_s9200_64x-r0/plugins/eeprom.py b/device/ingrasys/x86_64-ingrasys_s9200_64x-r0/plugins/eeprom.py index 64ddb99554b0..034c592c411e 100644 --- a/device/ingrasys/x86_64-ingrasys_s9200_64x-r0/plugins/eeprom.py +++ b/device/ingrasys/x86_64-ingrasys_s9200_64x-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Ingrasys S9200-64X # @@ -11,8 +9,8 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/ingrasys/x86_64-ingrasys_s9200_64x-r0/plugins/psuutil.py b/device/ingrasys/x86_64-ingrasys_s9200_64x-r0/plugins/psuutil.py index cc996057e09e..b2cdb9dca023 100644 --- a/device/ingrasys/x86_64-ingrasys_s9200_64x-r0/plugins/psuutil.py +++ b/device/ingrasys/x86_64-ingrasys_s9200_64x-r0/plugins/psuutil.py @@ -20,12 +20,12 @@ class PsuUtil(PsuBase): def __init__(self): PsuBase.__init__(self) - - + # Get sysfs attribute + def get_attr_value(self, attr_path): - - retval = 'ERR' + + retval = 'ERR' if (not os.path.isfile(attr_path)): return retval @@ -55,16 +55,16 @@ def get_psu_status(self, index): faulty """ status = 0 - attr_file = 'psu_pg' - attr_path = self.SYSFS_PSU_DIR[index-1] +'/' + attr_file - + attr_file = 'psu_pg' + attr_path = self.SYSFS_PSU_DIR[index-1] + '/' + attr_file + attr_value = self.get_attr_value(attr_path) - + if (attr_value != 'ERR'): attr_value = int(attr_value, 16) # Check for PSU status if (attr_value == 1): - status = 1 + status = 1 return status @@ -77,16 +77,15 @@ def get_psu_presence(self, index): """ status = 0 psu_absent = 0 - attr_file ='psu_abs' - attr_path = self.SYSFS_PSU_DIR[index-1] +'/' + attr_file - + attr_file = 'psu_abs' + attr_path = self.SYSFS_PSU_DIR[index-1] + '/' + attr_file + attr_value = self.get_attr_value(attr_path) if (attr_value != 'ERR'): attr_value = int(attr_value, 16) # Check for PSU presence if (attr_value == 0): - status = 1 + status = 1 return status - diff --git a/device/ingrasys/x86_64-ingrasys_s9200_64x-r0/plugins/sfputil.py b/device/ingrasys/x86_64-ingrasys_s9200_64x-r0/plugins/sfputil.py index 584b0e9716b8..1066c78ba826 100644 --- a/device/ingrasys/x86_64-ingrasys_s9200_64x-r0/plugins/sfputil.py +++ b/device/ingrasys/x86_64-ingrasys_s9200_64x-r0/plugins/sfputil.py @@ -14,7 +14,7 @@ class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" PORT_START = 0 - PORT_END = 63 + PORT_END = 63 PORTS_IN_BLOCK = 64 EEPROM_OFFSET = 29 @@ -22,70 +22,70 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} _logic_to_phy_port_mapping = { - 0: 0, - 1: 1, - 2: 4, - 3: 5, - 4: 8, - 5: 9, - 6: 12, - 7: 13, - 8: 16, - 9: 17, - 10: 20, - 11: 21, - 12: 24, - 13: 25, - 14: 28, - 15: 29, - 16: 32, - 17: 33, - 18: 36, - 19: 37, - 20: 40, - 21: 41, - 22: 44, - 23: 45, - 24: 48, - 25: 49, - 26: 52, - 27: 53, - 28: 56, - 29: 57, - 30: 60, - 31: 61, - 32: 2, - 33: 3, - 34: 6, - 35: 7, - 36: 10, - 37: 11, - 38: 14, - 39: 15, - 40: 18, - 41: 19, - 42: 22, - 43: 23, - 44: 26, - 45: 27, - 46: 30, - 47: 31, - 48: 34, - 49: 35, - 50: 38, - 51: 39, - 52: 42, - 53: 43, - 54: 46, - 55: 47, - 56: 50, - 57: 51, - 58: 54, - 59: 55, - 60: 58, - 61: 59, - 62: 62, - 63: 63 + 0: 0, + 1: 1, + 2: 4, + 3: 5, + 4: 8, + 5: 9, + 6: 12, + 7: 13, + 8: 16, + 9: 17, + 10: 20, + 11: 21, + 12: 24, + 13: 25, + 14: 28, + 15: 29, + 16: 32, + 17: 33, + 18: 36, + 19: 37, + 20: 40, + 21: 41, + 22: 44, + 23: 45, + 24: 48, + 25: 49, + 26: 52, + 27: 53, + 28: 56, + 29: 57, + 30: 60, + 31: 61, + 32: 2, + 33: 3, + 34: 6, + 35: 7, + 36: 10, + 37: 11, + 38: 14, + 39: 15, + 40: 18, + 41: 19, + 42: 22, + 43: 23, + 44: 26, + 45: 27, + 46: 30, + 47: 31, + 48: 34, + 49: 35, + 50: 38, + 51: 39, + 52: 42, + 53: 43, + 54: 46, + 55: 47, + 56: 50, + 57: 51, + 58: 54, + 59: 55, + 60: 58, + 61: 59, + 62: 62, + 63: 63 } @property @@ -98,7 +98,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(0, self.PORTS_IN_BLOCK + 1) + return list(range(0, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -124,7 +124,7 @@ def get_presence(self, port_num): try: reg_file = open("/sys/devices/platform/ingrasys-s9200-cpld.0/qsfp_modprs") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -152,7 +152,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open("/sys/devices/platform/ingrasys-s9200-cpld.0/qsfp_lpmode") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) content = reg_file.readline().rstrip() @@ -175,15 +175,14 @@ def set_low_power_mode(self, port_num, lpmode): # logic port to physical port mapping port_num = self._logic_to_phy_port_mapping[port_num] - + try: reg_file = open("/sys/devices/platform/ingrasys-s9200-cpld.0/qsfp_lpmode", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() - # content is a string containing the hex representation of the register reg_value = int(content, 16) @@ -219,7 +218,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -247,7 +246,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_value | mask diff --git a/device/ingrasys/x86_64-ingrasys_s9230_64x-r0/plugins/eeprom.py b/device/ingrasys/x86_64-ingrasys_s9230_64x-r0/plugins/eeprom.py index 770b0cf43baf..159e12d98f64 100644 --- a/device/ingrasys/x86_64-ingrasys_s9230_64x-r0/plugins/eeprom.py +++ b/device/ingrasys/x86_64-ingrasys_s9230_64x-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Ingrasys S9230-64X # @@ -11,8 +9,8 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/ingrasys/x86_64-ingrasys_s9230_64x-r0/plugins/psuutil.py b/device/ingrasys/x86_64-ingrasys_s9230_64x-r0/plugins/psuutil.py index cc996057e09e..b2cdb9dca023 100644 --- a/device/ingrasys/x86_64-ingrasys_s9230_64x-r0/plugins/psuutil.py +++ b/device/ingrasys/x86_64-ingrasys_s9230_64x-r0/plugins/psuutil.py @@ -20,12 +20,12 @@ class PsuUtil(PsuBase): def __init__(self): PsuBase.__init__(self) - - + # Get sysfs attribute + def get_attr_value(self, attr_path): - - retval = 'ERR' + + retval = 'ERR' if (not os.path.isfile(attr_path)): return retval @@ -55,16 +55,16 @@ def get_psu_status(self, index): faulty """ status = 0 - attr_file = 'psu_pg' - attr_path = self.SYSFS_PSU_DIR[index-1] +'/' + attr_file - + attr_file = 'psu_pg' + attr_path = self.SYSFS_PSU_DIR[index-1] + '/' + attr_file + attr_value = self.get_attr_value(attr_path) - + if (attr_value != 'ERR'): attr_value = int(attr_value, 16) # Check for PSU status if (attr_value == 1): - status = 1 + status = 1 return status @@ -77,16 +77,15 @@ def get_psu_presence(self, index): """ status = 0 psu_absent = 0 - attr_file ='psu_abs' - attr_path = self.SYSFS_PSU_DIR[index-1] +'/' + attr_file - + attr_file = 'psu_abs' + attr_path = self.SYSFS_PSU_DIR[index-1] + '/' + attr_file + attr_value = self.get_attr_value(attr_path) if (attr_value != 'ERR'): attr_value = int(attr_value, 16) # Check for PSU presence if (attr_value == 0): - status = 1 + status = 1 return status - diff --git a/device/ingrasys/x86_64-ingrasys_s9230_64x-r0/plugins/sfputil.py b/device/ingrasys/x86_64-ingrasys_s9230_64x-r0/plugins/sfputil.py index 2f7a5395bb47..f3e1d49cd86b 100644 --- a/device/ingrasys/x86_64-ingrasys_s9230_64x-r0/plugins/sfputil.py +++ b/device/ingrasys/x86_64-ingrasys_s9230_64x-r0/plugins/sfputil.py @@ -16,7 +16,7 @@ class SfpUtil(SfpUtilBase): PORT_START = 0 PORT_END = 63 PORTS_IN_BLOCK = 64 - #TODO: modify according to port map + # TODO: modify according to port map EEPROM_OFFSET = 33 CPLD1_PORTS = 12 CPLDx_PORTS = 13 @@ -32,70 +32,70 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} _logic_to_phy_port_mapping = { - 0: 0, - 1: 1, - 2: 4, - 3: 5, - 4: 8, - 5: 9, - 6: 12, - 7: 13, - 8: 16, - 9: 17, - 10: 20, - 11: 21, - 12: 24, - 13: 25, - 14: 28, - 15: 29, - 16: 32, - 17: 33, - 18: 36, - 19: 37, - 20: 40, - 21: 41, - 22: 44, - 23: 45, - 24: 48, - 25: 49, - 26: 52, - 27: 53, - 28: 56, - 29: 57, - 30: 60, - 31: 61, - 32: 2, - 33: 3, - 34: 6, - 35: 7, - 36: 10, - 37: 11, - 38: 14, - 39: 15, - 40: 18, - 41: 19, - 42: 22, - 43: 23, - 44: 26, - 45: 27, - 46: 30, - 47: 31, - 48: 34, - 49: 35, - 50: 38, - 51: 39, - 52: 42, - 53: 43, - 54: 46, - 55: 47, - 56: 50, - 57: 51, - 58: 54, - 59: 55, - 60: 58, - 61: 59, - 62: 62, - 63: 63 + 0: 0, + 1: 1, + 2: 4, + 3: 5, + 4: 8, + 5: 9, + 6: 12, + 7: 13, + 8: 16, + 9: 17, + 10: 20, + 11: 21, + 12: 24, + 13: 25, + 14: 28, + 15: 29, + 16: 32, + 17: 33, + 18: 36, + 19: 37, + 20: 40, + 21: 41, + 22: 44, + 23: 45, + 24: 48, + 25: 49, + 26: 52, + 27: 53, + 28: 56, + 29: 57, + 30: 60, + 31: 61, + 32: 2, + 33: 3, + 34: 6, + 35: 7, + 36: 10, + 37: 11, + 38: 14, + 39: 15, + 40: 18, + 41: 19, + 42: 22, + 43: 23, + 44: 26, + 45: 27, + 46: 30, + 47: 31, + 48: 34, + 49: 35, + 50: 38, + 51: 39, + 52: 42, + 53: 43, + 54: 46, + 55: 47, + 56: 50, + 57: 51, + 58: 54, + 59: 55, + 60: 58, + 61: 59, + 62: 62, + 63: 63 } @property @@ -108,13 +108,12 @@ def port_end(self): @property def qsfp_ports(self): - return range(0, self.PORTS_IN_BLOCK + 1) + return list(range(0, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): return self._port_to_eeprom_mapping - def __init__(self): # Override port_to_eeprom_mapping for class initialization eeprom_path = "/sys/class/i2c-adapter/i2c-{0}/{0}-0050/eeprom" @@ -132,7 +131,7 @@ def qsfp_to_cpld_index(self, port_num): else: cpld_id = 1 + (port_num - self.CPLD1_PORTS) / self.CPLDx_PORTS cpld_port_index = ((port_num - self.CPLD1_PORTS) % self.CPLDx_PORTS) + 1 - return cpld_id, cpld_port_index + return cpld_id, cpld_port_index def get_presence(self, port_num): # Check for invalid port_num @@ -144,25 +143,25 @@ def get_presence(self, port_num): cpld_id, cpld_port_index = self.qsfp_to_cpld_index(port_num) i2c_id = self.CPLD_OFFSET + cpld_id - reg_path = self.CPLD_REG_PATH.format(i2c_id, self.CPLDx_I2C_ADDR, \ - self.CPLD_PORT_STATUS_KEY, cpld_port_index) + reg_path = self.CPLD_REG_PATH.format(i2c_id, self.CPLDx_I2C_ADDR, + self.CPLD_PORT_STATUS_KEY, cpld_port_index) try: reg_file = open(reg_path) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # content is a string containing the status register value content = reg_file.readline().rstrip() reg_file.close() - + reg_value = int(content, 16) # mask for presence bit (bit 1) mask = (1 << self.CPLD_PRES_BIT) # 0 - presence, 1 - absence - if reg_value & mask == 0: + if reg_value & mask == 0: return True return False @@ -177,13 +176,13 @@ def get_low_power_mode(self, port_num): cpld_id, cpld_port_index = self.qsfp_to_cpld_index(port_num) i2c_id = self.CPLD_OFFSET + cpld_id - reg_path = self.CPLD_REG_PATH.format(i2c_id, self.CPLDx_I2C_ADDR, \ - self.CPLD_PORT_CONFIG_KEY, cpld_port_index) + reg_path = self.CPLD_REG_PATH.format(i2c_id, self.CPLDx_I2C_ADDR, + self.CPLD_PORT_CONFIG_KEY, cpld_port_index) try: reg_file = open(reg_path) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # content is a string containing the status register value @@ -195,7 +194,7 @@ def get_low_power_mode(self, port_num): mask = (1 << self.CPLD_LPMOD_BIT) # 0 - disable, 1 - low power mode - if reg_value & mask == 0: + if reg_value & mask == 0: return False return True @@ -210,13 +209,13 @@ def set_low_power_mode(self, port_num, lpmode): cpld_id, cpld_port_index = self.qsfp_to_cpld_index(port_num) i2c_id = self.CPLD_OFFSET + cpld_id - reg_path = self.CPLD_REG_PATH.format(i2c_id, self.CPLDx_I2C_ADDR, \ - self.CPLD_PORT_CONFIG_KEY, cpld_port_index) + reg_path = self.CPLD_REG_PATH.format(i2c_id, self.CPLDx_I2C_ADDR, + self.CPLD_PORT_CONFIG_KEY, cpld_port_index) try: reg_file = open(reg_path, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # content is a string containing the status register value @@ -250,14 +249,14 @@ def reset(self, port_num): cpld_id, cpld_port_index = self.qsfp_to_cpld_index(port_num) i2c_id = self.CPLD_OFFSET + cpld_id - reg_path = self.CPLD_REG_PATH.format(i2c_id, self.CPLDx_I2C_ADDR, \ - self.CPLD_PORT_CONFIG_KEY, cpld_port_index) + reg_path = self.CPLD_REG_PATH.format(i2c_id, self.CPLDx_I2C_ADDR, + self.CPLD_PORT_CONFIG_KEY, cpld_port_index) # reset the port try: reg_file = open(reg_path, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # content is a string containing the status register value @@ -280,7 +279,7 @@ def reset(self, port_num): try: reg_file = open(reg_path, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_value | mask diff --git a/device/ingrasys/x86_64-ingrasys_s9280_64x-r0/plugins/eeprom.py b/device/ingrasys/x86_64-ingrasys_s9280_64x-r0/plugins/eeprom.py index ecf171539843..3fc614fc2632 100644 --- a/device/ingrasys/x86_64-ingrasys_s9280_64x-r0/plugins/eeprom.py +++ b/device/ingrasys/x86_64-ingrasys_s9280_64x-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Ingrasys S9280-64X # @@ -11,8 +9,8 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/ingrasys/x86_64-ingrasys_s9280_64x-r0/plugins/psuutil.py b/device/ingrasys/x86_64-ingrasys_s9280_64x-r0/plugins/psuutil.py index c4b78c943e81..8c7d5cfa4174 100644 --- a/device/ingrasys/x86_64-ingrasys_s9280_64x-r0/plugins/psuutil.py +++ b/device/ingrasys/x86_64-ingrasys_s9280_64x-r0/plugins/psuutil.py @@ -21,12 +21,12 @@ class PsuUtil(PsuBase): def __init__(self): PsuBase.__init__(self) - - + # Get sysfs attribute + def get_attr_value(self, attr_path): - - retval = 'ERR' + + retval = 'ERR' if (not os.path.isfile(attr_path)): return retval @@ -56,16 +56,16 @@ def get_psu_status(self, index): faulty """ status = 0 - attr_file = 'psu_pg' - attr_path = self.SYSFS_PSU_DIR[index-1] +'/' + attr_file - + attr_file = 'psu_pg' + attr_path = self.SYSFS_PSU_DIR[index-1] + '/' + attr_file + attr_value = self.get_attr_value(attr_path) - + if (attr_value != 'ERR'): attr_value = int(attr_value, 16) # Check for PSU status if (attr_value == 1): - status = 1 + status = 1 return status @@ -78,16 +78,15 @@ def get_psu_presence(self, index): """ status = 0 psu_absent = 0 - attr_file ='psu_abs' - attr_path = self.SYSFS_PSU_DIR[index-1] +'/' + attr_file - + attr_file = 'psu_abs' + attr_path = self.SYSFS_PSU_DIR[index-1] + '/' + attr_file + attr_value = self.get_attr_value(attr_path) if (attr_value != 'ERR'): attr_value = int(attr_value, 16) # Check for PSU presence if (attr_value == 0): - status = 1 + status = 1 return status - diff --git a/device/ingrasys/x86_64-ingrasys_s9280_64x-r0/plugins/sfputil.py b/device/ingrasys/x86_64-ingrasys_s9280_64x-r0/plugins/sfputil.py index 57edb81cd109..689710cf3f4d 100644 --- a/device/ingrasys/x86_64-ingrasys_s9280_64x-r0/plugins/sfputil.py +++ b/device/ingrasys/x86_64-ingrasys_s9280_64x-r0/plugins/sfputil.py @@ -19,7 +19,7 @@ class SfpUtil(SfpUtilBase): EEPROM_OFFSET = 41 CPLD1_PORTS = 12 CPLDx_PORTS = 13 - #TODO: check init sequence for CPLD i2c bus + # TODO: check init sequence for CPLD i2c bus CPLD_OFFSET = 1 CPLD_PRES_BIT = 1 CPLD_RESET_BIT = 0 @@ -32,72 +32,72 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} - #TODO: check the fp port to phy port mapping + # TODO: check the fp port to phy port mapping _fp2phy_port_mapping = { - 0: 0, - 1: 1, - 2: 4, - 3: 5, - 4: 8, - 5: 9, - 6: 12, - 7: 13, - 8: 16, - 9: 17, - 10: 20, - 11: 21, - 12: 24, - 13: 25, - 14: 28, - 15: 29, - 16: 32, - 17: 33, - 18: 36, - 19: 37, - 20: 40, - 21: 41, - 22: 44, - 23: 45, - 24: 48, - 25: 49, - 26: 52, - 27: 53, - 28: 56, - 29: 57, - 30: 60, - 31: 61, - 32: 2, - 33: 3, - 34: 6, - 35: 7, - 36: 10, - 37: 11, - 38: 14, - 39: 15, - 40: 18, - 41: 19, - 42: 22, - 43: 23, - 44: 26, - 45: 27, - 46: 30, - 47: 31, - 48: 34, - 49: 35, - 50: 38, - 51: 39, - 52: 42, - 53: 43, - 54: 46, - 55: 47, - 56: 50, - 57: 51, - 58: 54, - 59: 55, - 60: 58, - 61: 59, - 62: 62, - 63: 63 + 0: 0, + 1: 1, + 2: 4, + 3: 5, + 4: 8, + 5: 9, + 6: 12, + 7: 13, + 8: 16, + 9: 17, + 10: 20, + 11: 21, + 12: 24, + 13: 25, + 14: 28, + 15: 29, + 16: 32, + 17: 33, + 18: 36, + 19: 37, + 20: 40, + 21: 41, + 22: 44, + 23: 45, + 24: 48, + 25: 49, + 26: 52, + 27: 53, + 28: 56, + 29: 57, + 30: 60, + 31: 61, + 32: 2, + 33: 3, + 34: 6, + 35: 7, + 36: 10, + 37: 11, + 38: 14, + 39: 15, + 40: 18, + 41: 19, + 42: 22, + 43: 23, + 44: 26, + 45: 27, + 46: 30, + 47: 31, + 48: 34, + 49: 35, + 50: 38, + 51: 39, + 52: 42, + 53: 43, + 54: 46, + 55: 47, + 56: 50, + 57: 51, + 58: 54, + 59: 55, + 60: 58, + 61: 59, + 62: 62, + 63: 63 } @property @@ -110,13 +110,12 @@ def port_end(self): @property def qsfp_ports(self): - return range(0, self.PORTS_IN_BLOCK + 1) + return list(range(0, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): return self._port_to_eeprom_mapping - def __init__(self): # Override port_to_eeprom_mapping for class initialization eeprom_path = "/sys/class/i2c-adapter/i2c-{0}/{0}-00{1}/eeprom" @@ -134,7 +133,7 @@ def qsfp_to_cpld_index(self, port_num): else: cpld_id = 1 + (port_num - self.CPLD1_PORTS) / self.CPLDx_PORTS cpld_port_index = ((port_num - self.CPLD1_PORTS) % self.CPLDx_PORTS) + 1 - return cpld_id, cpld_port_index + return cpld_id, cpld_port_index def fp2phy_port_num(self, fp_port_num): @@ -151,25 +150,25 @@ def get_presence(self, port_num): cpld_id, cpld_port_index = self.qsfp_to_cpld_index(port_num) i2c_id = self.CPLD_OFFSET + cpld_id - reg_path = self.CPLD_REG_PATH.format(i2c_id, self.CPLDx_I2C_ADDR, \ - self.CPLD_PORT_STATUS_KEY, cpld_port_index) + reg_path = self.CPLD_REG_PATH.format(i2c_id, self.CPLDx_I2C_ADDR, + self.CPLD_PORT_STATUS_KEY, cpld_port_index) try: reg_file = open(reg_path) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # content is a string containing the status register value content = reg_file.readline().rstrip() reg_file.close() - + reg_value = int(content, 16) # mask for presence bit (bit 1) mask = (1 << self.CPLD_PRES_BIT) # 0 - presence, 1 - absence - if reg_value & mask == 0: + if reg_value & mask == 0: return True return False @@ -184,13 +183,13 @@ def get_low_power_mode(self, port_num): cpld_id, cpld_port_index = self.qsfp_to_cpld_index(port_num) i2c_id = self.CPLD_OFFSET + cpld_id - reg_path = self.CPLD_REG_PATH.format(i2c_id, self.CPLDx_I2C_ADDR, \ - self.CPLD_PORT_CONFIG_KEY, cpld_port_index) + reg_path = self.CPLD_REG_PATH.format(i2c_id, self.CPLDx_I2C_ADDR, + self.CPLD_PORT_CONFIG_KEY, cpld_port_index) try: reg_file = open(reg_path) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # content is a string containing the status register value @@ -202,7 +201,7 @@ def get_low_power_mode(self, port_num): mask = (1 << self.CPLD_LPMOD_BIT) # 0 - disable, 1 - low power mode - if reg_value & mask == 0: + if reg_value & mask == 0: return False return True @@ -217,13 +216,13 @@ def set_low_power_mode(self, port_num, lpmode): cpld_id, cpld_port_index = self.qsfp_to_cpld_index(port_num) i2c_id = self.CPLD_OFFSET + cpld_id - reg_path = self.CPLD_REG_PATH.format(i2c_id, self.CPLDx_I2C_ADDR, \ - self.CPLD_PORT_CONFIG_KEY, cpld_port_index) + reg_path = self.CPLD_REG_PATH.format(i2c_id, self.CPLDx_I2C_ADDR, + self.CPLD_PORT_CONFIG_KEY, cpld_port_index) try: reg_file = open(reg_path, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # content is a string containing the status register value @@ -257,14 +256,14 @@ def reset(self, port_num): cpld_id, cpld_port_index = self.qsfp_to_cpld_index(port_num) i2c_id = self.CPLD_OFFSET + cpld_id - reg_path = self.CPLD_REG_PATH.format(i2c_id, self.CPLDx_I2C_ADDR, \ - self.CPLD_PORT_CONFIG_KEY, cpld_port_index) + reg_path = self.CPLD_REG_PATH.format(i2c_id, self.CPLDx_I2C_ADDR, + self.CPLD_PORT_CONFIG_KEY, cpld_port_index) # reset the port try: reg_file = open(reg_path, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # content is a string containing the status register value @@ -287,7 +286,7 @@ def reset(self, port_num): try: reg_file = open(reg_path, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_value | mask @@ -305,4 +304,3 @@ def get_transceiver_change_event(self): on this platform. """ raise NotImplementedError - diff --git a/device/inventec/x86_64-inventec_d6254qs-r0/plugins/eeprom.py b/device/inventec/x86_64-inventec_d6254qs-r0/plugins/eeprom.py index de5c24ba0e6d..31f847614fb0 100644 --- a/device/inventec/x86_64-inventec_d6254qs-r0/plugins/eeprom.py +++ b/device/inventec/x86_64-inventec_d6254qs-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Inventec d7032q28b # @@ -11,8 +9,8 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/inventec/x86_64-inventec_d6254qs-r0/plugins/psuutil.py b/device/inventec/x86_64-inventec_d6254qs-r0/plugins/psuutil.py index 4bd3f7a27052..162e240bae35 100644 --- a/device/inventec/x86_64-inventec_d6254qs-r0/plugins/psuutil.py +++ b/device/inventec/x86_64-inventec_d6254qs-r0/plugins/psuutil.py @@ -22,8 +22,8 @@ def __init__(self): # Get sysfs attribute def get_attr_value(self, attr_path): - - retval = 'ERR' + + retval = 'ERR' if (not os.path.isfile(attr_path)): return retval @@ -35,7 +35,7 @@ def get_attr_value(self, attr_path): retval = retval.rstrip(' \t\n\r') return retval - + def get_num_psus(self): """ Retrieves the number of PSUs available on the device @@ -53,14 +53,14 @@ def get_psu_status(self, index): faulty """ status = 0 - attr_file = 'psoc_psu'+ str(index) + '_iout' - attr_path = self.PSU_DIR +'/' + attr_file - + attr_file = 'psoc_psu' + str(index) + '_iout' + attr_path = self.PSU_DIR + '/' + attr_file + attr_value = self.get_attr_value(attr_path) if (attr_value != 'ERR'): # Check for PSU status if (attr_value != 0): - status = 1 + status = 1 return status def get_psu_presence(self, index): @@ -73,12 +73,12 @@ def get_psu_presence(self, index): status = 0 psu_absent = 0 ind = index-1 - attr_file ='psu'+ str(ind) - attr_path = self.PSU_DIR +'/' + attr_file - normal_attr_value = '0 : normal' + attr_file = 'psu' + str(ind) + attr_path = self.PSU_DIR + '/' + attr_file + normal_attr_value = '0 : normal' attr_value = self.get_attr_value(attr_path) if (attr_value != 'ERR'): # Check for PSU presence if (attr_value == normal_attr_value): - status = 1 + status = 1 return status diff --git a/device/inventec/x86_64-inventec_d6254qs-r0/plugins/sfputil.py b/device/inventec/x86_64-inventec_d6254qs-r0/plugins/sfputil.py index 6cd470795fb6..62a67f72e1a4 100644 --- a/device/inventec/x86_64-inventec_d6254qs-r0/plugins/sfputil.py +++ b/device/inventec/x86_64-inventec_d6254qs-r0/plugins/sfputil.py @@ -95,7 +95,7 @@ def qsfp_port_end(self): @property def qsfp_ports(self): - return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -117,7 +117,7 @@ def get_presence(self, port_num): try: reg_file = open("/sys/class/swps/port"+str(port_num)+"/present") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = int(reg_file.readline().rstrip()) @@ -137,7 +137,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open("/sys/class/swps/port"+str(port_num)+"/lpmod") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) reg_value = int(reg_file.readline().rstrip()) @@ -151,13 +151,13 @@ def set_low_power_mode(self, port_num, lpmode): if port_num < self.port_start or port_num > self.port_end: return False if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: - print "\nError:SFP's don't support this property" + print("\nError:SFP's don't support this property") return False try: reg_file = open("/sys/class/swps/port"+str(port_num)+"/lpmod", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = int(reg_file.readline().rstrip()) @@ -179,13 +179,13 @@ def reset(self, port_num): if port_num < self.port_start or port_num > self.port_end: return False if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: - print "\nError:SFP's don't support this property" + print("\nError:SFP's don't support this property") return False try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 0 @@ -199,7 +199,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 1 diff --git a/device/inventec/x86_64-inventec_d6332-r0/plugins/eeprom.py b/device/inventec/x86_64-inventec_d6332-r0/plugins/eeprom.py index b58e704a5566..96e27323aa44 100644 --- a/device/inventec/x86_64-inventec_d6332-r0/plugins/eeprom.py +++ b/device/inventec/x86_64-inventec_d6332-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Inventec d6356j # @@ -11,8 +9,8 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/inventec/x86_64-inventec_d6332-r0/plugins/psuutil.py b/device/inventec/x86_64-inventec_d6332-r0/plugins/psuutil.py index b2033963872d..3ae6d5ddb355 100755 --- a/device/inventec/x86_64-inventec_d6332-r0/plugins/psuutil.py +++ b/device/inventec/x86_64-inventec_d6332-r0/plugins/psuutil.py @@ -23,8 +23,8 @@ def __init__(self): # Get sysfs attribute def get_attr_value(self, attr_path): - - retval = 'ERR' + + retval = 'ERR' if (not os.path.isfile(attr_path)): return retval @@ -36,7 +36,7 @@ def get_attr_value(self, attr_path): retval = retval.rstrip(' \t\n\r') return retval - + def get_num_psus(self): """ Retrieves the number of PSUs available on the device @@ -54,17 +54,17 @@ def get_psu_status(self, index): faulty """ status = 0 - attr_file ='psu'+ str(index) - attr_path = self.PSU_DIR +'/' + attr_file + attr_file = 'psu' + str(index) + attr_path = self.PSU_DIR + '/' + attr_file normal_attr_value = '1:normal' unpower_attr_value = '0:unpowered' attr_value = self.get_attr_value(attr_path) if (attr_value != 'ERR'): # Check for PSU presence if (attr_value == normal_attr_value): - status = 1 + status = 1 elif (attr_value == unpower_attr_value): - status = 0 + status = 0 return status def get_psu_presence(self, index): @@ -75,15 +75,15 @@ def get_psu_presence(self, index): :return: Boolean, True if PSU is plugged, False if not """ status = 0 - attr_file ='psu'+ str(index) - attr_path = self.PSU_DIR +'/' + attr_file + attr_file = 'psu' + str(index) + attr_path = self.PSU_DIR + '/' + attr_file normal_attr_value = '1:normal' unpower_attr_value = '0:unpowered' attr_value = self.get_attr_value(attr_path) if (attr_value != 'ERR'): # Check for PSU presence if (attr_value == normal_attr_value): - status = 1 + status = 1 if (attr_value == unpower_attr_value): - status = 1 + status = 1 return status diff --git a/device/inventec/x86_64-inventec_d6332-r0/plugins/sfputil.py b/device/inventec/x86_64-inventec_d6332-r0/plugins/sfputil.py index 0f2d3aad1720..7c3b78c1bc22 100755 --- a/device/inventec/x86_64-inventec_d6332-r0/plugins/sfputil.py +++ b/device/inventec/x86_64-inventec_d6332-r0/plugins/sfputil.py @@ -5,9 +5,11 @@ try: import time - import os, re, socket + import os + import re + import socket from sonic_sfp.sfputilbase import SfpUtilBase - from collections import OrderedDict + from collections import OrderedDict from sonic_sfp.sff8472 import sff8472Dom except ImportError as e: raise ImportError("%s - required module not found" % str(e)) @@ -22,6 +24,7 @@ NETLINK_KOBJECT_UEVENT = 15 monitor = None + class SWPSEventMonitor(object): def __init__(self): @@ -76,38 +79,38 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} port_to_i2cbus_mapping = { - 0:12, - 1:13, - 2:14, - 3:15, - 4:16, - 5:17, - 6:18, - 7:19, - 8:20, - 9:21, - 10:22, - 11:23, - 12:24, - 13:25, - 14:26, - 15:27, - 16:28, - 17:29, - 18:30, - 19:31, - 20:32, - 21:33, - 22:34, - 23:35, - 24:36, - 25:37, - 26:38, - 27:39, - 28:40, - 29:41, - 30:42, - 31:43 + 0: 12, + 1: 13, + 2: 14, + 3: 15, + 4: 16, + 5: 17, + 6: 18, + 7: 19, + 8: 20, + 9: 21, + 10: 22, + 11: 23, + 12: 24, + 13: 25, + 14: 26, + 15: 27, + 16: 28, + 17: 29, + 18: 30, + 19: 31, + 20: 32, + 21: 33, + 22: 34, + 23: 35, + 24: 36, + 25: 37, + 26: 38, + 27: 39, + 28: 40, + 29: 41, + 30: 42, + 31: 43 } @property @@ -120,7 +123,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(0, self.PORTS_IN_BLOCK + 1) + return list(range(0, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -143,7 +146,7 @@ def get_presence(self, port_num): try: reg_file = open("/sys/class/swps/port"+str(port_num)+"/present") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = int(reg_file.readline().rstrip()) @@ -161,7 +164,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open("/sys/class/swps/port"+str(port_num)+"/lpmod") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) reg_value = int(reg_file.readline().rstrip()) @@ -178,7 +181,7 @@ def set_low_power_mode(self, port_num, lpmode): try: reg_file = open("/sys/class/swps/port"+str(port_num)+"/lpmod", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False lpmode = int(reg_file.readline().rstrip()) @@ -203,7 +206,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 0 @@ -217,7 +220,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 1 @@ -228,7 +231,7 @@ def reset(self, port_num): def _get_port_eeprom_path(self, port_num, devid): sysfs_i2c_adapter_base_path = "/sys/class/i2c-adapter" - if devid == self.IDENTITY_EEPROM_ADDR : + if devid == self.IDENTITY_EEPROM_ADDR: return SfpUtilBase._get_port_eeprom_path(self, port_num, devid) else: i2c_adapter_id = self._get_port_i2c_adapter_id(port_num) @@ -252,7 +255,7 @@ def _get_port_eeprom_path(self, port_num, devid): # If sfp device is not present on bus, Add it if not os.path.exists(sysfs_sfp_i2c_client_path): ret = self._add_new_sfp_device( - sysfs_sfp_i2c_adapter_path, devid) + sysfs_sfp_i2c_adapter_path, devid) if ret != 0: print("Error adding sfp device") return None @@ -282,7 +285,8 @@ 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: print(dom_temperature_raw) dom_temperature_data = sfpd_obj.parse_temperature(dom_temperature_raw, 0) @@ -290,14 +294,16 @@ def get_transceiver_dom_info_dict(self, port_num): 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: print(dom_voltage_raw) 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: @@ -334,7 +340,7 @@ def get_transceiver_change_event(self, timeout=0): if event['SUBSYSTEM'] == 'swps': #print('SWPS event. From %s, ACTION %s, IF_TYPE %s, IF_LANE %s' % (event['DEVPATH'], event['ACTION'], event['IF_TYPE'], event['IF_LANE'])) portname = event['DEVPATH'].split("/")[-1] - rc = re.match(r"port(?P\d+)",portname) + rc = re.match(r"port(?P\d+)", portname) if rc is not None: if event['ACTION'] == "remove": remove_num = int(rc.group("num")) diff --git a/device/inventec/x86_64-inventec_d6356-r0/plugins/eeprom.py b/device/inventec/x86_64-inventec_d6356-r0/plugins/eeprom.py index 953570d79cd7..4c75d0918add 100644 --- a/device/inventec/x86_64-inventec_d6356-r0/plugins/eeprom.py +++ b/device/inventec/x86_64-inventec_d6356-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Inventec d6356 # @@ -11,8 +9,8 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/inventec/x86_64-inventec_d6356-r0/plugins/psuutil.py b/device/inventec/x86_64-inventec_d6356-r0/plugins/psuutil.py index 732650ffe638..ce8d0b321928 100755 --- a/device/inventec/x86_64-inventec_d6356-r0/plugins/psuutil.py +++ b/device/inventec/x86_64-inventec_d6356-r0/plugins/psuutil.py @@ -22,8 +22,8 @@ def __init__(self): # Get sysfs attribute def get_attr_value(self, attr_path): - - retval = 'ERR' + + retval = 'ERR' if (not os.path.isfile(attr_path)): return retval @@ -35,7 +35,7 @@ def get_attr_value(self, attr_path): retval = retval.rstrip(' \t\n\r') return retval - + def get_num_psus(self): """ Retrieves the number of PSUs available on the device @@ -53,17 +53,17 @@ def get_psu_status(self, index): faulty """ status = 0 - - if index == 1 : + + if index == 1: attr_path = "/sys/class/hwmon/hwmon7/in1_input" - else : + else: attr_path = "/sys/class/hwmon/hwmon8/in1_input" attr_value = self.get_attr_value(attr_path) if (attr_value != 'ERR'): # Check for PSU status if (attr_value != 0): - status = 1 + status = 1 return status def get_psu_presence(self, index): @@ -76,13 +76,12 @@ def get_psu_presence(self, index): status = 0 psu_absent = 0 ind = index - attr_file ='psu'+ str(ind) - attr_path = self.PSU_DIR +'/' + attr_file - normal_attr_value = '1:normal' + attr_file = 'psu' + str(ind) + attr_path = self.PSU_DIR + '/' + attr_file + normal_attr_value = '1:normal' attr_value = self.get_attr_value(attr_path) if (attr_value != 'ERR'): # Check for PSU presence if (attr_value == normal_attr_value): - status = 1 + status = 1 return status - diff --git a/device/inventec/x86_64-inventec_d6356-r0/plugins/sfputil.py b/device/inventec/x86_64-inventec_d6356-r0/plugins/sfputil.py index 116a3d9acbc9..d58d1e96b766 100755 --- a/device/inventec/x86_64-inventec_d6356-r0/plugins/sfputil.py +++ b/device/inventec/x86_64-inventec_d6356-r0/plugins/sfputil.py @@ -14,7 +14,9 @@ # try: import time - import socket, re,os + import socket + import re + import os from collections import OrderedDict from sonic_sfp.sfputilbase import SfpUtilBase from sonic_sfp.sff8472 import sff8472Dom @@ -31,6 +33,7 @@ NETLINK_KOBJECT_UEVENT = 15 monitor = None + class SWPSEventMonitor(object): def __init__(self): @@ -76,6 +79,7 @@ def next_events(self): except ValueError: pass + class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" @@ -87,62 +91,62 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} port_to_i2c_mapping = { - 0:22, - 1:23, - 2:24, - 3:25, - 4:26, - 5:27, - 6:28, - 7:29, - 8:30, - 9:31, - 10:32, - 11:33, - 12:34, - 13:35, - 14:36, - 15:37, - 16:38, - 17:39, - 18:40, - 19:41, - 20:42, - 21:43, - 22:44, - 23:45, - 24:46, - 25:47, - 26:48, - 27:49, - 28:50, - 29:51, - 30:52, - 31:53, - 32:54, - 33:55, - 34:56, - 35:57, - 36:58, - 37:59, - 38:60, - 39:61, - 40:62, - 41:63, - 42:64, - 43:65, - 44:66, - 45:67, - 46:68, - 47:69, - 48:14, - 49:15, - 50:16, - 51:17, - 52:18, - 53:19, - 54:20, - 55:21 + 0: 22, + 1: 23, + 2: 24, + 3: 25, + 4: 26, + 5: 27, + 6: 28, + 7: 29, + 8: 30, + 9: 31, + 10: 32, + 11: 33, + 12: 34, + 13: 35, + 14: 36, + 15: 37, + 16: 38, + 17: 39, + 18: 40, + 19: 41, + 20: 42, + 21: 43, + 22: 44, + 23: 45, + 24: 46, + 25: 47, + 26: 48, + 27: 49, + 28: 50, + 29: 51, + 30: 52, + 31: 53, + 32: 54, + 33: 55, + 34: 56, + 35: 57, + 36: 58, + 37: 59, + 38: 60, + 39: 61, + 40: 62, + 41: 63, + 42: 64, + 43: 65, + 44: 66, + 45: 67, + 46: 68, + 47: 69, + 48: 14, + 49: 15, + 50: 16, + 51: 17, + 52: 18, + 53: 19, + 54: 20, + 55: 21 } @property @@ -163,7 +167,7 @@ def qsfp_port_end(self): @property def qsfp_ports(self): - return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -185,7 +189,7 @@ def get_presence(self, port_num): try: reg_file = open("/sys/class/swps/port"+str(port_num)+"/present") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = int(reg_file.readline().rstrip()) @@ -205,7 +209,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open("/sys/class/swps/port"+str(port_num)+"/lpmod") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) reg_value = int(reg_file.readline().rstrip()) @@ -219,13 +223,13 @@ def set_low_power_mode(self, port_num, lpmode): if port_num < self.port_start or port_num > self.port_end: return False if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: - print "\nError:SFP's don't support this property" + print("\nError:SFP's don't support this property") return False try: reg_file = open("/sys/class/swps/port"+str(port_num)+"/lpmod", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = int(reg_file.readline().rstrip()) @@ -247,13 +251,13 @@ def reset(self, port_num): if port_num < self.port_start or port_num > self.port_end: return False if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: - print "\nError:SFP's don't support this property" + print("\nError:SFP's don't support this property") return False try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 0 @@ -267,7 +271,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 1 @@ -293,7 +297,7 @@ def get_transceiver_change_event(self): if event['SUBSYSTEM'] == 'swps': #print('SWPS event. From %s, ACTION %s, IF_TYPE %s, IF_LANE %s' % (event['DEVPATH'], event['ACTION'], event['IF_TYPE'], event['IF_LANE'])) portname = event['DEVPATH'].split("/")[-1] - rc = re.match(r"port(?P\d+)",portname) + rc = re.match(r"port(?P\d+)", portname) if rc is not None: if event['ACTION'] == "remove": remove_num = int(rc.group("num")) @@ -335,19 +339,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: @@ -375,5 +382,3 @@ def get_transceiver_dom_info_dict(self, port_num): transceiver_dom_info_dict['tx4power'] = 'N/A' return transceiver_dom_info_dict - - diff --git a/device/inventec/x86_64-inventec_d6556-r0/plugins/eeprom.py b/device/inventec/x86_64-inventec_d6556-r0/plugins/eeprom.py index de5c24ba0e6d..31f847614fb0 100644 --- a/device/inventec/x86_64-inventec_d6556-r0/plugins/eeprom.py +++ b/device/inventec/x86_64-inventec_d6556-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Inventec d7032q28b # @@ -11,8 +9,8 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/inventec/x86_64-inventec_d6556-r0/plugins/psuutil.py b/device/inventec/x86_64-inventec_d6556-r0/plugins/psuutil.py index 855162f63b98..ced851d6c82a 100644 --- a/device/inventec/x86_64-inventec_d6556-r0/plugins/psuutil.py +++ b/device/inventec/x86_64-inventec_d6556-r0/plugins/psuutil.py @@ -22,8 +22,8 @@ def __init__(self): # Get sysfs attribute def get_attr_value(self, attr_path): - - retval = 'ERR' + + retval = 'ERR' if (not os.path.isfile(attr_path)): return retval @@ -35,7 +35,7 @@ def get_attr_value(self, attr_path): retval = retval.rstrip(' \t\n\r') return retval - + def get_num_psus(self): """ Retrieves the number of PSUs available on the device @@ -53,14 +53,14 @@ def get_psu_status(self, index): faulty """ status = 0 - attr_file = 'psoc_psu'+ str(index) + '_iout' - attr_path = self.PSU_DIR +'/' + attr_file - + attr_file = 'psoc_psu' + str(index) + '_iout' + attr_path = self.PSU_DIR + '/' + attr_file + attr_value = self.get_attr_value(attr_path) if (attr_value != 'ERR'): # Check for PSU status if (attr_value != 0): - status = 1 + status = 1 return status def get_psu_presence(self, index): @@ -73,12 +73,12 @@ def get_psu_presence(self, index): status = 0 psu_absent = 0 ind = index-1 - attr_file ='psu'+ str(ind) - attr_path = self.PSU_DIR +'/' + attr_file - normal_attr_value = '0 : normal' + attr_file = 'psu' + str(ind) + attr_path = self.PSU_DIR + '/' + attr_file + normal_attr_value = '0 : normal' attr_value = self.get_attr_value(attr_path) if (attr_value != 'ERR'): # Check for PSU presence if (attr_value == normal_attr_value): - status = 1 + status = 1 return status diff --git a/device/inventec/x86_64-inventec_d6556-r0/plugins/sfputil.py b/device/inventec/x86_64-inventec_d6556-r0/plugins/sfputil.py index 155b956827f1..3cd6c43d7cde 100644 --- a/device/inventec/x86_64-inventec_d6556-r0/plugins/sfputil.py +++ b/device/inventec/x86_64-inventec_d6556-r0/plugins/sfputil.py @@ -97,7 +97,7 @@ def qsfp_port_end(self): @property def qsfp_ports(self): - return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -119,7 +119,7 @@ def get_presence(self, port_num): try: reg_file = open("/sys/class/swps/port"+str(port_num)+"/present") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = int(reg_file.readline().rstrip()) @@ -139,7 +139,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open("/sys/class/swps/port"+str(port_num)+"/lpmod") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) reg_value = int(reg_file.readline().rstrip()) @@ -153,13 +153,13 @@ def set_low_power_mode(self, port_num, lpmode): if port_num < self.port_start or port_num > self.port_end: return False if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: - print "\nError:SFP's don't support this property" + print("\nError:SFP's don't support this property") return False try: reg_file = open("/sys/class/swps/port"+str(port_num)+"/lpmod", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = int(reg_file.readline().rstrip()) @@ -181,13 +181,13 @@ def reset(self, port_num): if port_num < self.port_start or port_num > self.port_end: return False if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: - print "\nError:SFP's don't support this property" + print("\nError:SFP's don't support this property") return False try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 0 @@ -201,7 +201,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 1 diff --git a/device/inventec/x86_64-inventec_d7032q28b-r0/plugins/eeprom.py b/device/inventec/x86_64-inventec_d7032q28b-r0/plugins/eeprom.py index de5c24ba0e6d..31f847614fb0 100644 --- a/device/inventec/x86_64-inventec_d7032q28b-r0/plugins/eeprom.py +++ b/device/inventec/x86_64-inventec_d7032q28b-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Inventec d7032q28b # @@ -11,8 +9,8 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/inventec/x86_64-inventec_d7032q28b-r0/plugins/psuutil.py b/device/inventec/x86_64-inventec_d7032q28b-r0/plugins/psuutil.py index cc5ca004dadf..2e058a9e410e 100644 --- a/device/inventec/x86_64-inventec_d7032q28b-r0/plugins/psuutil.py +++ b/device/inventec/x86_64-inventec_d7032q28b-r0/plugins/psuutil.py @@ -22,8 +22,8 @@ def __init__(self): # Get sysfs attribute def get_attr_value(self, attr_path): - - retval = 'ERR' + + retval = 'ERR' if (not os.path.isfile(attr_path)): return retval @@ -35,7 +35,7 @@ def get_attr_value(self, attr_path): retval = retval.rstrip(' \t\n\r') return retval - + def get_num_psus(self): """ Retrieves the number of PSUs available on the device @@ -54,17 +54,17 @@ def get_psu_status(self, index): """ status = 0 if (index == 1): - ind = 2 + ind = 2 if (index == 2): - ind = 1 - attr_file = 'psu'+ str(ind) + '_iout' - attr_path = self.PSU_DIR +'/' + attr_file - + ind = 1 + attr_file = 'psu' + str(ind) + '_iout' + attr_path = self.PSU_DIR + '/' + attr_file + attr_value = self.get_attr_value(attr_path) if (attr_value != 'ERR'): # Check for PSU status if (attr_value != 0): - status = 1 + status = 1 return status def get_psu_presence(self, index): @@ -77,12 +77,12 @@ def get_psu_presence(self, index): status = 0 psu_absent = 0 ind = index-1 - attr_file ='psu'+ str(ind) - attr_path = self.PSU_DIR +'/' + attr_file - normal_attr_value = '0 : normal' + attr_file = 'psu' + str(ind) + attr_path = self.PSU_DIR + '/' + attr_file + normal_attr_value = '0 : normal' attr_value = self.get_attr_value(attr_path) if (attr_value != 'ERR'): # Check for PSU presence if (attr_value == normal_attr_value): - status = 1 + status = 1 return status diff --git a/device/inventec/x86_64-inventec_d7032q28b-r0/plugins/sfputil.py b/device/inventec/x86_64-inventec_d7032q28b-r0/plugins/sfputil.py index d109f49f2e7d..5321e0c072e8 100644 --- a/device/inventec/x86_64-inventec_d7032q28b-r0/plugins/sfputil.py +++ b/device/inventec/x86_64-inventec_d7032q28b-r0/plugins/sfputil.py @@ -73,7 +73,7 @@ def qsfp_port_end(self): @property def qsfp_ports(self): - return range(0, self.PORTS_IN_BLOCK + 1) + return list(range(0, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -95,7 +95,7 @@ def get_presence(self, port_num): try: reg_file = open("/sys/class/swps/port"+str(port_num)+"/present") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = int(reg_file.readline().rstrip()) @@ -113,7 +113,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open("/sys/class/swps/port"+str(port_num)+"/lpmod") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) reg_value = int(reg_file.readline().rstrip()) @@ -130,7 +130,7 @@ def set_low_power_mode(self, port_num, lpmode): try: reg_file = open("/sys/class/swps/port"+str(port_num)+"/lpmod", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = int(reg_file.readline().rstrip()) @@ -155,7 +155,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 0 @@ -169,7 +169,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 1 diff --git a/device/inventec/x86_64-inventec_d7054q28b-r0/plugins/eeprom.py b/device/inventec/x86_64-inventec_d7054q28b-r0/plugins/eeprom.py index de5c24ba0e6d..31f847614fb0 100644 --- a/device/inventec/x86_64-inventec_d7054q28b-r0/plugins/eeprom.py +++ b/device/inventec/x86_64-inventec_d7054q28b-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Inventec d7032q28b # @@ -11,8 +9,8 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/inventec/x86_64-inventec_d7054q28b-r0/plugins/psuutil.py b/device/inventec/x86_64-inventec_d7054q28b-r0/plugins/psuutil.py index 4bd3f7a27052..162e240bae35 100644 --- a/device/inventec/x86_64-inventec_d7054q28b-r0/plugins/psuutil.py +++ b/device/inventec/x86_64-inventec_d7054q28b-r0/plugins/psuutil.py @@ -22,8 +22,8 @@ def __init__(self): # Get sysfs attribute def get_attr_value(self, attr_path): - - retval = 'ERR' + + retval = 'ERR' if (not os.path.isfile(attr_path)): return retval @@ -35,7 +35,7 @@ def get_attr_value(self, attr_path): retval = retval.rstrip(' \t\n\r') return retval - + def get_num_psus(self): """ Retrieves the number of PSUs available on the device @@ -53,14 +53,14 @@ def get_psu_status(self, index): faulty """ status = 0 - attr_file = 'psoc_psu'+ str(index) + '_iout' - attr_path = self.PSU_DIR +'/' + attr_file - + attr_file = 'psoc_psu' + str(index) + '_iout' + attr_path = self.PSU_DIR + '/' + attr_file + attr_value = self.get_attr_value(attr_path) if (attr_value != 'ERR'): # Check for PSU status if (attr_value != 0): - status = 1 + status = 1 return status def get_psu_presence(self, index): @@ -73,12 +73,12 @@ def get_psu_presence(self, index): status = 0 psu_absent = 0 ind = index-1 - attr_file ='psu'+ str(ind) - attr_path = self.PSU_DIR +'/' + attr_file - normal_attr_value = '0 : normal' + attr_file = 'psu' + str(ind) + attr_path = self.PSU_DIR + '/' + attr_file + normal_attr_value = '0 : normal' attr_value = self.get_attr_value(attr_path) if (attr_value != 'ERR'): # Check for PSU presence if (attr_value == normal_attr_value): - status = 1 + status = 1 return status diff --git a/device/inventec/x86_64-inventec_d7054q28b-r0/plugins/sfputil.py b/device/inventec/x86_64-inventec_d7054q28b-r0/plugins/sfputil.py index 5dffdd0335b0..93baaa88ac3e 100755 --- a/device/inventec/x86_64-inventec_d7054q28b-r0/plugins/sfputil.py +++ b/device/inventec/x86_64-inventec_d7054q28b-r0/plugins/sfputil.py @@ -95,7 +95,7 @@ def qsfp_port_end(self): @property def qsfp_ports(self): - return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -117,7 +117,7 @@ def get_presence(self, port_num): try: reg_file = open("/sys/class/swps/port"+str(port_num)+"/present") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = int(reg_file.readline().rstrip()) @@ -137,7 +137,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open("/sys/class/swps/port"+str(port_num)+"/lpmod") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) reg_value = int(reg_file.readline().rstrip()) @@ -151,13 +151,13 @@ def set_low_power_mode(self, port_num, lpmode): if port_num < self.port_start or port_num > self.port_end: return False if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: - print "\nError:SFP's don't support this property" + print("\nError:SFP's don't support this property") return False try: reg_file = open("/sys/class/swps/port"+str(port_num)+"/lpmod", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = int(reg_file.readline().rstrip()) @@ -179,13 +179,13 @@ def reset(self, port_num): if port_num < self.port_start or port_num > self.port_end: return False if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: - print "\nError:SFP's don't support this property" + print("\nError:SFP's don't support this property") return False try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 0 @@ -199,7 +199,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 1 diff --git a/device/inventec/x86_64-inventec_d7264q28b-r0/plugins/eeprom.py b/device/inventec/x86_64-inventec_d7264q28b-r0/plugins/eeprom.py index de5c24ba0e6d..31f847614fb0 100644 --- a/device/inventec/x86_64-inventec_d7264q28b-r0/plugins/eeprom.py +++ b/device/inventec/x86_64-inventec_d7264q28b-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Inventec d7032q28b # @@ -11,8 +9,8 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/inventec/x86_64-inventec_d7264q28b-r0/plugins/psuutil.py b/device/inventec/x86_64-inventec_d7264q28b-r0/plugins/psuutil.py index c2337a97f4ea..8e100d36405d 100755 --- a/device/inventec/x86_64-inventec_d7264q28b-r0/plugins/psuutil.py +++ b/device/inventec/x86_64-inventec_d7264q28b-r0/plugins/psuutil.py @@ -23,8 +23,8 @@ def __init__(self): # Get sysfs attribute def get_attr_value(self, attr_path): - - retval = 'ERR' + + retval = 'ERR' if (not os.path.isfile(attr_path)): return retval @@ -36,7 +36,7 @@ def get_attr_value(self, attr_path): retval = retval.rstrip(' \t\n\r') return retval - + def get_num_psus(self): """ Retrieves the number of PSUs available on the device @@ -54,18 +54,18 @@ def get_psu_status(self, index): faulty """ status = 0 - attr_file = 'psoc_psu'+ str(index) + '_iout' - attr_path = self.PSU_DIR1 +'/' + attr_file - + attr_file = 'psoc_psu' + str(index) + '_iout' + attr_path = self.PSU_DIR1 + '/' + attr_file + attr_value = self.get_attr_value(attr_path) if (attr_value == 'ERR'): - attr_path = self.PSU_DIR2 +'/' + attr_file + attr_path = self.PSU_DIR2 + '/' + attr_file attr_value = self.get_attr_value(attr_path) # Check for PSU status if (attr_value != 0): - status = 1 + status = 1 if (attr_value != 0): - status = 1 + status = 1 return status def get_psu_presence(self, index): @@ -78,16 +78,16 @@ def get_psu_presence(self, index): status = 0 psu_absent = 0 ind = index-1 - attr_file ='psu'+ str(ind) + attr_file = 'psu' + str(ind) normal_attr_value = '0 : normal' - attr_path = self.PSU_DIR1 +'/' + attr_file + attr_path = self.PSU_DIR1 + '/' + attr_file attr_value = self.get_attr_value(attr_path) if (attr_value == 'ERR'): - attr_path = self.PSU_DIR2 +'/' + attr_file + attr_path = self.PSU_DIR2 + '/' + attr_file attr_value = self.get_attr_value(attr_path) # Check for PSU presence if (attr_value == normal_attr_value): - status = 1 + status = 1 if (attr_value == normal_attr_value): - status = 1 + status = 1 return status diff --git a/device/inventec/x86_64-inventec_d7264q28b-r0/plugins/sfputil.py b/device/inventec/x86_64-inventec_d7264q28b-r0/plugins/sfputil.py index 6f23ad01bd2c..6591809194af 100755 --- a/device/inventec/x86_64-inventec_d7264q28b-r0/plugins/sfputil.py +++ b/device/inventec/x86_64-inventec_d7264q28b-r0/plugins/sfputil.py @@ -76,15 +76,15 @@ class SfpUtil(SfpUtilBase): 52: 65, 53: 64, 54: 63, - 55: 62, - 56: 69, - 57: 68, - 58: 67, - 59: 66, - 60: 73, - 61: 72, - 62: 71, - 63: 70 + 55: 62, + 56: 69, + 57: 68, + 58: 67, + 59: 66, + 60: 73, + 61: 72, + 62: 71, + 63: 70 } @property @@ -105,7 +105,7 @@ def qsfp_port_end(self): @property def qsfp_ports(self): - return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -127,7 +127,7 @@ def get_presence(self, port_num): try: reg_file = open("/sys/class/swps/port"+str(port_num)+"/present") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = int(reg_file.readline().rstrip()) @@ -147,7 +147,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open("/sys/class/swps/port"+str(port_num)+"/lpmod") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) reg_value = int(reg_file.readline().rstrip()) @@ -161,13 +161,13 @@ def set_low_power_mode(self, port_num, lpmode): if port_num < self.port_start or port_num > self.port_end: return False if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: - print "\nError:SFP's don't support this property" + print("\nError:SFP's don't support this property") return False try: reg_file = open("/sys/class/swps/port"+str(port_num)+"/lpmod", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = int(reg_file.readline().rstrip()) @@ -189,13 +189,13 @@ def reset(self, port_num): if port_num < self.port_start or port_num > self.port_end: return False if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: - print "\nError:SFP's don't support this property" + print("\nError:SFP's don't support this property") return False try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 0 @@ -209,7 +209,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 1 diff --git a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/eeprom.py b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/eeprom.py index 49a903290a18..33898d83a0e9 100644 --- a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/eeprom.py +++ b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/eeprom.py @@ -1,15 +1,14 @@ -#!/usr/bin/env python # # Name: eeprom.py version: 1.0 # -# Description: Platform-specific EEPROM interface for Juniper QFX5200 +# Description: Platform-specific EEPROM interface for Juniper QFX5200 # # Copyright (c) 2020, Juniper Networks, Inc. # All rights reserved. # -# Notice and Disclaimer: This code is licensed to you under the GNU General -# Public License as published by the Free Software Foundation, version 3 or -# any later version. This code is not an official Juniper product. You can +# Notice and Disclaimer: This code is licensed to you under the GNU General +# Public License as published by the Free Software Foundation, version 3 or +# any later version. This code is not an official Juniper product. You can # obtain a copy of the License at # # OSS License: @@ -27,9 +26,9 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . # -# Third-Party Code: This code may depend on other components under separate -# copyright notice and license terms. Your use of the source code for those -# components is subject to the terms and conditions of the respective license +# Third-Party Code: This code may depend on other components under separate +# copyright notice and license terms. Your use of the source code for those +# components is subject to the terms and conditions of the respective license # as noted in the Third-Party source code file. try: @@ -37,18 +36,19 @@ from sonic_eeprom import eeprom_tlvinfo import syslog from array import * - -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") SYSLOG_IDENTIFIER = "eeprom.py" EEPROM_PATH = "/sys/bus/i2c/devices/0-0051/eeprom" + def log_error(msg): syslog.openlog(SYSLOG_IDENTIFIER) syslog.syslog(syslog.LOG_ERR, msg) syslog.closelog() + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 @@ -60,4 +60,3 @@ def __init__(self, name, path, cpld_root, ro): self.eeprom_path = EEPROM_PATH super(board, self).__init__(self.eeprom_path, 0, '', True) - diff --git a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/led_control.py b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/led_control.py index d85b65696d69..223c6dc8a289 100644 --- a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/led_control.py +++ b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/led_control.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # # Name: led_control.py version: 1.0 # @@ -7,9 +6,9 @@ # Copyright (c) 2020, Juniper Networks, Inc. # All rights reserved. # -# Notice and Disclaimer: This code is licensed to you under the GNU General -# Public License as published by the Free Software Foundation, version 3 or -# any later version. This code is not an official Juniper product. You can +# Notice and Disclaimer: This code is licensed to you under the GNU General +# Public License as published by the Free Software Foundation, version 3 or +# any later version. This code is not an official Juniper product. You can # obtain a copy of the License at # # OSS License: @@ -27,8 +26,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . # -# Third-Party Code: This code may depend on other components under separate -# copyright notice and license terms. Your use of the source code for those +# Third-Party Code: This code may depend on other components under separate +# copyright notice and license terms. Your use of the source code for those # components is subject to the terms and conditions of the respective license # as noted in the Third-Party source code file. @@ -39,11 +38,10 @@ import glob from socket import * from select import * -except ImportError, e: +except ImportError as e: raise ImportError(str(e) + " - required module not found") - def DBG_PRINT(str): syslog.openlog("ledi_control") syslog.syslog(syslog.LOG_INFO, str) @@ -53,7 +51,7 @@ def DBG_PRINT(str): class LedControl(LedControlBase): """Platform specific LED control class""" SONIC_PORT_NAME_PREFIX = "Ethernet" - LED_MODE_OFF = 0 + LED_MODE_OFF = 0 LED_MODE_GREEN = 1 PORT_START = 0 PORT_END = 127 @@ -69,7 +67,7 @@ class LedControl(LedControlBase): GPIO_LANE3_PORT_LED_OFFSET = 112 # Turn OFF all port leds during init - def gpio_create_file(self,gpio_pin): + def gpio_create_file(self, gpio_pin): gpio_export_path = "/sys/class/gpio/export" gpio_pin_path = "/sys/class/gpio/gpio" + str(gpio_pin) if not os.path.exists(gpio_pin_path): @@ -78,61 +76,58 @@ def gpio_create_file(self,gpio_pin): gpio_export_file.write(str(gpio_pin)) gpio_export_file.close() except IOError as e: - print "Error: unable to open export file: %s" % str(e) + print("Error: unable to open export file: %s" % str(e)) return False return True - def gpio_port_led_init(self,gpio_base, port): - port_led_pin = gpio_base + self.GPIO_LANE0_PORT_LED_OFFSET + 16*(port%4) + ((port % 64)/4) + def gpio_port_led_init(self, gpio_base, port): + port_led_pin = gpio_base + self.GPIO_LANE0_PORT_LED_OFFSET + 16*(port % 4) + ((port % 64)/4) if self.gpio_create_file(port_led_pin): self.port_to_gpio_pin_mapping[port] = port_led_pin - - def gpio_port_led_slave_init(self,gpio_base_path, gpio_port_start, gpio_port_end): + def gpio_port_led_slave_init(self, gpio_base_path, gpio_port_start, gpio_port_end): flist = glob.glob(gpio_base_path) if len(flist) == 1: try: fp = open(flist[0] + "/base") gpio_base = int(fp.readline().rstrip()) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return for port in range(gpio_port_start, gpio_port_end + 1): self.gpio_port_led_init(gpio_base, port) - def gpio_port_led_base_init(self): self.gpio_port_led_slave_init("/sys/bus/platform/drivers/gpioslave-tmc/gpioslave-tmc.22/gpio/gpio*", - self.GPIO_SLAVE0_PORT_START, self.GPIO_SLAVE0_PORT_END) + self.GPIO_SLAVE0_PORT_START, self.GPIO_SLAVE0_PORT_END) self.gpio_port_led_slave_init("/sys/bus/platform/drivers/gpioslave-tmc/gpioslave-tmc.21/gpio/gpio*", - self.GPIO_SLAVE1_PORT_START, self.GPIO_SLAVE1_PORT_END) - + self.GPIO_SLAVE1_PORT_START, self.GPIO_SLAVE1_PORT_END) # Write driver for port led - def gpio_led_write(self,gpio_pin, value): + def gpio_led_write(self, gpio_pin, value): success = False gpio_pin_path = "/sys/class/gpio/gpio" + str(gpio_pin) try: - gpio_file = open(gpio_pin_path +"/value", 'w') + gpio_file = open(gpio_pin_path + "/value", 'w') gpio_file.write(str(value)) success = True except IOError as e: - print "error: unable to open file: %s" % str(e) + print("error: unable to open file: %s" % str(e)) return success # Read driver for port led - def gpio_led_read(self,gpio_pin): + def gpio_led_read(self, gpio_pin): gpio_pin_path = "/sys/class/gpio/gpio" + str(gpio_pin) value = 0 try: - reg_file = open(gpio_pin_path +"/value") + reg_file = open(gpio_pin_path + "/value") value = int(reg_file.readline().rstrip()) except IOError as e: - print "error: unable to open file: %s" % str(e) + print("error: unable to open file: %s" % str(e)) return value @@ -160,16 +155,16 @@ def _port_state_to_mode(self, state): else: return self.LED_MODE_OFF - # Set the port led mode to Green/OFF + def _port_led_mode_update(self, gpio_pin, ledMode): if ledMode == self.LED_MODE_GREEN: self.gpio_led_write(gpio_pin, 1) else: self.gpio_led_write(gpio_pin, 0) - # Concrete implementation of port_link_state_change() method + def port_link_state_change(self, portname, state): port_idx = self._port_name_to_index(portname) gpio_pin = self.port_to_gpio_pin_mapping[port_idx] diff --git a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/psuutil.py b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/psuutil.py index a7fef390b2a0..7ee1d3c38a3d 100644 --- a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/psuutil.py +++ b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/psuutil.py @@ -1,15 +1,14 @@ -#!/usr/bin/env python # # Name: psuutil.py version: 1.0 # -# Description: Platform-specific PSU status interface for Juniper QFX5200 +# Description: Platform-specific PSU status interface for Juniper QFX5200 # # Copyright (c) 2020, Juniper Networks, Inc. # All rights reserved. # -# Notice and Disclaimer: This code is licensed to you under the GNU General -# Public License as published by the Free Software Foundation, version 3 or -# any later version. This code is not an official Juniper product. You can +# Notice and Disclaimer: This code is licensed to you under the GNU General +# Public License as published by the Free Software Foundation, version 3 or +# any later version. This code is not an official Juniper product. You can # obtain a copy of the License at # # OSS License: @@ -27,9 +26,9 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . # -# Third-Party Code: This code may depend on other components under separate -# copyright notice and license terms. Your use of the source code for those -# components is subject to the terms and conditions of the respective license +# Third-Party Code: This code may depend on other components under separate +# copyright notice and license terms. Your use of the source code for those +# components is subject to the terms and conditions of the respective license # as noted in the Third-Party source code file. @@ -51,9 +50,11 @@ def __init__(self): # Get sysfs attribute + + def get_attr_value(self, attr_path): - - retval = 'ERR' + + retval = 'ERR' if (not os.path.isfile(attr_path)): return retval @@ -65,7 +66,7 @@ def get_attr_value(self, attr_path): retval = retval.rstrip(' \t\n\r') return int(retval) - + def get_num_psus(self): """ Retrieves the number of PSUs available on the device @@ -82,8 +83,8 @@ def get_psu_status(self, index): :return: Boolean, True if PSU is operating properly, False if PSU is\ faulty """ - attr_file = 'psu'+ str(index-1) +'_' + 'present' - attr_path = self.PSU_DIR +'/' + attr_file + attr_file = 'psu' + str(index-1) + '_' + 'present' + attr_path = self.PSU_DIR + '/' + attr_file attr_value = self.get_attr_value(attr_path) return attr_value == 1 @@ -95,7 +96,7 @@ def get_psu_presence(self, index): :param index: An integer, index of the PSU of which to query status :return: Boolean, True if PSU is plugged, False if not """ - attr_file ='psu'+ str(index-1) +'_' + 'present' - attr_path = self.PSU_DIR +'/' + attr_file + attr_file = 'psu' + str(index-1) + '_' + 'present' + attr_path = self.PSU_DIR + '/' + attr_file attr_value = self.get_attr_value(attr_path) return attr_value == 1 diff --git a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/qfx5200_eeprom_data.py b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/qfx5200_eeprom_data.py index 7d7465212050..ea53f11e698d 100644 --- a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/qfx5200_eeprom_data.py +++ b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/qfx5200_eeprom_data.py @@ -1,15 +1,15 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # Name: juniper_qfx5200_eepromconv.py version: 1.0 # -# Description: This file contains the code to store the contents of Main Board EEPROM and CPU Board EEPROM in file +# Description: This file contains the code to store the contents of Main Board EEPROM and CPU Board EEPROM in file # # Copyright (c) 2020, Juniper Networks, Inc. # All rights reserved. # -# Notice and Disclaimer: This code is licensed to you under the GNU General -# Public License as published by the Free Software Foundation, version 3 or -# any later version. This code is not an official Juniper product. You can +# Notice and Disclaimer: This code is licensed to you under the GNU General +# Public License as published by the Free Software Foundation, version 3 or +# any later version. This code is not an official Juniper product. You can # obtain a copy of the License at # # OSS License: @@ -27,16 +27,21 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . # -# Third-Party Code: This code may depend on other components under separate -# copyright notice and license terms. Your use of the source code for those -# components is subject to the terms and conditions of the respective license +# Third-Party Code: This code may depend on other components under separate +# copyright notice and license terms. Your use of the source code for those +# components is subject to the terms and conditions of the respective license # as noted in the Third-Party source code file. -import os -import commands import binascii +import os +import sys from sonic_eeprom import eeprom_tlvinfo +if sys.version_info[0] < 3: + import commands +else: + import subprocess as commands + def fantype_detect(): @@ -45,7 +50,7 @@ def fantype_detect(): AFO = "1" AFI = "0" - #default fan type is AFO + # default fan type is AFO default_fantype = "0" for filename in os.listdir(refpgaTMC_path): @@ -53,14 +58,13 @@ def fantype_detect(): fantype_path = os.path.join(refpgaTMC_path, filename) cat_string = "cat " fantype_string = cat_string + fantype_path - status,fan_type=commands.getstatusoutput(fantype_string) + status, fan_type = commands.getstatusoutput(fantype_string) if ((fan_type == AFO) or (fan_type == AFI)): return fan_type else: pass - return default_fantype - + return default_fantype def main(): @@ -69,9 +73,9 @@ def main(): eeprom_qfx5200 = Eeprom() fan_type = fantype_detect() - + # creating the "/var/run/eeprom" file and storing values of CPU board EEPROM and MAIN Board EEPROM in this file. - eeprom_file = open ("/var/run/eeprom", "a+") + eeprom_file = open("/var/run/eeprom", "a+") eeprom_file.write("\n") if fan_type == AFO_value: eeprom_file.write("Fan Type=AFO\r\n") @@ -95,29 +99,29 @@ def main(): eeprom_dict = eeprom_qfx5200.system_eeprom_info() key = '0x29' - if key in eeprom_dict.keys(): + if key in list(eeprom_dict.keys()): onie_version_str = eeprom_dict.get('0x29', None) else: onie_version_str = "N/A" eeprom_file.write("ONIE Version=%s\r\n" % onie_version_str) vendor_value_formatted, vendor_value_hexvalue = eeprom_qfx5200.vendor_ext_str() - + eeprom_hex = '/etc/init.d/eeprom_qfx5200_hex' with open(eeprom_hex, 'wb+') as Hexfile: Hexfile.write(vendor_value_hexvalue) - # Assembly ID + # Assembly ID ASMID_str = "0D83" with open(eeprom_hex, 'rb+') as AsmID_Hexfile: AsmID_Hexfile.seek(24, 0) AsmID_Hexfile.write(ASMID_str) AsmID_Hexfile.seek(0, 0) vendorext_read = AsmID_Hexfile.read(58) - vendorext="" + vendorext = "" vendorext += "0x" + vendorext_read[0:2] - for i in range(2,58,2): + for i in range(2, 58, 2): vendorext += " 0x" + vendorext_read[i:i+2] eeprom_file.write("Vendor Extension=%s\r\n" % str(vendorext)) @@ -139,31 +143,26 @@ def main(): eeprom_file.write("\t") eeprom_file.write("Assembly ID=0x%s\r\n" % AssemblyID_write) - eeprom_hexfile.seek(28, 0) HWMajorRev_write = eeprom_hexfile.read(2) eeprom_file.write("\t") eeprom_file.write("HW Major Revision=0x%s\r\n" % HWMajorRev_write) - eeprom_hexfile.seek(30, 0) HWMinorRev_write = eeprom_hexfile.read(2) eeprom_file.write("\t") eeprom_file.write("HW Minor Revision=0x%s\r\n" % HWMinorRev_write) - eeprom_hexfile.seek(32, 0) Deviation_write = eeprom_hexfile.read(10) eeprom_file.write("\t") eeprom_file.write("Deviation=0x%s\r\n" % Deviation_write) - eeprom_hexfile.seek(52, 0) JEDC_write = eeprom_hexfile.read(4) eeprom_file.write("\t") eeprom_file.write("JEDC=0x%s\r\n" % JEDC_write) - eeprom_hexfile.seek(56, 0) EEPROM_version_write = eeprom_hexfile.read(2) eeprom_file.write("\t") @@ -182,14 +181,14 @@ def main(): try: os.system(MainEepromCreate) except OSError: - print 'Error: Execution of "%s" failed', MainEepromCreate + print('Error: Execution of "%s" failed', MainEepromCreate) return False MainEepromFileCmd = 'cat /sys/bus/i2c/devices/i2c-0/0-0057/eeprom > /etc/init.d/MainEeprom_qfx5200_ascii' try: os.system(MainEepromFileCmd) except OSError: - print 'Error: Execution of "%s" failed', MainEepromFileCmd + print('Error: Execution of "%s" failed', MainEepromFileCmd) return False maineeprom_ascii = '/etc/init.d/MainEeprom_qfx5200_ascii' @@ -200,7 +199,7 @@ def main(): Hexformatoutput = binascii.hexlify(content) eeprom_hex = '/etc/init.d/MainEeprom_qfx5200_hex' - #Write contents of CPU EEPROM to new file in hexa format + # Write contents of CPU EEPROM to new file in hexa format with open(eeprom_hex, 'wb+') as Hexfile: Hexfile.write(Hexformatoutput) @@ -245,7 +244,7 @@ def main(): FRUModelNumber_read = eeprom_hexfile.read(46) FRUModelNumber_write = binascii.unhexlify(FRUModelNumber_read) eeprom_file.write("FRU Model Number=%s\r\n" % str(FRUModelNumber_write)) - + eeprom_hexfile.seek(204, 0) FRUModelMajorNumber_read = eeprom_hexfile.read(2) eeprom_file.write("FRU Model Major Number=0x%s\r\n" % str(FRUModelMajorNumber_read)) @@ -264,7 +263,8 @@ def main(): eeprom_file.write("Chassis Serial Number=%s\r\n" % str(SerialNumber_write)) eeprom_file.close() return True - + + class Eeprom(eeprom_tlvinfo.TlvInfoDecoder): def __init__(self): self.__eeprom_path = "/sys/class/i2c-adapter/i2c-0/0-0051/eeprom" @@ -308,14 +308,14 @@ def __init__(self): def serial_number_str(self): (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_SERIAL_NUMBER) + self.__eeprom_data, self._TLV_CODE_SERIAL_NUMBER) if not is_valid: return "N/A" return results[2] def base_mac_address(self): (is_valid, t) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_MAC_BASE) + self.__eeprom_data, self._TLV_CODE_MAC_BASE) if not is_valid or t[1] != 6: return super(eeprom_tlvinfo.TlvInfoDecoder, self).switchaddrstr(self.__eeprom_data) @@ -323,7 +323,7 @@ def base_mac_address(self): def modelstr(self): (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_PRODUCT_NAME) + self.__eeprom_data, self._TLV_CODE_PRODUCT_NAME) if not is_valid: return "N/A" @@ -331,7 +331,7 @@ def modelstr(self): def part_number_str(self): (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_PART_NUMBER) + self.__eeprom_data, self._TLV_CODE_PART_NUMBER) if not is_valid: return "N/A" @@ -339,7 +339,7 @@ def part_number_str(self): def serial_tag_str(self): (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_SERVICE_TAG) + self.__eeprom_data, self._TLV_CODE_SERVICE_TAG) if not is_valid: return "N/A" @@ -347,7 +347,7 @@ def serial_tag_str(self): def revision_str(self): (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_DEVICE_VERSION) + self.__eeprom_data, self._TLV_CODE_DEVICE_VERSION) if not is_valid: return "N/A" @@ -355,7 +355,7 @@ def revision_str(self): def manuDate_str(self): (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_MANUF_DATE) + self.__eeprom_data, self._TLV_CODE_MANUF_DATE) if not is_valid: return "N/A" @@ -363,23 +363,23 @@ def manuDate_str(self): def platform_str(self): (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_PLATFORM_NAME) + self.__eeprom_data, self._TLV_CODE_PLATFORM_NAME) if not is_valid: return "N/A" return results[2] def MACsize_str(self): - (is_valid, t) = self.get_tlv_field(self.__eeprom_data, self._TLV_CODE_MAC_SIZE) - - if not is_valid: - return "N/A" + (is_valid, t) = self.get_tlv_field(self.__eeprom_data, self._TLV_CODE_MAC_SIZE) - return str((ord(t[2][0]) << 8) | ord(t[2][1])) + if not is_valid: + return "N/A" + + return str((ord(t[2][0]) << 8) | ord(t[2][1])) def vendor_name_str(self): (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_VENDOR_NAME) + self.__eeprom_data, self._TLV_CODE_VENDOR_NAME) if not is_valid: return "N/A" @@ -387,7 +387,7 @@ def vendor_name_str(self): def manufacture_name_str(self): (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_MANUF_NAME) + self.__eeprom_data, self._TLV_CODE_MANUF_NAME) if not is_valid: return "N/A" @@ -396,31 +396,31 @@ def manufacture_name_str(self): def onie_version_str(self): value = "" (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_ONIE_VERSION) + self.__eeprom_data, self._TLV_CODE_ONIE_VERSION) if not is_valid: return "N/A" for c in results[2:2 + ord(results[1])]: value += "0x%02X " % (ord(c),) - + return value def vendor_ext_str(self): (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_VENDOR_EXT) + self.__eeprom_data, self._TLV_CODE_VENDOR_EXT) if not is_valid: return "N/A" - vendor_value_formatted = ''.join( [ " 0x" + "%02X " % ord( x ) for x in results[2] ] ).strip() - vendor_value_hexvalue = ''.join( ["%02X" % ord( x ) for x in results[2] ] ).strip() + vendor_value_formatted = ''.join([" 0x" + "%02X " % ord(x) for x in results[2]]).strip() + vendor_value_hexvalue = ''.join(["%02X" % ord(x) for x in results[2]]).strip() return vendor_value_formatted, vendor_value_hexvalue def crc_str(self): (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_CRC_32) + self.__eeprom_data, self._TLV_CODE_CRC_32) if not is_valid: return "N/A" @@ -432,5 +432,6 @@ def system_eeprom_info(self): """ return self.__eeprom_tlv_dict + if __name__ == "__main__": main() diff --git a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/qfx5200_sfp_init.py b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/qfx5200_sfp_init.py index 3f33e4dc152a..723a4073687e 100644 --- a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/qfx5200_sfp_init.py +++ b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/qfx5200_sfp_init.py @@ -1,15 +1,15 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # Name: juniper_sfp_init.py version: 1.0 # -# Description: Platform-specific SFP Transceiver Initialization for Juniper QFX5200 +# Description: Platform-specific SFP Transceiver Initialization for Juniper QFX5200 # # Copyright (c) 2020, Juniper Networks, Inc. # All rights reserved. # -# Notice and Disclaimer: This code is licensed to you under the GNU General -# Public License as published by the Free Software Foundation, version 3 or -# any later version. This code is not an official Juniper product. You can +# Notice and Disclaimer: This code is licensed to you under the GNU General +# Public License as published by the Free Software Foundation, version 3 or +# any later version. This code is not an official Juniper product. You can # obtain a copy of the License at # # OSS License: @@ -27,9 +27,9 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . # -# Third-Party Code: This code may depend on other components under separate -# copyright notice and license terms. Your use of the source code for those -# components is subject to the terms and conditions of the respective license +# Third-Party Code: This code may depend on other components under separate +# copyright notice and license terms. Your use of the source code for those +# components is subject to the terms and conditions of the respective license # as noted in the Third-Party source code file. import time @@ -45,6 +45,7 @@ DEBUG = False + def i2c_eeprom_dev_update(port, create_eeprom): eeprom_path = "/sys/class/i2c-adapter/i2c-{0}/{0}-0050/eeprom" i2c_path = "/sys/class/i2c-adapter/i2c-{0}" @@ -57,7 +58,7 @@ def i2c_eeprom_dev_update(port, create_eeprom): i2c_file = open(port_i2c_path + "/new_device", "w") i2c_file.write("optoe2 0x50") except IOError as e: - print "Error: unable to write to i2c file: %s" % str(e) + print("Error: unable to write to i2c file: %s" % str(e)) return else: if os.path.exists(port_eeprom_path): @@ -65,24 +66,25 @@ def i2c_eeprom_dev_update(port, create_eeprom): i2c_file = open(port_i2c_path + "/delete_device", "w") i2c_file.write("0x50") except IOError as e: - print "Error: unable to write to i2c file: %s" % str(e) + print("Error: unable to write to i2c file: %s" % str(e)) return + def gpio_sfp_init(): jnpr_sfp.gpio_sfp_base_init() time.sleep(2) - #Reset all ports + # Reset all ports for port in range(jnpr_sfp.GPIO_PORT_START, jnpr_sfp.GPIO_PORT_END + 1): logger.log_debug("GPIO SFP port {}".format(port)) - + jnpr_sfp.gpio_sfp_reset_set(port, 0) i2c_eeprom_dev_update(port, True) time.sleep(1) - #Enable optics for all ports which have XCVRs present + # Enable optics for all ports which have XCVRs present for port in range(jnpr_sfp.GPIO_PORT_START, jnpr_sfp.GPIO_PORT_END + 1): jnpr_sfp.gpio_sfp_lpmode_set(port, 1) @@ -90,13 +92,13 @@ def gpio_sfp_init(): if __name__ == '__main__': if DEBUG == True: - print "Initializing Juniper SFP module" + print("Initializing Juniper SFP module") gpio_sfp_init() if DEBUG == True: - print "Juniper GPIO presence pin mapping:" + print("Juniper GPIO presence pin mapping:") pprint(jnpr_sfp.gpio_sfp_presence) - print "Juniper GPIO reset pin mapping:" + print("Juniper GPIO reset pin mapping:") pprint(jnpr_sfp.gpio_sfp_reset) - print "Juniper GPIO lpmode pin mapping:" + print("Juniper GPIO lpmode pin mapping:") pprint(jnpr_sfp.gpio_sfp_lpmode) diff --git a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/sfputil.py b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/sfputil.py index 91957139967d..54dbdacc1c21 100644 --- a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/sfputil.py +++ b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/sfputil.py @@ -1,15 +1,13 @@ -#!/usr/bin/env python -# # Name: sfputil.py version: 1.0 # -# Description: Platform-specific SFP transceiver interface for Juniper QFX5200 +# Description: Platform-specific SFP transceiver interface for Juniper QFX5200 # # Copyright (c) 2020, Juniper Networks, Inc. # All rights reserved. # -# Notice and Disclaimer: This code is licensed to you under the GNU General -# Public License as published by the Free Software Foundation, version 3 or -# any later version. This code is not an official Juniper product. You can +# Notice and Disclaimer: This code is licensed to you under the GNU General +# Public License as published by the Free Software Foundation, version 3 or +# any later version. This code is not an official Juniper product. You can # obtain a copy of the License at # # OSS License: @@ -27,9 +25,9 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . # -# Third-Party Code: This code may depend on other components under separate -# copyright notice and license terms. Your use of the source code for those -# components is subject to the terms and conditions of the respective license +# Third-Party Code: This code may depend on other components under separate +# copyright notice and license terms. Your use of the source code for those +# components is subject to the terms and conditions of the respective license # as noted in the Third-Party source code file. try: @@ -54,23 +52,23 @@ logger = Logger(SYSLOG_IDENTIFIER) qfx5200_qsfp_cable_length_tup = ('Length(km)', 'Length OM3(2m)', - 'Length OM2(m)', 'Length OM1(m)', - 'Length Cable Assembly(m)') - + 'Length OM2(m)', 'Length OM1(m)', + 'Length Cable Assembly(m)') + qfx5200_sfp_cable_length_tup = ('LengthSMFkm-UnitsOfKm', 'LengthSMF(UnitsOf100m)', - 'Length50um(UnitsOf10m)', 'Length62.5um(UnitsOfm)', - 'LengthCable(UnitsOfm)', 'LengthOM3(UnitsOf10m)') - + 'Length50um(UnitsOf10m)', 'Length62.5um(UnitsOfm)', + 'LengthCable(UnitsOfm)', 'LengthOM3(UnitsOf10m)') + qfx5200_sfp_compliance_code_tup = ('10GEthernetComplianceCode', 'InfinibandComplianceCode', - 'ESCONComplianceCodes', 'SONETComplianceCodes', - 'EthernetComplianceCodes','FibreChannelLinkLength', - 'FibreChannelTechnology', 'SFP+CableTechnology', - 'FibreChannelTransmissionMedia','FibreChannelSpeed') - + 'ESCONComplianceCodes', 'SONETComplianceCodes', + 'EthernetComplianceCodes', 'FibreChannelLinkLength', + 'FibreChannelTechnology', 'SFP+CableTechnology', + 'FibreChannelTransmissionMedia', 'FibreChannelSpeed') + qfx5200_qsfp_compliance_code_tup = ('10/40G Ethernet Compliance Code', 'SONET Compliance codes', - 'SAS/SATA compliance codes', 'Gigabit Ethernet Compliant codes', - 'Fibre Channel link length/Transmitter Technology', - 'Fibre Channel transmission media', 'Fibre Channel Speed') + 'SAS/SATA compliance codes', 'Gigabit Ethernet Compliant codes', + 'Fibre Channel link length/Transmitter Technology', + 'Fibre Channel transmission media', 'Fibre Channel Speed') GPIO_SLAVE0_PORT_START = 0 @@ -122,7 +120,7 @@ OSFP_HW_REV_OFFSET = 164 OSFP_VENDOR_SN_OFFSET = 166 -#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 @@ -155,21 +153,22 @@ def gpio_create_file(gpio_pin): gpio_export_file.write(str(gpio_pin)) gpio_export_file.close() except IOError as e: - print "Error: unable to open export file: %s" % str(e) + print("Error: unable to open export file: %s" % str(e)) return False - + return True + def gpio_sfp_port_init(gpio_base, port): - presence_pin = gpio_base + GPIO_PRESENCE_OFFSET + (port % 16) - if gpio_create_file(presence_pin): - gpio_sfp_presence[port] = presence_pin - reset_pin = gpio_base + GPIO_RESET_OFFSET + (port % 16) - if gpio_create_file(reset_pin): - gpio_sfp_reset[port] = reset_pin - lpmode_pin = gpio_base + GPIO_LPMODE_OFFSET + (port % 16) - if gpio_create_file(lpmode_pin): - gpio_sfp_lpmode[port] = lpmode_pin + presence_pin = gpio_base + GPIO_PRESENCE_OFFSET + (port % 16) + if gpio_create_file(presence_pin): + gpio_sfp_presence[port] = presence_pin + reset_pin = gpio_base + GPIO_RESET_OFFSET + (port % 16) + if gpio_create_file(reset_pin): + gpio_sfp_reset[port] = reset_pin + lpmode_pin = gpio_base + GPIO_LPMODE_OFFSET + (port % 16) + if gpio_create_file(lpmode_pin): + gpio_sfp_lpmode[port] = lpmode_pin def gpio_sfp_slave_init(gpio_base_path, gpio_port_start, gpio_port_end): @@ -179,72 +178,80 @@ def gpio_sfp_slave_init(gpio_base_path, gpio_port_start, gpio_port_end): fp = open(flist[0]+"/base") gpio_base = int(fp.readline().rstrip()) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return - - for port in range(gpio_port_start, gpio_port_end + 1): + + for port in range(gpio_port_start, gpio_port_end + 1): gpio_sfp_port_init(gpio_base, port) + def gpio_sfp_base_init(): gpio_sfp_slave_init("/sys/bus/platform/drivers/gpioslave-tmc/gpioslave-tmc.21/gpio/gpio*", - GPIO_SLAVE0_PORT_START, GPIO_SLAVE0_PORT_END) + GPIO_SLAVE0_PORT_START, GPIO_SLAVE0_PORT_END) gpio_sfp_slave_init("/sys/bus/platform/drivers/gpioslave-tmc/gpioslave-tmc.22/gpio/gpio*", - GPIO_SLAVE1_PORT_START, GPIO_SLAVE1_PORT_END) + GPIO_SLAVE1_PORT_START, GPIO_SLAVE1_PORT_END) + def gpio_sfp_read(gpio_pin): gpio_pin_path = "/sys/class/gpio/gpio" + str(gpio_pin) value = 0 try: - reg_file = open(gpio_pin_path +"/value") + reg_file = open(gpio_pin_path + "/value") value = int(reg_file.readline().rstrip()) except IOError as e: - print "error: unable to open file: %s" % str(e) - + print("error: unable to open file: %s" % str(e)) + return value + def gpio_sfp_write(gpio_pin, value): success = False gpio_pin_path = "/sys/class/gpio/gpio" + str(gpio_pin) try: - gpio_file = open(gpio_pin_path +"/value", 'w') + gpio_file = open(gpio_pin_path + "/value", 'w') gpio_file.write(str(value)) success = True except IOError as e: - print "error: unable to open file: %s" % str(e) + print("error: unable to open file: %s" % str(e)) return success + def gpio_sfp_presence_get(port): - if port not in gpio_sfp_presence.keys(): - print "Port:" + str(port) + " not in sfp dict" + if port not in list(gpio_sfp_presence.keys()): + print("Port:" + str(port) + " not in sfp dict") return 0 gpio_pin = gpio_sfp_presence[port] return gpio_sfp_read(gpio_pin) + def gpio_sfp_lpmode_get(port): - if port not in gpio_sfp_lpmode.keys(): + if port not in list(gpio_sfp_lpmode.keys()): return 0 gpio_pin = gpio_sfp_lpmode[port] return gpio_sfp_read(gpio_pin) + def gpio_sfp_lpmode_set(port, value): - if port not in gpio_sfp_lpmode.keys(): + if port not in list(gpio_sfp_lpmode.keys()): return False gpio_pin = gpio_sfp_lpmode[port] return gpio_sfp_write(gpio_pin, value) + def gpio_sfp_reset_set(port, value): - if port not in gpio_sfp_reset.keys(): + if port not in list(gpio_sfp_reset.keys()): return False gpio_pin = gpio_sfp_reset[port] return gpio_sfp_write(gpio_pin, value) + class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" @@ -291,57 +298,57 @@ class SfpUtil(SfpUtilBase): 30: 44, 31: 45 } - + port_ctle_settings = { - 0: 119, # 0x77 - 1: 102, # 0x66 - 2: 102, # 0x66 - 3: 102, # 0x66 - 4: 102, # 0x66 - 5: 85, # 0x55 - 6: 102, # 0x66 - 7: 85, # 0x55 - 8: 85, # 0x55 - 9: 85, # 0x55 - 10: 119, # 0x77 - 11: 119, # 0x77 - 12: 102, # 0x66 - 13: 85, # 0x55 - 14: 68, # 0x44 - 15: 51, # 0x33 - 16: 68, # 0x44 - 17: 85, # 0x55 - 18: 102, # 0x66 - 19: 102, # 0x66 - 20: 119, # 0X77 - 21: 102, # 0x66 - 22: 85, # 0X55 - 23: 85, # 0X55 - 24: 85, # 0x55 - 25: 85, # 0x55 - 26: 102, # 0x66 - 27: 85, # 0x55 - 28: 102, # 0x66 - 29: 102, # 0x66 - 30: 119, # 0x77 - 31: 119 # 0x77 + 0: 119, # 0x77 + 1: 102, # 0x66 + 2: 102, # 0x66 + 3: 102, # 0x66 + 4: 102, # 0x66 + 5: 85, # 0x55 + 6: 102, # 0x66 + 7: 85, # 0x55 + 8: 85, # 0x55 + 9: 85, # 0x55 + 10: 119, # 0x77 + 11: 119, # 0x77 + 12: 102, # 0x66 + 13: 85, # 0x55 + 14: 68, # 0x44 + 15: 51, # 0x33 + 16: 68, # 0x44 + 17: 85, # 0x55 + 18: 102, # 0x66 + 19: 102, # 0x66 + 20: 119, # 0X77 + 21: 102, # 0x66 + 22: 85, # 0X55 + 23: 85, # 0X55 + 24: 85, # 0x55 + 25: 85, # 0x55 + 26: 102, # 0x66 + 27: 85, # 0x55 + 28: 102, # 0x66 + 29: 102, # 0x66 + 30: 119, # 0x77 + 31: 119 # 0x77 } optics_list_100g = { - "AFBR-89CDDZ-JU1", + "AFBR-89CDDZ-JU1", "AFBR-89CDDZ-JU2", - "FTLC9551REPM-J1", - "FCBN425QE1C30-J1", - "FCBN425QE1C10-J1", + "FTLC9551REPM-J1", + "FCBN425QE1C30-J1", + "FCBN425QE1C10-J1", "FTLC9551REPM-J3", - "LUX42604CO", - "LUX42604BO", - "EOLQ-161HG-10-LJ1", - "FTLC1151RDPL-J1", - "TR-FC13R-NJC", + "LUX42604CO", + "LUX42604BO", + "EOLQ-161HG-10-LJ1", + "FTLC1151RDPL-J1", + "TR-FC13R-NJC", "TR-FC13L-NJC", - "TR-FC13R-NJ3", - "SPQ-CE-LR-CDFB-J2", + "TR-FC13R-NJ3", + "SPQ-CE-LR-CDFB-J2", "1K1QAC", "SPQCELRCDFAJ2" } @@ -361,11 +368,11 @@ def set_bit(self, data, pos): def is_100g_optics(self, part_num): ret = part_num in self.optics_list_100g - return ret - + return ret + def is_40g_optics(self, part_num): ret = part_num in self.optics_list_40g - return ret + return ret def is_optics(self, part_num): if self.is_100g_optics(part_num): @@ -377,27 +384,27 @@ def is_optics(self, part_num): def process_TxCTLE(self, eeprom, port_num, part_num): if self.is_100g_optics(part_num): - logger.log_debug(" QFX5200: TxCTLE port {} and SFP PN NUM {} ".format(port_num,part_num)) - # Accessing page 3 of optics - regval = 3 - buffer = create_string_buffer(1) - buffer[0] = chr(regval) - eeprom.seek(127) - eeprom.write(buffer[0]) + logger.log_debug(" QFX5200: TxCTLE port {} and SFP PN NUM {} ".format(port_num, part_num)) + # Accessing page 3 of optics + regval = 3 + buffer = create_string_buffer(1) + buffer[0] = chr(regval) + eeprom.seek(127) + eeprom.write(buffer[0]) regval = self.port_ctle_settings[port_num] - logger.log_debug("QFX5200: TxCTLE port {}, SFP PN NUM {}, regval {} ".format(port_num,part_num,regval)) + logger.log_debug("QFX5200: TxCTLE port {}, SFP PN NUM {}, regval {} ".format(port_num, part_num, regval)) eeprom.seek(234) - buffer[0] = chr(regval) + buffer[0] = chr(regval) eeprom.write(buffer[0]) eeprom.seek(235) - eeprom.write(buffer[0]) - # Moving back the optics page to 0 - regval = 0x0 - buffer[0] = chr(regval) - eeprom.seek(127) - eeprom.write(buffer[0]) + eeprom.write(buffer[0]) + # Moving back the optics page to 0 + regval = 0x0 + buffer[0] = chr(regval) + eeprom.seek(127) + eeprom.write(buffer[0]) else: pass @@ -425,7 +432,7 @@ def qsfp_port_end(self): @property def qsfp_ports(self): - return range(0, self.PORTS_IN_BLOCK + 1) + return list(range(0, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -436,12 +443,12 @@ def __init__(self): eeprom_path = "/sys/class/i2c-adapter/i2c-{0}/{0}-0050/eeprom" for x in range(0, self.port_end + 1): self.port_to_eeprom_mapping[x] = eeprom_path.format(self.port_to_i2cbus_mapping[x]) - + logger.log_debug("QFX5200: SfpUtil __init__") if os.path.isfile(self.cmd): logger.log_debug("QFX5200: SfpUtil removing sfppresence file") os.remove(self.cmd) - + SfpUtilBase.__init__(self) def get_presence(self, port_num): @@ -464,7 +471,7 @@ def set_low_power_mode(self, port_num, lpmode): lpmode = 1 else: lpmode = 0 - + status = gpio_sfp_lpmode_set(port_num, lpmode) return status @@ -478,7 +485,7 @@ def write_to_file(self, file_name, from_list): try: fp1 = open(file_name, 'w') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False for i in from_list: @@ -488,19 +495,19 @@ def write_to_file(self, file_name, from_list): fp1.close() return True - # Reading from a file to a list + def read_from_file(self, file_name): try: fp = open(file_name, 'r') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False - to_list = fp.readlines() - to_list = [x.rstrip() for x in to_list] - fp.close() - return to_list + to_list = fp.readlines() + to_list = [x.rstrip() for x in to_list] + fp.close() + return to_list def sfp_detect(self): port = 0 @@ -522,56 +529,57 @@ def sfp_detect(self): # Read the current values from sysfs for port in range(GPIO_PORT_START, GPIO_PORT_END + 1): - sfp_present = gpio_sfp_presence_get(port) - current_sfp_values[port] = str(sfp_present) - ret_dict.update({port:current_sfp_values[port]}) - - prev_value = str(previous_sfp_values[port]) - - current_value = current_sfp_values[port] - if (prev_value != current_value): - ret_dict.update({port:current_sfp_values[port]}) - value = str(current_sfp_values[port]) - if (value): - offset = 128 - sfpi_obj = sff8436InterfaceId() - if sfpi_obj is None: - return None - - file_path = self._get_port_eeprom_path(port, self.IDENTITY_EEPROM_ADDR) - if not self._sfp_eeprom_present(file_path, 0): - print("Error, file not exist %s" % file_path) - return None - - try: - sysfsfile_eeprom = open(file_path, mode="rb", buffering=0) - except IOError: - print("Error: reading sysfs file %s" % file_path) - return None - - sfp_vendor_pn_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + XCVR_VENDOR_PN_OFFSET), XCVR_VENDOR_PN_WIDTH) - if sfp_vendor_pn_raw is not None: - sfp_vendor_pn_data = sfpi_obj.parse_vendor_pn(sfp_vendor_pn_raw, 0) - else: - return None - - try: - sysfsfile_eeprom.close() - except IOError: - print("Error: closing sysfs file %s" % file_path) - return None - - sfp_pn_num = str(sfp_vendor_pn_data['data']['Vendor PN']['value']) - if self.is_optics(sfp_pn_num): - logger.log_debug("QFX5200: Port {} is connected with Optics with Part Number {}".format(port,sfp_pn_num)) - eeprom1 = open(self._port_to_eeprom_mapping[port], "r+b") - self.process_TxCTLE(eeprom1, port, sfp_pn_num) - eeprom1.close - # End of if(value) - # End of current_sfp_values != previous_sfp_vlalues + sfp_present = gpio_sfp_presence_get(port) + current_sfp_values[port] = str(sfp_present) + ret_dict.update({port: current_sfp_values[port]}) + + prev_value = str(previous_sfp_values[port]) + + current_value = current_sfp_values[port] + if (prev_value != current_value): + ret_dict.update({port: current_sfp_values[port]}) + value = str(current_sfp_values[port]) + if (value): + offset = 128 + sfpi_obj = sff8436InterfaceId() + if sfpi_obj is None: + return None + + file_path = self._get_port_eeprom_path(port, self.IDENTITY_EEPROM_ADDR) + if not self._sfp_eeprom_present(file_path, 0): + print("Error, file not exist %s" % file_path) + return None + + try: + sysfsfile_eeprom = open(file_path, mode="rb", buffering=0) + except IOError: + print("Error: reading sysfs file %s" % file_path) + return None + + sfp_vendor_pn_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + XCVR_VENDOR_PN_OFFSET), XCVR_VENDOR_PN_WIDTH) + if sfp_vendor_pn_raw is not None: + sfp_vendor_pn_data = sfpi_obj.parse_vendor_pn(sfp_vendor_pn_raw, 0) + else: + return None + + try: + sysfsfile_eeprom.close() + except IOError: + print("Error: closing sysfs file %s" % file_path) + return None + + sfp_pn_num = str(sfp_vendor_pn_data['data']['Vendor PN']['value']) + if self.is_optics(sfp_pn_num): + logger.log_debug( + "QFX5200: Port {} is connected with Optics with Part Number {}".format(port, sfp_pn_num)) + eeprom1 = open(self._port_to_eeprom_mapping[port], "r+b") + self.process_TxCTLE(eeprom1, port, sfp_pn_num) + eeprom1.close + # End of if(value) + # End of current_sfp_values != previous_sfp_vlalues # End of for loop - if(self.write_to_file(self.cmd, current_sfp_values) == True): logger.log_debug("QFX5200: sfp_detect, current sfp values written successfully to sfppresence file") logger.log_debug("QFX5200: sfp_detect ret_dict is {}".format(ret_dict)) @@ -609,31 +617,36 @@ def get_transceiver_info_dict(self, port_num): print("Error: reading sysfs file %s" % file_path) return None - sfp_type_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + OSFP_TYPE_OFFSET), XCVR_TYPE_WIDTH) + sfp_type_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + OSFP_TYPE_OFFSET), XCVR_TYPE_WIDTH) if sfp_type_raw is not None: sfp_type_data = sfpi_obj.parse_sfp_type(sfp_type_raw, 0) else: return None - sfp_vendor_name_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + OSFP_VENDOR_NAME_OFFSET), XCVR_VENDOR_NAME_WIDTH) + sfp_vendor_name_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + OSFP_VENDOR_NAME_OFFSET), XCVR_VENDOR_NAME_WIDTH) if sfp_vendor_name_raw is not None: sfp_vendor_name_data = sfpi_obj.parse_vendor_name(sfp_vendor_name_raw, 0) else: return None - sfp_vendor_pn_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + OSFP_VENDOR_PN_OFFSET), XCVR_VENDOR_PN_WIDTH) + sfp_vendor_pn_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + OSFP_VENDOR_PN_OFFSET), XCVR_VENDOR_PN_WIDTH) if sfp_vendor_pn_raw is not None: sfp_vendor_pn_data = sfpi_obj.parse_vendor_pn(sfp_vendor_pn_raw, 0) else: return None - sfp_vendor_rev_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + OSFP_HW_REV_OFFSET), vendor_rev_width) + sfp_vendor_rev_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + OSFP_HW_REV_OFFSET), vendor_rev_width) if sfp_vendor_rev_raw is not None: sfp_vendor_rev_data = sfpi_obj.parse_vendor_rev(sfp_vendor_rev_raw, 0) else: return None - sfp_vendor_sn_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + OSFP_VENDOR_SN_OFFSET), XCVR_VENDOR_SN_WIDTH) + sfp_vendor_sn_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + OSFP_VENDOR_SN_OFFSET), XCVR_VENDOR_SN_WIDTH) if sfp_vendor_sn_raw is not None: sfp_vendor_sn_data = sfpi_obj.parse_vendor_sn(sfp_vendor_sn_raw, 0) else: @@ -697,43 +710,50 @@ def get_transceiver_info_dict(self, port_num): print("Error: reading sysfs file %s" % file_path) return None - sfp_interface_bulk_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + XCVR_INTFACE_BULK_OFFSET), interface_info_bulk_width) + sfp_interface_bulk_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + XCVR_INTFACE_BULK_OFFSET), interface_info_bulk_width) if sfp_interface_bulk_raw is not None: sfp_interface_bulk_data = sfpi_obj.parse_sfp_info_bulk(sfp_interface_bulk_raw, 0) else: return None - sfp_vendor_name_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + XCVR_VENDOR_NAME_OFFSET), XCVR_VENDOR_NAME_WIDTH) + sfp_vendor_name_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + XCVR_VENDOR_NAME_OFFSET), XCVR_VENDOR_NAME_WIDTH) if sfp_vendor_name_raw is not None: sfp_vendor_name_data = sfpi_obj.parse_vendor_name(sfp_vendor_name_raw, 0) else: return None - sfp_vendor_pn_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + XCVR_VENDOR_PN_OFFSET), XCVR_VENDOR_PN_WIDTH) + sfp_vendor_pn_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + XCVR_VENDOR_PN_OFFSET), XCVR_VENDOR_PN_WIDTH) if sfp_vendor_pn_raw is not None: sfp_vendor_pn_data = sfpi_obj.parse_vendor_pn(sfp_vendor_pn_raw, 0) else: return None - sfp_vendor_rev_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + XCVR_HW_REV_OFFSET), vendor_rev_width) + sfp_vendor_rev_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + XCVR_HW_REV_OFFSET), vendor_rev_width) if sfp_vendor_rev_raw is not None: sfp_vendor_rev_data = sfpi_obj.parse_vendor_rev(sfp_vendor_rev_raw, 0) else: return None - sfp_vendor_sn_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + XCVR_VENDOR_SN_OFFSET), XCVR_VENDOR_SN_WIDTH) + sfp_vendor_sn_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + XCVR_VENDOR_SN_OFFSET), XCVR_VENDOR_SN_WIDTH) if sfp_vendor_sn_raw is not None: sfp_vendor_sn_data = sfpi_obj.parse_vendor_sn(sfp_vendor_sn_raw, 0) else: return None - sfp_vendor_oui_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + XCVR_VENDOR_OUI_OFFSET), XCVR_VENDOR_OUI_WIDTH) + sfp_vendor_oui_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + XCVR_VENDOR_OUI_OFFSET), XCVR_VENDOR_OUI_WIDTH) if sfp_vendor_oui_raw is not None: sfp_vendor_oui_data = sfpi_obj.parse_vendor_oui(sfp_vendor_oui_raw, 0) else: return None - sfp_vendor_date_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + XCVR_VENDOR_DATE_OFFSET), XCVR_VENDOR_DATE_WIDTH) + sfp_vendor_date_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + XCVR_VENDOR_DATE_OFFSET), XCVR_VENDOR_DATE_WIDTH) if sfp_vendor_date_raw is not None: sfp_vendor_date_data = sfpi_obj.parse_vendor_date(sfp_vendor_date_raw, 0) else: @@ -752,7 +772,8 @@ def get_transceiver_info_dict(self, port_num): transceiver_info_dict['hardware_rev'] = sfp_vendor_rev_data['data']['Vendor Rev']['value'] transceiver_info_dict['serial'] = sfp_vendor_sn_data['data']['Vendor SN']['value'] transceiver_info_dict['vendor_oui'] = sfp_vendor_oui_data['data']['Vendor OUI']['value'] - transceiver_info_dict['vendor_date'] = sfp_vendor_date_data['data']['VendorDataCode(YYYY-MM-DD Lot)']['value'] + transceiver_info_dict['vendor_date'] = sfp_vendor_date_data[ + 'data']['VendorDataCode(YYYY-MM-DD Lot)']['value'] transceiver_info_dict['connector'] = sfp_interface_bulk_data['data']['Connector']['value'] transceiver_info_dict['encoding'] = sfp_interface_bulk_data['data']['EncodingCodes']['value'] transceiver_info_dict['ext_identifier'] = sfp_interface_bulk_data['data']['Extended Identifier']['value'] @@ -771,10 +792,11 @@ def get_transceiver_info_dict(self, port_num): if key in sfp_interface_bulk_data['data']['Specification compliance']['value']: compliance_code_dict[key] = sfp_interface_bulk_data['data']['Specification compliance']['value'][key]['value'] transceiver_info_dict['specification_compliance'] = str(compliance_code_dict) - - if sfp_interface_bulk_data['data'].has_key('Nominal Bit Rate(100Mbs)'): - transceiver_info_dict['nominal_bit_rate'] = str(sfp_interface_bulk_data['data']['Nominal Bit Rate(100Mbs)']['value']) - else: + + if 'Nominal Bit Rate(100Mbs)' in sfp_interface_bulk_data['data']: + transceiver_info_dict['nominal_bit_rate'] = str( + sfp_interface_bulk_data['data']['Nominal Bit Rate(100Mbs)']['value']) + else: transceiver_info_dict['nominal_bit_rate'] = 'N/A' else: for key in qfx5200_sfp_cable_length_tup: @@ -784,17 +806,18 @@ def get_transceiver_info_dict(self, port_num): else: transceiver_info_dict['cable_type'] = key transceiver_info_dict['cable_length'] = 'N/A' - + for key in qfx5200_sfp_compliance_code_tup: if key in sfp_interface_bulk_data['data']['Specification compliance']['value']: compliance_code_dict[key] = sfp_interface_bulk_data['data']['Specification compliance']['value'][key]['value'] transceiver_info_dict['specification_compliance'] = str(compliance_code_dict) - if sfp_interface_bulk_data['data'].has_key('NominalSignallingRate(UnitsOf100Mbd)'): - transceiver_info_dict['nominal_bit_rate'] = str(sfp_interface_bulk_data['data']['NominalSignallingRate(UnitsOf100Mbd)']['value']) - else: + if 'NominalSignallingRate(UnitsOf100Mbd)' in sfp_interface_bulk_data['data']: + transceiver_info_dict['nominal_bit_rate'] = str( + sfp_interface_bulk_data['data']['NominalSignallingRate(UnitsOf100Mbd)']['value']) + else: transceiver_info_dict['nominal_bit_rate'] = 'N/A' - + logger.log_debug("QFX5200: get_transceiver_info_dict End") return transceiver_info_dict @@ -844,25 +867,29 @@ def get_transceiver_dom_info_dict(self, port_num): # TODO: in the future when decided to migrate to support SFF-8636 instead of SFF-8436, # need to add more code for determining the capability and version compliance # in SFF-8636 dom capability definitions evolving with the versions. - qsfp_dom_capability_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset_xcvr + XCVR_DOM_CAPABILITY_OFFSET), XCVR_DOM_CAPABILITY_WIDTH) + qsfp_dom_capability_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset_xcvr + XCVR_DOM_CAPABILITY_OFFSET), XCVR_DOM_CAPABILITY_WIDTH) if qsfp_dom_capability_raw is not None: qspf_dom_capability_data = sfpi_obj.parse_qsfp_dom_capability(qsfp_dom_capability_raw, 0) else: return None - dom_temperature_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + QSFP_TEMPE_OFFSET), QSFP_TEMPE_WIDTH) + dom_temperature_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + QSFP_TEMPE_OFFSET), QSFP_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 + QSFP_VOLT_OFFSET), QSFP_VOLT_WIDTH) + dom_voltage_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + QSFP_VOLT_OFFSET), QSFP_VOLT_WIDTH) if dom_voltage_raw is not None: dom_voltage_data = sfpd_obj.parse_voltage(dom_voltage_raw, 0) else: return None - qsfp_dom_rev_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + QSFP_DOM_REV_OFFSET), QSFP_DOM_REV_WIDTH) + qsfp_dom_rev_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + QSFP_DOM_REV_OFFSET), QSFP_DOM_REV_WIDTH) if qsfp_dom_rev_raw is not None: qsfp_dom_rev_data = sfpd_obj.parse_sfp_dom_rev(qsfp_dom_rev_raw, 0) else: @@ -877,7 +904,8 @@ def get_transceiver_dom_info_dict(self, port_num): 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) + 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: @@ -888,9 +916,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 @@ -932,19 +962,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_VOLT_OFFSET), SFP_VOLT_WIDTH) + dom_voltage_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + SFP_VOLT_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: @@ -986,7 +1019,7 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): 'txpowerlowalarm', 'txpowerlowwarning', 'txbiashighalarm', 'txbiashighwarning', 'txbiaslowalarm', 'txbiaslowwarning' - ] + ] transceiver_dom_threshold_info_dict = dict.fromkeys(dom_info_dict_keys, 'N/A') logger.log_debug("QFX5200: get_transceiver_dom_threshold_info_dict Start") @@ -1009,18 +1042,18 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): # Revert offset back to 0 once data is retrieved offset = 384 dom_module_threshold_raw = self._read_eeprom_specific_bytes( - sysfsfile_eeprom, - (offset + QSFP_MODULE_THRESHOLD_OFFSET), - QSFP_MODULE_THRESHOLD_WIDTH) + sysfsfile_eeprom, + (offset + QSFP_MODULE_THRESHOLD_OFFSET), + QSFP_MODULE_THRESHOLD_WIDTH) if dom_module_threshold_raw is not None: dom_module_threshold_data = sfpd_obj.parse_module_threshold_values(dom_module_threshold_raw, 0) else: return transceiver_dom_threshold_info_dict dom_channel_threshold_raw = self._read_eeprom_specific_bytes( - sysfsfile_eeprom, - (offset + QSFP_CHANNL_THRESHOLD_OFFSET), - QSFP_CHANNL_THRESHOLD_WIDTH) + sysfsfile_eeprom, + (offset + QSFP_CHANNL_THRESHOLD_OFFSET), + QSFP_CHANNL_THRESHOLD_WIDTH) if dom_channel_threshold_raw is not None: dom_channel_threshold_data = sfpd_obj.parse_channel_threshold_values(dom_channel_threshold_raw, 0) else: @@ -1057,18 +1090,18 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): return None try: - sysfsfile_eeprom = io.open(file_path,"rb",0) + sysfsfile_eeprom = io.open(file_path, "rb", 0) except IOError: print("Error: reading sysfs file %s" % file_path) return None - - sfpd_obj = sff8472Dom(None,1) + + sfpd_obj = sff8472Dom(None, 1) if sfpd_obj is None: return transceiver_dom_threshold_info_dict - - dom_module_threshold_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, - (offset + SFP_MODULE_THRESHOLD_OFFSET), SFP_MODULE_THRESHOLD_WIDTH) - + + dom_module_threshold_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, + (offset + SFP_MODULE_THRESHOLD_OFFSET), SFP_MODULE_THRESHOLD_WIDTH) + if dom_module_threshold_raw is not None: dom_module_threshold_data = sfpd_obj.parse_alarm_warning_threshold(dom_module_threshold_raw, 0) else: @@ -1080,7 +1113,7 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): print("Error: closing sysfs file %s" % file_path) return None - #Threshold Data + # Threshold Data transceiver_dom_threshold_info_dict['temphighalarm'] = dom_module_threshold_data['data']['TempHighAlarm']['value'] transceiver_dom_threshold_info_dict['templowalarm'] = dom_module_threshold_data['data']['TempLowAlarm']['value'] transceiver_dom_threshold_info_dict['temphighwarning'] = dom_module_threshold_data['data']['TempHighWarning']['value'] @@ -1101,11 +1134,10 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): transceiver_dom_threshold_info_dict['rxpowerlowalarm'] = dom_module_threshold_data['data']['RXPowerLowAlarm']['value'] transceiver_dom_threshold_info_dict['rxpowerhighwarning'] = dom_module_threshold_data['data']['RXPowerHighWarning']['value'] transceiver_dom_threshold_info_dict['rxpowerlowwarning'] = dom_module_threshold_data['data']['RXPowerLowWarning']['value'] - + logger.log_debug("QFX5200: get_transceiver_dom_threshold_info_dict End") return transceiver_dom_threshold_info_dict def get_transceiver_change_event(self, timeout=2000): - time.sleep(3) + time.sleep(3) return self.sfp_detect() - diff --git a/device/juniper/x86_64-juniper_qfx5210-r0/plugins/eeprom.py b/device/juniper/x86_64-juniper_qfx5210-r0/plugins/eeprom.py index a5453dc4f0a3..4f087afc6eb0 100644 --- a/device/juniper/x86_64-juniper_qfx5210-r0/plugins/eeprom.py +++ b/device/juniper/x86_64-juniper_qfx5210-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -14,18 +11,19 @@ import syslog from struct import * from array import * - -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") SYSLOG_IDENTIFIER = "eeprom.py" EEPROM_PATH = "/sys/bus/i2c/devices/0-0056/eeprom" + def log_error(msg): syslog.openlog(SYSLOG_IDENTIFIER) syslog.syslog(syslog.LOG_ERR, msg) syslog.closelog() + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 @@ -37,4 +35,3 @@ def __init__(self, name, path, cpld_root, ro): self.eeprom_path = EEPROM_PATH super(board, self).__init__(self.eeprom_path, 0, '', True) - diff --git a/device/juniper/x86_64-juniper_qfx5210-r0/plugins/psuutil.py b/device/juniper/x86_64-juniper_qfx5210-r0/plugins/psuutil.py index 707c7c897c82..b05cf3e477ac 100644 --- a/device/juniper/x86_64-juniper_qfx5210-r0/plugins/psuutil.py +++ b/device/juniper/x86_64-juniper_qfx5210-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Accton # @@ -13,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/juniper/x86_64-juniper_qfx5210-r0/plugins/qfx5210_eeprom_data.py b/device/juniper/x86_64-juniper_qfx5210-r0/plugins/qfx5210_eeprom_data.py index 973a2abe492b..b0aef43ba273 100644 --- a/device/juniper/x86_64-juniper_qfx5210-r0/plugins/qfx5210_eeprom_data.py +++ b/device/juniper/x86_64-juniper_qfx5210-r0/plugins/qfx5210_eeprom_data.py @@ -1,15 +1,15 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # Name: juniper_qfx5210_eepromconv.py version: 1.0 # -# Description: This file contains the code to store the contents of Board EEPROM in file +# Description: This file contains the code to store the contents of Board EEPROM in file # # Copyright (c) 2020, Juniper Networks, Inc. # All rights reserved. # -# Notice and Disclaimer: This code is licensed to you under the GNU General -# Public License as published by the Free Software Foundation, version 3 or -# any later version. This code is not an official Juniper product. You can +# Notice and Disclaimer: This code is licensed to you under the GNU General +# Public License as published by the Free Software Foundation, version 3 or +# any later version. This code is not an official Juniper product. You can # obtain a copy of the License at # # OSS License: @@ -27,47 +27,47 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . # -# Third-Party Code: This code may depend on other components under separate -# copyright notice and license terms. Your use of the source code for those -# components is subject to the terms and conditions of the respective license +# Third-Party Code: This code may depend on other components under separate +# copyright notice and license terms. Your use of the source code for those +# components is subject to the terms and conditions of the respective license # as noted in the Third-Party source code file. import os -import commands import binascii from sonic_eeprom import eeprom_tlvinfo + def main(): eeprom_qfx5210 = Eeprom() - FANTYPE_PATH = '/sys/bus/i2c/devices/17-0068/fan1_direction' + FANTYPE_PATH = '/sys/bus/i2c/devices/17-0068/fan1_direction' isPlatformAFO = False try: fan_type_file = open(FANTYPE_PATH) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) fan_type = -1 else: fan_type = fan_type_file.read() fan_type_file.close() - + if (int(fan_type) == -1 or int(fan_type) == 0): - if (int(fan_type) == -1): - print "unable to open sys file for fan handling, defaulting it to AFO" - - isPlatformAFO = True + if (int(fan_type) == -1): + print("unable to open sys file for fan handling, defaulting it to AFO") + + isPlatformAFO = True else: - isPlatformAFO = False + isPlatformAFO = False # creating the "/var/run/eeprom" file and storing values of CPU board EEPROM in this file. - eeprom_file = open ("/var/run/eeprom", "a+") + eeprom_file = open("/var/run/eeprom", "a+") eeprom_file.write("\n") if isPlatformAFO == True: eeprom_file.write("Fan Type=AFO\r\n") else: eeprom_file.write("Fan Type=AFI\r\n") eeprom_file.write("\n") - + # Write the contents of CPU Board EEPROM to file eeprom_file.write("CPU Board EEPROM (0x56)\r\n") eeprom_file.write("===============================\r\n") @@ -81,12 +81,12 @@ def main(): eeprom_file.write("Vendor Name=%s\r\n" % eeprom_qfx5210.vendor_name_str()) eeprom_file.write("Manufacture Name=%s\r\n" % eeprom_qfx5210.manufacture_name_str()) - CPUeepromFileCmd = 'cat /sys/devices/pci0000:00/0000:00:1f.3/i2c-0/0-0056/eeprom > /etc/init.d/eeprom_qfx5210_ascii' + CPUeepromFileCmd = 'cat /sys/devices/pci0000:00/0000:00:1f.3/i2c-0/0-0056/eeprom > /etc/init.d/eeprom_qfx5210_ascii' # Write the contents of CPU EEPROM to file try: os.system(CPUeepromFileCmd) except OSError: - print 'Error: Execution of "%s" failed', CPUeepromFileCmd + print('Error: Execution of "%s" failed', CPUeepromFileCmd) return False eeprom_ascii = '/etc/init.d/eeprom_qfx5210_ascii' @@ -94,18 +94,18 @@ def main(): with open(eeprom_ascii, 'rb') as Hexformat: content = Hexformat.read() Hexformatoutput = binascii.hexlify(content) - + eeprom_hex = '/etc/init.d/eeprom_qfx5210_hex' with open(eeprom_hex, 'wb+') as Hexfile: Hexfile.write(Hexformatoutput) - - #Write contents of CPU EEPROM to new file in hexa format + + # Write contents of CPU EEPROM to new file in hexa format with open(eeprom_hex, 'rb') as eeprom_hexfile: eeprom_hexfile.seek(350, 0) vendorext_read = eeprom_hexfile.read(124) - vendorext="" + vendorext = "" vendorext += "0x" + vendorext_read[0:2] - for i in range(2,124,2): + for i in range(2, 124, 2): vendorext += " 0x" + vendorext_read[i:i+2] eeprom_file.write("Vendor Extension=%s\r\n" % str(vendorext)) @@ -146,10 +146,10 @@ def main(): CLEI_read = eeprom_hexfile.read(20) CLEI_name = binascii.unhexlify(CLEI_read) eeprom_file.write("CLEI code=%s\r\n" % str(CLEI_name)) - + eeprom_dict = eeprom_qfx5210.system_eeprom_info() key = '0x29' - if key in eeprom_dict.keys(): + if key in list(eeprom_dict.keys()): onie_version_str = eeprom_dict.get('0x29', None) else: onie_version_str = "N/A" @@ -159,7 +159,8 @@ def main(): eeprom_file.write("CRC=%s\r\n" % crc_str) eeprom_file.close() return True - + + class Eeprom(eeprom_tlvinfo.TlvInfoDecoder): def __init__(self): self.__eeprom_path = "/sys/class/i2c-adapter/i2c-0/0-0056/eeprom" @@ -203,14 +204,14 @@ def __init__(self): def serial_number_str(self): (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_SERIAL_NUMBER) + self.__eeprom_data, self._TLV_CODE_SERIAL_NUMBER) if not is_valid: return "N/A" return results[2] def base_mac_address(self): (is_valid, t) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_MAC_BASE) + self.__eeprom_data, self._TLV_CODE_MAC_BASE) if not is_valid or t[1] != 6: return super(eeprom_tlvinfo.TlvInfoDecoder, self).switchaddrstr(self.__eeprom_data) @@ -218,7 +219,7 @@ def base_mac_address(self): def modelstr(self): (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_PRODUCT_NAME) + self.__eeprom_data, self._TLV_CODE_PRODUCT_NAME) if not is_valid: return "N/A" @@ -226,7 +227,7 @@ def modelstr(self): def part_number_str(self): (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_PART_NUMBER) + self.__eeprom_data, self._TLV_CODE_PART_NUMBER) if not is_valid: return "N/A" @@ -234,7 +235,7 @@ def part_number_str(self): def serial_tag_str(self): (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_SERVICE_TAG) + self.__eeprom_data, self._TLV_CODE_SERVICE_TAG) if not is_valid: return "N/A" @@ -242,7 +243,7 @@ def serial_tag_str(self): def revision_str(self): (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_DEVICE_VERSION) + self.__eeprom_data, self._TLV_CODE_DEVICE_VERSION) if not is_valid: return "N/A" @@ -250,7 +251,7 @@ def revision_str(self): def manuDate_str(self): (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_MANUF_DATE) + self.__eeprom_data, self._TLV_CODE_MANUF_DATE) if not is_valid: return "N/A" @@ -258,23 +259,23 @@ def manuDate_str(self): def platform_str(self): (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_PLATFORM_NAME) + self.__eeprom_data, self._TLV_CODE_PLATFORM_NAME) if not is_valid: return "N/A" return results[2] def MACsize_str(self): - (is_valid, t) = self.get_tlv_field(self.__eeprom_data, self._TLV_CODE_MAC_SIZE) - - if not is_valid: - return "N/A" + (is_valid, t) = self.get_tlv_field(self.__eeprom_data, self._TLV_CODE_MAC_SIZE) - return str((ord(t[2][0]) << 8) | ord(t[2][1])) + if not is_valid: + return "N/A" + + return str((ord(t[2][0]) << 8) | ord(t[2][1])) def vendor_name_str(self): (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_VENDOR_NAME) + self.__eeprom_data, self._TLV_CODE_VENDOR_NAME) if not is_valid: return "N/A" @@ -282,7 +283,7 @@ def vendor_name_str(self): def manufacture_name_str(self): (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_MANUF_NAME) + self.__eeprom_data, self._TLV_CODE_MANUF_NAME) if not is_valid: return "N/A" @@ -291,31 +292,31 @@ def manufacture_name_str(self): def onie_version_str(self): value = "" (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_ONIE_VERSION) + self.__eeprom_data, self._TLV_CODE_ONIE_VERSION) if not is_valid: return "N/A" for c in results[2:2 + ord(results[1])]: value += "0x%02X " % (ord(c),) - + return value def vendor_ext_str(self): (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_VENDOR_EXT) + self.__eeprom_data, self._TLV_CODE_VENDOR_EXT) if not is_valid: return "N/A" - vendor_value_formatted = ''.join( [ " 0x" + "%02X " % ord( x ) for x in results[2] ] ).strip() - vendor_value_hexvalue = ''.join( ["%02X" % ord( x ) for x in results[2] ] ).strip() + vendor_value_formatted = ''.join([" 0x" + "%02X " % ord(x) for x in results[2]]).strip() + vendor_value_hexvalue = ''.join(["%02X" % ord(x) for x in results[2]]).strip() return vendor_value_formatted, vendor_value_hexvalue def crc_str(self): (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_CRC_32) + self.__eeprom_data, self._TLV_CODE_CRC_32) if not is_valid: return "N/A" @@ -327,5 +328,6 @@ def system_eeprom_info(self): """ return self.__eeprom_tlv_dict + if __name__ == "__main__": main() diff --git a/device/juniper/x86_64-juniper_qfx5210-r0/plugins/sfputil.py b/device/juniper/x86_64-juniper_qfx5210-r0/plugins/sfputil.py index 034a2e68bad5..a854f8fa2915 100644 --- a/device/juniper/x86_64-juniper_qfx5210-r0/plugins/sfputil.py +++ b/device/juniper/x86_64-juniper_qfx5210-r0/plugins/sfputil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - try: import time from sonic_sfp.sfputilbase import * @@ -9,31 +7,30 @@ import string from ctypes import create_string_buffer from sonic_py_common.logger import Logger -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") SYSLOG_IDENTIFIER = "sfputil" logger = Logger(SYSLOG_IDENTIFIER) qfx5210_qsfp_cable_length_tup = ('Length(km)', 'Length OM3(2m)', - 'Length OM2(m)', 'Length OM1(m)', - 'Length Cable Assembly(m)') - + 'Length OM2(m)', 'Length OM1(m)', + 'Length Cable Assembly(m)') + qfx5210_sfp_cable_length_tup = ('LengthSMFkm-UnitsOfKm', 'LengthSMF(UnitsOf100m)', - 'Length50um(UnitsOf10m)', 'Length62.5um(UnitsOfm)', - 'LengthCable(UnitsOfm)', 'LengthOM3(UnitsOf10m)') + 'Length50um(UnitsOf10m)', 'Length62.5um(UnitsOfm)', + 'LengthCable(UnitsOfm)', 'LengthOM3(UnitsOf10m)') qfx5210_sfp_compliance_code_tup = ('10GEthernetComplianceCode', 'InfinibandComplianceCode', - 'ESCONComplianceCodes', 'SONETComplianceCodes', - 'EthernetComplianceCodes','FibreChannelLinkLength', - 'FibreChannelTechnology', 'SFP+CableTechnology', - 'FibreChannelTransmissionMedia','FibreChannelSpeed') + 'ESCONComplianceCodes', 'SONETComplianceCodes', + 'EthernetComplianceCodes', 'FibreChannelLinkLength', + 'FibreChannelTechnology', 'SFP+CableTechnology', + 'FibreChannelTransmissionMedia', 'FibreChannelSpeed') qfx5210_qsfp_compliance_code_tup = ('10/40G Ethernet Compliance Code', 'SONET Compliance codes', - 'SAS/SATA compliance codes', 'Gigabit Ethernet Compliant codes', - 'Fibre Channel link length/Transmitter Technology', - 'Fibre Channel transmission media', 'Fibre Channel Speed') - + 'SAS/SATA compliance codes', 'Gigabit Ethernet Compliant codes', + 'Fibre Channel link length/Transmitter Technology', + 'Fibre Channel transmission media', 'Fibre Channel Speed') class SfpUtil(SfpUtilBase): @@ -42,77 +39,76 @@ class SfpUtil(SfpUtilBase): _port_start = 0 _port_end = 63 ports_in_block = 64 - cmd = '/var/run/sfppresence' + cmd = '/var/run/sfppresence' _port_to_eeprom_mapping = {} port_to_i2c_mapping = { - 60 : 25, - 61 : 26, - 62 : 27, - 63 : 28, - 54 : 29, - 55 : 30, - 52 : 31, - 53 : 32, - 8 : 33, - 9 : 34, - 10 : 35, - 11 : 36, - 0 : 37, - 1 : 38, - 2 : 39, - 3 : 40, - 5 : 41, - 4 : 42, - 7 : 43, - 6 : 44, - 12 : 45, - 13 : 46, - 14 : 47, - 15 : 48, - 16 : 49, - 17 : 50, - 18 : 51, - 19 : 52, - 24 : 53, - 25 : 54, - 26 : 55, - 27 : 56, - 28 : 57, - 29 : 58, - 30 : 59, - 31 : 60, - 20 : 61, - 21 : 62, - 22 : 63, - 23 : 64, - 40 : 65, - 41 : 66, - 42 : 67, - 43 : 68, - 32 : 69, - 33 : 70, - 34 : 71, - 35 : 72, - 44 : 73, - 45 : 74, - 46 : 75, - 47 : 76, - 36 : 77, - 37 : 78, - 38 : 79, - 39 : 80, - 56 : 81, - 57 : 82, - 58 : 83, - 59 : 84, - 48 : 85, - 49 : 86, - 50 : 87, - 51 : 88,} - - # sys.path.append('/usr/local/bin') - _qsfp_ports = range(0, ports_in_block + 1) - + 60: 25, + 61: 26, + 62: 27, + 63: 28, + 54: 29, + 55: 30, + 52: 31, + 53: 32, + 8: 33, + 9: 34, + 10: 35, + 11: 36, + 0: 37, + 1: 38, + 2: 39, + 3: 40, + 5: 41, + 4: 42, + 7: 43, + 6: 44, + 12: 45, + 13: 46, + 14: 47, + 15: 48, + 16: 49, + 17: 50, + 18: 51, + 19: 52, + 24: 53, + 25: 54, + 26: 55, + 27: 56, + 28: 57, + 29: 58, + 30: 59, + 31: 60, + 20: 61, + 21: 62, + 22: 63, + 23: 64, + 40: 65, + 41: 66, + 42: 67, + 43: 68, + 32: 69, + 33: 70, + 34: 71, + 35: 72, + 44: 73, + 45: 74, + 46: 75, + 47: 76, + 36: 77, + 37: 78, + 38: 79, + 39: 80, + 56: 81, + 57: 82, + 58: 83, + 59: 84, + 48: 85, + 49: 86, + 50: 87, + 51: 88, } + + # sys.path.append('/usr/local/bin') + _qsfp_ports = list(range(0, ports_in_block + 1)) def __init__(self): eeprom_path = '/sys/bus/i2c/devices/{0}-0050/eeprom' @@ -125,21 +121,21 @@ def reset(self, port_num): # Check for invalid port_num if port_num < self._port_start or port_num > self._port_end: return False - path = "/sys/bus/i2c/devices/19-0060/module_reset_{0}" + path = "/sys/bus/i2c/devices/19-0060/module_reset_{0}" port_ps = path.format(port_num+1) - + try: reg_file = open(port_ps, 'w') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False - #HW will clear reset after set. + # HW will clear reset after set. reg_file.seek(0) reg_file.write('1') reg_file.close() return True - + def get_presence(self, port_num): # Check for invalid port_num if port_num < self._port_start or port_num > self._port_end: @@ -151,7 +147,7 @@ def get_presence(self, port_num): try: reg_file = open(port_ps) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_file.readline().rstrip() @@ -167,21 +163,21 @@ def port_start(self): @property def port_end(self): return self._port_end - + @property def qsfp_ports(self): - return range(0, self.ports_in_block + 1) + return list(range(0, self.ports_in_block + 1)) - @property + @property def port_to_eeprom_mapping(self): - return self._port_to_eeprom_mapping + return self._port_to_eeprom_mapping # Writing to a file from a list def write_to_file(self, file_name, from_list): try: fp1 = open(file_name, 'w') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False for i in from_list: @@ -191,20 +187,20 @@ def write_to_file(self, file_name, from_list): fp1.close() return True - # Reading from a file to a list + def read_from_file(self, file_name): try: fp = open(file_name, 'r') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False - to_list = fp.readlines() - to_list = [x.rstrip() for x in to_list] - fp.close() - return to_list - + to_list = fp.readlines() + to_list = [x.rstrip() for x in to_list] + fp.close() + return to_list + def sfp_detect(self): x = 0 ret_dict = {} @@ -222,20 +218,20 @@ def sfp_detect(self): else: previous_sfp_values = self.read_from_file(self.cmd) - # Read the current values from sysfs - for x in range(self._port_start , self._port_end + 1): + # Read the current values from sysfs + for x in range(self._port_start, self._port_end + 1): try: new_path = path.format(x + 1) reg_file = open(new_path, 'r') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False, defl_dict - sfp_present = reg_file.readline().rstrip() + sfp_present = reg_file.readline().rstrip() reg_file.close() current_sfp_values[x] = sfp_present - if (current_sfp_values[x] != previous_sfp_values[x]): - ret_dict.update({x:current_sfp_values[x]}) + if (current_sfp_values[x] != previous_sfp_values[x]): + ret_dict.update({x: current_sfp_values[x]}) if(self.write_to_file(self.cmd, current_sfp_values) == True): return True, ret_dict @@ -262,20 +258,21 @@ def get_low_power_mode(self, port_num): lpmode = ord(eeprom.read(1)) if ((lpmode & 0x3) == 0x3): - return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 + return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 else: - return False # High Power Mode if one of the following conditions is matched: - # 1. "Power override" bit is 0 - # 2. "Power override" bit is 1 and "Power set" bit is 0 + # High Power Mode if one of the following conditions is matched: + # 1. "Power override" bit is 0 + # 2. "Power override" bit is 1 and "Power set" bit is 0 + return False except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False finally: if eeprom is not None: eeprom.close() time.sleep(0.01) - def set_low_power_mode(self, port_num, 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 @@ -284,10 +281,10 @@ def set_low_power_mode(self, port_num, lpmode): eeprom = None if not self.get_presence(port_num): - return False # Port is not present, unable to set the eeprom + return False # Port is not present, unable to set the eeprom # Fill in write buffer - regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode + regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode buffer = create_string_buffer(1) buffer[0] = chr(regval) @@ -297,7 +294,7 @@ def set_low_power_mode(self, port_num, lpmode): eeprom.write(buffer[0]) return True except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False finally: if eeprom is not None: @@ -332,31 +329,36 @@ def get_transceiver_info_dict(self, port_num): print("Error: reading sysfs file %s" % file_path) return None - sfp_type_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + OSFP_TYPE_OFFSET), XCVR_TYPE_WIDTH) + sfp_type_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + OSFP_TYPE_OFFSET), XCVR_TYPE_WIDTH) if sfp_type_raw is not None: sfp_type_data = sfpi_obj.parse_sfp_type(sfp_type_raw, 0) else: return None - sfp_vendor_name_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + OSFP_VENDOR_NAME_OFFSET), XCVR_VENDOR_NAME_WIDTH) + sfp_vendor_name_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + OSFP_VENDOR_NAME_OFFSET), XCVR_VENDOR_NAME_WIDTH) if sfp_vendor_name_raw is not None: sfp_vendor_name_data = sfpi_obj.parse_vendor_name(sfp_vendor_name_raw, 0) else: return None - sfp_vendor_pn_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + OSFP_VENDOR_PN_OFFSET), XCVR_VENDOR_PN_WIDTH) + sfp_vendor_pn_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + OSFP_VENDOR_PN_OFFSET), XCVR_VENDOR_PN_WIDTH) if sfp_vendor_pn_raw is not None: sfp_vendor_pn_data = sfpi_obj.parse_vendor_pn(sfp_vendor_pn_raw, 0) else: return None - sfp_vendor_rev_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + OSFP_HW_REV_OFFSET), vendor_rev_width) + sfp_vendor_rev_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + OSFP_HW_REV_OFFSET), vendor_rev_width) if sfp_vendor_rev_raw is not None: sfp_vendor_rev_data = sfpi_obj.parse_vendor_rev(sfp_vendor_rev_raw, 0) else: return None - sfp_vendor_sn_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + OSFP_VENDOR_SN_OFFSET), XCVR_VENDOR_SN_WIDTH) + sfp_vendor_sn_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + OSFP_VENDOR_SN_OFFSET), XCVR_VENDOR_SN_WIDTH) if sfp_vendor_sn_raw is not None: sfp_vendor_sn_data = sfpi_obj.parse_vendor_sn(sfp_vendor_sn_raw, 0) else: @@ -422,43 +424,50 @@ def get_transceiver_info_dict(self, port_num): print("Error: reading sysfs file %s" % file_path) return None - sfp_interface_bulk_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + XCVR_INTFACE_BULK_OFFSET), interface_info_bulk_width) + sfp_interface_bulk_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + XCVR_INTFACE_BULK_OFFSET), interface_info_bulk_width) if sfp_interface_bulk_raw is not None: sfp_interface_bulk_data = sfpi_obj.parse_sfp_info_bulk(sfp_interface_bulk_raw, 0) else: return None - sfp_vendor_name_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + XCVR_VENDOR_NAME_OFFSET), XCVR_VENDOR_NAME_WIDTH) + sfp_vendor_name_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + XCVR_VENDOR_NAME_OFFSET), XCVR_VENDOR_NAME_WIDTH) if sfp_vendor_name_raw is not None: sfp_vendor_name_data = sfpi_obj.parse_vendor_name(sfp_vendor_name_raw, 0) else: return None - sfp_vendor_pn_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + XCVR_VENDOR_PN_OFFSET), XCVR_VENDOR_PN_WIDTH) + sfp_vendor_pn_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + XCVR_VENDOR_PN_OFFSET), XCVR_VENDOR_PN_WIDTH) if sfp_vendor_pn_raw is not None: sfp_vendor_pn_data = sfpi_obj.parse_vendor_pn(sfp_vendor_pn_raw, 0) else: return None - sfp_vendor_rev_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + XCVR_HW_REV_OFFSET), vendor_rev_width) + sfp_vendor_rev_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + XCVR_HW_REV_OFFSET), vendor_rev_width) if sfp_vendor_rev_raw is not None: sfp_vendor_rev_data = sfpi_obj.parse_vendor_rev(sfp_vendor_rev_raw, 0) else: return None - sfp_vendor_sn_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + XCVR_VENDOR_SN_OFFSET), XCVR_VENDOR_SN_WIDTH) + sfp_vendor_sn_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + XCVR_VENDOR_SN_OFFSET), XCVR_VENDOR_SN_WIDTH) if sfp_vendor_sn_raw is not None: sfp_vendor_sn_data = sfpi_obj.parse_vendor_sn(sfp_vendor_sn_raw, 0) else: return None - sfp_vendor_oui_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + XCVR_VENDOR_OUI_OFFSET), XCVR_VENDOR_OUI_WIDTH) + sfp_vendor_oui_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + XCVR_VENDOR_OUI_OFFSET), XCVR_VENDOR_OUI_WIDTH) if sfp_vendor_oui_raw is not None: sfp_vendor_oui_data = sfpi_obj.parse_vendor_oui(sfp_vendor_oui_raw, 0) else: return None - sfp_vendor_date_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + XCVR_VENDOR_DATE_OFFSET), XCVR_VENDOR_DATE_WIDTH) + sfp_vendor_date_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + XCVR_VENDOR_DATE_OFFSET), XCVR_VENDOR_DATE_WIDTH) if sfp_vendor_date_raw is not None: sfp_vendor_date_data = sfpi_obj.parse_vendor_date(sfp_vendor_date_raw, 0) else: @@ -477,7 +486,8 @@ def get_transceiver_info_dict(self, port_num): transceiver_info_dict['hardware_rev'] = sfp_vendor_rev_data['data']['Vendor Rev']['value'] transceiver_info_dict['serial'] = sfp_vendor_sn_data['data']['Vendor SN']['value'] transceiver_info_dict['vendor_oui'] = sfp_vendor_oui_data['data']['Vendor OUI']['value'] - transceiver_info_dict['vendor_date'] = sfp_vendor_date_data['data']['VendorDataCode(YYYY-MM-DD Lot)']['value'] + transceiver_info_dict['vendor_date'] = sfp_vendor_date_data[ + 'data']['VendorDataCode(YYYY-MM-DD Lot)']['value'] transceiver_info_dict['connector'] = sfp_interface_bulk_data['data']['Connector']['value'] transceiver_info_dict['encoding'] = sfp_interface_bulk_data['data']['EncodingCodes']['value'] transceiver_info_dict['ext_identifier'] = sfp_interface_bulk_data['data']['Extended Identifier']['value'] @@ -496,10 +506,11 @@ def get_transceiver_info_dict(self, port_num): if key in sfp_interface_bulk_data['data']['Specification compliance']['value']: compliance_code_dict[key] = sfp_interface_bulk_data['data']['Specification compliance']['value'][key]['value'] transceiver_info_dict['specification_compliance'] = str(compliance_code_dict) - - if sfp_interface_bulk_data['data'].has_key('Nominal Bit Rate(100Mbs)'): - transceiver_info_dict['nominal_bit_rate'] = str(sfp_interface_bulk_data['data']['Nominal Bit Rate(100Mbs)']['value']) - else: + + if 'Nominal Bit Rate(100Mbs)' in sfp_interface_bulk_data['data']: + transceiver_info_dict['nominal_bit_rate'] = str( + sfp_interface_bulk_data['data']['Nominal Bit Rate(100Mbs)']['value']) + else: transceiver_info_dict['nominal_bit_rate'] = 'N/A' else: for key in qfx5210_sfp_cable_length_tup: @@ -509,18 +520,19 @@ def get_transceiver_info_dict(self, port_num): else: transceiver_info_dict['cable_type'] = key transceiver_info_dict['cable_length'] = 'N/A' - + for key in qfx5210_sfp_compliance_code_tup: if key in sfp_interface_bulk_data['data']['Specification compliance']['value']: compliance_code_dict[key] = sfp_interface_bulk_data['data']['Specification compliance']['value'][key]['value'] transceiver_info_dict['specification_compliance'] = str(compliance_code_dict) - if sfp_interface_bulk_data['data'].has_key('NominalSignallingRate(UnitsOf100Mbd)'): - transceiver_info_dict['nominal_bit_rate'] = str(sfp_interface_bulk_data['data']['NominalSignallingRate(UnitsOf100Mbd)']['value']) - else: + if 'NominalSignallingRate(UnitsOf100Mbd)' in sfp_interface_bulk_data['data']: + transceiver_info_dict['nominal_bit_rate'] = str( + sfp_interface_bulk_data['data']['NominalSignallingRate(UnitsOf100Mbd)']['value']) + else: transceiver_info_dict['nominal_bit_rate'] = 'N/A' #transceiver_info_dict['nominal_bit_rate'] = str(sfp_interface_bulk_data['data']['NominalSignallingRate(UnitsOf100Mbd)']['value']) - + return transceiver_info_dict def get_transceiver_dom_info_dict(self, port_num): @@ -568,25 +580,29 @@ def get_transceiver_dom_info_dict(self, port_num): # TODO: in the future when decided to migrate to support SFF-8636 instead of SFF-8436, # need to add more code for determining the capability and version compliance # in SFF-8636 dom capability definitions evolving with the versions. - qsfp_dom_capability_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset_xcvr + XCVR_DOM_CAPABILITY_OFFSET), XCVR_DOM_CAPABILITY_WIDTH) + qsfp_dom_capability_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset_xcvr + XCVR_DOM_CAPABILITY_OFFSET), XCVR_DOM_CAPABILITY_WIDTH) if qsfp_dom_capability_raw is not None: qspf_dom_capability_data = sfpi_obj.parse_qsfp_dom_capability(qsfp_dom_capability_raw, 0) else: return None - dom_temperature_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + QSFP_TEMPE_OFFSET), QSFP_TEMPE_WIDTH) + dom_temperature_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + QSFP_TEMPE_OFFSET), QSFP_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 + QSFP_VOLT_OFFSET), QSFP_VOLT_WIDTH) + dom_voltage_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + QSFP_VOLT_OFFSET), QSFP_VOLT_WIDTH) if dom_voltage_raw is not None: dom_voltage_data = sfpd_obj.parse_voltage(dom_voltage_raw, 0) else: return None - qsfp_dom_rev_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + QSFP_DOM_REV_OFFSET), QSFP_DOM_REV_WIDTH) + qsfp_dom_rev_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + QSFP_DOM_REV_OFFSET), QSFP_DOM_REV_WIDTH) if qsfp_dom_rev_raw is not None: qsfp_dom_rev_data = sfpd_obj.parse_sfp_dom_rev(qsfp_dom_rev_raw, 0) else: @@ -601,7 +617,8 @@ def get_transceiver_dom_info_dict(self, port_num): 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) + 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: @@ -612,9 +629,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 @@ -656,19 +675,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_VOLT_OFFSET), SFP_VOLT_WIDTH) + dom_voltage_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + SFP_VOLT_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: @@ -696,7 +718,7 @@ def get_transceiver_dom_info_dict(self, port_num): transceiver_dom_info_dict['tx4power'] = 'N/A' return transceiver_dom_info_dict - + def get_transceiver_dom_threshold_info_dict(self, port_num): transceiver_dom_threshold_info_dict = {} dom_info_dict_keys = ['temphighalarm', 'temphighwarning', @@ -709,7 +731,7 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): 'txpowerlowalarm', 'txpowerlowwarning', 'txbiashighalarm', 'txbiashighwarning', 'txbiaslowalarm', 'txbiaslowwarning' - ] + ] transceiver_dom_threshold_info_dict = dict.fromkeys(dom_info_dict_keys, 'N/A') logger.log_debug("QFX5210: get_transceiver_dom_threshold_info_dict Start") @@ -732,18 +754,18 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): # Revert offset back to 0 once data is retrieved offset = 384 dom_module_threshold_raw = self._read_eeprom_specific_bytes( - sysfsfile_eeprom, - (offset + QSFP_MODULE_THRESHOLD_OFFSET), - QSFP_MODULE_THRESHOLD_WIDTH) + sysfsfile_eeprom, + (offset + QSFP_MODULE_THRESHOLD_OFFSET), + QSFP_MODULE_THRESHOLD_WIDTH) if dom_module_threshold_raw is not None: dom_module_threshold_data = sfpd_obj.parse_module_threshold_values(dom_module_threshold_raw, 0) else: return transceiver_dom_threshold_info_dict dom_channel_threshold_raw = self._read_eeprom_specific_bytes( - sysfsfile_eeprom, - (offset + QSFP_CHANNL_THRESHOLD_OFFSET), - QSFP_CHANNL_THRESHOLD_WIDTH) + sysfsfile_eeprom, + (offset + QSFP_CHANNL_THRESHOLD_OFFSET), + QSFP_CHANNL_THRESHOLD_WIDTH) if dom_channel_threshold_raw is not None: dom_channel_threshold_data = sfpd_obj.parse_channel_threshold_values(dom_channel_threshold_raw, 0) else: @@ -780,18 +802,18 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): return None try: - sysfsfile_eeprom = io.open(file_path,"rb",0) + sysfsfile_eeprom = io.open(file_path, "rb", 0) except IOError: print("Error: reading sysfs file %s" % file_path) return None - - sfpd_obj = sff8472Dom(None,1) + + sfpd_obj = sff8472Dom(None, 1) if sfpd_obj is None: return transceiver_dom_threshold_info_dict - - dom_module_threshold_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, - (offset + SFP_MODULE_THRESHOLD_OFFSET), SFP_MODULE_THRESHOLD_WIDTH) - + + dom_module_threshold_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, + (offset + SFP_MODULE_THRESHOLD_OFFSET), SFP_MODULE_THRESHOLD_WIDTH) + if dom_module_threshold_raw is not None: dom_module_threshold_data = sfpd_obj.parse_alarm_warning_threshold(dom_module_threshold_raw, 0) else: @@ -803,7 +825,7 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): print("Error: closing sysfs file %s" % file_path) return None - #Threshold Data + # Threshold Data transceiver_dom_threshold_info_dict['temphighalarm'] = dom_module_threshold_data['data']['TempHighAlarm']['value'] transceiver_dom_threshold_info_dict['templowalarm'] = dom_module_threshold_data['data']['TempLowAlarm']['value'] transceiver_dom_threshold_info_dict['temphighwarning'] = dom_module_threshold_data['data']['TempHighWarning']['value'] @@ -824,6 +846,6 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): transceiver_dom_threshold_info_dict['rxpowerlowalarm'] = dom_module_threshold_data['data']['RXPowerLowAlarm']['value'] transceiver_dom_threshold_info_dict['rxpowerhighwarning'] = dom_module_threshold_data['data']['RXPowerHighWarning']['value'] transceiver_dom_threshold_info_dict['rxpowerlowwarning'] = dom_module_threshold_data['data']['RXPowerLowWarning']['value'] - + logger.log_debug("QFX5210: get_transceiver_dom_threshold_info_dict End") return transceiver_dom_threshold_info_dict diff --git a/device/marvell/arm64-marvell_db98cx8580_16cd-r0/plugins/eeprom.py b/device/marvell/arm64-marvell_db98cx8580_16cd-r0/plugins/eeprom.py index ea525f5d74b1..71f05c5b70f5 100644 --- a/device/marvell/arm64-marvell_db98cx8580_16cd-r0/plugins/eeprom.py +++ b/device/marvell/arm64-marvell_db98cx8580_16cd-r0/plugins/eeprom.py @@ -1,9 +1,7 @@ -#!/usr/bin/env python - try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/marvell/arm64-marvell_db98cx8580_16cd-r0/plugins/sfputil.py b/device/marvell/arm64-marvell_db98cx8580_16cd-r0/plugins/sfputil.py index da13b129a9a3..4463e687e695 100644 --- a/device/marvell/arm64-marvell_db98cx8580_16cd-r0/plugins/sfputil.py +++ b/device/marvell/arm64-marvell_db98cx8580_16cd-r0/plugins/sfputil.py @@ -1,27 +1,25 @@ -#!/usr/bin/env python - try: import os import time import sys import re - import subprocess from sonic_sfp.sfputilbase import SfpUtilBase -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") if sys.version_info[0] < 3: - import commands as cmd + import commands else: - import subprocess as cmd + import subprocess as commands smbus_present = 1 try: import smbus -except ImportError, e: +except ImportError as e: smbus_present = 0 + class SfpUtil(SfpUtilBase): """Platform specific sfputil class""" _port_start = 1 @@ -30,17 +28,17 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} - _qsfp_ports = range(_port_start, ports_in_block + 1) + _qsfp_ports = list(range(_port_start, ports_in_block + 1)) def __init__(self): os.system("modprobe i2c-dev") - if not os.path.exists("/sys/bus/i2c/devices/0-0050") : + if not os.path.exists("/sys/bus/i2c/devices/0-0050"): os.system("echo optoe2 0x50 > /sys/bus/i2c/devices/i2c-0/new_device") eeprom_path = '/sys/bus/i2c/devices/0-0050/eeprom' - #for x in range(self.port _start, self.port_end +1): + # for x in range(self.port _start, self.port_end +1): x = self.port_start - while(x self._port_end: @@ -104,11 +102,11 @@ def get_presence(self, port_num): self.i2c_set(0x74, 0, 0) reg = (port_num)/8 offset = reg % 8 - if offset >=4: - offset=offset-4 - elif offset<4: - offset=offset+4 - bin_offset = 1<= 4: + offset = offset-4 + elif offset < 4: + offset = offset+4 + bin_offset = 1 << offset if port_num >= 0 and port_num <= 63: device_reg = 0x70 @@ -122,8 +120,8 @@ def get_presence(self, port_num): path = "/sys/bus/i2c/devices/0-0050/eeprom" try: reg_file = open(path) - reg_file.seek(01) - reg_file.read(02) + reg_file.seek(0o1) + reg_file.read(0o2) except IOError as e: return False @@ -171,13 +169,12 @@ def read_porttab_mappings(self, porttabfile): bcm_port = str(port_pos_in_file) - if "index" in title: fp_port_index = int(line.split()[title.index("index")]) # Leave the old code for backward compatibility - #if len(line.split()) >= 4: + # if len(line.split()) >= 4: # fp_port_index = (line.split()[3]) - # print(fp_port_index) + # print(fp_port_index) else: fp_port_index = portname.split("Ethernet").pop() fp_port_index = int(fp_port_index.split("s").pop(0))+1 @@ -226,9 +223,8 @@ def read_porttab_mappings(self, porttabfile): self.logical_to_physical = logical_to_physical self.physical_to_logical = physical_to_logical - - #print(self.logical_to_physical) - '''print("logical: " + self.logical) + # print(self.logical_to_physical) + '''print("logical: " + self.logical) print("logical to bcm: " + self.logical_to_bcm) print("logical to physical: " + self.logical_to_physical) print("physical to logical: " + self.physical_to_logical)''' @@ -241,15 +237,15 @@ def port_start(self): @property def port_end(self): return self._port_end - + @property def qsfp_ports(self): return self._qsfp_ports - @property + @property def port_to_eeprom_mapping(self): - return self._port_to_eeprom_mapping - + return self._port_to_eeprom_mapping + @property def get_transceiver_change_event(self): - raise NotImplementedError + raise NotImplementedError diff --git a/device/marvell/arm64-marvell_db98cx8580_32cd-r0/plugins/eeprom.py b/device/marvell/arm64-marvell_db98cx8580_32cd-r0/plugins/eeprom.py index ea525f5d74b1..71f05c5b70f5 100644 --- a/device/marvell/arm64-marvell_db98cx8580_32cd-r0/plugins/eeprom.py +++ b/device/marvell/arm64-marvell_db98cx8580_32cd-r0/plugins/eeprom.py @@ -1,9 +1,7 @@ -#!/usr/bin/env python - try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/marvell/arm64-marvell_db98cx8580_32cd-r0/plugins/sfputil.py b/device/marvell/arm64-marvell_db98cx8580_32cd-r0/plugins/sfputil.py index 80b11bf0630e..b3d1ea371454 100644 --- a/device/marvell/arm64-marvell_db98cx8580_32cd-r0/plugins/sfputil.py +++ b/device/marvell/arm64-marvell_db98cx8580_32cd-r0/plugins/sfputil.py @@ -1,27 +1,25 @@ -#!/usr/bin/env python - try: import os import time import sys import re - import subprocess from sonic_sfp.sfputilbase import SfpUtilBase -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") if sys.version_info[0] < 3: - import commands as cmd + import commands else: - import subprocess as cmd + import subprocess as commands smbus_present = 1 try: import smbus -except ImportError, e: +except ImportError as e: smbus_present = 0 + class SfpUtil(SfpUtilBase): """Platform specific sfputil class""" _port_start = 1 @@ -30,17 +28,17 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} - _qsfp_ports = range(_port_start, ports_in_block + 1) + _qsfp_ports = list(range(_port_start, ports_in_block + 1)) def __init__(self): os.system("modprobe i2c-dev") - if not os.path.exists("/sys/bus/i2c/devices/0-0050") : + if not os.path.exists("/sys/bus/i2c/devices/0-0050"): os.system("echo optoe2 0x50 > /sys/bus/i2c/devices/i2c-0/new_device") eeprom_path = '/sys/bus/i2c/devices/0-0050/eeprom' - #for x in range(self.port _start, self.port_end +1): + # for x in range(self.port _start, self.port_end +1): x = self.port_start - while(x self._port_end: @@ -106,11 +104,11 @@ def get_presence(self, port_num): self.i2c_set(0x74, 0, 0) reg = (port_num)/8 offset = reg % 8 - if offset >=4: - offset=offset-4 - elif offset<4: - offset=offset+4 - bin_offset = 1<= 4: + offset = offset-4 + elif offset < 4: + offset = offset+4 + bin_offset = 1 << offset if port_num >= 0 and port_num <= 63: device_reg = 0x70 @@ -128,8 +126,8 @@ def get_presence(self, port_num): path = "/sys/bus/i2c/devices/0-0050/eeprom" try: reg_file = open(path) - reg_file.seek(01) - reg_file.read(02) + reg_file.seek(0o1) + reg_file.read(0o2) except IOError as e: return False @@ -177,13 +175,12 @@ def read_porttab_mappings(self, porttabfile): bcm_port = str(port_pos_in_file) - if "index" in title: fp_port_index = int(line.split()[title.index("index")]) # Leave the old code for backward compatibility - #if len(line.split()) >= 4: + # if len(line.split()) >= 4: # fp_port_index = (line.split()[3]) - # print(fp_port_index) + # print(fp_port_index) else: fp_port_index = portname.split("Ethernet").pop() fp_port_index = int(fp_port_index.split("s").pop(0))+1 @@ -232,9 +229,8 @@ def read_porttab_mappings(self, porttabfile): self.logical_to_physical = logical_to_physical self.physical_to_logical = physical_to_logical - - #print(self.logical_to_physical) - '''print("logical: " + self.logical) + # print(self.logical_to_physical) + '''print("logical: " + self.logical) print("logical to bcm: " + self.logical_to_bcm) print("logical to physical: " + self.logical_to_physical) print("physical to logical: " + self.physical_to_logical)''' @@ -247,15 +243,15 @@ def port_start(self): @property def port_end(self): return self._port_end - + @property def qsfp_ports(self): return self._qsfp_ports - @property + @property def port_to_eeprom_mapping(self): - return self._port_to_eeprom_mapping - + return self._port_to_eeprom_mapping + @property def get_transceiver_change_event(self): - raise NotImplementedError + raise NotImplementedError diff --git a/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/eeprom.py b/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/eeprom.py index ea525f5d74b1..71f05c5b70f5 100644 --- a/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/eeprom.py +++ b/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/eeprom.py @@ -1,9 +1,7 @@ -#!/usr/bin/env python - try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/psuutil.py b/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/psuutil.py index 16965414e64b..ab6aeff2b20b 100755 --- a/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/psuutil.py +++ b/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/psuutil.py @@ -1,29 +1,28 @@ -#!/usr/bin/env python - import sys import os.path if sys.version_info[0] < 3: - import commands as cmd + import commands else: - import subprocess as cmd + import subprocess as commands smbus_present = 1 try: - import smbus + import smbus except ImportError as e: - smbus_present = 0 + smbus_present = 0 try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" def __init__(self): - PsuBase.__init__(self) - MAX_PSUS = 2 + PsuBase.__init__(self) + MAX_PSUS = 2 def get_num_psus(self): MAX_PSUS = 2 @@ -31,46 +30,47 @@ def get_num_psus(self): def get_psu_status(self, index): if index is None: - return False - if smbus_present == 0: - cmdstatus, psustatus = cmd.getstatusoutput('i2cget -y 0 0x41 0xa') #need to verify the cpld register logic - psustatus = int(psustatus, 16) - else : - bus = smbus.SMBus(0) - DEVICE_ADDRESS = 0x41 - DEVICE_REG = 0xa - psustatus = bus.read_byte_data(DEVICE_ADDRESS, DEVICE_REG) + return False + if smbus_present == 0: + cmdstatus, psustatus = commands.getstatusoutput( + 'i2cget -y 0 0x41 0xa') # need to verify the cpld register logic + psustatus = int(psustatus, 16) + else: + bus = smbus.SMBus(0) + DEVICE_ADDRESS = 0x41 + DEVICE_REG = 0xa + psustatus = bus.read_byte_data(DEVICE_ADDRESS, DEVICE_REG) if index == 1: - psustatus = psustatus&4 - if psustatus == 4 : - return True + psustatus = psustatus & 4 + if psustatus == 4: + return True if index == 2: - psustatus = psustatus&8 - if psustatus == 8 : - return True - + psustatus = psustatus & 8 + if psustatus == 8: + return True + return False def get_psu_presence(self, index): if index is None: return False - if smbus_present == 0: - cmdstatus, psustatus = cmd.getstatusoutput('i2cget -y 0 0x41 0xa') #need to verify the cpld register logic - psustatus = int(psustatus, 16) - else : - bus = smbus.SMBus(0) - DEVICE_ADDRESS = 0x41 - DEVICE_REG = 0xa - psustatus = bus.read_byte_data(DEVICE_ADDRESS, DEVICE_REG) + if smbus_present == 0: + cmdstatus, psustatus = commands.getstatusoutput( + 'i2cget -y 0 0x41 0xa') # need to verify the cpld register logic + psustatus = int(psustatus, 16) + else: + bus = smbus.SMBus(0) + DEVICE_ADDRESS = 0x41 + DEVICE_REG = 0xa + psustatus = bus.read_byte_data(DEVICE_ADDRESS, DEVICE_REG) if index == 1: - psustatus = psustatus&1 - if psustatus == 1 : - return True + psustatus = psustatus & 1 + if psustatus == 1: + return True if index == 2: - psustatus = psustatus&2 - if psustatus == 2 : + psustatus = psustatus & 2 + if psustatus == 2: return True return False - diff --git a/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/sfputil.py b/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/sfputil.py index 431d2bc615aa..39d5db4ce7f4 100755 --- a/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/sfputil.py +++ b/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/sfputil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - try: import os import time @@ -7,21 +5,22 @@ import sys import glob from sonic_sfp.sfputilbase import SfpUtilBase -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") if sys.version_info[0] < 3: - import commands as cmd + import commands else: - import subprocess as cmd + import subprocess as commands smbus_present = 1 try: import smbus -except ImportError, e: +except ImportError as e: smbus_present = 0 + class SfpUtil(SfpUtilBase): """Platform specific sfputil class""" @@ -31,24 +30,25 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} port_to_i2c_mapping = { - 49 : 2, - 50 : 3, - 51 : 4, - 52 : 5 + 49: 2, + 50: 3, + 51: 4, + 52: 5 } - _qsfp_ports = range(_port_start, ports_in_block + 1) - _changed_ports = [0,0,0,0] + _qsfp_ports = list(range(_port_start, ports_in_block + 1)) + _changed_ports = [0, 0, 0, 0] + def __init__(self): # Enable optical SFP Tx - if smbus_present == 0 : + if smbus_present == 0: os.system("i2cset -y -m 0x0f 0 0x41 0x5 0x00") - else : + else: bus = smbus.SMBus(0) DEVICE_ADDRESS = 0x41 DEVICEREG = 0x5 - OPTIC_E = bus.read_byte_data(DEVICE_ADDRESS, DEVICEREG) + OPTIC_E = bus.read_byte_data(DEVICE_ADDRESS, DEVICEREG) OPTIC_E = OPTIC_E & 0xf0 bus.write_byte_data(DEVICE_ADDRESS, DEVICEREG, OPTIC_E) @@ -83,10 +83,10 @@ def reset(self, port_num): try: reg_file = open(port_ps, 'w') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False - #toggle reset + # toggle reset reg_file.seek(0) reg_file.write('1') time.sleep(1) @@ -110,23 +110,24 @@ def get_presence(self, port_num): p = sel[0] q = sel[1] - pos = [1,2,4,8] + pos = [1, 2, 4, 8] bit_pos = pos[prt] if smbus_present == 0: - cmdstatus, sfpstatus = cmd.getstatusoutput('i2cget -y 0 0x41 0x3') #need to verify the cpld register logic - sfpstatus = int(sfpstatus, 16) - else : - bus = smbus.SMBus(0) - DEVICE_ADDRESS = 0x41 - DEVICE_REG = 0x3 - sfpstatus = bus.read_byte_data(DEVICE_ADDRESS, DEVICE_REG) - sfpstatus = sfpstatus&(bit_pos) + cmdstatus, sfpstatus = commands.getstatusoutput( + 'i2cget -y 0 0x41 0x3') # need to verify the cpld register logic + sfpstatus = int(sfpstatus, 16) + else: + bus = smbus.SMBus(0) + DEVICE_ADDRESS = 0x41 + DEVICE_REG = 0x3 + sfpstatus = bus.read_byte_data(DEVICE_ADDRESS, DEVICE_REG) + sfpstatus = sfpstatus & (bit_pos) if sfpstatus == 0: #print("Port " + str(port_num) + "present") return True return False - + def read_porttab_mappings(self, porttabfile): logical = [] logical_to_physical = {} @@ -170,7 +171,7 @@ def read_porttab_mappings(self, porttabfile): else: fp_port_index = portname.split("Ethernet").pop() fp_port_index = int(fp_port_index.split("s").pop(0))+1 - #print(fp_port_index) + # print(fp_port_index) else: # Parsing logic for older 'portmap.ini' file fp_port_index = portname.split("Ethernet").pop() fp_port_index = int(fp_port_index.split("s").pop(0))+1 @@ -211,8 +212,7 @@ def read_porttab_mappings(self, porttabfile): self.logical = logical self.logical_to_physical = logical_to_physical self.physical_to_logical = physical_to_logical - #print(self.logical_to_physical) - + # print(self.logical_to_physical) @property def port_start(self): @@ -228,43 +228,40 @@ def qsfp_ports(self): @property def port_to_eeprom_mapping(self): - return self._port_to_eeprom_mapping + return self._port_to_eeprom_mapping def get_transceiver_change_event(self, timeout): port_dict = {} port = 0 if timeout == 0: - cd_ms = sys.maxint + cd_ms = sys.maxsize else: cd_ms = timeout changed_port = 0 - #poll per second + # poll per second while cd_ms > 0: - for port_num in range(49,53): - prt = port_num % 49 - sfpstatus = self.get_presence(port_num) - if sfpstatus : - port_dict[str(port_num)]= '1' - if self._changed_ports[prt] == 0: - changed_port = 1 - self._changed_ports[prt] = 1 - else : - port_dict[str(port_num)] = '0' - if self._changed_ports[prt] == 1: - changed_port = 1 - self._changed_ports[prt] = 0 - - if changed_port != 0: - break - time.sleep(1) - cd_ms = cd_ms - 1000 + for port_num in range(49, 53): + prt = port_num % 49 + sfpstatus = self.get_presence(port_num) + if sfpstatus: + port_dict[str(port_num)] = '1' + if self._changed_ports[prt] == 0: + changed_port = 1 + self._changed_ports[prt] = 1 + else: + port_dict[str(port_num)] = '0' + if self._changed_ports[prt] == 1: + changed_port = 1 + self._changed_ports[prt] = 0 + + if changed_port != 0: + break + time.sleep(1) + cd_ms = cd_ms - 1000 if changed_port: return True, port_dict else: return True, {} return False, {} - - - diff --git a/device/marvell/x86_64-marvell_db98cx8580_16cd-r0/plugins/eeprom.py b/device/marvell/x86_64-marvell_db98cx8580_16cd-r0/plugins/eeprom.py index ea525f5d74b1..71f05c5b70f5 100644 --- a/device/marvell/x86_64-marvell_db98cx8580_16cd-r0/plugins/eeprom.py +++ b/device/marvell/x86_64-marvell_db98cx8580_16cd-r0/plugins/eeprom.py @@ -1,9 +1,7 @@ -#!/usr/bin/env python - try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/marvell/x86_64-marvell_db98cx8580_16cd-r0/plugins/sfputil.py b/device/marvell/x86_64-marvell_db98cx8580_16cd-r0/plugins/sfputil.py index da13b129a9a3..4463e687e695 100644 --- a/device/marvell/x86_64-marvell_db98cx8580_16cd-r0/plugins/sfputil.py +++ b/device/marvell/x86_64-marvell_db98cx8580_16cd-r0/plugins/sfputil.py @@ -1,27 +1,25 @@ -#!/usr/bin/env python - try: import os import time import sys import re - import subprocess from sonic_sfp.sfputilbase import SfpUtilBase -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") if sys.version_info[0] < 3: - import commands as cmd + import commands else: - import subprocess as cmd + import subprocess as commands smbus_present = 1 try: import smbus -except ImportError, e: +except ImportError as e: smbus_present = 0 + class SfpUtil(SfpUtilBase): """Platform specific sfputil class""" _port_start = 1 @@ -30,17 +28,17 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} - _qsfp_ports = range(_port_start, ports_in_block + 1) + _qsfp_ports = list(range(_port_start, ports_in_block + 1)) def __init__(self): os.system("modprobe i2c-dev") - if not os.path.exists("/sys/bus/i2c/devices/0-0050") : + if not os.path.exists("/sys/bus/i2c/devices/0-0050"): os.system("echo optoe2 0x50 > /sys/bus/i2c/devices/i2c-0/new_device") eeprom_path = '/sys/bus/i2c/devices/0-0050/eeprom' - #for x in range(self.port _start, self.port_end +1): + # for x in range(self.port _start, self.port_end +1): x = self.port_start - while(x self._port_end: @@ -104,11 +102,11 @@ def get_presence(self, port_num): self.i2c_set(0x74, 0, 0) reg = (port_num)/8 offset = reg % 8 - if offset >=4: - offset=offset-4 - elif offset<4: - offset=offset+4 - bin_offset = 1<= 4: + offset = offset-4 + elif offset < 4: + offset = offset+4 + bin_offset = 1 << offset if port_num >= 0 and port_num <= 63: device_reg = 0x70 @@ -122,8 +120,8 @@ def get_presence(self, port_num): path = "/sys/bus/i2c/devices/0-0050/eeprom" try: reg_file = open(path) - reg_file.seek(01) - reg_file.read(02) + reg_file.seek(0o1) + reg_file.read(0o2) except IOError as e: return False @@ -171,13 +169,12 @@ def read_porttab_mappings(self, porttabfile): bcm_port = str(port_pos_in_file) - if "index" in title: fp_port_index = int(line.split()[title.index("index")]) # Leave the old code for backward compatibility - #if len(line.split()) >= 4: + # if len(line.split()) >= 4: # fp_port_index = (line.split()[3]) - # print(fp_port_index) + # print(fp_port_index) else: fp_port_index = portname.split("Ethernet").pop() fp_port_index = int(fp_port_index.split("s").pop(0))+1 @@ -226,9 +223,8 @@ def read_porttab_mappings(self, porttabfile): self.logical_to_physical = logical_to_physical self.physical_to_logical = physical_to_logical - - #print(self.logical_to_physical) - '''print("logical: " + self.logical) + # print(self.logical_to_physical) + '''print("logical: " + self.logical) print("logical to bcm: " + self.logical_to_bcm) print("logical to physical: " + self.logical_to_physical) print("physical to logical: " + self.physical_to_logical)''' @@ -241,15 +237,15 @@ def port_start(self): @property def port_end(self): return self._port_end - + @property def qsfp_ports(self): return self._qsfp_ports - @property + @property def port_to_eeprom_mapping(self): - return self._port_to_eeprom_mapping - + return self._port_to_eeprom_mapping + @property def get_transceiver_change_event(self): - raise NotImplementedError + raise NotImplementedError diff --git a/device/marvell/x86_64-marvell_db98cx8580_32cd-r0/plugins/eeprom.py b/device/marvell/x86_64-marvell_db98cx8580_32cd-r0/plugins/eeprom.py index ea525f5d74b1..71f05c5b70f5 100644 --- a/device/marvell/x86_64-marvell_db98cx8580_32cd-r0/plugins/eeprom.py +++ b/device/marvell/x86_64-marvell_db98cx8580_32cd-r0/plugins/eeprom.py @@ -1,9 +1,7 @@ -#!/usr/bin/env python - try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/marvell/x86_64-marvell_db98cx8580_32cd-r0/plugins/sfputil.py b/device/marvell/x86_64-marvell_db98cx8580_32cd-r0/plugins/sfputil.py index 80b11bf0630e..b3d1ea371454 100644 --- a/device/marvell/x86_64-marvell_db98cx8580_32cd-r0/plugins/sfputil.py +++ b/device/marvell/x86_64-marvell_db98cx8580_32cd-r0/plugins/sfputil.py @@ -1,27 +1,25 @@ -#!/usr/bin/env python - try: import os import time import sys import re - import subprocess from sonic_sfp.sfputilbase import SfpUtilBase -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") if sys.version_info[0] < 3: - import commands as cmd + import commands else: - import subprocess as cmd + import subprocess as commands smbus_present = 1 try: import smbus -except ImportError, e: +except ImportError as e: smbus_present = 0 + class SfpUtil(SfpUtilBase): """Platform specific sfputil class""" _port_start = 1 @@ -30,17 +28,17 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} - _qsfp_ports = range(_port_start, ports_in_block + 1) + _qsfp_ports = list(range(_port_start, ports_in_block + 1)) def __init__(self): os.system("modprobe i2c-dev") - if not os.path.exists("/sys/bus/i2c/devices/0-0050") : + if not os.path.exists("/sys/bus/i2c/devices/0-0050"): os.system("echo optoe2 0x50 > /sys/bus/i2c/devices/i2c-0/new_device") eeprom_path = '/sys/bus/i2c/devices/0-0050/eeprom' - #for x in range(self.port _start, self.port_end +1): + # for x in range(self.port _start, self.port_end +1): x = self.port_start - while(x self._port_end: @@ -106,11 +104,11 @@ def get_presence(self, port_num): self.i2c_set(0x74, 0, 0) reg = (port_num)/8 offset = reg % 8 - if offset >=4: - offset=offset-4 - elif offset<4: - offset=offset+4 - bin_offset = 1<= 4: + offset = offset-4 + elif offset < 4: + offset = offset+4 + bin_offset = 1 << offset if port_num >= 0 and port_num <= 63: device_reg = 0x70 @@ -128,8 +126,8 @@ def get_presence(self, port_num): path = "/sys/bus/i2c/devices/0-0050/eeprom" try: reg_file = open(path) - reg_file.seek(01) - reg_file.read(02) + reg_file.seek(0o1) + reg_file.read(0o2) except IOError as e: return False @@ -177,13 +175,12 @@ def read_porttab_mappings(self, porttabfile): bcm_port = str(port_pos_in_file) - if "index" in title: fp_port_index = int(line.split()[title.index("index")]) # Leave the old code for backward compatibility - #if len(line.split()) >= 4: + # if len(line.split()) >= 4: # fp_port_index = (line.split()[3]) - # print(fp_port_index) + # print(fp_port_index) else: fp_port_index = portname.split("Ethernet").pop() fp_port_index = int(fp_port_index.split("s").pop(0))+1 @@ -232,9 +229,8 @@ def read_porttab_mappings(self, porttabfile): self.logical_to_physical = logical_to_physical self.physical_to_logical = physical_to_logical - - #print(self.logical_to_physical) - '''print("logical: " + self.logical) + # print(self.logical_to_physical) + '''print("logical: " + self.logical) print("logical to bcm: " + self.logical_to_bcm) print("logical to physical: " + self.logical_to_physical) print("physical to logical: " + self.physical_to_logical)''' @@ -247,15 +243,15 @@ def port_start(self): @property def port_end(self): return self._port_end - + @property def qsfp_ports(self): return self._qsfp_ports - @property + @property def port_to_eeprom_mapping(self): - return self._port_to_eeprom_mapping - + return self._port_to_eeprom_mapping + @property def get_transceiver_change_event(self): - raise NotImplementedError + raise NotImplementedError diff --git a/device/marvell/x86_64-marvell_slm5401_54x-r0/plugins/eeprom.py b/device/marvell/x86_64-marvell_slm5401_54x-r0/plugins/eeprom.py index 7681caafeef4..951384d5e37d 100755 --- a/device/marvell/x86_64-marvell_slm5401_54x-r0/plugins/eeprom.py +++ b/device/marvell/x86_64-marvell_slm5401_54x-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,14 +8,16 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom" - #Two i2c buses might get flipped order, check them both. + # Two i2c buses might get flipped order, check them both. if not os.path.exists(self.eeprom_path): self.eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/marvell/x86_64-marvell_slm5401_54x-r0/plugins/sfputil.py b/device/marvell/x86_64-marvell_slm5401_54x-r0/plugins/sfputil.py index fa706867a585..b1d356e393ee 100755 --- a/device/marvell/x86_64-marvell_slm5401_54x-r0/plugins/sfputil.py +++ b/device/marvell/x86_64-marvell_slm5401_54x-r0/plugins/sfputil.py @@ -1,10 +1,8 @@ -#!/usr/bin/env python - try: import time from sonic_sfp.sfputilbase import SfpUtilBase -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") class sfputil(SfpUtilBase): @@ -16,41 +14,41 @@ class sfputil(SfpUtilBase): port_to_eeprom_mapping = {} port_to_i2c_mapping = { - 9 : 18, - 10 : 19, - 11 : 20, - 12 : 21, - 1 : 22, - 2 : 23, - 3 : 24, - 4 : 25, - 6 : 26, - 5 : 27, - 8 : 28, - 7 : 29, - 13 : 30, - 14 : 31, - 15 : 32, - 16 : 33, - 17 : 34, - 18 : 35, - 19 : 36, - 20 : 37, - 25 : 38, - 26 : 39, - 27 : 40, - 28 : 41, - 29 : 42, - 30 : 43, - 31 : 44, - 32 : 45, - 21 : 46, - 22 : 47, - 23 : 48, - 24 : 49, + 9: 18, + 10: 19, + 11: 20, + 12: 21, + 1: 22, + 2: 23, + 3: 24, + 4: 25, + 6: 26, + 5: 27, + 8: 28, + 7: 29, + 13: 30, + 14: 31, + 15: 32, + 16: 33, + 17: 34, + 18: 35, + 19: 36, + 20: 37, + 25: 38, + 26: 39, + 27: 40, + 28: 41, + 29: 42, + 30: 43, + 31: 44, + 32: 45, + 21: 46, + 22: 47, + 23: 48, + 24: 49, } - _qsfp_ports = range(0, ports_in_block + 1) + _qsfp_ports = list(range(0, ports_in_block + 1)) def __init__(self): # Override port_to_eeprom_mapping for class initialization @@ -67,14 +65,14 @@ def reset(self, port_num): path = "/sys/bus/i2c/devices/{0}-0050/sfp_port_reset" port_ps = path.format(self.port_to_i2c_mapping[port_num+1]) - + try: reg_file = open(port_ps, 'w') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False - #toggle reset + # toggle reset reg_file.seek(0) reg_file.write('1') time.sleep(1) @@ -88,7 +86,7 @@ def set_low_power_mode(self, port_nuM, lpmode): def get_low_power_mode(self, port_num): raise NotImplementedErro - + def get_presence(self, port_num): # Check for invalid port_num if port_num < self._port_start or port_num > self._port_end: @@ -97,11 +95,10 @@ def get_presence(self, port_num): path = "/sys/bus/i2c/devices/{0}-0050/sfp_is_present" port_ps = path.format(self.port_to_i2c_mapping[port_num+1]) - try: reg_file = open(port_ps) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_file.readline().rstrip() @@ -117,14 +114,14 @@ def port_start(self): @property def port_end(self): return self._port_end - + @property def qsfp_ports(self): - return range(0, self.ports_in_block + 1) + return list(range(0, self.ports_in_block + 1)) - @property + @property def port_to_eeprom_mapping(self): - return self._port_to_eeprom_mapping + return self._port_to_eeprom_mapping def get_transceiver_change_event(self): """ diff --git a/device/mellanox/x86_64-mlnx_msn2010-r0/plugins/psuutil.py b/device/mellanox/x86_64-mlnx_msn2010-r0/plugins/psuutil.py index a51a9b07292c..0d864849dc48 100644 --- a/device/mellanox/x86_64-mlnx_msn2010-r0/plugins/psuutil.py +++ b/device/mellanox/x86_64-mlnx_msn2010-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Mellanox # @@ -13,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/mellanox/x86_64-mlnx_msn2100-r0/plugins/psuutil.py b/device/mellanox/x86_64-mlnx_msn2100-r0/plugins/psuutil.py index b14b1d9dac4d..2b4f87397bc4 100644 --- a/device/mellanox/x86_64-mlnx_msn2100-r0/plugins/psuutil.py +++ b/device/mellanox/x86_64-mlnx_msn2100-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Mellanox # @@ -13,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/eeprom.py b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/eeprom.py index fbfe0d99ae71..0f20ffff3b53 100644 --- a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/eeprom.py +++ b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Mellanox # @@ -10,7 +8,6 @@ ############################################################################# try: - import exceptions import binascii import time import optparse @@ -18,18 +15,24 @@ import os import sys import syslog - from cStringIO import StringIO + + if sys.version_info.major == 3: + from io import StringIO + else: + from cStringIO import StringIO + from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo from sonic_py_common.device_info import get_machine_info import subprocess -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") SYSLOG_IDENTIFIER = "eeprom.py" EEPROM_SYMLINK = "/var/run/hw-management/eeprom/vpd_info" CACHE_FILE = "/var/cache/sonic/decode-syseeprom/syseeprom_cache" + def log_error(msg): syslog.openlog(SYSLOG_IDENTIFIER) syslog.syslog(syslog.LOG_ERR, msg) @@ -43,6 +46,7 @@ def log_error(msg): subprocess.check_call(['/usr/bin/xxd', '-r', '-p', 'syseeprom.hex', 'syseeprom.bin'], cwd=platform_path) CACHE_FILE = os.path.join(platform_path, 'syseeprom.bin') + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 @@ -53,7 +57,7 @@ def __init__(self, name, path, cpld_root, ro): if not os.path.islink(EEPROM_SYMLINK): time.sleep(1) else: - break + break if not (os.path.exists(EEPROM_SYMLINK) or os.path.isfile(CACHE_FILE)): log_error("Nowhere to read syseeprom from! No symlink or cache file found") @@ -69,4 +73,3 @@ def decode_eeprom(self, e): decode_output = sys.stdout.getvalue() sys.stdout = original_stdout print(decode_output.replace('\0', '')) - diff --git a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/fanutil.py b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/fanutil.py index 429bf44750a2..ee6446e7c053 100644 --- a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/fanutil.py +++ b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/fanutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Mellanox # @@ -16,20 +14,23 @@ from glob import glob from sonic_fan.fan_base import FanBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + def log_err(msg): syslog.openlog("fanutil") syslog.syslog(syslog.LOG_ERR, msg) syslog.closelog() + class FanUtil(FanBase): """Platform-specific FanUtil class""" PWM_MAX = 255 MAX_FAN_PER_DRAWER = 2 GET_HWSKU_CMD = "sonic-cfggen -d -v DEVICE_METADATA.localhost.hwsku" - sku_without_fan_direction = ['ACS-MSN2010', 'ACS-MSN2100', 'ACS-MSN2410', 'ACS-MSN2700', 'Mellanox-SN2700', 'Mellanox-SN2700-D48C8', 'LS-SN2700', 'ACS-MSN2740'] + sku_without_fan_direction = ['ACS-MSN2010', 'ACS-MSN2100', 'ACS-MSN2410', + 'ACS-MSN2700', 'Mellanox-SN2700', 'Mellanox-SN2700-D48C8', 'LS-SN2700', 'ACS-MSN2740'] sku_with_unpluggable_fan = ['ACS-MSN2010', 'ACS-MSN2100'] def __init__(self): @@ -50,12 +51,12 @@ def __init__(self): self.fan_direction = None else: self.fan_direction = "system/fan_dir" - + self.fan_led_green = "led/led_fan*_green" self.num_of_fan, self.num_of_drawer = self._extract_num_of_fans_and_fan_drawers() def _get_sku_name(self): - p = subprocess.Popen(self.GET_HWSKU_CMD, shell=True, stdout=subprocess.PIPE) + p = subprocess.Popen(self.GET_HWSKU_CMD, shell=True, universal_newlines=True, stdout=subprocess.PIPE) out, err = p.communicate() return out.rstrip('\n') @@ -74,7 +75,7 @@ def _extract_num_of_fans_and_fan_drawers(self): def _convert_fan_index_to_drawer_index(self, index): return (index + self.MAX_FAN_PER_DRAWER - 1) / self.MAX_FAN_PER_DRAWER - def _read_file(self, file_pattern, index = 0): + def _read_file(self, file_pattern, index=0): """ Reads the file of the fan @@ -124,7 +125,8 @@ def get_presence(self, index): :return: Boolean, True if FAN is plugged, False if not """ if index > self.num_of_fan: - raise RuntimeError("index ({}) shouldn't be greater than number of fans ({})".format(index, self.num_of_fan)) + raise RuntimeError( + "index ({}) shouldn't be greater than number of fans ({})".format(index, self.num_of_fan)) if self.unpluggable_fan: return True @@ -156,7 +158,8 @@ def get_direction(self, index): return self.FAN_DIRECTION_NOT_APPLICABLE if index > self.num_of_fan: - raise RuntimeError("index ({}) shouldn't be greater than number of fans ({})".format(index, self.num_of_fan)) + raise RuntimeError( + "index ({}) shouldn't be greater than number of fans ({})".format(index, self.num_of_fan)) drawer_index = self._convert_fan_index_to_drawer_index(index) diff --git a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/psuutil.py b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/psuutil.py index cd01a1905a06..6da5770c294f 100644 --- a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/psuutil.py +++ b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Mellanox # @@ -14,7 +12,8 @@ import subprocess from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + def log_err(msg): syslog.openlog("psuutil") @@ -30,7 +29,8 @@ class PsuUtil(PsuBase): GET_HWSKU_CMD = "sonic-cfggen -d -v DEVICE_METADATA.localhost.hwsku" # for spectrum1 switches with plugable PSUs, the output voltage file is psuX_volt # for spectrum2 switches the output voltage file is psuX_volt_out2 - sku_spectrum1_with_plugable_psu = ['ACS-MSN2410', 'ACS-MSN2700', 'Mellanox-SN2700', 'Mellanox-SN2700-D48C8', 'LS-SN2700', 'ACS-MSN2740'] + sku_spectrum1_with_plugable_psu = ['ACS-MSN2410', 'ACS-MSN2700', + 'Mellanox-SN2700', 'Mellanox-SN2700-D48C8', 'LS-SN2700', 'ACS-MSN2740'] def __init__(self): PsuBase.__init__(self) @@ -49,7 +49,7 @@ def __init__(self): self.fan_speed = "thermal/psu{}_fan1_speed_get" def _get_sku_name(self): - p = subprocess.Popen(self.GET_HWSKU_CMD, shell=True, stdout=subprocess.PIPE) + p = subprocess.Popen(self.GET_HWSKU_CMD, shell=True, universal_newlines=True, stdout=subprocess.PIPE) out, err = p.communicate() return out.rstrip('\n') diff --git a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfplpmget.py b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfplpmget.py index 2f19edfa1a52..ca16c3573d06 100644 --- a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfplpmget.py +++ b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfplpmget.py @@ -1,4 +1,5 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 + """ This utility get the power mode of a given module. """ @@ -7,6 +8,7 @@ import errno from python_sdk_api.sx_api import * + def mgmt_phy_mod_pwr_attr_get(handle, module_id, power_attr_type): sx_mgmt_phy_mod_pwr_attr_p = new_sx_mgmt_phy_mod_pwr_attr_t_p() sx_mgmt_phy_mod_pwr_attr = sx_mgmt_phy_mod_pwr_attr_t() @@ -21,6 +23,7 @@ def mgmt_phy_mod_pwr_attr_get(handle, module_id, power_attr_type): finally: delete_sx_mgmt_phy_mod_pwr_attr_t_p(sx_mgmt_phy_mod_pwr_attr_p) + # Check if SFP port number is provided if len(sys.argv) < 2: print("SFP module number is missed.") @@ -46,6 +49,6 @@ def mgmt_phy_mod_pwr_attr_get(handle, module_id, power_attr_type): else: print("LPM UNKNOWN") -print "LPM ON" if lpm_status else "LPM OFF" +print("LPM ON" if lpm_status else "LPM OFF") sx_api_close(handle) diff --git a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfplpmset.py b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfplpmset.py index 132d34257558..61423880ac71 100644 --- a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfplpmset.py +++ b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfplpmset.py @@ -1,4 +1,5 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 + """ This utility set the power mode of a given module. """ @@ -19,12 +20,15 @@ NVE_MASK = PORT_TYPE_MASK & (PORT_TYPE_NVE << PORT_TYPE_OFFSET) CPU_MASK = PORT_TYPE_MASK & (PORT_TYPE_CPU << PORT_TYPE_OFFSET) + def is_nve(port): return (port & NVE_MASK) != 0 + def is_cpu(port): return (port & CPU_MASK) != 0 + def is_port_admin_status_up(log_port): oper_state_p = new_sx_port_oper_state_t_p() admin_state_p = new_sx_port_admin_state_t_p() @@ -38,11 +42,14 @@ def is_port_admin_status_up(log_port): else: return False + def set_port_admin_status_by_log_port(handle, log_port, admin_status): rc = sx_api_port_state_set(handle, log_port, admin_status) assert rc == SX_STATUS_SUCCESS, "sx_api_port_state_set failed, rc = %d" % rc # Get all the ports related to the sfp, if port admin status is up, put it to list + + def get_log_ports(handle, sfp_module): port_attributes_list = new_sx_port_attributes_t_arr(SX_PORT_ATTR_ARR_SIZE) port_cnt_p = new_uint32_t_p() @@ -63,6 +70,7 @@ def get_log_ports(handle, sfp_module): return log_port_list + def mgmt_phy_mod_pwr_attr_set(handle, module_id, power_attr_type, admin_pwr_mode): sx_mgmt_phy_mod_pwr_attr = sx_mgmt_phy_mod_pwr_attr_t() sx_mgmt_phy_mod_pwr_mode_attr = sx_mgmt_phy_mod_pwr_mode_attr_t() @@ -77,6 +85,7 @@ def mgmt_phy_mod_pwr_attr_set(handle, module_id, power_attr_type, admin_pwr_mode finally: delete_sx_mgmt_phy_mod_pwr_attr_t_p(sx_mgmt_phy_mod_pwr_attr_p) + def mgmt_phy_mod_pwr_attr_get(handle, module_id, power_attr_type): sx_mgmt_phy_mod_pwr_attr_p = new_sx_mgmt_phy_mod_pwr_attr_t_p() sx_mgmt_phy_mod_pwr_attr = sx_mgmt_phy_mod_pwr_attr_t() @@ -109,20 +118,24 @@ def pwr_attr_set(handle, module_id, ports, attr_type, power_mode): for port in ports: set_port_admin_status_by_log_port(handle, port, SX_PORT_ADMIN_STATUS_UP) + def set_lpmode(handle, cmd, module_id): # Construct the port module map. log_port_list = get_log_ports(handle, module_id) if cmd == "enable": - pwr_attr_set(handle, module_id, log_port_list, SX_MGMT_PHY_MOD_PWR_ATTR_PWR_MODE_E, SX_MGMT_PHY_MOD_PWR_MODE_LOW_E) + pwr_attr_set(handle, module_id, log_port_list, + SX_MGMT_PHY_MOD_PWR_ATTR_PWR_MODE_E, SX_MGMT_PHY_MOD_PWR_MODE_LOW_E) print("Enabled low power mode for module [%d]" % module_id) elif cmd == "disable": - pwr_attr_set(handle, module_id, log_port_list, SX_MGMT_PHY_MOD_PWR_ATTR_PWR_MODE_E, SX_MGMT_PHY_MOD_PWR_MODE_AUTO_E) + pwr_attr_set(handle, module_id, log_port_list, + SX_MGMT_PHY_MOD_PWR_ATTR_PWR_MODE_E, SX_MGMT_PHY_MOD_PWR_MODE_AUTO_E) print("Disabled low power mode for module [%d]" % module_id) else: print("Error: Invalid command") sys.exit(0) + if len(sys.argv) < 3: print("SFP module number or LPM is missed.") print("Usage: sfplpmset.py ") @@ -143,7 +156,7 @@ def set_lpmode(handle, cmd, module_id): # Get SFP module sfp_module = int(sys.argv[1]) - 1 -print "[+] opening sdk" +print("[+] opening sdk") rc, handle = sx_api_open(None) if (rc != SX_STATUS_SUCCESS): diff --git a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfpreset.py b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfpreset.py index 2e6de2e8bc8c..af237b705e9f 100644 --- a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfpreset.py +++ b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfpreset.py @@ -1,28 +1,29 @@ -#!/usr/bin/env python -""" -This utility reset the given SFP module. -""" - -import sys -import errno -from python_sdk_api.sx_api import * - -# Check if SFP port number is provided -if len(sys.argv) < 2: - print("SFP module number or LPM is missed.") - print("Usage: sfpreset.py ") - sys.exit(errno.EINVAL) - -# Init SDK API -rc, handle = sx_api_open(None) -if rc != SX_STATUS_SUCCESS: - print("Failed to open api handle.\nPlease check that SDK is running.") - sys.exit(errno.EACCES) - -# Get SFP module number -sfp_module = int(sys.argv[1]) - 1 - -rc = sx_mgmt_phy_mod_reset(handle, sfp_module) -assert rc == SX_STATUS_SUCCESS, "sx_mgmt_phy_mod_reset failed, rc = %d" % rc - -sx_api_close(handle) +#!/usr/bin/env python3 + +""" +This utility reset the given SFP module. +""" + +import sys +import errno +from python_sdk_api.sx_api import * + +# Check if SFP port number is provided +if len(sys.argv) < 2: + print("SFP module number or LPM is missed.") + print("Usage: sfpreset.py ") + sys.exit(errno.EINVAL) + +# Init SDK API +rc, handle = sx_api_open(None) +if rc != SX_STATUS_SUCCESS: + print("Failed to open api handle.\nPlease check that SDK is running.") + sys.exit(errno.EACCES) + +# Get SFP module number +sfp_module = int(sys.argv[1]) - 1 + +rc = sx_mgmt_phy_mod_reset(handle, sfp_module) +assert rc == SX_STATUS_SUCCESS, "sx_mgmt_phy_mod_reset failed, rc = %d" % rc + +sx_api_close(handle) diff --git a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfputil.py b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfputil.py index 09ba9f22e51e..954ed23d8eac 100644 --- a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfputil.py +++ b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfputil.py @@ -21,7 +21,7 @@ # I2C page size for sfp SFP_I2C_PAGE_SIZE = 256 -# parameters for DB connection +# parameters for DB connection REDIS_TIMEOUT_USECS = 0 # parameters for SFP presence @@ -41,19 +41,24 @@ # magic code defnition for port number, qsfp port position of each platform # port_position_tuple = (PORT_START, QSFP_PORT_START, PORT_END, PORT_IN_BLOCK, EEPROM_OFFSET) -platform_dict = {'x86_64-mlnx_msn2700-r0': 0, 'x86_64-mlnx_msn2740-r0': 0, 'x86_64-mlnx_msn2100-r0': 1, 'x86_64-mlnx_msn2410-r0': 2, 'x86_64-mlnx_msn2010-r0': 3, 'x86_64-mlnx_msn3420-r0':5, 'x86_64-mlnx_msn3700-r0': 0, 'x86_64-mlnx_msn3700c-r0': 0, 'x86_64-mlnx_msn3800-r0': 4, 'x86_64-mlnx_msn4600c':4, 'x86_64-mlnx_msn4700-r0': 0} -port_position_tuple_list = [(0, 0, 31, 32, 1), (0, 0, 15, 16, 1), (0, 48, 55, 56, 1), (0, 18, 21, 22, 1), (0, 0, 63, 64, 1), (0, 48, 59, 60, 1)] +platform_dict = {'x86_64-mlnx_msn2700-r0': 0, 'x86_64-mlnx_msn2740-r0': 0, 'x86_64-mlnx_msn2100-r0': 1, 'x86_64-mlnx_msn2410-r0': 2, 'x86_64-mlnx_msn2010-r0': 3, + 'x86_64-mlnx_msn3420-r0': 5, 'x86_64-mlnx_msn3700-r0': 0, 'x86_64-mlnx_msn3700c-r0': 0, 'x86_64-mlnx_msn3800-r0': 4, 'x86_64-mlnx_msn4600c': 4, 'x86_64-mlnx_msn4700-r0': 0} +port_position_tuple_list = [(0, 0, 31, 32, 1), (0, 0, 15, 16, 1), (0, 48, 55, 56, 1), + (0, 18, 21, 22, 1), (0, 0, 63, 64, 1), (0, 48, 59, 60, 1)] + def log_info(msg, also_print_to_console=False): syslog.openlog("sfputil") syslog.syslog(syslog.LOG_INFO, msg) syslog.closelog() + def log_err(msg, also_print_to_console=False): syslog.openlog("sfputil") syslog.syslog(syslog.LOG_ERR, msg) syslog.closelog() + class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" PORT_START = 0 @@ -79,15 +84,15 @@ def port_end(self): @property def qsfp_ports(self): - return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): - print "dependency on sysfs has been removed" - raise Exception() + print("dependency on sysfs has been removed") + raise Exception() def get_port_position_tuple_by_platform_name(self): - p = subprocess.Popen(GET_PLATFORM_CMD, shell=True, stdout=subprocess.PIPE) + p = subprocess.Popen(GET_PLATFORM_CMD, shell=True, universal_newlines=True, stdout=subprocess.PIPE) out, err = p.communicate() position_tuple = port_position_tuple_list[platform_dict[out.rstrip('\n')]] return position_tuple @@ -115,14 +120,14 @@ def get_presence(self, port_num): ethtool_cmd = "ethtool -m {} 2>/dev/null".format(sfpname) try: - proc = subprocess.Popen(ethtool_cmd, stdout=subprocess.PIPE, shell=True, stderr=subprocess.STDOUT) + proc = subprocess.Popen(ethtool_cmd, stdout=subprocess.PIPE, shell=True, universal_newlines=True, stderr=subprocess.STDOUT) stdout = proc.communicate()[0] proc.wait() result = stdout.rstrip('\n') if result != '': presence = True - except OSError, e: + except OSError as e: return presence return presence @@ -135,11 +140,11 @@ def get_low_power_mode(self, port_num): lpm_cmd = "docker exec syncd python /usr/share/sonic/platform/plugins/sfplpmget.py {}".format(port_num) try: - output = subprocess.check_output(lpm_cmd, shell=True) + output = subprocess.check_output(lpm_cmd, shell=True, universal_newlines=True) if 'LPM ON' in output: return True except subprocess.CalledProcessError as e: - print "Error! Unable to get LPM for {}, rc = {}, err msg: {}".format(port_num, e.returncode, e.output) + print("Error! Unable to get LPM for {}, rc = {}, err msg: {}".format(port_num, e.returncode, e.output)) return False return False @@ -159,9 +164,9 @@ def set_low_power_mode(self, port_num, lpmode): # Set LPM try: - subprocess.check_output(lpm_cmd, shell=True) + subprocess.check_output(lpm_cmd, shell=True, universal_newlines=True) except subprocess.CalledProcessError as e: - print "Error! Unable to set LPM for {}, rc = {}, err msg: {}".format(port_num, e.returncode, e.output) + print("Error! Unable to set LPM for {}, rc = {}, err msg: {}".format(port_num, e.returncode, e.output)) return False return True @@ -174,10 +179,10 @@ def reset(self, port_num): lpm_cmd = "docker exec syncd python /usr/share/sonic/platform/plugins/sfpreset.py {}".format(port_num) try: - subprocess.check_output(lpm_cmd, shell=True) + subprocess.check_output(lpm_cmd, shell=True, universal_newlines=True) return True except subprocess.CalledProcessError as e: - print "Error! Unable to set LPM for {}, rc = {}, err msg: {}".format(port_num, e.returncode, e.output) + print("Error! Unable to set LPM for {}, rc = {}, err msg: {}".format(port_num, e.returncode, e.output)) return False return False @@ -247,7 +252,7 @@ def _read_eeprom_specific_bytes_via_ethtool(self, port_num, offset, num_bytes): eeprom_raw = [] ethtool_cmd = "ethtool -m {} hex on offset {} length {}".format(sfpname, offset, num_bytes) try: - output = subprocess.check_output(ethtool_cmd, shell=True) + output = subprocess.check_output(ethtool_cmd, shell=True, universal_newlines=True) output_lines = output.splitlines() first_line_raw = output_lines[0] if "Offset" in first_line_raw: @@ -260,13 +265,13 @@ def _read_eeprom_specific_bytes_via_ethtool(self, port_num, offset, num_bytes): return eeprom_raw # Read eeprom - def _read_eeprom_devid(self, port_num, devid, offset, num_bytes = 512): + def _read_eeprom_devid(self, port_num, devid, offset, num_bytes=512): if port_num in self.osfp_ports: pass elif port_num in self.qsfp_ports: pass elif (self.DOM_EEPROM_ADDR == devid): - offset += 256 + offset += 256 eeprom_raw = self._read_eeprom_specific_bytes_via_ethtool(port_num, offset, num_bytes) @@ -289,31 +294,36 @@ def get_transceiver_info_dict(self, port_num): print("Error: sfp_object open failed") return None - sfp_type_raw = self._read_eeprom_specific_bytes_via_ethtool(port_num, (offset + OSFP_TYPE_OFFSET), XCVR_TYPE_WIDTH) + sfp_type_raw = self._read_eeprom_specific_bytes_via_ethtool( + port_num, (offset + OSFP_TYPE_OFFSET), XCVR_TYPE_WIDTH) if sfp_type_raw is not None: sfp_type_data = sfpi_obj.parse_sfp_type(sfp_type_raw, 0) else: return None - sfp_vendor_name_raw = self._read_eeprom_specific_bytes_via_ethtool(port_num, (offset + OSFP_VENDOR_NAME_OFFSET), XCVR_VENDOR_NAME_WIDTH) + sfp_vendor_name_raw = self._read_eeprom_specific_bytes_via_ethtool( + port_num, (offset + OSFP_VENDOR_NAME_OFFSET), XCVR_VENDOR_NAME_WIDTH) if sfp_vendor_name_raw is not None: sfp_vendor_name_data = sfpi_obj.parse_vendor_name(sfp_vendor_name_raw, 0) else: return None - sfp_vendor_pn_raw = self._read_eeprom_specific_bytes_via_ethtool(port_num, (offset + OSFP_VENDOR_PN_OFFSET), XCVR_VENDOR_PN_WIDTH) + sfp_vendor_pn_raw = self._read_eeprom_specific_bytes_via_ethtool( + port_num, (offset + OSFP_VENDOR_PN_OFFSET), XCVR_VENDOR_PN_WIDTH) if sfp_vendor_pn_raw is not None: sfp_vendor_pn_data = sfpi_obj.parse_vendor_pn(sfp_vendor_pn_raw, 0) else: return None - sfp_vendor_rev_raw = self._read_eeprom_specific_bytes_via_ethtool(port_num, (offset + OSFP_HW_REV_OFFSET), vendor_rev_width) + sfp_vendor_rev_raw = self._read_eeprom_specific_bytes_via_ethtool( + port_num, (offset + OSFP_HW_REV_OFFSET), vendor_rev_width) if sfp_vendor_rev_raw is not None: sfp_vendor_rev_data = sfpi_obj.parse_vendor_rev(sfp_vendor_rev_raw, 0) else: return None - sfp_vendor_sn_raw = self._read_eeprom_specific_bytes_via_ethtool(port_num, (offset + OSFP_VENDOR_SN_OFFSET), XCVR_VENDOR_SN_WIDTH) + sfp_vendor_sn_raw = self._read_eeprom_specific_bytes_via_ethtool( + port_num, (offset + OSFP_VENDOR_SN_OFFSET), XCVR_VENDOR_SN_WIDTH) if sfp_vendor_sn_raw is not None: sfp_vendor_sn_data = sfpi_obj.parse_vendor_sn(sfp_vendor_sn_raw, 0) else: @@ -361,43 +371,50 @@ def get_transceiver_info_dict(self, port_num): print("Error: sfp_object open failed") return None - sfp_interface_bulk_raw = self._read_eeprom_specific_bytes_via_ethtool(port_num, (offset + XCVR_INTFACE_BULK_OFFSET), interface_info_bulk_width) + sfp_interface_bulk_raw = self._read_eeprom_specific_bytes_via_ethtool( + port_num, (offset + XCVR_INTFACE_BULK_OFFSET), interface_info_bulk_width) if sfp_interface_bulk_raw is not None: sfp_interface_bulk_data = sfpi_obj.parse_sfp_info_bulk(sfp_interface_bulk_raw, 0) else: return None - sfp_vendor_name_raw = self._read_eeprom_specific_bytes_via_ethtool(port_num, (offset + XCVR_VENDOR_NAME_OFFSET), XCVR_VENDOR_NAME_WIDTH) + sfp_vendor_name_raw = self._read_eeprom_specific_bytes_via_ethtool( + port_num, (offset + XCVR_VENDOR_NAME_OFFSET), XCVR_VENDOR_NAME_WIDTH) if sfp_vendor_name_raw is not None: sfp_vendor_name_data = sfpi_obj.parse_vendor_name(sfp_vendor_name_raw, 0) else: return None - sfp_vendor_pn_raw = self._read_eeprom_specific_bytes_via_ethtool(port_num, (offset + XCVR_VENDOR_PN_OFFSET), XCVR_VENDOR_PN_WIDTH) + sfp_vendor_pn_raw = self._read_eeprom_specific_bytes_via_ethtool( + port_num, (offset + XCVR_VENDOR_PN_OFFSET), XCVR_VENDOR_PN_WIDTH) if sfp_vendor_pn_raw is not None: sfp_vendor_pn_data = sfpi_obj.parse_vendor_pn(sfp_vendor_pn_raw, 0) else: return None - sfp_vendor_rev_raw = self._read_eeprom_specific_bytes_via_ethtool(port_num, (offset + XCVR_HW_REV_OFFSET), vendor_rev_width) + sfp_vendor_rev_raw = self._read_eeprom_specific_bytes_via_ethtool( + port_num, (offset + XCVR_HW_REV_OFFSET), vendor_rev_width) if sfp_vendor_rev_raw is not None: sfp_vendor_rev_data = sfpi_obj.parse_vendor_rev(sfp_vendor_rev_raw, 0) else: return None - sfp_vendor_sn_raw = self._read_eeprom_specific_bytes_via_ethtool(port_num, (offset + XCVR_VENDOR_SN_OFFSET), XCVR_VENDOR_SN_WIDTH) + sfp_vendor_sn_raw = self._read_eeprom_specific_bytes_via_ethtool( + port_num, (offset + XCVR_VENDOR_SN_OFFSET), XCVR_VENDOR_SN_WIDTH) if sfp_vendor_sn_raw is not None: sfp_vendor_sn_data = sfpi_obj.parse_vendor_sn(sfp_vendor_sn_raw, 0) else: return None - sfp_vendor_oui_raw = self._read_eeprom_specific_bytes_via_ethtool(port_num, (offset + XCVR_VENDOR_OUI_OFFSET), XCVR_VENDOR_OUI_WIDTH) + sfp_vendor_oui_raw = self._read_eeprom_specific_bytes_via_ethtool( + port_num, (offset + XCVR_VENDOR_OUI_OFFSET), XCVR_VENDOR_OUI_WIDTH) if sfp_vendor_oui_raw is not None: sfp_vendor_oui_data = sfpi_obj.parse_vendor_oui(sfp_vendor_oui_raw, 0) else: return None - sfp_vendor_date_raw = self._read_eeprom_specific_bytes_via_ethtool(port_num, (offset + XCVR_VENDOR_DATE_OFFSET), XCVR_VENDOR_DATE_WIDTH) + sfp_vendor_date_raw = self._read_eeprom_specific_bytes_via_ethtool( + port_num, (offset + XCVR_VENDOR_DATE_OFFSET), XCVR_VENDOR_DATE_WIDTH) if sfp_vendor_date_raw is not None: sfp_vendor_date_data = sfpi_obj.parse_vendor_date(sfp_vendor_date_raw, 0) else: @@ -409,7 +426,8 @@ def get_transceiver_info_dict(self, port_num): transceiver_info_dict['hardware_rev'] = sfp_vendor_rev_data['data']['Vendor Rev']['value'] transceiver_info_dict['serial'] = sfp_vendor_sn_data['data']['Vendor SN']['value'] transceiver_info_dict['vendor_oui'] = sfp_vendor_oui_data['data']['Vendor OUI']['value'] - transceiver_info_dict['vendor_date'] = sfp_vendor_date_data['data']['VendorDataCode(YYYY-MM-DD Lot)']['value'] + transceiver_info_dict['vendor_date'] = sfp_vendor_date_data[ + 'data']['VendorDataCode(YYYY-MM-DD Lot)']['value'] transceiver_info_dict['connector'] = sfp_interface_bulk_data['data']['Connector']['value'] transceiver_info_dict['encoding'] = sfp_interface_bulk_data['data']['EncodingCodes']['value'] transceiver_info_dict['ext_identifier'] = sfp_interface_bulk_data['data']['Extended Identifier']['value'] @@ -424,8 +442,9 @@ def get_transceiver_info_dict(self, port_num): if key in sfp_interface_bulk_data['data']['Specification compliance']['value']: compliance_code_dict[key] = sfp_interface_bulk_data['data']['Specification compliance']['value'][key]['value'] transceiver_info_dict['specification_compliance'] = str(compliance_code_dict) - - transceiver_info_dict['nominal_bit_rate'] = str(sfp_interface_bulk_data['data']['Nominal Bit Rate(100Mbs)']['value']) + + transceiver_info_dict['nominal_bit_rate'] = str( + sfp_interface_bulk_data['data']['Nominal Bit Rate(100Mbs)']['value']) else: for key in sfp_cable_length_tup: if key in sfp_interface_bulk_data['data']: @@ -437,7 +456,8 @@ def get_transceiver_info_dict(self, port_num): compliance_code_dict[key] = sfp_interface_bulk_data['data']['Specification compliance']['value'][key]['value'] transceiver_info_dict['specification_compliance'] = str(compliance_code_dict) - transceiver_info_dict['nominal_bit_rate'] = str(sfp_interface_bulk_data['data']['NominalSignallingRate(UnitsOf100Mbd)']['value']) + transceiver_info_dict['nominal_bit_rate'] = str( + sfp_interface_bulk_data['data']['NominalSignallingRate(UnitsOf100Mbd)']['value']) return transceiver_info_dict @@ -447,15 +467,15 @@ def get_transceiver_dom_info_dict(self, port_num): # Below part is added to avoid failing xcvrd # Currently, the way in which dom data is read has been changed from # using sysfs to using ethtool. - # The ethtool returns None for ports without dom support, resulting in - # None being returned. However, this fails xcvrd to add the + # The ethtool returns None for ports without dom support, resulting in + # None being returned. However, this fails xcvrd to add the # TRANSCEIVER_DOM_SENSOR table entry of associated port to CONFIG_DB # and then causes SNMP fail. # To address this issue a default dict is initialized with all data set to # 'N/A' and is returned is the above case. # BTW, in the original implementation which sysfs is used to read dom data, - # even though non-None data is returned for ports without dom support, - # it does not contain valid data. This can result in wrong data in + # even though non-None data is returned for ports without dom support, + # it does not contain valid data. This can result in wrong data in # TRANSCEIVER_DOM_SENSOR table. transceiver_dom_info_dict['temperature'] = 'N/A' transceiver_dom_info_dict['voltage'] = 'N/A' @@ -486,30 +506,33 @@ def get_transceiver_dom_info_dict(self, port_num): if sfpi_obj is None: return None - # QSFP capability byte parse, through this byte can know whether it support tx_power or not. # TODO: in the future when decided to migrate to support SFF-8636 instead of SFF-8436, # need to add more code for determining the capability and version compliance # in SFF-8636 dom capability definitions evolving with the versions. - qsfp_dom_capability_raw = self._read_eeprom_specific_bytes_via_ethtool(port_num, (offset_xcvr + XCVR_DOM_CAPABILITY_OFFSET), XCVR_DOM_CAPABILITY_WIDTH) + qsfp_dom_capability_raw = self._read_eeprom_specific_bytes_via_ethtool( + port_num, (offset_xcvr + XCVR_DOM_CAPABILITY_OFFSET), XCVR_DOM_CAPABILITY_WIDTH) if qsfp_dom_capability_raw is not None: qspf_dom_capability_data = sfpi_obj.parse_qsfp_dom_capability(qsfp_dom_capability_raw, 0) else: return transceiver_dom_info_dict - dom_temperature_raw = self._read_eeprom_specific_bytes_via_ethtool(port_num, (offset + QSFP_TEMPE_OFFSET), QSFP_TEMPE_WIDTH) + dom_temperature_raw = self._read_eeprom_specific_bytes_via_ethtool( + port_num, (offset + QSFP_TEMPE_OFFSET), QSFP_TEMPE_WIDTH) if dom_temperature_raw is not None: dom_temperature_data = sfpd_obj.parse_temperature(dom_temperature_raw, 0) else: return transceiver_dom_info_dict - dom_voltage_raw = self._read_eeprom_specific_bytes_via_ethtool(port_num, (offset + QSFP_VOLT_OFFSET), QSFP_VOLT_WIDTH) + dom_voltage_raw = self._read_eeprom_specific_bytes_via_ethtool( + port_num, (offset + QSFP_VOLT_OFFSET), QSFP_VOLT_WIDTH) if dom_voltage_raw is not None: dom_voltage_data = sfpd_obj.parse_voltage(dom_voltage_raw, 0) else: return transceiver_dom_info_dict - qsfp_dom_rev_raw = self._read_eeprom_specific_bytes_via_ethtool(port_num, (offset + QSFP_DOM_REV_OFFSET), QSFP_DOM_REV_WIDTH) + qsfp_dom_rev_raw = self._read_eeprom_specific_bytes_via_ethtool( + port_num, (offset + QSFP_DOM_REV_OFFSET), QSFP_DOM_REV_WIDTH) if qsfp_dom_rev_raw is not None: qsfp_dom_rev_data = sfpd_obj.parse_sfp_dom_rev(qsfp_dom_rev_raw, 0) else: @@ -524,15 +547,18 @@ def get_transceiver_dom_info_dict(self, port_num): 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_via_ethtool(port_num, (offset + QSFP_CHANNL_MON_OFFSET), QSFP_CHANNL_MON_WIDTH) + dom_channel_monitor_raw = self._read_eeprom_specific_bytes_via_ethtool( + port_num, (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: return transceiver_dom_info_dict else: - dom_channel_monitor_raw = self._read_eeprom_specific_bytes_via_ethtool(port_num, (offset + QSFP_CHANNL_MON_OFFSET), QSFP_CHANNL_MON_WITH_TX_POWER_WIDTH) + dom_channel_monitor_raw = self._read_eeprom_specific_bytes_via_ethtool( + port_num, (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 transceiver_dom_info_dict @@ -556,8 +582,9 @@ def get_transceiver_dom_info_dict(self, port_num): offset = SFP_I2C_PAGE_SIZE eeprom_raw = ['0'] * SFP_I2C_PAGE_SIZE - eeprom_raw[XCVR_DOM_CAPABILITY_OFFSET : XCVR_DOM_CAPABILITY_OFFSET + XCVR_DOM_CAPABILITY_WIDTH] = \ - self._read_eeprom_specific_bytes_via_ethtool(port_num, XCVR_DOM_CAPABILITY_OFFSET, XCVR_DOM_CAPABILITY_WIDTH) + eeprom_raw[XCVR_DOM_CAPABILITY_OFFSET: XCVR_DOM_CAPABILITY_OFFSET + XCVR_DOM_CAPABILITY_WIDTH] = \ + self._read_eeprom_specific_bytes_via_ethtool( + port_num, XCVR_DOM_CAPABILITY_OFFSET, XCVR_DOM_CAPABILITY_WIDTH) sfp_obj = sff8472InterfaceId() calibration_type = sfp_obj._get_calibration_type(eeprom_raw) @@ -571,7 +598,7 @@ def get_transceiver_dom_info_dict(self, port_num): sfpd_obj = sff8472Dom(None, calibration_type) if sfpd_obj is None: - print "no sff8472Dom" + print("no sff8472Dom") return None dom_temperature_raw = eeprom_domraw[SFP_TEMPE_OFFSET:SFP_TEMPE_OFFSET+SFP_TEMPE_WIDTH] @@ -604,7 +631,7 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): 'txpowerlowalarm', 'txpowerlowwarning', 'txbiashighalarm', 'txbiashighwarning', 'txbiaslowalarm', 'txbiaslowwarning' - ] + ] transceiver_dom_threshold_info_dict = dict.fromkeys(dom_info_dict_keys, 'N/A') if port_num in self.qsfp_ports: @@ -614,8 +641,9 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): offset = SFP_I2C_PAGE_SIZE eeprom_raw = ['0'] * SFP_I2C_PAGE_SIZE - eeprom_raw[XCVR_DOM_CAPABILITY_OFFSET : XCVR_DOM_CAPABILITY_OFFSET + XCVR_DOM_CAPABILITY_WIDTH] = \ - self._read_eeprom_specific_bytes_via_ethtool(port_num, XCVR_DOM_CAPABILITY_OFFSET, XCVR_DOM_CAPABILITY_WIDTH) + eeprom_raw[XCVR_DOM_CAPABILITY_OFFSET: XCVR_DOM_CAPABILITY_OFFSET + XCVR_DOM_CAPABILITY_WIDTH] = \ + self._read_eeprom_specific_bytes_via_ethtool( + port_num, XCVR_DOM_CAPABILITY_OFFSET, XCVR_DOM_CAPABILITY_WIDTH) sfp_obj = sff8472InterfaceId() calibration_type = sfp_obj._get_calibration_type(eeprom_raw) @@ -628,8 +656,8 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): return transceiver_dom_threshold_info_dict dom_module_threshold_raw = self._read_eeprom_specific_bytes_via_ethtool(port_num, - (offset + SFP_MODULE_THRESHOLD_OFFSET), - SFP_MODULE_THRESHOLD_WIDTH) + (offset + SFP_MODULE_THRESHOLD_OFFSET), + SFP_MODULE_THRESHOLD_WIDTH) if dom_module_threshold_raw is not None: dom_module_threshold_data = sfpd_obj.parse_alarm_warning_threshold(dom_module_threshold_raw, 0) else: diff --git a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/thermalutil.py b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/thermalutil.py index 73d27a41ac23..980ef8a9fc38 100644 --- a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/thermalutil.py +++ b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/thermalutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Mellanox # @@ -14,7 +12,8 @@ import subprocess from sonic_thermal.thermal_base import ThermalBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + def log_info(msg): syslog.openlog("thermalutil") @@ -44,57 +43,57 @@ def log_info(msg): HW_MGMT_THERMAL_ROOT = "/var/run/hw-management/thermal/" thermal_api_handler_cpu_core = { - THERMAL_API_GET_TEMPERATURE:"cpu_core{}", - THERMAL_API_GET_HIGH_THRESHOLD:"cpu_core{}_max", - THERMAL_API_GET_HIGH_CRITICAL_THRESHOLD:"cpu_core{}_crit" + THERMAL_API_GET_TEMPERATURE: "cpu_core{}", + THERMAL_API_GET_HIGH_THRESHOLD: "cpu_core{}_max", + THERMAL_API_GET_HIGH_CRITICAL_THRESHOLD: "cpu_core{}_crit" } thermal_api_handler_cpu_pack = { - THERMAL_API_GET_TEMPERATURE:"cpu_pack", - THERMAL_API_GET_HIGH_THRESHOLD:"cpu_pack_max", - THERMAL_API_GET_HIGH_CRITICAL_THRESHOLD:"cpu_pack_crit" + THERMAL_API_GET_TEMPERATURE: "cpu_pack", + THERMAL_API_GET_HIGH_THRESHOLD: "cpu_pack_max", + THERMAL_API_GET_HIGH_CRITICAL_THRESHOLD: "cpu_pack_crit" } thermal_api_handler_module = { - THERMAL_API_GET_TEMPERATURE:"module{}_temp_input", - THERMAL_API_GET_HIGH_THRESHOLD:"module{}_temp_crit", - THERMAL_API_GET_HIGH_CRITICAL_THRESHOLD:"module{}_temp_emergency" + THERMAL_API_GET_TEMPERATURE: "module{}_temp_input", + THERMAL_API_GET_HIGH_THRESHOLD: "module{}_temp_crit", + THERMAL_API_GET_HIGH_CRITICAL_THRESHOLD: "module{}_temp_emergency" } thermal_api_handler_psu = { - THERMAL_API_GET_TEMPERATURE:"psu{}_temp", - THERMAL_API_GET_HIGH_THRESHOLD:"psu{}_temp_max", - THERMAL_API_GET_HIGH_CRITICAL_THRESHOLD:None + THERMAL_API_GET_TEMPERATURE: "psu{}_temp", + THERMAL_API_GET_HIGH_THRESHOLD: "psu{}_temp_max", + THERMAL_API_GET_HIGH_CRITICAL_THRESHOLD: None } thermal_api_handler_gearbox = { - THERMAL_API_GET_TEMPERATURE:"gearbox{}_temp_input", - THERMAL_API_GET_HIGH_THRESHOLD:None, - THERMAL_API_GET_HIGH_CRITICAL_THRESHOLD:None + THERMAL_API_GET_TEMPERATURE: "gearbox{}_temp_input", + THERMAL_API_GET_HIGH_THRESHOLD: None, + THERMAL_API_GET_HIGH_CRITICAL_THRESHOLD: None } thermal_ambient_apis = { - THERMAL_DEV_ASIC_AMBIENT : "asic", - THERMAL_DEV_PORT_AMBIENT : "port_amb", - THERMAL_DEV_FAN_AMBIENT : "fan_amb", - THERMAL_DEV_COMEX_AMBIENT : "comex_amb", - THERMAL_DEV_BOARD_AMBIENT : "board_amb" + THERMAL_DEV_ASIC_AMBIENT: "asic", + THERMAL_DEV_PORT_AMBIENT: "port_amb", + THERMAL_DEV_FAN_AMBIENT: "fan_amb", + THERMAL_DEV_COMEX_AMBIENT: "comex_amb", + THERMAL_DEV_BOARD_AMBIENT: "board_amb" } thermal_ambient_name = { - THERMAL_DEV_ASIC_AMBIENT : "Ambient ASIC Temp", - THERMAL_DEV_PORT_AMBIENT : "Ambient Port Side Temp", - THERMAL_DEV_FAN_AMBIENT : "Ambient Fan Side Temp", - THERMAL_DEV_COMEX_AMBIENT : "Ambient COMEX Temp", - THERMAL_DEV_BOARD_AMBIENT : "Ambient Board Temp" + THERMAL_DEV_ASIC_AMBIENT: "Ambient ASIC Temp", + THERMAL_DEV_PORT_AMBIENT: "Ambient Port Side Temp", + THERMAL_DEV_FAN_AMBIENT: "Ambient Fan Side Temp", + THERMAL_DEV_COMEX_AMBIENT: "Ambient COMEX Temp", + THERMAL_DEV_BOARD_AMBIENT: "Ambient Board Temp" } thermal_api_handlers = { - THERMAL_DEV_CATEGORY_CPU_CORE : thermal_api_handler_cpu_core, - THERMAL_DEV_CATEGORY_CPU_PACK : thermal_api_handler_cpu_pack, - THERMAL_DEV_CATEGORY_MODULE : thermal_api_handler_module, - THERMAL_DEV_CATEGORY_PSU : thermal_api_handler_psu, - THERMAL_DEV_CATEGORY_GEARBOX : thermal_api_handler_gearbox + THERMAL_DEV_CATEGORY_CPU_CORE: thermal_api_handler_cpu_core, + THERMAL_DEV_CATEGORY_CPU_PACK: thermal_api_handler_cpu_pack, + THERMAL_DEV_CATEGORY_MODULE: thermal_api_handler_module, + THERMAL_DEV_CATEGORY_PSU: thermal_api_handler_psu, + THERMAL_DEV_CATEGORY_GEARBOX: thermal_api_handler_gearbox } thermal_name = { - THERMAL_DEV_CATEGORY_CPU_CORE : "CPU Core {} Temp", - THERMAL_DEV_CATEGORY_CPU_PACK : "CPU Pack Temp", - THERMAL_DEV_CATEGORY_MODULE : "xSFP module {} Temp", - THERMAL_DEV_CATEGORY_PSU : "PSU-{} Temp", - THERMAL_DEV_CATEGORY_GEARBOX : "Gearbox {} Temp" + THERMAL_DEV_CATEGORY_CPU_CORE: "CPU Core {} Temp", + THERMAL_DEV_CATEGORY_CPU_PACK: "CPU Pack Temp", + THERMAL_DEV_CATEGORY_MODULE: "xSFP module {} Temp", + THERMAL_DEV_CATEGORY_PSU: "PSU-{} Temp", + THERMAL_DEV_CATEGORY_GEARBOX: "Gearbox {} Temp" } thermal_device_categories_all = [ @@ -115,130 +114,131 @@ def log_info(msg): THERMAL_API_GET_HIGH_THRESHOLD ] -hwsku_dict_thermal = {'ACS-MSN2700': 0, 'LS-SN2700':0, 'ACS-MSN2740': 3, 'ACS-MSN2100': 1, 'ACS-MSN2410': 2, 'ACS-MSN2010': 4, 'ACS-MSN3700': 5, 'ACS-MSN3700C': 6, 'Mellanox-SN2700': 0, 'Mellanox-SN2700-D48C8': 0, 'ACS-MSN3800': 7, 'Mellanox-SN3800-D112C8': 7} +hwsku_dict_thermal = {'ACS-MSN2700': 0, 'LS-SN2700': 0, 'ACS-MSN2740': 3, 'ACS-MSN2100': 1, 'ACS-MSN2410': 2, 'ACS-MSN2010': 4, + 'ACS-MSN3700': 5, 'ACS-MSN3700C': 6, 'Mellanox-SN2700': 0, 'Mellanox-SN2700-D48C8': 0, 'ACS-MSN3800': 7, 'Mellanox-SN3800-D112C8': 7} thermal_profile_list = [ # 2700 { - THERMAL_DEV_CATEGORY_CPU_CORE:(0, 2), - THERMAL_DEV_CATEGORY_MODULE:(1, 32), - THERMAL_DEV_CATEGORY_PSU:(1, 2), - THERMAL_DEV_CATEGORY_CPU_PACK:(0,1), - THERMAL_DEV_CATEGORY_GEARBOX:(0,0), - THERMAL_DEV_CATEGORY_AMBIENT:(0, - [ - THERMAL_DEV_ASIC_AMBIENT, - THERMAL_DEV_PORT_AMBIENT, - THERMAL_DEV_FAN_AMBIENT - ] - ) + THERMAL_DEV_CATEGORY_CPU_CORE: (0, 2), + THERMAL_DEV_CATEGORY_MODULE: (1, 32), + THERMAL_DEV_CATEGORY_PSU: (1, 2), + THERMAL_DEV_CATEGORY_CPU_PACK: (0, 1), + THERMAL_DEV_CATEGORY_GEARBOX: (0, 0), + THERMAL_DEV_CATEGORY_AMBIENT: (0, + [ + THERMAL_DEV_ASIC_AMBIENT, + THERMAL_DEV_PORT_AMBIENT, + THERMAL_DEV_FAN_AMBIENT + ] + ) }, # 2100 { - THERMAL_DEV_CATEGORY_CPU_CORE:(0, 4), - THERMAL_DEV_CATEGORY_MODULE:(1, 16), - THERMAL_DEV_CATEGORY_PSU:(0, 0), - THERMAL_DEV_CATEGORY_CPU_PACK:(0,0), - THERMAL_DEV_CATEGORY_GEARBOX:(0,0), - THERMAL_DEV_CATEGORY_AMBIENT:(0, - [ - THERMAL_DEV_ASIC_AMBIENT, - THERMAL_DEV_PORT_AMBIENT, - THERMAL_DEV_FAN_AMBIENT, - ] - ) + THERMAL_DEV_CATEGORY_CPU_CORE: (0, 4), + THERMAL_DEV_CATEGORY_MODULE: (1, 16), + THERMAL_DEV_CATEGORY_PSU: (0, 0), + THERMAL_DEV_CATEGORY_CPU_PACK: (0, 0), + THERMAL_DEV_CATEGORY_GEARBOX: (0, 0), + THERMAL_DEV_CATEGORY_AMBIENT: (0, + [ + THERMAL_DEV_ASIC_AMBIENT, + THERMAL_DEV_PORT_AMBIENT, + THERMAL_DEV_FAN_AMBIENT, + ] + ) }, # 2410 { - THERMAL_DEV_CATEGORY_CPU_CORE:(0, 2), - THERMAL_DEV_CATEGORY_MODULE:(1, 56), - THERMAL_DEV_CATEGORY_PSU:(1, 2), - THERMAL_DEV_CATEGORY_CPU_PACK:(0,1), - THERMAL_DEV_CATEGORY_GEARBOX:(0,0), - THERMAL_DEV_CATEGORY_AMBIENT:(0, - [ - THERMAL_DEV_ASIC_AMBIENT, - THERMAL_DEV_PORT_AMBIENT, - THERMAL_DEV_FAN_AMBIENT, - ] - ) + THERMAL_DEV_CATEGORY_CPU_CORE: (0, 2), + THERMAL_DEV_CATEGORY_MODULE: (1, 56), + THERMAL_DEV_CATEGORY_PSU: (1, 2), + THERMAL_DEV_CATEGORY_CPU_PACK: (0, 1), + THERMAL_DEV_CATEGORY_GEARBOX: (0, 0), + THERMAL_DEV_CATEGORY_AMBIENT: (0, + [ + THERMAL_DEV_ASIC_AMBIENT, + THERMAL_DEV_PORT_AMBIENT, + THERMAL_DEV_FAN_AMBIENT, + ] + ) }, # 2740 { - THERMAL_DEV_CATEGORY_CPU_CORE:(0, 4), - THERMAL_DEV_CATEGORY_MODULE:(1, 32), - THERMAL_DEV_CATEGORY_PSU:(1, 2), - THERMAL_DEV_CATEGORY_CPU_PACK:(0,0), - THERMAL_DEV_CATEGORY_GEARBOX:(0,0), - THERMAL_DEV_CATEGORY_AMBIENT:(0, - [ - THERMAL_DEV_ASIC_AMBIENT, - THERMAL_DEV_PORT_AMBIENT, - THERMAL_DEV_FAN_AMBIENT, - ] - ) + THERMAL_DEV_CATEGORY_CPU_CORE: (0, 4), + THERMAL_DEV_CATEGORY_MODULE: (1, 32), + THERMAL_DEV_CATEGORY_PSU: (1, 2), + THERMAL_DEV_CATEGORY_CPU_PACK: (0, 0), + THERMAL_DEV_CATEGORY_GEARBOX: (0, 0), + THERMAL_DEV_CATEGORY_AMBIENT: (0, + [ + THERMAL_DEV_ASIC_AMBIENT, + THERMAL_DEV_PORT_AMBIENT, + THERMAL_DEV_FAN_AMBIENT, + ] + ) }, # 2010 { - THERMAL_DEV_CATEGORY_CPU_CORE:(0, 4), - THERMAL_DEV_CATEGORY_MODULE:(1, 22), - THERMAL_DEV_CATEGORY_PSU:(0, 0), - THERMAL_DEV_CATEGORY_CPU_PACK:(0,0), - THERMAL_DEV_CATEGORY_GEARBOX:(0,0), - THERMAL_DEV_CATEGORY_AMBIENT:(0, - [ - THERMAL_DEV_ASIC_AMBIENT, - THERMAL_DEV_PORT_AMBIENT, - THERMAL_DEV_FAN_AMBIENT, - ] - ) + THERMAL_DEV_CATEGORY_CPU_CORE: (0, 4), + THERMAL_DEV_CATEGORY_MODULE: (1, 22), + THERMAL_DEV_CATEGORY_PSU: (0, 0), + THERMAL_DEV_CATEGORY_CPU_PACK: (0, 0), + THERMAL_DEV_CATEGORY_GEARBOX: (0, 0), + THERMAL_DEV_CATEGORY_AMBIENT: (0, + [ + THERMAL_DEV_ASIC_AMBIENT, + THERMAL_DEV_PORT_AMBIENT, + THERMAL_DEV_FAN_AMBIENT, + ] + ) }, # 3700 { - THERMAL_DEV_CATEGORY_CPU_CORE:(0, 4), - THERMAL_DEV_CATEGORY_MODULE:(1, 32), - THERMAL_DEV_CATEGORY_PSU:(1, 2), - THERMAL_DEV_CATEGORY_CPU_PACK:(0,1), - THERMAL_DEV_CATEGORY_GEARBOX:(0,0), - THERMAL_DEV_CATEGORY_AMBIENT:(0, - [ - THERMAL_DEV_ASIC_AMBIENT, - THERMAL_DEV_COMEX_AMBIENT, - THERMAL_DEV_PORT_AMBIENT, - THERMAL_DEV_FAN_AMBIENT - ] - ) + THERMAL_DEV_CATEGORY_CPU_CORE: (0, 4), + THERMAL_DEV_CATEGORY_MODULE: (1, 32), + THERMAL_DEV_CATEGORY_PSU: (1, 2), + THERMAL_DEV_CATEGORY_CPU_PACK: (0, 1), + THERMAL_DEV_CATEGORY_GEARBOX: (0, 0), + THERMAL_DEV_CATEGORY_AMBIENT: (0, + [ + THERMAL_DEV_ASIC_AMBIENT, + THERMAL_DEV_COMEX_AMBIENT, + THERMAL_DEV_PORT_AMBIENT, + THERMAL_DEV_FAN_AMBIENT + ] + ) }, # 3700c { - THERMAL_DEV_CATEGORY_CPU_CORE:(0, 2), - THERMAL_DEV_CATEGORY_MODULE:(1, 32), - THERMAL_DEV_CATEGORY_PSU:(1, 2), - THERMAL_DEV_CATEGORY_CPU_PACK:(0,1), - THERMAL_DEV_CATEGORY_GEARBOX:(0,0), - THERMAL_DEV_CATEGORY_AMBIENT:(0, - [ - THERMAL_DEV_ASIC_AMBIENT, - THERMAL_DEV_COMEX_AMBIENT, - THERMAL_DEV_PORT_AMBIENT, - THERMAL_DEV_FAN_AMBIENT - ] - ) + THERMAL_DEV_CATEGORY_CPU_CORE: (0, 2), + THERMAL_DEV_CATEGORY_MODULE: (1, 32), + THERMAL_DEV_CATEGORY_PSU: (1, 2), + THERMAL_DEV_CATEGORY_CPU_PACK: (0, 1), + THERMAL_DEV_CATEGORY_GEARBOX: (0, 0), + THERMAL_DEV_CATEGORY_AMBIENT: (0, + [ + THERMAL_DEV_ASIC_AMBIENT, + THERMAL_DEV_COMEX_AMBIENT, + THERMAL_DEV_PORT_AMBIENT, + THERMAL_DEV_FAN_AMBIENT + ] + ) }, # 3800 { - THERMAL_DEV_CATEGORY_CPU_CORE:(0, 4), - THERMAL_DEV_CATEGORY_MODULE:(1, 64), - THERMAL_DEV_CATEGORY_PSU:(1, 2), - THERMAL_DEV_CATEGORY_CPU_PACK:(0,1), - THERMAL_DEV_CATEGORY_GEARBOX:(1,32), - THERMAL_DEV_CATEGORY_AMBIENT:(0, - [ - THERMAL_DEV_ASIC_AMBIENT, - THERMAL_DEV_COMEX_AMBIENT, - THERMAL_DEV_PORT_AMBIENT, - THERMAL_DEV_FAN_AMBIENT - ] - ) + THERMAL_DEV_CATEGORY_CPU_CORE: (0, 4), + THERMAL_DEV_CATEGORY_MODULE: (1, 64), + THERMAL_DEV_CATEGORY_PSU: (1, 2), + THERMAL_DEV_CATEGORY_CPU_PACK: (0, 1), + THERMAL_DEV_CATEGORY_GEARBOX: (1, 32), + THERMAL_DEV_CATEGORY_AMBIENT: (0, + [ + THERMAL_DEV_ASIC_AMBIENT, + THERMAL_DEV_COMEX_AMBIENT, + THERMAL_DEV_PORT_AMBIENT, + THERMAL_DEV_FAN_AMBIENT + ] + ) }, ] @@ -364,7 +364,7 @@ class ThermalUtil(ThermalBase): thermal_list = [] def _get_sku_name(self): - p = subprocess.Popen(self.GET_HWSKU_CMD, shell=True, stdout=subprocess.PIPE) + p = subprocess.Popen(self.GET_HWSKU_CMD, shell=True, universal_newlines=True, stdout=subprocess.PIPE) out, err = p.communicate() return out.rstrip('\n') diff --git a/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/plugins/eeprom.py b/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/plugins/eeprom.py index 96dcc5975328..96dc19ad5b36 100644 --- a/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/plugins/eeprom.py +++ b/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,14 +8,16 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/2-0050/eeprom" - #Two i2c buses might get flipped order, check them both. + # Two i2c buses might get flipped order, check them both. if not os.path.exists(self.eeprom_path): self.eeprom_path = "/sys/bus/i2c/devices/2-0050/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/plugins/sfputil.py b/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/plugins/sfputil.py index 33e98016384a..97c04f6d0d43 100644 --- a/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/plugins/sfputil.py +++ b/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/plugins/sfputil.py @@ -31,7 +31,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(0, self.PORTS_IN_BLOCK + 1) + return list(range(0, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -51,16 +51,17 @@ def get_presence(self, port_num): return False if port_num > 16: - cpld_addr=33 + cpld_addr = 33 else: - cpld_addr=32 + cpld_addr = 32 - file_path="/sys/bus/i2c/devices/1-00" + str(cpld_addr) + "/port" + str(port_num) + "/port" + str(port_num) + "_present" + file_path = "/sys/bus/i2c/devices/1-00" + \ + str(cpld_addr) + "/port" + str(port_num) + "/port" + str(port_num) + "_present" try: reg_file = open("file_path") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -68,7 +69,6 @@ def get_presence(self, port_num): # content is a string containing the hex representation of the register reg_value = int(content, 16) - # ModPrsL is active low if reg_value == 0: return True @@ -81,17 +81,17 @@ def get_low_power_mode(self, port_num): return False if port_num > 16: - cpld_addr=33 + cpld_addr = 33 else: - cpld_addr=32 - + cpld_addr = 32 - file_path="/sys/bus/i2c/devices/1-00" + str(cpld_addr) + "/port" + str(port_num) + "/port" + str(port_num) + "_lpmode" + file_path = "/sys/bus/i2c/devices/1-00" + \ + str(cpld_addr) + "/port" + str(port_num) + "/port" + str(port_num) + "_lpmode" try: reg_file = open(file_path) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) content = reg_file.readline().rstrip() @@ -110,21 +110,22 @@ def set_low_power_mode(self, port_num, lpmode): return False if port_num > 16: - cpld_addr=33 + cpld_addr = 33 else: - cpld_addr=32 + cpld_addr = 32 - file_path="/sys/bus/i2c/devices/1-00" + str(cpld_num) + "/port" + str(port_num) + "/port" + str(port_num) + "_lpmode" + file_path = "/sys/bus/i2c/devices/1-00" + \ + str(cpld_num) + "/port" + str(port_num) + "/port" + str(port_num) + "_lpmode" try: reg_file = open(file_path, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # LPMode is active high; set or clear the bit accordingly if lpmode is True: - reg_value = 1 + reg_value = 1 else: reg_value = 0 @@ -144,16 +145,17 @@ def reset(self, port_num): return False if port_num > 16: - cpld_addr=33 + cpld_addr = 33 else: - cpld_addr=32 + cpld_addr = 32 - file_path="/sys/bus/i2c/devices/1-00" + str(cpld_num) + "/port" + str(port_num) + "/port" + str(port_num) + "_rst" + file_path = "/sys/bus/i2c/devices/1-00" + \ + str(cpld_num) + "/port" + str(port_num) + "/port" + str(port_num) + "_rst" try: reg_file = open(file_path, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # ResetL is active low @@ -171,7 +173,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 1 diff --git a/device/nokia/armhf-nokia_ixs7215_52x-r0/plugins/eeprom.py b/device/nokia/armhf-nokia_ixs7215_52x-r0/plugins/eeprom.py index be538d1c0e89..cbd48237cc10 100644 --- a/device/nokia/armhf-nokia_ixs7215_52x-r0/plugins/eeprom.py +++ b/device/nokia/armhf-nokia_ixs7215_52x-r0/plugins/eeprom.py @@ -10,5 +10,5 @@ class board(eeprom_tlvinfo.TlvInfoDecoder): def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/class/i2c-adapter/i2c-0/0-0053/eeprom" if not os.path.exists(self.eeprom_path): - os.system("echo 24c02 0x53 > /sys/class/i2c-adapter/i2c-0/new_device") + os.system("echo 24c02 0x53 > /sys/class/i2c-adapter/i2c-0/new_device") super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/nokia/armhf-nokia_ixs7215_52x-r0/plugins/sfputil.py b/device/nokia/armhf-nokia_ixs7215_52x-r0/plugins/sfputil.py index 9b12e38226d5..1ca3b9ec6f2d 100755 --- a/device/nokia/armhf-nokia_ixs7215_52x-r0/plugins/sfputil.py +++ b/device/nokia/armhf-nokia_ixs7215_52x-r0/plugins/sfputil.py @@ -26,7 +26,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(0, 0) + return list(range(0, 0)) @property def port_to_eeprom_mapping(self): diff --git a/device/pegatron/x86_64-pegatron_porsche-r0/plugins/eeprom.py b/device/pegatron/x86_64-pegatron_porsche-r0/plugins/eeprom.py index 6964c6bade4f..5c2a90e81c2f 100755 --- a/device/pegatron/x86_64-pegatron_porsche-r0/plugins/eeprom.py +++ b/device/pegatron/x86_64-pegatron_porsche-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,11 +8,13 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/4-0054/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/pegatron/x86_64-pegatron_porsche-r0/plugins/psuutil.py b/device/pegatron/x86_64-pegatron_porsche-r0/plugins/psuutil.py index a23a7b7fe73e..ce859cb70c77 100755 --- a/device/pegatron/x86_64-pegatron_porsche-r0/plugins/psuutil.py +++ b/device/pegatron/x86_64-pegatron_porsche-r0/plugins/psuutil.py @@ -19,12 +19,12 @@ class PsuUtil(PsuBase): def __init__(self): PsuBase.__init__(self) - - + # Get sysfs attribute + def get_attr_value(self, attr_path): - - retval = 'ERR' + + retval = 'ERR' if (not os.path.isfile(attr_path)): return retval @@ -56,16 +56,16 @@ def get_psu_status(self, index): faulty """ status = 0 - attr_file = 'psu_'+str(index)+'_status' - attr_path = self.SYSFS_PSU_DIR +'/' + attr_file - + attr_file = 'psu_'+str(index)+'_status' + attr_path = self.SYSFS_PSU_DIR + '/' + attr_file + attr_value = self.get_attr_value(attr_path) - + if (attr_value != 'ERR'): attr_value = int(attr_value, 16) # Check for PSU status if (attr_value == 1): - status = 1 + status = 1 return status @@ -78,15 +78,14 @@ def get_psu_presence(self, index): """ status = 0 attr_file = 'psu_'+str(index)+'_present' - attr_path = self.SYSFS_PSU_DIR +'/' + attr_file - + attr_path = self.SYSFS_PSU_DIR + '/' + attr_file + attr_value = self.get_attr_value(attr_path) if (attr_value != 'ERR'): attr_value = int(attr_value, 16) # Check for PSU presence if (attr_value == 0): - status = 1 + status = 1 return status - diff --git a/device/pegatron/x86_64-pegatron_porsche-r0/plugins/sfputil.py b/device/pegatron/x86_64-pegatron_porsche-r0/plugins/sfputil.py index 28909f00110c..3a757333cd2f 100755 --- a/device/pegatron/x86_64-pegatron_porsche-r0/plugins/sfputil.py +++ b/device/pegatron/x86_64-pegatron_porsche-r0/plugins/sfputil.py @@ -1,12 +1,10 @@ -#!/usr/bin/env python - try: import os import re import time from sonic_sfp.sfputilbase import SfpUtilBase -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") class SfpUtil(SfpUtilBase): @@ -21,18 +19,17 @@ class SfpUtil(SfpUtilBase): port_to_eeprom_mapping = {} port_to_i2c_mapping = {} - sfp_ports = range(0, ports_in_block) - qsfp_ports = range(ports_in_block - 6, ports_in_block) - + sfp_ports = list(range(0, ports_in_block)) + qsfp_ports = list(range(ports_in_block - 6, ports_in_block)) def __init__(self): for x in range(self.port_start, self.port_end + 1): if x < self.cpldb_sfp_num: - self.port_to_i2c_mapping.update({x:7}) + self.port_to_i2c_mapping.update({x: 7}) elif x < self.cplda_sfp_num + self.cpldb_sfp_num: - self.port_to_i2c_mapping.update({x:6}) + self.port_to_i2c_mapping.update({x: 6}) else: - self.port_to_i2c_mapping.update({x:8}) + self.port_to_i2c_mapping.update({x: 8}) for x in range(self.port_start, self.port_end+1): eeprom_path = '/sys/bus/i2c/devices/{0}-0050/sfp'+str(x+1)+'_eeprom' @@ -40,7 +37,6 @@ def __init__(self): self.port_to_eeprom_mapping[x] = port_eeprom_path SfpUtilBase.__init__(self) - def get_presence(self, port_num): if port_num < self.port_start or port_num > self.port_end: return False @@ -51,11 +47,11 @@ def get_presence(self, port_num): presence_path = '/sys/bus/i2c/devices/6-0074/sfp'+str(port_num+1)+'_present' else: presence_path = '/sys/bus/i2c/devices/8-0076/sfp'+str(port_num+1)+'_present' - + try: file = open(presence_path) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False value = int(file.readline().rstrip()) @@ -71,11 +67,11 @@ def get_low_power_mode(self, port_num): return False lowpower_path = '/sys/bus/i2c/devices/8-0076/sfp'+str(port_num+1)+'_lowpower' - + try: file = open(lowpower_path) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False value = int(file.readline().rstrip()) @@ -101,7 +97,7 @@ def set_low_power_mode(self, port_num, lpmode): try: file = open(lowpower_path, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False file.seek(0) @@ -118,7 +114,7 @@ def reset(self, port_num): try: file = open(reset_path, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False file.seek(0) @@ -131,7 +127,7 @@ def reset(self, port_num): try: file = open(reset_path, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False file.seek(0) @@ -233,6 +229,3 @@ def read_porttab_mappings(self, porttabfile): print "logical to physical: " + self.logical_to_physical print "physical to logical: " + self.physical_to_logical """ - - - diff --git a/device/quanta/x86_64-quanta_ix1b_rglbmc-r0/plugins/eeprom.py b/device/quanta/x86_64-quanta_ix1b_rglbmc-r0/plugins/eeprom.py index 989f7fe50794..ddefcf8877fb 100755 --- a/device/quanta/x86_64-quanta_ix1b_rglbmc-r0/plugins/eeprom.py +++ b/device/quanta/x86_64-quanta_ix1b_rglbmc-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,11 +8,13 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/22-0054/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/quanta/x86_64-quanta_ix1b_rglbmc-r0/plugins/psuutil.py b/device/quanta/x86_64-quanta_ix1b_rglbmc-r0/plugins/psuutil.py index 1986aa846c5e..0b2027afdda4 100755 --- a/device/quanta/x86_64-quanta_ix1b_rglbmc-r0/plugins/psuutil.py +++ b/device/quanta/x86_64-quanta_ix1b_rglbmc-r0/plugins/psuutil.py @@ -15,64 +15,73 @@ DEBUG = False + def show_log(txt): if DEBUG == True: print("[IX2]"+txt) return + def exec_cmd(cmd, show): logging.info('Run :'+cmd) try: - output = subprocess.check_output(cmd, shell=True) - show_log (cmd +"output:"+str(output)) + output = subprocess.check_output(cmd, shell=True, universal_newlines=True) + show_log(cmd + "output:"+str(output)) except subprocess.CalledProcessError as e: logging.info("Failed :"+cmd) if show: - print("Failed :"+cmd +"returncode = {}, err msg: {}".format(e.returncode, e.output)) - return output + print("Failed :"+cmd + "returncode = {}, err msg: {}".format(e.returncode, e.output)) + return output + def my_log(txt): if DEBUG == True: print("[QUANTA DBG]: "+txt) return + def log_os_system(cmd, show): logging.info('Run :'+cmd) status = 1 output = "" try: - output = subprocess.check_output(cmd, shell=True) - my_log (cmd +"output:"+str(output)) + output = subprocess.check_output(cmd, shell=True, universal_newlines=True) + my_log(cmd + "output:"+str(output)) except subprocess.CalledProcessError as e: logging.info('Failed :'+cmd) if show: - print("Failed :"+cmd +"returncode = {}, err msg: {}".format(e.returncode, e.output)) - return output + print("Failed :"+cmd + "returncode = {}, err msg: {}".format(e.returncode, e.output)) + return output + def gpio16_exist(): ls = log_os_system("ls /sys/class/gpio/ | grep gpio16", 0) logging.info('mods:'+ls) - if len(ls) ==0: + if len(ls) == 0: return False + def gpio17_exist(): ls = log_os_system("ls /sys/class/gpio/ | grep gpio17", 0) logging.info('mods:'+ls) - if len(ls) ==0: + if len(ls) == 0: return False + def gpio19_exist(): ls = log_os_system("ls /sys/class/gpio/ | grep gpio19", 0) logging.info('mods:'+ls) - if len(ls) ==0: + if len(ls) == 0: return False + def gpio20_exist(): ls = log_os_system("ls /sys/class/gpio/ | grep gpio20", 0) logging.info('mods:'+ls) - if len(ls) ==0: + if len(ls) == 0: return False + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" @@ -81,6 +90,7 @@ class PsuUtil(PsuBase): SYSFS_PSU_POWERGOOD_DIR = ["/sys/class/gpio/gpio17", "/sys/class/gpio/gpio20"] + def __init__(self): PsuBase.__init__(self) @@ -134,7 +144,7 @@ def get_psu_status(self, index): """ status = 0 attr_file = 'value' - attr_path = self.SYSFS_PSU_POWERGOOD_DIR[index-1] +'/' + attr_file + attr_path = self.SYSFS_PSU_POWERGOOD_DIR[index-1] + '/' + attr_file attr_value = self.get_attr_value(attr_path) @@ -142,7 +152,7 @@ def get_psu_status(self, index): attr_value = int(attr_value, 16) # Check for PSU status if (attr_value == 1): - status = 1 + status = 1 return status @@ -155,8 +165,8 @@ def get_psu_presence(self, index): """ status = 0 psu_absent = 0 - attr_file ='value' - attr_path = self.SYSFS_PSU_PRESENT_DIR[index-1] +'/' + attr_file + attr_file = 'value' + attr_path = self.SYSFS_PSU_PRESENT_DIR[index-1] + '/' + attr_file attr_value = self.get_attr_value(attr_path) @@ -164,7 +174,6 @@ def get_psu_presence(self, index): attr_value = int(attr_value, 16) # Check for PSU presence if (attr_value == 0): - status = 1 + status = 1 return status - diff --git a/device/quanta/x86_64-quanta_ix1b_rglbmc-r0/plugins/sfputil.py b/device/quanta/x86_64-quanta_ix1b_rglbmc-r0/plugins/sfputil.py index 851f4b90277d..cbaf8b71832f 100755 --- a/device/quanta/x86_64-quanta_ix1b_rglbmc-r0/plugins/sfputil.py +++ b/device/quanta/x86_64-quanta_ix1b_rglbmc-r0/plugins/sfputil.py @@ -1,10 +1,8 @@ -#!/usr/bin/env python - try: import time - from sonic_sfp.sfputilbase import SfpUtilBase -except ImportError, e: - raise ImportError (str(e) + "- required module not found") + from sonic_sfp.sfputilbase import SfpUtilBase +except ImportError as e: + raise ImportError(str(e) + "- required module not found") class SfpUtil(SfpUtilBase): @@ -16,41 +14,41 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} port_to_i2c_mapping = { - 1 : 32, - 2 : 33, - 3 : 34, - 4 : 35, - 5 : 36, - 6 : 37, - 7 : 38, - 8 : 39, - 9 : 40, - 10 : 41, - 11 : 42, - 12 : 43, - 13 : 44, - 14 : 45, - 15 : 46, - 16 : 47, - 17 : 48, - 18 : 49, - 19 : 50, - 20 : 51, - 21 : 52, - 22 : 53, - 23 : 54, - 24 : 55, - 25 : 56, - 26 : 57, - 27 : 58, - 28 : 59, - 29 : 60, - 30 : 61, - 31 : 62, - 32 : 63, + 1: 32, + 2: 33, + 3: 34, + 4: 35, + 5: 36, + 6: 37, + 7: 38, + 8: 39, + 9: 40, + 10: 41, + 11: 42, + 12: 43, + 13: 44, + 14: 45, + 15: 46, + 16: 47, + 17: 48, + 18: 49, + 19: 50, + 20: 51, + 21: 52, + 22: 53, + 23: 54, + 24: 55, + 25: 56, + 26: 57, + 27: 58, + 28: 59, + 29: 60, + 30: 61, + 31: 62, + 32: 63, } - _qsfp_ports = range(0, ports_in_block + 1) + _qsfp_ports = list(range(0, ports_in_block + 1)) def __init__(self): eeprom_path = '/sys/bus/i2c/devices/{0}-0050/eeprom' @@ -67,7 +65,7 @@ def reset(self, port_num): try: reg_file = open("/sys/class/cpld-qsfp28/port-"+str(port_num+1)+"/reset", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 0 @@ -81,7 +79,7 @@ def reset(self, port_num): try: reg_file = open("/sys/class/cpld-qsfp28/port-"+str(port_num+1)+"/reset", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 1 @@ -91,14 +89,14 @@ def reset(self, port_num): return True def set_low_power_mode(self, port_num, lpmode): - # Check for invalid port_num + # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False try: reg_file = open("/sys/class/cpld-qsfp28/port-"+str(port_num+1)+"/lpmode", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = int(reg_file.readline().rstrip()) @@ -115,14 +113,14 @@ def set_low_power_mode(self, port_num, lpmode): return True def get_low_power_mode(self, port_num): - # Check for invalid port_num + # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False try: reg_file = open("/sys/class/cpld-qsfp28/port-"+str(port_num+1)+"/lpmode") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = int(reg_file.readline().rstrip()) @@ -131,7 +129,7 @@ def get_low_power_mode(self, port_num): return False return True - + def get_presence(self, port_num): # Check for invalid port_num if port_num < self._port_start or port_num > self._port_end: @@ -139,11 +137,11 @@ def get_presence(self, port_num): #path = "/sys/class/cpld-qsfp28/port-{0}/module_present" #port_ps = path.format(self.port_to_i2c_mapping[port_num+1]) - + try: reg_file = open("/sys/class/cpld-qsfp28/port-"+str(port_num+1)+"/module_present") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_file.readline().rstrip() @@ -159,14 +157,14 @@ def port_start(self): @property def port_end(self): return self._port_end - + @property def qsfp_ports(self): - return range(0, self.ports_in_block + 1) + return list(range(0, self.ports_in_block + 1)) - @property + @property def port_to_eeprom_mapping(self): - return self._port_to_eeprom_mapping + return self._port_to_eeprom_mapping def get_transceiver_change_event(self): """ @@ -175,5 +173,3 @@ def get_transceiver_change_event(self): on this platform. """ raise NotImplementedError - - diff --git a/device/quanta/x86_64-quanta_ix7_rglbmc-r0/plugins/eeprom.py b/device/quanta/x86_64-quanta_ix7_rglbmc-r0/plugins/eeprom.py index 2a35f3a22a17..fa34110c04ea 100644 --- a/device/quanta/x86_64-quanta_ix7_rglbmc-r0/plugins/eeprom.py +++ b/device/quanta/x86_64-quanta_ix7_rglbmc-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,11 +8,13 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/18-0054/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/quanta/x86_64-quanta_ix7_rglbmc-r0/plugins/psuutil.py b/device/quanta/x86_64-quanta_ix7_rglbmc-r0/plugins/psuutil.py index 885842bbda5a..5cf06fb5d66a 100644 --- a/device/quanta/x86_64-quanta_ix7_rglbmc-r0/plugins/psuutil.py +++ b/device/quanta/x86_64-quanta_ix7_rglbmc-r0/plugins/psuutil.py @@ -8,7 +8,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/quanta/x86_64-quanta_ix7_rglbmc-r0/plugins/sfputil.py b/device/quanta/x86_64-quanta_ix7_rglbmc-r0/plugins/sfputil.py index 85a4aad26dae..14b0ef6674be 100644 --- a/device/quanta/x86_64-quanta_ix7_rglbmc-r0/plugins/sfputil.py +++ b/device/quanta/x86_64-quanta_ix7_rglbmc-r0/plugins/sfputil.py @@ -21,38 +21,38 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} _port_to_i2c_mapping = { - 1 : 32, - 2 : 33, - 3 : 34, - 4 : 35, - 5 : 36, - 6 : 37, - 7 : 38, - 8 : 39, - 9 : 40, - 10 : 41, - 11 : 42, - 12 : 43, - 13 : 44, - 14 : 45, - 15 : 46, - 16 : 47, - 17 : 48, - 18 : 49, - 19 : 50, - 20 : 51, - 21 : 52, - 22 : 53, - 23 : 54, - 24 : 55, - 25 : 56, - 26 : 57, - 27 : 58, - 28 : 59, - 29 : 60, - 30 : 61, - 31 : 62, - 32 : 63, + 1: 32, + 2: 33, + 3: 34, + 4: 35, + 5: 36, + 6: 37, + 7: 38, + 8: 39, + 9: 40, + 10: 41, + 11: 42, + 12: 43, + 13: 44, + 14: 45, + 15: 46, + 16: 47, + 17: 48, + 18: 49, + 19: 50, + 20: 51, + 21: 52, + 22: 53, + 23: 54, + 24: 55, + 25: 56, + 26: 57, + 27: 58, + 28: 59, + 29: 60, + 30: 61, + 31: 62, + 32: 63, } @property @@ -65,11 +65,11 @@ def port_end(self): @property def qsfp_ports(self): - return range(self.PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): - return self._port_to_eeprom_mapping + return self._port_to_eeprom_mapping def __init__(self): eeprom_path = '/sys/bus/i2c/devices/{0}-0050/eeprom' @@ -85,7 +85,7 @@ def get_presence(self, port_num): try: reg_file = open("/sys/class/cpld-qsfp28/port-"+str(port_num)+"/module_present") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_file.readline().rstrip() @@ -102,7 +102,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open("/sys/class/cpld-qsfp28/port-"+str(port_num)+"/lpmode") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = int(reg_file.readline().rstrip()) @@ -120,7 +120,7 @@ def set_low_power_mode(self, port_num, lpmode): try: reg_file = open("/sys/class/cpld-qsfp28/port-"+str(port_num)+"/lpmode", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = int(reg_file.readline().rstrip()) @@ -144,7 +144,7 @@ def reset(self, port_num): try: reg_file = open("/sys/class/cpld-qsfp28/port-"+str(port_num)+"/reset", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 0 @@ -158,7 +158,7 @@ def reset(self, port_num): try: reg_file = open("/sys/class/cpld-qsfp28/port-"+str(port_num)+"/reset", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 1 diff --git a/device/quanta/x86_64-quanta_ix8_rglbmc-r0/plugins/eeprom.py b/device/quanta/x86_64-quanta_ix8_rglbmc-r0/plugins/eeprom.py index 2a35f3a22a17..fa34110c04ea 100644 --- a/device/quanta/x86_64-quanta_ix8_rglbmc-r0/plugins/eeprom.py +++ b/device/quanta/x86_64-quanta_ix8_rglbmc-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,11 +8,13 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/18-0054/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/quanta/x86_64-quanta_ix8_rglbmc-r0/plugins/psuutil.py b/device/quanta/x86_64-quanta_ix8_rglbmc-r0/plugins/psuutil.py index 885842bbda5a..5cf06fb5d66a 100644 --- a/device/quanta/x86_64-quanta_ix8_rglbmc-r0/plugins/psuutil.py +++ b/device/quanta/x86_64-quanta_ix8_rglbmc-r0/plugins/psuutil.py @@ -8,7 +8,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/quanta/x86_64-quanta_ix8_rglbmc-r0/plugins/sfputil.py b/device/quanta/x86_64-quanta_ix8_rglbmc-r0/plugins/sfputil.py index 627c99fee0c9..3067919795d5 100644 --- a/device/quanta/x86_64-quanta_ix8_rglbmc-r0/plugins/sfputil.py +++ b/device/quanta/x86_64-quanta_ix8_rglbmc-r0/plugins/sfputil.py @@ -23,62 +23,62 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} _port_to_i2c_mapping = { - 1 : 32, - 2 : 33, - 3 : 34, - 4 : 35, - 5 : 36, - 6 : 37, - 7 : 38, - 8 : 39, - 9 : 40, - 10 : 41, - 11 : 42, - 12 : 43, - 13 : 44, - 14 : 45, - 15 : 46, - 16 : 47, - 17 : 48, - 18 : 49, - 19 : 50, - 20 : 51, - 21 : 52, - 22 : 53, - 23 : 54, - 24 : 55, - 25 : 56, - 26 : 57, - 27 : 58, - 28 : 59, - 29 : 60, - 30 : 61, - 31 : 62, - 32 : 63, - 33 : 64, - 34 : 65, - 35 : 66, - 36 : 67, - 37 : 68, - 38 : 69, - 39 : 70, - 40 : 71, - 41 : 72, - 42 : 73, - 43 : 74, - 44 : 75, - 45 : 76, - 46 : 77, - 47 : 78, - 48 : 79, - 49 : 80,#QSFP49 - 50 : 81,#QSFP50 - 51 : 82,#QSFP51 - 52 : 83,#QSFP52 - 53 : 84,#QSFP53 - 54 : 85,#QSFP54 - 55 : 86,#QSFP55 - 56 : 87,#QSFP56 + 1: 32, + 2: 33, + 3: 34, + 4: 35, + 5: 36, + 6: 37, + 7: 38, + 8: 39, + 9: 40, + 10: 41, + 11: 42, + 12: 43, + 13: 44, + 14: 45, + 15: 46, + 16: 47, + 17: 48, + 18: 49, + 19: 50, + 20: 51, + 21: 52, + 22: 53, + 23: 54, + 24: 55, + 25: 56, + 26: 57, + 27: 58, + 28: 59, + 29: 60, + 30: 61, + 31: 62, + 32: 63, + 33: 64, + 34: 65, + 35: 66, + 36: 67, + 37: 68, + 38: 69, + 39: 70, + 40: 71, + 41: 72, + 42: 73, + 43: 74, + 44: 75, + 45: 76, + 46: 77, + 47: 78, + 48: 79, + 49: 80, # QSFP49 + 50: 81, # QSFP50 + 51: 82, # QSFP51 + 52: 83, # QSFP52 + 53: 84, # QSFP53 + 54: 85, # QSFP54 + 55: 86, # QSFP55 + 56: 87, # QSFP56 } @property @@ -99,11 +99,11 @@ def qsfp_port_end(self): @property def qsfp_ports(self): - return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): - return self._port_to_eeprom_mapping + return self._port_to_eeprom_mapping def __init__(self): eeprom_path = '/sys/bus/i2c/devices/{0}-0050/eeprom' @@ -122,7 +122,7 @@ def get_presence(self, port_num): else: reg_file = open("/sys/class/gpio/gpio"+str((port_num-self.qsfp_port_start)*4+34)+"/value") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_file.readline().rstrip() @@ -143,7 +143,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open("/sys/class/gpio/gpio"+str((port_num-self.qsfp_port_start)*4+35)+"/value") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = int(reg_file.readline().rstrip()) @@ -161,7 +161,7 @@ def set_low_power_mode(self, port_num, lpmode): try: reg_file = open("/sys/class/gpio/gpio"+str((port_num-self.qsfp_port_start)*4+35)+"/value", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = int(reg_file.readline().rstrip()) @@ -185,7 +185,7 @@ def reset(self, port_num): try: reg_file = open("/sys/class/gpio/gpio"+str((port_num-self.qsfp_port_start)*4+32)+"/value", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 0 @@ -199,7 +199,7 @@ def reset(self, port_num): try: reg_file = open("/sys/class/gpio/gpio"+str((port_num-self.qsfp_port_start)*4+32)+"/value", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 1 diff --git a/device/quanta/x86_64-quanta_ix8c_bwde-r0/plugins/eeprom.py b/device/quanta/x86_64-quanta_ix8c_bwde-r0/plugins/eeprom.py index 2a35f3a22a17..fa34110c04ea 100644 --- a/device/quanta/x86_64-quanta_ix8c_bwde-r0/plugins/eeprom.py +++ b/device/quanta/x86_64-quanta_ix8c_bwde-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,11 +8,13 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/18-0054/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/quanta/x86_64-quanta_ix8c_bwde-r0/plugins/psuutil.py b/device/quanta/x86_64-quanta_ix8c_bwde-r0/plugins/psuutil.py index cc9be248aa1b..319c35d490e4 100644 --- a/device/quanta/x86_64-quanta_ix8c_bwde-r0/plugins/psuutil.py +++ b/device/quanta/x86_64-quanta_ix8c_bwde-r0/plugins/psuutil.py @@ -8,7 +8,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/quanta/x86_64-quanta_ix8c_bwde-r0/plugins/sfputil.py b/device/quanta/x86_64-quanta_ix8c_bwde-r0/plugins/sfputil.py index 627c99fee0c9..3067919795d5 100644 --- a/device/quanta/x86_64-quanta_ix8c_bwde-r0/plugins/sfputil.py +++ b/device/quanta/x86_64-quanta_ix8c_bwde-r0/plugins/sfputil.py @@ -23,62 +23,62 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} _port_to_i2c_mapping = { - 1 : 32, - 2 : 33, - 3 : 34, - 4 : 35, - 5 : 36, - 6 : 37, - 7 : 38, - 8 : 39, - 9 : 40, - 10 : 41, - 11 : 42, - 12 : 43, - 13 : 44, - 14 : 45, - 15 : 46, - 16 : 47, - 17 : 48, - 18 : 49, - 19 : 50, - 20 : 51, - 21 : 52, - 22 : 53, - 23 : 54, - 24 : 55, - 25 : 56, - 26 : 57, - 27 : 58, - 28 : 59, - 29 : 60, - 30 : 61, - 31 : 62, - 32 : 63, - 33 : 64, - 34 : 65, - 35 : 66, - 36 : 67, - 37 : 68, - 38 : 69, - 39 : 70, - 40 : 71, - 41 : 72, - 42 : 73, - 43 : 74, - 44 : 75, - 45 : 76, - 46 : 77, - 47 : 78, - 48 : 79, - 49 : 80,#QSFP49 - 50 : 81,#QSFP50 - 51 : 82,#QSFP51 - 52 : 83,#QSFP52 - 53 : 84,#QSFP53 - 54 : 85,#QSFP54 - 55 : 86,#QSFP55 - 56 : 87,#QSFP56 + 1: 32, + 2: 33, + 3: 34, + 4: 35, + 5: 36, + 6: 37, + 7: 38, + 8: 39, + 9: 40, + 10: 41, + 11: 42, + 12: 43, + 13: 44, + 14: 45, + 15: 46, + 16: 47, + 17: 48, + 18: 49, + 19: 50, + 20: 51, + 21: 52, + 22: 53, + 23: 54, + 24: 55, + 25: 56, + 26: 57, + 27: 58, + 28: 59, + 29: 60, + 30: 61, + 31: 62, + 32: 63, + 33: 64, + 34: 65, + 35: 66, + 36: 67, + 37: 68, + 38: 69, + 39: 70, + 40: 71, + 41: 72, + 42: 73, + 43: 74, + 44: 75, + 45: 76, + 46: 77, + 47: 78, + 48: 79, + 49: 80, # QSFP49 + 50: 81, # QSFP50 + 51: 82, # QSFP51 + 52: 83, # QSFP52 + 53: 84, # QSFP53 + 54: 85, # QSFP54 + 55: 86, # QSFP55 + 56: 87, # QSFP56 } @property @@ -99,11 +99,11 @@ def qsfp_port_end(self): @property def qsfp_ports(self): - return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): - return self._port_to_eeprom_mapping + return self._port_to_eeprom_mapping def __init__(self): eeprom_path = '/sys/bus/i2c/devices/{0}-0050/eeprom' @@ -122,7 +122,7 @@ def get_presence(self, port_num): else: reg_file = open("/sys/class/gpio/gpio"+str((port_num-self.qsfp_port_start)*4+34)+"/value") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_file.readline().rstrip() @@ -143,7 +143,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open("/sys/class/gpio/gpio"+str((port_num-self.qsfp_port_start)*4+35)+"/value") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = int(reg_file.readline().rstrip()) @@ -161,7 +161,7 @@ def set_low_power_mode(self, port_num, lpmode): try: reg_file = open("/sys/class/gpio/gpio"+str((port_num-self.qsfp_port_start)*4+35)+"/value", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = int(reg_file.readline().rstrip()) @@ -185,7 +185,7 @@ def reset(self, port_num): try: reg_file = open("/sys/class/gpio/gpio"+str((port_num-self.qsfp_port_start)*4+32)+"/value", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 0 @@ -199,7 +199,7 @@ def reset(self, port_num): try: reg_file = open("/sys/class/gpio/gpio"+str((port_num-self.qsfp_port_start)*4+32)+"/value", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 1 diff --git a/device/quanta/x86_64-quanta_ix9_bwde-r0/plugins/eeprom.py b/device/quanta/x86_64-quanta_ix9_bwde-r0/plugins/eeprom.py index 2a35f3a22a17..fa34110c04ea 100644 --- a/device/quanta/x86_64-quanta_ix9_bwde-r0/plugins/eeprom.py +++ b/device/quanta/x86_64-quanta_ix9_bwde-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,11 +8,13 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/18-0054/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/quanta/x86_64-quanta_ix9_bwde-r0/plugins/psuutil.py b/device/quanta/x86_64-quanta_ix9_bwde-r0/plugins/psuutil.py index 885842bbda5a..5cf06fb5d66a 100644 --- a/device/quanta/x86_64-quanta_ix9_bwde-r0/plugins/psuutil.py +++ b/device/quanta/x86_64-quanta_ix9_bwde-r0/plugins/psuutil.py @@ -8,7 +8,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/quanta/x86_64-quanta_ix9_bwde-r0/plugins/sfputil.py b/device/quanta/x86_64-quanta_ix9_bwde-r0/plugins/sfputil.py index 6dc23d8195f4..832dac4e0570 100644 --- a/device/quanta/x86_64-quanta_ix9_bwde-r0/plugins/sfputil.py +++ b/device/quanta/x86_64-quanta_ix9_bwde-r0/plugins/sfputil.py @@ -1,10 +1,8 @@ -#!/usr/bin/env python - try: import time - from sonic_sfp.sfputilbase import SfpUtilBase -except ImportError, e: - raise ImportError (str(e) + "- required module not found") + from sonic_sfp.sfputilbase import SfpUtilBase +except ImportError as e: + raise ImportError(str(e) + "- required module not found") class SfpUtil(SfpUtilBase): @@ -16,41 +14,41 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} port_to_i2c_mapping = { - 1 : 32, - 2 : 33, - 3 : 34, - 4 : 35, - 5 : 36, - 6 : 37, - 7 : 38, - 8 : 39, - 9 : 40, - 10 : 41, - 11 : 42, - 12 : 43, - 13 : 44, - 14 : 45, - 15 : 46, - 16 : 47, - 17 : 48, - 18 : 49, - 19 : 50, - 20 : 51, - 21 : 52, - 22 : 53, - 23 : 54, - 24 : 55, - 25 : 56, - 26 : 57, - 27 : 58, - 28 : 59, - 29 : 60, - 30 : 61, - 31 : 62, - 32 : 63, + 1: 32, + 2: 33, + 3: 34, + 4: 35, + 5: 36, + 6: 37, + 7: 38, + 8: 39, + 9: 40, + 10: 41, + 11: 42, + 12: 43, + 13: 44, + 14: 45, + 15: 46, + 16: 47, + 17: 48, + 18: 49, + 19: 50, + 20: 51, + 21: 52, + 22: 53, + 23: 54, + 24: 55, + 25: 56, + 26: 57, + 27: 58, + 28: 59, + 29: 60, + 30: 61, + 31: 62, + 32: 63, } - _qsfp_ports = range(0, ports_in_block + 1) + _qsfp_ports = list(range(0, ports_in_block + 1)) def __init__(self): eeprom_path = '/sys/bus/i2c/devices/{0}-0050/eeprom' @@ -67,7 +65,7 @@ def reset(self, port_num): try: reg_file = open("/sys/class/cpld-qsfpdd/port-"+str(port_num+1)+"/reset", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 0 @@ -81,7 +79,7 @@ def reset(self, port_num): try: reg_file = open("/sys/class/cpld-qsfpdd/port-"+str(port_num+1)+"/reset", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 1 @@ -91,14 +89,14 @@ def reset(self, port_num): return True def set_low_power_mode(self, port_num, lpmode): - # Check for invalid port_num + # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False try: reg_file = open("/sys/class/cpld-qsfpdd/port-"+str(port_num+1)+"/lpmode", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = int(reg_file.readline().rstrip()) @@ -115,14 +113,14 @@ def set_low_power_mode(self, port_num, lpmode): return True def get_low_power_mode(self, port_num): - # Check for invalid port_num + # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False try: reg_file = open("/sys/class/cpld-qsfpdd/port-"+str(port_num+1)+"/lpmode") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = int(reg_file.readline().rstrip()) @@ -131,16 +129,16 @@ def get_low_power_mode(self, port_num): return False return True - + def get_presence(self, port_num): # Check for invalid port_num if port_num < self._port_start or port_num > self._port_end: return False - + try: reg_file = open("/sys/class/cpld-qsfpdd/port-"+str(port_num+1)+"/module_present") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_file.readline().rstrip() @@ -156,14 +154,14 @@ def port_start(self): @property def port_end(self): return self._port_end - + @property def qsfp_ports(self): - return range(0, self.ports_in_block + 1) + return list(range(0, self.ports_in_block + 1)) - @property + @property def port_to_eeprom_mapping(self): - return self._port_to_eeprom_mapping + return self._port_to_eeprom_mapping def get_transceiver_change_event(self): """ @@ -172,5 +170,3 @@ def get_transceiver_change_event(self): on this platform. """ raise NotImplementedError - - diff --git a/device/virtual/x86_64-kvm_x86_64-r0/plugins/eeprom.py b/device/virtual/x86_64-kvm_x86_64-r0/plugins/eeprom.py index 5cc8cb68018f..163c31ba20fc 100644 --- a/device/virtual/x86_64-kvm_x86_64-r0/plugins/eeprom.py +++ b/device/virtual/x86_64-kvm_x86_64-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # SONiC Virtual switch platform # @@ -18,7 +16,7 @@ def is_checksum_valid(self, e): def read_eeprom(self): return \ -""" + """ TLV Name Code Len Value -------------------- ---- --- ----- Product Name 0x21 5 SONiC @@ -35,7 +33,7 @@ def read_eeprom(self): """ def decode_eeprom(self, e): - print e + print(e) def serial_number_str(self, e): """Return service tag instead of serial number""" diff --git a/device/wnc/x86_64-wnc_osw1800-r0/plugins/eeprom.py b/device/wnc/x86_64-wnc_osw1800-r0/plugins/eeprom.py index a073374794fa..7c36371812ae 100644 --- a/device/wnc/x86_64-wnc_osw1800-r0/plugins/eeprom.py +++ b/device/wnc/x86_64-wnc_osw1800-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -10,8 +7,8 @@ import sys from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): @@ -19,4 +16,3 @@ class board(eeprom_tlvinfo.TlvInfoDecoder): def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/class/i2c-adapter/i2c-8/8-0052/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) - diff --git a/device/wnc/x86_64-wnc_osw1800-r0/plugins/sfputil.py b/device/wnc/x86_64-wnc_osw1800-r0/plugins/sfputil.py index 549790bfb44f..ebb3d1c9bfa7 100644 --- a/device/wnc/x86_64-wnc_osw1800-r0/plugins/sfputil.py +++ b/device/wnc/x86_64-wnc_osw1800-r0/plugins/sfputil.py @@ -12,7 +12,7 @@ from sff8472 import sff8472Dom from sff8436 import sff8436InterfaceId from sff8436 import sff8436Dom -except ImportError, e: +except ImportError as e: raise ImportError("%s - required module not found" % str(e)) @@ -37,7 +37,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(self.PORT_START + 48, self.PORTS_IN_BLOCK) + return list(range(self.PORT_START + 48, self.PORTS_IN_BLOCK)) @property def port_to_eeprom_mapping(self): @@ -77,7 +77,7 @@ def get_presence(self, port_num): try: reg_file = open(presence_path, "rb") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -98,7 +98,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open("/sys/bus/i2c/devices/4-0032/qsfp_lpmode") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) content = reg_file.readline().rstrip() reg_value = int(content, 16) @@ -118,7 +118,7 @@ def set_low_power_mode(self, port_num, lpmode): try: reg_file = open("/sys/bus/i2c/devices/4-0032/qsfp_lpmode", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -144,7 +144,7 @@ def reset(self, port_num): try: reg_file = open("/sys/bus/i2c/devices/4-0032/reset_control", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -160,7 +160,7 @@ def reset(self, port_num): try: reg_file = open("/sys/bus/i2c/devices/4-0032/reset_control", "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_value | (1 << bit_mask) diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index 82fb75d6c058..461c629284e7 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -144,12 +144,26 @@ sudo cp {{sonic_py_common_py3_wheel_path}} $FILESYSTEM_ROOT/$SONIC_PY_COMMON_PY3 sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip3 install $SONIC_PY_COMMON_PY3_WHEEL_NAME sudo rm -rf $FILESYSTEM_ROOT/$SONIC_PY_COMMON_PY3_WHEEL_NAME -# Install SONiC config engine Python package +# Install SONiC config engine Python 2 package CONFIG_ENGINE_PY2_WHEEL_NAME=$(basename {{config_engine_py2_wheel_path}}) sudo cp {{config_engine_py2_wheel_path}} $FILESYSTEM_ROOT/$CONFIG_ENGINE_PY2_WHEEL_NAME sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip2 install $CONFIG_ENGINE_PY2_WHEEL_NAME sudo rm -rf $FILESYSTEM_ROOT/$CONFIG_ENGINE_PY2_WHEEL_NAME +# For sonic-config-engine Python 3 package +# Install pyangbind here, outside sonic-config-engine dependencies, as pyangbind causes enum34 to be installed. +# Then immediately uninstall enum34, as enum34 should not be installed for Python >= 3.4, as it causes a +# conflict with the new 'enum' module in the standard library +# https://github.com/robshakir/pyangbind/issues/232 +sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip3 install pyangbind==0.8.1 +sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip3 uninstall -y enum34 + +# Install SONiC config engine Python 3 package +CONFIG_ENGINE_PY3_WHEEL_NAME=$(basename {{config_engine_py3_wheel_path}}) +sudo cp {{config_engine_py3_wheel_path}} $FILESYSTEM_ROOT/$CONFIG_ENGINE_PY3_WHEEL_NAME +sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip3 install $CONFIG_ENGINE_PY3_WHEEL_NAME +sudo rm -rf $FILESYSTEM_ROOT/$CONFIG_ENGINE_PY3_WHEEL_NAME + # Install sonic-yang-models py3 package, install dependencies sudo dpkg --root=$FILESYSTEM_ROOT -i $debs_path/libyang_*.deb sudo dpkg --root=$FILESYSTEM_ROOT -i $debs_path/libyang-cpp_*.deb @@ -205,11 +219,11 @@ sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y in # Install prerequisites needed for using the Python m2crypto package, used by sonic-utilities sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y install openssl -# Install SONiC Utilities Python 2 package -SONIC_UTILITIES_PY2_WHEEL_NAME=$(basename {{sonic_utilities_py2_wheel_path}}) -sudo cp {{sonic_utilities_py2_wheel_path}} $FILESYSTEM_ROOT/$SONIC_UTILITIES_PY2_WHEEL_NAME -sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip2 install $SONIC_UTILITIES_PY2_WHEEL_NAME -sudo rm -rf $FILESYSTEM_ROOT/$SONIC_UTILITIES_PY2_WHEEL_NAME +# Install SONiC Utilities Python package +SONIC_UTILITIES_PY3_WHEEL_NAME=$(basename {{sonic_utilities_py3_wheel_path}}) +sudo cp {{sonic_utilities_py3_wheel_path}} $FILESYSTEM_ROOT/$SONIC_UTILITIES_PY3_WHEEL_NAME +sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip3 install $SONIC_UTILITIES_PY3_WHEEL_NAME +sudo rm -rf $FILESYSTEM_ROOT/$SONIC_UTILITIES_PY3_WHEEL_NAME # Install sonic-utilities data files (and any dependencies via 'apt-get -y install -f') sudo dpkg --root=$FILESYSTEM_ROOT -i $debs_path/sonic-utilities-data_*.deb || \ diff --git a/platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform/eeprom.py b/platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform/eeprom.py index a1ebe5f224a9..e25d224c1e8b 100644 --- a/platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform/eeprom.py +++ b/platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform/eeprom.py @@ -1,6 +1,3 @@ -#!/usr/bin/python - - try: import os import sys @@ -12,12 +9,16 @@ sys.path.append(os.path.dirname(__file__)) - from cStringIO import StringIO + if sys.version_info.major == 3: + from io import StringIO + else: + from cStringIO import StringIO + from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo from .platform_thrift_client import thrift_try -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") diff --git a/platform/broadcom/sonic-platform-modules-cel/services/platform_api/sonic_platform/eeprom.py b/platform/broadcom/sonic-platform-modules-cel/services/platform_api/sonic_platform/eeprom.py index 53306c003474..7756c0f2f839 100644 --- a/platform/broadcom/sonic-platform-modules-cel/services/platform_api/sonic_platform/eeprom.py +++ b/platform/broadcom/sonic-platform-modules-cel/services/platform_api/sonic_platform/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # @@ -13,9 +11,14 @@ import os import sys import re - from cStringIO import StringIO + + if sys.version_info.major == 3: + from io import StringIO + else: + from cStringIO import StringIO + from sonic_platform_base.sonic_eeprom import eeprom_tlvinfo -except ImportError, e: +except ImportError as e: raise ImportError(str(e) + "- required module not found") CACHE_ROOT = '/var/cache/sonic/decode-syseeprom' diff --git a/platform/broadcom/sonic-platform-modules-inventec/d6332/sonic_platform/eeprom.py b/platform/broadcom/sonic-platform-modules-inventec/d6332/sonic_platform/eeprom.py index 3995bc70fd5b..0d210b47beb2 100644 --- a/platform/broadcom/sonic-platform-modules-inventec/d6332/sonic_platform/eeprom.py +++ b/platform/broadcom/sonic-platform-modules-inventec/d6332/sonic_platform/eeprom.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # # Name: eeprom.py, version: 1.0 # @@ -7,7 +6,7 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ( ImportError, e ): +except ImportError as e: raise ImportError(str(e) + "- required module not found") EEPROM_TOTAL_LEN_HIGH_OFFSET = 9 diff --git a/platform/broadcom/sonic-platform-modules-inventec/d6356/sonic_platform/eeprom.py b/platform/broadcom/sonic-platform-modules-inventec/d6356/sonic_platform/eeprom.py index 5840246fddc2..ef0d6385534e 100644 --- a/platform/broadcom/sonic-platform-modules-inventec/d6356/sonic_platform/eeprom.py +++ b/platform/broadcom/sonic-platform-modules-inventec/d6356/sonic_platform/eeprom.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # # Name: eeprom.py, version: 1.0 # @@ -8,7 +7,7 @@ try: from sonic_eeprom import eeprom_tlvinfo import binascii -except ImportError, e: +except ImportError as e: raise ImportError(str(e) + "- required module not found") class Eeprom(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/platform/broadcom/sonic-platform-modules-inventec/d7054q28b/sonic_platform/eeprom.py b/platform/broadcom/sonic-platform-modules-inventec/d7054q28b/sonic_platform/eeprom.py index b0ebee54ee24..70a4b0ecb437 100644 --- a/platform/broadcom/sonic-platform-modules-inventec/d7054q28b/sonic_platform/eeprom.py +++ b/platform/broadcom/sonic-platform-modules-inventec/d7054q28b/sonic_platform/eeprom.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # # Name: eeprom.py, version: 1.0 # @@ -8,7 +7,7 @@ try: from sonic_eeprom import eeprom_tlvinfo import binascii -except ImportError, e: +except ImportError as e: raise ImportError(str(e) + "- required module not found") class Eeprom(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/eeprom.py b/platform/mellanox/mlnx-platform-api/sonic_platform/eeprom.py index 6557a6c4ba63..53b8e7173686 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/eeprom.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Mellanox # @@ -7,11 +5,14 @@ # provides the eeprom information which are available in the platform # ############################################################################# -import exceptions import os import sys import re -from cStringIO import StringIO + +if sys.version_info.major == 3: + from io import StringIO +else: + from cStringIO import StringIO try: from sonic_platform_base.sonic_eeprom import eeprom_tlvinfo diff --git a/platform/p4/docker-sonic-p4.mk b/platform/p4/docker-sonic-p4.mk index b499a99aefe5..940b85ed5d2a 100644 --- a/platform/p4/docker-sonic-p4.mk +++ b/platform/p4/docker-sonic-p4.mk @@ -12,7 +12,7 @@ $(DOCKER_SONIC_P4)_DEPENDS += $(SWSS) \ $(LIBTEAMDCTL) \ $(LIBTEAM_UTILS) \ $(SONIC_DEVICE_DATA) \ - $(SONIC_UTILITIES_PY2) \ + $(SONIC_UTILITIES_PY3) \ $(IPROUTE2) # ifeq ($(ROUTING_STACK), quagga) diff --git a/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddf_eeprom.py b/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddf_eeprom.py index 95ca7b574622..222cdcf4edd3 100644 --- a/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddf_eeprom.py +++ b/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddf_eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # PDDF # @@ -9,7 +7,7 @@ try: from sonic_eeprom import eeprom_tlvinfo import binascii -except ImportError, e: +except ImportError as e: raise ImportError(str(e) + "- required module not found") diff --git a/platform/pddf/platform-api-pddf-base/sonic_platform_ref/eeprom.py b/platform/pddf/platform-api-pddf-base/sonic_platform_ref/eeprom.py index 4857895c2a01..c25d711354f5 100644 --- a/platform/pddf/platform-api-pddf-base/sonic_platform_ref/eeprom.py +++ b/platform/pddf/platform-api-pddf-base/sonic_platform_ref/eeprom.py @@ -1,8 +1,6 @@ -#!/usr/bin/env python - try: from sonic_platform_pddf_base.pddf_eeprom import PddfEeprom -except ImportError, e: +except ImportError as e: raise ImportError(str(e) + "- required module not found") diff --git a/platform/vs/docker-sonic-vs.mk b/platform/vs/docker-sonic-vs.mk index 299ca7c14c13..9cb59ca2188f 100644 --- a/platform/vs/docker-sonic-vs.mk +++ b/platform/vs/docker-sonic-vs.mk @@ -12,6 +12,7 @@ $(DOCKER_SONIC_VS)_DEPENDS += $(SWSS) \ $(LIBYANG) \ $(LIBYANG_CPP) \ $(LIBYANG_PY2) \ + $(LIBYANG_PY3) \ $(SONIC_UTILITIES_DATA) \ $(SONIC_HOST_SERVICES_DATA) @@ -23,7 +24,8 @@ $(DOCKER_SONIC_VS)_PYTHON_WHEELS += $(SWSSSDK_PY2) \ $(SONIC_PY_COMMON_PY3) \ $(SONIC_YANG_MODELS_PY3) \ $(SONIC_YANG_MGMT_PY2) \ - $(SONIC_UTILITIES_PY2) \ + $(SONIC_YANG_MGMT_PY3) \ + $(SONIC_UTILITIES_PY3) \ $(SONIC_HOST_SERVICES_PY3) ifeq ($(INSTALL_DEBUG_TOOLS), y) diff --git a/platform/vs/docker-sonic-vs/Dockerfile.j2 b/platform/vs/docker-sonic-vs/Dockerfile.j2 index 054446e525b0..2798095556cb 100644 --- a/platform/vs/docker-sonic-vs/Dockerfile.j2 +++ b/platform/vs/docker-sonic-vs/Dockerfile.j2 @@ -83,6 +83,14 @@ RUN pip2 install urllib3 RUN pip2 install requests RUN pip2 install crontab +# For sonic-config-engine Python 3 package +# Install pyangbind here, outside sonic-config-engine dependencies, as pyangbind causes enum34 to be installed. +# Then immediately uninstall enum34, as enum34 should not be installed for Python >= 3.4, as it causes a +# conflict with the new 'enum' module in the standard library +# https://github.com/robshakir/pyangbind/issues/232 +RUN pip3 install pyangbind==0.8.1 +RUN pip3 uninstall -y enum34 + {% if docker_sonic_vs_debs.strip() -%} # Copy locally-built Debian package dependencies {%- for deb in docker_sonic_vs_debs.split(' ') %} diff --git a/rules/sonic-utilities.dep b/rules/sonic-utilities.dep index 8686c79b61b7..848b8d66296e 100644 --- a/rules/sonic-utilities.dep +++ b/rules/sonic-utilities.dep @@ -1,10 +1,10 @@ -SPATH := $($(SONIC_UTILITIES_PY2)_SRC_PATH) +SPATH := $($(SONIC_UTILITIES_PY3)_SRC_PATH) DEP_FILES := $(SONIC_COMMON_FILES_LIST) rules/sonic-utilities.mk rules/sonic-utilities.dep DEP_FILES += $(SONIC_COMMON_BASE_FILES_LIST) SMDEP_FILES := $(addprefix $(SPATH)/,$(shell cd $(SPATH) && git ls-files)) -$(SONIC_UTILITIES_PY2)_CACHE_MODE := GIT_CONTENT_SHA -$(SONIC_UTILITIES_PY2)_DEP_FLAGS := $(SONIC_COMMON_FLAGS_LIST) -$(SONIC_UTILITIES_PY2)_DEP_FILES := $(DEP_FILES) -$(SONIC_UTILITIES_PY2)_SMDEP_FILES := $(SMDEP_FILES) -$(SONIC_UTILITIES_PY2)_SMDEP_PATHS := $(SPATH) +$(SONIC_UTILITIES_PY3)_CACHE_MODE := GIT_CONTENT_SHA +$(SONIC_UTILITIES_PY3)_DEP_FLAGS := $(SONIC_COMMON_FLAGS_LIST) +$(SONIC_UTILITIES_PY3)_DEP_FILES := $(DEP_FILES) +$(SONIC_UTILITIES_PY3)_SMDEP_FILES := $(SMDEP_FILES) +$(SONIC_UTILITIES_PY3)_SMDEP_PATHS := $(SPATH) diff --git a/rules/sonic-utilities.mk b/rules/sonic-utilities.mk index f3b6e332545d..7119b4b98eb0 100644 --- a/rules/sonic-utilities.mk +++ b/rules/sonic-utilities.mk @@ -1,27 +1,16 @@ # sonic utilities package -# -# NOTE: sonic-config-engine is a build-time dependency of sonic-utilities -# due to unit tests which are run during the build. However, -# sonic-platform-common and swsssdk are runtime dependencies, and should be -# added here also. However, the current build system assumes all runtime -# dependencies are .deb packages. -# -SONIC_UTILITIES_PY2 = sonic_utilities-1.2-py2-none-any.whl -$(SONIC_UTILITIES_PY2)_SRC_PATH = $(SRC_PATH)/sonic-utilities -$(SONIC_UTILITIES_PY2)_PYTHON_VERSION = 2 -$(SONIC_UTILITIES_PY2)_DEPENDS += $(SONIC_PY_COMMON_PY2) \ - $(SONIC_PY_COMMON_PY3) \ - $(SWSSSDK_PY2) \ - $(SONIC_CONFIG_ENGINE_PY2) \ - $(SONIC_YANG_MGMT_PY2) \ +SONIC_UTILITIES_PY3 = sonic_utilities-1.2-py3-none-any.whl +$(SONIC_UTILITIES_PY3)_SRC_PATH = $(SRC_PATH)/sonic-utilities +$(SONIC_UTILITIES_PY3)_PYTHON_VERSION = 3 +$(SONIC_UTILITIES_PY3)_DEPENDS += $(SONIC_PY_COMMON_PY3) \ + $(SWSSSDK_PY3) \ + $(SONIC_CONFIG_ENGINE_PY3) \ $(SONIC_YANG_MGMT_PY3) \ $(SONIC_YANG_MODELS_PY3) -$(SONIC_UTILITIES_PY2)_DEBS_DEPENDS = $(LIBYANG) \ +$(SONIC_UTILITIES_PY3)_DEBS_DEPENDS = $(LIBYANG) \ $(LIBYANG_CPP) \ - $(LIBYANG_PY2) \ $(LIBYANG_PY3) \ $(LIBSWSSCOMMON) \ - $(PYTHON_SWSSCOMMON) \ $(PYTHON3_SWSSCOMMON) -SONIC_PYTHON_WHEELS += $(SONIC_UTILITIES_PY2) +SONIC_PYTHON_WHEELS += $(SONIC_UTILITIES_PY3) diff --git a/slave.mk b/slave.mk index a959936f1aa4..88d64e6bc409 100644 --- a/slave.mk +++ b/slave.mk @@ -825,7 +825,7 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \ $$(addprefix $(FILES_PATH)/,$$($$*_FILES)) \ $(if $(findstring y,$(ENABLE_ZTP)),$(addprefix $(IMAGE_DISTRO_DEBS_PATH)/,$(SONIC_ZTP))) \ $(if $(findstring y,$(INCLUDE_HOST_SERVICE)),$(addprefix $(IMAGE_DISTRO_DEBS_PATH)/,$(SONIC_HOST_SERVICE))) \ - $(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_UTILITIES_PY2)) \ + $(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_UTILITIES_PY3)) \ $(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_PY_COMMON_PY2)) \ $(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_PY_COMMON_PY3)) \ $(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_CONFIG_ENGINE_PY2)) \ @@ -886,7 +886,7 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \ export multi_instance="false" export python_swss_debs="$(addprefix $(IMAGE_DISTRO_DEBS_PATH)/,$($(LIBSWSSCOMMON)_RDEPENDS))" export python_swss_debs+=" $(addprefix $(IMAGE_DISTRO_DEBS_PATH)/,$(LIBSWSSCOMMON)) $(addprefix $(IMAGE_DISTRO_DEBS_PATH)/,$(PYTHON_SWSSCOMMON)) $(addprefix $(IMAGE_DISTRO_DEBS_PATH)/,$(PYTHON3_SWSSCOMMON))" - export sonic_utilities_py2_wheel_path="$(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_UTILITIES_PY2))" + export sonic_utilities_py3_wheel_path="$(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_UTILITIES_PY3))" export sonic_host_services_py3_wheel_path="$(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_HOST_SERVICES_PY3))" $(foreach docker, $($*_DOCKERS),\ diff --git a/sonic-slave-buster/Dockerfile.j2 b/sonic-slave-buster/Dockerfile.j2 index b58027bf30d4..909a8e0b2e9c 100644 --- a/sonic-slave-buster/Dockerfile.j2 +++ b/sonic-slave-buster/Dockerfile.j2 @@ -392,6 +392,7 @@ RUN pip3 install Pympler==0.8 # For sonic_yang_model build RUN pip2 install pyang==2.1.1 +RUN pip3 install pyang==2.1.1 # For mgmt-framework build RUN pip2 install mmh3 diff --git a/src/sonic-config-engine/config_samples.py b/src/sonic-config-engine/config_samples.py index be8ab3e0a955..9072e0209c3e 100644 --- a/src/sonic-config-engine/config_samples.py +++ b/src/sonic-config-engine/config_samples.py @@ -13,10 +13,10 @@ def generate_t1_sample_config(data): for port in natsorted(data['PORT']): data['PORT'][port]['admin_status'] = 'up' data['PORT'][port]['mtu'] = '9100' - local_addr = '10.0.{}.{}'.format(2 * port_count / 256, 2 * port_count % 256) - peer_addr = '10.0.{}.{}'.format(2 * port_count / 256, 2 * port_count % 256 + 1) - peer_name='ARISTA{0:02d}{1}'.format(1+port_count%(total_port_amount/2), 'T2' if port_count < (total_port_amount/2) else 'T0') - peer_asn = 65200 if port_count < total_port_amount/2 else 64001 + port_count - total_port_amount/2 + local_addr = '10.0.{}.{}'.format(2 * port_count // 256, 2 * port_count % 256) + peer_addr = '10.0.{}.{}'.format(2 * port_count // 256, 2 * port_count % 256 + 1) + peer_name='ARISTA{0:02d}{1}'.format(1+port_count%(total_port_amount // 2), 'T2' if port_count < (total_port_amount // 2) else 'T0') + peer_asn = 65200 if port_count < (total_port_amount // 2) else 64001 + port_count - (total_port_amount // 2) data['INTERFACE']['{}|{}/31'.format(port, local_addr)] = {} data['BGP_NEIGHBOR'][peer_addr] = { 'rrclient': 0, diff --git a/src/sonic-py-swsssdk b/src/sonic-py-swsssdk index 9d9f0c60239d..1664be94387c 160000 --- a/src/sonic-py-swsssdk +++ b/src/sonic-py-swsssdk @@ -1 +1 @@ -Subproject commit 9d9f0c60239d9b02e7589b8cedeafcc4e60bd7c8 +Subproject commit 1664be94387ccb3088f4176bf4b701c68796ef50 diff --git a/src/sonic-utilities b/src/sonic-utilities index 3f158352b2ce..f9eb739fa238 160000 --- a/src/sonic-utilities +++ b/src/sonic-utilities @@ -1 +1 @@ -Subproject commit 3f158352b2cef171a0aa5e89d075ed4328cef6dd +Subproject commit f9eb739fa238284c10ecb7c00b07094ac90b27db