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

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

Merged
merged 1 commit into from
Nov 5, 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
19 changes: 7 additions & 12 deletions device/accton/x86_64-accton_as5812_54t-r0/plugins/sfputil.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
try:
import time
import os
import pickle
from ctypes import create_string_buffer
from sonic_sfp.sfputilbase import SfpUtilBase
except ImportError as e:
Expand Down Expand Up @@ -83,16 +82,13 @@ def __init__(self):

#Two i2c buses might get flipped order, check them both.
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:
eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom"
if os.path.exists(eeprom_path):
self.I2C_BUS_ORDER = 0
eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom"
if os.path.exists(eeprom_path):
self.I2C_BUS_ORDER = 1
if self.I2C_BUS_ORDER < 0:
eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom"
if os.path.exists(eeprom_path):
self.I2C_BUS_ORDER = 0
eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom"
if os.path.exists(eeprom_path):
self.I2C_BUS_ORDER = 1
return self.I2C_BUS_ORDER

def get_presence(self, port_num):
Expand Down Expand Up @@ -285,4 +281,3 @@ def get_transceiver_change_event(self, timeout=2000):
else:
return True, {}
return False, {}

18 changes: 7 additions & 11 deletions device/accton/x86_64-accton_as5812_54x-r0/plugins/sfputil.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
try:
import time
import os
import pickle
from ctypes import create_string_buffer
from sonic_sfp.sfputilbase import SfpUtilBase
except ImportError as e:
Expand Down Expand Up @@ -132,16 +131,13 @@ def __init__(self):

#Two i2c buses might get flipped order, check them both.
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:
eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom"
if os.path.exists(eeprom_path):
self.I2C_BUS_ORDER = 0
eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom"
if os.path.exists(eeprom_path):
self.I2C_BUS_ORDER = 1
if self.I2C_BUS_ORDER < 0:
eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom"
if os.path.exists(eeprom_path):
self.I2C_BUS_ORDER = 0
eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom"
if os.path.exists(eeprom_path):
self.I2C_BUS_ORDER = 1
return self.I2C_BUS_ORDER

def get_presence(self, port_num):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import logging
import re
import time
import pickle
from collections import namedtuple

PROJECT_NAME = 'as5712_54x'
Expand Down Expand Up @@ -295,30 +294,26 @@ def i2c_order_check():
# i2c bus 0 and 1 might be installed in different order.
# Here check if 0x70 is exist @ i2c-0
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():
order = 1
else:
order = 0
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

def update_i2c_order():
global I2C_BUS_ORDER

order = i2c_order_check()
pickle.dump(order, open("/tmp/accton_util.p", "wb")) # save it
I2C_BUS_ORDER = order
print "[%s]Detected I2C_BUS_ORDER:%d" % (os.path.basename(__file__), I2C_BUS_ORDER)

def get_i2c_order():
global I2C_BUS_ORDER
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():
global FORCE
Expand Down Expand Up @@ -369,18 +364,16 @@ def device_install():

def device_uninstall():
global FORCE
global I2C_BUS_ORDER

get_i2c_order()
order = I2C_BUS_ORDER
for i in range(0,len(sfp_map)):
target = "/sys/bus/i2c/devices/i2c-"+str(sfp_map[i])+"/delete_device"
status, output =log_os_system("echo 0x50 > "+ target, 1)
if status:
print output
if FORCE == 0:
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:
nodelist = mknod
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import logging
import re
import time
import pickle
from collections import namedtuple

PROJECT_NAME = 'as5812_54x'
Expand Down Expand Up @@ -295,30 +294,26 @@ def i2c_order_check():
# i2c bus 0 and 1 might be installed in different order.
# Here check if 0x70 is exist @ i2c-0
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():
order = 1
else:
order = 0
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

def update_i2c_order():
global I2C_BUS_ORDER

order = i2c_order_check()
pickle.dump(order, open("/tmp/accton_util.p", "wb")) # save it
I2C_BUS_ORDER = order
print "[%s]Detected I2C_BUS_ORDER:%d" % (os.path.basename(__file__), I2C_BUS_ORDER)

def get_i2c_order():
global I2C_BUS_ORDER
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():
global FORCE
Expand Down Expand Up @@ -369,18 +364,16 @@ def device_install():

def device_uninstall():
global FORCE
global I2C_BUS_ORDER

get_i2c_order()
order = I2C_BUS_ORDER
for i in range(0,len(sfp_map)):
target = "/sys/bus/i2c/devices/i2c-"+str(sfp_map[i])+"/delete_device"
status, output =log_os_system("echo 0x50 > "+ target, 1)
if status:
print output
if FORCE == 0:
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:
nodelist = mknod
else:
Expand Down