Skip to content

Commit

Permalink
add ansible-lint-collection
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
richm committed May 11, 2023
1 parent 18b5e3d commit dd0fd5e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 11 deletions.
9 changes: 0 additions & 9 deletions src/tox_lsr/config_files/collection_yamllint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 20 additions & 1 deletion src/tox_lsr/config_files/tox-default.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/tox_lsr/test_scripts/runcollection.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
19 changes: 18 additions & 1 deletion tests/fixtures/test_tox_merge_ini/result.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.*}
Expand Down

0 comments on commit dd0fd5e

Please sign in to comment.