Merge branch 'main' into ci/477-molecule-controller-image
This commit is contained in:
commit
1289da3104
25 files changed
+317
-24
No files matched your search
@@ -5,8 +5,10 @@
|
||||
python3 -I scripts/check_scenarios_load_checkout.py < scenario-dirs
|
||||
|
||||
Checks the environment molecule hands ansible-playbook, not only the inherited one: a scenario's
|
||||
own env can change it. The rule it holds is in .gitea/workflows/AGENTS.md (Molecule). Exit 1 when
|
||||
a scenario would load another copy, or none.
|
||||
own env can change it. Also checks that molecule's prerun, its install of the collection, is off
|
||||
once the base config is merged as molecule's CLI merges it. The rule it holds is in
|
||||
.gitea/workflows/AGENTS.md (Molecule). Exit 1 when a scenario would load another copy, or none,
|
||||
or has prerun on.
|
||||
"""
|
||||
|
||||
import json
|
||||
@@ -16,6 +18,8 @@ import sys
|
||||
import tempfile
|
||||
|
||||
from molecule.config import Config
|
||||
from molecule.shell import LOCAL_CONFIG_SEARCH
|
||||
from molecule.util import lookup_config_file
|
||||
|
||||
CHECKOUT = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
|
||||
RULE = (
|
||||
@@ -23,20 +27,25 @@ RULE = (
|
||||
" copy: the scenario selector ignores galaxy.yml on that rule"
|
||||
" (.gitea/workflows/AGENTS.md, Molecule)"
|
||||
)
|
||||
PRERUN = (
|
||||
"prerun must be off, so molecule does not install mortis.kamino again: set `prerun: false`"
|
||||
" in the base config {base} and do not turn it on in the scenario (.gitea/workflows/AGENTS.md, Molecule)"
|
||||
)
|
||||
|
||||
|
||||
def playbook_env(scenario):
|
||||
"""The environment molecule gives ansible-playbook in `scenario`, as a role scenario runs it."""
|
||||
def scenario_config(scenario):
|
||||
"""Molecule's config of `scenario` as `molecule converge` builds it there, and its base config."""
|
||||
parts = scenario.split("/")
|
||||
cwd = os.path.join(CHECKOUT, *parts[:2]) if parts[0] == "roles" else CHECKOUT
|
||||
# molecule takes the project from the working directory; each call sets it afresh
|
||||
# molecule takes the project and the base config from the working directory; set it afresh
|
||||
os.chdir(cwd)
|
||||
base = lookup_config_file(LOCAL_CONFIG_SEARCH)
|
||||
config = Config(
|
||||
os.path.relpath(os.path.join(CHECKOUT, scenario, "molecule.yml")),
|
||||
args={},
|
||||
args={"base_config": [base] if base else []},
|
||||
command_args={"subcommand": "converge"},
|
||||
)
|
||||
return dict(config.provisioner.env)
|
||||
return config, base
|
||||
|
||||
|
||||
def collection_paths(env, cwd):
|
||||
@@ -79,8 +88,16 @@ def main():
|
||||
os.environ.setdefault("ANSIBLE_HOME", home)
|
||||
for scenario in filter(None, sys.stdin.read().splitlines()):
|
||||
scenario_dir = os.path.join(CHECKOUT, scenario)
|
||||
config, base = scenario_config(scenario)
|
||||
# molecule's worker reads this key to decide whether to install the collection
|
||||
if config.config_data["prerun"] is not False:
|
||||
failed = True
|
||||
base = (
|
||||
base or os.path.join(CHECKOUT, LOCAL_CONFIG_SEARCH) + " (not found)"
|
||||
)
|
||||
print(f"::error::{scenario}: " + PRERUN.format(base=base))
|
||||
paths = [os.path.join(scenario_dir, "collections")]
|
||||
paths += collection_paths(playbook_env(scenario), scenario_dir)
|
||||
paths += collection_paths(dict(config.provisioner.env), scenario_dir)
|
||||
found = loaded_copy(paths)
|
||||
if found and os.path.realpath(found) == CHECKOUT:
|
||||
continue
|
||||
|
||||
@@ -30,7 +30,7 @@ fi
|
||||
ansible --version
|
||||
molecule --version
|
||||
# The collection under test first; molecule does not install it again (prerun is off in
|
||||
# .config/molecule/config.yml).
|
||||
# .config/molecule/config.yml, which check_scenarios_load_checkout.py holds).
|
||||
export ANSIBLE_COLLECTIONS_PATH="$AC_ROOT:${extra_collections}/opt/collections"
|
||||
# Facts are not injected as variables (deprecated in ansible-core 2.22, removal scheduled for 2.24, see #364), so a
|
||||
# role that reads a bare `ansible_<fact>` fails its scenario here instead of in a consumer's inventory.
|
||||
|
||||
Reference in new issue
Block a user