mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 05:42:50 +00:00
[PR #11686/68ae04a9 backport][stable-12] Cleanup of aliases skip statements (#11709)
Cleanup of `aliases` skip statements (#11686)
* add scripts to clean aliases' skips
* remove legacy skips
* code cosmetics
* add license to ALIASES.md
* Fix typos in ALIASES.md documentation
* rolling back freebsd14.2 and 14.3 in iso_extract
* fix versions and re-run
(cherry picked from commit 68ae04a95a)
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
38
tests/utils/ALIASES.md
Normal file
38
tests/utils/ALIASES.md
Normal file
@@ -0,0 +1,38 @@
|
||||
<!--
|
||||
Copyright (c) Ansible Project
|
||||
GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
||||
-->
|
||||
|
||||
# Cleaning up `aliases` skips
|
||||
|
||||
The skip statements in `tests/integration/targets/*/aliases` files may contain specific OSes and their versions.
|
||||
|
||||
For example:
|
||||
|
||||
skip/rhel8.8
|
||||
skip/centos6
|
||||
skip/macos
|
||||
|
||||
Those items being skipped are called `remotes` and they come from the file `test/lib/ansible_test/_data/completion/remote.txt`
|
||||
in the `ansible-core` repository. Eventually, these remotes are removed from that `ansible_test` config,
|
||||
but they keep silently cluttering the aliases files here.
|
||||
|
||||
The scripts `list-remotes` and `clean-aliases-skips` can help you remove those entries from the `aliases` files.
|
||||
For that, you will need to have a clone of the `ansible-core` repository in your machine.
|
||||
|
||||
In the example below, the path to that repo is `../ansible`:
|
||||
|
||||
```shell
|
||||
./tests/utils/list-remotes ../ansible
|
||||
```
|
||||
|
||||
**Note:** The supported versions of `ansible-core` are hardcoded in `list-remotes`. Those should be updated or automated in the future.
|
||||
|
||||
To remove all the skips that are **not** in that list, you should run:
|
||||
|
||||
```shell
|
||||
./tests/utils/list-remotes ../ansible | ./tests/utils/clean-aliases-skips
|
||||
```
|
||||
|
||||
Make sure to thoroughly review the changes before committing!
|
||||
42
tests/utils/clean-aliases-skips
Executable file
42
tests/utils/clean-aliases-skips
Executable file
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env python
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import re
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def sanitize(filepath, remotes_re):
|
||||
with open(filepath) as fileread:
|
||||
lines = fileread.readlines()
|
||||
|
||||
changed = False
|
||||
out_lines = []
|
||||
for ll in lines:
|
||||
if not ll.startswith("skip/") or any(r.match(ll) for r in remotes_re):
|
||||
out_lines.append(ll)
|
||||
continue
|
||||
changed = True
|
||||
|
||||
if changed:
|
||||
print(f"sanitizing {filepath}", file=sys.stderr)
|
||||
with open(filepath, "w") as filewrite:
|
||||
filewrite.writelines(out_lines)
|
||||
|
||||
|
||||
def main():
|
||||
remotes = [x.strip() for x in sys.stdin.readlines()]
|
||||
remotes.append("docker")
|
||||
|
||||
print(f"Valid remotes: {', '.join(remotes)}", file=sys.stderr)
|
||||
|
||||
remotes_re = [re.compile(rf"^skip/{r}(\s.*)?$") for r in remotes]
|
||||
|
||||
for filepath in Path("tests/integration/targets").glob("*/aliases"):
|
||||
sanitize(filepath, remotes_re)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
29
tests/utils/list-remotes
Executable file
29
tests/utils/list-remotes
Executable file
@@ -0,0 +1,29 @@
|
||||
#!/bin/sh
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
SUPPORTED_AC2="17 18 19 20"
|
||||
|
||||
[ -z "$1" ] && {
|
||||
echo 'usage: ./tests/utils/list-remotes <ansible git repo dir>' >&2
|
||||
exit 1
|
||||
}
|
||||
ansible_repo_dir="$1"
|
||||
|
||||
(
|
||||
cd "$ansible_repo_dir"
|
||||
|
||||
versions=$(
|
||||
for minor in $SUPPORTED_AC2; do
|
||||
echo v2.$minor.$(git tag -l | awk -F. "\$2 == $minor && /v2\.[0-9]+\.[0-9]+$/ { print \$3 }" | sort -rn | head -1)
|
||||
done
|
||||
)
|
||||
versions="$versions devel"
|
||||
|
||||
echo "Listing remotes from ansible-core:" $versions >&2
|
||||
for head in $versions; do
|
||||
git checkout -q $head
|
||||
cat test/lib/ansible_test/_data/completion/remote.txt
|
||||
done | awk '/[a-z]+(\/[0-9]+)?/ { print $1 }' | sort -u | sed -e s'/\///g'
|
||||
)
|
||||
Reference in New Issue
Block a user