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

Add integration tests for lookup plugin 'version' #421

Merged
merged 2 commits into from
Aug 24, 2023
Merged
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
68 changes: 68 additions & 0 deletions .github/workflows/ans-int-test-lkp-version.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# README:
# - When changing the module name, it needs to be changed in 'env:MODULE_NAME' and in 'on:pull_requests:path'!
#
# Resources:
# - Template for this file: https://github.com/ansible-collections/collection_template/blob/main/.github/workflows/ansible-test.yml
# - About Ansible integration tests: https://docs.ansible.com/ansible/latest/dev_guide/testing_integration.html

env:
NAMESPACE: checkmk
COLLECTION_NAME: general
MODULE_NAME: lookup_version

name: Ansible Integration Tests for Version Lookup Module
on:
workflow_dispatch:
pull_request:
branches:
- main
- devel
paths:
- 'plugins/lookup/version.py'

jobs:

integration:
runs-on: ubuntu-latest
name: Ⓐ${{ matrix.ansible }}+py${{ matrix.python }}
strategy:
fail-fast: false
matrix:
ansible:
- stable-2.13
- stable-2.14
- stable-2.15
- devel
python:
- '3.8'
- '3.9'
- '3.10'
- '3.11'
exclude:
# Exclude unsupported sets.
- ansible: stable-2.13
python: '3.11'

steps:
- name: Check out code
uses: actions/checkout@v3
with:
path: ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10' # Ansible 2.13 does not support Python 3.11.

- name: Install ansible-base (${{ matrix.ansible }})
run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check

- name: Provide secrets file
run: echo "${{ secrets.CHECKMK_DOWNLOAD_PW }}" > ./tests/integration/files/.dl-secret
working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}
env:
CHECKMK_DOWNLOAD_PW: ${{ secrets.CHECKMK_DOWNLOAD_PW }}

- name: Run integration test
run: ansible-test integration ${{env.MODULE_NAME}} -v --color --retry-on-error --continue-on-error --diff --python ${{ matrix.python }} --docker
working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}
2 changes: 1 addition & 1 deletion plugins/lookup/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
description: automation secret for the REST API access
required: True
validate_certs:
description: Wether or not to validate TLS cerificates
description: Wether or not to validate TLS certificates
type: boolean
required: False
default: True
Expand Down
18 changes: 18 additions & 0 deletions tests/integration/targets/lookup_version/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
- name: "Run preparations."
ansible.builtin.include_tasks: prep.yml

- name: "Wait for site to be ready."
ansible.builtin.pause:
seconds: 5
when: |
((download_pass is defined and download_pass | length) or item.item.edition == 'cre')
and (item.stdout_lines is defined and 'OVERALL 1' in item.stdout_lines)
loop: "{{ site_status.results }}"

- name: "Testing."
ansible.builtin.include_tasks: test.yml
loop: "{{ test_sites }}"
loop_control:
loop_var: outer_item
when: (download_pass is defined and download_pass | length) or outer_item.edition == "cre"
31 changes: 31 additions & 0 deletions tests/integration/targets/lookup_version/tasks/prep.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
- name: "Download Checkmk Versions."
ansible.builtin.get_url:
url: "{{ download_url }}"
dest: /tmp/checkmk-server-{{ item.site }}.deb
mode: "0640"
url_username: "{{ download_user | default(omit) }}"
url_password: "{{ download_pass | default(omit) }}"
loop: "{{ test_sites }}"
when: (download_pass is defined and download_pass | length) or item.edition == "cre"

- name: "Install Checkmk Versions."
ansible.builtin.apt:
deb: /tmp/checkmk-server-{{ item.site }}.deb
state: present
loop: "{{ test_sites }}"
when: (download_pass is defined and download_pass | length) or item.edition == "cre"

- name: "Create Sites."
ansible.builtin.command: "omd -V {{ item.version }}.{{ item.edition }} create --no-tmpfs --admin-password {{ automation_secret }} {{ item.site }}"
args:
creates: "/omd/sites/{{ item.site }}"
loop: "{{ test_sites }}"
when: (download_pass is defined and download_pass | length) or item.edition == "cre"

- name: "Start Sites."
ansible.builtin.shell: "omd status -b {{ item.site }} || omd start {{ item.site }}"
register: site_status
changed_when: site_status.rc == "0"
loop: "{{ test_sites }}"
when: (download_pass is defined and download_pass | length) or item.edition == "cre"
17 changes: 17 additions & 0 deletions tests/integration/targets/lookup_version/tasks/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
- name: "{{ outer_item.version }} - Get Checkmk version."
ansible.builtin.debug:
msg: "Version is {{ version }}"
vars:
version: "{{ lookup('checkmk.general.version',
server_url + '/' + outer_item.site,
validate_certs=False,
automation_user=automation_user,
automation_secret=automation_secret)
}}"
delegate_to: localhost
register: looked_up_version

- name: "{{ outer_item.version }} - Verify Checkmk version."
ansible.builtin.assert:
that: "outer_item.version in looked_up_version.msg"
33 changes: 33 additions & 0 deletions tests/integration/targets/lookup_version/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
# In these integration tests, we do not normalize the edition naming, but stick
# to the naming of the setup files. For example 'raw' and 'enterprise' rather
# than 'CRE' and 'CEE'.
test_sites:
- version: "2.2.0p7"
edition: "cre"
site: "stable_raw"
- version: "2.2.0p7"
edition: "cee"
site: "stable_ent"
- version: "2.1.0p32"
edition: "cre"
site: "old_raw"
- version: "2.0.0p38"
edition: "cre"
site: "ancient_raw"

server_url: "http://127.0.0.1/"
automation_user: "cmkadmin"
automation_secret: "d7589df1"

download_url: "https://download.checkmk.com/checkmk/{{ item.version }}/check-mk-{{ checkmk_server_edition_mapping[item.edition] }}-{{ item.version }}_0.{{ ansible_distribution_release }}_amd64.deb" # noqa yaml[line-length]
download_user: "d-gh-ansible-dl"
download_pass: "{{ lookup('ansible.builtin.file', '/root/ansible_collections/checkmk/general/tests/integration/files/.dl-secret', errors='ignore') | default(omit) }}" # noqa yaml[line-length]

# Due to inconsistent naming of editions, we normalize them here for convenience
checkmk_server_edition_mapping:
cre: raw
cfe: free
cee: enterprise
cce: cloud
cme: managed