Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

configure vbguest and validate Vagrantfile during lifecycle test #115

Merged
merged 3 commits into from
Mar 31, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions tests/test_vagrant.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,10 @@ def test_vm_status(vm_dir):


def test_vm_lifecycle(vm_dir):
"""Test methods controlling the VM - init(), up(), halt(), destroy()."""
"""Test methods controlling the VM - init(), up(), suspend(), halt(), destroy()."""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the reason for removing the suspend() here ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't? I just updated the comment to include suspend().

    v.suspend()
    assert v.SAVED == v.status()[0].state

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, sorry. -ENOCOFFEE.

VAGRANT_DIR = f"{os.environ['HOME']}/.vagrant.d"
VAGRANTFILE_CREATED = False

v = vagrant.Vagrant(vm_dir)

# Test init by removing Vagrantfile, since v.init() will create one.
Expand All @@ -278,9 +281,24 @@ def test_vm_lifecycle(vm_dir):
except FileNotFoundError:
pass

try:
os.mkdir(VAGRANT_DIR, mode=0o755)
except FileExistsError:
pass

if not os.path.isfile(f"{VAGRANT_DIR}/Vagrantfile"):
with open(f"{VAGRANT_DIR}/Vagrantfile", "w", encoding="UTF-8") as config:
config.write(
'Vagrant.configure("2") do |config|\n config.vbguest.auto_update = false if Vagrant.has_plugin?("vagrant-vbguest")\nend\n'
)
VAGRANTFILE_CREATED = True

v.init(TEST_BOX_NAME)
assert v.NOT_CREATED == v.status()[0].state

validation = v.validate(vm_dir)
assert validation.returncode == 0

v.up()
assert v.RUNNING == v.status()[0].state

Expand All @@ -293,12 +311,14 @@ def test_vm_lifecycle(vm_dir):
v.destroy()
assert v.NOT_CREATED == v.status()[0].state

if VAGRANTFILE_CREATED:
os.unlink(f"{VAGRANT_DIR}/Vagrantfile")


def test_valid_config(vm_dir):
v = vagrant.Vagrant(vm_dir)
v.up()
validation = v.validate(vm_dir)

assert validation.returncode == 0


Expand Down