Skip to content

Commit

Permalink
test: improve load_balancer_target integration using new framework (a…
Browse files Browse the repository at this point in the history
…nsible-collections#547)

##### SUMMARY

Use the new testing framework for the load_balancer_target integration
tests.

Depends on ansible-collections#546
  • Loading branch information
jooola authored Aug 8, 2024
1 parent d56d12b commit 04a45bd
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 101 deletions.
1 change: 0 additions & 1 deletion .ansible-lint
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ exclude_paths:
- examples/
- tests/integration/targets/certificate
- tests/integration/targets/floating_ip
- tests/integration/targets/load_balancer_target
- tests/integration/targets/placement_group
- tests/integration/targets/primary_ip
- tests/integration/targets/route
Expand Down
10 changes: 10 additions & 0 deletions tests/integration/targets/load_balancer_target/tasks/cleanup.yml
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions tests/integration/targets/load_balancer_target/tasks/prepare.yml
Original file line number Diff line number Diff line change
@@ -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
220 changes: 120 additions & 100 deletions tests/integration/targets/load_balancer_target/tasks/test.yml
Original file line number Diff line number Diff line change
@@ -1,154 +1,174 @@
# Copyright: (c) 2019, Hetzner Cloud GmbH <[email protected]>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
---
- name: setup 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: 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
- name: Test missing required parameters
hetzner.hcloud.load_balancer_target:
state: present
location: "{{ hcloud_location_name }}"
register: load_balancer
- name: verify setup load_balancer
assert:
ignore_errors: true
register: result
- name: Verify missing required parameters
ansible.builtin.assert:
that:
- load_balancer is success
- result is failed
- 'result.msg == "missing required arguments: load_balancer, type"'

- name: test fail load balancer does not exist
- name: Test create with not existing load_balancer
hetzner.hcloud.load_balancer_target:
load_balancer: not-existing
type: server
load_balancer: does-not-exist
server: "{{ hcloud_server_name }}"
register: result
state: present
ignore_errors: true
- name: verify test fail load_balancer does not exist
assert:
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: does-not-exist'"
- 'result.msg == "resource (load_balancer) does not exist: not-existing"'

- name: test fail server does not exist
- name: Test create with not existing server
hetzner.hcloud.load_balancer_target:
type: server
load_balancer: "{{ hcloud_load_balancer_name }}"
server: does-not-exist
register: result
type: server
server: not-existing
state: present
ignore_errors: true
- name: verify test fail server does not exist
assert:
register: result
- name: Verify create with not existing server
ansible.builtin.assert:
that:
- result is failed
- "result.msg == 'resource (server) does not exist: does-not-exist'"
- 'result.msg == "resource (server) does not exist: not-existing"'

- name: test create load_balancer target with checkmode
- name: Test create with checkmode
hetzner.hcloud.load_balancer_target:
type: "server"
load_balancer: "{{hcloud_load_balancer_name}}"
server: "{{hcloud_server_name}}"
load_balancer: "{{ hcloud_load_balancer_name }}"
type: server
server: "{{ hcloud_server_name }}"
state: present
register: result
check_mode: true
- name: verify test create load_balancer target with checkmode
assert:
register: result
- name: Verify create with checkmode
ansible.builtin.assert:
that:
- result is changed

- name: test create load_balancer target
- name: Test create with server
hetzner.hcloud.load_balancer_target:
type: "server"
load_balancer: "{{hcloud_load_balancer_name}}"
server: "{{hcloud_server_name}}"
load_balancer: "{{ hcloud_load_balancer_name }}"
type: server
server: "{{ hcloud_server_name }}"
state: present
register: load_balancer_target
- name: verify create load_balancer target
assert:
register: result
- name: Verify create with server
ansible.builtin.assert:
that:
- load_balancer_target is changed
- load_balancer_target.hcloud_load_balancer_target.type == "server"
- load_balancer_target.hcloud_load_balancer_target.server == hcloud_server_name
- load_balancer_target.hcloud_load_balancer_target.load_balancer == hcloud_load_balancer_name
- result is changed
- result.hcloud_load_balancer_target.load_balancer == hcloud_load_balancer_name
- result.hcloud_load_balancer_target.type == "server"
- 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:
type: "server"
load_balancer: "{{hcloud_load_balancer_name}}"
server: "{{hcloud_server_name}}"
load_balancer: "{{ hcloud_load_balancer_name }}"
type: server
server: "{{ hcloud_server_name }}"
state: present
register: load_balancer_target
- name: verify create load_balancer target idempotency
assert:
register: result
- name: Verify create with server idempotency
ansible.builtin.assert:
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:
type: "server"
load_balancer: "{{hcloud_load_balancer_name}}"
server: "{{hcloud_server_name}}"
load_balancer: "{{ hcloud_load_balancer_name }}"
type: server
server: "{{ hcloud_server_name }}"
state: absent
register: result
- name: verify test absent load_balancer target
assert:
- name: Verify delete with server
ansible.builtin.assert:
that:
- result is changed

- name: test create label_selector target
- name: Test create with label_selector
hetzner.hcloud.load_balancer_target:
type: "label_selector"
load_balancer: "{{hcloud_load_balancer_name}}"
label_selector: "application=backend"
load_balancer: "{{ hcloud_load_balancer_name }}"
type: label_selector
label_selector: application=backend
state: present
register: load_balancer_target
- name: verify create label_selector target
assert:
register: result
- name: Verify create with label_selector
ansible.builtin.assert:
that:
- load_balancer_target is changed
- load_balancer_target.hcloud_load_balancer_target.type == "label_selector"
- load_balancer_target.hcloud_load_balancer_target.label_selector == "application=backend"
- load_balancer_target.hcloud_load_balancer_target.load_balancer == hcloud_load_balancer_name
- result is changed
- result.hcloud_load_balancer_target.load_balancer == hcloud_load_balancer_name
- result.hcloud_load_balancer_target.type == "label_selector"
- 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:
type: "ip"
load_balancer: "{{ hcloud_load_balancer_name }}"
ip: "{{ hetzner_server_ip }}"
type: label_selector
label_selector: application=backend
state: present
register: load_balancer_target
- name: verify create ip target
assert:
register: result
- name: Verify create with label_selector idempotency
ansible.builtin.assert:
that:
- load_balancer_target is changed
- load_balancer_target.hcloud_load_balancer_target.type == "ip"
- load_balancer_target.hcloud_load_balancer_target.ip == hetzner_server_ip
- load_balancer_target.hcloud_load_balancer_target.load_balancer == hcloud_load_balancer_name
- result is not changed

- name: cleanup load_balancer
hetzner.hcloud.load_balancer:
name: "{{ hcloud_load_balancer_name }}"
- 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
until: result is not failed
retries: 5
delay: 2
- name: Verify delete with label_selector
ansible.builtin.assert:
that:
- result is changed

- name: cleanup
hetzner.hcloud.server:
name: "{{hcloud_server_name}}"
- name: Test create with ip
hetzner.hcloud.load_balancer_target:
load_balancer: "{{ hcloud_load_balancer_name }}"
type: ip
ip: "{{ hetzner_server_ip }}"
state: present
register: result
- name: Verify create with ip
ansible.builtin.assert:
that:
- result is changed
- result.hcloud_load_balancer_target.load_balancer == hcloud_load_balancer_name
- result.hcloud_load_balancer_target.type == "ip"
- result.hcloud_load_balancer_target.ip == hetzner_server_ip
- result.hcloud_load_balancer_target.use_private_ip == none

- name: Test create with ip idempotency
hetzner.hcloud.load_balancer_target:
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
register: result
- name: verify cleanup
assert:
- name: Verify delete with ip
ansible.builtin.assert:
that:
- result is success
- result is changed

0 comments on commit 04a45bd

Please sign in to comment.