RHELPLAN-56586 - sync collections related changes from template to network role

The task 56586 is for adding tests against the collection converted
format to the tox/travis CI to capture a problem before merging the
pr, if any. It'd be helpful to find out bugs in the conversion tool
lsr_role2collection.py, as well. The source of this commit is located
in linux-system-roles/template. They are synced by auto-maintenance/
sync-template.sh, then manually adjusted to the network role.

.travis/runcollection.sh is the test script. tox.ini is modified to run
it in the tox/travis CI. The script downloads lsr_role2collection.py,
then converts the network role into the conversion format in the working
directory .tox. In the collection, it runs a set of tests black, flake8,
yamllint, py38 to check the converted result.
This commit is contained in:
Noriko Hosoi 2020-10-12 13:25:17 -07:00 committed by Gris Ge
parent 3c7580d7f9
commit 890af84071
7 changed files with 60 additions and 12 deletions

View file

@ -42,7 +42,7 @@
type -f lsr_check_python_version > /dev/null 2>&1 || . ${SCRIPTDIR}/utils.sh
if lsr_check_python_version python -lt 3.0
then
PYTHON2_EXCLUDES="tests/ensure_provider_tests.py,scripts/print_all_options.py"
PYTHON2_EXCLUDES="tests/ensure_provider_tests.py,scripts/print_all_options.py,tests/network/ensure_provider_tests.py"
FLAKE8_DEFAULT_EXCLUDES=".svn,CVS,.bzr,.hg,.git,__pycache__,.tox,.eggs,*.egg"
RUN_PYLINT_EXCLUDE='^(\..*|ensure_provider_tests\.py|print_all_options\.py)$'
RUN_FLAKE8_EXTRA_ARGS="--exclude ${FLAKE8_DEFAULT_EXCLUDES},${PYTHON2_EXCLUDES}"

38
.travis/runcollection.sh Executable file
View file

@ -0,0 +1,38 @@
#!/bin/bash
# SPDX-License-Identifier: MIT
set -e
#uncomment if you use $ME - otherwise set in utils.sh
#ME=$(basename "$0")
SCRIPTDIR=$(readlink -f "$(dirname "$0")")
. "${SCRIPTDIR}/utils.sh"
. "${SCRIPTDIR}/config.sh"
# Collection commands that are run when `tox -e collection`:
role=$(basename "${TOPDIR}")
toxworkdir=${1:-"${TOPDIR}"/.tox}
STABLE_TAG=${2:-master}
cd "${toxworkdir}"
toxworkdir=$(pwd)
envlist=${3:-"black,flake8,yamllint,py38,shellcheck"}
automaintenancerepo=https://raw.githubusercontent.com/linux-system-roles/auto-maintenance/
curl -L -o lsr_role2collection.py "${automaintenancerepo}${STABLE_TAG}"/lsr_role2collection.py
python lsr_role2collection.py --src-path "${TOPDIR}/.." --dest-path "${toxworkdir}" --role "${role}" > "${toxworkdir}"/collection.out 2>&1
yamllint="${toxworkdir}"/ansible_collections/fedora/system_roles/.yamllint_defaults.yml
sed -i -e 's/\( *\)\(document-start: disable\)/\1\2\n\1line-length:\n\1\1level: warning/' "${yamllint}"
cd ansible_collections/fedora/system_roles
tox -e "${envlist}" 2>&1 | tee "${toxworkdir}"/collection.tox.out || :
rm -rf "${toxworkdir}"/auto-maintenance "${toxworkdir}"/ansible_collections
cd "${TOPDIR}"
res=$(grep "^ERROR: .*failed" "${toxworkdir}"/collection.tox.out || :)
if [ "$res" != "" ]; then
lsr_error "${ME}: tox in the converted collection format failed."
exit 1
fi

View file

@ -14,17 +14,17 @@ import traceback
# pylint: disable=import-error, no-name-in-module
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network_lsr import ethtool
from ansible.module_utils.network_lsr import MyError
from ansible.module_utils.network_lsr import ethtool # noqa:E501
from ansible.module_utils.network_lsr import MyError # noqa:E501
from ansible.module_utils.network_lsr.argument_validator import (
from ansible.module_utils.network_lsr.argument_validator import ( # noqa:E501
ArgUtil,
ArgValidator_ListConnections,
ValidationError,
)
from ansible.module_utils.network_lsr.utils import Util
from ansible.module_utils.network_lsr import nm_provider
from ansible.module_utils.network_lsr.utils import Util # noqa:E501
from ansible.module_utils.network_lsr import nm_provider # noqa:E501
# pylint: enable=import-error, no-name-in-module

View file

@ -6,8 +6,8 @@ import posixpath
import socket
# pylint: disable=import-error, no-name-in-module
from ansible.module_utils.network_lsr import MyError
from ansible.module_utils.network_lsr.utils import Util
from ansible.module_utils.network_lsr import MyError # noqa:E501
from ansible.module_utils.network_lsr.utils import Util # noqa:E501
class ArgUtil:

View file

@ -2,7 +2,7 @@
""" Support for NetworkManager aka the NM provider """
# pylint: disable=import-error, no-name-in-module
from ansible.module_utils.network_lsr.utils import Util
from ansible.module_utils.network_lsr.utils import Util # noqa:E501
ETHTOOL_FEATURE_PREFIX = "ETHTOOL_OPTNAME_FEATURE_"

View file

@ -7,7 +7,7 @@ import sys
import uuid
# pylint: disable=import-error, no-name-in-module
from ansible.module_utils.network_lsr import MyError
from ansible.module_utils.network_lsr import MyError # noqa:E501
class Util:

14
tox.ini
View file

@ -3,7 +3,7 @@
envlist =
black, pylint, flake8, yamllint
py{26,27,36,37,38},
custom
collection, custom
skipsdist = true
skip_missing_interpreters = true
@ -162,6 +162,16 @@ commands =
{[testenv:molecule_syntax]commands}
{[testenv:molecule_test]commands}
[testenv:collection]
changedir = {toxinidir}
ansible_python_interpreter = /usr/bin/python3
deps =
ruamel.yaml
ansible
jmespath
commands =
bash {toxinidir}/.travis/runcollection.sh {toxworkdir} master 'black,flake8,yamllint,py38'
[testenv:custom]
changedir = {toxinidir}
envdir = {toxworkdir}/env-{env:TRAVIS_PYTHON_VERSION:custom}
@ -192,7 +202,7 @@ max-line-length = 88
python =
2.6: py26,coveralls,custom
2.7: py27,coveralls,flake8,pylint,custom
3.6: py36,coveralls,black,yamllint,custom
3.6: py36,coveralls,black,yamllint,custom,collection
3.7: py37,coveralls,custom
3.8: py38,coveralls,custom
3.8-dev: py38,coveralls,custom