Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sonic-utilities] Update submodule; Build and install as a Python 3 wheel #5926

Merged
merged 24 commits into from
Nov 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
9d74e67
[sonic-utilities] Install Python 3 package
jleveque Nov 13, 2020
64ad57b
[sonic-utilities] Update submodule
jleveque Nov 15, 2020
302255d
Update submodule further
jleveque Nov 16, 2020
baf95b8
Add 'pyang' to install dependencies of sonic-yang-mgmt package
jleveque Nov 16, 2020
170f683
Install pyang in Buster slave container
jleveque Nov 16, 2020
37028c3
Install Python 3 libyang package in VS container
jleveque Nov 16, 2020
40a115b
Install Python 3 sonic-config-engine package in host OS
jleveque Nov 16, 2020
093e1b9
Revert "Add 'pyang' to install dependencies of sonic-yang-mgmt package"
jleveque Nov 16, 2020
8f9ab66
[sonic-confic-engine] Use integer division in config_samples.py
jleveque Nov 17, 2020
25e5e55
[x86_64-kvm_x86_64-r0] Use Python 3-compliant print function in eepro…
jleveque Nov 17, 2020
53877c1
Update utilities further
jleveque Nov 18, 2020
b757b0c
Update swsssdk submodule
jleveque Nov 18, 2020
e70daa2
Explicitly install Python 3 pyangbind and uninstall enum 34 in host a…
jleveque Nov 19, 2020
3c47a6a
Update utils further
jleveque Nov 20, 2020
576d9b8
Update utils further
jleveque Nov 21, 2020
c95f65d
Make all eeprom plugins Python 3-compliant to work with Python 3 deco…
jleveque Nov 21, 2020
11887ec
Update utils further
jleveque Nov 22, 2020
59ffeda
Make all other platform plugins compliant with both Python 2 and 3
jleveque Nov 23, 2020
695a509
Update shebangs to Python 3, remove unnecessary ones
jleveque Nov 24, 2020
2e4475e
Replace tabs with spaces in Python plugins; fix alignment using autopep8
jleveque Nov 24, 2020
981c5af
Format remaining Python files wil autopep8 for consistency
jleveque Nov 24, 2020
9529029
Fix comment placement
jleveque Nov 24, 2020
c313fa6
Fix alignment
jleveque Nov 24, 2020
3fab9f4
Pass 'universal_newlines=True' arg to all relevant subprocess functions
jleveque Nov 25, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 4 additions & 5 deletions device/accton/x86_64-accton_as4630_54pe-r0/plugins/eeprom.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#!/usr/bin/env python

try:
import exceptions
import binascii
import time
import optparse
Expand All @@ -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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a must? I am wondering if the vendor's plugin will have other python3 incompatible issues, it seems you only find one of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a must to make decode-syseeprom work, now that it is Python 3. Technically, with the addition of syseepromd, we should be able to replace decode-syseeprom with simple reads from the DB. But until then, we should maintain backward compatibility with the existing CLI utility while it is still being used.

I found and fixed a few common Python 3 issues with the eeprom.py plugin. It's possible there are Python 3 compatibility issues with other plugins, but these plugins are deprecated in favor of the new platform API. I do not intend to maintain support for the old platform plugins.

Rather than changing these plugins, we could remove decode-syseeprom altogether, but I felt that was a more disruptive change which is best suited for a separate PR.

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)
5 changes: 2 additions & 3 deletions device/accton/x86_64-accton_as4630_54pe-r0/plugins/psuutil.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env python

#############################################################################
# Accton
#
Expand All @@ -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"""
Expand Down
43 changes: 22 additions & 21 deletions device/accton/x86_64-accton_as4630_54pe-r0/plugins/sfputil.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
SFP_STATUS_INSERTED = '1'
SFP_STATUS_REMOVED = '0'


class SfpUtil(SfpUtilBase):
"""Platform-specific SfpUtil class"""

Expand All @@ -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):
Expand All @@ -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))
lguohan marked this conversation as resolved.
Show resolved Hide resolved

@property
def port_to_eeprom_mapping(self):
Expand All @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -192,4 +194,3 @@ def get_transceiver_change_event(self, timeout=0):
else:
return True, {}
return False, {}

11 changes: 5 additions & 6 deletions device/accton/x86_64-accton_as5712_54x-r0/plugins/eeprom.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#!/usr/bin/env python

try:
import exceptions
import binascii
import time
import optparse
Expand All @@ -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)
5 changes: 2 additions & 3 deletions device/accton/x86_64-accton_as5712_54x-r0/plugins/psuutil.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env python

#############################################################################
# Accton
#
Expand All @@ -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"""
Expand Down
Loading