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

Rename meta-unsupported-ansible to meta-runtime and correct its logic #3000

Merged
merged 7 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tox.yml
Expand Up @@ -70,7 +70,7 @@ jobs:
WSLENV: FORCE_COLOR:PYTEST_REQPASS:TOXENV:GITHUB_STEP_SUMMARY
# Number of expected test passes, safety measure for accidental skip of
# tests. Update value if you add/remove tests.
PYTEST_REQPASS: 780
PYTEST_REQPASS: 781

steps:
- name: Activate WSL1
Expand Down
35 changes: 17 additions & 18 deletions docs/profiles.md
Expand Up @@ -64,12 +64,12 @@ content easier to read and maintain. It extends [basic](#basic) profile.
The `safety` profile avoids module calls that can have non-determinant outcomes
or security concerns. It extends [moderate](#moderate) profile.

- [avoid-implicit](rules/avoid-implicit/)
- [latest](rules/latest/)
- [package-latest](rules/package-latest/)
- [risky-file-permissions](rules/risky-file-permissions/)
- [risky-octal](rules/risky-octal/)
- [risky-shell-pipe](rules/risky-shell-pipe/)
- [avoid-implicit](/rules/avoid-implicit/)
- [latest](/rules/latest/)
- [package-latest](/rules/package-latest/)
- [risky-file-permissions](/rules/risky-file-permissions/)
- [risky-octal](/rules/risky-octal/)
- [risky-shell-pipe](/rules/risky-shell-pipe/)

## shared

Expand All @@ -80,19 +80,18 @@ Ansible playbooks, roles, or collections available from
[automation-hub](https://console.redhat.com/ansible/automation-hub), or a
private instance. It extends [safety](#safety) profile.

- [galaxy](rules/galaxy/)
- [ignore-errors](rules/ignore-errors/)
- [galaxy](/rules/galaxy/)
- [ignore-errors](/rules/ignore-errors/)
- [layout](https://github.com/ansible/ansible-lint/issues/1900)
- [meta-incorrect](rules/meta-incorrect/)
- [meta-no-info](rules/meta-no-info/)
- [meta-no-tags](rules/meta-no-tags/)
- [meta-video-links](rules/meta-video-links/)
- [meta-incorrect](/rules/meta-incorrect/)
- [meta-no-info](/rules/meta-no-info/)
- [meta-no-tags](/rules/meta-no-tags/)
- [meta-video-links](/rules/meta-video-links/)
- [meta-version](https://github.com/ansible/ansible-lint/issues/2103)
- [meta-unsupported-ansible](https://github.com/ansible/ansible-lint/issues/2102)
- [no-changed-when](rules/no-changed-when/)
- [no-changelog](https://github.com/ansible/ansible-lint/issues/2101)
- [no-handler](rules/no-handler/)
- [no-relative-paths](rules/no-relative-paths/)
- [meta-runtime](/rules/meta-runtime/)
- [no-changed-when](/rules/no-changed-when/)
- [no-handler](/rules/no-handler/)
- [no-relative-paths](/rules/no-relative-paths/)
- [max-block-depth](https://github.com/ansible/ansible-lint/issues/2173)
- [max-tasks](https://github.com/ansible/ansible-lint/issues/2172)
- [unsafe-loop](https://github.com/ansible/ansible-lint/issues/2038)
Expand All @@ -106,7 +105,7 @@ as validated or certified content. It extends [shared](#shared) profile.

- [avoid-dot-notation](https://github.com/ansible/ansible-lint/issues/2174)
- [disallowed-ignore](https://github.com/ansible/ansible-lint/issues/2121)
- [fqcn](rules/fqcn/)
- [fqcn](/rules/fqcn/)
- [import-task-no-when](https://github.com/ansible/ansible-lint/issues/2219)
- [meta-no-dependencies](https://github.com/ansible/ansible-lint/issues/2159)
- [single-entry-point](https://github.com/ansible/ansible-lint/issues/2242)
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/index.md
Expand Up @@ -23,7 +23,7 @@
- [meta-incorrect][]
- [meta-no-info][]
- [meta-no-tags][]
- [meta-unsupported-ansible][]
- [meta-runtime][]
- [meta-video-links][]
- [name][]
- [no-changed-when][]
Expand Down
1 change: 1 addition & 0 deletions docs/rules/meta-runtime.md
1 change: 0 additions & 1 deletion docs/rules/meta-unsupported-ansible.md

This file was deleted.

@@ -1,2 +1,2 @@
---
requires_ansible: ">=2.15.0"
requires_ansible: ">=2.20.0"
@@ -0,0 +1,2 @@
---
requires_ansible: "2.13.0,<2.15"
@@ -1,2 +1,2 @@
---
requires_ansible: ">=2.13.0"
requires_ansible: ">=2.13.0,<2.15"
2 changes: 1 addition & 1 deletion mkdocs.yml
Expand Up @@ -95,7 +95,7 @@ nav:
- rules/meta-incorrect.md
- rules/meta-no-info.md
- rules/meta-no-tags.md
- rules/meta-unsupported-ansible.md
- rules/meta-runtime.md
- rules/meta-video-links.md
- rules/name.md
- rules/no-changed-when.md
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/data/profiles.yml
Expand Up @@ -84,7 +84,7 @@ shared:
meta-video-links:
meta-version:
url: https://github.com/ansible/ansible-lint/issues/2103
meta-unsupported-ansible:
meta-runtime:
url: https://github.com/ansible/ansible-lint/issues/2102
no-changed-when:
no-changelog:
Expand Down
@@ -1,4 +1,4 @@
# meta-unsupported-ansible
# meta-runtime

This rule checks the meta/runtime.yml `requires_ansible` key against the list of currently supported versions of ansible-core.

Expand All @@ -13,6 +13,13 @@ Currently supported versions of ansible-core are:
- `2.12.x`
- `2.13.x`
- `2.14.x`
- `2.15.x`

This rule can produce messages such as:

- `meta-runtime[unsupported-version]` - `requires_ansible` key must contain a supported version, shown in the list above.
- `meta-runtime[invalid-version]` - `requires_ansible` key must be a valid version identifier.


## Problematic code

Expand All @@ -22,6 +29,13 @@ Currently supported versions of ansible-core are:
requires_ansible: ">=2.9"
```


```yaml
# runtime.yml
---
requires_ansible: "2.9"
```

## Correct code

```yaml
Expand Down
@@ -1,9 +1,11 @@
"""Implementation of meta-unsupported-ansible rule."""
"""Implementation of meta-runtime rule."""
from __future__ import annotations

import sys
from typing import TYPE_CHECKING

from packaging.specifiers import SpecifierSet

from ansiblelint.rules import AnsibleLintRule

# Copyright (c) 2018, Ansible Project
Expand All @@ -15,29 +17,31 @@
from ansiblelint.errors import MatchError
from ansiblelint.file_utils import Lintable

META_TAG_VALID = """
galaxy_info:
galaxy_tags: ['database', 'my s q l', 'MYTAG']
categories: 'my_category_not_in_a_list'
"""


class CheckRequiresAnsibleVersion(AnsibleLintRule):
"""Required ansible version in meta/runtime.yml must be a supported version."""

id = "meta-unsupported-ansible"
id = "meta-runtime"
description = (
"The ``requires_ansible`` key in runtime.yml must specify "
"a supported platform version of ansible-core."
"a supported platform version of ansible-core and be a valid version."
)
severity = "VERY_HIGH"
tags = ["metadata"]
version_added = "v6.11.0 (last update)"

supported_ansible = ["2.9.10", "2.11", "2.12", "2.13", "2.14"]
# 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."]

def matchyaml(self, file: Lintable) -> list[MatchError]:
"""Find violations inside meta files."""
"""Find violations inside meta files.

:param file: Input lintable file that is a match for `meta-runtime`
:returns: List of errors matched to the input file
"""
results = []

if file.kind != "meta-runtime":
return []

Expand All @@ -47,12 +51,25 @@ def matchyaml(self, file: Lintable) -> list[MatchError]:
if not any(
version in version_required for version in self.supported_ansible
):
return [
results.append(
self.create_matcherror(
message="requires_ansible key must be set to a supported version.",
tag="meta-runtime[unsupported-version]",
filename=file,
)
]
)

try:
SpecifierSet(version_required)
except ValueError:
results.append(
self.create_matcherror(
message="'requires_ansible' is not a valid requirement specification",
tag="meta-runtime[invalid-version]",
filename=file,
)
)
return results

return []

Expand All @@ -65,31 +82,44 @@ def matchyaml(self, file: Lintable) -> list[MatchError]:
from ansiblelint.runner import Runner # pylint: disable=ungrouped-imports

@pytest.mark.parametrize(
("test_file", "failures"),
("test_file", "failures", "tags"),
(
pytest.param(
"examples/meta_runtime_version_checks/pass/meta/runtime.yml",
0,
"meta-runtime[unsupported-version]",
id="pass",
),
pytest.param(
"examples/meta_runtime_version_checks/fail_0/meta/runtime.yml",
1,
"meta-runtime[unsupported-version]",
id="fail0",
),
pytest.param(
"examples/meta_runtime_version_checks/fail_1/meta/runtime.yml",
1,
"meta-runtime[unsupported-version]",
id="fail1",
),
pytest.param(
"examples/meta_runtime_version_checks/fail_2/meta/runtime.yml",
1,
"meta-runtime[invalid-version]",
id="fail2",
),
),
)
def test_loop_var_prefix(
default_rules_collection: RulesCollection, test_file: str, failures: int
def test_meta_supported_version(
default_rules_collection: RulesCollection,
test_file: str,
failures: int,
tags: str,
) -> None:
"""Test rule matches."""
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
2 changes: 1 addition & 1 deletion src/ansiblelint/schemas/ansible-lint-config.json
Expand Up @@ -146,7 +146,7 @@
"meta-incorrect",
"meta-no-info",
"meta-no-tags",
"meta-unsupported-ansible",
"meta-runtime",
"meta-video-links",
"name",
"no-changed-when",
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Expand Up @@ -165,7 +165,7 @@ commands =
allowlist_externals =
.tox/venv/bin/pip
setenv =
PYTEST_REQPASS=9
PYTEST_REQPASS=7

[testenv:pkg]
description =
Expand Down