Skip to content

Commit 179e71b

Browse files
committed
upstream ci: Add support for testing ipaserver deployment
This patch provides the base for testing ipaserver role using Azure's infrastructure. By using containers prepared to thave FreeIPA installed, but unconfigured, allows the use of a test matrix to test the behavior of modules in differnt IPA configurations. It also improves tests by allowing the creation of a test matrix of FreeIPA deployment. A new pipeline script is provided, which can be used as a standalone pipeline, os as part of an existing pipeline. The script 'tests/server_role/inventory.py' is used to create inventory files for the tests, which should be executed using the existing 'install-server.yml' playbook. More information on how to generate different inventories can be found in the accompanying README file 'tests/server_role/README.md'.
1 parent 79080c9 commit 179e71b

File tree

4 files changed

+235
-0
lines changed

4 files changed

+235
-0
lines changed

tests/azure/deployment.yml

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
schedules:
3+
- cron: "0 19 * * *"
4+
displayName: Nightly Builds
5+
branches:
6+
include:
7+
- master
8+
always: true
9+
10+
trigger: none
11+
12+
pool:
13+
vmImage: 'ubuntu-22.04'
14+
15+
stages:
16+
17+
# Fedora
18+
19+
- stage: FedoraLatest_Ansible_Core_2_15
20+
dependsOn: []
21+
jobs:
22+
- template: templates/deployment_tests.yml
23+
parameters:
24+
build_number: $(Build.BuildNumber)
25+
scenario: fedora-latest
26+
ansible_version: "-core >=2.15,<2.16"
27+
28+
- stage: FedoraLatest_Ansible_Core_2_16
29+
dependsOn: []
30+
jobs:
31+
- template: templates/deployment_tests.yml
32+
parameters:
33+
build_number: $(Build.BuildNumber)
34+
scenario: fedora-latest
35+
ansible_version: "-core >=2.16,<2.17"
36+
37+
#- stage: FedoraLatest_Ansible_Core_2_17
38+
# dependsOn: []
39+
# jobs:
40+
# - template: templates/deployment_tests.yml
41+
# parameters:
42+
# build_number: $(Build.BuildNumber)
43+
# scenario: fedora-latest
44+
# ansible_version: "-core >=2.17,<2.18"
45+
46+
- stage: FedoraLatest_Ansible_latest
47+
dependsOn: []
48+
jobs:
49+
- template: templates/deployment_tests.yml
50+
parameters:
51+
build_number: $(Build.BuildNumber)
52+
scenario: fedora-latest
53+
ansible_version: ""
+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---
2+
parameters:
3+
- name: scenario
4+
type: string
5+
default: fedora-latest
6+
- name: ansible_version
7+
type: string
8+
default: ""
9+
- name: python_version
10+
type: string
11+
default: 3.x
12+
- name: build_number
13+
type: string
14+
15+
jobs:
16+
- job: Test_Deployment
17+
displayName: Run deployment tests ${{ parameters.scenario }}
18+
timeoutInMinutes: 240
19+
steps:
20+
- task: UsePythonVersion@0
21+
inputs:
22+
versionSpec: '${{ parameters.python_version }}'
23+
24+
- script: |
25+
pip install "ansible${{ parameters.ansible_version }}"
26+
retryCountOnTaskFailure: 5
27+
displayName: Install Ansible
28+
29+
- script: ansible-galaxy collection install community.docker ansible.posix
30+
retryCountOnTaskFailure: 5
31+
displayName: Install Ansible collections
32+
33+
- script: pip install -r requirements-tests.txt
34+
retryCountOnTaskFailure: 5
35+
displayName: Install dependencies
36+
37+
- script: |
38+
rm -rf ~/.ansible/plugins ~/.ansible/roles
39+
ln -snf "$(realpath plugins)" ~/.ansible/plugins
40+
ln -snf "$(realpath roles)" ~/.ansible/roles
41+
ls -l ~/.ansible
42+
docker pull ${SCENARIO_IMAGE}
43+
env:
44+
SCENARIO_IMAGE: quay.io/ansible-freeipa/upstream-tests:raw-${{ parameters.scenario }}
45+
retryCountOnTaskFailure: 5
46+
displayName: Setup test environment
47+
48+
- script: tests/server_role/inventory.py | tee inventory.yml
49+
displayName: Create inventory files
50+
51+
- script: |
52+
# remove stray container
53+
docker rm --force ${{ parameters.scenario }} >&2 2>/dev/null
54+
# run test
55+
docker run -d --privileged --name ${IPA_CONTAINER} --hostname ${IPA_HOSTNAME} ${SCENARIO_IMAGE}
56+
# ansible-playbook -i inventory.yml tests/server_role/ipv6config.yml
57+
ansible-playbook -i inventory.yml playbooks/install-server.yml
58+
# Run tests to verify installation
59+
ansible-playbook -i inventory.yml tests/user/test_user.yml
60+
displayName: Run deployment tests
61+
env:
62+
SCENARIO_IMAGE: quay.io/ansible-freeipa/upstream-tests:raw-${{ parameters.scenario }}
63+
IPA_CONTAINER: ipaserver_test_container
64+
IPA_HOSTNAME: ipaserver.test.local
65+
66+
- task: PublishTestResults@2
67+
inputs:
68+
mergeTestResults: true
69+
testRunTitle: DeploymentTests-Build${{ parameters.build_number }}
70+
condition: succeededOrFailed()

tests/server_role/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This file should include how to test ipaserver.

tests/server_role/inventory.py

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#!/usr/bin/env python
2+
"""Dynamic inventory to test ipaserver role."""
3+
4+
import os
5+
import sys
6+
from collections import namedtuple
7+
8+
try:
9+
import yaml
10+
11+
inventory_to_string = yaml.dump
12+
except ImportError:
13+
import json
14+
15+
inventory_to_string = json.dumps
16+
17+
Config = namedtuple(
18+
"Config",
19+
"""
20+
engine
21+
container
22+
hostname
23+
ipa_domain
24+
ipa_realm
25+
setup_kra
26+
setup_dns
27+
dns_no_forwarders
28+
dns_auto_reverse
29+
setup_adtrust
30+
ipa_netbios_name
31+
""",
32+
)
33+
34+
35+
def to_boolean(value):
36+
return value.lower() == "true"
37+
38+
39+
def get_inventory_data(config):
40+
"""Generate inventory based on given configuration."""
41+
return {
42+
"all": {
43+
"children": {
44+
"ipaserver": {
45+
"hosts": {
46+
"ipa_server": {
47+
"ansible_connection": config.engine,
48+
"ansible_host": config.container,
49+
},
50+
},
51+
"vars": {
52+
# KRA
53+
"ipaserver_setup_kra": config.setup_kra,
54+
# DNS
55+
"ipaserver_setup_dns": config.setup_dns,
56+
"ipaserver_no_forwarders": config.dns_no_forwarders,
57+
"ipaserver_auto_reverse": config.dns_auto_reverse,
58+
# AD Trust
59+
"ipaserver_setup_adtrust": config.setup_adtrust,
60+
"ipaserver_netbios_name": config.ipa_netbios_name,
61+
# adjtimex fails on container, so do not set ntp
62+
"ipaclient_no_ntp": True,
63+
# server configuration
64+
"ipaserver_hostname": config.hostname,
65+
},
66+
},
67+
},
68+
"vars": {
69+
# server/realm
70+
"ipaserver_domain": config.ipa_domain,
71+
"ipaserver_realm": config.ipa_realm,
72+
# passwords
73+
"ipaadmin_password": "SomeADMINpassword",
74+
"ipadm_password": "SomeDMpassword",
75+
},
76+
},
77+
}
78+
79+
80+
def gen_default_inventory():
81+
default_hostname = "ipaserver.test.local"
82+
ipa_hostname = os.environ.get("IPA_HOSTNAME", default_hostname).split(".")
83+
84+
setup_dns = to_boolean(os.environ.get("SETUP_DNS", "False"))
85+
86+
config = Config(
87+
engine=(
88+
"containers.podman.podman"
89+
if "--podman" in sys.argv
90+
else "community.docker.docker"
91+
),
92+
container=os.environ.get("IPA_CONTAINER", "ipaserver_test_container"),
93+
hostname=".".join(ipa_hostname),
94+
ipa_domain=os.environ.get("IPA_DOMAIN", ".".join(ipa_hostname[1:])),
95+
ipa_realm=os.environ.get(
96+
"IPA_REALM", ".".join(ipa_hostname[1:]).upper()
97+
),
98+
setup_kra=to_boolean(os.environ.get("SETUP_KRA", "False")),
99+
setup_dns=setup_dns,
100+
dns_no_forwarders=os.environ.get("DNS_NO_FORWARDERS", setup_dns),
101+
dns_auto_reverse=os.environ.get("DNS_AUTO_REVERSE", setup_dns),
102+
setup_adtrust=to_boolean(os.environ.get("SETUP_ADTRUST", "False")),
103+
ipa_netbios_name=os.environ.get("IPA_NETBIOS_NAME", "IPA"),
104+
)
105+
print(inventory_to_string(get_inventory_data(config)))
106+
107+
108+
if "--matrix" in sys.argv: # pylint: disable=no-else-raise
109+
raise NotImplementedError("Test matrix not implemented yet.")
110+
else:
111+
gen_default_inventory()

0 commit comments

Comments
 (0)