diff --git a/device/centec/arm64-centec_e530_24x2c-r0/platform_reboot b/device/centec/arm64-centec_e530_24x2c-r0/platform_reboot index f22723f98d..abb89fdc19 100755 --- a/device/centec/arm64-centec_e530_24x2c-r0/platform_reboot +++ b/device/centec/arm64-centec_e530_24x2c-r0/platform_reboot @@ -1,11 +1,13 @@ #!/usr/bin/python -import os def main(): # reboot the system - os.system('echo 502 > /sys/class/gpio/export') - os.system('echo out > /sys/class/gpio/gpio502/direction') - os.system('echo 1 > /sys/class/gpio/gpio502/value') + with open('/sys/class/gpio/export', 'w') as file: + file.write('502\n') + with open('/sys/class/gpio/gpio502/direction', 'w') as file: + file.write('out\n') + with open('/sys/class/gpio/gpio502/value', 'w') as file: + file.write('1\n') if __name__ == "__main__": main() diff --git a/device/centec/arm64-centec_e530_24x2q-r0/platform_reboot b/device/centec/arm64-centec_e530_24x2q-r0/platform_reboot index f22723f98d..abb89fdc19 100755 --- a/device/centec/arm64-centec_e530_24x2q-r0/platform_reboot +++ b/device/centec/arm64-centec_e530_24x2q-r0/platform_reboot @@ -1,11 +1,13 @@ #!/usr/bin/python -import os def main(): # reboot the system - os.system('echo 502 > /sys/class/gpio/export') - os.system('echo out > /sys/class/gpio/gpio502/direction') - os.system('echo 1 > /sys/class/gpio/gpio502/value') + with open('/sys/class/gpio/export', 'w') as file: + file.write('502\n') + with open('/sys/class/gpio/gpio502/direction', 'w') as file: + file.write('out\n') + with open('/sys/class/gpio/gpio502/value', 'w') as file: + file.write('1\n') if __name__ == "__main__": main() diff --git a/device/centec/arm64-centec_e530_48s4x-r0/platform_reboot b/device/centec/arm64-centec_e530_48s4x-r0/platform_reboot index 98f62ca16c..78563edef5 100755 --- a/device/centec/arm64-centec_e530_48s4x-r0/platform_reboot +++ b/device/centec/arm64-centec_e530_48s4x-r0/platform_reboot @@ -1,12 +1,12 @@ #!/usr/bin/python -import os +import subprocess def main(): # reboot the system - os.system('modprobe i2c-dev') - os.system('i2cset -y 0 0x36 0x23 0x0') - os.system('sleep 1') - os.system('i2cset -y 0 0x36 0x23 0x3') + subprocess.call(['modprobe', 'i2c-dev']) + subprocess.call(['i2cset', '-y', '0', '0x36', '0x23', '0x0']) + subprocess.call(['sleep', '1']) + subprocess.call(['i2cset', '-y', '0', '0x36', '0x23', '0x3']) if __name__ == "__main__": main() diff --git a/device/centec/arm64-centec_e530_48t4x_p-r0/platform_reboot b/device/centec/arm64-centec_e530_48t4x_p-r0/platform_reboot index f22723f98d..abb89fdc19 100755 --- a/device/centec/arm64-centec_e530_48t4x_p-r0/platform_reboot +++ b/device/centec/arm64-centec_e530_48t4x_p-r0/platform_reboot @@ -1,11 +1,13 @@ #!/usr/bin/python -import os def main(): # reboot the system - os.system('echo 502 > /sys/class/gpio/export') - os.system('echo out > /sys/class/gpio/gpio502/direction') - os.system('echo 1 > /sys/class/gpio/gpio502/value') + with open('/sys/class/gpio/export', 'w') as file: + file.write('502\n') + with open('/sys/class/gpio/gpio502/direction', 'w') as file: + file.write('out\n') + with open('/sys/class/gpio/gpio502/value', 'w') as file: + file.write('1\n') if __name__ == "__main__": main() diff --git a/device/centec/x86_64-centec_v682_48x8c-r0/platform_reboot b/device/centec/x86_64-centec_v682_48x8c-r0/platform_reboot index 5e49eecb61..bac7c091dc 100755 --- a/device/centec/x86_64-centec_v682_48x8c-r0/platform_reboot +++ b/device/centec/x86_64-centec_v682_48x8c-r0/platform_reboot @@ -1,15 +1,15 @@ #!/usr/bin/env python -import os +import subprocess import time def main(): - os.system('hwclock -w -f /dev/rtc1') + subprocess.call(['hwclock', '-w', '-f', '/dev/rtc1']) time.sleep(1) - os.system('i2cset -y 0 0x36 0x23 0') + subprocess.call(['i2cset', '-y', '0', '0x36', '0x23', '0']) time.sleep(1) - os.system('i2cset -y 0 0x36 0x23 1') + subprocess.call(['i2cset', '-y', '0', '0x36', '0x23', '1']) if __name__ == '__main__': main() diff --git a/device/centec/x86_64-centec_v682_48x8c-r0/plugins/led_control.py b/device/centec/x86_64-centec_v682_48x8c-r0/plugins/led_control.py index b787320d78..c373b5c1d8 100644 --- a/device/centec/x86_64-centec_v682_48x8c-r0/plugins/led_control.py +++ b/device/centec/x86_64-centec_v682_48x8c-r0/plugins/led_control.py @@ -166,11 +166,11 @@ class LedControl(LedControlBase): def _initSystemLed(self): try: - cmd = 'i2cset -y 0 0x36 0x2 0x5' - Popen(cmd, shell=True) + cmd = ['i2cset', '-y', '0', '0x36', '0x2', '0x5'] + Popen(cmd) DBG_PRINT("init system led to normal") - cmd = 'i2cset -y 0 0x36 0x3 0x1' - Popen(cmd, shell=True) + cmd = ['i2cset', '-y', '0', '0x36', '0x3', '0x1'] + Popen(cmd) DBG_PRINT("init idn led to off") except IOError as e: DBG_PRINT(str(e)) diff --git a/device/centec/x86_64-centec_v682_48x8c-r0/plugins/psuutil.py b/device/centec/x86_64-centec_v682_48x8c-r0/plugins/psuutil.py index 9e311d9b4f..1a178a3853 100644 --- a/device/centec/x86_64-centec_v682_48x8c-r0/plugins/psuutil.py +++ b/device/centec/x86_64-centec_v682_48x8c-r0/plugins/psuutil.py @@ -40,8 +40,8 @@ class PsuUtil(PsuBase): if index is None: return False - cmd = 'i2cget -y 0 0x36 0x1e' - status = int(Popen(cmd, stdout=PIPE, stderr=STDOUT, shell=True).stdout.readline(), 16) + cmd = ['i2cget', '-y', '0', '0x36', '0x1e'] + status = int(Popen(cmd, stdout=PIPE, stderr=STDOUT).stdout.readline(), 16) powergood = ((status & (1 << (3 * (index - 1) + 2))) != 0) return powergood @@ -56,7 +56,7 @@ class PsuUtil(PsuBase): if index is None: return False - cmd = 'i2cget -y 0 0x36 0x1e' - status = int(Popen(cmd, stdout=PIPE, stderr=STDOUT, shell=True).stdout.readline(), 16) + cmd = ['i2cget', '-y', '0', '0x36', '0x1e'] + status = int(Popen(cmd, stdout=PIPE, stderr=STDOUT).stdout.readline(), 16) presence = ((status & (1 << (3 * (index - 1) + 1))) == 0) return presence diff --git a/device/centec/x86_64-centec_v682_48y8c-r0/platform_reboot b/device/centec/x86_64-centec_v682_48y8c-r0/platform_reboot index 5e49eecb61..bac7c091dc 100755 --- a/device/centec/x86_64-centec_v682_48y8c-r0/platform_reboot +++ b/device/centec/x86_64-centec_v682_48y8c-r0/platform_reboot @@ -1,15 +1,15 @@ #!/usr/bin/env python -import os +import subprocess import time def main(): - os.system('hwclock -w -f /dev/rtc1') + subprocess.call(['hwclock', '-w', '-f', '/dev/rtc1']) time.sleep(1) - os.system('i2cset -y 0 0x36 0x23 0') + subprocess.call(['i2cset', '-y', '0', '0x36', '0x23', '0']) time.sleep(1) - os.system('i2cset -y 0 0x36 0x23 1') + subprocess.call(['i2cset', '-y', '0', '0x36', '0x23', '1']) if __name__ == '__main__': main() diff --git a/device/centec/x86_64-centec_v682_48y8c-r0/plugins/led_control.py b/device/centec/x86_64-centec_v682_48y8c-r0/plugins/led_control.py index 973a9354fb..9e9426d455 100644 --- a/device/centec/x86_64-centec_v682_48y8c-r0/plugins/led_control.py +++ b/device/centec/x86_64-centec_v682_48y8c-r0/plugins/led_control.py @@ -166,11 +166,11 @@ class LedControl(LedControlBase): def _initSystemLed(self): try: - cmd = 'i2cset -y 0 0x36 0x2 0x5' - Popen(cmd, shell=True) + cmd = ['i2cset', '-y', '0', '0x36', '0x2', '0x5'] + Popen(cmd) DBG_PRINT("init system led to normal") - cmd = 'i2cset -y 0 0x36 0x3 0x1' - Popen(cmd, shell=True) + cmd = ['i2cset', '-y', '0', '0x36', '0x3', '0x1'] + Popen(cmd) DBG_PRINT("init idn led to off") except IOError as e: DBG_PRINT(str(e)) diff --git a/device/centec/x86_64-centec_v682_48y8c-r0/plugins/psuutil.py b/device/centec/x86_64-centec_v682_48y8c-r0/plugins/psuutil.py index 9e311d9b4f..1a178a3853 100644 --- a/device/centec/x86_64-centec_v682_48y8c-r0/plugins/psuutil.py +++ b/device/centec/x86_64-centec_v682_48y8c-r0/plugins/psuutil.py @@ -40,8 +40,8 @@ class PsuUtil(PsuBase): if index is None: return False - cmd = 'i2cget -y 0 0x36 0x1e' - status = int(Popen(cmd, stdout=PIPE, stderr=STDOUT, shell=True).stdout.readline(), 16) + cmd = ['i2cget', '-y', '0', '0x36', '0x1e'] + status = int(Popen(cmd, stdout=PIPE, stderr=STDOUT).stdout.readline(), 16) powergood = ((status & (1 << (3 * (index - 1) + 2))) != 0) return powergood @@ -56,7 +56,7 @@ class PsuUtil(PsuBase): if index is None: return False - cmd = 'i2cget -y 0 0x36 0x1e' - status = int(Popen(cmd, stdout=PIPE, stderr=STDOUT, shell=True).stdout.readline(), 16) + cmd = ['i2cget', '-y', '0', '0x36', '0x1e'] + status = int(Popen(cmd, stdout=PIPE, stderr=STDOUT).stdout.readline(), 16) presence = ((status & (1 << (3 * (index - 1) + 1))) == 0) return presence diff --git a/device/centec/x86_64-ew_es6220_x48q2h4-r0/plugins/psuutil.py b/device/centec/x86_64-ew_es6220_x48q2h4-r0/plugins/psuutil.py index d55f711594..1e31de9972 100644 --- a/device/centec/x86_64-ew_es6220_x48q2h4-r0/plugins/psuutil.py +++ b/device/centec/x86_64-ew_es6220_x48q2h4-r0/plugins/psuutil.py @@ -1,4 +1,4 @@ -import os.path +import subprocess try: from sonic_psu.psu_base import PsuBase @@ -14,7 +14,7 @@ class PsuUtil(PsuBase): self.psu_path = "/sys/bus/i2c/devices/{}-0058/" self.psu_oper_status = "in1_input" - self.psu_presence = "i2cget -y {} 0x50 0x00" + self.psu_presence = ["i2cget", "-y", "", "0x50", "0x00"] def get_num_psus(self): """ @@ -46,8 +46,9 @@ class PsuUtil(PsuBase): Base_bus_number = 39 status = 0 try: - p = os.popen(self.psu_presence.format(index + Base_bus_number) + "> /dev/null 2>&1") - if p.readline() != None: + self.psu_presence[2] = str(index + Base_bus_number) + p = subprocess.Popen(self.psu_presence) + if p.stdout.readline() is not None: status = 1 p.close() except IOError: 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 2aced92016..28a6940055 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 @@ -5,7 +5,6 @@ try: import time - import os from sonic_sfp.sfputilbase import SfpUtilBase except ImportError as e: raise ImportError("%s - required module not found" % str(e)) @@ -47,32 +46,6 @@ class SfpUtil(SfpUtilBase): SfpUtilBase.__init__(self) - def get_presence(self, port_name): - # 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_key = (port_num - 1)/8 - 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) - - if cpld_value & cpld_mask == 0: - return True - else: - return False - def get_low_power_mode(self, port_num): ''' # Check for invalid port_num