Skip to content

Commit 2b7cf6e

Browse files
authored
Merge pull request #100 from konstruktoid/vagrant_validate
add `vagrant validate`
2 parents b8950f0 + aee16f3 commit 2b7cf6e

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

tests/test_vagrant.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,14 @@ def test_vm_lifecycle(vm_dir):
294294
assert v.NOT_CREATED == v.status()[0].state
295295

296296

297+
def test_valid_config(vm_dir):
298+
v = vagrant.Vagrant(vm_dir)
299+
v.up()
300+
validation = v.validate(vm_dir)
301+
302+
assert validation.returncode == 0
303+
304+
297305
def test_vm_config(vm_dir):
298306
"""
299307
Test methods retrieving ssh config settings, like user, hostname, and port.

vagrant/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,20 @@ def plugin_list(self):
876876
output = self._run_vagrant_command(["plugin", "list", "--machine-readable"])
877877
return self._parse_plugin_list(output)
878878

879+
def validate(self, directory):
880+
"""
881+
This command validates present Vagrantfile.
882+
"""
883+
validate = subprocess.run(
884+
["vagrant", "validate"],
885+
cwd=directory,
886+
check=True,
887+
stdout=subprocess.PIPE,
888+
stderr=subprocess.PIPE,
889+
)
890+
891+
return validate
892+
879893
def _parse_plugin_list(self, output):
880894
"""
881895
Remove Vagrant from the equation for unit testing.

0 commit comments

Comments
 (0)