Blame tests/README.md

Packit Service 0a38ef
# Running the tests
Packit Service 0a38ef
Packit Service 0a38ef
## Before starting
Packit Service 0a38ef
Packit Service a166ed
In order to run ansible-freeipa tests you will need to install the dependencies listed in the file `requirements-tests.txt` in your local machine. We'll call this local machine `controller`.
Packit Service 0a38ef
Packit Service 0a38ef
You will also need to have a remote host with freeipa server installed and configured. We'll call this remote host `ipaserver`.
Packit Service 0a38ef
Packit Service 0a38ef
Some other requirements:
Packit Service 0a38ef
Packit Service 0a38ef
 * The `controller` must be able to connect to `ipaserver` through ssh using keys.
Packit Service 0a38ef
 * IPA admin password must be `SomeADMINpassword`.
Packit Service 0a38ef
 * Directory Server admin password must be `SomeDMpassword`.
Packit Service 0a38ef
Packit Service a166ed
To provide broader test coverage, `ipaserver` should be configured with DNS and KRA support, and playbook tests are written based on this configuration. Without such support, some tests are expected to fail. Use a different configuration to evaluate those scenarios. See also [ipaserver role](../roles/ipaserver/README.md).
Packit Service 0a38ef
Packit Service 0a38ef
## Running the tests
Packit Service 0a38ef
Packit Service 0a38ef
To run the tests run:
Packit Service 0a38ef
Packit Service 0a38ef
```
Packit Service 0a38ef
IPA_SERVER_HOST=<ipaserver_host_or_ip> pytest
Packit Service 0a38ef
```
Packit Service 0a38ef
Packit Service 0a38ef
If you need to run using a different user you can use `ANSIBLE_REMOTE_USER`
Packit Service 0a38ef
environment variable. For example:
Packit Service 0a38ef
Packit Service 0a38ef
```
Packit Service 0a38ef
ANSIBLE_REMOTE_USER=root IPA_SERVER_HOST=<ipaserver_host_or_ip> pytest
Packit Service 0a38ef
```
Packit Service 0a38ef
Packit Service a166ed
If you want to use ssh with password, you must set `IPA_SSH_PASSWORD`
Packit Service a166ed
environment variable. For example:
Packit Service a166ed
Packit Service a166ed
```
Packit Service a166ed
IPA_SSH_PASSWORD=<ipaserver_ssh_password> IPA_SERVER_HOST=<ipaserver_host_or_ip> pytest
Packit Service a166ed
```
Packit Service a166ed
Packit Service a166ed
Packit Service a166ed
To run a single test use the full path with the following format:
Packit Service a166ed
Packit Service a166ed
```
Packit Service a166ed
IPA_SERVER_HOST=<ipaserver_host_or_ip> pytest tests/test_playbook_runs.py::sudorule::test_sudorule
Packit Service a166ed
```
Packit Service a166ed
Packit Service a166ed
To select which tests to run based on search use the option `-k`. For example:
Packit Service 0a38ef
Packit Service 0a38ef
```
Packit Service 0a38ef
IPA_SERVER_HOST=<ipaserver_host_or_ip> pytest -k dnszone
Packit Service 0a38ef
```
Packit Service 0a38ef
Packit Service 0a38ef
To see the ansible output use the option `--capture=sys`. For example:
Packit Service 0a38ef
Packit Service 0a38ef
```
Packit Service 0a38ef
IPA_SERVER_HOST=<ipaserver_host_or_ip> pytest --capture=sys
Packit Service 0a38ef
```
Packit Service 0a38ef
Packit Service 0a38ef
To see why tests were skipped use `-rs`. For example:
Packit Service 0a38ef
Packit Service 0a38ef
```
Packit Service 0a38ef
IPA_SERVER_HOST=<ipaserver_host_or_ip> pytest -rs
Packit Service 0a38ef
```
Packit Service 0a38ef
Packit Service 0a38ef
For a complete list of options check `pytest --help`.
Packit Service 0a38ef
Packit Service a166ed
### Types of tests
Packit Service a166ed
Packit Service a166ed
#### Playbook tests
Packit Service a166ed
Packit Service a166ed
The playbook tests will run our roles / modules using Ansible with various parameters. Most of these tests will be executed more than once, to verify idempotence. In  general those tests don't verify the state of the machine after the playbook is executed.
Packit Service a166ed
Packit Service a166ed
To select only these tests use the option `-m "playbook"`
Packit Service a166ed
Packit Service a166ed
#### Python tests (pytests)
Packit Service a166ed
Packit Service a166ed
The pytests are tests that will execute small playbooks and then will verify the test results immediately after, using python code for that.
Packit Service a166ed
Packit Service a166ed
To select only these tests on a test execution use the option `-m "not playbook"`.
Packit Service a166ed
Packit Service a166ed
Packit Service a166ed
## Running tests in a docker container
Packit Service a166ed
Packit Service a166ed
It's also possible to run the tests in a container.
Packit Service a166ed
Packit Service a166ed
### Creating a container to run the tests
Packit Service a166ed
Packit Service a166ed
Before setting up a container you will need to install molecule framework:
Packit Service a166ed
Packit Service a166ed
```
Packit Service a166ed
pip install molecule[docker]>=3
Packit Service a166ed
```
Packit Service a166ed
Packit Service a166ed
Now you can start a test container using the following command:
Packit Service a166ed
```
Packit Service a166ed
molecule create -s centos-8
Packit Service a166ed
```
Packit Service a166ed
Packit Service a166ed
Note: Currently the containers available for running the tests are:
Packit Service a166ed
 * centos-7
Packit Service a166ed
 * centos-8
Packit Service a166ed
Packit Service a166ed
### Running the tests inside the container
Packit Service a166ed
Packit Service a166ed
To run the tests you will use pytest (works the same as for VMs).
Packit Service a166ed
Packit Service a166ed
```
Packit Service a166ed
RUN_TESTS_IN_DOCKER=1 IPA_SERVER_HOST=centos-8 pytest
Packit Service a166ed
```
Packit Service a166ed
Packit Service a166ed
### Cleaning up after tests
Packit Service a166ed
Packit Service a166ed
After running the tests you should probably destroy the test container using:
Packit Service a166ed
Packit Service a166ed
```
Packit Service a166ed
molecule destroy -s centos-8
Packit Service a166ed
```
Packit Service a166ed
Packit Service a166ed
See [Running the tests](#running-the-tests) section for more information on available options.
Packit Service 0a38ef
Packit Service 0a38ef
## Upcoming/desired improvements:
Packit Service 0a38ef
Packit Service 0a38ef
* A script to pre-config the complete test environment using virsh.
Packit Service 0a38ef
* A test matrix to run tests against different distros in parallel (probably using tox).