diff --git a/plugins/doc_fragments/cloud.py b/plugins/doc_fragments/cloud.py index aec1cd1..54e6cad 100644 --- a/plugins/doc_fragments/cloud.py +++ b/plugins/doc_fragments/cloud.py @@ -10,7 +10,7 @@ class ModuleDocFragment: api_key: description: - GCore API auth key - - Can be passed as I(CLOUD_API_HOST) environment variable. + - Can be passed as I(CLOUD_API_KEY) environment variable. type: str api_timeout: description: diff --git a/tests/integration/targets/instance/tasks/tests.yml b/tests/integration/targets/instance/tasks/tests.yml index e51bcb7..b93420f 100644 --- a/tests/integration/targets/instance/tasks/tests.yml +++ b/tests/integration/targets/instance/tasks/tests.yml @@ -34,8 +34,8 @@ ansible.builtin.assert: that: - created_instance.data.status == "ACTIVE" - - created_instance.data.instance_name == "{{ instance_name }}" - - created_instance.data.flavor.flavor_name == "{{ instance_flavor }}" + - created_instance.data.instance_name == instance_name + - created_instance.data.flavor.flavor_name == instance_flavor - name: Update instance's name gcore.cloud.instance: @@ -50,4 +50,4 @@ - name: Verify new instance name ansible.builtin.assert: that: - - updated_instance.data.instance_name == "{{ new_instance_name }}" + - updated_instance.data.instance_name == new_instance_name diff --git a/tests/integration/targets/common/tasks/cleanup_keypairs.yml b/tests/integration/targets/keypair/tasks/cleanup.yml similarity index 100% rename from tests/integration/targets/common/tasks/cleanup_keypairs.yml rename to tests/integration/targets/keypair/tasks/cleanup.yml diff --git a/tests/integration/targets/keypair/tasks/main.yml b/tests/integration/targets/keypair/tasks/main.yml index 45da808..aa49caf 100644 --- a/tests/integration/targets/keypair/tasks/main.yml +++ b/tests/integration/targets/keypair/tasks/main.yml @@ -19,7 +19,7 @@ - name: Verify created keypair ansible.builtin.assert: that: - - created_keypair.data.sshkey_name == "{{ keypair_name }}" + - created_keypair.data.sshkey_name == keypair_name - created_keypair.data.state == "ACTIVE" - created_keypair.data.shared_in_project == true @@ -48,4 +48,4 @@ always: - name: Cleanup keypairs - import_tasks: ./targets/common/tasks/cleanup_keypairs.yml + import_tasks: cleanup.yml diff --git a/tests/integration/targets/common/tasks/cleanup_lifecycle_policy.yml b/tests/integration/targets/lifecycle_policy/tasks/cleanup.yml similarity index 100% rename from tests/integration/targets/common/tasks/cleanup_lifecycle_policy.yml rename to tests/integration/targets/lifecycle_policy/tasks/cleanup.yml diff --git a/tests/integration/targets/lifecycle_policy/tasks/cleanup_volumes.yml b/tests/integration/targets/lifecycle_policy/tasks/cleanup_volumes.yml new file mode 100644 index 0000000..ed80736 --- /dev/null +++ b/tests/integration/targets/lifecycle_policy/tasks/cleanup_volumes.yml @@ -0,0 +1,30 @@ +--- +- vars: + api_key: "{{ API_KEY }}" + api_host: "{{ API_HOST }}" + project_id: "{{ PROJECT_ID }}" + region_id: "{{ REGION_ID }}" + + block: + - name: List all test volumes + gcore.cloud.volume_info: + api_key: "{{ api_key }}" + api_host: "{{ api_host }}" + project_id: "{{ project_id }}" + region_id: "{{ region_id }}" + register: list_volumes + + - name: Delete all test volumes + gcore.cloud.volume: + api_key: "{{ api_key }}" + api_host: "{{ api_host }}" + project_id: "{{ project_id }}" + region_id: "{{ region_id }}" + command: delete + volume_id: "{{ item.id }}" + ignore_errors: True + when: + - item.name.startswith('test_ansible') + with_items: "{{ list_volumes.data }}" + loop_control: + label: "{{ item.name }} ({{ item.id }})" diff --git a/tests/integration/targets/lifecycle_policy/tasks/tests.yml b/tests/integration/targets/lifecycle_policy/tasks/tests.yml index dc1621b..250e63f 100644 --- a/tests/integration/targets/lifecycle_policy/tasks/tests.yml +++ b/tests/integration/targets/lifecycle_policy/tasks/tests.yml @@ -24,7 +24,7 @@ - name: Verify policy ansible.builtin.assert: that: - - created_policy.data["name"] == "{{ policy_name }}" + - created_policy.data["name"] == policy_name - name: Update policy gcore.cloud.lifecycle_policy: @@ -36,7 +36,7 @@ lifecycle_policy_id: "{{ created_policy.data.id }}" name: "{{ new_policy_name }}" register: updated_policy - + - name: Get policy by id gcore.cloud.lifecycle_policy_info: api_key: "{{ api_key }}" @@ -45,13 +45,13 @@ region_id: "{{ region_id }}" lifecycle_policy_id: "{{ updated_policy.data.id }}" register: policy - + - name: Verify policy ansible.builtin.assert: that: - - policy.data.name == "{{ new_policy_name }}" - - policy.data.action == "{{ policy_action }}" - + - policy.data.name == new_policy_name + - policy.data.action == policy_action + - name: Add volume to policy gcore.cloud.lifecycle_policy: api_key: "{{ api_key }}" @@ -75,11 +75,11 @@ - name: Validate policies volumes ansible.builtin.assert: that: - - policy_with_volumes.data.volumes[0].volume_id == "{{ created_volume.data.id }}" - - policy_with_volumes.data.volumes[0].volume_name == "{{ created_volume.data.name }}" + - policy_with_volumes.data.volumes[0].volume_id == created_volume.data.id + - policy_with_volumes.data.volumes[0].volume_name == created_volume.data.name always: - name: Cleanup policies - import_tasks: ./targets/common/tasks/cleanup_lifecycle_policy.yml + import_tasks: cleanup.yml - name: Cleanup volumes - import_tasks: ./targets/common/tasks/cleanup_volumes.yml + import_tasks: cleanup_volumes.yml diff --git a/tests/integration/targets/loadbalancer/tasks/tests.yml b/tests/integration/targets/loadbalancer/tasks/tests.yml index 4e24fdc..a8b6505 100644 --- a/tests/integration/targets/loadbalancer/tasks/tests.yml +++ b/tests/integration/targets/loadbalancer/tasks/tests.yml @@ -20,7 +20,7 @@ - name: Verify loadbalancer ansible.builtin.assert: that: - - created_loadbalancer.data.name == "{{ loadbalancer_name }}" + - created_loadbalancer.data.name == loadbalancer_name - name: Update existing loadbalancer's name gcore.cloud.loadbalancer: @@ -35,7 +35,7 @@ - name: Verify name updated ansible.builtin.assert: that: - - updated_loadbalancer.data.name == "{{ new_loadbalancer_name }}" + - updated_loadbalancer.data.name == new_loadbalancer_name - name: Get loadbalancer with stats gcore.cloud.loadbalancer_info: @@ -50,4 +50,4 @@ - name: Verify get loadbalancer with params ansible.builtin.assert: that: - - loadbalancer_with_stats.data.stats.active_connections == 0 \ No newline at end of file + - loadbalancer_with_stats.data.stats.active_connections == 0 diff --git a/tests/integration/targets/loadbalancer_listener/tasks/tests.yml b/tests/integration/targets/loadbalancer_listener/tasks/tests.yml index 234a477..f265899 100644 --- a/tests/integration/targets/loadbalancer_listener/tasks/tests.yml +++ b/tests/integration/targets/loadbalancer_listener/tasks/tests.yml @@ -24,8 +24,8 @@ - name: Verify lb listener ansible.builtin.assert: that: - - created_lb_listener.data.name == "{{ lb_listener_name }}" - - created_lb_listener.data.protocol == "{{ listener_protocol }}" + - created_lb_listener.data.name == lb_listener_name + - created_lb_listener.data.protocol == listener_protocol - name: Update listener's name gcore.cloud.loadbalancer_listener: @@ -40,4 +40,4 @@ - name: Verify new listener name ansible.builtin.assert: that: - - updated_lb_listener.data.name == "{{ new_lb_listener_name }}" + - updated_lb_listener.data.name == new_lb_listener_name diff --git a/tests/integration/targets/network/tasks/tests.yml b/tests/integration/targets/network/tasks/tests.yml index aa91717..426de04 100644 --- a/tests/integration/targets/network/tasks/tests.yml +++ b/tests/integration/targets/network/tasks/tests.yml @@ -21,7 +21,7 @@ - name: Verify network ansible.builtin.assert: that: - - created_network.data.name == "{{ network_name }}" + - created_network.data.name == network_name - created_network.data.type == "vxlan" - created_network.data.metadata[0].key == "ansible_key" @@ -38,4 +38,4 @@ - name: Verify name updated ansible.builtin.assert: that: - - updated_network.data.name == "{{ new_network_name }}" + - updated_network.data.name == new_network_name diff --git a/tests/integration/targets/common/tasks/cleanup_reserved_fixed_ips.yml b/tests/integration/targets/reserved_fixed_ip/tasks/cleanup.yml similarity index 100% rename from tests/integration/targets/common/tasks/cleanup_reserved_fixed_ips.yml rename to tests/integration/targets/reserved_fixed_ip/tasks/cleanup.yml diff --git a/tests/integration/targets/reserved_fixed_ip/tasks/main.yml b/tests/integration/targets/reserved_fixed_ip/tasks/main.yml index 4bd39bc..d8adc99 100644 --- a/tests/integration/targets/reserved_fixed_ip/tasks/main.yml +++ b/tests/integration/targets/reserved_fixed_ip/tasks/main.yml @@ -50,4 +50,4 @@ always: - name: Cleanup reserved fixed ips - import_tasks: ./targets/common/tasks/cleanup_reserved_fixed_ips.yml + import_tasks: cleanup.yml diff --git a/tests/integration/targets/router/tasks/tests.yml b/tests/integration/targets/router/tasks/tests.yml index d68337e..a56326b 100644 --- a/tests/integration/targets/router/tasks/tests.yml +++ b/tests/integration/targets/router/tasks/tests.yml @@ -20,7 +20,7 @@ - name: Verify router ansible.builtin.assert: that: - - created_router.data.name == "{{ router_name }}" + - created_router.data.name == router_name - name: Update router gcore.cloud.router: @@ -35,4 +35,4 @@ - name: Verify router updating ansible.builtin.assert: that: - - updated_router.data.name == "{{ updated_router_name }}" + - updated_router.data.name == updated_router_name diff --git a/tests/integration/targets/common/tasks/cleanup_secrets.yml b/tests/integration/targets/secret/tasks/cleanup.yml similarity index 100% rename from tests/integration/targets/common/tasks/cleanup_secrets.yml rename to tests/integration/targets/secret/tasks/cleanup.yml diff --git a/tests/integration/targets/secret/tasks/main.yml b/tests/integration/targets/secret/tasks/main.yml index 8bcea38..30f4882 100644 --- a/tests/integration/targets/secret/tasks/main.yml +++ b/tests/integration/targets/secret/tasks/main.yml @@ -25,8 +25,8 @@ - name: Verify secret ansible.builtin.assert: that: - - created_secret.data.name == "{{ secret_name }}" + - created_secret.data.name == secret_name always: - name: Cleanup secrets - import_tasks: ./targets/common/tasks/cleanup_secrets.yml + import_tasks: cleanup.yml diff --git a/tests/integration/targets/securitygroup/tasks/cleanup.yml b/tests/integration/targets/securitygroup/tasks/cleanup.yml new file mode 100644 index 0000000..17decc8 --- /dev/null +++ b/tests/integration/targets/securitygroup/tasks/cleanup.yml @@ -0,0 +1,30 @@ +--- +- vars: + api_key: "{{ API_KEY }}" + api_host: "{{ API_HOST }}" + project_id: "{{ PROJECT_ID }}" + region_id: "{{ REGION_ID }}" + + block: + - name: List all test securitygroups + gcore.cloud.securitygroup_info: + api_key: "{{ api_key }}" + api_host: "{{ api_host }}" + project_id: "{{ project_id }}" + region_id: "{{ region_id }}" + register: list_securitygroups + + - name: Delete all test securitygroups + gcore.cloud.securitygroup: + api_key: "{{ api_key }}" + api_host: "{{ api_host }}" + project_id: "{{ project_id }}" + region_id: "{{ region_id }}" + command: delete + securitygroup_id: "{{ item.id }}" + ignore_errors: True + when: + - item.name.startswith('test_ansible') + with_items: "{{ list_securitygroups.data }}" + loop_control: + label: "{{ item.name }} ({{ item.id }})" diff --git a/tests/integration/targets/securitygroup/tasks/main.yml b/tests/integration/targets/securitygroup/tasks/main.yml index c3912c3..4603eeb 100644 --- a/tests/integration/targets/securitygroup/tasks/main.yml +++ b/tests/integration/targets/securitygroup/tasks/main.yml @@ -26,7 +26,7 @@ - name: Verify securitygroup ansible.builtin.assert: that: - - created_securitygroup.data.name == "{{ securitygroup_name }}" + - created_securitygroup.data.name == securitygroup_name - created_securitygroup.data.security_group_rules | list | length >= 1 - name: Update securitygroup @@ -42,7 +42,7 @@ - name: Verify updating securitygroup ansible.builtin.assert: that: - - updated_securitygroup.data.name == "{{ updated_securitygroup_name }}" + - updated_securitygroup.data.name == updated_securitygroup_name - name: Copy securitygroup gcore.cloud.securitygroup: @@ -57,8 +57,8 @@ - name: Verify securitygroup copy ansible.builtin.assert: that: - - copied_securitygroup.data.name == "{{ copied_securitygroup_name }}" - + - copied_securitygroup.data.name == copied_securitygroup_name + - name: Get list securitygroup gcore.cloud.securitygroup_info: api_key: "{{ api_key }}" @@ -82,8 +82,8 @@ - name: Verify securitygroup ansible.builtin.assert: that: - - copied_securitygroup.data.name == "{{ copied_securitygroup_name }}" + - copied_securitygroup.data.name == copied_securitygroup_name always: - name: Cleanup securitygroups - import_tasks: ./targets/common/tasks/cleanup_securitygroups.yml + import_tasks: cleanup.yml diff --git a/tests/integration/targets/securitygroup_rule/tasks/cleanup.yml b/tests/integration/targets/securitygroup_rule/tasks/cleanup.yml new file mode 100644 index 0000000..17decc8 --- /dev/null +++ b/tests/integration/targets/securitygroup_rule/tasks/cleanup.yml @@ -0,0 +1,30 @@ +--- +- vars: + api_key: "{{ API_KEY }}" + api_host: "{{ API_HOST }}" + project_id: "{{ PROJECT_ID }}" + region_id: "{{ REGION_ID }}" + + block: + - name: List all test securitygroups + gcore.cloud.securitygroup_info: + api_key: "{{ api_key }}" + api_host: "{{ api_host }}" + project_id: "{{ project_id }}" + region_id: "{{ region_id }}" + register: list_securitygroups + + - name: Delete all test securitygroups + gcore.cloud.securitygroup: + api_key: "{{ api_key }}" + api_host: "{{ api_host }}" + project_id: "{{ project_id }}" + region_id: "{{ region_id }}" + command: delete + securitygroup_id: "{{ item.id }}" + ignore_errors: True + when: + - item.name.startswith('test_ansible') + with_items: "{{ list_securitygroups.data }}" + loop_control: + label: "{{ item.name }} ({{ item.id }})" diff --git a/tests/integration/targets/securitygroup_rule/tasks/tests.yml b/tests/integration/targets/securitygroup_rule/tasks/tests.yml index 3cc5ca4..715e59e 100644 --- a/tests/integration/targets/securitygroup_rule/tasks/tests.yml +++ b/tests/integration/targets/securitygroup_rule/tasks/tests.yml @@ -20,7 +20,7 @@ - name: Verify rule ansible.builtin.assert: that: - - created_rule.data.security_group_id == "{{ created_securitygroup.data.id }}" + - created_rule.data.security_group_id == created_securitygroup.data.id - created_rule.data.direction == "ingress" - created_rule.data.ethertype == "IPv4" @@ -62,4 +62,4 @@ always: - name: Cleanup securitygroups - import_tasks: ./targets/common/tasks/cleanup_securitygroups.yml + import_tasks: cleanup.yml diff --git a/tests/integration/targets/common/tasks/cleanup_servergroups.yml b/tests/integration/targets/servergroup/tasks/cleanup.yml similarity index 100% rename from tests/integration/targets/common/tasks/cleanup_servergroups.yml rename to tests/integration/targets/servergroup/tasks/cleanup.yml diff --git a/tests/integration/targets/servergroup/tasks/main.yml b/tests/integration/targets/servergroup/tasks/main.yml index e66a68a..d0d551a 100644 --- a/tests/integration/targets/servergroup/tasks/main.yml +++ b/tests/integration/targets/servergroup/tasks/main.yml @@ -21,8 +21,8 @@ - name: Verify servergroup ansible.builtin.assert: that: - - created_servergroup.data.name == "{{ servergroup_name }}" - - created_servergroup.data.policy == "{{ servergroup_policy }}" + - created_servergroup.data.name == servergroup_name + - created_servergroup.data.policy == servergroup_policy - created_servergroup.data.instances | list | length == 0 - name: Get servergroup list @@ -40,4 +40,4 @@ always: - name: Cleanup servergroups - import_tasks: ./targets/common/tasks/cleanup_servergroups.yml + import_tasks: cleanup.yml diff --git a/tests/integration/targets/subnet/tasks/tests.yml b/tests/integration/targets/subnet/tasks/tests.yml index d897c39..66b0104 100644 --- a/tests/integration/targets/subnet/tasks/tests.yml +++ b/tests/integration/targets/subnet/tasks/tests.yml @@ -28,11 +28,11 @@ - name: Verify subnet ansible.builtin.assert: that: - - created_subnet.data.name == "{{ subnet_name }}" + - created_subnet.data.name == subnet_name - created_subnet.data.has_router == false - created_subnet.data.dns_nameservers == ['8.8.8.8', '8.8.4.4'] - - created_subnet.data.cidr == "{{ subnet_cidr }}" - - created_subnet.data.network_id == "{{ created_network.data.id }}" + - created_subnet.data.cidr == subnet_cidr + - created_subnet.data.network_id == created_network.data.id - created_subnet.data.metadata[0].key == "ansible_key" - name: Update existing subnet @@ -50,11 +50,11 @@ - name: Verify updated subnet ansible.builtin.assert: that: - - updated_subnet.data.name == "{{ new_subnet_name }}" - - updated_subnet.data.dns_nameservers == {{ dns_nameservers }} + - updated_subnet.data.name == new_subnet_name + - updated_subnet.data.dns_nameservers == dns_nameservers - updated_subnet.data.enable_dhcp == false - updated_subnet.data.host_routes | list | length == 0 - + - name: Update routes for subnet gcore.cloud.subnet: api_key: "{{ api_key }}" @@ -69,9 +69,3 @@ ansible.builtin.assert: that: - subnet_with_routes.data.host_routes | list | length == 1 - - always: - - name: Cleanup subnets - import_tasks: ./targets/common/tasks/cleanup_subnets.yml - - name: Cleanup newtworks - import_tasks: ./targets/common/tasks/cleanup_networks.yml diff --git a/tests/integration/targets/volume/tasks/main.yml b/tests/integration/targets/volume/tasks/main.yml index 48a6b4e..a2fb2ca 100644 --- a/tests/integration/targets/volume/tasks/main.yml +++ b/tests/integration/targets/volume/tasks/main.yml @@ -3,4 +3,4 @@ - import_tasks: tests.yml always: - name: Cleanup volumes - import_tasks: ./targets/common/tasks/cleanup_volumes.yml + import_tasks: cleanup.yml diff --git a/tests/integration/targets/volume/tasks/tests.yml b/tests/integration/targets/volume/tasks/tests.yml index f42049c..79d5118 100644 --- a/tests/integration/targets/volume/tasks/tests.yml +++ b/tests/integration/targets/volume/tasks/tests.yml @@ -27,9 +27,9 @@ - name: Verify volume ansible.builtin.assert: that: - - created_volume.data.name == "{{ volume_name }}" + - created_volume.data.name == volume_name - created_volume.data.size == 1 - - created_volume.data.volume_type == "{{ volume_type_name }}" + - created_volume.data.volume_type == volume_type_name - created_volume.data.metadata.ansible_key == "ansible_value" - name: Get volume by ID @@ -54,7 +54,7 @@ - name: Verify volume's rename ansible.builtin.assert: that: - - updated_volume.data.name == "{{ updated_volume_name }}" + - updated_volume.data.name == updated_volume_name - name: Extend existing volume gcore.cloud.volume: @@ -70,7 +70,7 @@ ansible.builtin.assert: that: - extended_volume.data.size == 2 - + - name: Retype existing volume gcore.cloud.volume: api_key: "{{ api_key }}" @@ -80,7 +80,7 @@ command: retype volume_id: "{{ extended_volume.data.id }}" volume_type: "{{ new_volume_type_name }}" - + - name: Wait for retyping ansible.builtin.pause: seconds: 10 @@ -96,4 +96,4 @@ - name: Verify volume's new type ansible.builtin.assert: that: - - retyped_volume.data.volume_type == "{{ new_volume_type_name }}" + - retyped_volume.data.volume_type == new_volume_type_name diff --git a/tests/integration/targets/volume_snapshot/tasks/main.yml b/tests/integration/targets/volume_snapshot/tasks/main.yml index ff07890..db502a9 100644 --- a/tests/integration/targets/volume_snapshot/tasks/main.yml +++ b/tests/integration/targets/volume_snapshot/tasks/main.yml @@ -3,5 +3,5 @@ - import_tasks: setup.yml - import_tasks: tests.yml always: - - name: Cleanup subnets + - name: Cleanup volumes snapshots and volumes include_tasks: cleanup.yml diff --git a/tests/integration/targets/volume_snapshot/tasks/tests.yml b/tests/integration/targets/volume_snapshot/tasks/tests.yml index 3d32223..a5727db 100644 --- a/tests/integration/targets/volume_snapshot/tasks/tests.yml +++ b/tests/integration/targets/volume_snapshot/tasks/tests.yml @@ -15,7 +15,7 @@ region_id: "{{ region_id }}" volume_id: "{{ created_volume.data.id }}" register: find_volume - + - name: Create new snapshot gcore.cloud.volume_snapshot: api_key: "{{ api_key }}" @@ -29,7 +29,7 @@ - name: Verify snapshot ansible.builtin.assert: that: - - created_snapshot.data.name == "{{ snapshot_name }}" + - created_snapshot.data.name == snapshot_name - name: Get snapshot by its volume id gcore.cloud.volume_snapshot_info: @@ -54,9 +54,3 @@ - volume.data.snapshot_ids | list | length == 1 - volume.data.snapshot_ids[0] == find_snapshot.data[0]['id'] - volume.data.id == find_snapshot.data[0].volume_id - - always: - - name: Cleanup volumes snapshots - import_tasks: ./targets/common/tasks/cleanup_volume_snapshots.yml - - name: Cleanup volumes - import_tasks: ./targets/common/tasks/cleanup_volumes.yml