diff --git a/tests/integration/targets/server/tasks/cleanup.yml b/tests/integration/targets/server/tasks/cleanup.yml index 8066c411..9d9f85d4 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 4bdb9599..a88cc471 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 e00bcce5..2970b8e1 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_basic.yml b/tests/integration/targets/server/tasks/test_basic.yml index 1e94d67a..0edda716 100644 --- a/tests/integration/targets/server/tasks/test_basic.yml +++ b/tests/integration/targets/server/tasks/test_basic.yml @@ -7,7 +7,7 @@ register: result check_mode: true - name: test create server server - assert: + ansible.builtin.assert: that: - result is changed @@ -20,7 +20,7 @@ state: started register: main_server - name: verify create server - assert: + ansible.builtin.assert: that: - main_server is changed - main_server.hcloud_server.name == hcloud_server_name @@ -34,7 +34,7 @@ state: started register: result - name: verify create server idempotence - assert: + ansible.builtin.assert: that: - result is not changed @@ -45,7 +45,7 @@ register: result check_mode: true - name: verify stop server with check mode - assert: + ansible.builtin.assert: that: - result is changed - result.hcloud_server.status == "running" @@ -56,7 +56,7 @@ state: stopped register: result - name: verify stop server - assert: + ansible.builtin.assert: that: - result is changed - result.hcloud_server.status == "off" @@ -68,7 +68,7 @@ register: result check_mode: true - name: verify start server with check mode - assert: + ansible.builtin.assert: that: - result is changed @@ -78,7 +78,7 @@ state: started register: result - name: verify start server - assert: + ansible.builtin.assert: that: - result is changed - result.hcloud_server.status == "running" @@ -89,7 +89,7 @@ state: started register: result - name: verify start server idempotence - assert: + ansible.builtin.assert: that: - result is not changed - result.hcloud_server.status == "running" @@ -100,7 +100,7 @@ state: stopped register: result - name: verify stop server by its id - assert: + ansible.builtin.assert: that: - result is changed - result.hcloud_server.status == "off" @@ -113,7 +113,7 @@ register: result check_mode: true - name: verify test resize server running without force - assert: + ansible.builtin.assert: that: - result is changed - result.hcloud_server.server_type == "cx11" @@ -126,7 +126,7 @@ register: result check_mode: true - name: verify resize server with check mode - assert: + ansible.builtin.assert: that: - result is changed @@ -137,7 +137,7 @@ state: stopped register: result - name: verify resize server without disk - assert: + ansible.builtin.assert: that: - result is changed - result.hcloud_server.server_type == "cx21" @@ -149,7 +149,7 @@ state: stopped register: result - name: verify resize server idempotence - assert: + ansible.builtin.assert: that: - result is not changed @@ -160,7 +160,7 @@ state: stopped register: result - name: verify resize server to smaller plan - assert: + ansible.builtin.assert: that: - result is changed - result.hcloud_server.server_type == "cx11" @@ -173,7 +173,7 @@ state: stopped register: result - name: verify resize server with disk - assert: + ansible.builtin.assert: that: - result is changed - result.hcloud_server.server_type == "cx21" @@ -186,7 +186,7 @@ register: result check_mode: true - name: verify enable backups with check mode - assert: + ansible.builtin.assert: that: - result is changed @@ -197,7 +197,7 @@ state: stopped register: result - name: verify enable backups - assert: + ansible.builtin.assert: that: - result is changed - result.hcloud_server.backup_window != "" @@ -209,7 +209,7 @@ state: stopped register: result - name: verify enable backups idempotence - assert: + ansible.builtin.assert: that: - result is not changed - result.hcloud_server.backup_window != "" @@ -224,7 +224,7 @@ state: stopped register: result - name: verify backups are not accidentally disabled - assert: + ansible.builtin.assert: that: - result is not changed - result.hcloud_server.backup_window != "" @@ -236,7 +236,7 @@ state: rebuild register: result_after_test - name: verify rebuild server - assert: + ansible.builtin.assert: that: - result_after_test is changed - result.hcloud_server.id == result_after_test.hcloud_server.id @@ -249,7 +249,7 @@ register: result_after_test check_mode: true - name: verify rebuild server with check mode - assert: + ansible.builtin.assert: that: - result_after_test is changed @@ -261,7 +261,7 @@ register: result_after_test ignore_errors: true - name: verify update server protection booth protection arguments are required - assert: + ansible.builtin.assert: that: - result_after_test is failed - 'result_after_test.msg == "parameters are required together: delete_protection, rebuild_protection"' @@ -275,7 +275,7 @@ register: result_after_test ignore_errors: true - name: verify update server protection fails if they are not the same - assert: + ansible.builtin.assert: that: - result_after_test is failed @@ -288,7 +288,7 @@ register: result_after_test ignore_errors: true - name: verify update server protection - assert: + ansible.builtin.assert: that: - result_after_test is changed - result_after_test.hcloud_server.delete_protection is sameas true @@ -299,7 +299,7 @@ name: "{{hcloud_server_name}}" register: result_after_test - name: verify test server without protection set to be idempotent - assert: + ansible.builtin.assert: that: - result_after_test is not changed - result_after_test.hcloud_server.delete_protection is sameas true @@ -312,7 +312,7 @@ ignore_errors: true register: result - name: verify delete server fails if it is protected - assert: + ansible.builtin.assert: that: - result is failed - 'result.msg == "server deletion is protected"' @@ -325,7 +325,7 @@ ignore_errors: true register: result - name: verify rebuild server fails if it is protected - assert: + ansible.builtin.assert: that: - result is failed - 'result.msg == "server rebuild is protected"' @@ -339,7 +339,7 @@ register: result_after_test ignore_errors: true - name: verify remove server protection - assert: + ansible.builtin.assert: that: - result_after_test is changed - result_after_test.hcloud_server.delete_protection is sameas false @@ -351,7 +351,7 @@ state: absent register: result - name: verify absent server - assert: + ansible.builtin.assert: that: - result is success @@ -365,7 +365,7 @@ state: started register: main_server - name: verify create server with ssh key - assert: + ansible.builtin.assert: that: - main_server is changed - main_server.hcloud_server.name == hcloud_server_name @@ -383,7 +383,7 @@ register: main_server check_mode: true - name: verify activate rescue mode - assert: + ansible.builtin.assert: that: - main_server is changed @@ -396,7 +396,7 @@ state: present register: main_server - name: verify activate rescue mode - assert: + ansible.builtin.assert: that: - main_server is changed - main_server.hcloud_server.rescue_enabled is sameas true @@ -409,7 +409,7 @@ state: present register: main_server - name: verify activate rescue mode - assert: + ansible.builtin.assert: that: - main_server is changed - main_server.hcloud_server.rescue_enabled is sameas false @@ -421,7 +421,7 @@ state: present register: main_server - name: verify activate rescue mode without ssh keys - assert: + ansible.builtin.assert: that: - main_server is changed - main_server.hcloud_server.rescue_enabled is sameas true @@ -432,7 +432,7 @@ state: absent register: result - name: verify absent server - assert: + ansible.builtin.assert: that: - result is success @@ -447,7 +447,7 @@ state: started register: main_server - name: verify create server with rescue_mode - assert: + ansible.builtin.assert: that: - main_server is changed - main_server.hcloud_server.name == hcloud_server_name @@ -462,7 +462,7 @@ state: absent register: result - name: verify absent server - assert: + ansible.builtin.assert: that: - result is success - name: test create server with labels @@ -478,7 +478,7 @@ state: started register: main_server - name: verify create server with labels - assert: + ansible.builtin.assert: that: - main_server is changed - main_server.hcloud_server.labels.key == "value" @@ -497,7 +497,7 @@ state: started register: main_server - name: verify update server with labels - assert: + ansible.builtin.assert: that: - main_server is changed - main_server.hcloud_server.labels.key == "other" @@ -516,7 +516,7 @@ state: started register: main_server - name: verify update server with labels in other order - assert: + ansible.builtin.assert: that: - main_server is not changed @@ -526,7 +526,7 @@ state: absent register: result - name: verify cleanup - assert: + ansible.builtin.assert: that: - result is success @@ -541,7 +541,7 @@ state: present register: result - name: verify enable backups - assert: + ansible.builtin.assert: that: - result is changed - result.hcloud_server.backup_window != "" @@ -552,7 +552,7 @@ state: absent register: result - name: verify cleanup - assert: + ansible.builtin.assert: that: - result is success @@ -569,7 +569,7 @@ register: result_after_test ignore_errors: true - name: verify create server with protection - assert: + ansible.builtin.assert: that: - result_after_test is changed - result_after_test.hcloud_server.delete_protection is sameas true @@ -582,7 +582,7 @@ ignore_errors: true register: result - name: verify delete server fails if it is protected - assert: + ansible.builtin.assert: that: - result is failed - 'result.msg == "server deletion is protected"' @@ -596,7 +596,7 @@ register: result_after_test ignore_errors: true - name: verify update server protection - assert: + ansible.builtin.assert: that: - result_after_test is changed - result_after_test.hcloud_server.delete_protection is sameas false @@ -608,6 +608,6 @@ state: absent register: result - name: verify cleanup - assert: + ansible.builtin.assert: that: - result is success diff --git a/tests/integration/targets/server/tasks/test_firewalls.yml b/tests/integration/targets/server/tasks/test_firewalls.yml index 896a6c5c..76b27f7c 100644 --- a/tests/integration/targets/server/tasks/test_firewalls.yml +++ b/tests/integration/targets/server/tasks/test_firewalls.yml @@ -10,22 +10,10 @@ ignore_errors: true register: result - name: verify add not existing firewall should fail - assert: + ansible.builtin.assert: that: - result is failed - 'result.msg == "firewall not-existing was not found"' -- name: setup create firewalls - hetzner.hcloud.firewall: - name: "{{ item }}" - rules: - - direction: in - protocol: icmp - source_ips: - - 0.0.0.0/0 - - ::/0 - with_items: - - "{{ hcloud_firewall_name }}" - - "{{ hcloud_firewall_name }}2" - name: test create server with firewalls hetzner.hcloud.server: @@ -39,7 +27,7 @@ state: present register: result - name: verify test create server with firewalls - assert: + ansible.builtin.assert: that: - result is changed @@ -55,7 +43,7 @@ state: present register: result - name: verify test create server with firewalls idempotence - assert: + ansible.builtin.assert: that: - result is not changed @@ -71,7 +59,7 @@ state: present register: result - name: verify test update server with firewalls - assert: + ansible.builtin.assert: that: - result is changed @@ -87,7 +75,7 @@ state: present register: result - name: verify test update server with firewalls idempotence - assert: + ansible.builtin.assert: that: - result is not changed diff --git a/tests/integration/targets/server/tasks/test_primary_ips.yml b/tests/integration/targets/server/tasks/test_primary_ips.yml index 034da9f7..62f8b69d 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_private_network_only.yml b/tests/integration/targets/server/tasks/test_private_network_only.yml index a4219a00..33b66581 100644 --- a/tests/integration/targets/server/tasks/test_private_network_only.yml +++ b/tests/integration/targets/server/tasks/test_private_network_only.yml @@ -75,7 +75,7 @@ state: stopped register: result - name: verify test create server with primary network - assert: + ansible.builtin.assert: that: - result is changed @@ -95,7 +95,7 @@ state: stopped register: result - name: verify test update server by adding secondary network - assert: + ansible.builtin.assert: that: - result is changed @@ -115,7 +115,7 @@ state: stopped register: result - name: verify test update server idem - assert: + ansible.builtin.assert: that: - result is not changed diff --git a/tests/integration/targets/server/tasks/test_validation.yml b/tests/integration/targets/server/tasks/test_validation.yml index d4e0ef8b..16a21288 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"