Skip to content
Snippets Groups Projects
Unverified Commit 3633ba5a authored by Thomas Woerner's avatar Thomas Woerner Committed by GitHub
Browse files

Merge pull request #307 from seocam/molecule-tests

Running upstream tests on Azure pipelines
parents 4e89da85 627c6441
Branches
Tags
No related merge requests found
Showing
with 330 additions and 30 deletions
trigger:
- master
pool:
vmImage: 'ubuntu-18.04'
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '3.6'
- script: python -m pip install --upgrade pip setuptools wheel
displayName: Install tools
- script: pip install pydocstyle flake8
displayName: Install dependencies
- script: flake8 .
displayName: Run flake8 checks
- script: pydocstyle .
displayName: Verify docstings
---
dependency:
name: galaxy
driver:
name: docker
platforms:
- name: centos-7-build
image: centos/systemd
pre_build_image: true
hostname: ipaserver.test.local
dns_servers:
- 8.8.8.8
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
command: /usr/sbin/init
privileged: true
provisioner:
name: ansible
playbooks:
prepare: ../resources/playbooks/prepare-build.yml
---
dependency:
name: galaxy
driver:
name: docker
platforms:
- name: centos-7
image: quay.io/ansible-freeipa/upstream-tests:centos-7
pre_build_image: true
hostname: ipaserver.test.local
dns_servers:
- 127.0.0.1
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
command: /usr/sbin/init
privileged: true
provisioner:
name: ansible
playbooks:
prepare: ../resources/playbooks/prepare.yml
---
dependency:
name: galaxy
driver:
name: docker
platforms:
- name: centos-8-build
image: centos:8
pre_build_image: true
hostname: ipaserver.test.local
dns_servers:
- 8.8.8.8
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
command: /usr/sbin/init
privileged: true
provisioner:
name: ansible
playbooks:
prepare: ../resources/playbooks/prepare-build.yml
---
dependency:
name: galaxy
driver:
name: docker
platforms:
- name: centos-8
image: quay.io/ansible-freeipa/upstream-tests:centos-8
pre_build_image: true
hostname: ipaserver.test.local
dns_servers:
- 127.0.0.1
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
command: /usr/sbin/init
privileged: true
provisioner:
name: ansible
playbooks:
prepare: ../resources/playbooks/prepare.yml
/home/scampos/src/ansible-freeipa/molecule/centos-8
\ No newline at end of file
/home/scampos/src/ansible-freeipa/plugins/modules/
\ No newline at end of file
/home/scampos/src/ansible-freeipa/plugins/module_utils/
\ No newline at end of file
---
- name: Converge
hosts: all
tasks:
- name: Ensure IPv6 is ENABLED
sysctl:
name: "{{ item.name }}"
value: "{{ item.value }}"
sysctl_set: yes
state: present
reload: yes
with_items :
- name: net.ipv6.conf.all.disable_ipv6
value: 0
- name: net.ipv6.conf.lo.disable_ipv6
value: 0
- name: net.ipv6.conf.eth0.disable_ipv6
value: 1
- name: stat protected_regular
stat:
path: /proc/sys/fs/protected_regular
register: result
- name: Ensure fs.protected_regular is disabled
sysctl:
name: fs.protected_regular
value: 0
sysctl_set: yes
state: present
reload: yes
when: result.stat.exists
- name: Ensure sudo package is installed
package:
name: sudo
- name: Ensure nss package is updated
package:
name: nss
state: latest
- include_role:
name: ipaserver
vars:
ipaserver_setup_dns: yes
ipaserver_setup_kra: yes
ipaserver_auto_forwarders: yes
ipaserver_no_dnssec_validation: yes
ipaserver_auto_reverse: yes
ipaadmin_password: SomeADMINpassword
ipadm_password: SomeDMpassword
ipaserver_domain: test.local
ipaserver_realm: TEST.LOCAL
---
- name: Converge
hosts: all
tasks:
- name: Ensure lock dirs for DS exists
file:
state: directory
owner: dirsrv
group: dirsrv
path: "{{ item }} "
loop:
- /var/lock/dirsrv/
- /var/lock/dirsrv/slapd-TEST-LOCAL/
- name: Ensure IPA server is up an running
service:
name: ipa
state: started
/home/scampos/src/ansible-freeipa/roles
\ No newline at end of file
[pytest]
python_files = test_*.py
junit_family = xunit1
......@@ -29,7 +29,13 @@ environment variable. For example:
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 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
......@@ -50,6 +56,45 @@ 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.
......
# Using Ansible 2.10.0a1 under Azure there might happen that the output of a
# task is changed if a module uses no_log = True for an attribute.
#
# For example, if the output of the module should contain "changed: True", and
# an attribute with no_log set contains the value `hang` it might happen that
# the output is modified to "c******ed: True", and if this output is further
# processed (registering the result and comparing the value of `changed`),
# the test might fail, but not because of module code, but because of unexpected
# output processing.
#
# This behavior was, currently, only reproduced with Ansible 2.10.0a1 running
# under Azure.
---
trigger:
- master
pool:
vmImage: 'ubuntu-18.04'
jobs:
- job: RunLinters
displayName: Run Linters
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '3.6'
- script: python -m pip install --upgrade pip setuptools wheel
displayName: Install tools
- script: pip install pydocstyle flake8
displayName: Install dependencies
- script: flake8 .
displayName: Run flake8 checks
- script: pydocstyle .
displayName: Verify docstings
- template: templates/playbook_tests.yml
parameters:
group_number: 1
number_of_groups: 3
build_number: $(Build.BuildNumber)
- template: templates/playbook_tests.yml
parameters:
group_number: 2
number_of_groups: 3
build_number: $(Build.BuildNumber)
- template: templates/playbook_tests.yml
parameters:
group_number: 3
number_of_groups: 3
build_number: $(Build.BuildNumber)
parameters:
- name: group_number
type: number
default: 1
- name: number_of_groups
type: number
default: 1
- name: scenario
type: string
default: centos-8
- name: ansible_version
type: string
default: ">=2.9,<2.10"
- name: python_version
type: string
default: 3.6
- name: build_number
jobs:
- job: RunTests${{ parameters.group_number }}
displayName: Run tests ${{ parameters.group_number }}/${{ parameters.number_of_groups }}
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '${{ parameters.python_version }}'
- script: |
pip install \
"molecule[docker]>=3" \
"ansible${{ parameters.ansible_version }}" \
pytest \
pytest-split-tests
displayName: Install dependencies
- script: |
mkdir -p ~/.ansible/roles ~/.ansible/library ~/.ansible/module_utils
cp -a roles/* ~/.ansible/roles
cp -a plugins/modules/* ~/.ansible/library
cp -a plugins/module_utils/* ~/.ansible/module_utils
molecule create -s ${{ parameters.scenario }}
displayName: Setup test container
- script: |
pytest \
--verbose \
--color=yes \
--test-group-count=${{ parameters.number_of_groups }} \
--test-group=${{ parameters.group_number }} \
--test-group-random-seed=97943259814 \
--junit-xml=TEST-results-group-${{ parameters.group_number }}.xml
displayName: Run playbook tests
env:
IPA_SERVER_HOST: ${{ parameters.scenario }}
RUN_TESTS_IN_DOCKER: true
- task: PublishTestResults@2
inputs:
mergeTestResults: true
testRunTitle: PlaybookTests-Build${{ parameters.build_number }}
condition: succeededOrFailed()
......@@ -129,7 +129,7 @@
- "{{ zone_prefix_reverse_24 }}"
- "{{ zone_prefix_reverse_16 }}"
- "{{ zone_prefix_reverse_8 }}"
- "{{ zone_ipv6_reverse }}"
- "{{ zone_ipv6_reverse_workaround }}"
- "{{ testzone }}"
- ip6.arpa.
- d.f.ip6.arpa.
- "{{ safezone }}"
......@@ -18,8 +18,9 @@
- "{{ zone_prefix_reverse_24 }}"
- "{{ zone_prefix_reverse_16 }}"
- "{{ zone_prefix_reverse_8 }}"
- "{{ zone_ipv6_reverse_workaround }}"
- "{{ testzone }}"
- ip6.arpa.
- "{{ zone_ipv6_reverse }}"
- name: Ensure DNSSEC zone '"{{ safezone }}"' is present.
ipadnszone:
......
......@@ -2,8 +2,11 @@
# Set common vars and facts for test.
- name: Set IPv4 address prefix.
set_fact:
ipv4_prefix: '192.168.122'
ipv4_reverse_sufix: '122.168.192'
ipv4_prefix: "{{ ansible_default_ipv4.address.split('.')[:-1] |
join('.') }}"
ipv4_reverse_sufix: "{{ ansible_default_ipv4.address.split('.')[:-1] |
reverse |
join('.') }}"
- name: Set zone prefixes.
set_fact:
......
......@@ -12,7 +12,6 @@
- name: Create CA, get /root/ipa.csr signed by your CA, ..
hosts: localhost
gather_facts: false
tasks:
- name: Run external-ca.sh
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment