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

Fix: Update default globbing pattern for collection matching #4177

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
matrix: ${{ fromJson(needs.pre.outputs.matrix) }}

env:
PYTEST_REQPASS: 453
PYTEST_REQPASS: 454
environment: test
steps:
- uses: actions/checkout@v4
Expand Down
4 changes: 2 additions & 2 deletions src/molecule/command/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
from molecule.console import should_do_markup

LOG = logging.getLogger(__name__)
MOLECULE_GLOB = os.environ.get("MOLECULE_GLOB", "molecule/*/molecule.yml")
MOLECULE_GLOB = os.environ.get("MOLECULE_GLOB", "**/molecule/*/molecule.yml")
MOLECULE_DEFAULT_SCENARIO_NAME = "default"


Expand Down Expand Up @@ -94,7 +94,7 @@ def execute_cmdline_scenarios(scenario_name, args, command_args, ansible_args=()
"""
glob_str = MOLECULE_GLOB
if scenario_name:
glob_str = glob_str.replace("*", scenario_name)
glob_str = glob_str.replace("/*/", f"/{scenario_name}/")
scenarios = molecule.scenarios.Scenarios(
get_configs(args, command_args, ansible_args, glob_str),
scenario_name,
Expand Down
2 changes: 1 addition & 1 deletion src/molecule/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Config(metaclass=NewInitCaller):
"""Config Class.

Molecule searches the current directory for ``molecule.yml`` files by
globbing `molecule/*/molecule.yml`. The files are instantiated into
globbing `**/molecule/*/molecule.yml`. The files are instantiated into
a list of Molecule [molecule.config.Config][] objects, and each Molecule subcommand
operates on this list.

Expand Down
2 changes: 1 addition & 1 deletion test/a_unit/command/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def test_verify_configs_raises_with_no_configs(caplog):

assert e.value.code == 1

msg = "'molecule/*/molecule.yml' glob failed. Exiting."
msg = "'**/molecule/*/molecule.yml' glob failed. Exiting."
assert msg in caplog.text


Expand Down
47 changes: 39 additions & 8 deletions test/b_functional/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import os
import pathlib
import shutil
from test.b_functional.conftest import (
idempotence,
init_scenario,
Expand Down Expand Up @@ -330,14 +331,44 @@ def test_command_verify(scenario_to_test, with_scenario, scenario_name):
verify(scenario_name)


def test_sample_collection() -> None:
assert (
run_command(
["molecule", "test"],
cwd="test/resources/sample-collection",
).returncode
== 0
)
@pytest.mark.serial()
@pytest.mark.parametrize(
("scenario_name", "collection_name"),
[
pytest.param("default", "sample-collection"),
pytest.param("default", "sample-collection-nested"),
],
)
def test_sample_collection(
resources_folder_path,
tmp_path,
scenario_name,
collection_name,
):
collection_dir = tmp_path / "ansible_collections"
molecule_ephemeral_dir = tmp_path / "cache/molecule"
test_dir = tmp_path / f"{collection_name}"
verify_dir = pathlib.Path(f"{collection_dir}/acme/goodies/molecule")

shutil.copytree(f"{resources_folder_path}/sample-collection", test_dir)

if collection_name == "sample-collection-nested":
verify_dir = pathlib.Path(
f"{collection_dir}/acme/goodies/extensions/molecule",
)
# create collection with nested molecule directory
shutil.move(f"{test_dir}/molecule", f"{test_dir}/extensions/molecule")

cmd = [
f"ANSIBLE_COLLECTIONS_PATH={collection_dir}",
f"MOLECULE_EPHEMERAL_DIRECTORY={molecule_ephemeral_dir}",
"molecule",
"test",
"--scenario-name",
scenario_name,
]
assert run_command(cmd, cwd=test_dir).returncode == 0
assert verify_dir.is_dir()


@pytest.mark.parametrize(
Expand Down
Loading