Skip to content

Commit

Permalink
Use functions from sonic-py-common
Browse files Browse the repository at this point in the history
Signed-off-by: maipbui <[email protected]>
  • Loading branch information
maipbui committed Sep 13, 2022
1 parent ccc7e52 commit 072d8e9
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import re
import subprocess
from sonic_sfp.sfputilbase import SfpUtilBase
from sonic_py_common.general import getstatusoutput_noshell
except ImportError as e:
raise ImportError(str(e) + "- required module not found")

Expand Down Expand Up @@ -71,12 +72,9 @@ def i2c_get(self, device_addr, offset):
status = 0
if smbus_present == 0:
x = ["i2cget", "-y", "0", hex(device_addr), hex(offset)]
p = subprocess.run(x, capture_output=True, universal_newlines=True)
cmdstatus, status = p.returncode, p.stdout
cmdstatus, status = getstatusoutput_noshell(x)
if cmdstatus != 0:
return cmdstatus
if status[-1:] == '\n':
status = status[:-1]
status = int(status, 16)
else:
bus = smbus.SMBus(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import re
import subprocess
from sonic_sfp.sfputilbase import SfpUtilBase
from sonic_py_common.general import getstatusoutput_noshell
except ImportError as e:
raise ImportError(str(e) + "- required module not found")

Expand Down Expand Up @@ -71,12 +72,9 @@ def i2c_get(self, device_addr, offset):
status = 0
if smbus_present == 0:
x = ["i2cget", "-y", "0", hex(device_addr), hex(offset)]
p = subprocess.run(x, capture_output=True, universal_newlines=True)
cmdstatus, status = p.returncode, p.stdout
cmdstatus, status = getstatusoutput_noshell(x)
if cmdstatus != 0:
return cmdstatus
if status[-1:] == '\n':
status = status[:-1]
status = int(status, 16)
else:
bus = smbus.SMBus(0)
Expand Down
12 changes: 3 additions & 9 deletions device/marvell/armhf-marvell_et6448m_52x-r0/plugins/psuutil.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import subprocess
from sonic_py_common.general import getstatusoutput_noshell

smbus_present = 1
try:
Expand Down Expand Up @@ -27,10 +27,7 @@ def get_psu_status(self, index):
if index is None:
return False
if smbus_present == 0:
p = subprocess.run(["i2cget", "-y", "0", "0x41", "0xa"], capture_output=True, universal_newlines=True) # need to verify the cpld register logic
cmdstatus, psustatus = p.returncode, p.stdout
if psustatus[-1:] == '\n':
psustatus = psustatus[:-1]
cmdstatus, psustatus = getstatusoutput_noshell(["i2cget", "-y", "0", "0x41", "0xa"])
psustatus = int(psustatus, 16)
else:
bus = smbus.SMBus(0)
Expand All @@ -53,10 +50,7 @@ def get_psu_presence(self, index):
return False

if smbus_present == 0:
p = subprocess.run(["i2cget", "-y", "0", "0x41", "0xa"], capture_output=True, universal_newlines=True) # need to verify the cpld register logic
cmdstatus, psustatus = p.returncode, p.stdout
if psustatus[-1:] == '\n':
psustatus = psustatus[:-1]
cmdstatus, psustatus = getstatusoutput_noshell(["i2cget", "-y", "0", "0x41", "0xa"])
psustatus = int(psustatus, 16)
else:
bus = smbus.SMBus(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import glob
import subprocess
from sonic_sfp.sfputilbase import SfpUtilBase
from sonic_py_common.general import getstatusoutput_noshell
except ImportError as e:
raise ImportError(str(e) + "- required module not found")

Expand Down Expand Up @@ -109,10 +110,7 @@ def get_presence(self, port_num):
pos = [1, 2, 4, 8]
bit_pos = pos[prt]
if smbus_present == 0:
proc = subprocess.run(['i2cget', '-y', '0', '0x41', '0x3'], capture_output=True, universal_newlines=True) # need to verify the cpld register logic
cmdstatus, sfpstatus = proc.returncode, proc.stdout
if sfpstatus[-1:] == '\n':
sfpstatus = sfpstatus[:-1]
cmdstatus, sfpstatus = getstatusoutput_noshell(['i2cget', '-y', '0', '0x41', '0x3'])
sfpstatus = int(sfpstatus, 16)
else:
bus = smbus.SMBus(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import re
import subprocess
from sonic_sfp.sfputilbase import SfpUtilBase
from sonic_py_common.general import getstatusoutput_noshell
except ImportError as e:
raise ImportError(str(e) + "- required module not found")

Expand Down Expand Up @@ -71,12 +72,9 @@ def i2c_get(self, device_addr, offset):
status = 0
if smbus_present == 0:
x = ["i2cget", "-y", "0", hex(device_addr), hex(offset)]
p = subprocess.run(x, capture_output=True, universal_newlines=True)
cmdstatus, status = p.returncode, p.stdout
cmdstatus, status = getstatusoutput_noshell(x)
if cmdstatus != 0:
return cmdstatus
if status[-1:] == '\n':
status = status[:-1]
status = int(status, 16)
else:
bus = smbus.SMBus(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import re
import subprocess
from sonic_sfp.sfputilbase import SfpUtilBase
from sonic_py_common.general import getstatusoutput_noshell
except ImportError as e:
raise ImportError(str(e) + "- required module not found")

Expand Down Expand Up @@ -71,12 +72,9 @@ def i2c_get(self, device_addr, offset):
status = 0
if smbus_present == 0:
x = ["i2cget", "-y", "0", hex(device_addr), hex(offset)]
p = subprocess.run(x, capture_output=True, universal_newlines=True)
cmdstatus, status = p.returncode, p.stdout
cmdstatus, status = getstatusoutput_noshell(x)
if cmdstatus != 0:
return cmdstatus
if status[-1:] == '\n':
status = status[:-1]
status = int(status, 16)
else:
bus = smbus.SMBus(0)
Expand Down

0 comments on commit 072d8e9

Please sign in to comment.