26
26
import sys
27
27
import subprocess
28
28
import click
29
- import xml .etree .ElementTree as ET
29
+ from shlex import join
30
+ from lxml import etree as ET
30
31
from sonic_py_common import device_info
31
32
except ImportError as e :
32
33
raise ImportError ("%s - required module not found" % str (e ))
@@ -46,9 +47,9 @@ def run_command(command, display_cmd=False, ignore_error=False, print_to_console
46
47
"""Run bash command and print output to stdout
47
48
"""
48
49
if display_cmd == True :
49
- click .echo (click .style ("Running command: " , fg = 'cyan' ) + click .style (command , fg = 'green' ))
50
+ click .echo (click .style ("Running command: " , fg = 'cyan' ) + click .style (join ( command ) , fg = 'green' ))
50
51
51
- proc = subprocess .Popen (command , shell = True , text = True , stdout = subprocess .PIPE )
52
+ proc = subprocess .Popen (command , text = True , stdout = subprocess .PIPE )
52
53
(out , err ) = proc .communicate ()
53
54
54
55
if len (out ) > 0 and print_to_console :
@@ -70,17 +71,17 @@ def mlnx():
70
71
# get current status of sniffer from conf file
71
72
def sniffer_status_get (env_variable_name ):
72
73
enabled = False
73
- command = "docker exec {} bash -c 'touch {}'" .format (CONTAINER_NAME , SNIFFER_CONF_FILE )
74
+ command = [ "docker" , " exec" , CONTAINER_NAME , " bash" , "-c" , 'touch {}' .format (SNIFFER_CONF_FILE )]
74
75
run_command (command )
75
- command = 'docker cp {} {}' . format ( SNIFFER_CONF_FILE_IN_CONTAINER , TMP_SNIFFER_CONF_FILE )
76
+ command = [ 'docker' , 'cp' , SNIFFER_CONF_FILE_IN_CONTAINER , TMP_SNIFFER_CONF_FILE ]
76
77
run_command (command )
77
78
conf_file = open (TMP_SNIFFER_CONF_FILE , 'r' )
78
79
for env_variable_string in conf_file :
79
80
if env_variable_string .find (env_variable_name ) >= 0 :
80
81
enabled = True
81
82
break
82
83
conf_file .close ()
83
- command = 'rm -rf {}' . format ( TMP_SNIFFER_CONF_FILE )
84
+ command = [ 'rm' , ' -rf' , TMP_SNIFFER_CONF_FILE ]
84
85
run_command (command )
85
86
return enabled
86
87
@@ -97,10 +98,8 @@ def is_issu_status_enabled():
97
98
# Get the SAI XML path from sai.profile
98
99
sai_profile_path = '/{}/sai.profile' .format (HWSKU_PATH )
99
100
100
- DOCKER_CAT_COMMAND = 'docker exec {container_name} cat {path}'
101
-
102
- command = DOCKER_CAT_COMMAND .format (container_name = CONTAINER_NAME , path = sai_profile_path )
103
- sai_profile_content , _ = run_command (command , print_to_console = False )
101
+ DOCKER_CAT_COMMAND = ['docker' , 'exec' , CONTAINER_NAME , 'cat' , sai_profile_path ]
102
+ sai_profile_content , _ = run_command (DOCKER_CAT_COMMAND , print_to_console = False )
104
103
105
104
sai_profile_kvs = {}
106
105
@@ -117,8 +116,8 @@ def is_issu_status_enabled():
117
116
sys .exit (1 )
118
117
119
118
# Get ISSU from SAI XML
120
- command = DOCKER_CAT_COMMAND . format ( container_name = CONTAINER_NAME , path = sai_xml_path )
121
- sai_xml_content , _ = run_command (command , print_to_console = False )
119
+ DOCKER_CAT_COMMAND = [ 'docker' , 'exec' , CONTAINER_NAME , 'cat' , sai_xml_path ]
120
+ sai_xml_content , _ = run_command (DOCKER_CAT_COMMAND , print_to_console = False )
122
121
123
122
try :
124
123
root = ET .fromstring (sai_xml_content )
0 commit comments