10
10
11
11
try :
12
12
import time
13
- import subprocess
14
13
from sonic_platform_base .chassis_base import ChassisBase
15
14
from sonic_platform .common import Common
16
15
from sonic_platform .sfp import Sfp
17
16
from sonic_platform .sfp import PORT_START
18
17
from sonic_platform .sfp import PORTS_IN_BLOCK
19
18
from sonic_platform .logger import logger
19
+ from sonic_py_common .general import getstatusoutput_noshell
20
20
except ImportError as e :
21
21
raise ImportError (str (e ) + "- required module not found" )
22
22
@@ -36,17 +36,17 @@ def __init__(self):
36
36
self .SFP_STATUS_INSERTED = "1"
37
37
self .SFP_STATUS_REMOVED = "0"
38
38
self .port_dict = {}
39
- self .enable_read = "i2cset -f -y 2 0x35 0x2a 0x01"
40
- self .disable_read = "i2cset -f -y 2 0x35 0x2a 0x00"
41
- self .enable_write = "i2cset -f -y 2 0x35 0x2b 0x00"
42
- self .disable_write = "i2cset -f -y 2 0x35 0x2b 0x01"
43
- self .enable_erase = "i2cset -f -y 2 0x35 0x2c 0x01"
44
- self .disable_erase = "i2cset -f -y 2 0x35 0x2c 0x00"
45
- self .read_value = "i2cget -f -y 2 0x35 0x25"
46
- self .write_value = "i2cset -f -y 2 0x35 0x21 0x0a"
47
- self .set_sys_led_cmd = "i2cset -f -y 2 0x33 0xb2 "
48
- self .get_sys_led_cmd = "i2cget -f -y 2 0x33 0xb2"
49
- self .led_status = "red"
39
+ self .enable_read = [ "i2cset" , "-f" , "-y" , "2" , " 0x35" , " 0x2a" , " 0x01"]
40
+ self .disable_read = [ "i2cset" , "-f" , "-y" , "2" , " 0x35" , " 0x2a" , " 0x00"]
41
+ self .enable_write = [ "i2cset" , "-f" , "-y" , "2" , " 0x35" , " 0x2b" , " 0x00"]
42
+ self .disable_write = [ "i2cset" , "-f" , "-y" , "2" , " 0x35" , " 0x2b" , " 0x01"]
43
+ self .enable_erase = [ "i2cset" , "-f" , "-y" , "2" , " 0x35" , " 0x2c" , " 0x01"]
44
+ self .disable_erase = [ "i2cset" , "-f" , "-y" , "2" , " 0x35" , " 0x2c" , " 0x00"]
45
+ self .read_value = [ "i2cget" , "-f" , "-y" , "2" , " 0x35" , " 0x25"]
46
+ self .write_value = [ "i2cset" , "-f" , "-y" , "2" , " 0x35" , " 0x21" , " 0x0a"]
47
+ self .set_sys_led_cmd = [ "i2cset" , "-f" , "-y" , "2" , " 0x33" , " 0xb2" ]
48
+ self .get_sys_led_cmd = [ "i2cget" , "-f" , "-y" , "2" , " 0x33" , " 0xb2"]
49
+ self .led_status = "red"
50
50
# Initialize SFP list
51
51
# sfp.py will read eeprom contents and retrive the eeprom data.
52
52
# It will also provide support sfp controls like reset and setting
@@ -210,25 +210,25 @@ def get_reboot_cause(self):
210
210
try :
211
211
is_power_loss = False
212
212
# enable read
213
- subprocess . getstatusoutput (self .disable_write )
214
- subprocess . getstatusoutput (self .enable_read )
215
- ret , log = subprocess . getstatusoutput (self .read_value )
213
+ getstatusoutput_noshell (self .disable_write )
214
+ getstatusoutput_noshell (self .enable_read )
215
+ ret , log = getstatusoutput_noshell (self .read_value )
216
216
if ret == 0 and "0x0a" in log :
217
217
is_power_loss = True
218
218
219
219
# erase i2c and e2
220
- subprocess . getstatusoutput (self .enable_erase )
220
+ getstatusoutput_noshell (self .enable_erase )
221
221
time .sleep (1 )
222
- subprocess . getstatusoutput (self .disable_erase )
222
+ getstatusoutput_noshell (self .disable_erase )
223
223
# clear data
224
- subprocess . getstatusoutput (self .enable_write )
225
- subprocess . getstatusoutput (self .disable_read )
226
- subprocess . getstatusoutput (self .disable_write )
227
- subprocess . getstatusoutput (self .enable_read )
224
+ getstatusoutput_noshell (self .enable_write )
225
+ getstatusoutput_noshell (self .disable_read )
226
+ getstatusoutput_noshell (self .disable_write )
227
+ getstatusoutput_noshell (self .enable_read )
228
228
# enable write and set data
229
- subprocess . getstatusoutput (self .enable_write )
230
- subprocess . getstatusoutput (self .disable_read )
231
- subprocess . getstatusoutput (self .write_value )
229
+ getstatusoutput_noshell (self .enable_write )
230
+ getstatusoutput_noshell (self .disable_read )
231
+ getstatusoutput_noshell (self .write_value )
232
232
if is_power_loss :
233
233
return (self .REBOOT_CAUSE_POWER_LOSS , None )
234
234
except Exception as e :
@@ -417,7 +417,8 @@ def set_status_led(self, color):
417
417
if regval is None :
418
418
print ("Invaild color input." )
419
419
return False
420
- ret , log = subprocess .getstatusoutput (self .set_sys_led_cmd + regval )
420
+ cmd = self .set_sys_led_cmd + [regval ]
421
+ ret , log = getstatusoutput_noshell (cmd )
421
422
if ret != 0 :
422
423
print ("Cannot execute %s" % self .set_sys_led_cmd + regval )
423
424
return False
@@ -431,7 +432,7 @@ def get_status_led(self):
431
432
A string, one of the valid LED color strings which could be vendor
432
433
specified.
433
434
"""
434
- ret , log = subprocess . getstatusoutput (self .get_sys_led_cmd )
435
+ ret , log = getstatusoutput_noshell (self .get_sys_led_cmd )
435
436
if ret != 0 :
436
437
print ("Cannot execute %s" % self .get_sys_led_cmd )
437
438
return False
0 commit comments