diff --git a/tests/test_vagrant.py b/tests/test_vagrant.py index fffaf7e..af8391e 100644 --- a/tests/test_vagrant.py +++ b/tests/test_vagrant.py @@ -290,6 +290,14 @@ def test_vm_lifecycle(vm_dir): assert v.NOT_CREATED == v.status()[0].state +def test_valid_config(vm_dir): + v = vagrant.Vagrant(vm_dir) + v.up() + validation = v.validate(vm_dir) + + assert validation.returncode == 0 + + def test_vm_config(vm_dir): """ Test methods retrieving ssh config settings, like user, hostname, and port. diff --git a/vagrant/__init__.py b/vagrant/__init__.py index 63f51e5..efe156f 100644 --- a/vagrant/__init__.py +++ b/vagrant/__init__.py @@ -876,6 +876,20 @@ def plugin_list(self): output = self._run_vagrant_command(["plugin", "list", "--machine-readable"]) return self._parse_plugin_list(output) + def validate(self, directory): + """ + This command validates present Vagrantfile. + """ + validate = subprocess.run( + ["vagrant", "validate"], + cwd=directory, + check=True, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + ) + + return validate + def _parse_plugin_list(self, output): """ Remove Vagrant from the equation for unit testing.