mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-06-10 02:26:09 +00:00
Update sanity ignores (#495)
Update sanity ignores SUMMARY A recent change in CI config means we need to add ignores for unsupported versions of python (2.6, 2.7 and 3.5). These changes effectively prevent sanity from doing anything when running on those versions and Ansible < 2.12. In Ansible 2.12 and later, this can be handled on a global level in tests/config.yml. ISSUE TYPE Bugfix Pull Request Docs Pull Request Feature Pull Request New Module Pull Request COMPONENT NAME ADDITIONAL INFORMATION Reviewed-by: Bikouo Aubin <None>
This commit is contained in:
@@ -53,19 +53,35 @@ SHEBANG_SKIPS = [
|
||||
"tests/sanity/refresh_ignore_files",
|
||||
]
|
||||
|
||||
# Add validate-modules:import-error
|
||||
VALIDATE_IMPORT_SKIPS = [
|
||||
"plugins/modules/k8s.py",
|
||||
"plugins/modules/k8s_cp.py",
|
||||
"plugins/modules/k8s_drain.py",
|
||||
"plugins/modules/k8s_exec.py",
|
||||
"plugins/modules/k8s_info.py",
|
||||
"plugins/modules/k8s_json_patch.py",
|
||||
"plugins/modules/k8s_log.py",
|
||||
"plugins/modules/k8s_rollback.py",
|
||||
"plugins/modules/k8s_scale.py",
|
||||
"plugins/modules/k8s_service.py",
|
||||
"plugins/modules/k8s_taint.py",
|
||||
]
|
||||
|
||||
|
||||
def import_skips(*versions):
|
||||
for f in IMPORT_SKIPS:
|
||||
for v in versions:
|
||||
yield f"{f} import-{v}!skip"
|
||||
|
||||
def param_type_skips():
|
||||
for f in PARAM_TYPE_SKIPS:
|
||||
yield f"{f} validate-modules:parameter-type-not-in-doc"
|
||||
def param_type_skips(ansible_version):
|
||||
if ansible_version not in ("2.9", "2.10"):
|
||||
for f in PARAM_TYPE_SKIPS:
|
||||
yield f"{f} validate-modules:parameter-type-not-in-doc"
|
||||
|
||||
|
||||
def return_syntax_skips(ansible_version):
|
||||
if ansible_version != "2.9":
|
||||
if ansible_version not in ("2.9", "2.10"):
|
||||
for f in RETURN_SYNTAX_SKIPS:
|
||||
yield f"{f} validate-modules:return-syntax-error"
|
||||
else:
|
||||
@@ -98,24 +114,98 @@ def metaclass_boilerplate(path, ansible_version):
|
||||
yield
|
||||
|
||||
|
||||
def unsupported_compile_skips(path, ansible_version):
|
||||
"""This adds rules for compile skips for all unsupported versions of python.
|
||||
|
||||
These aren't needed for Ansible version 2.12+ as that can be managed on a
|
||||
global level in tests/config.yml.
|
||||
"""
|
||||
if ansible_version in ("2.9", "2.10", "2.11"):
|
||||
for f in (p for p in path.glob("**/*.py") if not p.is_symlink()):
|
||||
yield (
|
||||
f"{f} compile-2.6!skip\n"
|
||||
f"{f} compile-2.7!skip\n"
|
||||
f"{f} compile-3.5!skip"
|
||||
)
|
||||
|
||||
|
||||
def unsupported_import_skips(path, ansible_version):
|
||||
"""This adds rules for import skips for all unsupported versions of python.
|
||||
|
||||
These aren't needed for Ansible version 2.12+ as that can be managed on a
|
||||
global level in tests/config.yml.
|
||||
"""
|
||||
if ansible_version in ("2.9", "2.10", "2.11"):
|
||||
if ansible_version in ("2.9", "2.10") and path.name == "plugins":
|
||||
pathglob = itertools.chain(
|
||||
path.joinpath("modules").glob("**/*.py"),
|
||||
path.joinpath("module_utils").glob("**/*.py")
|
||||
)
|
||||
else:
|
||||
pathglob = path.glob("**/*.py")
|
||||
for f in (p for p in pathglob if not p.is_symlink()):
|
||||
yield (
|
||||
f"{f} import-2.6!skip\n"
|
||||
f"{f} import-2.7!skip\n"
|
||||
f"{f} import-3.5!skip"
|
||||
)
|
||||
|
||||
|
||||
def unsupported_pylint_skips(path, ansible_version):
|
||||
"""This adds rules to skip pylint checks.
|
||||
|
||||
This is only a problem on Ansible version 2.9 and 2.10 with python 3.5,
|
||||
but there's no way to restrict this to a specific version of python.
|
||||
"""
|
||||
if ansible_version in ("2.9", "2.10"):
|
||||
pathglob = itertools.chain(
|
||||
path.joinpath("plugins/modules").glob("**/*.py"),
|
||||
path.joinpath("plugins/module_utils").glob("**/*.py"),
|
||||
path.joinpath("tests").glob("**/*.py"),
|
||||
)
|
||||
for f in (p for p in pathglob if not p.is_symlink()):
|
||||
yield f"{f} pylint!skip"
|
||||
|
||||
|
||||
def unsupported_validate_modules_skips(ansible_version):
|
||||
"""Disable validate-modules test.
|
||||
|
||||
Unfortunately, this is overly broad. Applying a validate-modules:import-error
|
||||
skip fixes ansible 2.9 and python <3.6, but causes validation of the ignores
|
||||
file itself to fail in python 3.6+. The only solution here is to simply
|
||||
skip validate-modules altogether.
|
||||
"""
|
||||
if ansible_version in ("2.9", "2.10"):
|
||||
for f in VALIDATE_IMPORT_SKIPS:
|
||||
yield f"{f} validate-modules!skip"
|
||||
|
||||
|
||||
def main():
|
||||
target_dir = Path('.')
|
||||
sanity_dir = target_dir / "tests" / "sanity"
|
||||
plugins = target_dir / "plugins"
|
||||
units = target_dir / "tests" / "unit"
|
||||
integration = target_dir / "tests" / "integration"
|
||||
|
||||
for ansible, python in ANSIBLE_VERSIONS.items():
|
||||
with open(sanity_dir / f"ignore-{ansible}.txt", "w") as fp:
|
||||
ignores = itertools.chain(
|
||||
import_skips(*python),
|
||||
param_type_skips(),
|
||||
param_type_skips(ansible),
|
||||
yaml_lint_skips(),
|
||||
shebang_skips(),
|
||||
return_syntax_skips(ansible),
|
||||
import_boilerplate(plugins, ansible),
|
||||
import_boilerplate(units, ansible),
|
||||
metaclass_boilerplate(plugins, ansible),
|
||||
metaclass_boilerplate(units, ansible))
|
||||
metaclass_boilerplate(units, ansible),
|
||||
unsupported_import_skips(plugins, ansible),
|
||||
unsupported_compile_skips(plugins, ansible),
|
||||
unsupported_compile_skips(units, ansible),
|
||||
unsupported_compile_skips(integration, ansible),
|
||||
unsupported_pylint_skips(target_dir, ansible),
|
||||
unsupported_validate_modules_skips(ansible),
|
||||
)
|
||||
for f in filter(None, ignores):
|
||||
fp.write(f + "\n")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user