linux-system-roles / linux-system-roles.github.io

Linux System Roles website
https://linux-system-roles.github.io/
Other
27 stars 23 forks source link

Use ansible-test units for unit testing #70

Open richm opened 2 years ago

richm commented 2 years ago

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.

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.

richm commented 2 years ago

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