mirror of
https://github.com/ansible-collections/hetzner.hcloud
synced 2024-11-10 06:34:13 +00:00
test: improve load_balancer_target
integration using new framework (#547)
##### SUMMARY Use the new testing framework for the load_balancer_target integration tests. Depends on #546
This commit is contained in:
parent
d56d12b68d
commit
04a45bd92c
4 changed files with 167 additions and 120 deletions
|
@ -8,7 +8,6 @@ exclude_paths:
|
||||||
- examples/
|
- examples/
|
||||||
- tests/integration/targets/certificate
|
- tests/integration/targets/certificate
|
||||||
- tests/integration/targets/floating_ip
|
- tests/integration/targets/floating_ip
|
||||||
- tests/integration/targets/load_balancer_target
|
|
||||||
- tests/integration/targets/placement_group
|
- tests/integration/targets/placement_group
|
||||||
- tests/integration/targets/primary_ip
|
- tests/integration/targets/primary_ip
|
||||||
- tests/integration/targets/route
|
- tests/integration/targets/route
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
---
|
||||||
|
- name: Cleanup test_load_balancer
|
||||||
|
hetzner.hcloud.load_balancer:
|
||||||
|
name: "{{ hcloud_load_balancer_name }}"
|
||||||
|
state: absent
|
||||||
|
|
||||||
|
- name: Cleanup test_server
|
||||||
|
hetzner.hcloud.server:
|
||||||
|
name: "{{ hcloud_server_name }}"
|
||||||
|
state: absent
|
|
@ -0,0 +1,18 @@
|
||||||
|
---
|
||||||
|
- name: Create test_server
|
||||||
|
hetzner.hcloud.server:
|
||||||
|
name: "{{ hcloud_server_name }}"
|
||||||
|
server_type: "{{ hcloud_server_type_name }}"
|
||||||
|
image: "{{ hcloud_image_name }}"
|
||||||
|
location: "{{ hcloud_location_name }}"
|
||||||
|
state: stopped
|
||||||
|
register: test_server
|
||||||
|
|
||||||
|
- name: Create test_load_balancer
|
||||||
|
hetzner.hcloud.load_balancer:
|
||||||
|
name: "{{ hcloud_load_balancer_name }}"
|
||||||
|
load_balancer_type: lb11
|
||||||
|
network_zone: "{{ hcloud_network_zone_name }}"
|
||||||
|
labels:
|
||||||
|
key: value
|
||||||
|
register: test_load_balancer
|
|
@ -1,154 +1,174 @@
|
||||||
# Copyright: (c) 2019, Hetzner Cloud GmbH <info@hetzner-cloud.de>
|
# Copyright: (c) 2019, Hetzner Cloud GmbH <info@hetzner-cloud.de>
|
||||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
---
|
---
|
||||||
- name: setup server
|
- name: Test missing required parameters
|
||||||
hetzner.hcloud.server:
|
|
||||||
name: "{{hcloud_server_name}}"
|
|
||||||
server_type: "{{ hcloud_server_type_name }}"
|
|
||||||
image: "{{ hcloud_image_name }}"
|
|
||||||
location: "{{ hcloud_location_name }}"
|
|
||||||
state: stopped
|
|
||||||
register: server
|
|
||||||
- name: verify setup server
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- server is success
|
|
||||||
|
|
||||||
- name: setup load_balancer
|
|
||||||
hetzner.hcloud.load_balancer:
|
|
||||||
name: "{{hcloud_load_balancer_name}}"
|
|
||||||
load_balancer_type: lb11
|
|
||||||
state: present
|
|
||||||
location: "{{ hcloud_location_name }}"
|
|
||||||
register: load_balancer
|
|
||||||
- name: verify setup load_balancer
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- load_balancer is success
|
|
||||||
|
|
||||||
- name: test fail load balancer does not exist
|
|
||||||
hetzner.hcloud.load_balancer_target:
|
hetzner.hcloud.load_balancer_target:
|
||||||
type: server
|
state: present
|
||||||
load_balancer: does-not-exist
|
|
||||||
server: "{{ hcloud_server_name }}"
|
|
||||||
register: result
|
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
- name: verify test fail load_balancer does not exist
|
register: result
|
||||||
assert:
|
- name: Verify missing required parameters
|
||||||
|
ansible.builtin.assert:
|
||||||
that:
|
that:
|
||||||
- result is failed
|
- result is failed
|
||||||
- "result.msg == 'resource (load_balancer) does not exist: does-not-exist'"
|
- 'result.msg == "missing required arguments: load_balancer, type"'
|
||||||
|
|
||||||
- name: test fail server does not exist
|
- name: Test create with not existing load_balancer
|
||||||
hetzner.hcloud.load_balancer_target:
|
hetzner.hcloud.load_balancer_target:
|
||||||
|
load_balancer: not-existing
|
||||||
type: server
|
type: server
|
||||||
load_balancer: "{{ hcloud_load_balancer_name }}"
|
|
||||||
server: does-not-exist
|
|
||||||
register: result
|
|
||||||
ignore_errors: true
|
|
||||||
- name: verify test fail server does not exist
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- result is failed
|
|
||||||
- "result.msg == 'resource (server) does not exist: does-not-exist'"
|
|
||||||
|
|
||||||
- name: test create load_balancer target with checkmode
|
|
||||||
hetzner.hcloud.load_balancer_target:
|
|
||||||
type: "server"
|
|
||||||
load_balancer: "{{hcloud_load_balancer_name}}"
|
|
||||||
server: "{{ hcloud_server_name }}"
|
server: "{{ hcloud_server_name }}"
|
||||||
state: present
|
state: present
|
||||||
|
ignore_errors: true
|
||||||
register: result
|
register: result
|
||||||
|
- name: Verify create with not existing load_balancer
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- result is failed
|
||||||
|
- 'result.msg == "resource (load_balancer) does not exist: not-existing"'
|
||||||
|
|
||||||
|
- name: Test create with not existing server
|
||||||
|
hetzner.hcloud.load_balancer_target:
|
||||||
|
load_balancer: "{{ hcloud_load_balancer_name }}"
|
||||||
|
type: server
|
||||||
|
server: not-existing
|
||||||
|
state: present
|
||||||
|
ignore_errors: true
|
||||||
|
register: result
|
||||||
|
- name: Verify create with not existing server
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- result is failed
|
||||||
|
- 'result.msg == "resource (server) does not exist: not-existing"'
|
||||||
|
|
||||||
|
- name: Test create with checkmode
|
||||||
|
hetzner.hcloud.load_balancer_target:
|
||||||
|
load_balancer: "{{ hcloud_load_balancer_name }}"
|
||||||
|
type: server
|
||||||
|
server: "{{ hcloud_server_name }}"
|
||||||
|
state: present
|
||||||
check_mode: true
|
check_mode: true
|
||||||
- name: verify test create load_balancer target with checkmode
|
register: result
|
||||||
assert:
|
- name: Verify create with checkmode
|
||||||
|
ansible.builtin.assert:
|
||||||
that:
|
that:
|
||||||
- result is changed
|
- result is changed
|
||||||
|
|
||||||
- name: test create load_balancer target
|
- name: Test create with server
|
||||||
hetzner.hcloud.load_balancer_target:
|
hetzner.hcloud.load_balancer_target:
|
||||||
type: "server"
|
|
||||||
load_balancer: "{{ hcloud_load_balancer_name }}"
|
load_balancer: "{{ hcloud_load_balancer_name }}"
|
||||||
|
type: server
|
||||||
server: "{{ hcloud_server_name }}"
|
server: "{{ hcloud_server_name }}"
|
||||||
state: present
|
state: present
|
||||||
register: load_balancer_target
|
register: result
|
||||||
- name: verify create load_balancer target
|
- name: Verify create with server
|
||||||
assert:
|
ansible.builtin.assert:
|
||||||
that:
|
that:
|
||||||
- load_balancer_target is changed
|
- result is changed
|
||||||
- load_balancer_target.hcloud_load_balancer_target.type == "server"
|
- result.hcloud_load_balancer_target.load_balancer == hcloud_load_balancer_name
|
||||||
- load_balancer_target.hcloud_load_balancer_target.server == hcloud_server_name
|
- result.hcloud_load_balancer_target.type == "server"
|
||||||
- load_balancer_target.hcloud_load_balancer_target.load_balancer == hcloud_load_balancer_name
|
- result.hcloud_load_balancer_target.server == hcloud_server_name
|
||||||
|
- result.hcloud_load_balancer_target.use_private_ip == false
|
||||||
|
|
||||||
- name: test create load_balancer target idempotency
|
- name: Test create with server idempotency
|
||||||
hetzner.hcloud.load_balancer_target:
|
hetzner.hcloud.load_balancer_target:
|
||||||
type: "server"
|
|
||||||
load_balancer: "{{ hcloud_load_balancer_name }}"
|
load_balancer: "{{ hcloud_load_balancer_name }}"
|
||||||
|
type: server
|
||||||
server: "{{ hcloud_server_name }}"
|
server: "{{ hcloud_server_name }}"
|
||||||
state: present
|
state: present
|
||||||
register: load_balancer_target
|
register: result
|
||||||
- name: verify create load_balancer target idempotency
|
- name: Verify create with server idempotency
|
||||||
assert:
|
ansible.builtin.assert:
|
||||||
that:
|
that:
|
||||||
- load_balancer_target is not changed
|
- result is not changed
|
||||||
|
|
||||||
- name: test absent load_balancer target
|
- name: Test delete with server
|
||||||
hetzner.hcloud.load_balancer_target:
|
hetzner.hcloud.load_balancer_target:
|
||||||
type: "server"
|
|
||||||
load_balancer: "{{ hcloud_load_balancer_name }}"
|
load_balancer: "{{ hcloud_load_balancer_name }}"
|
||||||
|
type: server
|
||||||
server: "{{ hcloud_server_name }}"
|
server: "{{ hcloud_server_name }}"
|
||||||
state: absent
|
state: absent
|
||||||
register: result
|
register: result
|
||||||
- name: verify test absent load_balancer target
|
- name: Verify delete with server
|
||||||
assert:
|
ansible.builtin.assert:
|
||||||
that:
|
that:
|
||||||
- result is changed
|
- result is changed
|
||||||
|
|
||||||
- name: test create label_selector target
|
- name: Test create with label_selector
|
||||||
hetzner.hcloud.load_balancer_target:
|
hetzner.hcloud.load_balancer_target:
|
||||||
type: "label_selector"
|
|
||||||
load_balancer: "{{ hcloud_load_balancer_name }}"
|
load_balancer: "{{ hcloud_load_balancer_name }}"
|
||||||
label_selector: "application=backend"
|
type: label_selector
|
||||||
|
label_selector: application=backend
|
||||||
state: present
|
state: present
|
||||||
register: load_balancer_target
|
register: result
|
||||||
- name: verify create label_selector target
|
- name: Verify create with label_selector
|
||||||
assert:
|
ansible.builtin.assert:
|
||||||
that:
|
that:
|
||||||
- load_balancer_target is changed
|
- result is changed
|
||||||
- load_balancer_target.hcloud_load_balancer_target.type == "label_selector"
|
- result.hcloud_load_balancer_target.load_balancer == hcloud_load_balancer_name
|
||||||
- load_balancer_target.hcloud_load_balancer_target.label_selector == "application=backend"
|
- result.hcloud_load_balancer_target.type == "label_selector"
|
||||||
- load_balancer_target.hcloud_load_balancer_target.load_balancer == hcloud_load_balancer_name
|
- result.hcloud_load_balancer_target.label_selector == "application=backend"
|
||||||
|
- result.hcloud_load_balancer_target.use_private_ip == false
|
||||||
|
|
||||||
- name: test create ip target
|
- name: Test create with label_selector idempotency
|
||||||
hetzner.hcloud.load_balancer_target:
|
hetzner.hcloud.load_balancer_target:
|
||||||
type: "ip"
|
|
||||||
load_balancer: "{{ hcloud_load_balancer_name }}"
|
load_balancer: "{{ hcloud_load_balancer_name }}"
|
||||||
|
type: label_selector
|
||||||
|
label_selector: application=backend
|
||||||
|
state: present
|
||||||
|
register: result
|
||||||
|
- name: Verify create with label_selector idempotency
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- result is not changed
|
||||||
|
|
||||||
|
- name: Test delete with label_selector
|
||||||
|
hetzner.hcloud.load_balancer_target:
|
||||||
|
load_balancer: "{{ hcloud_load_balancer_name }}"
|
||||||
|
type: label_selector
|
||||||
|
label_selector: application=backend
|
||||||
|
state: absent
|
||||||
|
register: result
|
||||||
|
- name: Verify delete with label_selector
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- result is changed
|
||||||
|
|
||||||
|
- name: Test create with ip
|
||||||
|
hetzner.hcloud.load_balancer_target:
|
||||||
|
load_balancer: "{{ hcloud_load_balancer_name }}"
|
||||||
|
type: ip
|
||||||
ip: "{{ hetzner_server_ip }}"
|
ip: "{{ hetzner_server_ip }}"
|
||||||
state: present
|
state: present
|
||||||
register: load_balancer_target
|
register: result
|
||||||
- name: verify create ip target
|
- name: Verify create with ip
|
||||||
assert:
|
ansible.builtin.assert:
|
||||||
that:
|
that:
|
||||||
- load_balancer_target is changed
|
- result is changed
|
||||||
- load_balancer_target.hcloud_load_balancer_target.type == "ip"
|
- result.hcloud_load_balancer_target.load_balancer == hcloud_load_balancer_name
|
||||||
- load_balancer_target.hcloud_load_balancer_target.ip == hetzner_server_ip
|
- result.hcloud_load_balancer_target.type == "ip"
|
||||||
- load_balancer_target.hcloud_load_balancer_target.load_balancer == hcloud_load_balancer_name
|
- result.hcloud_load_balancer_target.ip == hetzner_server_ip
|
||||||
|
- result.hcloud_load_balancer_target.use_private_ip == none
|
||||||
|
|
||||||
- name: cleanup load_balancer
|
- name: Test create with ip idempotency
|
||||||
hetzner.hcloud.load_balancer:
|
hetzner.hcloud.load_balancer_target:
|
||||||
name: "{{ hcloud_load_balancer_name }}"
|
load_balancer: "{{ hcloud_load_balancer_name }}"
|
||||||
|
type: ip
|
||||||
|
ip: "{{ hetzner_server_ip }}"
|
||||||
|
state: present
|
||||||
|
register: result
|
||||||
|
- name: Verify create with ip idempotency
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- result is not changed
|
||||||
|
|
||||||
|
- name: Test delete with ip
|
||||||
|
hetzner.hcloud.load_balancer_target:
|
||||||
|
load_balancer: "{{ hcloud_load_balancer_name }}"
|
||||||
|
type: ip
|
||||||
|
ip: "{{ hetzner_server_ip }}"
|
||||||
state: absent
|
state: absent
|
||||||
register: result
|
register: result
|
||||||
until: result is not failed
|
- name: Verify delete with ip
|
||||||
retries: 5
|
ansible.builtin.assert:
|
||||||
delay: 2
|
|
||||||
|
|
||||||
- name: cleanup
|
|
||||||
hetzner.hcloud.server:
|
|
||||||
name: "{{hcloud_server_name}}"
|
|
||||||
state: absent
|
|
||||||
register: result
|
|
||||||
- name: verify cleanup
|
|
||||||
assert:
|
|
||||||
that:
|
that:
|
||||||
- result is success
|
- result is changed
|
||||||
|
|
Loading…
Reference in a new issue