ci(molecule): fail the run when a scenario has molecule's prerun on
Build / build (pull_request) Successful in 37s
Lint / lint (pull_request) Successful in 5m15s
Molecule / molecule (pull_request) Successful in 36m0s

check_scenarios_load_checkout.py now merges the base config the way
molecule's CLI does (its own lookup of .config/molecule/config.yml) and
fails a scenario whose merged prerun is not false, naming the base
config. Before, it built Config with no base config, so a scenario that
turned prerun back on, or a moved base config, slowed every run and
nothing failed.

Closes #452

Assisted-by: Claude Code
This commit is contained in:
Defame1297 committed 2026-11-29 16:56:29 +00:00
1 parent 0173f6f226
commit 49afd900dc
4 files changed
+59 -12

No files matched your search

@@ -43,6 +43,11 @@ class CheckScenariosLoadCheckoutTest(unittest.TestCase):
self.ac_root = self.tmp / "ac"
self.checkout = collection(self.ac_root)
(self.checkout / "scripts").mkdir()
# molecule's CLI finds the base config from the repository root, as in the real checkout
subprocess.run(["git", "init", "-q", str(self.checkout)], check=True)
self.base_config = self.checkout / ".config" / "molecule" / "config.yml"
self.base_config.parent.mkdir(parents=True)
self.base_config.write_text("prerun: false\n")
shutil.copy(SCRIPT, self.checkout / "scripts")
self.other = self.tmp / "other"
collection(self.other)
@@ -55,10 +60,14 @@ class CheckScenariosLoadCheckoutTest(unittest.TestCase):
"ANSIBLE_COLLECTIONS_PATH": f"{self.ac_root}:{self.other}",
}
def scenario(self, path, env=None):
def scenario(self, path, env=None, **keys):
d = self.checkout / path
d.mkdir(parents=True, exist_ok=True)
config = {"driver": {"name": "default"}, "platforms": [{"name": "instance"}]}
config = {
"driver": {"name": "default"},
"platforms": [{"name": "instance"}],
**keys,
}
if env:
config["provisioner"] = {"name": "ansible", "env": env}
(d / "molecule.yml").write_text(yaml.safe_dump(config))
@@ -81,7 +90,14 @@ class CheckScenariosLoadCheckoutTest(unittest.TestCase):
self.assertIn("must load mortis.kamino from the checkout", result.stdout)
self.assertIn(found, result.stdout)
def assert_prerun_refused(self, result, scenario="roles/alpha/molecule/default"):
self.assertEqual(result.returncode, 1, result.stdout + result.stderr)
self.assertIn(f"::error::{scenario}: ", result.stdout)
self.assertIn("prerun", result.stdout)
self.assertIn(".config/molecule/config.yml", result.stdout)
def test_the_checkout_first_passes(self):
# the scenarios inherit prerun off from the base config
result = self.run_check(
"roles/alpha/molecule/default\nextensions/molecule/image-smoke\n"
)
@@ -120,6 +136,18 @@ class CheckScenariosLoadCheckoutTest(unittest.TestCase):
self.assert_refused(result, "extensions/molecule/image-smoke")
self.assertNotIn("roles/alpha/molecule/default", result.stdout)
def test_a_scenario_with_prerun_on_fails(self):
self.scenario("roles/alpha/molecule/default", prerun=True)
self.assert_prerun_refused(self.run_check())
def test_a_missing_base_config_fails(self):
self.base_config.unlink()
self.assert_prerun_refused(self.run_check())
def test_a_base_config_with_prerun_on_fails(self):
self.base_config.write_text("prerun: true\n")
self.assert_prerun_refused(self.run_check())
if __name__ == "__main__":
unittest.main()