Skip to content
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
12 changes: 0 additions & 12 deletions .github/labels-issues.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,38 +70,26 @@ lookup:bakery:

lookup:folder:
- 'Component Name: lookup_folder'

lookup:folders:
- 'Component Name: lookup_folders'

lookup:host:
- 'Component Name: lookup_host'

lookup:hosts:
- 'Component Name: lookup_hosts'

lookup:ldap_connection:
- 'Component Name: lookup_ldap_connection'

lookup:ldap_connections:
- 'Component Name: lookup_ldap_connections'

lookup:rule:
- 'Component Name: lookup_rule'

lookup:rules:
- 'Component Name: lookup_rules'

lookup:ruleset:
- 'Component Name: lookup_ruleset'

lookup:rulesets:
- 'Component Name: lookup_rulesets'

lookup:site:
- 'Component Name: lookup_site'

lookup:sites:
- 'Component Name: lookup_sites'

lookup:version:
Expand Down
24 changes: 0 additions & 24 deletions .github/labels-prs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,60 +113,36 @@ lookup:folder:
- any:
- changed-files:
- any-glob-to-any-file: 'plugins/modules/lookup/folder.py'

lookup:folders:
- any:
- changed-files:
- any-glob-to-any-file: 'plugins/modules/lookup/folders.py'

lookup:host:
- any:
- changed-files:
- any-glob-to-any-file: 'plugins/modules/lookup/host.py'

lookup:hosts:
- any:
- changed-files:
- any-glob-to-any-file: 'plugins/modules/lookup/hosts.py'

lookup:ldap_connection:
- any:
- changed-files:
- any-glob-to-any-file: 'plugins/modules/lookup/ldap_connection.py'

lookup:ldap_connections:
- any:
- changed-files:
- any-glob-to-any-file: 'plugins/modules/lookup/ldap_connections.py'

lookup:rule:
- any:
- changed-files:
- any-glob-to-any-file: 'plugins/modules/lookup/rule.py'

lookup:rules:
- any:
- changed-files:
- any-glob-to-any-file: 'plugins/modules/lookup/rules.py'

lookup:ruleset:
- any:
- changed-files:
- any-glob-to-any-file: 'plugins/modules/lookup/ruleset.py'

lookup:rulesets:
- any:
- changed-files:
- any-glob-to-any-file: 'plugins/modules/lookup/rulesets.py'

lookup:site:
- any:
- changed-files:
- any-glob-to-any-file: 'plugins/modules/lookup/site.py'

lookup:sites:
- any:
- changed-files:
- any-glob-to-any-file: 'plugins/modules/lookup/sites.py'

lookup:version:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/ans-int-test-lkp-folder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ on:
- devel
paths:
- 'plugins/lookup/folder.py'
- 'plugins/lookup/folders.py'
push:
paths:
- '.github/workflows/ans-int-test-lkp-folder.yaml'
- 'plugins/lookup/folder.py'
- 'plugins/lookup/folders.py'
- 'plugins/module_utils/**'
- 'tests/integration/files/includes/**'
- 'tests/integration/targets/lookup_folder/**'
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/ans-int-test-lkp-host.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ on:
- devel
paths:
- 'plugins/lookup/host.py'
- 'plugins/lookup/hosts.py'
push:
paths:
- '.github/workflows/ans-int-test-lkp-host.yaml'
- 'plugins/lookup/host.py'
- 'plugins/lookup/hosts.py'
- 'plugins/module_utils/**'
- 'tests/integration/files/includes/**'
- 'tests/integration/targets/lookup_host/**'
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/ans-int-test-lkp-ldap_connection.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ on:
- devel
paths:
- 'plugins/lookup/ldap_connection.py'
- 'plugins/lookup/ldap_connections.py'
push:
paths:
- '.github/workflows/ans-int-test-lkp-ldap_connection.yaml'
- 'plugins/lookup/ldap_connection.py'
- 'plugins/lookup/ldap_connections.py'
- 'plugins/module_utils/**'
- 'tests/integration/files/includes/**'
- 'tests/integration/targets/lookup_ldap_connection/**'
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/ans-int-test-lkp-site.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ on:
- devel
paths:
- 'plugins/lookup/site.py'
- 'plugins/lookup/sites.py'
push:
paths:
- '.github/workflows/ans-int-test-lkp-site.yaml'
- 'plugins/lookup/site.py'
- 'plugins/lookup/sites.py'
- 'plugins/module_utils/**'
- 'tests/integration/files/includes/**'
- 'tests/integration/targets/lookup_site/**'
Expand Down
109 changes: 66 additions & 43 deletions tests/integration/targets/lookup_folder/tasks/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,77 +3,100 @@
ansible.builtin.set_fact:
checkmk_var_customer: "{{ 'provider' if outer_item.edition == 'cme' else None }}"

- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Create folder."
- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Create folders."
folder:
server_url: "{{ checkmk_var_server_url }}"
site: "{{ outer_item.site }}"
api_user: "{{ checkmk_var_api_user }}"
api_secret: "{{ checkmk_var_api_secret }}"
name: "{{ checkmk_var_folder.name }}"
path: "{{ checkmk_var_folder.path }}"
attributes:
tag_criticality: "{{ checkmk_var_folder.criticality }}"
name: "{{ item.name }}"
path: "{{ item.path }}"
update_attributes:
tag_criticality: "{{ item.criticality }}"
state: "present"
delegate_to: localhost
run_once: true # noqa run-once[task]
loop: "{{ checkmk_var_folders }}"

- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Get all folders."
ansible.builtin.debug:
var: __checkmk_var_folders
vars:
__checkmk_var_folders: "{{ lookup('checkmk.general.folders',
'/',
server_url=checkmk_var_server_url,
site=outer_item.site,
validate_certs=False,
api_user=checkmk_var_api_user,
api_secret=checkmk_var_api_secret)
}}"
delegate_to: localhost
run_once: true # noqa run-once[task]
ansible.builtin.set_fact:
__checkmk_var_folder_list: "{{ lookup('checkmk.general.folders', '/',
recursive=True,
server_url=checkmk_var_server_url,
site=outer_item.site,
validate_certs=False,
api_user=checkmk_var_api_user,
api_secret=checkmk_var_api_secret) }}"

- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Get attributes of folder."
ansible.builtin.debug:
msg: "Criticality of {{ checkmk_var_folder.name }} is {{ __checkmk_var_folder.extensions.attributes.tag_criticality }}"
vars:
__checkmk_var_folder: "{{ lookup('checkmk.general.folder',
checkmk_var_folder.path,
server_url=checkmk_var_server_url,
site=outer_item.site,
validate_certs=False,
api_user=checkmk_var_api_user,
api_secret=checkmk_var_api_secret)
}}"
delegate_to: localhost
run_once: true # noqa run-once[task]
- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Verify folder count."
ansible.builtin.assert:
that: "__checkmk_var_folder_list | length == (checkmk_var_folders | length + 1)"
fail_msg: "Expected {{ checkmk_var_folders | length + 1 }} folders, but found {{ __checkmk_var_folder_list | length }}!"
success_msg: "Expected {{ checkmk_var_folders | length + 1 }} folders, and found {{ __checkmk_var_folder_list | length }}."

- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Verify folder criticality."
ansible.builtin.assert:
that: "__checkmk_var_folder.extensions.attributes.tag_criticality == checkmk_var_folder.criticality"
that: "item.extensions.attributes.tag_criticality == (checkmk_var_folders | selectattr('path', 'equalto', item.extensions.path) | map(attribute='criticality') | first)"
fail_msg: "Expected {{ item.id }} tag_criticality to be {{ checkmk_var_folders | selectattr('path', 'equalto', item.extensions.path) | map(attribute='criticality') | first }}, but found {{ item.extensions.attributes.tag_criticality }}!"
success_msg: "Expected {{ item.id }} tag_criticality to be {{ checkmk_var_folders | selectattr('path', 'equalto', item.extensions.path) | map(attribute='criticality') | first }}, and found {{ item.extensions.attributes.tag_criticality }}."
loop: "{{ __checkmk_var_folder_list }}"
when: item.id != '~'
loop_control:
label: "{{ item.id }}"

- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Verify folder criticality per host."
ansible.builtin.assert:
that: "__checkmk_var_folder.extensions.attributes.tag_criticality == item.extensions.attributes.tag_criticality"
fail_msg: "Expected {{ item.id }} tag_criticality to be {{ item.extensions.attributes.tag_criticality }}, but found {{ __checkmk_var_folder.extensions.attributes.tag_criticality }}!"
success_msg: "Expected {{ item.id }} tag_criticality to be {{ item.extensions.attributes.tag_criticality }}, and found {{ __checkmk_var_folder.extensions.attributes.tag_criticality }}."
vars:
__checkmk_var_folder: "{{ lookup('checkmk.general.folder',
checkmk_var_folder.path,
item.id,
server_url=checkmk_var_server_url,
site=outer_item.site,
validate_certs=False,
api_user=checkmk_var_api_user,
api_secret=checkmk_var_api_secret)
}}"
delegate_to: localhost
run_once: true # noqa run-once[task]
loop: "{{ __checkmk_var_folder_list }}"
when: item.id != '~'
loop_control:
label: "{{ item.id }}"

# We need this hack to overwrite the colliding global variable
- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Use variables from inventory."
delegate_to: localhost
run_once: true # noqa run-once[task]
when: outer_item.site == "stable_cme"
block:
- name: "Set checkmk_var_server_url for isolated testing."
ansible.builtin.set_fact:
checkmk_var_server_url: "http://127.0.0.1:5104/"

- name: "Test plugin with variables from inventory."
- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Get all folders."
ansible.builtin.set_fact:
__checkmk_var_folder_list: "{{ lookup('checkmk.general.folders', '/', recursive=True) }}"

- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Verify folder count."
ansible.builtin.assert:
that: "__checkmk_var_folder_list | length == (checkmk_var_folders | length + 1)"
fail_msg: "Expected {{ checkmk_var_folders | length + 1 }} folders, but found {{ __checkmk_var_folder_list | length }}!"
success_msg: "Expected {{ checkmk_var_folders | length + 1 }} folders, and found {{ __checkmk_var_folder_list | length }}."

- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Verify folder criticality."
ansible.builtin.assert:
that: "item.extensions.attributes.tag_criticality == (checkmk_var_folders | selectattr('path', 'equalto', item.extensions.path) | map(attribute='criticality') | first)"
fail_msg: "Expected {{ item.id }} tag_criticality to be {{ checkmk_var_folders | selectattr('path', 'equalto', item.extensions.path) | map(attribute='criticality') | first }}, but found {{ item.extensions.attributes.tag_criticality }}!"
success_msg: "Expected {{ item.id }} tag_criticality to be {{ checkmk_var_folders | selectattr('path', 'equalto', item.extensions.path) | map(attribute='criticality') | first }}, and found {{ item.extensions.attributes.tag_criticality }}."
loop: "{{ __checkmk_var_folder_list }}"
when: item.id != '~'
loop_control:
label: "{{ item.id }}"

- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Verify folder criticality per host."
ansible.builtin.assert:
that: "__checkmk_var_folder.extensions.attributes.tag_criticality == checkmk_var_folder.criticality"
that: "__checkmk_var_folder.extensions.attributes.tag_criticality == item.extensions.attributes.tag_criticality"
fail_msg: "Expected {{ item.id }} tag_criticality to be {{ item.extensions.attributes.tag_criticality }}, but found {{ __checkmk_var_folder.extensions.attributes.tag_criticality }}!"
success_msg: "Expected {{ item.id }} tag_criticality to be {{ item.extensions.attributes.tag_criticality }}, and found {{ __checkmk_var_folder.extensions.attributes.tag_criticality }}."
vars:
__checkmk_var_folder: "{{ lookup('checkmk.general.folder', checkmk_var_folder.path) }}"
__checkmk_var_folder: "{{ lookup('checkmk.general.folder', item.id) }}"
loop: "{{ __checkmk_var_folder_list }}"
when: item.id != '~'
loop_control:
label: "{{ item.id }}"
17 changes: 13 additions & 4 deletions tests/integration/targets/lookup_folder/vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@ checkmk_var_test_sites:
site: "stable_cme"
port: "5104"

checkmk_var_folder:
name: "Folder 1"
path: "/folder1"
criticality: "test"
checkmk_var_folders:
- name: "Folder 1"
path: "/folder1"
criticality: "test"
- name: "Folder 2"
path: "/folder2"
criticality: "test"
- name: "Folder 3"
path: "/folder3"
criticality: "test"
- name: "Folder 3a"
path: "/folder3/a"
criticality: "prod"
Loading