Skip to content

Commit 62af380

Browse files
FuzailBrcmCarl Keene
authored andcommitted
Few more python3 compatibility changes, PEP8 standard changes and add missing methods in PDDF common base APIs (sonic-net#7021)
#### Why I did it - Python3 compatibility changes for PDDF eeprom class - Adding API for temperature in PDDF psu class - PEP8 standard changes and adding missing method in PDDF sfp class #### How I did it - Using python3 to invoke the sonic_platform module in PDDF based platform - Running autopep8 tool to comply to PEP8 standards
1 parent 3f18925 commit 62af380

3 files changed

Lines changed: 65 additions & 25 deletions

File tree

platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddf_eeprom.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
try:
88
from sonic_eeprom import eeprom_tlvinfo
9-
import binascii
109
except ImportError as e:
1110
raise ImportError(str(e) + "- required module not found")
1211

@@ -70,42 +69,42 @@ def serial_number_str(self):
7069
(is_valid, results) = self.get_tlv_field(self.eeprom_data, self._TLV_CODE_SERIAL_NUMBER)
7170
if not is_valid:
7271
return "N/A"
73-
return results[2]
72+
return results[2].decode('ascii')
7473

7574
def base_mac_addr(self):
7675
(is_valid, t) = self.get_tlv_field(self.eeprom_data, self._TLV_CODE_MAC_BASE)
7776
if not is_valid or t[1] != 6:
7877
return super(TlvInfoDecoder, self).switchaddrstr(e)
7978

80-
return ":".join([binascii.b2a_hex(T) for T in t[2]])
79+
return ":".join(["{:02x}".format(T) for T in t[2]]).upper()
8180

8281
def modelstr(self):
8382
(is_valid, results) = self.get_tlv_field(self.eeprom_data, self._TLV_CODE_PRODUCT_NAME)
8483
if not is_valid:
8584
return "N/A"
8685

87-
return results[2]
86+
return results[2].decode('ascii')
8887

8988
def part_number_str(self):
9089
(is_valid, results) = self.get_tlv_field(self.eeprom_data, self._TLV_CODE_PART_NUMBER)
9190
if not is_valid:
9291
return "N/A"
9392

94-
return results[2]
93+
return results[2].decode('ascii')
9594

9695
def serial_str(self):
9796
(is_valid, results) = self.get_tlv_field(self.eeprom_data, self._TLV_CODE_SERVICE_TAG)
9897
if not is_valid:
9998
return "N/A"
10099

101-
return results[2]
100+
return results[2].decode('ascii')
102101

103102
def revision_str(self):
104103
(is_valid, results) = self.get_tlv_field(self.eeprom_data, self._TLV_CODE_DEVICE_VERSION)
105104
if not is_valid:
106105
return "N/A"
107106

108-
return results[2]
107+
return results[2].decode('ascii')
109108

110109
def system_eeprom_info(self):
111110
"""

platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddf_psu.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,24 @@ def get_status_led(self):
260260
color = self.pddf_obj.get_led_color()
261261
return (color)
262262

263+
def get_temperature(self):
264+
"""
265+
Retrieves current temperature reading from PSU
266+
267+
Returns:
268+
A float number of current temperature in Celsius up to nearest thousandth
269+
of one degree Celsius, e.g. 30.125
270+
"""
271+
device = "PSU{}".format(self.psu_index)
272+
output = self.pddf_obj.get_attr_name_output(device, "psu_temp1_input")
273+
if not output:
274+
return 0.0
275+
276+
temp1 = output['status']
277+
278+
# temperature returned is in milli celcius
279+
return float(temp1)/1000
280+
263281
def get_input_voltage(self):
264282
"""
265283
Retrieves current PSU input voltage

platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddf_sfp.py

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
QSFP_MODULE_THRESHOLD_OFFSET = 128
8484
QSFP_MODULE_THRESHOLD_WIDTH = 24
8585
QSFP_CHANNEL_THRESHOLD_OFFSET = 176
86-
QSFP_CHANNEL_THRESHOLD_WIDTH = 16
86+
QSFP_CHANNEL_THRESHOLD_WIDTH = 24
8787

8888

8989
SFP_TEMPE_OFFSET = 96
@@ -94,8 +94,6 @@
9494
SFP_CHANNL_MON_WIDTH = 6
9595
SFP_MODULE_THRESHOLD_OFFSET = 0
9696
SFP_MODULE_THRESHOLD_WIDTH = 40
97-
SFP_CHANNL_THRESHOLD_OFFSET = 112
98-
SFP_CHANNL_THRESHOLD_WIDTH = 2
9997
SFP_STATUS_CONTROL_OFFSET = 110
10098
SFP_STATUS_CONTROL_WIDTH = 1
10199
SFP_TX_DISABLE_HARD_BIT = 7
@@ -327,16 +325,16 @@ def get_transceiver_info(self):
327325
else:
328326
xcvr_info_dict['type'] = sfp_type_data['data']['type']['value'] if sfp_type_data else 'N/A'
329327
xcvr_info_dict['type_abbrv_name'] = sfp_type_abbrv_name['data']['type_abbrv_name']['value'] \
330-
if sfp_type_abbrv_name else 'N/A'
328+
if sfp_type_abbrv_name else 'N/A'
331329

332330
xcvr_info_dict['manufacturer'] = sfp_vendor_name_data['data']['Vendor Name']['value'] \
333-
if sfp_vendor_name_data else 'N/A'
331+
if sfp_vendor_name_data else 'N/A'
334332
xcvr_info_dict['model'] = sfp_vendor_pn_data['data']['Vendor PN']['value'] if sfp_vendor_pn_data else 'N/A'
335333
xcvr_info_dict['hardware_rev'] = sfp_vendor_rev_data['data']['Vendor Rev']['value'] \
336-
if sfp_vendor_rev_data else 'N/A'
334+
if sfp_vendor_rev_data else 'N/A'
337335
xcvr_info_dict['serial'] = sfp_vendor_sn_data['data']['Vendor SN']['value'] if sfp_vendor_sn_data else 'N/A'
338336
xcvr_info_dict['vendor_oui'] = sfp_vendor_oui_data['data']['Vendor OUI']['value'] \
339-
if sfp_vendor_oui_data else 'N/A'
337+
if sfp_vendor_oui_data else 'N/A'
340338
xcvr_info_dict['vendor_date'] = sfp_vendor_date_data['data'][
341339
'VendorDataCode(YYYY-MM-DD Lot)']['value'] if sfp_vendor_date_data else 'N/A'
342340
xcvr_info_dict['cable_type'] = "Unknown"
@@ -351,7 +349,7 @@ def get_transceiver_info(self):
351349
for key in qsfp_compliance_code_tup:
352350
if key in sfp_interface_bulk_data['data']['Specification compliance']['value']:
353351
compliance_code_dict[key] = sfp_interface_bulk_data['data']['Specification compliance'][
354-
'value'][key]['value']
352+
'value'][key]['value']
355353
xcvr_info_dict['specification_compliance'] = str(compliance_code_dict)
356354

357355
nkey = 'Nominal Bit Rate(100Mbs)'
@@ -371,7 +369,7 @@ def get_transceiver_info(self):
371369
for key in sfp_compliance_code_tup:
372370
if key in sfp_interface_bulk_data['data']['Specification compliance']['value']:
373371
compliance_code_dict[key] = sfp_interface_bulk_data['data']['Specification compliance'][
374-
'value'][key]['value']
372+
'value'][key]['value']
375373
xcvr_info_dict['specification_compliance'] = str(compliance_code_dict)
376374

377375
xcvr_info_dict['nominal_bit_rate'] = str(
@@ -592,8 +590,9 @@ def get_transceiver_threshold_info(self):
592590
if sfpd_obj is None:
593591
return None
594592

595-
dom_thres_raw = self.__read_eeprom_specific_bytes(QSFP_MODULE_THRESHOLD_OFFSET, QSFP_MODULE_THRESHOLD_WIDTH)
596-
593+
offset = 384
594+
dom_thres_raw = self.__read_eeprom_specific_bytes(
595+
(offset+QSFP_MODULE_THRESHOLD_OFFSET), QSFP_MODULE_THRESHOLD_WIDTH)
597596
if dom_thres_raw:
598597
module_threshold_values = sfpd_obj.parse_module_threshold_values(
599598
dom_thres_raw, 0)
@@ -608,8 +607,8 @@ def get_transceiver_threshold_info(self):
608607
xcvr_dom_threshold_info_dict['vcchighwarning'] = module_threshold_data['VccHighWarning']['value']
609608
xcvr_dom_threshold_info_dict['vcclowwarning'] = module_threshold_data['VccLowWarning']['value']
610609

611-
dom_thres_raw = self.__read_eeprom_specific_bytes(
612-
QSFP_CHANNEL_THRESHOLD_OFFSET, QSFP_CHANNEL_THRESHOLD_WIDTH)
610+
dom_thres_raw = self.__read_eeprom_specific_bytes((offset + QSFP_CHANNEL_THRESHOLD_OFFSET),
611+
QSFP_CHANNEL_THRESHOLD_WIDTH)
613612
if dom_thres_raw:
614613
channel_threshold_values = sfpd_obj.parse_channel_threshold_values(
615614
dom_thres_raw, 0)
@@ -659,15 +658,15 @@ def get_transceiver_threshold_info(self):
659658
xcvr_dom_threshold_info_dict['txpowerhighalarm'] = dom_mod_th_data['data']['TXPowerHighAlarm']['value']
660659
xcvr_dom_threshold_info_dict['txpowerlowalarm'] = dom_mod_th_data['data']['TXPowerLowAlarm']['value']
661660
xcvr_dom_threshold_info_dict['txpowerhighwarning'] = dom_mod_th_data['data']['TXPowerHighWarning'][
662-
'value']
661+
'value']
663662
xcvr_dom_threshold_info_dict['txpowerlowwarning'] = dom_mod_th_data['data']['TXPowerLowWarning'][
664-
'value']
663+
'value']
665664
xcvr_dom_threshold_info_dict['rxpowerhighalarm'] = dom_mod_th_data['data']['RXPowerHighAlarm']['value']
666665
xcvr_dom_threshold_info_dict['rxpowerlowalarm'] = dom_mod_th_data['data']['RXPowerLowAlarm']['value']
667666
xcvr_dom_threshold_info_dict['rxpowerhighwarning'] = dom_mod_th_data['data']['RXPowerHighWarning'][
668-
'value']
667+
'value']
669668
xcvr_dom_threshold_info_dict['rxpowerlowwarning'] = dom_mod_th_data['data']['RXPowerLowWarning'][
670-
'value']
669+
'value']
671670

672671
return xcvr_dom_threshold_info_dict
673672

@@ -764,7 +763,7 @@ def get_tx_fault(self):
764763
tx_fault_list = []
765764
dom_channel_monitor_raw = self.__read_eeprom_specific_bytes(
766765
QSFP_CHANNL_TX_FAULT_STATUS_OFFSET, QSFP_CHANNL_TX_FAULT_STATUS_WIDTH) \
767-
if self.get_presence() else None
766+
if self.get_presence() else None
768767
if dom_channel_monitor_raw is not None:
769768
tx_fault_data = int(dom_channel_monitor_raw[0], 16)
770769
tx_fault_list.append(tx_fault_data & 0x01 != 0)
@@ -1040,6 +1039,28 @@ def get_tx_power(self):
10401039
else:
10411040
return None
10421041

1042+
def get_intr_status(self):
1043+
"""
1044+
Retrieves the interrupt status for this transceiver
1045+
Returns:
1046+
A Boolean, True if there is interrupt, False if not
1047+
"""
1048+
intr_status = False
1049+
1050+
# Interrupt status can be checked for absent ports too
1051+
device = 'PORT{}'.format(self.port_index)
1052+
output = self.pddf_obj.get_attr_name_output(device, 'xcvr_intr_status')
1053+
1054+
if output:
1055+
status = int(output['status'].rstrip())
1056+
1057+
if status == 1:
1058+
intr_status = True
1059+
else:
1060+
intr_status = False
1061+
1062+
return intr_status
1063+
10431064
def reset(self):
10441065
"""
10451066
Reset SFP and return all user module settings to their default srate.
@@ -1354,6 +1375,8 @@ def get_presence(self):
13541375
# if self.plugin_data doesn't specify anything regarding Transceivers
13551376
if modpres == '1':
13561377
return True
1378+
else:
1379+
return False
13571380

13581381
def get_model(self):
13591382
"""

0 commit comments

Comments
 (0)