Skip to content

Commit 86933da

Browse files
authored
Merge pull request #112 from apatard/shell_removal
Don't use shell to run vagrant subprocess
2 parents 9d78aac + ed923df commit 86933da

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

tests/test_vagrant.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,16 @@ def fixture_test_dir() -> Generator[str, None, None]:
7575
sys.stderr.write("test temp dir: {}\n".format(my_dir))
7676
boxes = list_box_names()
7777
if TEST_BOX_NAME not in boxes:
78-
cmd = f"{VAGRANT_EXE} box add --provider {TEST_PROVIDER} {TEST_BOX_URL}"
79-
subprocess.check_call(cmd, shell=True)
78+
cmd = [VAGRANT_EXE, "box", "add", "--provider", TEST_PROVIDER, TEST_BOX_URL]
79+
subprocess.check_call(cmd)
8080

8181
yield my_dir
8282
# Removes the directory created initially, runs once after the last test
8383
sys.stderr.write("module teardown()\n")
8484
if my_dir is not None:
8585
try:
86-
subprocess.check_call("vagrant destroy -f", cwd=my_dir, shell=True)
86+
cmd = [VAGRANT_EXE, "destroy", "-f"]
87+
subprocess.check_call(cmd, cwd=my_dir)
8788
except subprocess.CalledProcessError:
8889
pass
8990

@@ -97,9 +98,7 @@ def list_box_names():
9798
even if the `Vagrant.box_list()` implementation is broken.
9899
"""
99100
listing = compat.decode(
100-
subprocess.check_output(
101-
f"{VAGRANT_EXE} box list --machine-readable", shell=True
102-
)
101+
subprocess.check_output([VAGRANT_EXE, "box", "list", "--machine-readable"])
103102
)
104103
box_names = []
105104
for line in listing.splitlines():
@@ -132,7 +131,7 @@ def fixture_vm_dir(request: FixtureRequest, test_dir) -> Generator[str, None, No
132131
# It is not an error if a VM has already been destroyed.
133132
try:
134133
# Try to destroy any vagrant box that might be running.
135-
subprocess.check_call(f"{VAGRANT_EXE} destroy -f", cwd=test_dir, shell=True)
134+
subprocess.check_call([VAGRANT_EXE, "destroy", "-f"], cwd=test_dir)
136135
except subprocess.CalledProcessError:
137136
pass
138137
finally:
@@ -249,20 +248,20 @@ def test_vm_status(vm_dir):
249248
assert (
250249
v.NOT_CREATED == v.status()[0].state
251250
), "Before going up status should be vagrant.NOT_CREATED"
252-
command = f"{VAGRANT_EXE} up"
253-
subprocess.check_call(command, cwd=vm_dir, shell=True)
251+
command = [VAGRANT_EXE, "up"]
252+
subprocess.check_call(command, cwd=vm_dir)
254253
assert (
255254
v.RUNNING in v.status()[0].state
256255
), "After going up status should be vagrant.RUNNING"
257256

258-
command = f"{VAGRANT_EXE} halt"
259-
subprocess.check_call(command, cwd=vm_dir, shell=True)
257+
command = [VAGRANT_EXE, "halt"]
258+
subprocess.check_call(command, cwd=vm_dir)
260259
assert (
261260
v.POWEROFF in v.status()[0].state
262261
), "After halting status should be vagrant.POWEROFF"
263262

264-
command = f"{VAGRANT_EXE} destroy -f"
265-
subprocess.check_call(command, cwd=vm_dir, shell=True)
263+
command = [VAGRANT_EXE, "destroy", "-f"]
264+
subprocess.check_call(command, cwd=vm_dir)
266265
assert (
267266
v.NOT_CREATED in v.status()[0].state
268267
), "After destroying status should be vagrant.NOT_CREATED"
@@ -308,8 +307,8 @@ def test_vm_config(vm_dir):
308307
"""
309308
v = vagrant.Vagrant(vm_dir)
310309
v.up()
311-
command = f"{VAGRANT_EXE} ssh-config"
312-
ssh_config = compat.decode(subprocess.check_output(command, cwd=vm_dir, shell=True))
310+
command = [VAGRANT_EXE, "ssh-config"]
311+
ssh_config = compat.decode(subprocess.check_output(command, cwd=vm_dir))
313312
parsed_config = dict(
314313
line.strip().split(None, 1)
315314
for line in ssh_config.splitlines()
@@ -548,8 +547,8 @@ def test_multivm_config(vm_dir):
548547
"""
549548
v = vagrant.Vagrant(vm_dir, quiet_stdout=False, quiet_stderr=False)
550549
v.up(vm_name=VM_1)
551-
command = f"{VAGRANT_EXE} ssh-config " + VM_1
552-
ssh_config = compat.decode(subprocess.check_output(command, cwd=vm_dir, shell=True))
550+
command = [VAGRANT_EXE, "ssh-config", VM_1]
551+
ssh_config = compat.decode(subprocess.check_output(command, cwd=vm_dir))
553552
parsed_config = dict(
554553
line.strip().split(None, 1)
555554
for line in ssh_config.splitlines()

0 commit comments

Comments
 (0)