diff options
| author | Colin Wilk <colin@wilk.cx> | 2026-07-03 20:15:09 +0200 |
|---|---|---|
| committer | Colin Wilk <colin@wilk.cx> | 2026-07-03 20:15:09 +0200 |
| commit | 9368443af5c0cdfbadbd54f92814dadce1c4e663 (patch) | |
| tree | 8bfd750d7c4623c52adc775f51468bced1a01d5e /molecule | |
| parent | 7074302088d7283181f03c8ad3108322b9033bc3 (diff) | |
| download | ansible-role-prometheus-target-9368443af5c0cdfbadbd54f92814dadce1c4e663.tar.gz ansible-role-prometheus-target-9368443af5c0cdfbadbd54f92814dadce1c4e663.zip | |
refactor: bump and fix pre-commit errors
Diffstat (limited to 'molecule')
| -rw-r--r-- | molecule/default/converge.yml | 42 | ||||
| -rw-r--r-- | molecule/default/molecule.yml | 11 | ||||
| -rw-r--r-- | molecule/default/tests/test_check_prometheus_targets.py | 87 |
3 files changed, 67 insertions, 73 deletions
diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml index cb6a281..98d7e8a 100644 --- a/molecule/default/converge.yml +++ b/molecule/default/converge.yml @@ -6,13 +6,13 @@ pre_tasks: - name: Create targets ansible.builtin.file: - path: '{{ item }}' + path: "{{ item }}" state: touch modification_time: preserve access_time: preserve - mode: '0644' + mode: "0644" become: true - delegate_to: '{{ prometheus_target_host }}' + delegate_to: "{{ prometheus_target_host }}" loop: - /opt/simple_target1.yml - /opt/simple_target2.yml @@ -24,10 +24,10 @@ prometheus_target_exporter_defaults: node_exporter: path: /opt/simple_target1.yml - host: '{{ inventory_hostname }}' + host: "{{ inventory_hostname }}" blackbox_exporter: path: /opt/simple_target2.yml - host: '{{ inventory_hostname }}_AA' + host: "{{ inventory_hostname }}_AA" roles: - role: kliwniloc.prometheus_target @@ -48,13 +48,13 @@ pre_tasks: - name: Create targets ansible.builtin.file: - path: '{{ item.path }}' - state: '{{ item.state }}' + path: "{{ item.path }}" + state: "{{ item.state }}" modification_time: preserve access_time: preserve - mode: '0644' + mode: "0644" become: true - delegate_to: '{{ prometheus_target_host }}' + delegate_to: "{{ prometheus_target_host }}" loop: - { state: touch, path: /opt/prefix_target1.yml } - { state: touch, path: /opt/prefix_target2.yml } @@ -67,17 +67,17 @@ prometheus_target_exporter_defaults: node_exporter: path: prefix_target1.yml - host: '{{ inventory_hostname }}' + host: "{{ inventory_hostname }}" blackbox_exporter: path: prefix_target_not_exist.yml - host: '{{ inventory_hostname }}' + host: "{{ inventory_hostname }}" path_prefix: /opt/prefix/ roles: - role: kliwniloc.prometheus_target prometheus_target_exporter: - id: node_exporter - - { id: node_exporter, path: /opt/prefix_target2.yml, path_prefix: '' } + - { id: node_exporter, path: /opt/prefix_target2.yml, path_prefix: "" } - { id: blackbox_exporter, path: prefix_target3.yml } ################################################################################ @@ -87,13 +87,13 @@ pre_tasks: - name: Create targets ansible.builtin.file: - path: '{{ item }}' + path: "{{ item }}" state: touch modification_time: preserve access_time: preserve - mode: '0644' + mode: "0644" become: true - delegate_to: '{{ prometheus_target_host }}' + delegate_to: "{{ prometheus_target_host }}" loop: - /opt/hook_target.yml - /opt/hook2 @@ -112,7 +112,7 @@ - role: kliwniloc.prometheus_target prometheus_target_exporter: - id: node_exporter - host: '{{ inventory_hostname }}' + host: "{{ inventory_hostname }}" path: /opt/hook_target.yml ################################################################################ @@ -124,14 +124,14 @@ ansible.builtin.user: name: prometheus become: true - delegate_to: '{{ prometheus_target_host }}' + delegate_to: "{{ prometheus_target_host }}" - name: Create target ansible.builtin.copy: dest: /opt/lineinfile.yml owner: prometheus group: prometheus - mode: '0600' + mode: "0600" force: false # yamllint disable rule:indentation content: | @@ -141,11 +141,11 @@ - existing:9100 # yamllint enable rule:indentation become: true - delegate_to: '{{ prometheus_target_host }}' + delegate_to: "{{ prometheus_target_host }}" vars: prometheus_target_host: prometheus - prometheus_target_strategy_lineinfile_prefix: ' - ' + prometheus_target_strategy_lineinfile_prefix: " - " prometheus_target_strategy_lineinfile_suffix: :9100 roles: @@ -153,4 +153,4 @@ prometheus_target_exporter: - id: node_exporter path: /opt/lineinfile.yml - host: '{{ inventory_hostname }}' + host: "{{ inventory_hostname }}" diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index de1ac40..3ffe0b8 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -2,15 +2,12 @@ dependency: name: galaxy - driver: name: docker - platforms: - - name: application - image: ${MOLECULE_DISTRO:-debian:10} + image: ${MOLECULE_DISTRO:-debian:12} dockerfile: Dockerfile.j2 pre_build_image: false docker_networks: @@ -23,7 +20,7 @@ platforms: groups: [application_group] - name: application2 - image: ${MOLECULE_DISTRO:-debian:10} + image: ${MOLECULE_DISTRO:-debian:12} dockerfile: Dockerfile.j2 pre_build_image: false networks: @@ -31,18 +28,16 @@ platforms: groups: [application_group] - name: prometheus - image: ${MOLECULE_DISTRO:-debian:10} + image: ${MOLECULE_DISTRO:-debian:12} dockerfile: Dockerfile.j2 pre_build_image: false networks: - name: molecule-container-net - provisioner: name: ansible playbooks: converge: ${MOLECULE_PLAYBOOK:-converge.yml} - verifier: name: testinfra diff --git a/molecule/default/tests/test_check_prometheus_targets.py b/molecule/default/tests/test_check_prometheus_targets.py index 2eeb21b..b9024b4 100644 --- a/molecule/default/tests/test_check_prometheus_targets.py +++ b/molecule/default/tests/test_check_prometheus_targets.py @@ -1,91 +1,90 @@ -testinfra_hosts = ['prometheus'] +testinfra_hosts = ["prometheus"] """ Test functionality of defining exporters and default fallbacks """ + + def test_check_hosts_added_simple(host): - t1 = host.file('/opt/simple_target1.yml') - t2 = host.file('/opt/simple_target2.yml') - t3 = host.file('/opt/simple_target3.yml') - t4 = host.file('/opt/simple_target4.yml') + t1 = host.file("/opt/simple_target1.yml") + t2 = host.file("/opt/simple_target2.yml") + t3 = host.file("/opt/simple_target3.yml") + t4 = host.file("/opt/simple_target4.yml") assert t1.exists assert t2.exists assert t3.exists assert t4.exists - assert t1.content_string == \ - ' - application\n' + assert t1.content_string == " - application\n" + assert t2.content_string == " - test1\n - test2\n" - assert t2.content_string == \ - ' - test1\n' \ - ' - test2\n' + assert t3.content_string == " - application_AA\n" - assert t3.content_string == \ - ' - application_AA\n' + assert t4.content_string == " - exporter_without_id\n" - assert t4.content_string == \ - ' - exporter_without_id\n' """ Test prefix functionality """ + + def test_check_hosts_added_prefix(host): - t1 = host.file('/opt/prefix_target1.yml') - t2 = host.file('/opt/prefix_target2.yml') - t3 = host.file('/opt/prefix/prefix_target3.yml') + t1 = host.file("/opt/prefix_target1.yml") + t2 = host.file("/opt/prefix_target2.yml") + t3 = host.file("/opt/prefix/prefix_target3.yml") assert t1.exists assert t2.exists assert t3.exists - assert t1.content_string == \ - ' - application\n' + assert t1.content_string == " - application\n" + assert t2.content_string == " - application\n" - assert t2.content_string == \ - ' - application\n' + assert t3.content_string == " - application\n" - assert t3.content_string == \ - ' - application\n' """ Test hook functionality """ + + def test_check_hosts_added_hooks(host): - t1 = host.file('/opt/hook_target.yml') - t2 = host.file('/opt/hook1') - t3 = host.file('/opt/hook2') + t1 = host.file("/opt/hook_target.yml") + t2 = host.file("/opt/hook1") + t3 = host.file("/opt/hook2") assert t1.exists assert t2.exists assert t3.exists - assert t1.content_string == \ - ' - application\n' \ - ' - application2\n' \ - or t1.content_string == \ - ' - application2\n' \ - ' - application\n' + assert ( + t1.content_string == " - application\n - application2\n" + or t1.content_string == " - application2\n - application\n" + ) + + assert t3.content_string == "hello\nhello\n" - assert t3.content_string == \ - 'hello\n' \ - 'hello\n' """ Test lineinfile strategy parameters """ + + def test_check_host_added_lineinfile(host): - t1 = host.file('/opt/lineinfile.yml') + t1 = host.file("/opt/lineinfile.yml") - assert t1.user == 'prometheus' - assert t1.group == 'prometheus' + assert t1.user == "prometheus" + assert t1.group == "prometheus" assert t1.mode == 0o600 - assert t1.content_string == \ - '- labels:\n' \ - ' my: label\n' \ - ' targets:\n' \ - ' - existing:9100\n' \ - ' - application:9100\n' + assert ( + t1.content_string == "- labels:\n" + " my: label\n" + " targets:\n" + " - existing:9100\n" + " - application:9100\n" + ) + |