From 62ab0570c85540991caafe6d3523aa8992d8f84e Mon Sep 17 00:00:00 2001 From: Jonas L Date: Fri, 8 Sep 2023 09:37:43 +0200 Subject: [PATCH] test: setup new temporary project service for integration tests (#316) ##### SUMMARY Setup new temporary project service for integration tests. - Use the hc-integrations-test.de domain for certificates creation - Use new Hetzner account vSwitch - Use new Hetzner account server IP - Create snapshots during setup (instead of "always-there-snapshot") --- .../hcloud_certificate/defaults/main/main.yml | 2 +- .../hcloud_image_info/defaults/main/main.yml | 4 ++-- .../targets/hcloud_image_info/meta/main.yml | 3 +++ .../hcloud_image_info/tasks/cleanup.yml | 5 ++++ .../hcloud_image_info/tasks/prepare.yml | 23 +++++++++++++++++++ .../targets/hcloud_image_info/tasks/test.yml | 4 ++-- .../defaults/main/main.yml | 3 ++- .../tasks/test.yml | 6 ++--- .../hcloud_subnetwork/defaults/main/main.yml | 2 +- .../targets/setup_hcloud_cli/tasks/main.yml | 16 +++++++++++++ 10 files changed, 58 insertions(+), 10 deletions(-) create mode 100644 tests/integration/targets/hcloud_image_info/meta/main.yml create mode 100644 tests/integration/targets/hcloud_image_info/tasks/cleanup.yml create mode 100644 tests/integration/targets/hcloud_image_info/tasks/prepare.yml create mode 100644 tests/integration/targets/setup_hcloud_cli/tasks/main.yml diff --git a/tests/integration/targets/hcloud_certificate/defaults/main/main.yml b/tests/integration/targets/hcloud_certificate/defaults/main/main.yml index b13616d..e94b577 100644 --- a/tests/integration/targets/hcloud_certificate/defaults/main/main.yml +++ b/tests/integration/targets/hcloud_certificate/defaults/main/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_certificate_name: "{{ hcloud_ns }}" -hcloud_dns_test_domain: "{{ hcloud_ns }}-{{ 100 | random }}.hc-certs.de" +hcloud_dns_test_domain: "{{ (hcloud_ns + 100 | random | string) | md5 }}.hc-integrations-test.de" diff --git a/tests/integration/targets/hcloud_image_info/defaults/main/main.yml b/tests/integration/targets/hcloud_image_info/defaults/main/main.yml index e457a21..d7a3505 100644 --- a/tests/integration/targets/hcloud_image_info/defaults/main/main.yml +++ b/tests/integration/targets/hcloud_image_info/defaults/main/main.yml @@ -1,6 +1,6 @@ # Copyright: (c) 2019, Hetzner Cloud GmbH # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) --- -hcloud_snapshot_id: 10164049 -hcloud_snapshot_name: always-there-snapshot +hcloud_server_name: "{{ hcloud_ns }}" +hcloud_snapshot_name: "{{ hcloud_ns }}" hcloud_image_name: ubuntu-22.04 diff --git a/tests/integration/targets/hcloud_image_info/meta/main.yml b/tests/integration/targets/hcloud_image_info/meta/main.yml new file mode 100644 index 0000000..49f5c0c --- /dev/null +++ b/tests/integration/targets/hcloud_image_info/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - setup_hcloud_cli diff --git a/tests/integration/targets/hcloud_image_info/tasks/cleanup.yml b/tests/integration/targets/hcloud_image_info/tasks/cleanup.yml new file mode 100644 index 0000000..751366b --- /dev/null +++ b/tests/integration/targets/hcloud_image_info/tasks/cleanup.yml @@ -0,0 +1,5 @@ +--- +- name: Cleanup test_server + hetzner.hcloud.hcloud_server: + name: "{{ hcloud_server_name }}" + state: absent diff --git a/tests/integration/targets/hcloud_image_info/tasks/prepare.yml b/tests/integration/targets/hcloud_image_info/tasks/prepare.yml new file mode 100644 index 0000000..190e432 --- /dev/null +++ b/tests/integration/targets/hcloud_image_info/tasks/prepare.yml @@ -0,0 +1,23 @@ +--- +- name: Create test_server + hetzner.hcloud.hcloud_server: + name: "{{ hcloud_server_name }}" + server_type: cx11 + image: ubuntu-22.04 + state: stopped + register: test_server + +- name: Create test_snapshot + ansible.builtin.script: + cmd: > + {{ hcloud_cli_path }} server create-image + --type snapshot + --description "{{ hcloud_snapshot_name }}" + --label key=value + "{{ test_server.hcloud_server.id }}" + | awk '{print $2}' + register: test_snapshot + +- name: Set test_snapshot_id + ansible.builtin.set_fact: + test_snapshot_id: "{{ test_snapshot.stdout_lines[0] }}" diff --git a/tests/integration/targets/hcloud_image_info/tasks/test.yml b/tests/integration/targets/hcloud_image_info/tasks/test.yml index 10ca2fa..4360b89 100644 --- a/tests/integration/targets/hcloud_image_info/tasks/test.yml +++ b/tests/integration/targets/hcloud_image_info/tasks/test.yml @@ -30,7 +30,7 @@ - name: Gather hcloud_image_info with correct id hetzner.hcloud.hcloud_image_info: - id: "{{ hcloud_snapshot_id }}" + id: "{{ test_snapshot_id }}" type: snapshot register: result - name: Verify hcloud_image_info with correct id @@ -40,7 +40,7 @@ - name: Gather hcloud_image_info with wrong id hetzner.hcloud.hcloud_image_info: - id: "{{ hcloud_snapshot_id }}4321" + id: "{{ test_snapshot_id }}4321" type: snapshot ignore_errors: true register: result diff --git a/tests/integration/targets/hcloud_load_balancer_target/defaults/main/main.yml b/tests/integration/targets/hcloud_load_balancer_target/defaults/main/main.yml index abcaa4b..2d60910 100644 --- a/tests/integration/targets/hcloud_load_balancer_target/defaults/main/main.yml +++ b/tests/integration/targets/hcloud_load_balancer_target/defaults/main/main.yml @@ -3,4 +3,5 @@ --- hcloud_server_name: "{{ hcloud_ns }}" hcloud_load_balancer_name: "{{ hcloud_ns }}" -hcloud_testing_ip: "176.9.59.39" + +hetzner_server_ip: 142.132.203.104 diff --git a/tests/integration/targets/hcloud_load_balancer_target/tasks/test.yml b/tests/integration/targets/hcloud_load_balancer_target/tasks/test.yml index 0e48ac5..c1c9093 100644 --- a/tests/integration/targets/hcloud_load_balancer_target/tasks/test.yml +++ b/tests/integration/targets/hcloud_load_balancer_target/tasks/test.yml @@ -122,8 +122,8 @@ - name: test create ip target hetzner.hcloud.hcloud_load_balancer_target: type: "ip" - load_balancer: "{{hcloud_load_balancer_name}}" - ip: "{{hcloud_testing_ip}}" + load_balancer: "{{ hcloud_load_balancer_name }}" + ip: "{{ hetzner_server_ip }}" state: present register: load_balancer_target - name: verify create ip target @@ -131,7 +131,7 @@ that: - load_balancer_target is changed - load_balancer_target.hcloud_load_balancer_target.type == "ip" - - load_balancer_target.hcloud_load_balancer_target.ip == hcloud_testing_ip + - load_balancer_target.hcloud_load_balancer_target.ip == hetzner_server_ip - load_balancer_target.hcloud_load_balancer_target.load_balancer == hcloud_load_balancer_name - name: cleanup load_balancer diff --git a/tests/integration/targets/hcloud_subnetwork/defaults/main/main.yml b/tests/integration/targets/hcloud_subnetwork/defaults/main/main.yml index 926992a..998a833 100644 --- a/tests/integration/targets/hcloud_subnetwork/defaults/main/main.yml +++ b/tests/integration/targets/hcloud_subnetwork/defaults/main/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_network_name: "{{ hcloud_ns }}" -hetzner_vswitch_id: 15311 +hetzner_vswitch_id: 43065 diff --git a/tests/integration/targets/setup_hcloud_cli/tasks/main.yml b/tests/integration/targets/setup_hcloud_cli/tasks/main.yml new file mode 100644 index 0000000..7b5356b --- /dev/null +++ b/tests/integration/targets/setup_hcloud_cli/tasks/main.yml @@ -0,0 +1,16 @@ +--- +- name: Create temporary file for hcloud_cli_path + ansible.builtin.tempfile: + state: directory + register: _tmp_hcloud_cli + +- name: Download hcloud cli from Github releases + ansible.builtin.unarchive: + src: https://github.com/hetznercloud/cli/releases/download/v1.37.0/hcloud-linux-amd64.tar.gz + dest: "{{ _tmp_hcloud_cli.path }}" + remote_src: true + extra_opts: [hcloud] + +- name: Set hcloud_cli_path + ansible.builtin.set_fact: + hcloud_cli_path: "{{ _tmp_hcloud_cli.path }}/hcloud"