Commit graph

53 commits

Author SHA1 Message Date
Rich Megginson
206c354b7e [citest skip] bump tox-lsr version to 2.9.1
Signed-off-by: Rich Megginson <rmeggins@redhat.com>

The new tox-lsr also requires the use of `{toxinidir}` for the
local config file paths.
2022-02-07 18:58:27 -07:00
Wen Liang
f813fb33b7 fix ensure_provider_tests.py; fix generated tests; add check to CI
Fix ensure_provider_tests.py so that the tests are correctly generated.
Because the generated tests have not been checked in a while, there was
some drift between the actual tests and what should have been generated,
so the new generated tests have also been included.
When `ensure_provider_tests.py` detects differences, it will now show
the diffs using a unified diff format.
Added a new tox testenv `ensure_provider_tests` - use
`tox -e ensure_provider_tests` to run - to pass arguments, use
`tox -e ensure_provider_tests -- generate`
Added `ensure_provider_tests` as one of the tox testenvs to run for
github tox CI.

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2021-10-19 20:21:03 +02:00
Rich Megginson
f5ff30a66c fix most ansible-test issues, suppress the rest
Automation Hub, and possibly Galaxy in the future, require the
collection to be screened with `ansible-test sanity` among other
checks.  The role had a number of issues:
* Use `AssertionError` instead of `assert`
* Use of `logging` module not in accordance with standards, but these
  are ok and the errors were suppressed
* Several import errors which are ok because they are checked
  elsewhere
* __init__.py in the module_utils directories must be empty, so a
  new file myerror.py was added to move the code from __init__.py
  * NOTE: network_lsr/nm/__init__.py is not empty
* The documentation block in the module was not properly constructed
  or formatted.
* shellcheck issues, including removing unused files
* use `unused` instead of `_` (underscore) for variables that are
  unused

add WARNING to module docs - collection users should not use directly

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2021-04-09 19:57:55 +02:00
Rich Megginson
4f9f7a4c94 make CI work with tox-lsr
Use tox-lsr instead of the scripts in the `.travis/` directory and the
asssociated config files.  Yes, `.travis/custom.sh` is still there,
but once you are familiar with the way that tox-lsr works, you can
remove it and use your own custom tox.ini action.  The goal of this
commit was to make as few changes as possible, to keep feature parity
with the old `.travis/` script way of running CI.  Also note that
linting has moved into tox, so we needed to disable molecule linting.
The new version of ansible-lint adds a lot of checks, so these are
disabled for now, and should be fixed later.  Also, shellcheck is
turned off until the network team can address the issues.

The `.travis/custom.sh` script is not run in the CI environment, so
this was changed slightly to remove the check for `$TRAVIS`, and it is
no longer run as a tox testenv in CI.

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2020-12-18 10:32:16 +08:00
Rich Megginson
c64b3b15ba use github actions instead of travis
adds a github actions tox workflow for CI testing, since
travis is discontinuing support for open source projects

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2020-12-11 14:46:40 +08:00
Noriko Hosoi
18ed81168f Sync with travis/runcollection.sh template
Source commit in the template repo: e9f2c3a 4f3c96a
    Merge pull request #48 from nhosoi/collections
    runcollection.sh - stop passing an argument list

This change allows to eliminate the test argument list as well as the
branch name to retrieve the lsr_role2collection.py script for the
collection test.

Signed-off-by: Noriko Hosoi <nhosoi@redhat.com>
2020-11-06 10:45:54 +01:00
Noriko Hosoi
890af84071 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.
2020-10-23 13:35:14 +08:00
Rich Megginson
67c1cced8f Fix Travis CI issue with Docker server API version mismatch
Travis CI is using a version of Docker server that supports API version
1.38.  However, the Python PYPI package `docker` version 4.3 was
recently released which uses Docker server API version 1.39, and there
is apparently no way to tell molecule to configure the `docker` Python
API to use a different API.  The solution is to install the latest 4.2.x
version of the `docker` Python PYPI package.
2020-08-17 14:45:41 +02:00
Till Maas
b5fb076579 tox: Use C.UTF-8 locale
Molecule requires a UTF-8 molecule because of click:
https://click.palletsprojects.com/en/7.x/python3/
2020-05-06 19:20:01 +02:00
Till Maas
615db2e642 tox: Move common options to testenv
Move several common options to testenv instead of base to simplify the
file and use normal tox inheritance.
2020-05-06 19:20:01 +02:00
Till Maas
47381469a1 tox: Add travis config for 3.8-dev
As reported in https://github.com/tox-dev/tox-travis/issues/147, the
python factor in tox-travis needs to match the Travis python environment
and not the python version. Therefore, add a separate line.
2020-05-05 15:47:58 +02:00
Till Maas
0258ee8575 travis: Upgrade to bionic 2020-05-05 11:14:01 +02:00
Till Maas
c398f401f9 Travis/tox: Run coveralls for all unit tests
Run coveralls after the unit tests to ensure that coverage data is
available
2020-04-18 16:20:52 +02:00
Rich Megginson
05a9223a33 move flake8 args to [flake8] section of tox.ini
tox supports a `[flake8]` section, so move the default
settings there rather than having them passed in on the
command line.  Projects can still override flake8 arguments
by using `RUN_FLAKE8_EXTRA_ARGS` in `.travis/config.sh`

Signed-off-by: Till Maas <opensource@till.name>
2020-04-08 13:16:43 +02:00
Rich Megginson
92519644ba python 2.6 support for pytest and ansible 2.6
Removed `mock` from the `testenv` `deps`.
Added `mock` to the template pytest_extra_requirements.txt,
commented out.  Projects such as network that need it can uncomment it.
2020-04-07 11:02:28 +02:00
Rich Megginson
7fdfa3204e update to latest template code
These changes don't directly affect network, or don't actually
change the behavior of existing code that network uses (coveralls),
but are intended to sync with the latest template code.

Adds `LSR_PUBLISH_COVERAGE=normal` to `.travis/config.sh` because
network wants to publish coverage normally (as opposed to `strict`
or not at all).
2020-04-07 11:01:26 +02:00
Rich Megginson
dec163940e support testing/linting module_utils code
This does not directly affect network because network has its own
solution for dealing with testing/linting module_utils code, but
it gets network to feature/code parity with the template and
other repos.

Defines a shell function in utils.sh - lsr_setup_module_utils -
that allows configuring a tox venv installed ansible to have
the repo module_utils code in the default pythonpath for the
venv, which allows testing and linting the module_utils code
without having to otherwise munge or mock the pythonpath.

Projects needing this functionality can set in `.travis/config.sh`
the variable `RUN_PYTEST_SETUP_MODULE_UTILS` to setup
module_utils/ for pytest, and `RUN_PYLINT_SETUP_MODULE_UTILS`
to setup module_utils/ for pylint.
2020-04-06 19:14:42 +02:00
Rich Megginson
23937b6360 use python instead of envpython
Many of the tests and tasks invoked from `tox` would try to use
the path to the `python` executable in the tox virtualenv, and
in some cases, would try to follow the symlink if the `python`
command were a symlink, in some cases, following the symlink to
the system python, and trying to use the absolute path.  This
would fail in some cases because when using the system python
with the absolute path, the python modules installed in the
tox venv could not be found.  So instead, just use the `python`
command from the venv with no path.

also enable travis 3.8-dev testing, since this fix allows that
platform to work correctly.
2020-04-01 20:57:09 +02:00
Till Maas
d32f4e5a7b molecule/tox: Support yamllint without molecule
With molecule v3, the linter config needs to be changed. To prepare for
this, run yamllint with tox as molecule would do it for V3.
2020-03-24 13:55:27 +01:00
Till Maas
446d78d373 Tox: Pin molecule to version 2
Molecule version 3 and later needs a different configuration file for
linters. This breaks the CI. Pin molecule to version 2 for now to
fix the CI until we have a proper fix.
2020-02-24 18:53:34 +01:00
Jiri Kucera
4b05c201db Support more Ansible versions
Support running the molecule tests against more versions of Ansible.
By typing

  LSR_ANSIBLE_DEP=<ansible> LSR_MSCENARIO=<scenario> tox -e molecule

one can run molecule inside tox with <ansible> version installed
under <scenario> scenario. For example

  LSR_ANSIBLE_DEP='ansible==2.7.*' LSR_MSCENARIO=foo tox -e molecule

will run molecule under scenario 'foo' and the recent Ansible 2.7
installed. `tox -e molecule` run molecule under default scenario
with the latest Ansible (from pypi) installed.

Travis runs molecule tests for Ansible 2.6, 2.7, and 2.8 installed
and under default scenario (can be overriden by user in config.sh).

Additional changes: Remove useless comment from custom.sh.
2020-02-03 12:41:30 +01:00
Jiri Kucera
cb518856c4 Run molecule via runsyspycmd.sh
runsyspycmd.sh script runs a given command only if venv Python
matches the system Python (this prevents failing when some command
depends on binary libraries).

Also put `molecule --version` and `ansible --version` to a standalone
testenv ([testenv:molecule_version]) so a user can display molecule
and ansible version by typing `tox -e molecule_version` without
running `molecule lint`.
2020-01-30 10:11:42 +01:00
Jiri Kucera
ad6cffe19d tox: molecule extra requirements
Pass extra molecule dependencies via file and not via environment
variable. Also add selinux as a permanent molecule dependency
(molecule needs it on selinux enabled systems to setup containers).
2020-01-20 13:23:38 +01:00
Jiri Kucera
fc0c37efc1 Wrap flake8
Wrapping flake8 give a possibility to a user to dissable flake8 via
setting environment variable in config.sh.
2020-01-20 10:10:14 +01:00
Jiri Kucera
677f7b8918 Wrap pylint runner
Prior this change, RUN_PYLINT_* environment variables set by config.sh
have effect only while running in Travis (because runtox script sets
them by including config.sh). By wrapping pylint runner with shell
script, RUN_PYLINT_* environment variables have effect also while
running tox locally.
2020-01-16 16:19:50 +01:00
Jiri Kucera
2c79fad96f Add black wrapper
Some system roles want not to run black on their code. This wrapper
decides whether to run black or not depending on content of config.sh.
This wrapper also allows to set patterns of files and directories via
config.sh to be processed or skipped by black.
2020-01-13 11:57:13 +01:00
Jiri Kucera
e026322cde Add pytest wrapper
Not every system role contains parts written in Python, which
confuses pytest. With a shell wrapper around pytest, pytest
can be skipped or run with adjusted parameters depending on the
content or presence of system role's specific directories.
2020-01-13 10:23:39 +01:00
Till Maas
6cf9124ce2 tox: Rename extra to custom 2019-11-27 19:19:42 +01:00
Till Maas
7145d894a4 tox: Support pylint extra requirements 2019-11-27 18:36:45 +01:00
Jiri Kucera
1490a46f47 Add SPDX-License-Identifier: MIT 2019-09-12 11:49:01 +02:00
Jiri Kucera
392ff45c9d Cleanup [travis] section 2019-09-12 11:22:36 +02:00
Jiri Kucera
7181919cc0 Add missing testenv: prefix 2019-09-12 10:51:02 +02:00
Jiri Kucera
4b51f0eb47 Exclude molecule from envlist
molecule needs root privileges to run, so it is better to run
molecule explicitly
2019-09-12 09:28:51 +02:00
Jiri Kucera
047469b14d Incorporate changes from PR #120 2019-09-02 14:27:10 +02:00
Jiri Kucera
b9b3561653 Support multiple Molecule scenarios
Other changes:
- run linters before tests
- return [pylint] and [pycodestyle] back on the list (some IDE's
  rely on this)
2019-08-19 12:48:30 +02:00
Jiri Kucera
7af5797b7d Reuse virtual environments
Virtual environments names are now based on the version of Python
interpreter that is used. This prevents creation of redundant
environments, that is there will be only one[1] virtual environment
per Python interpreter, which saves the time by preventing the
installation of the same packages more than once.

[1] In Travis CI, this is easy to implement by using the
    TRAVIS_PYTHON_VERSION environment variable. Locally, as there
    is no information about what version of Python interpreter is
    used when creating a virtual environment in tox, there may be
    more virtual environments per interpreter (for example, env-3.6
    and env-molecule may be both based on Python 3.6).
2019-08-01 00:19:07 +02:00
Jiri Kucera
f21d01ab68 Add pylint wrapper
Add run_pylint.py that probe working directory for python source files
and pass them to pylint. This is needed because pylint expects module
or package, so passing a directory with no __init__.py in it makes
pylint angry. With this change, LSR_PYLINT_DIRS is no longer needed.

Additionally, we no longer need:
- init-hook in pylintrc
- [pylintrc] section in tox.ini, because the configuration from this
  section is now the part of pylintrc
- [pycodestyle] section in tox.ini, because pycodestyle linter is not
  used
2019-07-31 00:52:26 +02:00
Jiri Kucera
f5bc42632d Missing backslash 2019-07-19 12:49:00 +02:00
Jiri Kucera
5d7e544134 Allow running tox also locally
- use `./.travis/runtox [ARG1 [ARG2 [...[ARGn]]]]` to run tox locally
- use LSR_USE_PYTHON to decide whether to run jobs with pylinters and
  pytesters or not
2019-07-19 11:45:26 +02:00
Jiri Kucera
8102fd6443 Refactor Travis CI setup
This commit introduces the refactored Travis CI setup and tox.ini
to fullfil the need to have common CI setup across all roles.

The current proposal and discussion can be found at:
https://github.com/linux-system-roles/template/issues/4
2019-07-17 11:18:50 +02:00
Till Maas
494b4cd5ed tox: Work around Python 2.6 issues with tox 3
Fedora 30 uses tox 3 which does not work with Python 2.6 out of the box.
Setting the install and list_dependencies commands to run `pip` instead
of `python -m pip` seems to fix this for now.
2019-06-11 14:40:57 +02:00
Till Maas
0cbf94af61 unitests: Move unit tests in separate directory 2019-06-06 09:06:16 +02:00
Till Maas
f9fff1776d tox: Use custom selinux shim
Travis uses Ubuntu which is not yet supported by the python selinux
shim. Use a custom fork instead.
2019-05-06 11:08:44 +02:00
Till Maas
2da9e46d16 Travis: Use python 3.5 for molecule
Python 3.5 is the native python version in Ubuntu Xenial:
https://packages.ubuntu.com/xenial/python3
2019-05-06 11:08:44 +02:00
Till Maas
48d17d44b3 Run molecule with tox 2019-05-06 11:08:44 +02:00
Till Maas
1ec39050ff travis: Test against more python versions 2019-04-25 13:23:34 +02:00
Till Maas
382c34197b Modularize role
Splitting the role in smaller parts helps to keep the overview and to
develop separate tests.
2018-08-15 10:04:47 +02:00
Till Maas
c279f0afc5 Run integration tests with other provider, too
- Amend and add files to run integration tests against the provider that
was not autodetected, too.
- Add check to ensure that all integration tests run against both
providers
- Run black check for all python scripts
2018-08-01 23:13:30 +02:00
Till Maas
e32033f995 Use black as formatter and enable flake8/pylint 2018-07-18 17:23:18 +02:00
Till Maas
7c5dce7a1d Fix typo in tox.ini 2018-07-11 12:35:35 +02:00