From 7d8f040c036e59166ac9ed0db1cb8a35a7f2a0c8 Mon Sep 17 00:00:00 2001 From: wadhah mahrouk <33103894+wadhah101@users.noreply.github.com> Date: Thu, 11 May 2023 10:23:17 +0200 Subject: [PATCH] Enhancement: Generate cookie cutter templates and apply linting on them (#123) * reset branch for cleanup * generate plugin names * use script to extract plugin names * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * update crypto in requirments.yml --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .ansible-lint | 5 -- .ansible-lint-ignore | 95 +++++++++++++++++++++++++++++++++++ .pre-commit-config.yaml | 3 +- requirements.yml | 3 ++ tools/extract_plugin_names.py | 20 ++++++++ tools/generate-templates.sh | 15 ++++++ tox.ini | 8 ++- 7 files changed, 141 insertions(+), 8 deletions(-) create mode 100644 .ansible-lint-ignore create mode 100644 tools/extract_plugin_names.py create mode 100644 tools/generate-templates.sh diff --git a/.ansible-lint b/.ansible-lint index a2cb290e..c70f8861 100644 --- a/.ansible-lint +++ b/.ansible-lint @@ -4,15 +4,10 @@ exclude_paths: - .github/ - requirements.yml - src/**/cookiecutter/{{* - # - src/molecule_gce/cookiecutter/{{cookiecutter.molecule_directory}} skip_list: # Temporary skips made during migration - args[module] - - experimental - - fqcn-builtins - - var-spacing - - yaml[line-length] mock_modules: - vagrant # only until we publish community.vagrant collection diff --git a/.ansible-lint-ignore b/.ansible-lint-ignore new file mode 100644 index 00000000..2e2b3258 --- /dev/null +++ b/.ansible-lint-ignore @@ -0,0 +1,95 @@ +src/molecule_plugins/docker/playbooks/create.yml yaml[line-length] +src/molecule_plugins/docker/playbooks/destroy.yml yaml[line-length] + +src/molecule_plugins/gce/playbooks/handlers/main.yml yaml[line-length] +src/molecule_plugins/gce/playbooks/tasks/create_linux_instance.yml yaml[line-length] +src/molecule_plugins/gce/playbooks/tasks/create_windows_instance.yml yaml[line-length] + +src/molecule_plugins/podman/playbooks/create.yml yaml[line-length] + +test/azure/scenarios/driver/azure/molecule/multi-node/prepare.yml fqcn[action-core] + +test/gce/scenarios/linux/converge.yml fqcn[action-core] +test/gce/scenarios/linux/create.yml fqcn[action-core] +test/gce/scenarios/linux/destroy.yml fqcn[action-core] +test/gce/scenarios/linux/handlers/main.yml fqcn[action-core] +test/gce/scenarios/linux/handlers/main.yml yaml[line-length] +test/gce/scenarios/linux/molecule.yml yaml[line-length] +test/gce/scenarios/linux/prepare.yml fqcn[action-core] +test/gce/scenarios/linux/tasks/create_linux_instance.yml fqcn[action-core] +test/gce/scenarios/linux/tasks/create_linux_instance.yml yaml[line-length] +test/gce/scenarios/linux/tasks/create_windows_instance.yml fqcn[action-core] +test/gce/scenarios/linux/tasks/create_windows_instance.yml yaml[line-length] +test/gce/scenarios/linux/verify.yml fqcn[action-core] + +test/gce/scenarios/windows/converge.yml fqcn[action-core] +test/gce/scenarios/windows/create.yml fqcn[action-core] +test/gce/scenarios/windows/destroy.yml fqcn[action-core] +test/gce/scenarios/windows/handlers/main.yml fqcn[action-core] +test/gce/scenarios/windows/handlers/main.yml yaml[line-length] +test/gce/scenarios/windows/molecule.yml yaml[line-length] +test/gce/scenarios/windows/prepare.yml fqcn[action-core] +test/gce/scenarios/windows/tasks/create_linux_instance.yml fqcn[action-core] +test/gce/scenarios/windows/tasks/create_linux_instance.yml yaml[line-length] +test/gce/scenarios/windows/tasks/create_windows_instance.yml fqcn[action-core] +test/gce/scenarios/windows/tasks/create_windows_instance.yml yaml[line-length] +test/gce/scenarios/windows/verify.yml fqcn[action-core] + +test/roles/azureplugin/meta/main.yml meta-incorrect +test/roles/azureplugin/meta/main.yml meta-no-info +test/roles/azureplugin/meta/main.yml schema[meta] +test/roles/azureplugin/molecule/default/create.yml yaml[octal-values] +test/roles/azureplugin/molecule/default/destroy.yml yaml[octal-values] +test/roles/azureplugin/molecule/default/verify.yml yaml[indentation] +test/roles/azureplugin/tests/test.yml name[play] + +test/roles/dockerplugin/meta/main.yml meta-incorrect +test/roles/dockerplugin/meta/main.yml meta-no-info +test/roles/dockerplugin/meta/main.yml schema[meta] +test/roles/dockerplugin/molecule/default/converge.yml fqcn[action-core] +test/roles/dockerplugin/molecule/default/verify.yml yaml[indentation] +test/roles/dockerplugin/tests/test.yml name[play] + +test/roles/ec2plugin/meta/main.yml meta-incorrect +test/roles/ec2plugin/meta/main.yml meta-no-info +test/roles/ec2plugin/meta/main.yml schema[meta] +test/roles/ec2plugin/molecule/default/converge.yml fqcn[action-core] +test/roles/ec2plugin/molecule/default/create.yml fqcn[action-core] +test/roles/ec2plugin/molecule/default/create.yml fqcn[action] +test/roles/ec2plugin/molecule/default/create.yml fqcn[keyword] +test/roles/ec2plugin/molecule/default/create.yml key-order[task] +test/roles/ec2plugin/molecule/default/create.yml name[missing] +test/roles/ec2plugin/molecule/default/create.yml no-handler +test/roles/ec2plugin/molecule/default/create.yml risky-file-permissions +test/roles/ec2plugin/molecule/default/destroy.yml fqcn[action-core] +test/roles/ec2plugin/molecule/default/destroy.yml fqcn[action] +test/roles/ec2plugin/molecule/default/destroy.yml fqcn[keyword] +test/roles/ec2plugin/molecule/default/destroy.yml risky-file-permissions +test/roles/ec2plugin/molecule/default/prepare.yml fqcn[action-core] +test/roles/ec2plugin/molecule/default/verify.yml yaml[indentation] +test/roles/ec2plugin/tests/test.yml name[play] + +test/roles/gceplugin/meta/main.yml meta-incorrect +test/roles/gceplugin/meta/main.yml meta-no-info +test/roles/gceplugin/meta/main.yml schema[meta] +test/roles/gceplugin/molecule/default/verify.yml yaml[indentation] +test/roles/gceplugin/tests/test.yml name[play] + +test/roles/podmanplugin/meta/main.yml meta-incorrect +test/roles/podmanplugin/meta/main.yml meta-no-info +test/roles/podmanplugin/meta/main.yml schema[meta] +test/roles/podmanplugin/molecule/default/verify.yml yaml[indentation] +test/roles/podmanplugin/tests/test.yml name[play] + +test/roles/vagrantplugin/meta/main.yml meta-incorrect +test/roles/vagrantplugin/meta/main.yml meta-no-info +test/roles/vagrantplugin/meta/main.yml schema[meta] +test/roles/vagrantplugin/molecule/default/verify.yml yaml[indentation] +test/roles/vagrantplugin/tests/test.yml name[play] + +test/roles/containersplugin/meta/main.yml meta-incorrect +test/roles/containersplugin/meta/main.yml meta-no-info +test/roles/containersplugin/meta/main.yml schema[meta] +test/roles/containersplugin/molecule/default/verify.yml yaml[indentation] +test/roles/containersplugin/tests/test.yml name[play] +test/roles/containersplugin/molecule/default/converge.yml fqcn[action-core] diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3199104d..1e9fa691 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,7 +9,7 @@ exclude: > )$ default_language_version: python: python3 -minimum_pre_commit_version: "1.14.0" +minimum_pre_commit_version: 1.14.0 repos: - repo: https://github.com/pre-commit/mirrors-prettier # keep it before yamllint @@ -50,3 +50,4 @@ repos: rev: v6.14.6 hooks: - id: ansible-lint + entry: env ANSIBLE_ROLES_PATH="$ANSIBLE_ROLES_PATH:test/roles" ansible-lint diff --git a/requirements.yml b/requirements.yml index 13ad720a..7a4ac22f 100644 --- a/requirements.yml +++ b/requirements.yml @@ -6,5 +6,8 @@ collections: - name: community.docker version: ">=3.0.2" - name: containers.podman + - name: azure.azcollection + version: ">=1,<2" - name: community.crypto + version: ">=1.8.0" - name: community.vagrant diff --git a/tools/extract_plugin_names.py b/tools/extract_plugin_names.py new file mode 100644 index 00000000..259a4902 --- /dev/null +++ b/tools/extract_plugin_names.py @@ -0,0 +1,20 @@ +import sys + + +def print_plugin_names() -> None: + import toml + + if len(sys.argv) != 2: + raise SystemExit(f"Usage: {sys.argv[0]} ") + + filename = sys.argv[1] + with open(filename) as f: + toml_data = toml.load(f) + + result = toml_data["project"]["entry-points"]["molecule.driver"].keys() + for i in result: + print(i) # noqa: T201 + + +if __name__ == "__main__": + print_plugin_names() diff --git a/tools/generate-templates.sh b/tools/generate-templates.sh new file mode 100644 index 00000000..a5941f8c --- /dev/null +++ b/tools/generate-templates.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +set -euo pipefail + +rm -rf test/roles/* || true +mkdir -p test/roles + +while IFS='' read -r line; do DRIVER_NAMES+=("$line"); done < <(python "tools/extract_plugin_names.py" "pyproject.toml") + +cd test/roles +for DRIVER_NAME in "${DRIVER_NAMES[@]}"; do + molecule init role roles."${DRIVER_NAME}"plugin --driver-name="${DRIVER_NAME}" +done + +exit 0 diff --git a/tox.ini b/tox.ini index 44b608ac..fa395466 100644 --- a/tox.ini +++ b/tox.ini @@ -77,9 +77,13 @@ commands = [testenv:lint] description = Performs linting, style checks -skip_install = true -sitepackages = false +allowlist_externals = + bash + rm deps = pre-commit + toml commands = + bash {toxinidir}/tools/generate-templates.sh pre-commit run -a + rm -rf test/roles