mirror of
https://github.com/freeipa/ansible-freeipa.git
synced 2026-07-26 17:34:41 +00:00
test_users_absent.yml was using users_absent.json. It has been adapted to use users.json instead with an additional json_query to get only the names from users_present.json. create_users_json.yml has been added to create users.json if it is missing containing 500 users. It is included by test_users_present.yml and test_users_absent.yml. users_present.sh has been renamed to users.sh and modified to create by default users.json with 1000 users and additional with password and passwordexpiration in two years. jmespath has been added to pip install list in tests/azure/templates/playbook_tests.yml to emable the use of json_query. The requirement for jmespath has been added to tests/README.md.
104 lines
2.7 KiB
Markdown
104 lines
2.7 KiB
Markdown
# Running the tests
|
|
|
|
## Before starting
|
|
|
|
In order to run ansible-freeipa tests you will need to have `ansible`, `pytest` and `jmespath` installed on your machine. We'll call this local machine `controller`. `jmespath` is needed for the `json_query` filter.
|
|
|
|
You will also need to have a remote host with freeipa server installed and configured. We'll call this remote host `ipaserver`.
|
|
|
|
Some other requirements:
|
|
|
|
* The `controller` must be able to connect to `ipaserver` through ssh using keys.
|
|
* `ipaserver` must be configured with DNS support. See [ipaserver role](../roles/ipaserver/README.md).
|
|
* IPA admin password must be `SomeADMINpassword`.
|
|
* Directory Server admin password must be `SomeDMpassword`.
|
|
|
|
|
|
## Running the tests
|
|
|
|
To run the tests run:
|
|
|
|
```
|
|
IPA_SERVER_HOST=<ipaserver_host_or_ip> pytest
|
|
```
|
|
|
|
If you need to run using a different user you can use `ANSIBLE_REMOTE_USER`
|
|
environment variable. For example:
|
|
|
|
```
|
|
ANSIBLE_REMOTE_USER=root IPA_SERVER_HOST=<ipaserver_host_or_ip> pytest
|
|
```
|
|
|
|
To run a single test use the full path with the following format:
|
|
|
|
```
|
|
IPA_SERVER_HOST=<ipaserver_host_or_ip> pytest tests/test_playbook_runs.py::sudorule::test_sudorule
|
|
```
|
|
|
|
To select which tests to run based on search use the option `-k`. For example:
|
|
|
|
```
|
|
IPA_SERVER_HOST=<ipaserver_host_or_ip> pytest -k dnszone
|
|
```
|
|
|
|
To see the ansible output use the option `--capture=sys`. For example:
|
|
|
|
```
|
|
IPA_SERVER_HOST=<ipaserver_host_or_ip> pytest --capture=sys
|
|
```
|
|
|
|
To see why tests were skipped use `-rs`. For example:
|
|
|
|
```
|
|
IPA_SERVER_HOST=<ipaserver_host_or_ip> pytest -rs
|
|
```
|
|
|
|
For a complete list of options check `pytest --help`.
|
|
|
|
|
|
## Running tests in a docker container
|
|
|
|
It's also possible to run the tests in a container.
|
|
|
|
### Creating a container to run the tests
|
|
|
|
Before setting up a container you will need to install molecule framework:
|
|
|
|
```
|
|
pip install molecule[docker]>=3
|
|
```
|
|
|
|
Now you can start a test container using the following command:
|
|
```
|
|
molecule create -s centos-8
|
|
```
|
|
|
|
Note: Currently the containers available for running the tests are:
|
|
* centos-7
|
|
* centos-8
|
|
|
|
### Running the tests inside the container
|
|
|
|
To run the tests you will use pytest (works the same as for VMs).
|
|
|
|
```
|
|
RUN_TESTS_IN_DOCKER=1 IPA_SERVER_HOST=centos-8 pytest
|
|
```
|
|
|
|
### Cleaning up after tests
|
|
|
|
After running the tests you should probably destroy the test container using:
|
|
|
|
```
|
|
molecule destroy -s centos-8
|
|
```
|
|
|
|
See [Running the tests](#running-the-tests) section for more information on available options.
|
|
|
|
## Upcoming/desired improvements:
|
|
|
|
* A script to pre-config the complete test environment using virsh.
|
|
* A test matrix to run tests against different distros in parallel (probably using tox).
|
|
* Allow to connect to `ipaserver` using ssh and password.
|
|
|