From df841c9aff12705675fd33e31c1783b9b3ce60b2 Mon Sep 17 00:00:00 2001 From: Rich Megginson Date: Thu, 11 May 2023 17:47:41 -0600 Subject: [PATCH] add ansible-lint-collection Add testenv for `ansible-lint-collection` that runs `ansible-lint` against a collection created with the `collection` testenv. Updated yamllint.yml with the latest fixes. Updated runcollection.sh to include some fixes to allow ansible-lint to pass. --- .../config_files/collection_yamllint.yml | 9 -------- src/tox_lsr/config_files/tox-default.ini | 21 ++++++++++++++++++- src/tox_lsr/test_scripts/runcollection.sh | 5 +++++ tests/fixtures/test_tox_merge_ini/result.ini | 19 ++++++++++++++++- 4 files changed, 43 insertions(+), 11 deletions(-) diff --git a/src/tox_lsr/config_files/collection_yamllint.yml b/src/tox_lsr/config_files/collection_yamllint.yml index 3260168..5cfeecb 100644 --- a/src/tox_lsr/config_files/collection_yamllint.yml +++ b/src/tox_lsr/config_files/collection_yamllint.yml @@ -3,17 +3,8 @@ extends: default ignore: | /.tox/ - /tests/storage/ rules: line-length: disable - truthy: disable - braces: - max-spaces-inside: 1 - level: error - brackets: - max-spaces-inside: 1 - level: error - document-start: disable comments: min-spaces-from-content: 1 comments-indentation: disable diff --git a/src/tox_lsr/config_files/tox-default.ini b/src/tox_lsr/config_files/tox-default.ini index 6f25b2c..f9698d7 100644 --- a/src/tox_lsr/config_files/tox-default.ini +++ b/src/tox_lsr/config_files/tox-default.ini @@ -30,6 +30,7 @@ setenv = LSR_ROLE2COLL_NAMESPACE = fedora LSR_ROLE2COLL_NAME = linux_system_roles LSR_TOX_ENV_TMP_DIR = {envtmpdir} + LSR_ANSIBLE_LINT_CONTAINER = {env:LSR_ANSIBLE_LINT_CONTAINER:quay.io/ansible/creator-ee:v0.16.0} deps = py{26,27,36,37,38,39,310,311}: pytest-cov py{27,36,37,38,39,310,311}: pytest>=3.5.1 @@ -245,12 +246,30 @@ commands = {env:LSR_CONTAINER_RUNTIME:podman} run --rm --privileged \ -v {toxinidir}:/workdir --workdir /workdir \ --entrypoint /usr/local/bin/ansible-lint \ - quay.io/ansible/creator-ee:v0.16.0 \ + {env:LSR_ANSIBLE_LINT_CONTAINER} \ {env:RUN_ANSIBLE_LINT_EXTRA_ARGS:} {posargs} {[lsr_config]commands_post} commands_post = bash {lsr_scriptdir}/ansible-lint-helper.sh post +[testenv:ansible-lint-collection] +changedir = {toxworkdir}/ansible_collections/{env:LSR_ROLE2COLL_NAMESPACE}/{env:LSR_ROLE2COLL_NAME} +allowlist_externals = + podman + bash + cp +commands = + bash {lsr_scriptdir}/setup_module_utils.sh + {[lsr_config]commands_pre} + cp {toxinidir}/.ansible-lint {toxworkdir}/ansible_collections/{env:LSR_ROLE2COLL_NAMESPACE}/{env:LSR_ROLE2COLL_NAME} + {env:LSR_CONTAINER_RUNTIME:podman} run --rm --privileged \ + -v {toxworkdir}/ansible_collections/{env:LSR_ROLE2COLL_NAMESPACE}/{env:LSR_ROLE2COLL_NAME}:/workdir \ + --workdir /workdir \ + --entrypoint /usr/local/bin/ansible-lint \ + {env:LSR_ANSIBLE_LINT_CONTAINER} \ + {env:RUN_ANSIBLE_LINT_EXTRA_ARGS:} {posargs} + {[lsr_config]commands_post} + [testenv:ansible-test] # NOTE: ansible-test in ansible 2.9 seems to become confused # when running in a venv that uses basepython 3.9 or later diff --git a/src/tox_lsr/test_scripts/runcollection.sh b/src/tox_lsr/test_scripts/runcollection.sh index 6797d12..8b47575 100755 --- a/src/tox_lsr/test_scripts/runcollection.sh +++ b/src/tox_lsr/test_scripts/runcollection.sh @@ -41,6 +41,11 @@ cp "$LSR_TOX_ENV_DIR/tmp/galaxy.yml" "$TOX_WORK_DIR/ansible_collections/$LSR_ROL # create the collection in this dir to share with other testenvs cd "$TOX_WORK_DIR/ansible_collections/$LSR_ROLE2COLL_NAMESPACE/$LSR_ROLE2COLL_NAME" +# these are for ansible-lint +cp "$LSR_CONFIGDIR/collection_yamllint.yml" \ + "$TOX_WORK_DIR/ansible_collections/$LSR_ROLE2COLL_NAMESPACE/$LSR_ROLE2COLL_NAME/.yamllint.yml" +touch "$TOX_WORK_DIR/ansible_collections/$LSR_ROLE2COLL_NAMESPACE/$LSR_ROLE2COLL_NAME/CHANGELOG.md" + # unit testing not working yet - will need these and more #export RUN_PYTEST_UNIT_DIR="$role/unit" #export PYTHONPATH="$MY_LSR_TOX_ENV_DIR/ansible_collections/"${LSR_ROLE2COLL_NAME}"/"${LSR_ROLE2COLL_NAME}"/plugins/modules:$MY_LSR_TOX_ENV_DIR/ansible_collections/"${LSR_ROLE2COLL_NAME}"/"${LSR_ROLE2COLL_NAME}"/plugins/module_utils" diff --git a/tests/fixtures/test_tox_merge_ini/result.ini b/tests/fixtures/test_tox_merge_ini/result.ini index 184dda1..214a77f 100644 --- a/tests/fixtures/test_tox_merge_ini/result.ini +++ b/tests/fixtures/test_tox_merge_ini/result.ini @@ -26,6 +26,7 @@ setenv = PYTHONPATH = {env:LSR_PYTHONPATH:}{toxinidir}/library:{toxinidir}/modul LSR_ROLE2COLL_NAMESPACE = fedora LSR_ROLE2COLL_NAME = linux_system_roles LSR_TOX_ENV_TMP_DIR = {envtmpdir} + LSR_ANSIBLE_LINT_CONTAINER = {env:LSR_ANSIBLE_LINT_CONTAINER:quay.io/ansible/creator-ee:v0.16.0} LOCAL1 = local1 LOCAL2 = local2 deps = py{26,27,36,37,38,39,310,311}: pytest-cov @@ -204,11 +205,27 @@ commands = bash {lsr_scriptdir}/setup_module_utils.sh {env:LSR_CONTAINER_RUNTIME:podman} run --rm --privileged \ -v {toxinidir}:/workdir --workdir /workdir \ --entrypoint /usr/local/bin/ansible-lint \ - quay.io/ansible/creator-ee:v0.16.0 \ + {env:LSR_ANSIBLE_LINT_CONTAINER} \ {env:RUN_ANSIBLE_LINT_EXTRA_ARGS:} {posargs} {[lsr_config]commands_post} commands_post = bash {lsr_scriptdir}/ansible-lint-helper.sh post +[testenv:ansible-lint-collection] +changedir = {toxworkdir}/ansible_collections/{env:LSR_ROLE2COLL_NAMESPACE}/{env:LSR_ROLE2COLL_NAME} +allowlist_externals = podman + bash + cp +commands = bash {lsr_scriptdir}/setup_module_utils.sh + {[lsr_config]commands_pre} + cp {toxinidir}/.ansible-lint {toxworkdir}/ansible_collections/{env:LSR_ROLE2COLL_NAMESPACE}/{env:LSR_ROLE2COLL_NAME} + {env:LSR_CONTAINER_RUNTIME:podman} run --rm --privileged \ + -v {toxworkdir}/ansible_collections/{env:LSR_ROLE2COLL_NAMESPACE}/{env:LSR_ROLE2COLL_NAME}:/workdir \ + --workdir /workdir \ + --entrypoint /usr/local/bin/ansible-lint \ + {env:LSR_ANSIBLE_LINT_CONTAINER} \ + {env:RUN_ANSIBLE_LINT_EXTRA_ARGS:} {posargs} + {[lsr_config]commands_post} + [testenv:ansible-test] basepython = python3 deps = {env:LSR_ANSIBLE_TEST_DEP:ansible-core==2.14.*}