Skip to content

Commit a94fc22

Browse files
committed
Add first iteration of integration tests for the bi_rule module.
1 parent c02f9ae commit a94fc22

File tree

5 files changed

+237
-2
lines changed

5 files changed

+237
-2
lines changed
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# README:
2+
# - When changing the module name, it needs to be changed in 'env:MODULE_NAME' and in 'on:pull_requests:path'!
3+
#
4+
# Resources:
5+
# - Template for this file: https://github.com/ansible-collections/collection_template/blob/main/.github/workflows/ansible-test.yml
6+
# - About Ansible integration tests: https://docs.ansible.com/ansible/latest/dev_guide/testing_integration.html
7+
8+
env:
9+
NAMESPACE: checkmk
10+
COLLECTION_NAME: general
11+
MODULE_NAME: dcd
12+
13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.ref }}
15+
cancel-in-progress: true
16+
17+
name: Ansible Integration Tests for the DCD Module
18+
on:
19+
workflow_dispatch:
20+
schedule:
21+
- cron: '0 0 * * 0'
22+
pull_request:
23+
branches:
24+
- main
25+
- devel
26+
paths:
27+
- 'plugins/modules/dcd.py'
28+
push:
29+
paths:
30+
- 'plugins/modules/dcd.py'
31+
- '.github/workflows/ans-int-test-dcd.yaml'
32+
33+
jobs:
34+
35+
integration:
36+
runs-on: ubuntu-22.04
37+
name: Ⓐ${{ matrix.ansible }}+py${{ matrix.python }}
38+
strategy:
39+
fail-fast: false
40+
matrix:
41+
ansible:
42+
- stable-2.15
43+
- stable-2.16
44+
- stable-2.17
45+
- devel
46+
python:
47+
- '3.9'
48+
- '3.10'
49+
- '3.11'
50+
- '3.12'
51+
exclude:
52+
# Exclude unsupported sets.
53+
- ansible: stable-2.15
54+
python: '3.12'
55+
- ansible: stable-2.16
56+
python: '3.9'
57+
- ansible: stable-2.17
58+
python: '3.9'
59+
- ansible: devel
60+
python: '3.9'
61+
- ansible: devel
62+
python: '3.10'
63+
64+
services:
65+
ancient_cre:
66+
image: checkmk/check-mk-raw:2.2.0p42
67+
ports:
68+
- 5022:5000
69+
env:
70+
CMK_SITE_ID: "ancient_cre"
71+
CMK_PASSWORD: "Sup3rSec4et!"
72+
old_cre:
73+
image: checkmk/check-mk-raw:2.3.0p33
74+
ports:
75+
- 5023:5000
76+
env:
77+
CMK_SITE_ID: "old_cre"
78+
CMK_PASSWORD: "Sup3rSec4et!"
79+
old_cme:
80+
image: checkmk/check-mk-managed:2.3.0p33
81+
ports:
82+
- 5323:5000
83+
env:
84+
CMK_SITE_ID: "old_cme"
85+
CMK_PASSWORD: "Sup3rSec4et!"
86+
stable_cre:
87+
image: checkmk/check-mk-raw:2.4.0p2
88+
ports:
89+
- 5024:5000
90+
env:
91+
CMK_SITE_ID: "stable_cre"
92+
CMK_PASSWORD: "Sup3rSec4et!"
93+
stable_cme:
94+
image: checkmk/check-mk-managed:2.4.0p2
95+
ports:
96+
- 5324:5000
97+
env:
98+
CMK_SITE_ID: "stable_cme"
99+
CMK_PASSWORD: "Sup3rSec4et!"
100+
101+
steps:
102+
- name: Check out code
103+
uses: actions/checkout@v4
104+
with:
105+
path: ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}
106+
107+
- name: Set up Python
108+
uses: actions/setup-python@v5
109+
with:
110+
python-version: ${{ matrix.python }}
111+
112+
- name: Install ansible-base (${{ matrix.ansible }})
113+
run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check
114+
115+
- name: Run integration test
116+
run: ansible-test integration ${{env.MODULE_NAME}} -v --color --retry-on-error --continue-on-error --diff --python ${{ matrix.python }}
117+
working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}

plugins/modules/bi_rule.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
EXAMPLES = r"""
8080
- name: Create a BI rule
8181
checkmk.general.bi_rule:
82-
server_url: "https://example.com/"
82+
server_url: "http://myserver/"
8383
site: "mysite"
8484
automation_auth_type: "bearer"
8585
automation_user: "myuser"
@@ -114,7 +114,7 @@
114114
115115
- name: Delete a BI rule
116116
checkmk.general.bi_rule:
117-
server_url: "https://example.com/"
117+
server_url: "http://myserver/"
118118
site: "mysite"
119119
automation_auth_type: "bearer"
120120
automation_user: "myuser"
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
- name: "Include Global Variables."
3+
ansible.builtin.include_vars: "{{ lookup('ansible.builtin.first_found', checkmk_var_params) }}"
4+
vars:
5+
checkmk_var_params:
6+
files:
7+
- global.yml
8+
paths:
9+
- /home/runner/work/ansible-collection-checkmk.general/ansible-collection-checkmk.general/ansible_collections/checkmk/general/tests/integration/files/includes/vars/
10+
- /root/ansible_collections/checkmk/general/tests/integration/files/includes/vars/
11+
- tests/integration/files/includes/vars/
12+
13+
- name: "Print Identifier."
14+
ansible.builtin.debug:
15+
msg: "{{ ansible_facts.system_vendor }} {{ ansible_facts.product_name }} running {{ ansible_facts.virtualization_type }}"
16+
17+
- name: "Run preparations."
18+
ansible.builtin.include_tasks: "{{ lookup('ansible.builtin.first_found', checkmk_var_params) }}"
19+
vars:
20+
checkmk_var_params:
21+
files:
22+
- prep.yml
23+
paths:
24+
- /home/runner/work/ansible-collection-checkmk.general/ansible-collection-checkmk.general/ansible_collections/checkmk/general/tests/integration/files/includes/tasks/
25+
- /root/ansible_collections/checkmk/general/tests/integration/files/includes/tasks/
26+
- tests/integration/files/includes/tasks/
27+
when: |
28+
(ansible_facts.system_vendor == "Dell Inc." and 'Latitude' in ansible_facts.product_name and ansible_facts.virtualization_type == "container")
29+
or (ansible_facts.system_vendor == "QEMU" and 'Ubuntu' in ansible_facts.product_name and ansible_facts.virtualization_type == "container")
30+
31+
- name: "Testing."
32+
ansible.builtin.include_tasks: test.yml
33+
loop: "{{ checkmk_var_test_sites }}"
34+
loop_control:
35+
loop_var: outer_item
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Set customer when needed."
3+
ansible.builtin.set_fact:
4+
checkmk_var_customer: "provider"
5+
when: (outer_item.edition == "cme") or (outer_item.edition == "cce")
6+
7+
- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Unset customer when needed."
8+
ansible.builtin.set_fact:
9+
checkmk_var_customer: null
10+
when: not ((outer_item.edition == "cme") or (outer_item.edition == "cce"))
11+
12+
- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Create a BI rule."
13+
bi_rule:
14+
server_url: "{{ checkmk_var_server_url }}"
15+
site: "{{ outer_item.site }}"
16+
automation_user: "{{ checkmk_var_automation_user }}"
17+
automation_secret: "{{ checkmk_var_automation_secret }}"
18+
automation_auth_type: "bearer"
19+
rule:
20+
pack_id: "default"
21+
id: "testrule1"
22+
nodes:
23+
- search:
24+
type: "empty"
25+
action:
26+
type: "call_a_rule"
27+
rule_id: "test-child-rule1"
28+
params:
29+
arguments: []
30+
properties:
31+
title: "Test Rule 1"
32+
comment: ""
33+
docu_url: ""
34+
icon: ""
35+
state_messages: {}
36+
aggregation_function:
37+
type: "best"
38+
count: 1
39+
restrict_state: 2
40+
computation_options:
41+
disabled: false
42+
node_visualization:
43+
type: "block"
44+
style_config: {}
45+
params:
46+
arguments: []
47+
state: "present"
48+
delegate_to: localhost
49+
50+
- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Delete a BI rule."
51+
bi_rule:
52+
server_url: "{{ checkmk_var_server_url }}"
53+
site: "{{ outer_item.site }}"
54+
automation_user: "{{ checkmk_var_automation_user }}"
55+
automation_secret: "{{ checkmk_var_automation_secret }}"
56+
automation_auth_type: "bearer"
57+
rule:
58+
pack_id: "cluster_pack"
59+
id: "testrule1"
60+
state: "absent"
61+
delegate_to: localhost
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
checkmk_var_test_sites:
3+
# - version: "2.2.0p42"
4+
# edition: "cre"
5+
# site: "ancient_cre"
6+
# port: "5022"
7+
# - version: "2.3.0p33"
8+
# edition: "cre"
9+
# site: "old_cre"
10+
# port: "5023"
11+
# - version: "2.3.0p33"
12+
# edition: "cme"
13+
# site: "old_cme"
14+
# port: "5323"
15+
# - version: "2.4.0p2"
16+
# edition: "cre"
17+
# site: "stable_cre"
18+
# port: "5024"
19+
- version: "2.4.0p2"
20+
edition: "cme"
21+
site: "stable_cme"
22+
port: "5324"

0 commit comments

Comments
 (0)