Skip to content

Commit 94a2b0f

Browse files
authored
configure vbguest and validate Vagrantfile during lifecycle test (#115)
1 parent 579d70e commit 94a2b0f

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

tests/test_vagrant.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,10 @@ def test_vm_status(vm_dir):
282282

283283

284284
def test_vm_lifecycle(vm_dir):
285-
"""Test methods controlling the VM - init(), up(), halt(), destroy()."""
285+
"""Test methods controlling the VM - init(), up(), suspend(), halt(), destroy()."""
286+
VAGRANT_DIR = f"{os.environ['HOME']}/.vagrant.d"
287+
VAGRANTFILE_CREATED = False
288+
286289
v = vagrant.Vagrant(vm_dir)
287290

288291
# Test init by removing Vagrantfile, since v.init() will create one.
@@ -291,9 +294,24 @@ def test_vm_lifecycle(vm_dir):
291294
except FileNotFoundError:
292295
pass
293296

297+
try:
298+
os.mkdir(VAGRANT_DIR, mode=0o755)
299+
except FileExistsError:
300+
pass
301+
302+
if not os.path.isfile(f"{VAGRANT_DIR}/Vagrantfile"):
303+
with open(f"{VAGRANT_DIR}/Vagrantfile", "w", encoding="UTF-8") as config:
304+
config.write(
305+
'Vagrant.configure("2") do |config|\n config.vbguest.auto_update = false if Vagrant.has_plugin?("vagrant-vbguest")\nend\n'
306+
)
307+
VAGRANTFILE_CREATED = True
308+
294309
v.init(TEST_BOX_NAME)
295310
assert v.NOT_CREATED == v.status()[0].state
296311

312+
validation = v.validate(vm_dir)
313+
assert validation.returncode == 0
314+
297315
v.up()
298316
assert v.RUNNING == v.status()[0].state
299317

@@ -306,12 +324,14 @@ def test_vm_lifecycle(vm_dir):
306324
v.destroy()
307325
assert v.NOT_CREATED == v.status()[0].state
308326

327+
if VAGRANTFILE_CREATED:
328+
os.unlink(f"{VAGRANT_DIR}/Vagrantfile")
329+
309330

310331
def test_valid_config(vm_dir):
311332
v = vagrant.Vagrant(vm_dir)
312333
v.up()
313334
validation = v.validate(vm_dir)
314-
315335
assert validation.returncode == 0
316336

317337

0 commit comments

Comments
 (0)