Skip to content

Commit 31ca0ea

Browse files
authored
Remove shell=True (#313)
Signed-off-by: maipbui <[email protected]> Signed-off-by: maipbui <[email protected]>
1 parent b26aa5e commit 31ca0ea

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

sonic_platform_base/sonic_pcie/pcie_common.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ def get_pcie_device(self):
3939
pciList = []
4040
p1 = "^(\w+):(\w+)\.(\w)\s(.*)\s*\(*.*\)*"
4141
p2 = "^.*:.*:.*:(\w+)\s*\(*.*\)*"
42-
command1 = "sudo lspci"
43-
command2 = "sudo lspci -n"
42+
command1 = ["sudo", "lspci"]
43+
command2 = ["sudo", "lspci", "-n"]
4444
# run command 1
45-
proc1 = subprocess.Popen(command1, shell=True, universal_newlines=True, stdout=subprocess.PIPE)
45+
proc1 = subprocess.Popen(command1, universal_newlines=True, stdout=subprocess.PIPE)
4646
output1 = proc1.stdout.readlines()
4747
(out, err) = proc1.communicate()
4848
# run command 2
49-
proc2 = subprocess.Popen(command2, shell=True, universal_newlines=True, stdout=subprocess.PIPE)
49+
proc2 = subprocess.Popen(command2, universal_newlines=True, stdout=subprocess.PIPE)
5050
output2 = proc2.stdout.readlines()
5151
(out, err) = proc2.communicate()
5252

tests/pcie_common_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ class TestPcieCommon:
131131
def test_get_pcie_devices(self, subprocess_popen_mock):
132132

133133
def subprocess_popen_side_effect(*args, **kwargs):
134-
if args[0] == 'sudo lspci':
134+
if args[0] == ['sudo', 'lspci']:
135135
output = lspci_output.splitlines()
136-
elif args[0] == 'sudo lspci -n':
136+
elif args[0] == ['sudo', 'lspci', '-n']:
137137
output = lspci_ID_output.splitlines()
138138

139139
popen_mock = mock.Mock()

0 commit comments

Comments
 (0)