forked from ansible-collections/hetzner.hcloud
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: improve
load_balancer_target
integration using new framework (a…
…nsible-collections#547) ##### SUMMARY Use the new testing framework for the load_balancer_target integration tests. Depends on ansible-collections#546
- Loading branch information
Showing
4 changed files
with
148 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
tests/integration/targets/load_balancer_target/tasks/cleanup.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
18
tests/integration/targets/load_balancer_target/tasks/prepare.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
220
tests/integration/targets/load_balancer_target/tasks/test.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |