Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pytest: Add support for defining domain and realm. #998

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ To run the tests run:
IPA_SERVER_HOST=<ipaserver_host_or_ip> pytest
```

To use a specific domain or realm set `IPA_SERVER_DOMAIN` (defaults to 'test.local') or `IPA_SERVER_REALM` (defaults to uppercase `IPA_SERVER_DOMAIN`):

```
IPA_SERVER_DOMAIN=<ipaserver_domain> IPA_SERVER_REALM=<ipaserver_realm> pytest
```

If you need to run using a different user you can use `ANSIBLE_REMOTE_USER`
environment variable. For example:

Expand All @@ -36,7 +42,6 @@ environment variable. For example:
IPA_SSH_PASSWORD=<ipaserver_ssh_password> IPA_SERVER_HOST=<ipaserver_host_or_ip> pytest
```


To run a single test use the full path with the following format:

```
Expand All @@ -61,7 +66,7 @@ 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`.
For a complete list of `pytest` options check `pytest --help`.

### Disabling and enabling playbook tests

Expand Down
34 changes: 31 additions & 3 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import os
import socket
import pytest
import re
import subprocess
Expand All @@ -32,6 +33,18 @@
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))


def is_ip_addr(ipaddr):
"""Test if given IPA_SERVER_HOST is an IP address."""
try:
socket.inet_pton(socket.AF_INET, ipaddr)
except socket.error:
try:
socket.inet_pton(socket.AF_INET6, ipaddr)
except socket.error:
return False
return True


def get_docker_env():
docker_env = os.getenv("RUN_TESTS_IN_DOCKER", None)
if docker_env in ["1", "True", "true", "yes", True]:
Expand Down Expand Up @@ -88,21 +101,36 @@ def get_enabled_test(group_name, test_name):
def get_inventory_content():
"""Create the content of an inventory file for a test run."""
ipa_server_host = get_server_host()

container_engine = get_docker_env()

if (
ipa_server_host
and container_engine is None
and not is_ip_addr(ipa_server_host)
):
default_domain = ipa_server_host.split(".", 1)[-1]
else:
default_domain = "test.local"

if container_engine is not None:
ipa_server_host += f" ansible_connection={container_engine}"

sshpass = get_ssh_password()
if sshpass:
ipa_server_host += " ansible_ssh_pass=%s" % sshpass

ipaserver_domain = os.environ.get("IPA_SERVER_DOMAIN", default_domain)
ipaserver_realm = os.environ.get(
"IPA_SERVER_REALM",
ipaserver_domain.upper()
)

lines = [
"[ipaserver]",
ipa_server_host,
"[ipaserver:vars]",
"ipaserver_domain=test.local",
"ipaserver_realm=TEST.LOCAL",
"ipaserver_domain=%s" % ipaserver_domain,
"ipaserver_realm=%s" % ipaserver_realm,
]
return "\n".join(lines).encode("utf8")

Expand Down
Loading