diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-05 16:18:34 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-05 16:18:34 +0000 |
commit | 3667197efb7b18ec842efd504785965911f8ac4b (patch) | |
tree | 0b986a4bc6879d080b100666a97cdabbc9ca1f28 /ansible_collections/hetzner/hcloud/tests | |
parent | Adding upstream version 9.5.1+dfsg. (diff) | |
download | ansible-3667197efb7b18ec842efd504785965911f8ac4b.tar.xz ansible-3667197efb7b18ec842efd504785965911f8ac4b.zip |
Adding upstream version 10.0.0+dfsg.upstream/10.0.0+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ansible_collections/hetzner/hcloud/tests')
96 files changed, 602 insertions, 672 deletions
diff --git a/ansible_collections/hetzner/hcloud/tests/integration/cloud-config-hcloud.ini.in b/ansible_collections/hetzner/hcloud/tests/integration/cloud-config-hcloud.ini.in new file mode 100644 index 000000000..06cd2c4b8 --- /dev/null +++ b/ansible_collections/hetzner/hcloud/tests/integration/cloud-config-hcloud.ini.in @@ -0,0 +1,2 @@ +[default] +hcloud_api_token=$HCLOUD_TOKEN diff --git a/ansible_collections/hetzner/hcloud/tests/integration/common/defaults/main/common.yml b/ansible_collections/hetzner/hcloud/tests/integration/common/defaults/main/common.yml index e45380565..2b6549ec6 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/common/defaults/main/common.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/common/defaults/main/common.yml @@ -5,5 +5,5 @@ hcloud_prefix: "tests" # Used to namespace resources created by concurrent test pipelines/targets hcloud_run_ns: "{{ hcloud_prefix | md5 }}" -hcloud_role_ns: "{{ role_name | split('_') | map('first') | join() }}" +hcloud_role_ns: "{{ role_name | split('_') | map('batch', 2) | map('first') | flatten() | join() }}" hcloud_ns: "ansible-{{ hcloud_run_ns }}-{{ hcloud_role_ns }}" diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/certificate/aliases b/ansible_collections/hetzner/hcloud/tests/integration/targets/certificate/aliases index 0e887600e..18b11115e 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/certificate/aliases +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/certificate/aliases @@ -1,2 +1,3 @@ cloud/hcloud +gather_facts/no azp/group2 diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/certificate/defaults/main/common.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/certificate/defaults/main/common.yml index e316b233c..159bb2088 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/certificate/defaults/main/common.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/certificate/defaults/main/common.yml @@ -8,5 +8,5 @@ hcloud_prefix: "tests" # Used to namespace resources created by concurrent test pipelines/targets hcloud_run_ns: "{{ hcloud_prefix | md5 }}" -hcloud_role_ns: "{{ role_name | split('_') | map('first') | join() }}" +hcloud_role_ns: "{{ role_name | split('_') | map('batch', 2) | map('first') | flatten() | join() }}" hcloud_ns: "ansible-{{ hcloud_run_ns }}-{{ hcloud_role_ns }}" diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/certificate_info/aliases b/ansible_collections/hetzner/hcloud/tests/integration/targets/certificate_info/aliases index 0e887600e..18b11115e 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/certificate_info/aliases +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/certificate_info/aliases @@ -1,2 +1,3 @@ cloud/hcloud +gather_facts/no azp/group2 diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/certificate_info/defaults/main/common.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/certificate_info/defaults/main/common.yml index e316b233c..159bb2088 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/certificate_info/defaults/main/common.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/certificate_info/defaults/main/common.yml @@ -8,5 +8,5 @@ hcloud_prefix: "tests" # Used to namespace resources created by concurrent test pipelines/targets hcloud_run_ns: "{{ hcloud_prefix | md5 }}" -hcloud_role_ns: "{{ role_name | split('_') | map('first') | join() }}" +hcloud_role_ns: "{{ role_name | split('_') | map('batch', 2) | map('first') | flatten() | join() }}" hcloud_ns: "ansible-{{ hcloud_run_ns }}-{{ hcloud_role_ns }}" diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/datacenter_info/aliases b/ansible_collections/hetzner/hcloud/tests/integration/targets/datacenter_info/aliases index 0e887600e..18b11115e 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/datacenter_info/aliases +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/datacenter_info/aliases @@ -1,2 +1,3 @@ cloud/hcloud +gather_facts/no azp/group2 diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/datacenter_info/defaults/main/common.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/datacenter_info/defaults/main/common.yml index e316b233c..159bb2088 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/datacenter_info/defaults/main/common.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/datacenter_info/defaults/main/common.yml @@ -8,5 +8,5 @@ hcloud_prefix: "tests" # Used to namespace resources created by concurrent test pipelines/targets hcloud_run_ns: "{{ hcloud_prefix | md5 }}" -hcloud_role_ns: "{{ role_name | split('_') | map('first') | join() }}" +hcloud_role_ns: "{{ role_name | split('_') | map('batch', 2) | map('first') | flatten() | join() }}" hcloud_ns: "ansible-{{ hcloud_run_ns }}-{{ hcloud_role_ns }}" diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/firewall/aliases b/ansible_collections/hetzner/hcloud/tests/integration/targets/firewall/aliases index 0e887600e..18b11115e 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/firewall/aliases +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/firewall/aliases @@ -1,2 +1,3 @@ cloud/hcloud +gather_facts/no azp/group2 diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/firewall/defaults/main/common.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/firewall/defaults/main/common.yml index e316b233c..159bb2088 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/firewall/defaults/main/common.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/firewall/defaults/main/common.yml @@ -8,5 +8,5 @@ hcloud_prefix: "tests" # Used to namespace resources created by concurrent test pipelines/targets hcloud_run_ns: "{{ hcloud_prefix | md5 }}" -hcloud_role_ns: "{{ role_name | split('_') | map('first') | join() }}" +hcloud_role_ns: "{{ role_name | split('_') | map('batch', 2) | map('first') | flatten() | join() }}" hcloud_ns: "ansible-{{ hcloud_run_ns }}-{{ hcloud_role_ns }}" diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/firewall/tasks/cleanup.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/firewall/tasks/cleanup.yml index 37fbd3413..fd69ed570 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/firewall/tasks/cleanup.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/firewall/tasks/cleanup.yml @@ -1,10 +1,11 @@ --- -- name: Cleanup test_server - hetzner.hcloud.server: - name: "{{ hcloud_server_name }}" - state: absent - - name: Cleanup test_firewall hetzner.hcloud.firewall: name: "{{ hcloud_firewall_name }}" state: absent + force: true + +- name: Cleanup test_server + hetzner.hcloud.server: + name: "{{ hcloud_server_name }}" + state: absent diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/firewall/tasks/test.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/firewall/tasks/test.yml index 57059848f..8179bc61a 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/firewall/tasks/test.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/firewall/tasks/test.yml @@ -183,7 +183,7 @@ ansible.builtin.assert: that: - result is failed - - '"is still in use" in result.msg' + - result.failure.code == "resource_in_use" - name: Test delete with force hetzner.hcloud.firewall: diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/firewall_info/aliases b/ansible_collections/hetzner/hcloud/tests/integration/targets/firewall_info/aliases index 55ec821a4..18b11115e 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/firewall_info/aliases +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/firewall_info/aliases @@ -1,2 +1,3 @@ cloud/hcloud -shippable/hcloud/group2 +gather_facts/no +azp/group2 diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/firewall_info/defaults/main/common.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/firewall_info/defaults/main/common.yml index e316b233c..159bb2088 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/firewall_info/defaults/main/common.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/firewall_info/defaults/main/common.yml @@ -8,5 +8,5 @@ hcloud_prefix: "tests" # Used to namespace resources created by concurrent test pipelines/targets hcloud_run_ns: "{{ hcloud_prefix | md5 }}" -hcloud_role_ns: "{{ role_name | split('_') | map('first') | join() }}" +hcloud_role_ns: "{{ role_name | split('_') | map('batch', 2) | map('first') | flatten() | join() }}" hcloud_ns: "ansible-{{ hcloud_run_ns }}-{{ hcloud_role_ns }}" diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/firewall_info/tasks/cleanup.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/firewall_info/tasks/cleanup.yml index 37fbd3413..fd69ed570 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/firewall_info/tasks/cleanup.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/firewall_info/tasks/cleanup.yml @@ -1,10 +1,11 @@ --- -- name: Cleanup test_server - hetzner.hcloud.server: - name: "{{ hcloud_server_name }}" - state: absent - - name: Cleanup test_firewall hetzner.hcloud.firewall: name: "{{ hcloud_firewall_name }}" state: absent + force: true + +- name: Cleanup test_server + hetzner.hcloud.server: + name: "{{ hcloud_server_name }}" + state: absent diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/firewall_resource/aliases b/ansible_collections/hetzner/hcloud/tests/integration/targets/firewall_resource/aliases index 0e887600e..d9a549fdd 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/firewall_resource/aliases +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/firewall_resource/aliases @@ -1,2 +1,3 @@ cloud/hcloud -azp/group2 +gather_facts/no +azp/group1 diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/firewall_resource/defaults/main/common.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/firewall_resource/defaults/main/common.yml index e316b233c..159bb2088 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/firewall_resource/defaults/main/common.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/firewall_resource/defaults/main/common.yml @@ -8,5 +8,5 @@ hcloud_prefix: "tests" # Used to namespace resources created by concurrent test pipelines/targets hcloud_run_ns: "{{ hcloud_prefix | md5 }}" -hcloud_role_ns: "{{ role_name | split('_') | map('first') | join() }}" +hcloud_role_ns: "{{ role_name | split('_') | map('batch', 2) | map('first') | flatten() | join() }}" hcloud_ns: "ansible-{{ hcloud_run_ns }}-{{ hcloud_role_ns }}" diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/firewall_resource/tasks/cleanup.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/firewall_resource/tasks/cleanup.yml index 37fbd3413..fd69ed570 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/firewall_resource/tasks/cleanup.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/firewall_resource/tasks/cleanup.yml @@ -1,10 +1,11 @@ --- -- name: Cleanup test_server - hetzner.hcloud.server: - name: "{{ hcloud_server_name }}" - state: absent - - name: Cleanup test_firewall hetzner.hcloud.firewall: name: "{{ hcloud_firewall_name }}" state: absent + force: true + +- name: Cleanup test_server + hetzner.hcloud.server: + name: "{{ hcloud_server_name }}" + state: absent diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/floating_ip/aliases b/ansible_collections/hetzner/hcloud/tests/integration/targets/floating_ip/aliases index a6a90a6bf..c96df02ff 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/floating_ip/aliases +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/floating_ip/aliases @@ -1,2 +1,3 @@ cloud/hcloud +gather_facts/no azp/group3 diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/floating_ip/defaults/main/common.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/floating_ip/defaults/main/common.yml index e316b233c..159bb2088 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/floating_ip/defaults/main/common.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/floating_ip/defaults/main/common.yml @@ -8,5 +8,5 @@ hcloud_prefix: "tests" # Used to namespace resources created by concurrent test pipelines/targets hcloud_run_ns: "{{ hcloud_prefix | md5 }}" -hcloud_role_ns: "{{ role_name | split('_') | map('first') | join() }}" +hcloud_role_ns: "{{ role_name | split('_') | map('batch', 2) | map('first') | flatten() | join() }}" hcloud_ns: "ansible-{{ hcloud_run_ns }}-{{ hcloud_role_ns }}" diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/floating_ip/tasks/test.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/floating_ip/tasks/test.yml index fba06e308..23f29b229 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/floating_ip/tasks/test.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/floating_ip/tasks/test.yml @@ -21,7 +21,7 @@ name: "{{ hcloud_server_name }}" server_type: cx11 image: ubuntu-22.04 - state: started + state: stopped location: "fsn1" register: main_server - name: verify setup server @@ -34,7 +34,7 @@ name: "{{ hcloud_server_name }}2" server_type: cx11 image: ubuntu-22.04 - state: started + state: stopped register: main_server2 - name: verify setup another server assert: @@ -101,6 +101,7 @@ assert: that: - result is failed + - result.failure.code == "invalid_input" - result.msg == "invalid input in fields 'server', 'home_location'" - name: test create Floating IP with check mode @@ -371,7 +372,8 @@ assert: that: - result is failed - - 'result.msg == "Floating IP deletion is protected"' + - result.failure.code == "protected" + - result.msg == "Floating IP deletion is protected" - name: test update Floating IP delete protection hetzner.hcloud.floating_ip: @@ -459,7 +461,8 @@ assert: that: - result is failed - - 'result.msg == "Floating IP deletion is protected"' + - result.failure.code == "protected" + - result.msg == "Floating IP deletion is protected" - name: test update Floating IP delete protection hetzner.hcloud.floating_ip: diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/floating_ip_info/aliases b/ansible_collections/hetzner/hcloud/tests/integration/targets/floating_ip_info/aliases index a6a90a6bf..c96df02ff 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/floating_ip_info/aliases +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/floating_ip_info/aliases @@ -1,2 +1,3 @@ cloud/hcloud +gather_facts/no azp/group3 diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/floating_ip_info/defaults/main/common.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/floating_ip_info/defaults/main/common.yml index e316b233c..159bb2088 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/floating_ip_info/defaults/main/common.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/floating_ip_info/defaults/main/common.yml @@ -8,5 +8,5 @@ hcloud_prefix: "tests" # Used to namespace resources created by concurrent test pipelines/targets hcloud_run_ns: "{{ hcloud_prefix | md5 }}" -hcloud_role_ns: "{{ role_name | split('_') | map('first') | join() }}" +hcloud_role_ns: "{{ role_name | split('_') | map('batch', 2) | map('first') | flatten() | join() }}" hcloud_ns: "ansible-{{ hcloud_run_ns }}-{{ hcloud_role_ns }}" diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/image_info/aliases b/ansible_collections/hetzner/hcloud/tests/integration/targets/image_info/aliases index 0e887600e..18b11115e 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/image_info/aliases +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/image_info/aliases @@ -1,2 +1,3 @@ cloud/hcloud +gather_facts/no azp/group2 diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/image_info/defaults/main/common.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/image_info/defaults/main/common.yml index e316b233c..159bb2088 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/image_info/defaults/main/common.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/image_info/defaults/main/common.yml @@ -8,5 +8,5 @@ hcloud_prefix: "tests" # Used to namespace resources created by concurrent test pipelines/targets hcloud_run_ns: "{{ hcloud_prefix | md5 }}" -hcloud_role_ns: "{{ role_name | split('_') | map('first') | join() }}" +hcloud_role_ns: "{{ role_name | split('_') | map('batch', 2) | map('first') | flatten() | join() }}" hcloud_ns: "ansible-{{ hcloud_run_ns }}-{{ hcloud_role_ns }}" diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/iso_info/aliases b/ansible_collections/hetzner/hcloud/tests/integration/targets/iso_info/aliases index a6a90a6bf..c96df02ff 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/iso_info/aliases +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/iso_info/aliases @@ -1,2 +1,3 @@ cloud/hcloud +gather_facts/no azp/group3 diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/iso_info/defaults/main/common.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/iso_info/defaults/main/common.yml index e316b233c..159bb2088 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/iso_info/defaults/main/common.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/iso_info/defaults/main/common.yml @@ -8,5 +8,5 @@ hcloud_prefix: "tests" # Used to namespace resources created by concurrent test pipelines/targets hcloud_run_ns: "{{ hcloud_prefix | md5 }}" -hcloud_role_ns: "{{ role_name | split('_') | map('first') | join() }}" +hcloud_role_ns: "{{ role_name | split('_') | map('batch', 2) | map('first') | flatten() | join() }}" hcloud_ns: "ansible-{{ hcloud_run_ns }}-{{ hcloud_role_ns }}" diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer/aliases b/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer/aliases index 62828d1e9..d9a549fdd 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer/aliases +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer/aliases @@ -1,2 +1,3 @@ cloud/hcloud +gather_facts/no azp/group1 diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer/defaults/main/common.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer/defaults/main/common.yml index e316b233c..159bb2088 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer/defaults/main/common.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer/defaults/main/common.yml @@ -8,5 +8,5 @@ hcloud_prefix: "tests" # Used to namespace resources created by concurrent test pipelines/targets hcloud_run_ns: "{{ hcloud_prefix | md5 }}" -hcloud_role_ns: "{{ role_name | split('_') | map('first') | join() }}" +hcloud_role_ns: "{{ role_name | split('_') | map('batch', 2) | map('first') | flatten() | join() }}" hcloud_ns: "ansible-{{ hcloud_run_ns }}-{{ hcloud_role_ns }}" diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer/tasks/test.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer/tasks/test.yml index 343f15672..3b7de5b11 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer/tasks/test.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer/tasks/test.yml @@ -120,7 +120,8 @@ ansible.builtin.assert: that: - result is failed - - 'result.msg == "load balancer deletion is protected"' + - result.failure.code == "protected" + - result.msg == "load balancer deletion is protected" - name: Test update delete_protection hetzner.hcloud.load_balancer: diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_info/aliases b/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_info/aliases index 62828d1e9..d9a549fdd 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_info/aliases +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_info/aliases @@ -1,2 +1,3 @@ cloud/hcloud +gather_facts/no azp/group1 diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_info/defaults/main/common.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_info/defaults/main/common.yml index e316b233c..159bb2088 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_info/defaults/main/common.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_info/defaults/main/common.yml @@ -8,5 +8,5 @@ hcloud_prefix: "tests" # Used to namespace resources created by concurrent test pipelines/targets hcloud_run_ns: "{{ hcloud_prefix | md5 }}" -hcloud_role_ns: "{{ role_name | split('_') | map('first') | join() }}" +hcloud_role_ns: "{{ role_name | split('_') | map('batch', 2) | map('first') | flatten() | join() }}" hcloud_ns: "ansible-{{ hcloud_run_ns }}-{{ hcloud_role_ns }}" diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_info/tasks/prepare.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_info/tasks/prepare.yml index bfad755df..653417e18 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_info/tasks/prepare.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_info/tasks/prepare.yml @@ -4,7 +4,7 @@ name: "{{ hcloud_server_name }}" server_type: cx11 image: ubuntu-22.04 - state: started + state: stopped register: test_server - name: Create test_load_balancer diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_network/aliases b/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_network/aliases index 62828d1e9..d9a549fdd 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_network/aliases +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_network/aliases @@ -1,2 +1,3 @@ cloud/hcloud +gather_facts/no azp/group1 diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_network/defaults/main/common.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_network/defaults/main/common.yml index e316b233c..159bb2088 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_network/defaults/main/common.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_network/defaults/main/common.yml @@ -8,5 +8,5 @@ hcloud_prefix: "tests" # Used to namespace resources created by concurrent test pipelines/targets hcloud_run_ns: "{{ hcloud_prefix | md5 }}" -hcloud_role_ns: "{{ role_name | split('_') | map('first') | join() }}" +hcloud_role_ns: "{{ role_name | split('_') | map('batch', 2) | map('first') | flatten() | join() }}" hcloud_ns: "ansible-{{ hcloud_run_ns }}-{{ hcloud_role_ns }}" diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_service/aliases b/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_service/aliases index 62828d1e9..d9a549fdd 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_service/aliases +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_service/aliases @@ -1,2 +1,3 @@ cloud/hcloud +gather_facts/no azp/group1 diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_service/defaults/main/common.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_service/defaults/main/common.yml index e316b233c..159bb2088 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_service/defaults/main/common.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_service/defaults/main/common.yml @@ -8,5 +8,5 @@ hcloud_prefix: "tests" # Used to namespace resources created by concurrent test pipelines/targets hcloud_run_ns: "{{ hcloud_prefix | md5 }}" -hcloud_role_ns: "{{ role_name | split('_') | map('first') | join() }}" +hcloud_role_ns: "{{ role_name | split('_') | map('batch', 2) | map('first') | flatten() | join() }}" hcloud_ns: "ansible-{{ hcloud_run_ns }}-{{ hcloud_role_ns }}" diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_target/aliases b/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_target/aliases index 62828d1e9..d9a549fdd 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_target/aliases +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_target/aliases @@ -1,2 +1,3 @@ cloud/hcloud +gather_facts/no azp/group1 diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_target/defaults/main/common.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_target/defaults/main/common.yml index e316b233c..159bb2088 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_target/defaults/main/common.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_target/defaults/main/common.yml @@ -8,5 +8,5 @@ hcloud_prefix: "tests" # Used to namespace resources created by concurrent test pipelines/targets hcloud_run_ns: "{{ hcloud_prefix | md5 }}" -hcloud_role_ns: "{{ role_name | split('_') | map('first') | join() }}" +hcloud_role_ns: "{{ role_name | split('_') | map('batch', 2) | map('first') | flatten() | join() }}" hcloud_ns: "ansible-{{ hcloud_run_ns }}-{{ hcloud_role_ns }}" diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_target/tasks/test.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_target/tasks/test.yml index 19fd0e9af..a392f4f3d 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_target/tasks/test.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_target/tasks/test.yml @@ -6,7 +6,7 @@ name: "{{hcloud_server_name}}" server_type: cx11 image: ubuntu-22.04 - state: started + state: stopped location: "fsn1" register: server - name: verify setup server diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_type_info/aliases b/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_type_info/aliases index 0e887600e..18b11115e 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_type_info/aliases +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_type_info/aliases @@ -1,2 +1,3 @@ cloud/hcloud +gather_facts/no azp/group2 diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_type_info/defaults/main/common.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_type_info/defaults/main/common.yml index e316b233c..159bb2088 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_type_info/defaults/main/common.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/load_balancer_type_info/defaults/main/common.yml @@ -8,5 +8,5 @@ hcloud_prefix: "tests" # Used to namespace resources created by concurrent test pipelines/targets hcloud_run_ns: "{{ hcloud_prefix | md5 }}" -hcloud_role_ns: "{{ role_name | split('_') | map('first') | join() }}" +hcloud_role_ns: "{{ role_name | split('_') | map('batch', 2) | map('first') | flatten() | join() }}" hcloud_ns: "ansible-{{ hcloud_run_ns }}-{{ hcloud_role_ns }}" diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/location_info/aliases b/ansible_collections/hetzner/hcloud/tests/integration/targets/location_info/aliases index a6a90a6bf..c96df02ff 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/location_info/aliases +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/location_info/aliases @@ -1,2 +1,3 @@ cloud/hcloud +gather_facts/no azp/group3 diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/location_info/defaults/main/common.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/location_info/defaults/main/common.yml index e316b233c..159bb2088 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/location_info/defaults/main/common.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/location_info/defaults/main/common.yml @@ -8,5 +8,5 @@ hcloud_prefix: "tests" # Used to namespace resources created by concurrent test pipelines/targets hcloud_run_ns: "{{ hcloud_prefix | md5 }}" -hcloud_role_ns: "{{ role_name | split('_') | map('first') | join() }}" +hcloud_role_ns: "{{ role_name | split('_') | map('batch', 2) | map('first') | flatten() | join() }}" hcloud_ns: "ansible-{{ hcloud_run_ns }}-{{ hcloud_role_ns }}" diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/network/aliases b/ansible_collections/hetzner/hcloud/tests/integration/targets/network/aliases index f150235ee..d9a549fdd 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/network/aliases +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/network/aliases @@ -1,3 +1,3 @@ cloud/hcloud +gather_facts/no azp/group1 -disabled diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/network/defaults/main/common.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/network/defaults/main/common.yml index e316b233c..159bb2088 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/network/defaults/main/common.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/network/defaults/main/common.yml @@ -8,5 +8,5 @@ hcloud_prefix: "tests" # Used to namespace resources created by concurrent test pipelines/targets hcloud_run_ns: "{{ hcloud_prefix | md5 }}" -hcloud_role_ns: "{{ role_name | split('_') | map('first') | join() }}" +hcloud_role_ns: "{{ role_name | split('_') | map('batch', 2) | map('first') | flatten() | join() }}" hcloud_ns: "ansible-{{ hcloud_run_ns }}-{{ hcloud_role_ns }}" diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/network/defaults/main/main.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/network/defaults/main/main.yml index a8320602c..a01c6d60c 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/network/defaults/main/main.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/network/defaults/main/main.yml @@ -2,4 +2,3 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) --- hcloud_network_name: "{{ hcloud_ns }}" -hcloud_network_name_with_vswitch: "{{ hcloud_ns }}-vswitch" diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/network/tasks/cleanup.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/network/tasks/cleanup.yml new file mode 100644 index 000000000..989d01b80 --- /dev/null +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/network/tasks/cleanup.yml @@ -0,0 +1,5 @@ +--- +- name: Cleanup test_network + hetzner.hcloud.network: + name: "{{ hcloud_network_name }}" + state: absent diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/network/tasks/test.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/network/tasks/test.yml index b4f3de284..b814ceb15 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/network/tasks/test.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/network/tasks/test.yml @@ -1,268 +1,186 @@ # 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) --- -- name: setup ensure network is absent +- name: Test missing required parameters hetzner.hcloud.network: - name: "{{ item }}" - state: absent - with_items: - - "{{ hcloud_network_name }}" - - "{{ hcloud_network_name_with_vswitch }}" - -- name: test missing ip_range parameter on create Network - hetzner.hcloud.network: - name: "{{hcloud_network_name}}" - register: result + name: "{{ hcloud_network_name }}" + state: present ignore_errors: true -- name: verify fail missing ip_range parameter on create Network result - assert: + register: result +- name: Verify missing required parameters + ansible.builtin.assert: that: - result is failed - 'result.msg == "missing required arguments: ip_range"' -- name: test create Network with check mode +- name: Test create with check mode hetzner.hcloud.network: - name: "{{hcloud_network_name}}" + name: "{{ hcloud_network_name }}" ip_range: "10.0.0.0/16" - register: result + labels: + key: value check_mode: true -- name: verify create Network with check mode result - assert: + register: result +- name: Verify create with check mode + ansible.builtin.assert: that: - result is changed -- name: test create Network - hetzner.hcloud.network: - name: "{{hcloud_network_name}}" - ip_range: "10.0.0.0/16" - register: network -- name: verify test create Network result - assert: - that: - - network is changed - - network.hcloud_network.name == hcloud_network_name - - network.hcloud_network.ip_range == "10.0.0.0/16" - -- name: test create Network idempotence - hetzner.hcloud.network: - name: "{{hcloud_network_name}}" - ip_range: "10.0.0.0/16" - register: network -- name: verify test create network - assert: - that: - - network is not changed - -- name: test create Network with expose_routes_to_vswitch +- name: Test create hetzner.hcloud.network: - name: "{{hcloud_network_name_with_vswitch}}" + name: "{{ hcloud_network_name }}" ip_range: "10.0.0.0/16" - expose_routes_to_vswitch: true - register: network -- name: verify test create Network with vSwitch result - assert: - that: - - network is changed - - network.hcloud_network.name == hcloud_network_name_with_vswitch - - network.hcloud_network.ip_range == "10.0.0.0/16" - - network.hcloud_network.expose_routes_to_vswitch is true - -- name: test create Network with expose_routes_to_vswitch idempotence - hetzner.hcloud.network: - name: "{{hcloud_network_name_with_vswitch}}" - ip_range: "10.0.0.0/16" - expose_routes_to_vswitch: true - register: network -- name: verify test create network idempotency - assert: - that: - - network is not changed - -- name: test update Network label - hetzner.hcloud.network: - name: "{{hcloud_network_name}}" labels: key: value - register: network -- name: verify test update Network label - assert: + register: result +- name: Verify create + ansible.builtin.assert: that: - - network is changed - - network.hcloud_network.labels.key == "value" + - result is changed + - result.hcloud_network.name == hcloud_network_name + - result.hcloud_network.ip_range == "10.0.0.0/16" + - result.hcloud_network.labels.key == "value" + - result.hcloud_network.expose_routes_to_vswitch == false + - result.hcloud_network.delete_protection == false -- name: test update Network label idempotency +- name: Test create idempotency hetzner.hcloud.network: - name: "{{hcloud_network_name}}" + name: "{{ hcloud_network_name }}" + ip_range: "10.0.0.0/16" labels: key: value - register: network -- name: verify test update Network label idempotency - assert: - that: - - network is not changed - -- name: test update Network ip range - hetzner.hcloud.network: - name: "{{hcloud_network_name}}" - ip_range: "10.0.0.0/8" - register: network -- name: verify test update Network ip range - assert: - that: - - network is changed - - network.hcloud_network.ip_range == "10.0.0.0/8" - -- name: test update Network ip range idempotency - hetzner.hcloud.network: - name: "{{hcloud_network_name}}" - ip_range: "10.0.0.0/8" - register: network -- name: verify test update Network ip range idempotency - assert: - that: - - network is not changed - -- name: test update Network expose_routes_to_vswitch - hetzner.hcloud.network: - name: "{{hcloud_network_name_with_vswitch}}" - expose_routes_to_vswitch: false - register: network -- name: verify test update Network expose_routes_to_vswitch - assert: - that: - - network is changed - - network.hcloud_network.expose_routes_to_vswitch is false - -- name: test update Network expose_routes_to_vswitch idempotency - hetzner.hcloud.network: - name: "{{hcloud_network_name_with_vswitch}}" - expose_routes_to_vswitch: false - register: network -- name: verify test update Network expose_routes_to_vswitch idempotency - assert: + register: result +- name: Verify create idempotency + ansible.builtin.assert: that: - - network is not changed + - result is not changed -- name: test update Network delete protection +- name: Test update hetzner.hcloud.network: - name: "{{hcloud_network_name}}" + name: "{{ hcloud_network_name }}" ip_range: "10.0.0.0/8" + labels: + key: changed + foo: bar + expose_routes_to_vswitch: true delete_protection: true - register: network -- name: verify test update Network delete protection - assert: + register: result +- name: Verify update + ansible.builtin.assert: that: - - network is changed - - network.hcloud_network.delete_protection is sameas true + - result is changed + - result.hcloud_network.ip_range == "10.0.0.0/8" + - result.hcloud_network.labels.key == "changed" + - result.hcloud_network.labels.foo == "bar" + - result.hcloud_network.expose_routes_to_vswitch == true + - result.hcloud_network.delete_protection == true -- name: test update Network delete protection idempotency +- name: Test update idempotency hetzner.hcloud.network: - name: "{{hcloud_network_name}}" + name: "{{ hcloud_network_name }}" ip_range: "10.0.0.0/8" + labels: + key: changed + foo: bar delete_protection: true - register: network -- name: verify test update Network delete protection idempotency - assert: - that: - - network is not changed - - network.hcloud_network.delete_protection is sameas true - -- name: test Network without delete protection set to be idempotent - hetzner.hcloud.network: - name: "{{hcloud_network_name}}" - ip_range: "10.0.0.0/8" - register: network -- name: verify test Network without delete protection set to be idempotent - assert: + register: result +- name: Verify update idempotency + ansible.builtin.assert: that: - - network is not changed - - network.hcloud_network.delete_protection is sameas true + - result is not changed -- name: test delete Network fails if it is protected +- name: Test delete with delete protection hetzner.hcloud.network: - name: "{{hcloud_network_name}}" + name: "{{ hcloud_network_name }}" state: absent ignore_errors: true register: result -- name: verify delete Network - assert: +- name: Verify delete with delete protection + ansible.builtin.assert: that: - result is failed - - 'result.msg == "network deletion is protected"' + - result.failure.code == "protected" + - result.msg == "network deletion is protected" -- name: test update Network delete protection +- name: Test update delete protection hetzner.hcloud.network: - name: "{{hcloud_network_name}}" - ip_range: "10.0.0.0/8" + name: "{{ hcloud_network_name }}" delete_protection: false - register: network -- name: verify test update Network delete protection - assert: + register: result +- name: Verify update delete protection + ansible.builtin.assert: that: - - network is changed - - network.hcloud_network.delete_protection is sameas false + - result is changed + - result.hcloud_network.delete_protection == false -- name: test delete Network +- name: Test update name hetzner.hcloud.network: - name: "{{hcloud_network_name}}" - state: absent + id: "{{ result.hcloud_network.id }}" + name: "changed-{{ hcloud_network_name }}" register: result -- name: verify delete Network - assert: +- name: Verify update name + ansible.builtin.assert: that: - - result is success + - result is changed + - result.hcloud_network.name == "changed-" + hcloud_network_name -- name: test create Network with delete protection +- name: Test update name and labels hetzner.hcloud.network: - name: "{{hcloud_network_name}}" - ip_range: "10.0.0.0/8" - delete_protection: true - register: network -- name: verify create Network with delete protection - assert: + id: "{{ result.hcloud_network.id }}" + name: "{{ hcloud_network_name }}" + labels: + key: value + register: result +- name: Verify update name and labels + ansible.builtin.assert: that: - - network is changed - - network.hcloud_network.delete_protection is sameas true + - result is changed + - result.hcloud_network.name == hcloud_network_name + - result.hcloud_network.labels.key == "value" + - result.hcloud_network.labels.foo is not defined -- name: test delete Network fails if it is protected +- name: Test delete hetzner.hcloud.network: - name: "{{hcloud_network_name}}" + name: "{{ hcloud_network_name }}" state: absent - ignore_errors: true register: result -- name: verify delete Network - assert: +- name: Verify delete + ansible.builtin.assert: that: - - result is failed - - 'result.msg == "network deletion is protected"' + - result is changed -- name: test update Network delete protection +- name: Test create with vSwitch hetzner.hcloud.network: - name: "{{hcloud_network_name}}" - delete_protection: false - register: network -- name: verify test update Network delete protection - assert: + name: "{{ hcloud_network_name }}" + ip_range: "10.0.0.0/16" + expose_routes_to_vswitch: true + register: result +- name: Verify create with vSwitch + ansible.builtin.assert: that: - - network is changed - - network.hcloud_network.delete_protection is sameas false + - result is changed + - result.hcloud_network.name == hcloud_network_name + - result.hcloud_network.ip_range == "10.0.0.0/16" + - result.hcloud_network.expose_routes_to_vswitch == true + - result.hcloud_network.delete_protection == false -- name: test delete Network +- name: Test create with vSwitch idempotency hetzner.hcloud.network: - name: "{{hcloud_network_name}}" - state: absent + name: "{{ hcloud_network_name }}" + ip_range: "10.0.0.0/16" + expose_routes_to_vswitch: true register: result -- name: verify delete Network - assert: +- name: Verify create + ansible.builtin.assert: that: - - result is success + - result is not changed -- name: test delete Network with expose_routes_to_vswitch +- name: Test delete with vSwitch hetzner.hcloud.network: - name: "{{hcloud_network_name_with_vswitch}}" + name: "{{ hcloud_network_name }}" state: absent register: result -- name: verify delete Network with expose_routes_to_vswitch - assert: +- name: Verify delete with vSwitch + ansible.builtin.assert: that: - - result is success + - result is changed diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/network_info/aliases b/ansible_collections/hetzner/hcloud/tests/integration/targets/network_info/aliases index 62828d1e9..d9a549fdd 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/network_info/aliases +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/network_info/aliases @@ -1,2 +1,3 @@ cloud/hcloud +gather_facts/no azp/group1 diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/network_info/defaults/main/common.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/network_info/defaults/main/common.yml index e316b233c..159bb2088 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/network_info/defaults/main/common.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/network_info/defaults/main/common.yml @@ -8,5 +8,5 @@ hcloud_prefix: "tests" # Used to namespace resources created by concurrent test pipelines/targets hcloud_run_ns: "{{ hcloud_prefix | md5 }}" -hcloud_role_ns: "{{ role_name | split('_') | map('first') | join() }}" +hcloud_role_ns: "{{ role_name | split('_') | map('batch', 2) | map('first') | flatten() | join() }}" hcloud_ns: "ansible-{{ hcloud_run_ns }}-{{ hcloud_role_ns }}" diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/placement_group/aliases b/ansible_collections/hetzner/hcloud/tests/integration/targets/placement_group/aliases index 0e887600e..18b11115e 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/placement_group/aliases +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/placement_group/aliases @@ -1,2 +1,3 @@ cloud/hcloud +gather_facts/no azp/group2 diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/placement_group/defaults/main/common.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/placement_group/defaults/main/common.yml index e316b233c..159bb2088 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/placement_group/defaults/main/common.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/placement_group/defaults/main/common.yml @@ -8,5 +8,5 @@ hcloud_prefix: "tests" # Used to namespace resources created by concurrent test pipelines/targets hcloud_run_ns: "{{ hcloud_prefix | md5 }}" -hcloud_role_ns: "{{ role_name | split('_') | map('first') | join() }}" +hcloud_role_ns: "{{ role_name | split('_') | map('batch', 2) | map('first') | flatten() | join() }}" hcloud_ns: "ansible-{{ hcloud_run_ns }}-{{ hcloud_role_ns }}" diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/placement_group/tasks/test.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/placement_group/tasks/test.yml index 3694c846f..d988275d6 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/placement_group/tasks/test.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/placement_group/tasks/test.yml @@ -80,7 +80,7 @@ - name: test remove server from placement group hetzner.hcloud.server: name: "{{ hcloud_server_name }}" - placement_group: null + placement_group: "" state: present register: result - name: verify remove server from placement group diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/primary_ip/aliases b/ansible_collections/hetzner/hcloud/tests/integration/targets/primary_ip/aliases index a6a90a6bf..c96df02ff 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/primary_ip/aliases +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/primary_ip/aliases @@ -1,2 +1,3 @@ cloud/hcloud +gather_facts/no azp/group3 diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/primary_ip/defaults/main/common.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/primary_ip/defaults/main/common.yml index e316b233c..159bb2088 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/primary_ip/defaults/main/common.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/primary_ip/defaults/main/common.yml @@ -8,5 +8,5 @@ hcloud_prefix: "tests" # Used to namespace resources created by concurrent test pipelines/targets hcloud_run_ns: "{{ hcloud_prefix | md5 }}" -hcloud_role_ns: "{{ role_name | split('_') | map('first') | join() }}" +hcloud_role_ns: "{{ role_name | split('_') | map('batch', 2) | map('first') | flatten() | join() }}" hcloud_ns: "ansible-{{ hcloud_run_ns }}-{{ hcloud_role_ns }}" diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/primary_ip/tasks/cleanup.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/primary_ip/tasks/cleanup.yml new file mode 100644 index 000000000..d8c44b945 --- /dev/null +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/primary_ip/tasks/cleanup.yml @@ -0,0 +1,10 @@ +--- +- name: Cleanup test_server + hetzner.hcloud.server: + name: "{{ hcloud_server_name }}" + state: absent + +- name: Cleanup test_primary_ip + hetzner.hcloud.primary_ip: + name: "{{ hcloud_primary_ip_name }}" + state: absent diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/primary_ip/tasks/prepare.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/primary_ip/tasks/prepare.yml new file mode 100644 index 000000000..8200e97a1 --- /dev/null +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/primary_ip/tasks/prepare.yml @@ -0,0 +1,10 @@ +--- +- name: Create test_server + hetzner.hcloud.server: + name: "{{ hcloud_server_name }}" + server_type: cx11 + image: ubuntu-22.04 + state: stopped + enable_ipv4: false + enable_ipv6: false + register: test_server diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/primary_ip/tasks/test.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/primary_ip/tasks/test.yml index 4c0fd2e5f..84fd6a31f 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/primary_ip/tasks/test.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/primary_ip/tasks/test.yml @@ -1,248 +1,181 @@ # 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) --- -- name: setup ensure primary ip is absent +- name: Test missing required parameters hetzner.hcloud.primary_ip: - name: "{{ hcloud_primary_ip_name }}" - state: absent - -- name: test create Primary IP with check mode - hetzner.hcloud.primary_ip: - name: "{{ hcloud_primary_ip_name }}" - type: ipv4 - datacenter: "fsn1-dc14" - register: primaryIP - check_mode: true -- name: verify test create Primary IP with check mode - assert: - that: - - primaryIP is changed - -- name: test create Primary IP - hetzner.hcloud.primary_ip: - name: "{{ hcloud_primary_ip_name }}" - type: ipv4 - datacenter: "fsn1-dc14" - register: primaryIP -- name: verify test create Primary IP - assert: - that: - - primaryIP is changed - - primaryIP.hcloud_primary_ip.name ==hcloud_primary_ip_name - - primaryIP.hcloud_primary_ip.datacenter == "fsn1-dc14" - -- name: test create Primary IP idempotency - hetzner.hcloud.primary_ip: - name: "{{ hcloud_primary_ip_name }}" - type: ipv4 - datacenter: "fsn1-dc14" - register: primaryIP -- name: verify test create Primary IP idempotency - assert: + state: present + ignore_errors: true + register: result +- name: Verify missing required parameters + ansible.builtin.assert: that: - - primaryIP is not changed + - result is failed + - 'result.msg == "one of the following is required: id, name"' -- name: test update Primary IP +- name: Test create with check mode hetzner.hcloud.primary_ip: name: "{{ hcloud_primary_ip_name }}" - type: ipv4 - datacenter: "fsn1-dc14" + type: ipv6 + datacenter: fsn1-dc14 labels: key: value - register: primaryIP -- name: verify test update Primary IP - assert: + check_mode: true + register: result +- name: Verify create with check mode + ansible.builtin.assert: that: - - primaryIP is changed + - result is changed -- name: test update Primary IP idempotency +- name: Test create hetzner.hcloud.primary_ip: name: "{{ hcloud_primary_ip_name }}" - type: ipv4 - datacenter: "fsn1-dc14" + type: ipv6 + datacenter: fsn1-dc14 labels: key: value - register: primaryIP -- name: verify test update Primary IP idempotency - assert: + register: result +- name: Verify create + ansible.builtin.assert: that: - - primaryIP is not changed + - result is changed + - result.hcloud_primary_ip.name == hcloud_primary_ip_name + - result.hcloud_primary_ip.type == "ipv6" + - result.hcloud_primary_ip.datacenter == "fsn1-dc14" + - result.hcloud_primary_ip.assignee_type == "server" + - result.hcloud_primary_ip.assignee_id is none + - result.hcloud_primary_ip.labels.key == "value" + - result.hcloud_primary_ip.auto_delete is false + - result.hcloud_primary_ip.delete_protection is false -- name: test update Primary IP with same labels +- name: Test create idempotency hetzner.hcloud.primary_ip: name: "{{ hcloud_primary_ip_name }}" - type: ipv4 - datacenter: "fsn1-dc14" + type: ipv6 + datacenter: fsn1-dc14 labels: key: value - register: primaryIP -- name: verify test update Primary IP with same labels - assert: + register: result +- name: Verify create idempotency + ansible.builtin.assert: that: - - primaryIP is not changed + - result is not changed -- name: test update Primary IP with other labels +- name: Test update hetzner.hcloud.primary_ip: name: "{{ hcloud_primary_ip_name }}" - type: ipv4 - datacenter: "fsn1-dc14" + type: ipv6 + datacenter: fsn1-dc14 labels: key: value - other: label - register: primaryIP -- name: verify test update Primary IP with other labels - assert: + foo: bar + auto_delete: true + register: result +- name: Verify update + ansible.builtin.assert: that: - - primaryIP is changed + - result is changed + - result.hcloud_primary_ip.name == hcloud_primary_ip_name + - result.hcloud_primary_ip.type == "ipv6" + - result.hcloud_primary_ip.datacenter == "fsn1-dc14" + - result.hcloud_primary_ip.assignee_type == "server" + - result.hcloud_primary_ip.assignee_id is none + - result.hcloud_primary_ip.labels.key == "value" + - result.hcloud_primary_ip.labels.foo == "bar" + - result.hcloud_primary_ip.delete_protection is false + - result.hcloud_primary_ip.auto_delete is true -- name: test update Primary IP with other labels in different order +- name: Test update idempotency hetzner.hcloud.primary_ip: name: "{{ hcloud_primary_ip_name }}" - type: ipv4 - datacenter: "fsn1-dc14" + type: ipv6 + datacenter: fsn1-dc14 labels: - other: label key: value - register: primaryIP -- name: verify test update Primary IP with other labels in different order - assert: - that: - - primaryIP is not changed - -- name: test update Primary IP delete protection - hetzner.hcloud.primary_ip: - name: "{{ hcloud_primary_ip_name }}" - type: ipv4 - delete_protection: true - register: primaryIP -- name: verify update Primary IP delete protection - assert: + foo: bar + auto_delete: true + register: result +- name: Verify update idempotency + ansible.builtin.assert: that: - - primaryIP is changed - - primaryIP.hcloud_primary_ip.delete_protection is sameas true + - result is not changed -- name: test update Primary IP delete protection idempotency +- name: Test update delete protection hetzner.hcloud.primary_ip: name: "{{ hcloud_primary_ip_name }}" - type: ipv4 delete_protection: true - register: primaryIP -- name: verify update Primary IP delete protection idempotency - assert: - that: - - primaryIP is not changed - - primaryIP.hcloud_primary_ip.delete_protection is sameas true - -- name: test Primary IP without delete protection set to be idempotent - hetzner.hcloud.primary_ip: - name: "{{ hcloud_primary_ip_name }}" - type: ipv4 - register: primaryIP -- name: verify Primary IP without delete protection set to be idempotent - assert: + register: result +- name: Verify update delete protection + ansible.builtin.assert: that: - - primaryIP is not changed - - primaryIP.hcloud_primary_ip.delete_protection is sameas true + - result is changed + - result.hcloud_primary_ip.delete_protection is true -- name: test delete Primary IP fails if it is protected +- name: Test delete with delete protection hetzner.hcloud.primary_ip: name: "{{ hcloud_primary_ip_name }}" - state: "absent" - register: result + state: absent ignore_errors: true -- name: verify test delete primary ip - assert: + register: result +- name: Verify delete with delete protection + ansible.builtin.assert: that: - result is failed - - 'result.msg == "Primary IP deletion is protected"' + - result.failure.code == "protected" + - result.msg == "Primary IP deletion is protected" -- name: test update Primary IP delete protection +- name: Test update delete protection hetzner.hcloud.primary_ip: name: "{{ hcloud_primary_ip_name }}" - type: ipv4 delete_protection: false - register: primaryIP -- name: verify update Primary IP delete protection - assert: - that: - - primaryIP is changed - - primaryIP.hcloud_primary_ip.delete_protection is sameas false - -- name: test delete primary ip - hetzner.hcloud.primary_ip: - name: "{{ hcloud_primary_ip_name }}" - state: "absent" register: result -- name: verify test delete primary ip - assert: +- name: Verify update delete protection + ansible.builtin.assert: that: - result is changed + - result.hcloud_primary_ip.delete_protection is false -- name: test create ipv6 primary ip +- name: Test delete hetzner.hcloud.primary_ip: name: "{{ hcloud_primary_ip_name }}" - type: ipv6 - datacenter: "fsn1-dc14" - state: "present" + state: absent register: result -- name: verify test create ipv6 primary ip - assert: +- name: Verify delete + ansible.builtin.assert: that: - result is changed -- name: test delete ipv6 primary ip +- name: Test create with server hetzner.hcloud.primary_ip: name: "{{ hcloud_primary_ip_name }}" - state: "absent" + type: ipv6 + server: "{{ hcloud_server_name }}" register: result -- name: verify test delete ipv6 primary ip - assert: +- name: Verify create with server + ansible.builtin.assert: that: - result is changed + - result.hcloud_primary_ip.name == hcloud_primary_ip_name + - result.hcloud_primary_ip.type == "ipv6" + - result.hcloud_primary_ip.assignee_id == test_server.hcloud_server.id | string + - result.hcloud_primary_ip.assignee_type == "server" -- name: test create Primary IP with delete protection - hetzner.hcloud.primary_ip: - name: "{{ hcloud_primary_ip_name }}" - type: ipv4 - datacenter: fsn1-dc14 - delete_protection: true - register: primaryIP -- name: verify create Primary IP with delete protection - assert: - that: - - primaryIP is changed - - primaryIP.hcloud_primary_ip.delete_protection is sameas true - -- name: test delete Primary IP fails if it is protected +- name: Test create with server idempotency hetzner.hcloud.primary_ip: name: "{{ hcloud_primary_ip_name }}" - state: "absent" + type: ipv6 + server: "{{ hcloud_server_name }}" register: result - ignore_errors: true -- name: verify test delete primary ip - assert: +- name: Verify create with server idempotency + ansible.builtin.assert: that: - - result is failed - - 'result.msg == "Primary IP deletion is protected"' + - result is not changed -- name: test update Primary IP delete protection +- name: Test delete with server hetzner.hcloud.primary_ip: name: "{{ hcloud_primary_ip_name }}" - type: ipv4 - delete_protection: false - register: primaryIP -- name: verify update Primary IP delete protection - assert: - that: - - primaryIP is changed - - primaryIP.hcloud_primary_ip.delete_protection is sameas false - -- name: test delete primary ip - hetzner.hcloud.primary_ip: - name: "{{ hcloud_primary_ip_name }}" - state: "absent" + state: absent register: result -- name: verify test delete primary ip - assert: +- name: Verify delete with server + ansible.builtin.assert: that: - result is changed diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/primary_ip_info/aliases b/ansible_collections/hetzner/hcloud/tests/integration/targets/primary_ip_info/aliases index a6a90a6bf..c96df02ff 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/primary_ip_info/aliases +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/primary_ip_info/aliases @@ -1,2 +1,3 @@ cloud/hcloud +gather_facts/no azp/group3 diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/primary_ip_info/defaults/main/common.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/primary_ip_info/defaults/main/common.yml index e316b233c..159bb2088 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/primary_ip_info/defaults/main/common.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/primary_ip_info/defaults/main/common.yml @@ -8,5 +8,5 @@ hcloud_prefix: "tests" # Used to namespace resources created by concurrent test pipelines/targets hcloud_run_ns: "{{ hcloud_prefix | md5 }}" -hcloud_role_ns: "{{ role_name | split('_') | map('first') | join() }}" +hcloud_role_ns: "{{ role_name | split('_') | map('batch', 2) | map('first') | flatten() | join() }}" hcloud_ns: "ansible-{{ hcloud_run_ns }}-{{ hcloud_role_ns }}" diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/rdns/aliases b/ansible_collections/hetzner/hcloud/tests/integration/targets/rdns/aliases index 62828d1e9..d9a549fdd 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/rdns/aliases +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/rdns/aliases @@ -1,2 +1,3 @@ cloud/hcloud +gather_facts/no azp/group1 diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/rdns/defaults/main/common.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/rdns/defaults/main/common.yml index e316b233c..159bb2088 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/rdns/defaults/main/common.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/rdns/defaults/main/common.yml @@ -8,5 +8,5 @@ hcloud_prefix: "tests" # Used to namespace resources created by concurrent test pipelines/targets hcloud_run_ns: "{{ hcloud_prefix | md5 }}" -hcloud_role_ns: "{{ role_name | split('_') | map('first') | join() }}" +hcloud_role_ns: "{{ role_name | split('_') | map('batch', 2) | map('first') | flatten() | join() }}" hcloud_ns: "ansible-{{ hcloud_run_ns }}-{{ hcloud_role_ns }}" diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/route/aliases b/ansible_collections/hetzner/hcloud/tests/integration/targets/route/aliases index 62828d1e9..d9a549fdd 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/route/aliases +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/route/aliases @@ -1,2 +1,3 @@ cloud/hcloud +gather_facts/no azp/group1 diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/route/defaults/main/common.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/route/defaults/main/common.yml index e316b233c..159bb2088 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/route/defaults/main/common.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/route/defaults/main/common.yml @@ -8,5 +8,5 @@ hcloud_prefix: "tests" # Used to namespace resources created by concurrent test pipelines/targets hcloud_run_ns: "{{ hcloud_prefix | md5 }}" -hcloud_role_ns: "{{ role_name | split('_') | map('first') | join() }}" +hcloud_role_ns: "{{ role_name | split('_') | map('batch', 2) | map('first') | flatten() | join() }}" hcloud_ns: "ansible-{{ hcloud_run_ns }}-{{ hcloud_role_ns }}" diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/server/aliases b/ansible_collections/hetzner/hcloud/tests/integration/targets/server/aliases index a6a90a6bf..c96df02ff 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/server/aliases +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/server/aliases @@ -1,2 +1,3 @@ cloud/hcloud +gather_facts/no azp/group3 diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/server/defaults/main/common.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/server/defaults/main/common.yml index e316b233c..159bb2088 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/server/defaults/main/common.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/server/defaults/main/common.yml @@ -8,5 +8,5 @@ hcloud_prefix: "tests" # Used to namespace resources created by concurrent test pipelines/targets hcloud_run_ns: "{{ hcloud_prefix | md5 }}" -hcloud_role_ns: "{{ role_name | split('_') | map('first') | join() }}" +hcloud_role_ns: "{{ role_name | split('_') | map('batch', 2) | map('first') | flatten() | join() }}" hcloud_ns: "ansible-{{ hcloud_run_ns }}-{{ hcloud_role_ns }}" diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/server/tasks/test_basic.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/server/tasks/test_basic.yml index 1e94d67af..879e2d678 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/server/tasks/test_basic.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/server/tasks/test_basic.yml @@ -315,7 +315,8 @@ assert: that: - result is failed - - 'result.msg == "server deletion is protected"' + - result.failure.code == "protected" + - result.msg == "server deletion is protected" - name: test rebuild server fails if it is protected hetzner.hcloud.server: @@ -328,7 +329,8 @@ assert: that: - result is failed - - 'result.msg == "server rebuild is protected"' + - result.failure.code == "protected" + - result.msg == "server rebuild is protected" - name: test remove server protection hetzner.hcloud.server: @@ -585,7 +587,8 @@ assert: that: - result is failed - - 'result.msg == "server deletion is protected"' + - result.failure.code == "protected" + - result.msg == "server deletion is protected" - name: remove protection from server hetzner.hcloud.server: diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/server/tasks/test_firewalls.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/server/tasks/test_firewalls.yml index 896a6c5cf..230df46de 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/server/tasks/test_firewalls.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/server/tasks/test_firewalls.yml @@ -13,7 +13,9 @@ assert: that: - result is failed - - 'result.msg == "firewall not-existing was not found"' + - result.failure.code == "not_found" + - result.msg == "firewall not-existing was not found" + - name: setup create firewalls hetzner.hcloud.firewall: name: "{{ item }}" diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/server/tasks/test_validation.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/server/tasks/test_validation.yml index d4e0ef8b4..e051816f9 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/server/tasks/test_validation.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/server/tasks/test_validation.yml @@ -34,7 +34,8 @@ assert: that: - result is failed - - 'result.msg == "server_type not-existing-server-type was not found"' + - result.failure.code == "not_found" + - result.msg == "server_type not-existing-server-type was not found" - name: test create server with not existing image hetzner.hcloud.server: @@ -48,4 +49,5 @@ assert: that: - result is failed - - 'result.msg == "Image my-not-existing-image-20.04 was not found"' + - result.failure.code == "not_found" + - result.msg == "Image my-not-existing-image-20.04 was not found" diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/server_info/aliases b/ansible_collections/hetzner/hcloud/tests/integration/targets/server_info/aliases index 0e887600e..18b11115e 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/server_info/aliases +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/server_info/aliases @@ -1,2 +1,3 @@ cloud/hcloud +gather_facts/no azp/group2 diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/server_info/defaults/main/common.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/server_info/defaults/main/common.yml index e316b233c..159bb2088 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/server_info/defaults/main/common.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/server_info/defaults/main/common.yml @@ -8,5 +8,5 @@ hcloud_prefix: "tests" # Used to namespace resources created by concurrent test pipelines/targets hcloud_run_ns: "{{ hcloud_prefix | md5 }}" -hcloud_role_ns: "{{ role_name | split('_') | map('first') | join() }}" +hcloud_role_ns: "{{ role_name | split('_') | map('batch', 2) | map('first') | flatten() | join() }}" hcloud_ns: "ansible-{{ hcloud_run_ns }}-{{ hcloud_role_ns }}" diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/server_info/tasks/prepare.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/server_info/tasks/prepare.yml index 9e8aa2c9f..8a7a09605 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/server_info/tasks/prepare.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/server_info/tasks/prepare.yml @@ -4,7 +4,7 @@ name: "{{ hcloud_server_name }}" server_type: cx11 image: ubuntu-22.04 - state: started + state: stopped labels: key: value register: test_server diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/server_network/aliases b/ansible_collections/hetzner/hcloud/tests/integration/targets/server_network/aliases index 6e9b68657..18b11115e 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/server_network/aliases +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/server_network/aliases @@ -1,3 +1,3 @@ cloud/hcloud +gather_facts/no azp/group2 -disabled diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/server_network/defaults/main/common.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/server_network/defaults/main/common.yml index e316b233c..159bb2088 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/server_network/defaults/main/common.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/server_network/defaults/main/common.yml @@ -8,5 +8,5 @@ hcloud_prefix: "tests" # Used to namespace resources created by concurrent test pipelines/targets hcloud_run_ns: "{{ hcloud_prefix | md5 }}" -hcloud_role_ns: "{{ role_name | split('_') | map('first') | join() }}" +hcloud_role_ns: "{{ role_name | split('_') | map('batch', 2) | map('first') | flatten() | join() }}" hcloud_ns: "ansible-{{ hcloud_run_ns }}-{{ hcloud_role_ns }}" diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/server_network/tasks/cleanup.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/server_network/tasks/cleanup.yml new file mode 100644 index 000000000..af15c63bb --- /dev/null +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/server_network/tasks/cleanup.yml @@ -0,0 +1,10 @@ +--- +- name: Cleanup test_server + hetzner.hcloud.server: + name: "{{ hcloud_server_name }}" + state: absent + +- name: Cleanup test_network + hetzner.hcloud.network: + name: "{{ hcloud_network_name }}" + state: absent diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/server_network/tasks/prepare.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/server_network/tasks/prepare.yml new file mode 100644 index 000000000..b74f43f06 --- /dev/null +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/server_network/tasks/prepare.yml @@ -0,0 +1,24 @@ +--- +- name: Create test_network + hetzner.hcloud.network: + name: "{{ hcloud_network_name }}" + ip_range: 10.0.0.0/16 + labels: + key: value + register: test_network + +- name: Create test_subnetwork + hetzner.hcloud.subnetwork: + network: "{{ hcloud_network_name }}" + type: server + network_zone: eu-central + ip_range: 10.0.1.0/24 + register: test_subnetwork + +- name: Create test_server + hetzner.hcloud.server: + name: "{{ hcloud_server_name }}" + server_type: cx11 + image: ubuntu-22.04 + state: stopped + register: test_server diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/server_network/tasks/test.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/server_network/tasks/test.yml index a77f2e30a..a232ae5d5 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/server_network/tasks/test.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/server_network/tasks/test.yml @@ -1,222 +1,152 @@ # 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) --- -- name: setup network - hetzner.hcloud.network: - name: "{{ hcloud_network_name }}" - ip_range: "10.0.0.0/8" - state: present - register: network -- name: verify setup network - assert: - that: - - network is success - -- name: setup subnetwork - hetzner.hcloud.subnetwork: - network: "{{ hcloud_network_name }}" - ip_range: "10.0.0.0/16" - type: "server" - network_zone: "eu-central" - state: present - register: subnetwork -- name: verify subnetwork - assert: - that: - - subnetwork is success - -- name: setup server - hetzner.hcloud.server: - name: "{{hcloud_server_name}}" - server_type: cx11 - image: ubuntu-22.04 - state: started - location: "fsn1" - register: server -- name: verify setup server - assert: - that: - - server is success - -- name: test missing required parameters on create server network +- name: Test missing required parameters hetzner.hcloud.server_network: state: present - register: result ignore_errors: true -- name: verify fail test missing required parameters on create server network - assert: + register: result +- name: Verify missing required parameters + ansible.builtin.assert: that: - result is failed - 'result.msg == "missing required arguments: network, server"' -- name: test create server network with checkmode +- name: Test create with checkmode hetzner.hcloud.server_network: network: "{{ hcloud_network_name }}" - server: "{{hcloud_server_name}}" + server: "{{ hcloud_server_name }}" state: present - register: result check_mode: true -- name: verify test create server network with checkmode - assert: + register: result +- name: Verify create with checkmode + ansible.builtin.assert: that: - result is changed -- name: test create server network +- name: Test create hetzner.hcloud.server_network: network: "{{ hcloud_network_name }}" - server: "{{hcloud_server_name}}" + server: "{{ hcloud_server_name }}" state: present - register: serverNetwork -- name: verify create server network - assert: + register: result +- name: Verify create + ansible.builtin.assert: that: - - serverNetwork is changed - - serverNetwork.hcloud_server_network.network == hcloud_network_name - - serverNetwork.hcloud_server_network.server == hcloud_server_name + - result is changed + - result.hcloud_server_network.network == hcloud_network_name + - result.hcloud_server_network.server == hcloud_server_name -- name: test create server network idempotency +- name: Test create idempotency hetzner.hcloud.server_network: network: "{{ hcloud_network_name }}" - server: "{{hcloud_server_name}}" + server: "{{ hcloud_server_name }}" state: present - register: serverNetwork -- name: verify create server network idempotency - assert: + register: result +- name: Verify create idempotency + ansible.builtin.assert: that: - - serverNetwork is not changed + - result is not changed -- name: test absent server network +- name: Test delete hetzner.hcloud.server_network: network: "{{ hcloud_network_name }}" - server: "{{hcloud_server_name}}" + server: "{{ hcloud_server_name }}" state: absent register: result -- name: verify test absent server network - assert: +- name: Verify delete + ansible.builtin.assert: that: - result is changed -- name: test create server network with specified ip +- name: Test create with ip hetzner.hcloud.server_network: network: "{{ hcloud_network_name }}" - server: "{{hcloud_server_name}}" - ip: "10.0.0.2" + server: "{{ hcloud_server_name }}" + ip: "10.0.1.2" state: present - register: serverNetwork -- name: verify create server network with specified ip - assert: + register: result +- name: Verify create with ip + ansible.builtin.assert: that: - - serverNetwork is changed - - serverNetwork.hcloud_server_network.network == hcloud_network_name - - serverNetwork.hcloud_server_network.server == hcloud_server_name - - serverNetwork.hcloud_server_network.ip == "10.0.0.2" + - result is changed + - result.hcloud_server_network.network == hcloud_network_name + - result.hcloud_server_network.server == hcloud_server_name + - result.hcloud_server_network.ip == "10.0.1.2" -- name: cleanup create server network with specified ip +- name: Test delete with ip hetzner.hcloud.server_network: network: "{{ hcloud_network_name }}" - server: "{{hcloud_server_name}}" + server: "{{ hcloud_server_name }}" state: absent register: result -- name: verify cleanup create server network with specified ip - assert: +- name: Verify delete with ip + ansible.builtin.assert: that: - result is changed -- name: test create server network with alias ips +- name: Test create with alias ips hetzner.hcloud.server_network: network: "{{ hcloud_network_name }}" - server: "{{hcloud_server_name}}" - ip: "10.0.0.2" + server: "{{ hcloud_server_name }}" + ip: "10.0.1.2" alias_ips: - - "10.0.1.2" - - "10.0.2.3" + - "10.0.1.10" + - "10.0.1.11" state: present - register: serverNetwork -- name: verify create server network with alias ips - assert: + register: result +- name: Verify create with alias ips + ansible.builtin.assert: that: - - serverNetwork is changed - - serverNetwork.hcloud_server_network.network == hcloud_network_name - - serverNetwork.hcloud_server_network.server == hcloud_server_name - - serverNetwork.hcloud_server_network.ip == "10.0.0.2" - - 'serverNetwork.hcloud_server_network.alias_ips[0] == "10.0.2.3"' - - 'serverNetwork.hcloud_server_network.alias_ips[1] == "10.0.1.2"' + - result is changed + - result.hcloud_server_network.network == hcloud_network_name + - result.hcloud_server_network.server == hcloud_server_name + - result.hcloud_server_network.ip == "10.0.1.2" + - result.hcloud_server_network.alias_ips[0] == "10.0.1.10" + - result.hcloud_server_network.alias_ips[1] == "10.0.1.11" -- name: test update server network with alias ips +- name: Test update with alias ips hetzner.hcloud.server_network: network: "{{ hcloud_network_name }}" - server: "{{hcloud_server_name}}" - ip: "10.0.0.2" + server: "{{ hcloud_server_name }}" + ip: "10.0.1.2" alias_ips: - - "10.0.2.3" - - "10.0.3.1" + - "10.0.1.10" + - "10.0.1.20" state: present - register: serverNetwork -- name: verify create server network with alias ips - assert: + register: result +- name: Verify update with alias ips + ansible.builtin.assert: that: - - serverNetwork is changed - - serverNetwork.hcloud_server_network.network == hcloud_network_name - - serverNetwork.hcloud_server_network.server == hcloud_server_name - - serverNetwork.hcloud_server_network.ip == "10.0.0.2" - - 'serverNetwork.hcloud_server_network.alias_ips[0] == "10.0.2.3"' - - 'serverNetwork.hcloud_server_network.alias_ips[1] == "10.0.3.1"' + - result is changed + - result.hcloud_server_network.network == hcloud_network_name + - result.hcloud_server_network.server == hcloud_server_name + - result.hcloud_server_network.ip == "10.0.1.2" + - result.hcloud_server_network.alias_ips[0] == "10.0.1.10" + - result.hcloud_server_network.alias_ips[1] == "10.0.1.20" -- name: test update server network with alias ips idempotency +- name: Test update with alias ips idempotency hetzner.hcloud.server_network: network: "{{ hcloud_network_name }}" - server: "{{hcloud_server_name}}" - ip: "10.0.0.2" + server: "{{ hcloud_server_name }}" + ip: "10.0.1.2" alias_ips: - - "10.0.2.3" - - "10.0.3.1" + - "10.0.1.10" + - "10.0.1.20" state: present - register: serverNetwork -- name: verify create server network with alias ips idempotency - assert: - that: - - serverNetwork is not changed - -- name: cleanup create server network with alias ips - hetzner.hcloud.server_network: - network: "{{ hcloud_network_name }}" - server: "{{hcloud_server_name}}" - state: absent - register: result -- name: verify cleanup create server network with alias ips - assert: - that: - - result is changed - -- name: cleanup server - hetzner.hcloud.server: - name: "{{ hcloud_server_name }}" - state: absent register: result -- name: verify cleanup server - assert: +- name: Verify update with alias ips idempotency + ansible.builtin.assert: that: - - result is success + - result is not changed -- name: cleanup subnetwork - hetzner.hcloud.subnetwork: +- name: Test delete with alias ips + hetzner.hcloud.server_network: network: "{{ hcloud_network_name }}" - ip_range: "10.0.0.0/16" - type: "server" - network_zone: "eu-central" + server: "{{ hcloud_server_name }}" state: absent register: result -- name: verify cleanup subnetwork - assert: +- name: Verify delete with alias ips + ansible.builtin.assert: that: - result is changed - -- name: cleanup - hetzner.hcloud.network: - name: "{{hcloud_network_name}}" - state: absent - register: result -- name: verify cleanup - assert: - that: - - result is success diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/server_type_info/aliases b/ansible_collections/hetzner/hcloud/tests/integration/targets/server_type_info/aliases index 0e887600e..18b11115e 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/server_type_info/aliases +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/server_type_info/aliases @@ -1,2 +1,3 @@ cloud/hcloud +gather_facts/no azp/group2 diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/server_type_info/defaults/main/common.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/server_type_info/defaults/main/common.yml index e316b233c..159bb2088 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/server_type_info/defaults/main/common.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/server_type_info/defaults/main/common.yml @@ -8,5 +8,5 @@ hcloud_prefix: "tests" # Used to namespace resources created by concurrent test pipelines/targets hcloud_run_ns: "{{ hcloud_prefix | md5 }}" -hcloud_role_ns: "{{ role_name | split('_') | map('first') | join() }}" +hcloud_role_ns: "{{ role_name | split('_') | map('batch', 2) | map('first') | flatten() | join() }}" hcloud_ns: "ansible-{{ hcloud_run_ns }}-{{ hcloud_role_ns }}" diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/ssh_key/aliases b/ansible_collections/hetzner/hcloud/tests/integration/targets/ssh_key/aliases index 0e887600e..18b11115e 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/ssh_key/aliases +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/ssh_key/aliases @@ -1,2 +1,3 @@ cloud/hcloud +gather_facts/no azp/group2 diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/ssh_key/defaults/main/common.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/ssh_key/defaults/main/common.yml index e316b233c..159bb2088 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/ssh_key/defaults/main/common.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/ssh_key/defaults/main/common.yml @@ -8,5 +8,5 @@ hcloud_prefix: "tests" # Used to namespace resources created by concurrent test pipelines/targets hcloud_run_ns: "{{ hcloud_prefix | md5 }}" -hcloud_role_ns: "{{ role_name | split('_') | map('first') | join() }}" +hcloud_role_ns: "{{ role_name | split('_') | map('batch', 2) | map('first') | flatten() | join() }}" hcloud_ns: "ansible-{{ hcloud_run_ns }}-{{ hcloud_role_ns }}" diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/ssh_key/tasks/test.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/ssh_key/tasks/test.yml index 41b9c351d..e314266a4 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/ssh_key/tasks/test.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/ssh_key/tasks/test.yml @@ -133,7 +133,8 @@ assert: that: - result is failed - - 'result.msg == "SSH key with the same fingerprint already exists"' + - result.failure.code == "uniqueness_error" + - result.msg == "SSH key with the same fingerprint already exists" - name: test delete ssh key hetzner.hcloud.ssh_key: diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/ssh_key_info/aliases b/ansible_collections/hetzner/hcloud/tests/integration/targets/ssh_key_info/aliases index 0e887600e..18b11115e 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/ssh_key_info/aliases +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/ssh_key_info/aliases @@ -1,2 +1,3 @@ cloud/hcloud +gather_facts/no azp/group2 diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/ssh_key_info/defaults/main/common.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/ssh_key_info/defaults/main/common.yml index e316b233c..159bb2088 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/ssh_key_info/defaults/main/common.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/ssh_key_info/defaults/main/common.yml @@ -8,5 +8,5 @@ hcloud_prefix: "tests" # Used to namespace resources created by concurrent test pipelines/targets hcloud_run_ns: "{{ hcloud_prefix | md5 }}" -hcloud_role_ns: "{{ role_name | split('_') | map('first') | join() }}" +hcloud_role_ns: "{{ role_name | split('_') | map('batch', 2) | map('first') | flatten() | join() }}" hcloud_ns: "ansible-{{ hcloud_run_ns }}-{{ hcloud_role_ns }}" diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/subnetwork/aliases b/ansible_collections/hetzner/hcloud/tests/integration/targets/subnetwork/aliases index a6a90a6bf..c96df02ff 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/subnetwork/aliases +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/subnetwork/aliases @@ -1,2 +1,3 @@ cloud/hcloud +gather_facts/no azp/group3 diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/subnetwork/defaults/main/common.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/subnetwork/defaults/main/common.yml index e316b233c..159bb2088 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/subnetwork/defaults/main/common.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/subnetwork/defaults/main/common.yml @@ -8,5 +8,5 @@ hcloud_prefix: "tests" # Used to namespace resources created by concurrent test pipelines/targets hcloud_run_ns: "{{ hcloud_prefix | md5 }}" -hcloud_role_ns: "{{ role_name | split('_') | map('first') | join() }}" +hcloud_role_ns: "{{ role_name | split('_') | map('batch', 2) | map('first') | flatten() | join() }}" hcloud_ns: "ansible-{{ hcloud_run_ns }}-{{ hcloud_role_ns }}" diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/volume/aliases b/ansible_collections/hetzner/hcloud/tests/integration/targets/volume/aliases index 0e887600e..18b11115e 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/volume/aliases +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/volume/aliases @@ -1,2 +1,3 @@ cloud/hcloud +gather_facts/no azp/group2 diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/volume/defaults/main/common.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/volume/defaults/main/common.yml index e316b233c..159bb2088 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/volume/defaults/main/common.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/volume/defaults/main/common.yml @@ -8,5 +8,5 @@ hcloud_prefix: "tests" # Used to namespace resources created by concurrent test pipelines/targets hcloud_run_ns: "{{ hcloud_prefix | md5 }}" -hcloud_role_ns: "{{ role_name | split('_') | map('first') | join() }}" +hcloud_role_ns: "{{ role_name | split('_') | map('batch', 2) | map('first') | flatten() | join() }}" hcloud_ns: "ansible-{{ hcloud_run_ns }}-{{ hcloud_role_ns }}" diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/volume/tasks/test.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/volume/tasks/test.yml index fd47d5343..9b586e051 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/volume/tasks/test.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/volume/tasks/test.yml @@ -6,7 +6,7 @@ name: "{{hcloud_server_name}}" server_type: cx11 image: ubuntu-22.04 - state: started + state: stopped location: "fsn1" register: vol_server - name: verify setup server @@ -208,7 +208,8 @@ assert: that: - result is failed - - 'result.msg == "volume deletion is protected"' + - result.failure.code == "protected" + - result.msg == "volume deletion is protected" - name: test update Volume delete protection hetzner.hcloud.volume: @@ -254,7 +255,8 @@ assert: that: - result is failed - - 'result.msg == "volume deletion is protected"' + - result.failure.code == "protected" + - result.msg == "volume deletion is protected" - name: test update Volume delete protection hetzner.hcloud.volume: diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/volume_info/aliases b/ansible_collections/hetzner/hcloud/tests/integration/targets/volume_info/aliases index 0e887600e..18b11115e 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/volume_info/aliases +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/volume_info/aliases @@ -1,2 +1,3 @@ cloud/hcloud +gather_facts/no azp/group2 diff --git a/ansible_collections/hetzner/hcloud/tests/integration/targets/volume_info/defaults/main/common.yml b/ansible_collections/hetzner/hcloud/tests/integration/targets/volume_info/defaults/main/common.yml index e316b233c..159bb2088 100644 --- a/ansible_collections/hetzner/hcloud/tests/integration/targets/volume_info/defaults/main/common.yml +++ b/ansible_collections/hetzner/hcloud/tests/integration/targets/volume_info/defaults/main/common.yml @@ -8,5 +8,5 @@ hcloud_prefix: "tests" # Used to namespace resources created by concurrent test pipelines/targets hcloud_run_ns: "{{ hcloud_prefix | md5 }}" -hcloud_role_ns: "{{ role_name | split('_') | map('first') | join() }}" +hcloud_role_ns: "{{ role_name | split('_') | map('batch', 2) | map('first') | flatten() | join() }}" hcloud_ns: "ansible-{{ hcloud_run_ns }}-{{ hcloud_role_ns }}" diff --git a/ansible_collections/hetzner/hcloud/tests/sanity/ignore-2.13.txt b/ansible_collections/hetzner/hcloud/tests/sanity/ignore-2.13.txt deleted file mode 100644 index 185a458e3..000000000 --- a/ansible_collections/hetzner/hcloud/tests/sanity/ignore-2.13.txt +++ /dev/null @@ -1,69 +0,0 @@ -plugins/inventory/hcloud.py validate-modules:illegal-future-imports -plugins/inventory/hcloud.py validate-modules:import-before-documentation -plugins/inventory/hcloud.py yamllint:unparsable-with-libyaml # bug in ansible-test - https://github.com/ansible/ansible/issues/82353 -plugins/modules/certificate_info.py validate-modules:illegal-future-imports -plugins/modules/certificate_info.py validate-modules:import-before-documentation -plugins/modules/certificate.py validate-modules:illegal-future-imports -plugins/modules/certificate.py validate-modules:import-before-documentation -plugins/modules/datacenter_info.py validate-modules:illegal-future-imports -plugins/modules/datacenter_info.py validate-modules:import-before-documentation -plugins/modules/firewall_info.py validate-modules:illegal-future-imports -plugins/modules/firewall_info.py validate-modules:import-before-documentation -plugins/modules/firewall_resource.py validate-modules:illegal-future-imports -plugins/modules/firewall_resource.py validate-modules:import-before-documentation -plugins/modules/firewall.py validate-modules:illegal-future-imports -plugins/modules/firewall.py validate-modules:import-before-documentation -plugins/modules/floating_ip_info.py validate-modules:illegal-future-imports -plugins/modules/floating_ip_info.py validate-modules:import-before-documentation -plugins/modules/floating_ip.py validate-modules:illegal-future-imports -plugins/modules/floating_ip.py validate-modules:import-before-documentation -plugins/modules/image_info.py validate-modules:illegal-future-imports -plugins/modules/image_info.py validate-modules:import-before-documentation -plugins/modules/iso_info.py validate-modules:illegal-future-imports -plugins/modules/iso_info.py validate-modules:import-before-documentation -plugins/modules/load_balancer_info.py validate-modules:illegal-future-imports -plugins/modules/load_balancer_info.py validate-modules:import-before-documentation -plugins/modules/load_balancer_network.py validate-modules:illegal-future-imports -plugins/modules/load_balancer_network.py validate-modules:import-before-documentation -plugins/modules/load_balancer_service.py validate-modules:illegal-future-imports -plugins/modules/load_balancer_service.py validate-modules:import-before-documentation -plugins/modules/load_balancer_target.py validate-modules:illegal-future-imports -plugins/modules/load_balancer_target.py validate-modules:import-before-documentation -plugins/modules/load_balancer_type_info.py validate-modules:illegal-future-imports -plugins/modules/load_balancer_type_info.py validate-modules:import-before-documentation -plugins/modules/load_balancer.py validate-modules:illegal-future-imports -plugins/modules/load_balancer.py validate-modules:import-before-documentation -plugins/modules/location_info.py validate-modules:illegal-future-imports -plugins/modules/location_info.py validate-modules:import-before-documentation -plugins/modules/network_info.py validate-modules:illegal-future-imports -plugins/modules/network_info.py validate-modules:import-before-documentation -plugins/modules/network.py validate-modules:illegal-future-imports -plugins/modules/network.py validate-modules:import-before-documentation -plugins/modules/placement_group.py validate-modules:illegal-future-imports -plugins/modules/placement_group.py validate-modules:import-before-documentation -plugins/modules/primary_ip_info.py validate-modules:illegal-future-imports -plugins/modules/primary_ip_info.py validate-modules:import-before-documentation -plugins/modules/primary_ip.py validate-modules:illegal-future-imports -plugins/modules/primary_ip.py validate-modules:import-before-documentation -plugins/modules/rdns.py validate-modules:illegal-future-imports -plugins/modules/rdns.py validate-modules:import-before-documentation -plugins/modules/route.py validate-modules:illegal-future-imports -plugins/modules/route.py validate-modules:import-before-documentation -plugins/modules/server_info.py validate-modules:illegal-future-imports -plugins/modules/server_info.py validate-modules:import-before-documentation -plugins/modules/server_network.py validate-modules:illegal-future-imports -plugins/modules/server_network.py validate-modules:import-before-documentation -plugins/modules/server_type_info.py validate-modules:illegal-future-imports -plugins/modules/server_type_info.py validate-modules:import-before-documentation -plugins/modules/server.py validate-modules:illegal-future-imports -plugins/modules/server.py validate-modules:import-before-documentation -plugins/modules/ssh_key_info.py validate-modules:illegal-future-imports -plugins/modules/ssh_key_info.py validate-modules:import-before-documentation -plugins/modules/ssh_key.py validate-modules:illegal-future-imports -plugins/modules/ssh_key.py validate-modules:import-before-documentation -plugins/modules/subnetwork.py validate-modules:illegal-future-imports -plugins/modules/subnetwork.py validate-modules:import-before-documentation -plugins/modules/volume_info.py validate-modules:illegal-future-imports -plugins/modules/volume_info.py validate-modules:import-before-documentation -plugins/modules/volume.py validate-modules:illegal-future-imports -plugins/modules/volume.py validate-modules:import-before-documentation diff --git a/ansible_collections/hetzner/hcloud/tests/unit/conftest.py b/ansible_collections/hetzner/hcloud/tests/unit/conftest.py new file mode 100644 index 000000000..af891afc2 --- /dev/null +++ b/ansible_collections/hetzner/hcloud/tests/unit/conftest.py @@ -0,0 +1,15 @@ +from __future__ import annotations + +from unittest.mock import MagicMock + +import pytest + + +@pytest.fixture() +def module(): + obj = MagicMock() + obj.params = { + "api_token": "dummy", + "api_endpoint": "https://api.hetzner.cloud/v1", + } + return obj diff --git a/ansible_collections/hetzner/hcloud/tests/unit/inventory/test_hcloud.py b/ansible_collections/hetzner/hcloud/tests/unit/inventory/test_hcloud.py new file mode 100644 index 000000000..b5d3b777b --- /dev/null +++ b/ansible_collections/hetzner/hcloud/tests/unit/inventory/test_hcloud.py @@ -0,0 +1,75 @@ +from __future__ import annotations + +import json +from unittest.mock import MagicMock + +from plugins.inventory.hcloud import InventoryModule, first_ipv6_address +from plugins.module_utils.vendor.hcloud.servers import BoundServer + + +def test_first_ipv6_address(): + found = first_ipv6_address("2001:db8::/64") + assert isinstance(found, str) + assert found == "2001:db8::1" + + +def test_build_inventory_server(): + client = MagicMock() + inventory = InventoryModule() + inventory.get_option = MagicMock() + inventory.get_option.return_value = None + + server = BoundServer( + client, + { + "id": 45921624, + "name": "my-server", + "labels": {}, + "status": "running", + "public_net": { + "ipv4": { + "id": 56583278, + "ip": "127.0.0.1", + "blocked": False, + "dns_ptr": "static.1.0.0.127.clients.your-server.de", + }, + "ipv6": {"id": 56583279, "ip": "2001:db8::/64", "blocked": False, "dns_ptr": []}, + "floating_ips": [], + "firewalls": [], + }, + "private_net": [], + "server_type": {"id": 1, "name": "cx11", "architecture": "x86"}, + "datacenter": { + "id": 3, + "name": "hel1-dc2", + "location": {"id": 3, "name": "hel1"}, + }, + "image": {"id": 114690387, "name": "debian-12", "os_flavor": "debian", "os_version": "12"}, + }, + ) + # pylint: disable=protected-access + variables = inventory._build_inventory_server(server) + + # Ensure the host_vars are json serializable + json.dumps(variables) + + assert variables == { + "id": 45921624, + "name": "my-server", + "status": "running", + "type": "cx11", + "server_type": "cx11", + "architecture": "x86", + "location": "hel1", + "datacenter": "hel1-dc2", + "labels": {}, + "ipv4": "127.0.0.1", + "ipv6": "2001:db8::1", + "ipv6_network": "2001:db8::", + "ipv6_network_mask": "64", + "private_networks": [], + "image_id": 114690387, + "image_name": "debian-12", + "image_os_flavor": "debian", + "ansible_host": None, + } diff --git a/ansible_collections/hetzner/hcloud/tests/unit/module_utils/test_hcloud.py b/ansible_collections/hetzner/hcloud/tests/unit/module_utils/test_hcloud.py index c1a9ffb77..2f5e7509f 100644 --- a/ansible_collections/hetzner/hcloud/tests/unit/module_utils/test_hcloud.py +++ b/ansible_collections/hetzner/hcloud/tests/unit/module_utils/test_hcloud.py @@ -2,8 +2,8 @@ from __future__ import annotations import traceback from datetime import datetime, timezone -from unittest.mock import MagicMock +import pytest from ansible_collections.hetzner.hcloud.plugins.module_utils.hcloud import AnsibleHCloud from ansible_collections.hetzner.hcloud.plugins.module_utils.vendor.hcloud import ( APIException, @@ -16,12 +16,7 @@ from ansible_collections.hetzner.hcloud.plugins.module_utils.vendor.hcloud.actio ) -def test_hcloud_fail_json_hcloud(): - module = MagicMock() - module.params = { - "api_token": "fake_token", - "api_endpoint": "https://api.hetzner.cloud/v1", - } +def test_hcloud_fail_json_hcloud(module): AnsibleHCloud.represent = "hcloud_test" hcloud = AnsibleHCloud(module) @@ -123,3 +118,28 @@ def test_hcloud_fail_json_hcloud(): } }, ) + + +@pytest.mark.parametrize( + ("kwargs", "msg"), + [ + ({"required": ["key1"]}, None), + ({"required": ["missing"]}, "missing required arguments: missing"), + ({"required_one_of": [["key1", "missing"]]}, None), + ({"required_one_of": [["missing1", "missing2"]]}, "one of the following is required: missing1, missing2"), + ], +) +def test_hcloud_fail_on_invalid_params(module, kwargs, msg): + AnsibleHCloud.represent = "hcloud_test" + hcloud = AnsibleHCloud(module) + + module.params = { + "key1": "value", + "key2": "value", + } + + hcloud.fail_on_invalid_params(**kwargs) + if msg is None: + module.fail_json.assert_not_called() + else: + module.fail_json.assert_called_with(msg=msg) |