48
48
SYSTEM_READY = 'system_become_ready'
49
49
SYSTEM_FAIL = 'system_fail'
50
50
51
- GET_PLATFORM_CMD = "sonic-cfggen -d -v DEVICE_METADATA.localhost.platform"
51
+ GET_PLATFORM_CMD = [ "sonic-cfggen" , "-d" , "-v" , " DEVICE_METADATA.localhost.platform"]
52
52
53
53
# Ethernet<n> <=> sfp<n+SFP_PORT_NAME_OFFSET>
54
54
SFP_PORT_NAME_OFFSET = 0
@@ -110,7 +110,7 @@ def port_to_eeprom_mapping(self):
110
110
raise Exception ()
111
111
112
112
def get_port_position_tuple_by_platform_name (self ):
113
- p = subprocess .Popen (GET_PLATFORM_CMD , shell = True , universal_newlines = True , stdout = subprocess .PIPE )
113
+ p = subprocess .Popen (GET_PLATFORM_CMD , universal_newlines = True , stdout = subprocess .PIPE )
114
114
out , err = p .communicate ()
115
115
position_tuple = port_position_tuple_list [platform_dict [out .rstrip ('\n ' )]]
116
116
return position_tuple
@@ -136,9 +136,9 @@ def get_presence(self, port_num):
136
136
port_num += SFP_PORT_NAME_OFFSET
137
137
sfpname = SFP_PORT_NAME_CONVENTION .format (port_num )
138
138
139
- ethtool_cmd = "ethtool -m {} 2>/dev/null" . format ( sfpname )
139
+ ethtool_cmd = [ "ethtool" , "-m" , sfpname ]
140
140
try :
141
- proc = subprocess .Popen (ethtool_cmd , stdout = subprocess .PIPE , shell = True , universal_newlines = True , stderr = subprocess .STDOUT )
141
+ proc = subprocess .Popen (ethtool_cmd , stdout = subprocess .PIPE , universal_newlines = True , stderr = subprocess .DEVNULL )
142
142
stdout = proc .communicate ()[0 ]
143
143
proc .wait ()
144
144
result = stdout .rstrip ('\n ' )
@@ -155,10 +155,10 @@ def get_low_power_mode(self, port_num):
155
155
if port_num < self .port_start or port_num > self .port_end :
156
156
return False
157
157
158
- lpm_cmd = "docker exec syncd python /usr/share/sonic/platform/plugins/sfplpmget.py {}" . format (port_num )
158
+ lpm_cmd = [ "docker" , " exec" , " syncd" , " python" , " /usr/share/sonic/platform/plugins/sfplpmget.py" , str (port_num )]
159
159
160
160
try :
161
- output = subprocess .check_output (lpm_cmd , shell = True , universal_newlines = True )
161
+ output = subprocess .check_output (lpm_cmd , universal_newlines = True )
162
162
if 'LPM ON' in output :
163
163
return True
164
164
except subprocess .CalledProcessError as e :
@@ -178,11 +178,11 @@ def set_low_power_mode(self, port_num, lpmode):
178
178
179
179
# Compose LPM command
180
180
lpm = 'on' if lpmode else 'off'
181
- lpm_cmd = "docker exec syncd python /usr/share/sonic/platform/plugins/sfplpmset.py {} {}" . format (port_num , lpm )
181
+ lpm_cmd = [ "docker" , " exec" , " syncd" , " python" , " /usr/share/sonic/platform/plugins/sfplpmset.py" , str (port_num ) , lpm ]
182
182
183
183
# Set LPM
184
184
try :
185
- subprocess .check_output (lpm_cmd , shell = True , universal_newlines = True )
185
+ subprocess .check_output (lpm_cmd , universal_newlines = True )
186
186
except subprocess .CalledProcessError as e :
187
187
print ("Error! Unable to set LPM for {}, rc = {}, err msg: {}" .format (port_num , e .returncode , e .output ))
188
188
return False
@@ -194,10 +194,10 @@ def reset(self, port_num):
194
194
if port_num < self .port_start or port_num > self .port_end :
195
195
return False
196
196
197
- lpm_cmd = "docker exec syncd python /usr/share/sonic/platform/plugins/sfpreset.py {}" . format (port_num )
197
+ lpm_cmd = [ "docker" , " exec" , " syncd" , " python" , " /usr/share/sonic/platform/plugins/sfpreset.py" , str (port_num )]
198
198
199
199
try :
200
- subprocess .check_output (lpm_cmd , shell = True , universal_newlines = True )
200
+ subprocess .check_output (lpm_cmd , universal_newlines = True )
201
201
return True
202
202
except subprocess .CalledProcessError as e :
203
203
print ("Error! Unable to set LPM for {}, rc = {}, err msg: {}" .format (port_num , e .returncode , e .output ))
@@ -267,9 +267,9 @@ def _read_eeprom_specific_bytes_via_ethtool(self, port_num, offset, num_bytes):
267
267
sfpname = SFP_PORT_NAME_CONVENTION .format (port_num )
268
268
269
269
eeprom_raw = []
270
- ethtool_cmd = "ethtool -m {} hex on offset {} length {}" . format ( sfpname , offset , num_bytes )
270
+ ethtool_cmd = [ "ethtool" , "-m" , sfpname , " hex" , "on" , " offset" , str ( offset ), "length" , str ( num_bytes )]
271
271
try :
272
- output = subprocess .check_output (ethtool_cmd , shell = True , universal_newlines = True )
272
+ output = subprocess .check_output (ethtool_cmd , universal_newlines = True )
273
273
output_lines = output .splitlines ()
274
274
first_line_raw = output_lines [0 ]
275
275
if "Offset" in first_line_raw :
0 commit comments