diff --git a/.gitignore b/.gitignore index 25a4804ab3..88e3b74c62 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,4 @@ tools/test-schema/node_modules site .DS_Store src/molecule/_version.py +.vscode diff --git a/src/molecule/test/b_functional/test_command.py b/src/molecule/test/b_functional/test_command.py index 8e86d87c86..b87ca05fdb 100644 --- a/src/molecule/test/b_functional/test_command.py +++ b/src/molecule/test/b_functional/test_command.py @@ -20,6 +20,7 @@ from __future__ import annotations import os +import subprocess import pytest from pytest import FixtureRequest @@ -336,6 +337,39 @@ def test_sample_collection() -> None: ) +def test_sample_collection_venv_with_gitignore() -> None: + op = subprocess.run( + "python -m venv venv \ + && source venv/bin/activate \ + && pip install ../../../../../ \ + && molecule list \ + && deactivate \ + && rm -rf source venv", + shell=True, + cwd="src/molecule/test/resources/sample-collection-venv-with-gitignore", + check=True, + ) + assert op.returncode == 0 + + +def test_sample_collection_venv_without_gitignore() -> None: + with pytest.raises(subprocess.CalledProcessError) as e: + subprocess.run( + "python -m venv venv \ + && source venv/bin/activate \ + && pip install ../../../../../ \ + && molecule list \ + && deactivate \ + && rm -rf source venv", + shell=True, + cwd="src/molecule/test/resources/sample-collection-venv-without-gitignore", + check=True, + ) + assert e.value.returncode == 1 + assert "The scenario config file" in e.value.stderr + assert "has been modified since the scenario was created" in e.value.stderr + + def test_podman() -> None: assert ( run_command( diff --git a/src/molecule/test/resources/sample-collection-venv-with-gitignore/.gitignore b/src/molecule/test/resources/sample-collection-venv-with-gitignore/.gitignore new file mode 100644 index 0000000000..ca944a00d1 --- /dev/null +++ b/src/molecule/test/resources/sample-collection-venv-with-gitignore/.gitignore @@ -0,0 +1,9 @@ +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ +source/ diff --git a/src/molecule/test/resources/sample-collection-venv-with-gitignore/extensions/molecule/default/converge.yml b/src/molecule/test/resources/sample-collection-venv-with-gitignore/extensions/molecule/default/converge.yml new file mode 100644 index 0000000000..73f7cfb3c3 --- /dev/null +++ b/src/molecule/test/resources/sample-collection-venv-with-gitignore/extensions/molecule/default/converge.yml @@ -0,0 +1,7 @@ +--- +- name: Converge + hosts: localhost + tasks: + - name: "Include sample role from current collection" + ansible.builtin.include_role: + name: acme.goodies.get_rich diff --git a/src/molecule/test/resources/sample-collection-venv-with-gitignore/extensions/molecule/default/molecule.yml b/src/molecule/test/resources/sample-collection-venv-with-gitignore/extensions/molecule/default/molecule.yml new file mode 100644 index 0000000000..1cec4936a1 --- /dev/null +++ b/src/molecule/test/resources/sample-collection-venv-with-gitignore/extensions/molecule/default/molecule.yml @@ -0,0 +1,11 @@ +--- +dependency: + name: galaxy +driver: + name: default +platforms: + - name: instance +provisioner: + name: ansible +verifier: + name: ansible diff --git a/src/molecule/test/resources/sample-collection-venv-with-gitignore/galaxy.yml b/src/molecule/test/resources/sample-collection-venv-with-gitignore/galaxy.yml new file mode 100644 index 0000000000..2a7e1164d3 --- /dev/null +++ b/src/molecule/test/resources/sample-collection-venv-with-gitignore/galaxy.yml @@ -0,0 +1,31 @@ +name: goodies +namespace: acme +version: 1.0.0 +readme: README.md +authors: + - Red Hat +description: Acme Goodies Collection +build_ignore: + - "*.egg-info" + - .DS_Store + - .eggs + - .gitignore + - .mypy_cache + - .pytest_cache + - .stestr + - .stestr.conf + - .tox + - .vscode + - MANIFEST.in + - build + - dist + - doc + - report.html + - setup.cfg + - setup.py + - "tests/unit/*.*" + - README.rst + - tox.ini + +repository: https://opendev.org/openstack/tripleo-repos +license_file: LICENSE diff --git a/src/molecule/test/resources/sample-collection-venv-with-gitignore/roles/get_rich/tasks/main.yml b/src/molecule/test/resources/sample-collection-venv-with-gitignore/roles/get_rich/tasks/main.yml new file mode 100644 index 0000000000..cf8063a148 --- /dev/null +++ b/src/molecule/test/resources/sample-collection-venv-with-gitignore/roles/get_rich/tasks/main.yml @@ -0,0 +1,3 @@ +- name: "some task inside foo.bar collection" + ansible.builtin.debug: + msg: "hello world!" diff --git a/src/molecule/test/resources/sample-collection-venv-without-gitignore/extensions/molecule/default/converge.yml b/src/molecule/test/resources/sample-collection-venv-without-gitignore/extensions/molecule/default/converge.yml new file mode 100644 index 0000000000..73f7cfb3c3 --- /dev/null +++ b/src/molecule/test/resources/sample-collection-venv-without-gitignore/extensions/molecule/default/converge.yml @@ -0,0 +1,7 @@ +--- +- name: Converge + hosts: localhost + tasks: + - name: "Include sample role from current collection" + ansible.builtin.include_role: + name: acme.goodies.get_rich diff --git a/src/molecule/test/resources/sample-collection-venv-without-gitignore/extensions/molecule/default/molecule.yml b/src/molecule/test/resources/sample-collection-venv-without-gitignore/extensions/molecule/default/molecule.yml new file mode 100644 index 0000000000..1cec4936a1 --- /dev/null +++ b/src/molecule/test/resources/sample-collection-venv-without-gitignore/extensions/molecule/default/molecule.yml @@ -0,0 +1,11 @@ +--- +dependency: + name: galaxy +driver: + name: default +platforms: + - name: instance +provisioner: + name: ansible +verifier: + name: ansible diff --git a/src/molecule/test/resources/sample-collection-venv-without-gitignore/galaxy.yml b/src/molecule/test/resources/sample-collection-venv-without-gitignore/galaxy.yml new file mode 100644 index 0000000000..2a7e1164d3 --- /dev/null +++ b/src/molecule/test/resources/sample-collection-venv-without-gitignore/galaxy.yml @@ -0,0 +1,31 @@ +name: goodies +namespace: acme +version: 1.0.0 +readme: README.md +authors: + - Red Hat +description: Acme Goodies Collection +build_ignore: + - "*.egg-info" + - .DS_Store + - .eggs + - .gitignore + - .mypy_cache + - .pytest_cache + - .stestr + - .stestr.conf + - .tox + - .vscode + - MANIFEST.in + - build + - dist + - doc + - report.html + - setup.cfg + - setup.py + - "tests/unit/*.*" + - README.rst + - tox.ini + +repository: https://opendev.org/openstack/tripleo-repos +license_file: LICENSE diff --git a/src/molecule/test/resources/sample-collection-venv-without-gitignore/roles/get_rich/tasks/main.yml b/src/molecule/test/resources/sample-collection-venv-without-gitignore/roles/get_rich/tasks/main.yml new file mode 100644 index 0000000000..cf8063a148 --- /dev/null +++ b/src/molecule/test/resources/sample-collection-venv-without-gitignore/roles/get_rich/tasks/main.yml @@ -0,0 +1,3 @@ +- name: "some task inside foo.bar collection" + ansible.builtin.debug: + msg: "hello world!"