mirror of
https://github.com/ansible-collections/hetzner.hcloud.git
synced 2026-02-04 08:01:49 +00:00
fix: check label_selector child targets with load_balancer_status filter (#552)
##### SUMMARY The previous implementation did not take into consideration label selectors targets, and their child targets. This change implements a recursive function that traverse all the targets. Related to #467 #550
This commit is contained in:
parent
fce8bc9bb9
commit
abdf72212b
3 changed files with 62 additions and 53 deletions
|
|
@ -4,14 +4,14 @@
|
|||
ansible.builtin.set_fact:
|
||||
load_balancer_status_healthy: >-
|
||||
{{ { "targets": [
|
||||
{"health_status": [{"status": "healthy"}]},
|
||||
{"health_status": [{"status": "healthy"}]},
|
||||
{ "type": "server", "health_status": [{ "status": "healthy" }]},
|
||||
{ "type": "label_selector", "targets": [{ "type": "server", "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"}]},
|
||||
{ "type": "server", "health_status": [{ "status": "healthy" }, { "status": "unhealthy" }]},
|
||||
{ "type": "label_selector", "targets": [{ "type": "server", "health_status": [{ "status": "healthy" }, { "status": "unhealthy" }] }]}
|
||||
]} | hetzner.hcloud.load_balancer_status }}
|
||||
|
||||
- name: Verify filter load_balancer_status
|
||||
|
|
|
|||
|
|
@ -4,39 +4,39 @@ import pytest
|
|||
|
||||
from plugins.filter.all import load_balancer_status
|
||||
|
||||
|
||||
def _lb_target_server(status: str) -> dict:
|
||||
return {"type": "server", "health_status": [{"status": status}]}
|
||||
|
||||
|
||||
def _lb_target_label_selector(status: str) -> dict:
|
||||
return {"type": "label_selector", "targets": [_lb_target_server(status)]}
|
||||
|
||||
|
||||
LOAD_BALANCER_STATUS_TEST_CASES = (
|
||||
({"targets": [{"health_status": []}]}, "unknown"),
|
||||
({"targets": [{"health_status": [{}]}]}, "unknown"),
|
||||
({"targets": [{"health_status": [{"status": "unknown"}]}]}, "unknown"),
|
||||
({"targets": [{"health_status": [{"status": "unhealthy"}]}]}, "unhealthy"),
|
||||
({"targets": [{"health_status": [{"status": "healthy"}]}]}, "healthy"),
|
||||
(
|
||||
{
|
||||
"targets": [
|
||||
{"health_status": [{"status": "healthy"}]},
|
||||
{"health_status": [{"status": "healthy"}]},
|
||||
]
|
||||
},
|
||||
"healthy",
|
||||
),
|
||||
(
|
||||
{
|
||||
"targets": [
|
||||
{"health_status": [{"status": "healthy"}, {"status": "unhealthy"}]},
|
||||
{"health_status": [{"status": "healthy"}, {"status": "unknown"}]},
|
||||
]
|
||||
},
|
||||
"unhealthy",
|
||||
),
|
||||
(
|
||||
{
|
||||
"targets": [
|
||||
{"health_status": [{"status": "healthy"}]},
|
||||
{"health_status": [{"status": "unhealthy"}]},
|
||||
]
|
||||
},
|
||||
"unhealthy",
|
||||
),
|
||||
({"targets": [{"type": "server", "health_status": []}]}, "unknown"),
|
||||
({"targets": [{"type": "server", "health_status": [{}]}]}, "unknown"),
|
||||
({"targets": [_lb_target_server("healthy")]}, "healthy"),
|
||||
({"targets": [_lb_target_server("unhealthy")]}, "unhealthy"),
|
||||
({"targets": [_lb_target_server("unknown")]}, "unknown"),
|
||||
({"targets": [_lb_target_label_selector("healthy"), _lb_target_server("healthy")]}, "healthy"),
|
||||
({"targets": [_lb_target_label_selector("healthy"), _lb_target_server("unhealthy")]}, "unhealthy"),
|
||||
({"targets": [_lb_target_label_selector("healthy"), _lb_target_server("unknown")]}, "unknown"),
|
||||
({"targets": [_lb_target_label_selector("unhealthy"), _lb_target_server("healthy")]}, "unhealthy"),
|
||||
({"targets": [_lb_target_label_selector("unhealthy"), _lb_target_server("unhealthy")]}, "unhealthy"),
|
||||
({"targets": [_lb_target_label_selector("unhealthy"), _lb_target_server("unknown")]}, "unhealthy"),
|
||||
({"targets": [_lb_target_label_selector("unknown"), _lb_target_server("healthy")]}, "unknown"),
|
||||
({"targets": [_lb_target_label_selector("unknown"), _lb_target_server("unhealthy")]}, "unhealthy"),
|
||||
({"targets": [_lb_target_label_selector("unknown"), _lb_target_server("unknown")]}, "unknown"),
|
||||
({"targets": [_lb_target_server("healthy"), _lb_target_label_selector("healthy")]}, "healthy"),
|
||||
({"targets": [_lb_target_server("healthy"), _lb_target_label_selector("unhealthy")]}, "unhealthy"),
|
||||
({"targets": [_lb_target_server("healthy"), _lb_target_label_selector("unknown")]}, "unknown"),
|
||||
({"targets": [_lb_target_server("unhealthy"), _lb_target_label_selector("healthy")]}, "unhealthy"),
|
||||
({"targets": [_lb_target_server("unhealthy"), _lb_target_label_selector("unhealthy")]}, "unhealthy"),
|
||||
({"targets": [_lb_target_server("unhealthy"), _lb_target_label_selector("unknown")]}, "unhealthy"),
|
||||
({"targets": [_lb_target_server("unknown"), _lb_target_label_selector("healthy")]}, "unknown"),
|
||||
({"targets": [_lb_target_server("unknown"), _lb_target_label_selector("unhealthy")]}, "unhealthy"),
|
||||
({"targets": [_lb_target_server("unknown"), _lb_target_label_selector("unknown")]}, "unknown"),
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue