Skip to content
This repository has been archived by the owner on Jan 6, 2023. It is now read-only.

Commit

Permalink
molecule_vagrant/modules/vagrant.py: Use vagrant.validate()
Browse files Browse the repository at this point in the history
python-vagrant 1.0.0 adds a new validate() function, so use it
instead of the open coded version here. [ So, bump minimal version
to 1.0.0 ].

While at it, add a small test case for it to make sure it's handled
properly as I managed to get it wrong in my first version of this
patch.

Signed-off-by: Arnaud Patard <apatard@hupstream.com>
  • Loading branch information
apatard committed Apr 12, 2022
1 parent 4285141 commit 23c49a1
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 12 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ jobs:
platform: ubuntu-latest
skip_vagrant: true
- tox_env: py38,py38-devel
PREFIX: PYTEST_REQPASS=9
PREFIX: PYTEST_REQPASS=10
platform: macos-10.15
python_version: "3.8"
- tox_env: py39,py39-devel
PREFIX: PYTEST_REQPASS=9
PREFIX: PYTEST_REQPASS=10
platform: macos-10.15
python_version: "3.9"
- tox_env: py310,py310-devel
PREFIX: PYTEST_REQPASS=9
PREFIX: PYTEST_REQPASS=10
platform: macos-10.15
python_version: "3.10"
- tox_env: packaging
Expand Down
12 changes: 4 additions & 8 deletions molecule_vagrant/modules/vagrant.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,15 +559,11 @@ def _write_vagrantfile(self):

def _write_configs(self):
self._write_vagrantfile()
valid = subprocess.run(
["vagrant", "validate"],
cwd=self._config["workdir"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
if valid.returncode != 0:
try:
self._vagrant.validate(self._config["workdir"])
except subprocess.CalledProcessError as e:
self._module.fail_json(
msg="Failed to validate generated Vagrantfile: {}".format(valid.stderr)
msg=f"Failed to validate generated Vagrantfile: {e.stderr}"
)

def _get_vagrant(self):
Expand Down
14 changes: 14 additions & 0 deletions molecule_vagrant/test/functional/test_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@ def test_command_init_scenario(temp_dir):
assert result.returncode == 0


def test_invalide_settings(temp_dir):

scenario_directory = os.path.join(
os.path.dirname(util.abs_path(__file__)), os.path.pardir, "scenarios"
)

with change_dir_to(scenario_directory):
cmd = ["molecule", "create", "--scenario-name", "invalid"]
result = run_command(cmd)
assert result.returncode == 2

assert "Failed to validate generated Vagrantfile" in result.stdout


@pytest.mark.parametrize(
"scenario",
[
Expand Down
11 changes: 11 additions & 0 deletions molecule_vagrant/test/scenarios/molecule/invalid/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
- name: Converge
hosts: all
gather_facts: false
become: true
tasks:
- name: sample task # noqa 305
ansible.builtin.shell:
cmd: uname
warn: false
changed_when: false
11 changes: 11 additions & 0 deletions molecule_vagrant/test/scenarios/molecule/invalid/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
dependency:
name: galaxy
driver:
name: vagrant
provider:
name: libvirt
platforms:
- name: instance/foo
provisioner:
name: ansible
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ install_requires =
pyyaml >= 5.1
Jinja2 >= 2.11.3
selinux
python-vagrant
python-vagrant >= 1.0.0

[options.extras_require]
test =
Expand Down

0 comments on commit 23c49a1

Please sign in to comment.