Use ansible-test units for unit testing
This is urgent due to ansible-core dropping support for python 2.7. This causes our tox -e py27 unit test to fail:
ERROR: Could not find a version that satisfies the requirement ansible-core==2.12.* (from versions: 0.0.1a1, 2.11.0b1, 2.11.0b2, 2.11.0b3, 2.11.0b4, 2.11.0rc1, 2.11.0rc2, 2.11.0, 2.11.1rc1, 2.11.1, 2.11.2rc1, 2.11.2, 2.11.3rc1, 2.11.3, 2.11.4rc1, 2.11.4, 2.11.5rc1, 2.11.5, 2.11.6rc1, 2.11.6, 2.11.7rc1)
It isn't clear from the error, but because ansible-core requires python >= 3.8, we get this error.
Instead, we should use ansible-test units which is designed for this purpose. And - it covers python 2.6 and 2.7, as well as all supported python 3.x versions (when using --docker - note that if you dnf install podman-docker you can use podman instead of the "real" docker)
We already have support for ansible-test in tox-lsr: https://github.com/linux-system-roles/tox-lsr/blob/main/src/tox_lsr/config_files/tox-default.ini#L244 and https://github.com/linux-system-roles/tox-lsr/blob/main/src/tox_lsr/test_scripts/runansible-test.sh
However, it will take a good bit of effort to make our unit testing work with ansible-test.
-
get rid of py26 and py27 from all .github/workflows/tox.yml These do not work and cause unnecessary test failures
-
support for
--dockeris more important than without That is - tests must work withansible-test units --dockerandansible-test sanity --docker. If they don't work without--docker, that is ok, at least for now. -
change lsr_role2collection.py This must convert the unit tests into the format expected by
ansible-test unitsandansible-test sanity. The tests must be in$namespace/$name/tests/unit/plugins/modules/$rolename/test_*.pyThe tests must use the FQCN to load the python code from the module and module_utils. This will be quite problematic for the network role especially. Must convert test requirements into tests/unit/requirements.txt - See https://github.com/ansible-collections/ansible.posix/blob/main/tests/unit/requirements.txt for example. We can probably use pytest_extra_requirements.txt. I think kernel_settings will be quite problematic as it uses tuned as a requirement, which also has system requirements (bindep.txt?)
We may have to change the individual tests/unit/*.py files in each role in order to support this, or to make it easier to convert.
-
fix
ansible-test sanityto make import and compile tests work If we convert roles to collections correctly, and get the requirements.txt correct, this may make the sanity import and compile tests work, so we don't have to ignore them -
should still be able to use
tox -e py38or evenpytestdirectly For role developers who just want to run tests directly on their local git clone without converting to collection format. -
add an
ansible-test-unitstest to tox-lsr So that developers can easily run this -
in github CI - get rid of
pyxxtests - add anansible-test-unitstest add a github CI test which uses tox-lsransible-test-units
For more information, see https://docs.ansible.com/ansible/latest/dev_guide/developing_collections_testing.html and https://docs.ansible.com/ansible/latest/dev_guide/testing_units_modules.html