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

Enhancement: Generate cookie cutter templates and apply linting on them #123

Merged
merged 6 commits into from
May 11, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every time we run tox -e lint, it will generate some temporary files locally, can we add test/roles in .gitignore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pre-commit will ignore stuff inside .gitignore

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be missing something but why not creating a temporary directory with mktemp ? issue with non linux os like macosx ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What benefitsmktemp can bring?

IMHO, mktemp is better for unique file name. In this PR, we just want to create a directory and generate some files in them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find it cleaner. It won't do any change in the working directory and it should avoid having to deal with configurations files of tools like git or pre-commit to ignore it.

Copy link
Contributor Author

@wadhah101 wadhah101 Apr 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's some errors in the generated molecule template that I have no way around. which requires me to add the files to .ansible-lint-ignore.

I prefer to use mktemp but .ansible-lint-ignore doesn't take wildcard paths sadly

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm. maybe it would be easier to fix all errors before merging this PR, maybe this would make the .ansible-lint-ignore file useless ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some errors are unfixable. And the fixable ones are too much to be included in this PR. there's no going around .ansible-lint-ignore file

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fun to fix the real lint issue in another issue.

Ignoring them to make the PR smaller is acceptable.


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