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

[DellEMC]: Platform modules Python3 compliance and other changes #5609

Merged
merged 3 commits into from
Oct 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions device/dell/x86_64-dell_s6100_c2538-r0/plugins/eeprom.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,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):
Expand Down
4 changes: 2 additions & 2 deletions device/dell/x86_64-dell_z9100_c2538-r0/plugins/eeprom.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,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):
Expand Down
4 changes: 2 additions & 2 deletions device/dell/x86_64-dellemc_s5232f_c3538-r0/plugins/eeprom.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
try:
import os.path
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):
Expand Down
4 changes: 2 additions & 2 deletions device/dell/x86_64-dellemc_s5248f_c3538-r0/plugins/eeprom.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
try:
import os.path
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):
Expand Down
4 changes: 2 additions & 2 deletions device/dell/x86_64-dellemc_z9264f_c3538-r0/plugins/eeprom.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
try:
import os.path
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):
Expand Down
4 changes: 2 additions & 2 deletions device/dell/x86_64-dellemc_z9332f_d1508-r0/plugins/eeprom.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,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):
Expand Down
30 changes: 13 additions & 17 deletions platform/broadcom/sonic-platform-modules-dell/common/fw-updater
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#!/usr/bin/python
#!/usr/bin/python3

# dell staging fw updater script

import os
import sys
import subprocess
import argparse


onie_boot_folder = '/mnt/onie-boot/onie/tools/bin/onie-fwpkg'
onie_fwpkg_tool = '/mnt/onie-boot/onie/tools/bin/onie-fwpkg'
onie_boot_folder = '/mnt/onie-boot/onie/tools/bin/onie-fwpkg'
onie_fwpkg_tool = '/mnt/onie-boot/onie/tools/bin/onie-fwpkg'
ONIE_BOOT_MODE_CMD = '/mnt/onie-boot/onie/tools/bin/onie-boot-mode'
HOST_GRUB_DIR = '/host'
HOST_GRUB_CFG = HOST_GRUB_DIR + '/grub/grub.cfg'
Expand All @@ -19,8 +18,6 @@ HOST_PLATFORM_INFO = HOST_GRUB_DIR + '/platform'
dell_reload_tool = '/usr/local/bin/reboot'




def set_onie_mode(option):
"""Select the ONIE boot mode, and set the next_entry to point to ONIE"""
_set_env_option('next_entry', 'ONIE')
Expand All @@ -30,12 +27,12 @@ def set_onie_fw_update_env():
"""Select the ONIE boot mode, and set the next_entry to point to ONIE"""

if not os.path.exists(onie_boot_folder):
os.makedirs(onie_boot_folder)
os.makedirs(onie_boot_folder)

try:
subprocess.check_call(['mount','/dev/disk/by-label/ONIE-BOOT','/mnt/onie-boot'])
subprocess.check_call(['mount', '/dev/disk/by-label/ONIE-BOOT', '/mnt/onie-boot'])
except:
print "onie-boot not able to mount"
print("onie-boot not able to mount")

def _set_env_option(option, value):
"""Set an option in the GRUB environment block. Pass None to value to
Expand All @@ -53,32 +50,32 @@ def _set_env_option(option, value):
def dell_firmware_update_staging(image_name):

try:
p = subprocess.Popen([onie_fwpkg_tool,"purge"],stdout=subprocess.PIPE,stdin=subprocess.PIPE)
p = subprocess.Popen([onie_fwpkg_tool, "purge"], stdout=subprocess.PIPE, stdin=subprocess.PIPE)
p.communicate("y")
except:
print "onie-fwpkg command not found for purging old fw updates"
print("onie-fwpkg command not found for purging old fw updates")

try:
subprocess.check_call([onie_fwpkg_tool,"add", str(image_name)])
subprocess.check_call([onie_fwpkg_tool, "add", str(image_name)])
except:
print "onie-fwpkg is not found to stage fw updates"
print("onie-fwpkg is not found to stage fw updates")

try:
set_onie_mode("update")
except:
print "dell-image command not found"
print("dell-image command not found")

try:
subprocess.check_call([dell_reload_tool])
except:
print "reload command not found"
print("reload command not found")


if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Dell HOST Firmware updates')
opts = parser.add_mutually_exclusive_group(required=True)
opts.add_argument('-u', '--update', nargs=1, metavar='IMAGE',
help='update specified image')
help='update specified image')

args = parser.parse_args()

Expand All @@ -88,4 +85,3 @@ if __name__ == '__main__':
if args.update:
set_onie_fw_update_env()
dell_firmware_update_staging(args.update[0])

67 changes: 32 additions & 35 deletions platform/broadcom/sonic-platform-modules-dell/common/io_rd_wr.py
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
#!/usr/bin/python
#Script to read/write the io based registers
#!/usr/bin/python3
# Script to read/write the io based registers

import sys
import os
import getopt
import struct

io_resource='/dev/port'
io_resource = '/dev/port'

def usage():
''' This is the Usage Method '''

print 'Utility for IO read/write'
print '\t\t io_rd_wr.py --get --offset <offset>'
print '\t\t io_rd_wr.py --set --val <val> --offset <offset>'
print('Utility for IO read/write')
print('\t\t io_rd_wr.py --get --offset <offset>')
print('\t\t io_rd_wr.py --set --val <val> --offset <offset>')
sys.exit(1)

def io_reg_read(io_resource,offset):
fd=os.open(io_resource, os.O_RDONLY)
if(fd<0):
print 'file open failed %s"%io_resource'
def io_reg_read(io_resource, offset):
fd = os.open(io_resource, os.O_RDONLY)
if(fd < 0):
print('file open failed %s' % io_resource)
return
if(os.lseek(fd, offset, os.SEEK_SET) != offset):
print 'lseek failed on %s'%io_resource
print('lseek failed on %s' % io_resource)
return
buf=os.read(fd,1)
reg_val1=ord(buf)
print 'reg value %x'%reg_val1
buf = os.read(fd, 1)
reg_val1 = ord(buf)
print('reg value %x' % reg_val1)
os.close(fd)

def io_reg_write(io_resource,offset,val):
fd=os.open(io_resource,os.O_RDWR)
if(fd<0):
print 'file open failed %s"%io_resource'
def io_reg_write(io_resource, offset, val):
fd = os.open(io_resource, os.O_RDWR)
if(fd < 0):
print('file open failed %s' % io_resource)
return
if(os.lseek(fd, offset, os.SEEK_SET) != offset):
print 'lseek failed on %s'%io_resource
print('lseek failed on %s' % io_resource)
return
ret=os.write(fd,struct.pack('B',val))
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)

Expand All @@ -51,19 +51,17 @@ def main(argv):
opts = ''
val = ''
choice = ''
resouce = ''
offset = ''

try:
opts, args = getopt.getopt(argv, "hgs:" , \
["val=","offset=","help", "get", "set"])

opts, args = getopt.getopt(argv, "hgs:",
["val=", "offset=", "help", "get", "set"])
except getopt.GetoptError:
usage()

for opt,arg in opts:
for opt, arg in opts:

if opt in ('-h','--help'):
if opt in ('-h', '--help'):
choice = 'help'

elif opt in ('-g', '--get'):
Expand All @@ -72,22 +70,21 @@ def main(argv):
elif opt in ('-s', '--set'):
choice = 'set'

elif opt == '--offset':
offset = int(arg,16)
elif opt == '--offset':
offset = int(arg, 16)

elif opt == '--val':
val = int(arg,16)
elif opt == '--val':
val = int(arg, 16)

if choice == 'get' and offset != '':
io_reg_read(io_resource,offset)
io_reg_read(io_resource, offset)

elif choice == 'set' and offset != '' and val != '':
io_reg_write(io_resource,offset,val)
io_reg_write(io_resource, offset, val)

else:
usage()

#Calling the main method
# Calling the main method
if __name__ == "__main__":
main(sys.argv[1:])

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/python
#!/usr/bin/python3

########################################################################
# DellEMC
Expand Down Expand Up @@ -53,7 +53,7 @@ def _get_ipmitool_raw_output(self, args):
stdout = proc.communicate()[0]
proc.wait()
if not proc.returncode:
result = stdout.rstrip('\n')
result = stdout.decode('utf-8').rstrip('\n')
except:
pass

Expand Down Expand Up @@ -144,10 +144,10 @@ def get_threshold(self, threshold_type):
if self.is_discrete:
raise TypeError("Threshold is not applicable for Discrete Sensor")

if threshold_type not in self.THRESHOLD_BIT_MASK.keys():
if threshold_type not in list(self.THRESHOLD_BIT_MASK.keys()):
raise ValueError("Invalid threshold type {} provided. Valid types "
"are {}".format(threshold_type,
self.THRESHOLD_BIT_MASK.keys()))
list(self.THRESHOLD_BIT_MASK.keys())))

bit_mask = self.THRESHOLD_BIT_MASK[threshold_type]

Expand Down Expand Up @@ -179,7 +179,7 @@ def _get_ipmitool_fru_print(self):
stdout = proc.communicate()[0]
proc.wait()
if not proc.returncode:
result = stdout.rstrip('\n')
result = stdout.decode('utf-8').rstrip('\n')
except:
pass

Expand All @@ -193,7 +193,7 @@ def _get_from_fru(self, info):
if not fru_output:
return "NA"

info_req = re.search(r"%s\s*:(.*)"%info, fru_output)
info_req = re.search(r"%s\s*:(.*)" % info, fru_output)
if not info_req:
return "NA"

Expand Down Expand Up @@ -223,7 +223,6 @@ def get_board_product(self):
"""
return self._get_from_fru('Board Product')


def get_fru_data(self, offset, count=1):
"""
Reads and returns the FRU data at the provided offset.
Expand Down Expand Up @@ -253,7 +252,7 @@ def get_fru_data(self, offset, count=1):
stdout = proc.communicate()[0]
proc.wait()
if not proc.returncode:
result = stdout.rstrip('\n')
result = stdout.decode('utf-8').rstrip('\n')
except:
is_valid = False

Expand Down
Loading