mirror of
https://github.com/ansible-collections/hetzner.hcloud.git
synced 2026-02-04 08:01:49 +00:00
feat: compute load balancer targets status using a filter (#550)
##### SUMMARY Allow to compute the status of a load balancer using a filter. Closes #467 ##### ISSUE TYPE - Feature Pull Request ##### COMPONENT NAME hetzner.hcloud.loab_balancer_status
This commit is contained in:
parent
a85bd39738
commit
fce8bc9bb9
10 changed files with 199 additions and 10 deletions
3
tests/integration/targets/filter_all/aliases
Normal file
3
tests/integration/targets/filter_all/aliases
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
cloud/hcloud
|
||||
gather_facts/no
|
||||
azp/group2
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
#
|
||||
# DO NOT EDIT THIS FILE! Please edit the files in tests/integration/common instead.
|
||||
#
|
||||
---
|
||||
# Azure Pipelines will configure this value to something similar to
|
||||
# "azp-84824-1-hetzner-2-13-test-2-13-hcloud-3-9-1-default-i"
|
||||
hcloud_prefix: "tests"
|
||||
|
||||
# Used to namespace resources created by concurrent test pipelines/targets
|
||||
hcloud_run_ns: "{{ hcloud_prefix | md5 }}"
|
||||
hcloud_role_ns: "{{ role_name | split('_') | map('batch', 2) | map('first') | flatten() | join() }}"
|
||||
hcloud_ns: "ansible-{{ hcloud_run_ns }}-{{ hcloud_role_ns }}"
|
||||
|
||||
# Used to easily update the server types and images across all our tests.
|
||||
hcloud_server_type_name: cax11
|
||||
hcloud_server_type_id: 45
|
||||
|
||||
hcloud_server_type_upgrade_name: cax21
|
||||
hcloud_server_type_upgrade_id: 93
|
||||
|
||||
hcloud_image_name: debian-12
|
||||
hcloud_image_id: 114690389 # architecture=arm
|
||||
|
||||
hcloud_location_name: hel1
|
||||
hcloud_location_id: 3
|
||||
hcloud_datacenter_name: hel1-dc2
|
||||
hcloud_datacenter_id: 3
|
||||
|
||||
hcloud_network_zone_name: eu-central
|
||||
31
tests/integration/targets/filter_all/tasks/main.yml
Normal file
31
tests/integration/targets/filter_all/tasks/main.yml
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#
|
||||
# DO NOT EDIT THIS FILE! Please edit the files in tests/integration/common instead.
|
||||
#
|
||||
---
|
||||
- name: Check if cleanup.yml exists
|
||||
ansible.builtin.stat:
|
||||
path: "{{ role_path }}/tasks/cleanup.yml"
|
||||
register: cleanup_file
|
||||
|
||||
- name: Check if prepare.yml exists
|
||||
ansible.builtin.stat:
|
||||
path: "{{ role_path }}/tasks/prepare.yml"
|
||||
register: prepare_file
|
||||
|
||||
- name: Include cleanup tasks
|
||||
ansible.builtin.include_tasks: "{{ role_path }}/tasks/cleanup.yml"
|
||||
when: cleanup_file.stat.exists
|
||||
|
||||
- name: Include prepare tasks
|
||||
ansible.builtin.include_tasks: "{{ role_path }}/tasks/prepare.yml"
|
||||
when: prepare_file.stat.exists
|
||||
|
||||
- name: Run tests
|
||||
block:
|
||||
- name: Include test tasks
|
||||
ansible.builtin.include_tasks: "{{ role_path }}/tasks/test.yml"
|
||||
|
||||
always:
|
||||
- name: Include cleanup tasks
|
||||
ansible.builtin.include_tasks: "{{ role_path }}/tasks/cleanup.yml"
|
||||
when: cleanup_file.stat.exists
|
||||
21
tests/integration/targets/filter_all/tasks/test.yml
Normal file
21
tests/integration/targets/filter_all/tasks/test.yml
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
- name: Test filter load_balancer_status
|
||||
block:
|
||||
- name: Load data
|
||||
ansible.builtin.set_fact:
|
||||
load_balancer_status_healthy: >-
|
||||
{{ { "targets": [
|
||||
{"health_status": [{"status": "healthy"}]},
|
||||
{"health_status": [{"status": "healthy"}]},
|
||||
]} | hetzner.hcloud.load_balancer_status }}
|
||||
|
||||
load_balancer_status_healthy_and_unhealthy: >-
|
||||
{{ { "targets": [
|
||||
{"health_status": [{"status": "healthy"}, {"status": "unhealthy"}]},
|
||||
{"health_status": [{"status": "healthy"}, {"status": "healthy"}]},
|
||||
]} | hetzner.hcloud.load_balancer_status }}
|
||||
|
||||
- name: Verify filter load_balancer_status
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- load_balancer_status_healthy == "healthy"
|
||||
- load_balancer_status_healthy_and_unhealthy == "unhealthy"
|
||||
Loading…
Add table
Add a link
Reference in a new issue