From 4916673ccb7412f8cfdd4a5ce14d412fe4753b67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20T=C3=B6lle?= Date: Fri, 31 Mar 2023 15:38:59 +0200 Subject: [PATCH] test: use testing framework for server integration tests --- .../targets/server/tasks/cleanup.yml | 32 +++++++++ .../targets/server/tasks/prepare.yml | 59 +++++++++++++++ .../integration/targets/server/tasks/test.yml | 4 +- .../targets/server/tasks/test_primary_ips.yml | 72 ++++--------------- .../targets/server/tasks/test_validation.yml | 48 ++++++------- 5 files changed, 127 insertions(+), 88 deletions(-) diff --git a/tests/integration/targets/server/tasks/cleanup.yml b/tests/integration/targets/server/tasks/cleanup.yml index 8066c41..9d9f85d 100644 --- a/tests/integration/targets/server/tasks/cleanup.yml +++ b/tests/integration/targets/server/tasks/cleanup.yml @@ -3,3 +3,35 @@ hetzner.hcloud.ssh_key: name: "{{ hcloud_ssh_key_name }}" state: absent + +- name: Cleanup test_network + hetzner.hcloud.network: + name: "{{ hcloud_network_name }}" + state: absent + +- name: Cleanup test_primary_ipv4_1 + hetzner.hcloud.primary_ip: + name: "{{ hcloud_primary_ip_name }}v4-1" + state: absent + +- name: Cleanup test_primary_ipv4_2 + hetzner.hcloud.primary_ip: + name: "{{ hcloud_primary_ip_name }}v4-2" + state: absent + +- name: Cleanup test_primary_ipv6 + hetzner.hcloud.primary_ip: + name: "{{ hcloud_primary_ip_name }}v6" + state: absent + +- name: Cleanup test_firewall_1 + hetzner.hcloud.firewall: + name: "{{ hcloud_firewall_name }}-1" + force: true + state: absent + +- name: Cleanup test_firewall_2 + hetzner.hcloud.firewall: + name: "{{ hcloud_firewall_name }}-2" + force: true + state: absent diff --git a/tests/integration/targets/server/tasks/prepare.yml b/tests/integration/targets/server/tasks/prepare.yml index 4bdb959..a88cc47 100644 --- a/tests/integration/targets/server/tasks/prepare.yml +++ b/tests/integration/targets/server/tasks/prepare.yml @@ -4,3 +4,62 @@ name: "{{ hcloud_ssh_key_name }}" public_key: "{{ test_ssh_keypair.public_key }}" register: test_ssh_key + +- 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_primary_ipv4_1 + hetzner.hcloud.primary_ip: + name: "{{ hcloud_primary_ip_name }}v4-1" + type: ipv4 + datacenter: fsn1-dc14 + register: test_primary_ipv4_1 + +- name: Create test_primary_ipv4_2 + hetzner.hcloud.primary_ip: + name: "{{ hcloud_primary_ip_name }}v4-2" + type: ipv4 + datacenter: fsn1-dc14 + register: test_primary_ipv4_2 + +- name: Create test_primary_ipv6 + hetzner.hcloud.primary_ip: + name: "{{ hcloud_primary_ip_name }}v6" + type: ipv6 + datacenter: fsn1-dc14 + register: test_primary_ipv6 + +- name: Create test_firewall_1 + hetzner.hcloud.firewall: + name: "{{ hcloud_firewall_name }}-1" + rules: + - direction: in + protocol: icmp + source_ips: + - 0.0.0.0/0 + - ::/0 + register: test_firewall_1 + +- name: Create test_firewall_2 + hetzner.hcloud.firewall: + name: "{{ hcloud_firewall_name }}-2" + rules: + - direction: in + protocol: icmp + source_ips: + - 0.0.0.0/0 + - ::/0 + register: test_firewall_2 diff --git a/tests/integration/targets/server/tasks/test.yml b/tests/integration/targets/server/tasks/test.yml index e00bcce..2970b8e 100644 --- a/tests/integration/targets/server/tasks/test.yml +++ b/tests/integration/targets/server/tasks/test.yml @@ -1,8 +1,8 @@ # Copyright: (c) 2022, Hetzner Cloud GmbH # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) --- -#- ansible.builtin.include_tasks: test_validation.yml +- ansible.builtin.include_tasks: test_validation.yml - ansible.builtin.include_tasks: test_basic.yml -#- ansible.builtin.include_tasks: test_firewalls.yml +- ansible.builtin.include_tasks: test_firewalls.yml - ansible.builtin.include_tasks: test_primary_ips.yml - ansible.builtin.include_tasks: test_private_network_only.yml diff --git a/tests/integration/targets/server/tasks/test_primary_ips.yml b/tests/integration/targets/server/tasks/test_primary_ips.yml index 034da9f..62f8b69 100644 --- a/tests/integration/targets/server/tasks/test_primary_ips.yml +++ b/tests/integration/targets/server/tasks/test_primary_ips.yml @@ -1,82 +1,36 @@ # Copyright: (c) 2022, Hetzner Cloud GmbH # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) --- -- name: setup create primary ipv4 - hetzner.hcloud.primary_ip: - name: "{{ hcloud_primary_ip_name }}v4" - type: ipv4 - datacenter: "fsn1-dc14" - register: primaryIPv4 - -- name: setup create second primary ipv4 - hetzner.hcloud.primary_ip: - name: "{{ hcloud_primary_ip_name }}v42" - type: ipv4 - datacenter: "fsn1-dc14" - register: secondPrimaryIPv4 - -- name: setup create primary ipv6 - hetzner.hcloud.primary_ip: - name: "{{ hcloud_primary_ip_name }}v6" - type: ipv6 - datacenter: "fsn1-dc14" - register: primaryIPv6 - -- name: test create server with primary ips +- name: Test create with primary ips hetzner.hcloud.server: name: "{{ hcloud_server_name }}" server_type: cpx11 - datacenter: "fsn1-dc14" - image: "ubuntu-22.04" - ipv4: "{{primaryIPv4.hcloud_primary_ip.id}}" - ipv6: "{{primaryIPv6.hcloud_primary_ip.id}}" + datacenter: fsn1-dc14 + image: ubuntu-22.04 + ipv4: "{{ test_primary_ipv4_1.hcloud_primary_ip.id }}" + ipv6: "{{ test_primary_ipv6.hcloud_primary_ip.id }}" ssh_keys: - "{{ hcloud_ssh_key_name }}" state: stopped register: result -- name: verify test create server with primary ips - assert: +- name: Verify create with primary ips + ansible.builtin.assert: that: - result is changed -- name: test update server with primary ips +- name: Test update with primary ips hetzner.hcloud.server: name: "{{ hcloud_server_name }}" server_type: cpx11 - datacenter: "fsn1-dc14" - image: "ubuntu-22.04" - ipv4: "{{secondPrimaryIPv4.hcloud_primary_ip.id}}" + datacenter: fsn1-dc14 + image: ubuntu-22.04 + ipv4: "{{ test_primary_ipv4_2.hcloud_primary_ip.id }}" ipv6: "" - enable_ipv6: false ssh_keys: - "{{ hcloud_ssh_key_name }}" state: stopped register: result -- name: verify test create server with primary ips - assert: +- name: Verify update with primary ips + ansible.builtin.assert: that: - result is changed - -- name: cleanup server with primary ips - hetzner.hcloud.server: - name: "{{ hcloud_server_name }}" - state: absent - -- name: cleanup test create primary ips - hetzner.hcloud.primary_ip: - name: "{{ hcloud_server_name }}v4" - state: absent -- name: cleanup test create primary ips - hetzner.hcloud.primary_ip: - name: "{{ hcloud_server_name }}v42" - state: absent - until: result is not failed - retries: 5 - delay: 2 -- name: cleanup test create primary ips - hetzner.hcloud.primary_ip: - name: "{{ hcloud_server_name }}v6" - state: absent - until: result is not failed - retries: 5 - delay: 2 diff --git a/tests/integration/targets/server/tasks/test_validation.yml b/tests/integration/targets/server/tasks/test_validation.yml index d4e0ef8..16a2128 100644 --- a/tests/integration/targets/server/tasks/test_validation.yml +++ b/tests/integration/targets/server/tasks/test_validation.yml @@ -1,51 +1,45 @@ # Copyright: (c) 2019, Hetzner Cloud GmbH # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) --- -- name: setup +- name: Test missing required parameters hetzner.hcloud.server: name: "{{ hcloud_server_name }}" - state: absent - register: result -- name: verify setup - assert: - that: - - result is success - -- name: test missing required parameters on create server - hetzner.hcloud.server: - name: "{{ hcloud_server_name }}" - register: result + state: present ignore_errors: true -- name: verify fail test missing required parameters on create server - assert: + register: result +- name: Verify missing required parameters + ansible.builtin.assert: that: - result is failed - - 'result.msg == "missing required arguments: server_type, image"' + - >- + result.msg == "missing required arguments: server_type, image" -- name: test create server with not existing server type +- name: Test create server with invalid server type hetzner.hcloud.server: name: "{{ hcloud_server_name }}" - server_type: not-existing-server-type + server_type: invalid-server-type image: ubuntu-22.04 state: present - register: result ignore_errors: true -- name: verify fail test create server with not existing server type - assert: + register: result +- name: Verify create server with invalid server type + ansible.builtin.assert: that: - result is failed - - 'result.msg == "server_type not-existing-server-type was not found"' + - >- + result.msg == "Invalid server type ID `invalid-server-type`: server_type invalid-server-type was not found" -- name: test create server with not existing image +- name: Test create server with invalid image hetzner.hcloud.server: name: "{{ hcloud_server_name }}" server_type: cx11 - image: my-not-existing-image-20.04 + image: invalid-image state: present - register: result ignore_errors: true -- name: verify fail test create server with not existing image - assert: + register: result +- name: Verify create server with invalid image + ansible.builtin.assert: that: - result is failed - - 'result.msg == "Image my-not-existing-image-20.04 was not found"' + - >- + result.msg == "image with ID 'invalid-image' not found: Image invalid-image was not found"