Skip to content

Commit

Permalink
test: rework load_balancer module tests (ansible-collections#367)
Browse files Browse the repository at this point in the history
##### SUMMARY

Use the new testing framework and clean up the load_balancer tests.

---------

Co-authored-by: Julian Tölle <[email protected]>
  • Loading branch information
jooola and apricote authored Oct 19, 2023
1 parent 3058995 commit 10a3e4f
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 177 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:
- tests/integration/targets/hcloud_certificate
- tests/integration/targets/hcloud_firewall
- tests/integration/targets/hcloud_floating_ip
- tests/integration/targets/hcloud_load_balancer
- tests/integration/targets/hcloud_load_balancer_network
- tests/integration/targets/hcloud_load_balancer_service
- tests/integration/targets/hcloud_load_balancer_target
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- name: Cleanup test_load_balancer
hetzner.hcloud.hcloud_load_balancer:
name: "{{ hcloud_load_balancer_name }}"
state: absent
237 changes: 61 additions & 176 deletions tests/integration/targets/hcloud_load_balancer/tasks/test.yml
Original file line number Diff line number Diff line change
@@ -1,247 +1,132 @@
# Copyright: (c) 2020, 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
- name: Test missing required parameters
hetzner.hcloud.hcloud_load_balancer:
name: "{{ hcloud_load_balancer_name }}"
state: absent
register: result
- name: verify setup
assert:
that:
- result is success
- name: test missing required parameters on create Load Balancer
hetzner.hcloud.hcloud_load_balancer:
name: "{{ hcloud_load_balancer_name }}"
register: result
state: present
ignore_errors: true
- name: verify fail test missing required parameters on create Load Balancer
assert:
register: result
- name: Verify missing required parameters
ansible.builtin.assert:
that:
- result is failed
- 'result.msg == "missing required arguments: load_balancer_type"'

- name: test create Load Balancer with check mode
- name: Test create with check mode
hetzner.hcloud.hcloud_load_balancer:
name: "{{ hcloud_load_balancer_name }}"
load_balancer_type: lb11
network_zone: eu-central
state: present
register: result
check_mode: true
- name: test create Load Balancer with check mode
assert:
register: result
- name: Verify create with check mode
ansible.builtin.assert:
that:
- result is changed

- name: test create Load Balancer
- name: Test create
hetzner.hcloud.hcloud_load_balancer:
name: "{{ hcloud_load_balancer_name}}"
name: "{{ hcloud_load_balancer_name }}"
load_balancer_type: lb11
network_zone: eu-central
labels:
key: value
label: value123
state: present
register: main_load_balancer
- name: verify create Load Balancer
assert:
register: result
- name: Verify create
ansible.builtin.assert:
that:
- main_load_balancer is changed
- main_load_balancer.hcloud_load_balancer.name == "{{ hcloud_load_balancer_name }}"
- main_load_balancer.hcloud_load_balancer.load_balancer_type == "lb11"
- result is changed
- result.hcloud_load_balancer.name == "{{ hcloud_load_balancer_name }}"
- result.hcloud_load_balancer.load_balancer_type == "lb11"
- result.hcloud_load_balancer.labels.key == "value"
- result.hcloud_load_balancer.labels.label == "value123"
- result.hcloud_load_balancer.delete_protection == false

- name: test create Load Balancer idempotence
- name: Test create idempotency
hetzner.hcloud.hcloud_load_balancer:
name: "{{ hcloud_load_balancer_name }}"
load_balancer_type: lb11
network_zone: eu-central
state: present
register: result
- name: verify create Load Balancer idempotence
assert:
- name: Verify create idempotency
ansible.builtin.assert:
that:
- result is not changed

- name: test change Load Balancer type
- name: Test update load_balancer_type
hetzner.hcloud.hcloud_load_balancer:
name: "{{ hcloud_load_balancer_name }}"
load_balancer_type: lb21
state: present
register: result_after_test
ignore_errors: true
- name: verify change Load Balancer type
assert:
that:
- result_after_test is changed
- result_after_test.hcloud_load_balancer.load_balancer_type == "lb21"

- name: test Load Balancer without type set to be idempotent
hetzner.hcloud.hcloud_load_balancer:
name: "{{hcloud_load_balancer_name}}"
register: result_after_test
- name: verify test Load Balancer without type set to be idempotent
assert:
that:
- result_after_test is not changed
- result_after_test.hcloud_load_balancer.load_balancer_type == "lb21"

- name: test update Load Balancer protection
hetzner.hcloud.hcloud_load_balancer:
name: "{{ hcloud_load_balancer_name }}"
delete_protection: true
state: present
register: result_after_test
ignore_errors: true
- name: verify update Load Balancer protection
assert:
that:
- result_after_test is changed
- result_after_test.hcloud_load_balancer.delete_protection is sameas true

- name: test Load Balancer without protection set to be idempotent
hetzner.hcloud.hcloud_load_balancer:
name: "{{hcloud_load_balancer_name}}"
register: result_after_test
- name: verify test Load Balancer without protection set to be idempotent
assert:
that:
- result_after_test is not changed
- result_after_test.hcloud_load_balancer.delete_protection is sameas true

- name: test delete Load Balancer fails if it is protected
hetzner.hcloud.hcloud_load_balancer:
name: "{{hcloud_load_balancer_name}}"
state: absent
ignore_errors: true
register: result
- name: verify delete Load Balancer fails if it is protected
assert:
that:
- result is failed
- 'result.msg == "load balancer deletion is protected"'

- name: test remove Load Balancer protection
hetzner.hcloud.hcloud_load_balancer:
name: "{{ hcloud_load_balancer_name }}"
delete_protection: false
state: present
register: result_after_test
ignore_errors: true
- name: verify remove Load Balancer protection
assert:
- name: Verify update load_balancer_type
ansible.builtin.assert:
that:
- result_after_test is changed
- result_after_test.hcloud_load_balancer.delete_protection is sameas false
- result is changed
- result.hcloud_load_balancer.load_balancer_type == "lb21"

- name: absent Load Balancer
- name: Test update labels
hetzner.hcloud.hcloud_load_balancer:
name: "{{ hcloud_load_balancer_name }}"
state: absent
register: result
- name: verify absent Load Balancer
assert:
that:
- result is success

- name: test create Load Balancer with labels
hetzner.hcloud.hcloud_load_balancer:
name: "{{ hcloud_load_balancer_name}}"
load_balancer_type: lb11
network_zone: eu-central
labels:
key: value
mylabel: "val123"
key: changed
label: changed123
state: present
register: main_load_balancer
- name: verify create Load Balancer with labels
assert:
that:
- main_load_balancer is changed
- main_load_balancer.hcloud_load_balancer.labels.key == "value"
- main_load_balancer.hcloud_load_balancer.labels.mylabel == "val123"

- name: test update Load Balancer with labels
hetzner.hcloud.hcloud_load_balancer:
name: "{{ hcloud_load_balancer_name}}"
load_balancer_type: lb11
network_zone: eu-central
labels:
key: other
mylabel: "val123"
state: present
register: main_load_balancer
- name: verify update Load Balancer with labels
assert:
that:
- main_load_balancer is changed
- main_load_balancer.hcloud_load_balancer.labels.key == "other"
- main_load_balancer.hcloud_load_balancer.labels.mylabel == "val123"

- name: test update Load Balancer with labels in other order
hetzner.hcloud.hcloud_load_balancer:
name: "{{ hcloud_load_balancer_name}}"
load_balancer_type: lb11
network_zone: eu-central
labels:
mylabel: "val123"
key: other
state: present
register: main_load_balancer
- name: verify update Load Balancer with labels in other order
assert:
that:
- main_load_balancer is not changed

- name: cleanup with labels
hetzner.hcloud.hcloud_load_balancer:
name: "{{ hcloud_load_balancer_name }}"
state: absent
register: result
- name: verify cleanup
assert:
- name: Verify update load_balancer_type
ansible.builtin.assert:
that:
- result is success
- result is changed
- result.hcloud_load_balancer.labels.key == "changed"
- result.hcloud_load_balancer.labels.label == "changed123"

- name: test create Load Balancer with delete protection
- name: Test update delete_protection
hetzner.hcloud.hcloud_load_balancer:
name: "{{ hcloud_load_balancer_name }}"
load_balancer_type: lb11
network_zone: eu-central
delete_protection: true
register: main_load_balancer
- name: verify create Load Balancer with delete protection
assert:
state: present
register: result
- name: Verify update load_balancer_type
ansible.builtin.assert:
that:
- main_load_balancer is changed
- main_load_balancer.hcloud_load_balancer.delete_protection is sameas true
- result is changed
- result.hcloud_load_balancer.delete_protection == true

- name: test delete Load Balancer fails if it is protected
- name: Test delete with protection
hetzner.hcloud.hcloud_load_balancer:
name: "{{ hcloud_load_balancer_name }}"
state: "absent"
state: absent
register: result
ignore_errors: true
- name: verify test delete Load Balancer
assert:
- name: Verify delete with protection
ansible.builtin.assert:
that:
- result is failed
- 'result.msg == "load balancer deletion is protected"'

- name: test update Load Balancer delete protection
- name: Test update delete_protection
hetzner.hcloud.hcloud_load_balancer:
name: "{{ hcloud_load_balancer_name }}"
delete_protection: false
register: main_load_balancer
- name: verify update Load Balancer delete protection
assert:
state: present
register: result
- name: Verify update delete_protection
ansible.builtin.assert:
that:
- main_load_balancer is changed
- main_load_balancer.hcloud_load_balancer.delete_protection is sameas false
- result is changed
- result.hcloud_load_balancer.delete_protection == false

- name: test delete Load Balancer
- name: Test delete
hetzner.hcloud.hcloud_load_balancer:
name: "{{ hcloud_load_balancer_name }}"
state: "absent"
state: absent
register: result
- name: verify test delete Load Balancer
assert:
- name: Verify delete
ansible.builtin.assert:
that:
- result is changed

0 comments on commit 10a3e4f

Please sign in to comment.