[device/accton] Remove the use of python pickle package (#5475)

Pickle is applied to save the order of i2c adapters at installation.
With pickle removed, it just checks the order of i2c buses every time it needs.
This commit is contained in:
Roy Lee 2020-11-05 08:24:53 +08:00 committed by GitHub
parent d3262d10f7
commit ce6286eb84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 47 deletions

View File

@ -5,7 +5,6 @@
try: try:
import time import time
import os import os
import pickle
from ctypes import create_string_buffer from ctypes import create_string_buffer
from sonic_sfp.sfputilbase import SfpUtilBase from sonic_sfp.sfputilbase import SfpUtilBase
except ImportError as e: except ImportError as e:
@ -83,9 +82,6 @@ class SfpUtil(SfpUtilBase):
#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): def update_i2c_order(self):
if os.path.exists("/tmp/accton_util.p"):
self.I2C_BUS_ORDER = pickle.load(open("/tmp/accton_util.p", "rb"))
else:
if self.I2C_BUS_ORDER < 0: if self.I2C_BUS_ORDER < 0:
eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom" eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom"
if os.path.exists(eeprom_path): if os.path.exists(eeprom_path):
@ -285,4 +281,3 @@ class SfpUtil(SfpUtilBase):
else: else:
return True, {} return True, {}
return False, {} return False, {}

View File

@ -5,7 +5,6 @@
try: try:
import time import time
import os import os
import pickle
from ctypes import create_string_buffer from ctypes import create_string_buffer
from sonic_sfp.sfputilbase import SfpUtilBase from sonic_sfp.sfputilbase import SfpUtilBase
except ImportError as e: except ImportError as e:
@ -132,9 +131,6 @@ class SfpUtil(SfpUtilBase):
#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): def update_i2c_order(self):
if os.path.exists("/tmp/accton_util.p"):
self.I2C_BUS_ORDER = pickle.load(open("/tmp/accton_util.p", "rb"))
else:
if self.I2C_BUS_ORDER < 0: if self.I2C_BUS_ORDER < 0:
eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom" eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom"
if os.path.exists(eeprom_path): if os.path.exists(eeprom_path):

View File

@ -35,7 +35,6 @@ import sys, getopt
import logging import logging
import re import re
import time import time
import pickle
from collections import namedtuple from collections import namedtuple
PROJECT_NAME = 'as5712_54x' PROJECT_NAME = 'as5712_54x'
@ -295,29 +294,25 @@ def i2c_order_check():
# i2c bus 0 and 1 might be installed in different order. # i2c bus 0 and 1 might be installed in different order.
# Here check if 0x70 is exist @ i2c-0 # Here check if 0x70 is exist @ i2c-0
tmp = "echo pca9548 0x70 > /sys/bus/i2c/devices/i2c-1/new_device" tmp = "echo pca9548 0x70 > /sys/bus/i2c/devices/i2c-1/new_device"
status, output = log_os_system(tmp, 0) log_os_system(tmp, 0)
if not device_exist(): if not device_exist():
order = 1 order = 1
else: else:
order = 0 order = 0
tmp = "echo 0x70 > /sys/bus/i2c/devices/i2c-1/delete_device" tmp = "echo 0x70 > /sys/bus/i2c/devices/i2c-1/delete_device"
status, output = log_os_system(tmp, 0) log_os_system(tmp, 0)
return order return order
def update_i2c_order(): def update_i2c_order():
global I2C_BUS_ORDER global I2C_BUS_ORDER
order = i2c_order_check() order = i2c_order_check()
pickle.dump(order, open("/tmp/accton_util.p", "wb")) # save it
I2C_BUS_ORDER = order I2C_BUS_ORDER = order
print "[%s]Detected I2C_BUS_ORDER:%d" % (os.path.basename(__file__), I2C_BUS_ORDER) print "[%s]Detected I2C_BUS_ORDER:%d" % (os.path.basename(__file__), I2C_BUS_ORDER)
def get_i2c_order(): def get_i2c_order():
global I2C_BUS_ORDER global I2C_BUS_ORDER
if I2C_BUS_ORDER < 0: if I2C_BUS_ORDER < 0:
if os.path.exists("/tmp/accton_util.p"):
I2C_BUS_ORDER = pickle.load(open("/tmp/accton_util.p", "rb"))
else:
update_i2c_order() update_i2c_order()
def device_install(): def device_install():
@ -369,10 +364,7 @@ def device_install():
def device_uninstall(): def device_uninstall():
global FORCE global FORCE
global I2C_BUS_ORDER
get_i2c_order()
order = I2C_BUS_ORDER
for i in range(0,len(sfp_map)): for i in range(0,len(sfp_map)):
target = "/sys/bus/i2c/devices/i2c-"+str(sfp_map[i])+"/delete_device" target = "/sys/bus/i2c/devices/i2c-"+str(sfp_map[i])+"/delete_device"
status, output =log_os_system("echo 0x50 > "+ target, 1) status, output =log_os_system("echo 0x50 > "+ target, 1)
@ -380,7 +372,8 @@ def device_uninstall():
print output print output
if FORCE == 0: if FORCE == 0:
return status return status
status, output = log_os_system("ls /sys/bus/i2c/devices/1-0070", 0)
order = 0 if (status == 0) else 1
if order == 0: if order == 0:
nodelist = mknod nodelist = mknod
else: else:

View File

@ -35,7 +35,6 @@ import sys, getopt
import logging import logging
import re import re
import time import time
import pickle
from collections import namedtuple from collections import namedtuple
PROJECT_NAME = 'as5812_54x' PROJECT_NAME = 'as5812_54x'
@ -295,29 +294,25 @@ def i2c_order_check():
# i2c bus 0 and 1 might be installed in different order. # i2c bus 0 and 1 might be installed in different order.
# Here check if 0x70 is exist @ i2c-0 # Here check if 0x70 is exist @ i2c-0
tmp = "echo pca9548 0x70 > /sys/bus/i2c/devices/i2c-1/new_device" tmp = "echo pca9548 0x70 > /sys/bus/i2c/devices/i2c-1/new_device"
status, output = log_os_system(tmp, 0) log_os_system(tmp, 0)
if not device_exist(): if not device_exist():
order = 1 order = 1
else: else:
order = 0 order = 0
tmp = "echo 0x70 > /sys/bus/i2c/devices/i2c-1/delete_device" tmp = "echo 0x70 > /sys/bus/i2c/devices/i2c-1/delete_device"
status, output = log_os_system(tmp, 0) log_os_system(tmp, 0)
return order return order
def update_i2c_order(): def update_i2c_order():
global I2C_BUS_ORDER global I2C_BUS_ORDER
order = i2c_order_check() order = i2c_order_check()
pickle.dump(order, open("/tmp/accton_util.p", "wb")) # save it
I2C_BUS_ORDER = order I2C_BUS_ORDER = order
print "[%s]Detected I2C_BUS_ORDER:%d" % (os.path.basename(__file__), I2C_BUS_ORDER) print "[%s]Detected I2C_BUS_ORDER:%d" % (os.path.basename(__file__), I2C_BUS_ORDER)
def get_i2c_order(): def get_i2c_order():
global I2C_BUS_ORDER global I2C_BUS_ORDER
if I2C_BUS_ORDER < 0: if I2C_BUS_ORDER < 0:
if os.path.exists("/tmp/accton_util.p"):
I2C_BUS_ORDER = pickle.load(open("/tmp/accton_util.p", "rb"))
else:
update_i2c_order() update_i2c_order()
def device_install(): def device_install():
@ -369,10 +364,7 @@ def device_install():
def device_uninstall(): def device_uninstall():
global FORCE global FORCE
global I2C_BUS_ORDER
get_i2c_order()
order = I2C_BUS_ORDER
for i in range(0,len(sfp_map)): for i in range(0,len(sfp_map)):
target = "/sys/bus/i2c/devices/i2c-"+str(sfp_map[i])+"/delete_device" target = "/sys/bus/i2c/devices/i2c-"+str(sfp_map[i])+"/delete_device"
status, output =log_os_system("echo 0x50 > "+ target, 1) status, output =log_os_system("echo 0x50 > "+ target, 1)
@ -380,7 +372,8 @@ def device_uninstall():
print output print output
if FORCE == 0: if FORCE == 0:
return status return status
status, output = log_os_system("ls /sys/bus/i2c/devices/1-0070", 0)
order = 0 if (status == 0) else 1
if order == 0: if order == 0:
nodelist = mknod nodelist = mknod
else: else: