summaryrefslogtreecommitdiffstats
path: root/src/ansiblelint/rules/meta_runtime.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/ansiblelint/rules/meta_runtime.py')
-rw-r--r--src/ansiblelint/rules/meta_runtime.py59
1 files changed, 42 insertions, 17 deletions
diff --git a/src/ansiblelint/rules/meta_runtime.py b/src/ansiblelint/rules/meta_runtime.py
index fed7121..3df2826 100644
--- a/src/ansiblelint/rules/meta_runtime.py
+++ b/src/ansiblelint/rules/meta_runtime.py
@@ -1,4 +1,5 @@
"""Implementation of meta-runtime rule."""
+
from __future__ import annotations
import sys
@@ -22,17 +23,15 @@ class CheckRequiresAnsibleVersion(AnsibleLintRule):
id = "meta-runtime"
description = (
"The ``requires_ansible`` key in runtime.yml must specify "
- "a supported platform version of ansible-core and be a valid version."
+ "a supported platform version of ansible-core and be a valid version value "
+ "in x.y.z format."
)
severity = "VERY_HIGH"
tags = ["metadata"]
version_added = "v6.11.0 (last update)"
- # Refer to https://access.redhat.com/support/policy/updates/ansible-automation-platform
- # Also add devel to this list
- supported_ansible = ["2.9.10", "2.11.", "2.12.", "2.13.", "2.14.", "2.15.", "2.16."]
_ids = {
- "meta-runtime[unsupported-version]": "requires_ansible key must be set to a supported version.",
+ "meta-runtime[unsupported-version]": "'requires_ansible' key must refer to a currently supported version",
"meta-runtime[invalid-version]": "'requires_ansible' is not a valid requirement specification",
}
@@ -47,22 +46,26 @@ class CheckRequiresAnsibleVersion(AnsibleLintRule):
if file.kind != "meta-runtime":
return []
- version_required = file.data.get("requires_ansible", None)
+ requires_ansible = file.data.get("requires_ansible", None)
- if version_required:
- if not any(
- version in version_required for version in self.supported_ansible
+ if requires_ansible:
+ if self.options and not any(
+ version in requires_ansible
+ for version in self.options.supported_ansible
):
+ supported_ansible = [f">={x}0" for x in self.options.supported_ansible]
+ msg = f"'requires_ansible' key must refer to a currently supported version such as: {', '.join(supported_ansible)}"
+
results.append(
self.create_matcherror(
- message="requires_ansible key must be set to a supported version.",
+ message=msg,
tag="meta-runtime[unsupported-version]",
filename=file,
),
)
try:
- SpecifierSet(version_required)
+ SpecifierSet(requires_ansible)
except ValueError:
results.append(
self.create_matcherror(
@@ -79,17 +82,18 @@ class CheckRequiresAnsibleVersion(AnsibleLintRule):
if "pytest" in sys.modules:
import pytest
- from ansiblelint.rules import RulesCollection # pylint: disable=ungrouped-imports
- from ansiblelint.runner import Runner # pylint: disable=ungrouped-imports
+ # pylint: disable=ungrouped-imports
+ from ansiblelint.rules import RulesCollection
+ from ansiblelint.runner import Runner
@pytest.mark.parametrize(
("test_file", "failures", "tags"),
(
pytest.param(
- "examples/meta_runtime_version_checks/pass/meta/runtime.yml",
+ "examples/meta_runtime_version_checks/pass_0/meta/runtime.yml",
0,
"meta-runtime[unsupported-version]",
- id="pass",
+ id="pass0",
),
pytest.param(
"examples/meta_runtime_version_checks/fail_0/meta/runtime.yml",
@@ -111,16 +115,37 @@ if "pytest" in sys.modules:
),
),
)
- def test_meta_supported_version(
+ def test_default_meta_supported_version(
default_rules_collection: RulesCollection,
test_file: str,
failures: int,
tags: str,
) -> None:
- """Test rule matches."""
+ """Test for default supported ansible versions."""
default_rules_collection.register(CheckRequiresAnsibleVersion())
results = Runner(test_file, rules=default_rules_collection).run()
for result in results:
assert result.rule.id == CheckRequiresAnsibleVersion().id
assert result.tag == tags
assert len(results) == failures
+
+ @pytest.mark.parametrize(
+ ("test_file", "failures"),
+ (
+ pytest.param(
+ "examples/meta_runtime_version_checks/pass_1/meta/runtime.yml",
+ 0,
+ id="pass1",
+ ),
+ ),
+ )
+ def test_added_meta_supported_version(
+ default_rules_collection: RulesCollection,
+ test_file: str,
+ failures: int,
+ ) -> None:
+ """Test for added supported ansible versions in the config."""
+ default_rules_collection.register(CheckRequiresAnsibleVersion())
+ default_rules_collection.options.supported_ansible_also = ["2.9"]
+ results = Runner(test_file, rules=default_rules_collection).run()
+ assert len(results) == failures