Skip to content

Commit

Permalink
Enhancement: Generate cookie cutter templates and apply linting on th…
Browse files Browse the repository at this point in the history
…em (#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>
  • Loading branch information
wadhah101 and pre-commit-ci[bot] authored May 11, 2023
1 parent c69541c commit 7d8f040
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 8 deletions.
5 changes: 0 additions & 5 deletions .ansible-lint
Original file line number Diff line number Diff line change
Expand Up @@ -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
95 changes: 95 additions & 0 deletions .ansible-lint-ignore
Original file line number Diff line number Diff line change
@@ -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]
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
3 changes: 3 additions & 0 deletions requirements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 20 additions & 0 deletions tools/extract_plugin_names.py
Original file line number Diff line number Diff line change
@@ -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>")

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()
15 changes: 15 additions & 0 deletions tools/generate-templates.sh
Original file line number Diff line number Diff line change
@@ -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
8 changes: 6 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7d8f040

Please sign in to comment.