Skip to content

Commit

Permalink
Remove shell=True (sonic-net#313)
Browse files Browse the repository at this point in the history
Signed-off-by: maipbui <[email protected]>

Signed-off-by: maipbui <[email protected]>
  • Loading branch information
maipbui authored Sep 28, 2022
1 parent b26aa5e commit 31ca0ea
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions sonic_platform_base/sonic_pcie/pcie_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ def get_pcie_device(self):
pciList = []
p1 = "^(\w+):(\w+)\.(\w)\s(.*)\s*\(*.*\)*"
p2 = "^.*:.*:.*:(\w+)\s*\(*.*\)*"
command1 = "sudo lspci"
command2 = "sudo lspci -n"
command1 = ["sudo", "lspci"]
command2 = ["sudo", "lspci", "-n"]
# run command 1
proc1 = subprocess.Popen(command1, shell=True, universal_newlines=True, stdout=subprocess.PIPE)
proc1 = subprocess.Popen(command1, universal_newlines=True, stdout=subprocess.PIPE)
output1 = proc1.stdout.readlines()
(out, err) = proc1.communicate()
# run command 2
proc2 = subprocess.Popen(command2, shell=True, universal_newlines=True, stdout=subprocess.PIPE)
proc2 = subprocess.Popen(command2, universal_newlines=True, stdout=subprocess.PIPE)
output2 = proc2.stdout.readlines()
(out, err) = proc2.communicate()

Expand Down
4 changes: 2 additions & 2 deletions tests/pcie_common_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ class TestPcieCommon:
def test_get_pcie_devices(self, subprocess_popen_mock):

def subprocess_popen_side_effect(*args, **kwargs):
if args[0] == 'sudo lspci':
if args[0] == ['sudo', 'lspci']:
output = lspci_output.splitlines()
elif args[0] == 'sudo lspci -n':
elif args[0] == ['sudo', 'lspci', '-n']:
output = lspci_ID_output.splitlines()

popen_mock = mock.Mock()
Expand Down

0 comments on commit 31ca0ea

Please sign in to comment.