From 6471e4653de2bff55dca9c0cf488ff897ba011da Mon Sep 17 00:00:00 2001 From: Gaudenz Steinlin Date: Tue, 12 Mar 2019 17:53:49 +0100 Subject: [PATCH] Integration test cleanup for cloudscale modules (#53629) * Integration test cleanup for cloudscale modules This refactors the cleanup procedure for the integration tests of the cloudscale_server and cloudscale_volume modules to use an "always" section for cleanup. The cleanup code also deletes all resources which contain the test run prefix. This ensures that all resources are cleaned up regardless of the actual test result which is a prerequisite for running these tests in CI. * Move cloudscale_floating_ip tests from legacy to integration This also adds code to make sure that floating IPs are deleted even if a test run fails. This is unfortunately not possible for floatint IPv6 networks. --- .../tasks/cleanup_floating_ips.yml | 17 + .../tasks/cleanup_servers.yml | 17 + .../tasks/cleanup_volumes.yml | 17 + .../targets/cloudscale_floating_ip/aliases | 2 + .../cloudscale_floating_ip/meta/main.yml | 3 + .../tasks/floating_ip.yml | 0 .../cloudscale_floating_ip/tasks/main.yml | 22 +- .../targets/cloudscale_server/tasks/main.yml | 452 +----------------- .../targets/cloudscale_server/tasks/tests.yml | 447 +++++++++++++++++ .../cloudscale_volume/tasks/failures.yml | 10 - .../targets/cloudscale_volume/tasks/main.yml | 167 +------ .../targets/cloudscale_volume/tasks/tests.yml | 154 ++++++ test/legacy/cloudscale.yml | 7 - .../cloudscale_floating_ip/defaults/main.yml | 5 - .../cloudscale_floating_ip/meta/main.yml | 2 - 15 files changed, 683 insertions(+), 639 deletions(-) create mode 100644 test/integration/targets/cloudscale_common/tasks/cleanup_floating_ips.yml create mode 100644 test/integration/targets/cloudscale_common/tasks/cleanup_servers.yml create mode 100644 test/integration/targets/cloudscale_common/tasks/cleanup_volumes.yml create mode 100644 test/integration/targets/cloudscale_floating_ip/aliases create mode 100644 test/integration/targets/cloudscale_floating_ip/meta/main.yml rename test/{legacy/roles => integration/targets}/cloudscale_floating_ip/tasks/floating_ip.yml (100%) rename test/{legacy/roles => integration/targets}/cloudscale_floating_ip/tasks/main.yml (55%) create mode 100644 test/integration/targets/cloudscale_server/tasks/tests.yml create mode 100644 test/integration/targets/cloudscale_volume/tasks/tests.yml delete mode 100644 test/legacy/cloudscale.yml delete mode 100644 test/legacy/roles/cloudscale_floating_ip/defaults/main.yml delete mode 100644 test/legacy/roles/cloudscale_floating_ip/meta/main.yml diff --git a/test/integration/targets/cloudscale_common/tasks/cleanup_floating_ips.yml b/test/integration/targets/cloudscale_common/tasks/cleanup_floating_ips.yml new file mode 100644 index 0000000000..8b60ab9260 --- /dev/null +++ b/test/integration/targets/cloudscale_common/tasks/cleanup_floating_ips.yml @@ -0,0 +1,17 @@ +--- +- name: List all floating IPs + uri: + url: 'https://api.cloudscale.ch/v1/floating-ips' + headers: + Authorization: 'Bearer {{ cloudscale_api_token }}' + status_code: 200 + register: floating_ip_list + +- name: Remove all floating IPs created by this test run + cloudscale_floating_ip: + ip: '{{ item.network | ipaddr("address") }}' + state: 'absent' + when: cloudscale_resource_prefix in (item.reverse_ptr | string ) + with_items: '{{ floating_ip_list.json }}' + loop_control: + label: '{{ item.reverse_ptr }} ({{ item.network }})' diff --git a/test/integration/targets/cloudscale_common/tasks/cleanup_servers.yml b/test/integration/targets/cloudscale_common/tasks/cleanup_servers.yml new file mode 100644 index 0000000000..8fe6798693 --- /dev/null +++ b/test/integration/targets/cloudscale_common/tasks/cleanup_servers.yml @@ -0,0 +1,17 @@ +--- +- name: List all servers + uri: + url: 'https://api.cloudscale.ch/v1/servers' + headers: + Authorization: 'Bearer {{ cloudscale_api_token }}' + status_code: 200 + register: server_list + +- name: Remove all servers created by this test run + cloudscale_server: + uuid: '{{ item.uuid }}' + state: 'absent' + when: cloudscale_resource_prefix in item.name + with_items: '{{ server_list.json }}' + loop_control: + label: '{{ item.name }} ({{ item.uuid }})' diff --git a/test/integration/targets/cloudscale_common/tasks/cleanup_volumes.yml b/test/integration/targets/cloudscale_common/tasks/cleanup_volumes.yml new file mode 100644 index 0000000000..67cc89bb31 --- /dev/null +++ b/test/integration/targets/cloudscale_common/tasks/cleanup_volumes.yml @@ -0,0 +1,17 @@ +--- +- name: List all volumes + uri: + url: 'https://api.cloudscale.ch/v1/volumes' + headers: + Authorization: 'Bearer {{ cloudscale_api_token }}' + status_code: 200 + register: volume_list + +- name: Remove all volumes created by this test run + cloudscale_volume: + uuid: '{{ item.uuid }}' + state: 'absent' + when: cloudscale_resource_prefix in item.name + with_items: '{{ volume_list.json }}' + loop_control: + label: '{{ item.name }} ({{ item.uuid }})' diff --git a/test/integration/targets/cloudscale_floating_ip/aliases b/test/integration/targets/cloudscale_floating_ip/aliases new file mode 100644 index 0000000000..c200a3d2c8 --- /dev/null +++ b/test/integration/targets/cloudscale_floating_ip/aliases @@ -0,0 +1,2 @@ +cloud/cloudscale +unsupported diff --git a/test/integration/targets/cloudscale_floating_ip/meta/main.yml b/test/integration/targets/cloudscale_floating_ip/meta/main.yml new file mode 100644 index 0000000000..8dd48f0337 --- /dev/null +++ b/test/integration/targets/cloudscale_floating_ip/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - cloudscale_common diff --git a/test/legacy/roles/cloudscale_floating_ip/tasks/floating_ip.yml b/test/integration/targets/cloudscale_floating_ip/tasks/floating_ip.yml similarity index 100% rename from test/legacy/roles/cloudscale_floating_ip/tasks/floating_ip.yml rename to test/integration/targets/cloudscale_floating_ip/tasks/floating_ip.yml diff --git a/test/legacy/roles/cloudscale_floating_ip/tasks/main.yml b/test/integration/targets/cloudscale_floating_ip/tasks/main.yml similarity index 55% rename from test/legacy/roles/cloudscale_floating_ip/tasks/main.yml rename to test/integration/targets/cloudscale_floating_ip/tasks/main.yml index fb33e634fe..c9d331f9c6 100644 --- a/test/legacy/roles/cloudscale_floating_ip/tasks/main.yml +++ b/test/integration/targets/cloudscale_floating_ip/tasks/main.yml @@ -2,7 +2,7 @@ block: - name: Create a server cloudscale_server: - name: '{{ resource_prefix }}-test01' + name: '{{ cloudscale_resource_prefix }}-test01' flavor: '{{ cloudscale_test_flavor }}' image: '{{ cloudscale_test_image }}' ssh_keys: '{{ cloudscale_test_ssh_key }}' @@ -10,7 +10,7 @@ - name: Create a second server cloudscale_server: - name: '{{ resource_prefix }}-test02' + name: '{{ cloudscale_resource_prefix }}-test02' flavor: '{{ cloudscale_test_flavor }}' image: '{{ cloudscale_test_image }}' ssh_keys: '{{ cloudscale_test_ssh_key }}' @@ -18,16 +18,14 @@ - include_tasks: floating_ip.yml with_items: - - { 'ip_version': 4, 'reverse_ptr': 'my-floating-ipv4.example.com' } - - { 'ip_version': 6 } + - { 'ip_version': 4, 'reverse_ptr': '{{ cloudscale_resource_prefix }}-4.example.com' } + - { 'ip_version': 6, 'reverse_ptr': '{{ cloudscale_resource_prefix }}-6.example.com' } - { 'ip_version': 6, 'prefix_length': 56 } always: - - name: Delete servers - cloudscale_server: - uuid: '{{ item.uuid }}' - state: 'absent' - ignore_errors: True - with_items: - - '{{ test01 }}' - - '{{ test02 }}' + - import_role: + name: cloudscale_common + tasks_from: cleanup_servers + - import_role: + name: cloudscale_common + tasks_from: cleanup_floating_ips diff --git a/test/integration/targets/cloudscale_server/tasks/main.yml b/test/integration/targets/cloudscale_server/tasks/main.yml index f784ea6af6..14db856dda 100644 --- a/test/integration/targets/cloudscale_server/tasks/main.yml +++ b/test/integration/targets/cloudscale_server/tasks/main.yml @@ -1,447 +1,7 @@ --- -- name: Test create a running server in check mode - cloudscale_server: - name: '{{ cloudscale_resource_prefix }}-test' - flavor: '{{ cloudscale_test_flavor }}' - image: '{{ cloudscale_test_image }}' - ssh_keys: '{{ cloudscale_test_ssh_key }}' - register: server - check_mode: yes -- name: Verify create a running server in check mode - assert: - that: - - server is changed - - server.state == 'absent' - -- name: Test create a running server - cloudscale_server: - name: '{{ cloudscale_resource_prefix }}-test' - flavor: '{{ cloudscale_test_flavor }}' - image: '{{ cloudscale_test_image }}' - ssh_keys: '{{ cloudscale_test_ssh_key }}' - register: server -- name: Verify create a running server - assert: - that: - - server is changed - - server.state == 'running' - -- name: Test create a running server idempotence - cloudscale_server: - name: '{{ cloudscale_resource_prefix }}-test' - flavor: '{{ cloudscale_test_flavor }}' - image: '{{ cloudscale_test_image }}' - ssh_keys: '{{ cloudscale_test_ssh_key }}' - register: server -- name: Verify create a running server idempotence - assert: - that: - - server is not changed - - server.state == 'running' - -- name: Test update flavor of a running server without force in check mode - cloudscale_server: - name: '{{ cloudscale_resource_prefix }}-test' - flavor: '{{ cloudscale_test_flavor_2 }}' - image: '{{ cloudscale_test_image }}' - ssh_keys: '{{ cloudscale_test_ssh_key }}' - force: no - register: server - check_mode: yes -- name: Verify update flavor of a running server without force in check mode - assert: - that: - - server is not changed - - server.state == 'running' - - server.flavor.slug == '{{ cloudscale_test_flavor }}' - -- name: Test update flavor of a running server without force - cloudscale_server: - name: '{{ cloudscale_resource_prefix }}-test' - flavor: '{{ cloudscale_test_flavor_2 }}' - image: '{{ cloudscale_test_image }}' - ssh_keys: '{{ cloudscale_test_ssh_key }}' - force: no - register: server -- name: Verify update flavor of a running server without force - assert: - that: - - server is not changed - - server.state == 'running' - - server.flavor.slug == '{{ cloudscale_test_flavor }}' - -- name: Test update flavor of a running server without force idempotence - cloudscale_server: - name: '{{ cloudscale_resource_prefix }}-test' - flavor: '{{ cloudscale_test_flavor_2 }}' - image: '{{ cloudscale_test_image }}' - ssh_keys: '{{ cloudscale_test_ssh_key }}' - force: no - register: server -- name: Verify update flavor of a running server without force idempotence - assert: - that: - - server is not changed - - server.state == 'running' - - server.flavor.slug == '{{ cloudscale_test_flavor }}' - -- name: Test update flavor and name of a running server without force in check mode - cloudscale_server: - uuid: '{{ server.uuid }}' - name: '{{ cloudscale_resource_prefix }}-test-renamed' - flavor: '{{ cloudscale_test_flavor_2 }}' - image: '{{ cloudscale_test_image }}' - ssh_keys: '{{ cloudscale_test_ssh_key }}' - force: no - register: server - check_mode: yes -- name: Verify update flavor and name of a running server without force in check mode - assert: - that: - - server is changed - - server.state == 'running' - - server.flavor.slug == '{{ cloudscale_test_flavor }}' - - server.name == '{{ cloudscale_resource_prefix }}-test' - -- name: Test update flavor and name of a running server without force - cloudscale_server: - uuid: '{{ server.uuid }}' - name: '{{ cloudscale_resource_prefix }}-test-renamed' - flavor: '{{ cloudscale_test_flavor_2 }}' - image: '{{ cloudscale_test_image }}' - ssh_keys: '{{ cloudscale_test_ssh_key }}' - force: no - register: server -- name: Verify update flavor and name of a running server without force - assert: - that: - - server is changed - - server.state == 'running' - - server.flavor.slug == '{{ cloudscale_test_flavor }}' - - server.name == '{{ cloudscale_resource_prefix }}-test-renamed' - -- name: Test update flavor and name of a running server without force idempotence - cloudscale_server: - uuid: '{{ server.uuid }}' - name: '{{ cloudscale_resource_prefix }}-test-renamed' - flavor: '{{ cloudscale_test_flavor_2 }}' - image: '{{ cloudscale_test_image }}' - ssh_keys: '{{ cloudscale_test_ssh_key }}' - force: no - register: server -- name: Verify update flavor and name of a running server without force idempotence - assert: - that: - - server is not changed - - server.state == 'running' - - server.flavor.slug == '{{ cloudscale_test_flavor }}' - - server.name == '{{ cloudscale_resource_prefix }}-test-renamed' - -- name: Test update flavor of a running server with force in check mode - cloudscale_server: - name: '{{ cloudscale_resource_prefix }}-test-renamed' - flavor: '{{ cloudscale_test_flavor_2 }}' - image: '{{ cloudscale_test_image }}' - ssh_keys: '{{ cloudscale_test_ssh_key }}' - force: yes - register: server - check_mode: yes -- name: Verify update flavor of a running server with force in check mode - assert: - that: - - server is changed - - server.state == 'running' - - server.flavor.slug == '{{ cloudscale_test_flavor }}' - - server.name == '{{ cloudscale_resource_prefix }}-test-renamed' - -- name: Test update flavor of a running server with force - cloudscale_server: - name: '{{ cloudscale_resource_prefix }}-test-renamed' - flavor: '{{ cloudscale_test_flavor_2 }}' - image: '{{ cloudscale_test_image }}' - ssh_keys: '{{ cloudscale_test_ssh_key }}' - force: yes - register: server -- name: Verify update flavor of a running server with force - assert: - that: - - server is changed - - server.state == 'running' - - server.flavor.slug == '{{ cloudscale_test_flavor_2 }}' - - server.name == '{{ cloudscale_resource_prefix }}-test-renamed' - -- name: Test update a running server with force idempotence - cloudscale_server: - name: '{{ cloudscale_resource_prefix }}-test-renamed' - flavor: '{{ cloudscale_test_flavor_2 }}' - image: '{{ cloudscale_test_image }}' - ssh_keys: '{{ cloudscale_test_ssh_key }}' - force: yes - register: server -- name: Verify update flavor of a running server with force idempotence - assert: - that: - - server is not changed - - server.state == 'running' - - server.flavor.slug == '{{ cloudscale_test_flavor_2 }}' - - server.name == '{{ cloudscale_resource_prefix }}-test-renamed' - -- name: Remember uuid of running server for anti affinity - set_fact: - running_server_uuid: '{{ server.uuid }}' - -- name: Test create server stopped in anti affinity and private network only in check mode - cloudscale_server: - name: '{{ cloudscale_resource_prefix }}-test-stopped' - flavor: '{{ cloudscale_test_flavor }}' - image: '{{ cloudscale_test_image }}' - ssh_keys: '{{ cloudscale_test_ssh_key }}' - anti_affinity_with: '{{ running_server_uuid }}' - use_public_network: no - use_private_network: yes - state: stopped - check_mode: yes - register: server_stopped -- name: Verify create server stopped in anti affinity and private network only in check mode - assert: - that: - - server_stopped is changed - - server_stopped.state == 'absent' - -- name: Test create server stopped in anti affinity and private network only - cloudscale_server: - name: '{{ cloudscale_resource_prefix }}-test-stopped' - flavor: '{{ cloudscale_test_flavor }}' - image: '{{ cloudscale_test_image }}' - ssh_keys: '{{ cloudscale_test_ssh_key }}' - anti_affinity_with: '{{ running_server_uuid }}' - use_public_network: no - use_private_network: yes - state: stopped - register: server_stopped -- name: Verify create server stopped in anti affinity and private network only - assert: - that: - - server_stopped is changed - - server_stopped.state == 'stopped' - - server_stopped.anti_affinity_with.0.uuid == running_server_uuid - - server_stopped.interfaces.0.type == 'private' - -- name: Test create server stopped in anti affinity and private network only idempotence - cloudscale_server: - name: '{{ cloudscale_resource_prefix }}-test-stopped' - flavor: '{{ cloudscale_test_flavor }}' - image: '{{ cloudscale_test_image }}' - ssh_keys: '{{ cloudscale_test_ssh_key }}' - anti_affinity_with: '{{ running_server_uuid }}' - use_public_network: no - use_private_network: yes - state: stopped - register: server_stopped -- name: Verify create server stopped in anti affinity and private network only idempotence - assert: - that: - - server_stopped is not changed - - server_stopped.state == 'stopped' - - server_stopped.anti_affinity_with.0.uuid == running_server_uuid - - server_stopped.interfaces.0.type == 'private' - -- name: Test create server failure without required parameters - cloudscale_server: - name: '{{ cloudscale_resource_prefix }}-test-failed' - register: server_failed - ignore_errors: yes -- name: Verify create server failure without required parameters - assert: - that: - - server_failed is failed - - "'missing required arguments' in server_failed.msg" - -- name: Test stop running server in check mode - cloudscale_server: - name: '{{ cloudscale_resource_prefix }}-test-renamed' - state: stopped - check_mode: yes - register: server -- name: Verify stop running server in check mode - assert: - that: - - server is changed - - server.state == 'running' - -- name: Test stop running server - cloudscale_server: - name: '{{ cloudscale_resource_prefix }}-test-renamed' - state: stopped - register: server -- name: Verify stop running server - assert: - that: - - server is changed - - server.state == 'stopped' - -- name: Test stop running server idempotence - cloudscale_server: - name: '{{ cloudscale_resource_prefix }}-test-renamed' - state: 'stopped' - register: server -- name: Verify stop running server idempotence - assert: - that: - - server is not changed - - server.state == 'stopped' - -- name: Test update a stopped server in check mode - cloudscale_server: - uuid: '{{ server.uuid }}' - name: '{{ cloudscale_resource_prefix }}-test' - flavor: '{{ cloudscale_test_flavor }}' - image: '{{ cloudscale_test_image }}' - ssh_keys: '{{ cloudscale_test_ssh_key }}' - state: stopped - register: server - check_mode: yes -- name: Verify update a stopped server in check mode - assert: - that: - - server is changed - - server.state == 'stopped' - - server.flavor.slug == '{{ cloudscale_test_flavor_2 }}' - - server.name == '{{ cloudscale_resource_prefix }}-test-renamed' - -- name: Test update a stopped server without force - cloudscale_server: - uuid: '{{ server.uuid }}' - name: '{{ cloudscale_resource_prefix }}-test' - flavor: '{{ cloudscale_test_flavor }}' - image: '{{ cloudscale_test_image }}' - ssh_keys: '{{ cloudscale_test_ssh_key }}' - state: stopped - register: server -- name: Verify update a stopped server without force - assert: - that: - - server is changed - - server.state == 'stopped' - - server.flavor.slug == '{{ cloudscale_test_flavor }}' - - server.name == '{{ cloudscale_resource_prefix }}-test' - - -- name: Test update a stopped server idempotence - cloudscale_server: - uuid: '{{ server.uuid }}' - name: '{{ cloudscale_resource_prefix }}-test' - flavor: '{{ cloudscale_test_flavor }}' - image: '{{ cloudscale_test_image }}' - ssh_keys: '{{ cloudscale_test_ssh_key }}' - state: stopped - register: server -- name: Verify update a stopped server idempotence - assert: - that: - - server is not changed - - server.state == 'stopped' - - server.flavor.slug == '{{ cloudscale_test_flavor }}' - - server.name == '{{ cloudscale_resource_prefix }}-test' - -- name: Test server running in check mode - cloudscale_server: - name: '{{ cloudscale_resource_prefix }}-test' - state: running - register: server - check_mode: yes -- name: Verify server running in check mode - assert: - that: - - server is changed - - server.state == 'stopped' - -- name: Test server running - cloudscale_server: - name: '{{ cloudscale_resource_prefix }}-test' - state: running - register: server -- name: Verify server running - assert: - that: - - server is changed - - server.state == 'running' - -- name: Test server running idempotence - cloudscale_server: - name: '{{ cloudscale_resource_prefix }}-test' - state: running - register: server -- name: Verify server running idempotence - assert: - that: - - server is not changed - - server.state == 'running' - -- name: Test running server deletion by name in check mode - cloudscale_server: - name: '{{ cloudscale_resource_prefix }}-test' - state: absent - register: server - check_mode: yes -- name: Verify running server deletion by name in check mode - assert: - that: - - server is changed - - server.state == 'running' - -- name: Test running server deletion by name - cloudscale_server: - name: '{{ cloudscale_resource_prefix }}-test' - state: absent - register: server -- name: Verify running server deletion by name - assert: - that: - - server is changed - - server.state == 'absent' - -- name: Test running server deletion by name idempotence - cloudscale_server: - name: '{{ cloudscale_resource_prefix }}-test' - state: absent - register: server -- name: Verify running server deletion by name idempotence - assert: - that: - - server is not changed - - server.state == 'absent' - -- name: Test stopped server deletion by uuid in check mode - cloudscale_server: - uuid: '{{ server_stopped.uuid }}' - state: absent - register: server_stopped - check_mode: yes -- name: Verify stopped server deletion by uuid in check mode - assert: - that: - - server_stopped is changed - - server_stopped.state == 'stopped' - -- name: Test stopped server deletion by uuid - cloudscale_server: - uuid: '{{ server_stopped.uuid }}' - state: absent - register: server_stopped -- name: Verify stopped server deletion by uuid - assert: - that: - - server_stopped is changed - - server_stopped.state == 'absent' - -- name: Test stopped server deletion by uuid idempotence - cloudscale_server: - uuid: '{{ server_stopped.uuid }}' - state: absent - register: server_stopped -- name: Verify stopped server deletion by uuid idempotence - assert: - that: - - server_stopped is not changed - - server_stopped.state == 'absent' +- block: + - import_tasks: tests.yml + always: + - import_role: + name: cloudscale_common + tasks_from: cleanup_servers diff --git a/test/integration/targets/cloudscale_server/tasks/tests.yml b/test/integration/targets/cloudscale_server/tasks/tests.yml new file mode 100644 index 0000000000..f784ea6af6 --- /dev/null +++ b/test/integration/targets/cloudscale_server/tasks/tests.yml @@ -0,0 +1,447 @@ +--- +- name: Test create a running server in check mode + cloudscale_server: + name: '{{ cloudscale_resource_prefix }}-test' + flavor: '{{ cloudscale_test_flavor }}' + image: '{{ cloudscale_test_image }}' + ssh_keys: '{{ cloudscale_test_ssh_key }}' + register: server + check_mode: yes +- name: Verify create a running server in check mode + assert: + that: + - server is changed + - server.state == 'absent' + +- name: Test create a running server + cloudscale_server: + name: '{{ cloudscale_resource_prefix }}-test' + flavor: '{{ cloudscale_test_flavor }}' + image: '{{ cloudscale_test_image }}' + ssh_keys: '{{ cloudscale_test_ssh_key }}' + register: server +- name: Verify create a running server + assert: + that: + - server is changed + - server.state == 'running' + +- name: Test create a running server idempotence + cloudscale_server: + name: '{{ cloudscale_resource_prefix }}-test' + flavor: '{{ cloudscale_test_flavor }}' + image: '{{ cloudscale_test_image }}' + ssh_keys: '{{ cloudscale_test_ssh_key }}' + register: server +- name: Verify create a running server idempotence + assert: + that: + - server is not changed + - server.state == 'running' + +- name: Test update flavor of a running server without force in check mode + cloudscale_server: + name: '{{ cloudscale_resource_prefix }}-test' + flavor: '{{ cloudscale_test_flavor_2 }}' + image: '{{ cloudscale_test_image }}' + ssh_keys: '{{ cloudscale_test_ssh_key }}' + force: no + register: server + check_mode: yes +- name: Verify update flavor of a running server without force in check mode + assert: + that: + - server is not changed + - server.state == 'running' + - server.flavor.slug == '{{ cloudscale_test_flavor }}' + +- name: Test update flavor of a running server without force + cloudscale_server: + name: '{{ cloudscale_resource_prefix }}-test' + flavor: '{{ cloudscale_test_flavor_2 }}' + image: '{{ cloudscale_test_image }}' + ssh_keys: '{{ cloudscale_test_ssh_key }}' + force: no + register: server +- name: Verify update flavor of a running server without force + assert: + that: + - server is not changed + - server.state == 'running' + - server.flavor.slug == '{{ cloudscale_test_flavor }}' + +- name: Test update flavor of a running server without force idempotence + cloudscale_server: + name: '{{ cloudscale_resource_prefix }}-test' + flavor: '{{ cloudscale_test_flavor_2 }}' + image: '{{ cloudscale_test_image }}' + ssh_keys: '{{ cloudscale_test_ssh_key }}' + force: no + register: server +- name: Verify update flavor of a running server without force idempotence + assert: + that: + - server is not changed + - server.state == 'running' + - server.flavor.slug == '{{ cloudscale_test_flavor }}' + +- name: Test update flavor and name of a running server without force in check mode + cloudscale_server: + uuid: '{{ server.uuid }}' + name: '{{ cloudscale_resource_prefix }}-test-renamed' + flavor: '{{ cloudscale_test_flavor_2 }}' + image: '{{ cloudscale_test_image }}' + ssh_keys: '{{ cloudscale_test_ssh_key }}' + force: no + register: server + check_mode: yes +- name: Verify update flavor and name of a running server without force in check mode + assert: + that: + - server is changed + - server.state == 'running' + - server.flavor.slug == '{{ cloudscale_test_flavor }}' + - server.name == '{{ cloudscale_resource_prefix }}-test' + +- name: Test update flavor and name of a running server without force + cloudscale_server: + uuid: '{{ server.uuid }}' + name: '{{ cloudscale_resource_prefix }}-test-renamed' + flavor: '{{ cloudscale_test_flavor_2 }}' + image: '{{ cloudscale_test_image }}' + ssh_keys: '{{ cloudscale_test_ssh_key }}' + force: no + register: server +- name: Verify update flavor and name of a running server without force + assert: + that: + - server is changed + - server.state == 'running' + - server.flavor.slug == '{{ cloudscale_test_flavor }}' + - server.name == '{{ cloudscale_resource_prefix }}-test-renamed' + +- name: Test update flavor and name of a running server without force idempotence + cloudscale_server: + uuid: '{{ server.uuid }}' + name: '{{ cloudscale_resource_prefix }}-test-renamed' + flavor: '{{ cloudscale_test_flavor_2 }}' + image: '{{ cloudscale_test_image }}' + ssh_keys: '{{ cloudscale_test_ssh_key }}' + force: no + register: server +- name: Verify update flavor and name of a running server without force idempotence + assert: + that: + - server is not changed + - server.state == 'running' + - server.flavor.slug == '{{ cloudscale_test_flavor }}' + - server.name == '{{ cloudscale_resource_prefix }}-test-renamed' + +- name: Test update flavor of a running server with force in check mode + cloudscale_server: + name: '{{ cloudscale_resource_prefix }}-test-renamed' + flavor: '{{ cloudscale_test_flavor_2 }}' + image: '{{ cloudscale_test_image }}' + ssh_keys: '{{ cloudscale_test_ssh_key }}' + force: yes + register: server + check_mode: yes +- name: Verify update flavor of a running server with force in check mode + assert: + that: + - server is changed + - server.state == 'running' + - server.flavor.slug == '{{ cloudscale_test_flavor }}' + - server.name == '{{ cloudscale_resource_prefix }}-test-renamed' + +- name: Test update flavor of a running server with force + cloudscale_server: + name: '{{ cloudscale_resource_prefix }}-test-renamed' + flavor: '{{ cloudscale_test_flavor_2 }}' + image: '{{ cloudscale_test_image }}' + ssh_keys: '{{ cloudscale_test_ssh_key }}' + force: yes + register: server +- name: Verify update flavor of a running server with force + assert: + that: + - server is changed + - server.state == 'running' + - server.flavor.slug == '{{ cloudscale_test_flavor_2 }}' + - server.name == '{{ cloudscale_resource_prefix }}-test-renamed' + +- name: Test update a running server with force idempotence + cloudscale_server: + name: '{{ cloudscale_resource_prefix }}-test-renamed' + flavor: '{{ cloudscale_test_flavor_2 }}' + image: '{{ cloudscale_test_image }}' + ssh_keys: '{{ cloudscale_test_ssh_key }}' + force: yes + register: server +- name: Verify update flavor of a running server with force idempotence + assert: + that: + - server is not changed + - server.state == 'running' + - server.flavor.slug == '{{ cloudscale_test_flavor_2 }}' + - server.name == '{{ cloudscale_resource_prefix }}-test-renamed' + +- name: Remember uuid of running server for anti affinity + set_fact: + running_server_uuid: '{{ server.uuid }}' + +- name: Test create server stopped in anti affinity and private network only in check mode + cloudscale_server: + name: '{{ cloudscale_resource_prefix }}-test-stopped' + flavor: '{{ cloudscale_test_flavor }}' + image: '{{ cloudscale_test_image }}' + ssh_keys: '{{ cloudscale_test_ssh_key }}' + anti_affinity_with: '{{ running_server_uuid }}' + use_public_network: no + use_private_network: yes + state: stopped + check_mode: yes + register: server_stopped +- name: Verify create server stopped in anti affinity and private network only in check mode + assert: + that: + - server_stopped is changed + - server_stopped.state == 'absent' + +- name: Test create server stopped in anti affinity and private network only + cloudscale_server: + name: '{{ cloudscale_resource_prefix }}-test-stopped' + flavor: '{{ cloudscale_test_flavor }}' + image: '{{ cloudscale_test_image }}' + ssh_keys: '{{ cloudscale_test_ssh_key }}' + anti_affinity_with: '{{ running_server_uuid }}' + use_public_network: no + use_private_network: yes + state: stopped + register: server_stopped +- name: Verify create server stopped in anti affinity and private network only + assert: + that: + - server_stopped is changed + - server_stopped.state == 'stopped' + - server_stopped.anti_affinity_with.0.uuid == running_server_uuid + - server_stopped.interfaces.0.type == 'private' + +- name: Test create server stopped in anti affinity and private network only idempotence + cloudscale_server: + name: '{{ cloudscale_resource_prefix }}-test-stopped' + flavor: '{{ cloudscale_test_flavor }}' + image: '{{ cloudscale_test_image }}' + ssh_keys: '{{ cloudscale_test_ssh_key }}' + anti_affinity_with: '{{ running_server_uuid }}' + use_public_network: no + use_private_network: yes + state: stopped + register: server_stopped +- name: Verify create server stopped in anti affinity and private network only idempotence + assert: + that: + - server_stopped is not changed + - server_stopped.state == 'stopped' + - server_stopped.anti_affinity_with.0.uuid == running_server_uuid + - server_stopped.interfaces.0.type == 'private' + +- name: Test create server failure without required parameters + cloudscale_server: + name: '{{ cloudscale_resource_prefix }}-test-failed' + register: server_failed + ignore_errors: yes +- name: Verify create server failure without required parameters + assert: + that: + - server_failed is failed + - "'missing required arguments' in server_failed.msg" + +- name: Test stop running server in check mode + cloudscale_server: + name: '{{ cloudscale_resource_prefix }}-test-renamed' + state: stopped + check_mode: yes + register: server +- name: Verify stop running server in check mode + assert: + that: + - server is changed + - server.state == 'running' + +- name: Test stop running server + cloudscale_server: + name: '{{ cloudscale_resource_prefix }}-test-renamed' + state: stopped + register: server +- name: Verify stop running server + assert: + that: + - server is changed + - server.state == 'stopped' + +- name: Test stop running server idempotence + cloudscale_server: + name: '{{ cloudscale_resource_prefix }}-test-renamed' + state: 'stopped' + register: server +- name: Verify stop running server idempotence + assert: + that: + - server is not changed + - server.state == 'stopped' + +- name: Test update a stopped server in check mode + cloudscale_server: + uuid: '{{ server.uuid }}' + name: '{{ cloudscale_resource_prefix }}-test' + flavor: '{{ cloudscale_test_flavor }}' + image: '{{ cloudscale_test_image }}' + ssh_keys: '{{ cloudscale_test_ssh_key }}' + state: stopped + register: server + check_mode: yes +- name: Verify update a stopped server in check mode + assert: + that: + - server is changed + - server.state == 'stopped' + - server.flavor.slug == '{{ cloudscale_test_flavor_2 }}' + - server.name == '{{ cloudscale_resource_prefix }}-test-renamed' + +- name: Test update a stopped server without force + cloudscale_server: + uuid: '{{ server.uuid }}' + name: '{{ cloudscale_resource_prefix }}-test' + flavor: '{{ cloudscale_test_flavor }}' + image: '{{ cloudscale_test_image }}' + ssh_keys: '{{ cloudscale_test_ssh_key }}' + state: stopped + register: server +- name: Verify update a stopped server without force + assert: + that: + - server is changed + - server.state == 'stopped' + - server.flavor.slug == '{{ cloudscale_test_flavor }}' + - server.name == '{{ cloudscale_resource_prefix }}-test' + + +- name: Test update a stopped server idempotence + cloudscale_server: + uuid: '{{ server.uuid }}' + name: '{{ cloudscale_resource_prefix }}-test' + flavor: '{{ cloudscale_test_flavor }}' + image: '{{ cloudscale_test_image }}' + ssh_keys: '{{ cloudscale_test_ssh_key }}' + state: stopped + register: server +- name: Verify update a stopped server idempotence + assert: + that: + - server is not changed + - server.state == 'stopped' + - server.flavor.slug == '{{ cloudscale_test_flavor }}' + - server.name == '{{ cloudscale_resource_prefix }}-test' + +- name: Test server running in check mode + cloudscale_server: + name: '{{ cloudscale_resource_prefix }}-test' + state: running + register: server + check_mode: yes +- name: Verify server running in check mode + assert: + that: + - server is changed + - server.state == 'stopped' + +- name: Test server running + cloudscale_server: + name: '{{ cloudscale_resource_prefix }}-test' + state: running + register: server +- name: Verify server running + assert: + that: + - server is changed + - server.state == 'running' + +- name: Test server running idempotence + cloudscale_server: + name: '{{ cloudscale_resource_prefix }}-test' + state: running + register: server +- name: Verify server running idempotence + assert: + that: + - server is not changed + - server.state == 'running' + +- name: Test running server deletion by name in check mode + cloudscale_server: + name: '{{ cloudscale_resource_prefix }}-test' + state: absent + register: server + check_mode: yes +- name: Verify running server deletion by name in check mode + assert: + that: + - server is changed + - server.state == 'running' + +- name: Test running server deletion by name + cloudscale_server: + name: '{{ cloudscale_resource_prefix }}-test' + state: absent + register: server +- name: Verify running server deletion by name + assert: + that: + - server is changed + - server.state == 'absent' + +- name: Test running server deletion by name idempotence + cloudscale_server: + name: '{{ cloudscale_resource_prefix }}-test' + state: absent + register: server +- name: Verify running server deletion by name idempotence + assert: + that: + - server is not changed + - server.state == 'absent' + +- name: Test stopped server deletion by uuid in check mode + cloudscale_server: + uuid: '{{ server_stopped.uuid }}' + state: absent + register: server_stopped + check_mode: yes +- name: Verify stopped server deletion by uuid in check mode + assert: + that: + - server_stopped is changed + - server_stopped.state == 'stopped' + +- name: Test stopped server deletion by uuid + cloudscale_server: + uuid: '{{ server_stopped.uuid }}' + state: absent + register: server_stopped +- name: Verify stopped server deletion by uuid + assert: + that: + - server_stopped is changed + - server_stopped.state == 'absent' + +- name: Test stopped server deletion by uuid idempotence + cloudscale_server: + uuid: '{{ server_stopped.uuid }}' + state: absent + register: server_stopped +- name: Verify stopped server deletion by uuid idempotence + assert: + that: + - server_stopped is not changed + - server_stopped.state == 'absent' diff --git a/test/integration/targets/cloudscale_volume/tasks/failures.yml b/test/integration/targets/cloudscale_volume/tasks/failures.yml index fd852b2b27..a1e8612171 100644 --- a/test/integration/targets/cloudscale_volume/tasks/failures.yml +++ b/test/integration/targets/cloudscale_volume/tasks/failures.yml @@ -24,12 +24,6 @@ that: - vol is failed -- name: Delete duplicate volumes by UUID - cloudscale_volume: - uuid: '{{ item.json.uuid }}' - state: 'absent' - with_items: '{{ duplicate.results }}' - - name: Fail volume creation with UUID cloudscale_volume: uuid: ea3b39a3-77a8-4d0b-881d-0bb00a1e7f48 @@ -57,7 +51,3 @@ assert: that: - vol is failed -- name: 'Delete volume' - cloudscale_volume: - name: '{{ cloudscale_resource_prefix }}-name-UUID' - state: 'absent' diff --git a/test/integration/targets/cloudscale_volume/tasks/main.yml b/test/integration/targets/cloudscale_volume/tasks/main.yml index 4e22c44df7..984f6e1a24 100644 --- a/test/integration/targets/cloudscale_volume/tasks/main.yml +++ b/test/integration/targets/cloudscale_volume/tasks/main.yml @@ -1,158 +1,11 @@ --- -- import_tasks: setup.yml - -- name: Create volume - cloudscale_volume: - name: '{{ cloudscale_resource_prefix }}-vol' - size_gb: 50 - register: vol -- name: 'VERIFY: Create volume' - assert: - that: - - vol is successful - - vol is changed - - vol.size_gb == 50 - - vol.name == '{{ cloudscale_resource_prefix }}-vol' - -- name: Create volume indempotence - cloudscale_volume: - name: '{{ cloudscale_resource_prefix }}-vol' - size_gb: 50 - register: vol -- name: 'VERIFY: Create volume indempotence' - assert: - that: - - vol is successful - - vol is not changed - -- name: Attach existing volume by name to server - cloudscale_volume: - name: '{{ cloudscale_resource_prefix }}-vol' - server_uuids: - - '{{ server.uuid }}' - register: vol -- name: 'VERIFY: Attach existing volume by name to server' - assert: - that: - - vol is successful - - vol is changed - - server.uuid in vol.server_uuids - -- name: Attach existing volume by name to server indempotence - cloudscale_volume: - name: '{{ cloudscale_resource_prefix }}-vol' - server_uuids: - - '{{ server.uuid }}' - register: vol -- name: 'VERIFY: Attach existing volume by name to server indempotence' - assert: - that: - - vol is successful - - vol is not changed - - server.uuid in vol.server_uuids - -- name: Resize attached volume by UUID - cloudscale_volume: - uuid: '{{ vol.uuid }}' - size_gb: 100 - register: vol -- name: 'VERIFY: Resize attached volume by UUID' - assert: - that: - - vol is successful - - vol is changed - - vol.size_gb == 100 - -- name: Resize attached volume by UUID indempotence - cloudscale_volume: - uuid: '{{ vol.uuid }}' - size_gb: 100 - register: vol -- name: 'VERIFY: Resize attached volume by UUID indempotence' - assert: - that: - - vol is successful - - vol is not changed - - vol.size_gb == 100 - -- name: Delete attached volume by UUID - cloudscale_volume: - uuid: '{{ vol.uuid }}' - state: 'absent' - register: deleted -- name: 'VERIFY: Delete attached volume by UUID' - assert: - that: - - deleted is successful - - deleted is changed - - deleted.state == 'absent' - -- name: Delete attached volume by UUID indempotence - cloudscale_volume: - uuid: '{{ vol.uuid }}' - state: 'absent' - register: deleted -- name: 'VERIFY: Delete attached volume by UUID indempotence' - assert: - that: - - deleted is successful - - deleted is not changed - - deleted.state == 'absent' - -- name: Create bulk volume and attach - cloudscale_volume: - name: '{{ cloudscale_resource_prefix }}-bulk' - type: bulk - size_gb: 100 - server_uuids: - - '{{ server.uuid }}' - register: bulk -- name: 'VERIFY: Create bulk volume and attach' - assert: - that: - - bulk is successful - - bulk is changed - - bulk.size_gb == 100 - - server.uuid in bulk.server_uuids - -- name: Detach volume by UUID - cloudscale_volume: - uuid: '{{ bulk.uuid }}' - server_uuids: [] - register: bulk -- name: 'VERIFY: Detach volume by UUID' - assert: - that: - - bulk is successful - - bulk is changed - - bulk.server_uuids == [] - -- name: Resize detached volume by name - cloudscale_volume: - name: '{{ bulk.name }}' - size_gb: 200 - register: bulk -- name: 'VERIFY: Resize detached volume by name' - assert: - that: - - bulk is successful - - bulk is changed - - bulk.size_gb == 200 - -- name: Delete volume by name - cloudscale_volume: - name: '{{ bulk.name }}' - state: 'absent' - register: bulk -- name: 'VERIFY: Delete volume by name' - assert: - that: - - bulk is successful - - bulk is changed - - bulk.state == 'absent' - -- import_tasks: failures.yml - -- import_tasks: check-mode.yml - -- import_tasks: cleanup.yml +- block: + - import_tasks: setup.yml + - import_tasks: tests.yml + always: + - import_role: + name: cloudscale_common + tasks_from: cleanup_servers + - import_role: + name: cloudscale_common + tasks_from: cleanup_volumes diff --git a/test/integration/targets/cloudscale_volume/tasks/tests.yml b/test/integration/targets/cloudscale_volume/tasks/tests.yml new file mode 100644 index 0000000000..8e93eab9af --- /dev/null +++ b/test/integration/targets/cloudscale_volume/tasks/tests.yml @@ -0,0 +1,154 @@ +--- +- name: Create volume + cloudscale_volume: + name: '{{ cloudscale_resource_prefix }}-vol' + size_gb: 50 + register: vol +- name: 'VERIFY: Create volume' + assert: + that: + - vol is successful + - vol is changed + - vol.size_gb == 50 + - vol.name == '{{ cloudscale_resource_prefix }}-vol' + +- name: Create volume indempotence + cloudscale_volume: + name: '{{ cloudscale_resource_prefix }}-vol' + size_gb: 50 + register: vol +- name: 'VERIFY: Create volume indempotence' + assert: + that: + - vol is successful + - vol is not changed + +- name: Attach existing volume by name to server + cloudscale_volume: + name: '{{ cloudscale_resource_prefix }}-vol' + server_uuids: + - '{{ server.uuid }}' + register: vol +- name: 'VERIFY: Attach existing volume by name to server' + assert: + that: + - vol is successful + - vol is changed + - server.uuid in vol.server_uuids + +- name: Attach existing volume by name to server indempotence + cloudscale_volume: + name: '{{ cloudscale_resource_prefix }}-vol' + server_uuids: + - '{{ server.uuid }}' + register: vol +- name: 'VERIFY: Attach existing volume by name to server indempotence' + assert: + that: + - vol is successful + - vol is not changed + - server.uuid in vol.server_uuids + +- name: Resize attached volume by UUID + cloudscale_volume: + uuid: '{{ vol.uuid }}' + size_gb: 100 + register: vol +- name: 'VERIFY: Resize attached volume by UUID' + assert: + that: + - vol is successful + - vol is changed + - vol.size_gb == 100 + +- name: Resize attached volume by UUID indempotence + cloudscale_volume: + uuid: '{{ vol.uuid }}' + size_gb: 100 + register: vol +- name: 'VERIFY: Resize attached volume by UUID indempotence' + assert: + that: + - vol is successful + - vol is not changed + - vol.size_gb == 100 + +- name: Delete attached volume by UUID + cloudscale_volume: + uuid: '{{ vol.uuid }}' + state: 'absent' + register: deleted +- name: 'VERIFY: Delete attached volume by UUID' + assert: + that: + - deleted is successful + - deleted is changed + - deleted.state == 'absent' + +- name: Delete attached volume by UUID indempotence + cloudscale_volume: + uuid: '{{ vol.uuid }}' + state: 'absent' + register: deleted +- name: 'VERIFY: Delete attached volume by UUID indempotence' + assert: + that: + - deleted is successful + - deleted is not changed + - deleted.state == 'absent' + +- name: Create bulk volume and attach + cloudscale_volume: + name: '{{ cloudscale_resource_prefix }}-bulk' + type: bulk + size_gb: 100 + server_uuids: + - '{{ server.uuid }}' + register: bulk +- name: 'VERIFY: Create bulk volume and attach' + assert: + that: + - bulk is successful + - bulk is changed + - bulk.size_gb == 100 + - server.uuid in bulk.server_uuids + +- name: Detach volume by UUID + cloudscale_volume: + uuid: '{{ bulk.uuid }}' + server_uuids: [] + register: bulk +- name: 'VERIFY: Detach volume by UUID' + assert: + that: + - bulk is successful + - bulk is changed + - bulk.server_uuids == [] + +- name: Resize detached volume by name + cloudscale_volume: + name: '{{ bulk.name }}' + size_gb: 200 + register: bulk +- name: 'VERIFY: Resize detached volume by name' + assert: + that: + - bulk is successful + - bulk is changed + - bulk.size_gb == 200 + +- name: Delete volume by name + cloudscale_volume: + name: '{{ bulk.name }}' + state: 'absent' + register: bulk +- name: 'VERIFY: Delete volume by name' + assert: + that: + - bulk is successful + - bulk is changed + - bulk.state == 'absent' + +- import_tasks: failures.yml + +- import_tasks: check-mode.yml diff --git a/test/legacy/cloudscale.yml b/test/legacy/cloudscale.yml deleted file mode 100644 index b0eb5b3897..0000000000 --- a/test/legacy/cloudscale.yml +++ /dev/null @@ -1,7 +0,0 @@ -- hosts: localhost - connection: local - gather_facts: no - tags: - - cloudscale - roles: - - { role: cloudscale_floating_ip, tags: cloudscale_floating_ip } diff --git a/test/legacy/roles/cloudscale_floating_ip/defaults/main.yml b/test/legacy/roles/cloudscale_floating_ip/defaults/main.yml deleted file mode 100644 index f318a20f64..0000000000 --- a/test/legacy/roles/cloudscale_floating_ip/defaults/main.yml +++ /dev/null @@ -1,5 +0,0 @@ ---- -cloudscale_test_flavor: flex-2 -cloudscale_test_image: debian-9 -cloudscale_test_ssh_key: | - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDSPmiqkvDH1/+MDAVDZT8381aYqp73Odz8cnD5hegNhqtXajqtiH0umVg7HybX3wt1HjcrwKJovZURcIbbcDvzdH2bnYbF93T4OLXA0bIfuIp6M86x1iutFtXdpN3TTicINrmSXEE2Ydm51iMu77B08ZERjVaToya2F7vC+egfoPvibf7OLxE336a5tPCywavvNihQjL8sjgpDT5AAScjb3YqK/6VLeQ18Ggt8/ufINsYkb+9/Ji/3OcGFeflnDXq80vPUyF3u4iIylob6RSZenC38cXmQB05tRNxS1B6BXCjMRdy0v4pa7oKM2GA4ADKpNrr0RI9ed+peRFwmsclH test@ansible diff --git a/test/legacy/roles/cloudscale_floating_ip/meta/main.yml b/test/legacy/roles/cloudscale_floating_ip/meta/main.yml deleted file mode 100644 index 07faa21776..0000000000 --- a/test/legacy/roles/cloudscale_floating_ip/meta/main.yml +++ /dev/null @@ -1,2 +0,0 @@ -dependencies: - - prepare_tests