mirror of
https://github.com/freeipa/ansible-freeipa.git
synced 2026-07-31 11:54:47 +00:00
Merge pull request #283 from seocam/fix-test-entry-point
Fix all tests entry point
This commit is contained in:
@@ -2,11 +2,9 @@
|
|||||||
|
|
||||||
## Before starting
|
## Before starting
|
||||||
|
|
||||||
In order to run ansible-freeipa tests you will need to have `ansible` and `pytest`
|
In order to run ansible-freeipa tests you will need to have `ansible` and `pytest` installed on your machine. We'll call this local machine `controller`.
|
||||||
installed on your machine. We'll call this local machine `controller`.
|
|
||||||
|
|
||||||
You will also need to have a remote host with freeipa server installed and configured.
|
You will also need to have a remote host with freeipa server installed and configured. We'll call this remote host `ipaserver`.
|
||||||
We'll call this remote host `ipaserver`.
|
|
||||||
|
|
||||||
Some other requirements:
|
Some other requirements:
|
||||||
|
|
||||||
@@ -19,27 +17,32 @@ Some other requirements:
|
|||||||
## Running the tests
|
## Running the tests
|
||||||
|
|
||||||
To run the tests run:
|
To run the tests run:
|
||||||
|
|
||||||
```
|
```
|
||||||
IPA_SERVER_HOST=<ipaserver_host_or_ip> pytest
|
IPA_SERVER_HOST=<ipaserver_host_or_ip> pytest
|
||||||
```
|
```
|
||||||
|
|
||||||
If you need to run using a different user you can use `ANSIBLE_REMOTE_USER`
|
If you need to run using a different user you can use `ANSIBLE_REMOTE_USER`
|
||||||
environment variable. For example:
|
environment variable. For example:
|
||||||
|
|
||||||
```
|
```
|
||||||
ANSIBLE_REMOTE_USER=root IPA_SERVER_HOST=<ipaserver_host_or_ip> pytest
|
ANSIBLE_REMOTE_USER=root IPA_SERVER_HOST=<ipaserver_host_or_ip> pytest
|
||||||
```
|
```
|
||||||
|
|
||||||
To select which tests to run use the option `-k`. For example:
|
To select which tests to run use the option `-k`. For example:
|
||||||
|
|
||||||
```
|
```
|
||||||
IPA_SERVER_HOST=<ipaserver_host_or_ip> pytest -k dnszone
|
IPA_SERVER_HOST=<ipaserver_host_or_ip> pytest -k dnszone
|
||||||
```
|
```
|
||||||
|
|
||||||
To see the ansible output use the option `--capture=sys`. For example:
|
To see the ansible output use the option `--capture=sys`. For example:
|
||||||
|
|
||||||
```
|
```
|
||||||
IPA_SERVER_HOST=<ipaserver_host_or_ip> pytest --capture=sys
|
IPA_SERVER_HOST=<ipaserver_host_or_ip> pytest --capture=sys
|
||||||
```
|
```
|
||||||
|
|
||||||
To see why tests were skipped use `-rs`. For example:
|
To see why tests were skipped use `-rs`. For example:
|
||||||
|
|
||||||
```
|
```
|
||||||
IPA_SERVER_HOST=<ipaserver_host_or_ip> pytest -rs
|
IPA_SERVER_HOST=<ipaserver_host_or_ip> pytest -rs
|
||||||
```
|
```
|
||||||
@@ -52,3 +55,4 @@ For a complete list of options check `pytest --help`.
|
|||||||
* A script to pre-config the complete test environment using virsh.
|
* 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).
|
* A test matrix to run tests against different distros in parallel (probably using tox).
|
||||||
* Allow to connect to `ipaserver` using ssh and password.
|
* Allow to connect to `ipaserver` using ssh and password.
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import functools
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
from subprocess import Popen
|
from subprocess import Popen
|
||||||
@@ -59,11 +60,16 @@ def get_test_groups():
|
|||||||
return groups
|
return groups
|
||||||
|
|
||||||
|
|
||||||
def rename(newname):
|
def prepare_test(test_name, test_path):
|
||||||
def decorator(f):
|
def decorator(func):
|
||||||
f.__name__ = newname
|
@functools.wraps(func)
|
||||||
return f
|
def wrapper(*args, **kwargs):
|
||||||
|
kwargs["test_path"] = test_path
|
||||||
|
return func(*args, **kwargs)
|
||||||
|
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
decorator.__name__ = test_name
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
|
|
||||||
@@ -73,14 +79,15 @@ for group_name, group_tests in get_test_groups().items():
|
|||||||
_tests = {}
|
_tests = {}
|
||||||
for test_config in group_tests:
|
for test_config in group_tests:
|
||||||
test_name = test_config["name"].replace("-", "_")
|
test_name = test_config["name"].replace("-", "_")
|
||||||
|
test_path = test_config["path"]
|
||||||
|
|
||||||
@pytest.mark.skipif(
|
@pytest.mark.skipif(
|
||||||
os.getenv("IPA_SERVER_HOST") is None,
|
os.getenv("IPA_SERVER_HOST") is None,
|
||||||
reason="Environment variable IPA_SERVER_HOST must be set",
|
reason="Environment variable IPA_SERVER_HOST must be set",
|
||||||
)
|
)
|
||||||
@rename(test_name)
|
@prepare_test(test_name, test_path)
|
||||||
def method(self):
|
def method(self, test_path):
|
||||||
result = run_playbook(test_config["path"])
|
result = run_playbook(test_path)
|
||||||
assert result.returncode == 0
|
assert result.returncode == 0
|
||||||
|
|
||||||
_tests[test_name] = method
|
_tests[test_name] = method
|
||||||
|
|||||||
Reference in New Issue
Block a user