From e218306028de81cc023adfc5bf8573bfd207bf7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20T=C3=B6lle?= Date: Mon, 13 Feb 2023 10:48:26 +0100 Subject: [PATCH] test: various fixes for integration tests (#193) * test: update for new locations * test(cert): fix issues with random name failing the test The variable hcloud_dns_test_domain used the random function to generate a number from 1-100. This number changed between every usage of the variable, so the test that compared the domain name of the cert to the variable kept failing, as different numbers were generated. By generating the number once and saving it into a fact, this is fixed. * test: fix issues with long resource names Server and volume names have restricted length (63 and 64 respectivly). This can cause issues when the `hcloud_prefix` is of certain length. By applying truncate, we can be sure to not reach the limit. This issue mainly happened in our internal ci, as the hcloud_prefix variable contains the hostname where the tests were running, and our hostnames are quite long. --- .../targets/hcloud_certificate/tasks/main.yml | 12 +++++++++--- .../targets/hcloud_datacenter_info/tasks/main.yml | 4 ++-- .../targets/hcloud_floating_ip/defaults/main.yml | 2 +- .../hcloud_load_balancer_info/defaults/main.yml | 2 +- .../hcloud_load_balancer_target/defaults/main.yml | 2 +- .../targets/hcloud_location_info/tasks/main.yml | 4 ++-- .../targets/hcloud_placement_group/defaults/main.yml | 2 +- .../targets/hcloud_placement_group/tasks/main.yml | 4 ++-- .../targets/hcloud_primary_ip/defaults/main.yml | 2 +- .../targets/hcloud_rdns/defaults/main.yml | 2 +- .../targets/hcloud_server/defaults/main.yml | 2 +- .../targets/hcloud_server_info/defaults/main.yml | 2 +- .../targets/hcloud_server_network/defaults/main.yml | 2 +- .../targets/hcloud_ssh_key/defaults/main.yml | 2 +- .../targets/hcloud_volume/defaults/main.yml | 4 ++-- .../targets/hcloud_volume_info/defaults/main.yml | 2 +- 16 files changed, 28 insertions(+), 22 deletions(-) diff --git a/tests/integration/targets/hcloud_certificate/tasks/main.yml b/tests/integration/targets/hcloud_certificate/tasks/main.yml index 34f0429..615c89d 100644 --- a/tests/integration/targets/hcloud_certificate/tasks/main.yml +++ b/tests/integration/targets/hcloud_certificate/tasks/main.yml @@ -96,7 +96,7 @@ key: value test: "val123" register: result -- name: test update certificate with other labels +- name: test update certificate with other labels assert: that: - result is changed @@ -122,6 +122,12 @@ that: - result is success +- name: generate dns domain name + set_fact: + # hcloud_dns_test_domain uses random, which generates a new random number + # on every invocation, by saving it into a fact we generate the number once + hcloud_dns_test_domain: "{{ hcloud_dns_test_domain }}" + - name: test create managed certificate hcloud_certificate: name: "{{ hcloud_certificate_name }}" @@ -131,7 +137,7 @@ labels: HC-Use-Staging-CA: "true" register: result -- name: test rename certificate +- name: verify create managed certificate assert: that: - result is changed @@ -143,7 +149,7 @@ id: "{{ result.hcloud_certificate.id }}" state: absent register: result -- name: verify absent server +- name: verify absent certificate assert: that: - result is success diff --git a/tests/integration/targets/hcloud_datacenter_info/tasks/main.yml b/tests/integration/targets/hcloud_datacenter_info/tasks/main.yml index 602d2a6..3d144ae 100644 --- a/tests/integration/targets/hcloud_datacenter_info/tasks/main.yml +++ b/tests/integration/targets/hcloud_datacenter_info/tasks/main.yml @@ -8,7 +8,7 @@ - name: verify test gather hcloud datacenter infos assert: that: - - hcloud_datacenters.hcloud_datacenter_info| list | count == 4 + - hcloud_datacenters.hcloud_datacenter_info| list | count >= 5 - name: test gather hcloud datacenter infos in check mode hcloud_datacenter_info: @@ -18,7 +18,7 @@ - name: verify test gather hcloud datacenter infos in check mode assert: that: - - hcloud_datacenters.hcloud_datacenter_info| list | count == 4 + - hcloud_datacenters.hcloud_datacenter_info| list | count >= 5 - name: test gather hcloud datacenter infos with correct name hcloud_datacenter_info: diff --git a/tests/integration/targets/hcloud_floating_ip/defaults/main.yml b/tests/integration/targets/hcloud_floating_ip/defaults/main.yml index 5e878d6..ebd5ccc 100644 --- a/tests/integration/targets/hcloud_floating_ip/defaults/main.yml +++ b/tests/integration/targets/hcloud_floating_ip/defaults/main.yml @@ -3,4 +3,4 @@ --- hcloud_prefix: "tests" hcloud_floating_ip_name: "{{hcloud_prefix}}-i" -hcloud_server_name: "{{hcloud_prefix}}-fip-t" +hcloud_server_name: "{{ hcloud_prefix | truncate(45, True, '', 0) }}-fip-t" diff --git a/tests/integration/targets/hcloud_load_balancer_info/defaults/main.yml b/tests/integration/targets/hcloud_load_balancer_info/defaults/main.yml index d82c213..326973a 100644 --- a/tests/integration/targets/hcloud_load_balancer_info/defaults/main.yml +++ b/tests/integration/targets/hcloud_load_balancer_info/defaults/main.yml @@ -3,4 +3,4 @@ --- hcloud_prefix: "tests" hcloud_load_balancer_name: "{{hcloud_prefix}}-i" -hcloud_server_name: "{{hcloud_prefix}}-lb-i" +hcloud_server_name: "{{ hcloud_prefix | truncate(45, True, '', 0) }}-lb-i" diff --git a/tests/integration/targets/hcloud_load_balancer_target/defaults/main.yml b/tests/integration/targets/hcloud_load_balancer_target/defaults/main.yml index b6bc252..180133f 100644 --- a/tests/integration/targets/hcloud_load_balancer_target/defaults/main.yml +++ b/tests/integration/targets/hcloud_load_balancer_target/defaults/main.yml @@ -2,6 +2,6 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) --- hcloud_prefix: "tests" -hcloud_server_name: "{{hcloud_prefix}}-lb-t" +hcloud_server_name: "{{ hcloud_prefix | truncate(45, True, '', 0) }}-lb-t" hcloud_load_balancer_name: "{{hcloud_prefix}}-lb-target" hcloud_testing_ip: "176.9.59.39" diff --git a/tests/integration/targets/hcloud_location_info/tasks/main.yml b/tests/integration/targets/hcloud_location_info/tasks/main.yml index e0ae5f1..99d5880 100644 --- a/tests/integration/targets/hcloud_location_info/tasks/main.yml +++ b/tests/integration/targets/hcloud_location_info/tasks/main.yml @@ -8,7 +8,7 @@ - name: verify test gather hcloud location infos assert: that: - - hcloud_location.hcloud_location_info | list | count == 3 + - hcloud_location.hcloud_location_info | list | count >= 5 - name: test gather hcloud location infos in check mode hcloud_location_info: @@ -18,7 +18,7 @@ - name: verify test gather hcloud location infos in check mode assert: that: - - hcloud_location.hcloud_location_info | list | count == 3 + - hcloud_location.hcloud_location_info | list | count >= 5 - name: test gather hcloud location infos with correct name hcloud_location_info: diff --git a/tests/integration/targets/hcloud_placement_group/defaults/main.yml b/tests/integration/targets/hcloud_placement_group/defaults/main.yml index 7557ffb..21ce342 100644 --- a/tests/integration/targets/hcloud_placement_group/defaults/main.yml +++ b/tests/integration/targets/hcloud_placement_group/defaults/main.yml @@ -3,4 +3,4 @@ --- hcloud_prefix: "tests" hcloud_placement_group_name: "{{hcloud_prefix}}-i" -hcloud_server_name: "{{hcloud_prefix}}-i" +hcloud_server_name: "{{ hcloud_prefix | truncate(45, True, '', 0) }}-i" diff --git a/tests/integration/targets/hcloud_placement_group/tasks/main.yml b/tests/integration/targets/hcloud_placement_group/tasks/main.yml index df47b1b..d79aa0c 100644 --- a/tests/integration/targets/hcloud_placement_group/tasks/main.yml +++ b/tests/integration/targets/hcloud_placement_group/tasks/main.yml @@ -92,7 +92,7 @@ - name: test add server to placement group hcloud_server: name: "{{ hcloud_server_name }}" - placement_group: "{{ hcloud_server_name }}" + placement_group: "{{ hcloud_placement_group_name }}" force: True state: present register: result @@ -106,7 +106,7 @@ - name: test add server to placement group idempotence hcloud_server: name: "{{ hcloud_server_name }}" - placement_group: "{{ hcloud_server_name }}" + placement_group: "{{ hcloud_placement_group_name }}" force: True state: present register: result diff --git a/tests/integration/targets/hcloud_primary_ip/defaults/main.yml b/tests/integration/targets/hcloud_primary_ip/defaults/main.yml index 15a09eb..98aa28e 100644 --- a/tests/integration/targets/hcloud_primary_ip/defaults/main.yml +++ b/tests/integration/targets/hcloud_primary_ip/defaults/main.yml @@ -3,4 +3,4 @@ --- hcloud_prefix: "tests" hcloud_primary_ip_name: "{{hcloud_prefix}}-i" -hcloud_server_name: "{{hcloud_prefix}}-fip-t" +hcloud_server_name: "{{ hcloud_prefix | truncate(45, True, '', 0) }}-fip-t" diff --git a/tests/integration/targets/hcloud_rdns/defaults/main.yml b/tests/integration/targets/hcloud_rdns/defaults/main.yml index e5df50f..50117a8 100644 --- a/tests/integration/targets/hcloud_rdns/defaults/main.yml +++ b/tests/integration/targets/hcloud_rdns/defaults/main.yml @@ -2,7 +2,7 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) --- hcloud_prefix: "tests" -hcloud_server_name: "{{hcloud_prefix}}" +hcloud_server_name: "{{ hcloud_prefix | truncate(45, True, '', 0) }}" hcloud_floating_ip_name: "{{hcloud_prefix}}" hcloud_primary_ip_name: "{{hcloud_prefix}}" hcloud_load_balancer_name: "{{hcloud_prefix}}" diff --git a/tests/integration/targets/hcloud_server/defaults/main.yml b/tests/integration/targets/hcloud_server/defaults/main.yml index 77b8c6b..4e1c4dc 100644 --- a/tests/integration/targets/hcloud_server/defaults/main.yml +++ b/tests/integration/targets/hcloud_server/defaults/main.yml @@ -2,7 +2,7 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) --- hcloud_prefix: "tests" -hcloud_server_name: "{{hcloud_prefix}}-i" +hcloud_server_name: "{{ hcloud_prefix | truncate(45, True, '', 0) }}-i" hcloud_firewall_name: "{{hcloud_prefix}}-i" hcloud_primary_ip_name: "{{hcloud_prefix}}-i" hcloud_network_name: "{{hcloud_prefix}}-i" diff --git a/tests/integration/targets/hcloud_server_info/defaults/main.yml b/tests/integration/targets/hcloud_server_info/defaults/main.yml index 0c4dba2..aa27d64 100644 --- a/tests/integration/targets/hcloud_server_info/defaults/main.yml +++ b/tests/integration/targets/hcloud_server_info/defaults/main.yml @@ -2,4 +2,4 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) --- hcloud_prefix: "tests" -hcloud_server_name: "{{hcloud_prefix}}-ii" +hcloud_server_name: "{{ hcloud_prefix | truncate(45, True, '', 0) }}-ii" diff --git a/tests/integration/targets/hcloud_server_network/defaults/main.yml b/tests/integration/targets/hcloud_server_network/defaults/main.yml index 9a6bc8e..2e020c4 100644 --- a/tests/integration/targets/hcloud_server_network/defaults/main.yml +++ b/tests/integration/targets/hcloud_server_network/defaults/main.yml @@ -3,4 +3,4 @@ --- hcloud_prefix: "tests" hcloud_network_name: "{{hcloud_prefix}}-sn" -hcloud_server_name: "{{hcloud_prefix}}-sn" +hcloud_server_name: "{{ hcloud_prefix | truncate(45, True, '', 0) }}-sn" diff --git a/tests/integration/targets/hcloud_ssh_key/defaults/main.yml b/tests/integration/targets/hcloud_ssh_key/defaults/main.yml index ca7c426..cee1d46 100644 --- a/tests/integration/targets/hcloud_ssh_key/defaults/main.yml +++ b/tests/integration/targets/hcloud_ssh_key/defaults/main.yml @@ -2,7 +2,7 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) --- hcloud_prefix: "tests" -hcloud_server_name: "{{hcloud_prefix}}" +hcloud_server_name: "{{ hcloud_prefix | truncate(45, True, '', 0) }}" hcloud_ssh_key_name: "{{hcloud_prefix}}" hcloud_ssh_key_public_key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDnaTPfKaX1QKcRLOfr34buVLh5FhJAThI9NYB0xNdXsMd4Y0zLyyCQzHbx4eWCVZxym/s6csWSeLaAhO1GOHeAw3hQFMqf1oTBx6Y8g0pKpeotKPa/PDSUzdZF9Lc+DadtpQd8kFVHAu1Kd3zoEUnk1u6kP7I4qu4Z/6F9qBDF+M3aobiPVxdS7GwaVRW3nZu+FcQDLiBiNOjuRDyjHcDfEUkoh2SOu25RrFtGPzFu5mGmBJwotKpWAocLGfHzyn/fAHxgw3jKZVH/t+XWQFnl82Ie8yE3Z1EZ7oDkNRqFQT9AdXEQOLycTTYTQMJZpgeFTv3sAo6lPRCusiFmmLcf ci@ansible.hetzner.cloud" hcloud_ssh_key_fingerprint: "56:89:c4:d6:a7:4a:79:82:f4:c2:58:9c:e1:d2:2d:4e" diff --git a/tests/integration/targets/hcloud_volume/defaults/main.yml b/tests/integration/targets/hcloud_volume/defaults/main.yml index 3a9fb02..ff16ce2 100644 --- a/tests/integration/targets/hcloud_volume/defaults/main.yml +++ b/tests/integration/targets/hcloud_volume/defaults/main.yml @@ -2,5 +2,5 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) --- hcloud_prefix: "tests" -hcloud_volume_name: "{{hcloud_prefix}}-i" -hcloud_server_name: "{{hcloud_prefix}}-vs" +hcloud_volume_name: "{{ hcloud_prefix | truncate(60, True, '', 0) }}-i" +hcloud_server_name: "{{ hcloud_prefix | truncate(45, True, '', 0) }}-vs" diff --git a/tests/integration/targets/hcloud_volume_info/defaults/main.yml b/tests/integration/targets/hcloud_volume_info/defaults/main.yml index 5c589a8..52c468e 100644 --- a/tests/integration/targets/hcloud_volume_info/defaults/main.yml +++ b/tests/integration/targets/hcloud_volume_info/defaults/main.yml @@ -2,4 +2,4 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) --- hcloud_prefix: "tests" -hcloud_volume_name: "{{hcloud_prefix}}-i" +hcloud_volume_name: "{{ hcloud_prefix | truncate(60, True, '', 0) }}-i"