From 5137bd59587ae6ab9d32643fd5436fe697f8a9f8 Mon Sep 17 00:00:00 2001 From: Alex Stephen Date: Wed, 16 Jan 2019 09:58:57 -0800 Subject: [PATCH] Bug fixes for GCP modules (as of 2019-01-09T15:35:45-08:00) (#50786) --- .../google/gcp_pubsub_subscription_facts.py | 2 +- .../cloud/google/gcp_spanner_database.py | 11 +++---- .../google/gcp_spanner_database_facts.py | 11 +++---- .../modules/cloud/google/gcp_sql_database.py | 13 ++++---- .../cloud/google/gcp_sql_database_facts.py | 11 +++---- .../modules/cloud/google/gcp_sql_instance.py | 14 ++++---- .../cloud/google/gcp_sql_instance_facts.py | 6 ++-- .../modules/cloud/google/gcp_sql_user.py | 13 ++++---- .../cloud/google/gcp_sql_user_facts.py | 11 +++---- .../cloud/google/gcp_storage_bucket.py | 22 ++++++------- .../gcp_storage_bucket_access_control.py | 13 ++++---- .../targets/gcp_pubsub_topic/tasks/main.yml | 4 +-- .../gcp_spanner_database/tasks/main.yml | 26 ++++++++++----- .../gcp_spanner_instance/tasks/main.yml | 22 ++++++++----- .../targets/gcp_sql_database/tasks/main.yml | 30 +++++++++++------ .../targets/gcp_sql_instance/tasks/main.yml | 32 +++++++++++-------- .../targets/gcp_sql_user/tasks/main.yml | 14 ++++---- .../tasks/main.yml | 6 ++-- 18 files changed, 142 insertions(+), 119 deletions(-) diff --git a/lib/ansible/modules/cloud/google/gcp_pubsub_subscription_facts.py b/lib/ansible/modules/cloud/google/gcp_pubsub_subscription_facts.py index ea1f16dd7dc..50272b74c37 100644 --- a/lib/ansible/modules/cloud/google/gcp_pubsub_subscription_facts.py +++ b/lib/ansible/modules/cloud/google/gcp_pubsub_subscription_facts.py @@ -67,7 +67,7 @@ items: description: - A reference to a Topic resource. returned: success - type: dict + type: str pushConfig: description: - If push delivery is used with this subscription, this field is used to configure diff --git a/lib/ansible/modules/cloud/google/gcp_spanner_database.py b/lib/ansible/modules/cloud/google/gcp_spanner_database.py index 00bf487c43c..1435fc4d878 100644 --- a/lib/ansible/modules/cloud/google/gcp_spanner_database.py +++ b/lib/ansible/modules/cloud/google/gcp_spanner_database.py @@ -65,10 +65,9 @@ options: description: - The instance to create the database on. - 'This field represents a link to a Instance resource in GCP. It can be specified - in two ways. You can add `register: name-of-resource` to a gcp_spanner_instance - task and then set this instance field to "{{ name-of-resource }}" Alternatively, - you can set this instance to a dictionary with the name key where the value - is the name of your Instance' + in two ways. First, you can place in the name of the resource here as a string + Alternatively, you can add `register: name-of-resource` to a gcp_spanner_instance + task and then set this instance field to "{{ name-of-resource }}"' required: true extends_documentation_fragment: gcp ''' @@ -118,7 +117,7 @@ instance: description: - The instance to create the database on. returned: success - type: dict + type: str ''' ################################################################################ @@ -141,7 +140,7 @@ def main(): state=dict(default='present', choices=['present', 'absent'], type='str'), name=dict(type='str'), extra_statements=dict(type='list', elements='str'), - instance=dict(required=True, type='dict') + instance=dict(required=True) ) ) diff --git a/lib/ansible/modules/cloud/google/gcp_spanner_database_facts.py b/lib/ansible/modules/cloud/google/gcp_spanner_database_facts.py index 87e866a5e1b..d781a9e9925 100644 --- a/lib/ansible/modules/cloud/google/gcp_spanner_database_facts.py +++ b/lib/ansible/modules/cloud/google/gcp_spanner_database_facts.py @@ -45,10 +45,9 @@ options: description: - The instance to create the database on. - 'This field represents a link to a Instance resource in GCP. It can be specified - in two ways. You can add `register: name-of-resource` to a gcp_spanner_instance - task and then set this instance field to "{{ name-of-resource }}" Alternatively, - you can set this instance to a dictionary with the name key where the value - is the name of your Instance' + in two ways. First, you can place in the name of the resource here as a string + Alternatively, you can add `register: name-of-resource` to a gcp_spanner_instance + task and then set this instance field to "{{ name-of-resource }}"' required: true extends_documentation_fragment: gcp ''' @@ -87,7 +86,7 @@ items: description: - The instance to create the database on. returned: success - type: dict + type: str ''' ################################################################################ @@ -104,7 +103,7 @@ import json def main(): module = GcpModule( argument_spec=dict( - instance=dict(required=True, type='dict') + instance=dict(required=True) ) ) diff --git a/lib/ansible/modules/cloud/google/gcp_sql_database.py b/lib/ansible/modules/cloud/google/gcp_sql_database.py index e0d110632ce..d19b6c7865f 100644 --- a/lib/ansible/modules/cloud/google/gcp_sql_database.py +++ b/lib/ansible/modules/cloud/google/gcp_sql_database.py @@ -65,10 +65,9 @@ options: description: - The name of the Cloud SQL instance. This does not include the project ID. - 'This field represents a link to a Instance resource in GCP. It can be specified - in two ways. You can add `register: name-of-resource` to a gcp_sql_instance - task and then set this instance field to "{{ name-of-resource }}" Alternatively, - you can set this instance to a dictionary with the name key where the value - is the name of your Instance' + in two ways. First, you can place in the name of the resource here as a string + Alternatively, you can add `register: name-of-resource` to a gcp_sql_instance + task and then set this instance field to "{{ name-of-resource }}"' required: true extends_documentation_fragment: gcp ''' @@ -76,7 +75,7 @@ extends_documentation_fragment: gcp EXAMPLES = ''' - name: create a instance gcp_sql_instance: - name: "instance-database" + name: "{{resource_name}}-3" settings: ip_configuration: authorized_networks: @@ -122,7 +121,7 @@ instance: description: - The name of the Cloud SQL instance. This does not include the project ID. returned: success - type: dict + type: str ''' ################################################################################ @@ -147,7 +146,7 @@ def main(): charset=dict(type='str'), collation=dict(type='str'), name=dict(type='str'), - instance=dict(required=True, type='dict') + instance=dict(required=True) ) ) diff --git a/lib/ansible/modules/cloud/google/gcp_sql_database_facts.py b/lib/ansible/modules/cloud/google/gcp_sql_database_facts.py index bebaf9cd732..cc4e6bb9377 100644 --- a/lib/ansible/modules/cloud/google/gcp_sql_database_facts.py +++ b/lib/ansible/modules/cloud/google/gcp_sql_database_facts.py @@ -45,10 +45,9 @@ options: description: - The name of the Cloud SQL instance. This does not include the project ID. - 'This field represents a link to a Instance resource in GCP. It can be specified - in two ways. You can add `register: name-of-resource` to a gcp_sql_instance - task and then set this instance field to "{{ name-of-resource }}" Alternatively, - you can set this instance to a dictionary with the name key where the value - is the name of your Instance' + in two ways. First, you can place in the name of the resource here as a string + Alternatively, you can add `register: name-of-resource` to a gcp_sql_instance + task and then set this instance field to "{{ name-of-resource }}"' required: true extends_documentation_fragment: gcp ''' @@ -88,7 +87,7 @@ items: description: - The name of the Cloud SQL instance. This does not include the project ID. returned: success - type: dict + type: str ''' ################################################################################ @@ -105,7 +104,7 @@ import json def main(): module = GcpModule( argument_spec=dict( - instance=dict(required=True, type='dict') + instance=dict(required=True) ) ) diff --git a/lib/ansible/modules/cloud/google/gcp_sql_instance.py b/lib/ansible/modules/cloud/google/gcp_sql_instance.py index 161aa889762..df4a46ef75e 100644 --- a/lib/ansible/modules/cloud/google/gcp_sql_instance.py +++ b/lib/ansible/modules/cloud/google/gcp_sql_instance.py @@ -87,7 +87,7 @@ options: description: - The availability status of the failover replica. A false status indicates that the failover replica is out of sync. The master can only failover to - the falover replica when the status is true. + the failover replica when the status is true. required: false type: bool name: @@ -163,8 +163,8 @@ options: required: false client_key: description: - - PEM representation of the slave's private key. The corresponsing public - key is encoded in the client's asf asd certificate. + - PEM representation of the slave's private key. The corresponding public + key is encoded in the client's certificate. required: false connect_retry_interval: description: @@ -273,7 +273,7 @@ extends_documentation_fragment: gcp EXAMPLES = ''' - name: create a instance gcp_sql_instance: - name: "test_object" + name: "{{resource_name}}-2" settings: ip_configuration: authorized_networks: @@ -320,7 +320,7 @@ failoverReplica: description: - The availability status of the failover replica. A false status indicates that the failover replica is out of sync. The master can only failover to - the falover replica when the status is true. + the failover replica when the status is true. returned: success type: bool name: @@ -427,8 +427,8 @@ replicaConfiguration: type: str clientKey: description: - - PEM representation of the slave's private key. The corresponsing public - key is encoded in the client's asf asd certificate. + - PEM representation of the slave's private key. The corresponding public + key is encoded in the client's certificate. returned: success type: str connectRetryInterval: diff --git a/lib/ansible/modules/cloud/google/gcp_sql_instance_facts.py b/lib/ansible/modules/cloud/google/gcp_sql_instance_facts.py index fdde60aabce..55842f9f72c 100644 --- a/lib/ansible/modules/cloud/google/gcp_sql_instance_facts.py +++ b/lib/ansible/modules/cloud/google/gcp_sql_instance_facts.py @@ -90,7 +90,7 @@ items: description: - The availability status of the failover replica. A false status indicates that the failover replica is out of sync. The master can only failover - to the falover replica when the status is true. + to the failover replica when the status is true. returned: success type: bool name: @@ -200,8 +200,8 @@ items: type: str clientKey: description: - - PEM representation of the slave's private key. The corresponsing public - key is encoded in the client's asf asd certificate. + - PEM representation of the slave's private key. The corresponding public + key is encoded in the client's certificate. returned: success type: str connectRetryInterval: diff --git a/lib/ansible/modules/cloud/google/gcp_sql_user.py b/lib/ansible/modules/cloud/google/gcp_sql_user.py index 4e6f2c5c85c..54f7a4ff4b3 100644 --- a/lib/ansible/modules/cloud/google/gcp_sql_user.py +++ b/lib/ansible/modules/cloud/google/gcp_sql_user.py @@ -62,10 +62,9 @@ options: description: - The name of the Cloud SQL instance. This does not include the project ID. - 'This field represents a link to a Instance resource in GCP. It can be specified - in two ways. You can add `register: name-of-resource` to a gcp_sql_instance - task and then set this instance field to "{{ name-of-resource }}" Alternatively, - you can set this instance to a dictionary with the name key where the value - is the name of your Instance' + in two ways. First, you can place in the name of the resource here as a string + Alternatively, you can add `register: name-of-resource` to a gcp_sql_instance + task and then set this instance field to "{{ name-of-resource }}"' required: true password: description: @@ -77,7 +76,7 @@ extends_documentation_fragment: gcp EXAMPLES = ''' - name: create a instance gcp_sql_instance: - name: "instance-user" + name: "{{resource_name}}-1" settings: ip_configuration: authorized_networks: @@ -120,7 +119,7 @@ instance: description: - The name of the Cloud SQL instance. This does not include the project ID. returned: success - type: dict + type: str password: description: - The password for the user. @@ -149,7 +148,7 @@ def main(): state=dict(default='present', choices=['present', 'absent'], type='str'), host=dict(required=True, type='str'), name=dict(required=True, type='str'), - instance=dict(required=True, type='dict'), + instance=dict(required=True), password=dict(type='str') ) ) diff --git a/lib/ansible/modules/cloud/google/gcp_sql_user_facts.py b/lib/ansible/modules/cloud/google/gcp_sql_user_facts.py index 9e89835b5e4..462efcb22c3 100644 --- a/lib/ansible/modules/cloud/google/gcp_sql_user_facts.py +++ b/lib/ansible/modules/cloud/google/gcp_sql_user_facts.py @@ -45,10 +45,9 @@ options: description: - The name of the Cloud SQL instance. This does not include the project ID. - 'This field represents a link to a Instance resource in GCP. It can be specified - in two ways. You can add `register: name-of-resource` to a gcp_sql_instance - task and then set this instance field to "{{ name-of-resource }}" Alternatively, - you can set this instance to a dictionary with the name key where the value - is the name of your Instance' + in two ways. First, you can place in the name of the resource here as a string + Alternatively, you can add `register: name-of-resource` to a gcp_sql_instance + task and then set this instance field to "{{ name-of-resource }}"' required: true extends_documentation_fragment: gcp ''' @@ -84,7 +83,7 @@ items: description: - The name of the Cloud SQL instance. This does not include the project ID. returned: success - type: dict + type: str password: description: - The password for the user. @@ -106,7 +105,7 @@ import json def main(): module = GcpModule( argument_spec=dict( - instance=dict(required=True, type='dict') + instance=dict(required=True) ) ) diff --git a/lib/ansible/modules/cloud/google/gcp_storage_bucket.py b/lib/ansible/modules/cloud/google/gcp_storage_bucket.py index 3c00e92ad11..6c432a9bd75 100644 --- a/lib/ansible/modules/cloud/google/gcp_storage_bucket.py +++ b/lib/ansible/modules/cloud/google/gcp_storage_bucket.py @@ -62,10 +62,9 @@ options: description: - The name of the bucket. - 'This field represents a link to a Bucket resource in GCP. It can be specified - in two ways. You can add `register: name-of-resource` to a gcp_storage_bucket - task and then set this bucket field to "{{ name-of-resource }}" Alternatively, - you can set this bucket to a dictionary with the name key where the value - is the name of your Bucket' + in two ways. First, you can place in the name of the resource here as a + string Alternatively, you can add `register: name-of-resource` to a gcp_storage_bucket + task and then set this bucket field to "{{ name-of-resource }}"' required: true domain: description: @@ -154,10 +153,9 @@ options: description: - The name of the bucket. - 'This field represents a link to a Bucket resource in GCP. It can be specified - in two ways. You can add `register: name-of-resource` to a gcp_storage_bucket - task and then set this bucket field to "{{ name-of-resource }}" Alternatively, - you can set this bucket to a dictionary with the name key where the value - is the name of your Bucket' + in two ways. First, you can place in the name of the resource here as a + string Alternatively, you can add `register: name-of-resource` to a gcp_storage_bucket + task and then set this bucket field to "{{ name-of-resource }}"' required: true domain: description: @@ -415,7 +413,7 @@ acl: description: - The name of the bucket. returned: success - type: dict + type: str domain: description: - The domain associated with the entity. @@ -509,7 +507,7 @@ defaultObjectAcl: description: - The name of the bucket. returned: success - type: dict + type: str domain: description: - The domain associated with the entity. @@ -793,7 +791,7 @@ def main(): argument_spec=dict( state=dict(default='present', choices=['present', 'absent'], type='str'), acl=dict(type='list', elements='dict', options=dict( - bucket=dict(required=True, type='dict'), + bucket=dict(required=True), domain=dict(type='str'), email=dict(type='str'), entity=dict(required=True, type='str'), @@ -812,7 +810,7 @@ def main(): response_header=dict(type='list', elements='str') )), default_object_acl=dict(type='list', elements='dict', options=dict( - bucket=dict(required=True, type='dict'), + bucket=dict(required=True), domain=dict(type='str'), email=dict(type='str'), entity=dict(required=True, type='str'), diff --git a/lib/ansible/modules/cloud/google/gcp_storage_bucket_access_control.py b/lib/ansible/modules/cloud/google/gcp_storage_bucket_access_control.py index 09e141f4bc0..6a7defa7a10 100644 --- a/lib/ansible/modules/cloud/google/gcp_storage_bucket_access_control.py +++ b/lib/ansible/modules/cloud/google/gcp_storage_bucket_access_control.py @@ -61,10 +61,9 @@ options: description: - The name of the bucket. - 'This field represents a link to a Bucket resource in GCP. It can be specified - in two ways. You can add `register: name-of-resource` to a gcp_storage_bucket - task and then set this bucket field to "{{ name-of-resource }}" Alternatively, - you can set this bucket to a dictionary with the name key where the value is - the name of your Bucket' + in two ways. First, you can place in the name of the resource here as a string + Alternatively, you can add `register: name-of-resource` to a gcp_storage_bucket + task and then set this bucket field to "{{ name-of-resource }}"' required: true entity: description: @@ -110,7 +109,7 @@ extends_documentation_fragment: gcp EXAMPLES = ''' - name: create a bucket gcp_storage_bucket: - name: "bucket-bac" + name: "{{ resource_name }}" project: "{{ gcp_project }}" auth_kind: "{{ gcp_cred_kind }}" service_account_file: "{{ gcp_cred_file }}" @@ -133,7 +132,7 @@ bucket: description: - The name of the bucket. returned: success - type: dict + type: str domain: description: - The domain associated with the entity. @@ -205,7 +204,7 @@ def main(): module = GcpModule( argument_spec=dict( state=dict(default='present', choices=['present', 'absent'], type='str'), - bucket=dict(required=True, type='dict'), + bucket=dict(required=True), entity=dict(required=True, type='str'), entity_id=dict(type='str'), project_team=dict(type='dict', options=dict( diff --git a/test/integration/targets/gcp_pubsub_topic/tasks/main.yml b/test/integration/targets/gcp_pubsub_topic/tasks/main.yml index 8d1a0635c58..c26ecfbf962 100644 --- a/test/integration/targets/gcp_pubsub_topic/tasks/main.yml +++ b/test/integration/targets/gcp_pubsub_topic/tasks/main.yml @@ -44,7 +44,7 @@ - name: verify that command succeeded assert: that: - - results['items'] | length == 1 + - "'test-topic1' in \"{{ results['items'] | map(attribute='name') | list }}\"" # ---------------------------------------------------------------------------- - name: create a topic that already exists gcp_pubsub_topic: @@ -82,7 +82,7 @@ - name: verify that command succeeded assert: that: - - results['items'] | length == 0 + - "'test-topic1' not in \"{{ results['items'] | map(attribute='name') | list }}\"" # ---------------------------------------------------------------------------- - name: delete a topic that does not exist gcp_pubsub_topic: diff --git a/test/integration/targets/gcp_spanner_database/tasks/main.yml b/test/integration/targets/gcp_spanner_database/tasks/main.yml index 269d2e5fd74..cc4b251db93 100644 --- a/test/integration/targets/gcp_spanner_database/tasks/main.yml +++ b/test/integration/targets/gcp_spanner_database/tasks/main.yml @@ -49,13 +49,18 @@ that: - result.changed == true - name: verify that database was created - shell: | - gcloud spanner databases describe --project="{{ gcp_project }}" --instance="{{ instance.name }}" "webstore" + gcp_spanner_database_facts: + instance: "{{ instance }}" + project: "{{ gcp_project }}" + auth_kind: "{{ gcp_cred_kind }}" + service_account_file: "{{ gcp_cred_file }}" + scopes: + - https://www.googleapis.com/auth/spanner.admin register: results - name: verify that command succeeded assert: that: - - results.rc == 0 + - "'webstore' in \"{{ results['items'] | map(attribute='name') | list }}\"" # ---------------------------------------------------------------------------- - name: create a database that already exists gcp_spanner_database: @@ -85,15 +90,18 @@ that: - result.changed == true - name: verify that database was deleted - shell: | - gcloud spanner databases describe --project="{{ gcp_project }}" --instance="{{ instance.name }}" "webstore" + gcp_spanner_database_facts: + instance: "{{ instance }}" + project: "{{ gcp_project }}" + auth_kind: "{{ gcp_cred_kind }}" + service_account_file: "{{ gcp_cred_file }}" + scopes: + - https://www.googleapis.com/auth/spanner.admin register: results - failed_when: results.rc == 0 - name: verify that command succeeded assert: that: - - results.rc == 1 - - "\"Database not found: projects/{{ gcp_project }}/instances/instance-database/databases/webstore\" in results.stderr" + - "'webstore' not in \"{{ results['items'] | map(attribute='name') | list }}\"" # ---------------------------------------------------------------------------- - name: delete a database that does not exist gcp_spanner_database: @@ -110,6 +118,7 @@ - result.changed == false #--------------------------------------------------------- # Post-test teardown +# If errors happen, don't crash the playbook! - name: delete a instance gcp_spanner_instance: name: "instance-database" @@ -123,3 +132,4 @@ service_account_file: "{{ gcp_cred_file }}" state: absent register: instance + ignore_errors: true diff --git a/test/integration/targets/gcp_spanner_instance/tasks/main.yml b/test/integration/targets/gcp_spanner_instance/tasks/main.yml index b79df29cc9d..e95b8907309 100644 --- a/test/integration/targets/gcp_spanner_instance/tasks/main.yml +++ b/test/integration/targets/gcp_spanner_instance/tasks/main.yml @@ -44,13 +44,17 @@ that: - result.changed == true - name: verify that instance was created - shell: | - gcloud spanner instances describe --project="{{ gcp_project }}" "{{ resource_name }}" + gcp_spanner_instance_facts: + project: "{{ gcp_project }}" + auth_kind: "{{ gcp_cred_kind }}" + service_account_file: "{{ gcp_cred_file }}" + scopes: + - https://www.googleapis.com/auth/spanner.admin register: results - name: verify that command succeeded assert: that: - - results.rc == 0 + - "\"{{resource_name}}\" in \"{{ results['items'] | map(attribute='name') | list }}\"" # ---------------------------------------------------------------------------- - name: create a instance that already exists gcp_spanner_instance: @@ -88,15 +92,17 @@ that: - result.changed == true - name: verify that instance was deleted - shell: | - gcloud spanner instances describe --project="{{ gcp_project }}" "{{ resource_name }}" + gcp_spanner_instance_facts: + project: "{{ gcp_project }}" + auth_kind: "{{ gcp_cred_kind }}" + service_account_file: "{{ gcp_cred_file }}" + scopes: + - https://www.googleapis.com/auth/spanner.admin register: results - failed_when: results.rc == 0 - name: verify that command succeeded assert: that: - - results.rc == 1 - - "\"Instance not found: projects/{{ gcp_project }}/instances/{{ resource_name }}\" in results.stderr" + - "\"{{resource_name}}\" not in \"{{ results['items'] | map(attribute='name') | list }}\"" # ---------------------------------------------------------------------------- - name: delete a instance that does not exist gcp_spanner_instance: diff --git a/test/integration/targets/gcp_sql_database/tasks/main.yml b/test/integration/targets/gcp_sql_database/tasks/main.yml index 81226327fdf..a9dd18bdf45 100644 --- a/test/integration/targets/gcp_sql_database/tasks/main.yml +++ b/test/integration/targets/gcp_sql_database/tasks/main.yml @@ -15,7 +15,7 @@ # Pre-test setup - name: create a instance gcp_sql_instance: - name: "instance-database" + name: "{{resource_name}}-3" settings: ip_configuration: authorized_networks: @@ -54,13 +54,18 @@ - result.changed == true - "result.kind == 'sql#database'" - name: verify that database was created - shell: | - gcloud sql databases describe --instance='instance-database' --project="{{ gcp_project}}" "{{ resource_name }}" + gcp_sql_database_facts: + instance: "{{ instance }}" + project: "{{ gcp_project }}" + auth_kind: "{{ gcp_cred_kind }}" + service_account_file: "{{ gcp_cred_file }}" + scopes: + - https://www.googleapis.com/auth/sqlservice.admin register: results - name: verify that command succeeded assert: that: - - results.rc == 0 + - "\"{{resource_name}}\" in \"{{ results['items'] | map(attribute='name') | list }}\"" # ---------------------------------------------------------------------------- - name: create a database that already exists gcp_sql_database: @@ -94,15 +99,18 @@ - result.changed == true - result.has_key('kind') == False - name: verify that database was deleted - shell: | - gcloud sql databases describe --instance='instance-database' --project="{{ gcp_project}}" "{{ resource_name }}" + gcp_sql_database_facts: + instance: "{{ instance }}" + project: "{{ gcp_project }}" + auth_kind: "{{ gcp_cred_kind }}" + service_account_file: "{{ gcp_cred_file }}" + scopes: + - https://www.googleapis.com/auth/sqlservice.admin register: results - failed_when: results.rc == 0 - name: verify that command succeeded assert: that: - - results.rc == 1 - - "\"(gcloud.sql.databases.describe) HTTPError 404: Not Found\" in results.stderr" + - "\"{{resource_name}}\" not in \"{{ results['items'] | map(attribute='name') | list }}\"" # ---------------------------------------------------------------------------- - name: delete a database that does not exist gcp_sql_database: @@ -121,9 +129,10 @@ - result.has_key('kind') == False #--------------------------------------------------------- # Post-test teardown +# If errors happen, don't crash the playbook! - name: delete a instance gcp_sql_instance: - name: "instance-database" + name: "{{resource_name}}-3" settings: ip_configuration: authorized_networks: @@ -136,3 +145,4 @@ service_account_file: "{{ gcp_cred_file }}" state: absent register: instance + ignore_errors: true diff --git a/test/integration/targets/gcp_sql_instance/tasks/main.yml b/test/integration/targets/gcp_sql_instance/tasks/main.yml index 5ef8f165acd..fa7690c1e80 100644 --- a/test/integration/targets/gcp_sql_instance/tasks/main.yml +++ b/test/integration/targets/gcp_sql_instance/tasks/main.yml @@ -15,7 +15,7 @@ # Pre-test setup - name: delete a instance gcp_sql_instance: - name: "{{ resource_name }}" + name: "{{resource_name}}-2" settings: ip_configuration: authorized_networks: @@ -30,7 +30,7 @@ #---------------------------------------------------------- - name: create a instance gcp_sql_instance: - name: "{{ resource_name }}" + name: "{{resource_name}}-2" settings: ip_configuration: authorized_networks: @@ -49,17 +49,21 @@ - result.changed == true - "result.kind == 'sql#instance'" - name: verify that instance was created - shell: | - gcloud sql instances describe --project="{{ gcp_project}}" "{{ resource_name }}" + gcp_sql_instance_facts: + project: "{{ gcp_project }}" + auth_kind: "{{ gcp_cred_kind }}" + service_account_file: "{{ gcp_cred_file }}" + scopes: + - https://www.googleapis.com/auth/sqlservice.admin register: results - name: verify that command succeeded assert: that: - - results.rc == 0 + - results['items'] | length >= 1 # ---------------------------------------------------------------------------- - name: create a instance that already exists gcp_sql_instance: - name: "{{ resource_name }}" + name: "{{resource_name}}-2" settings: ip_configuration: authorized_networks: @@ -80,7 +84,7 @@ #---------------------------------------------------------- - name: delete a instance gcp_sql_instance: - name: "{{ resource_name }}" + name: "{{resource_name}}-2" settings: ip_configuration: authorized_networks: @@ -99,19 +103,21 @@ - result.changed == true - result.has_key('kind') == False - name: verify that instance was deleted - shell: | - gcloud sql instances describe --project="{{ gcp_project}}" "{{ resource_name }}" + gcp_sql_instance_facts: + project: "{{ gcp_project }}" + auth_kind: "{{ gcp_cred_kind }}" + service_account_file: "{{ gcp_cred_file }}" + scopes: + - https://www.googleapis.com/auth/sqlservice.admin register: results - failed_when: results.rc == 0 - name: verify that command succeeded assert: that: - - results.rc == 1 - - "\"Cloud SQL instance does not exist\" in results.stderr" + - results['items'] | length == 0 # ---------------------------------------------------------------------------- - name: delete a instance that does not exist gcp_sql_instance: - name: "{{ resource_name }}" + name: "{{resource_name}}-2" settings: ip_configuration: authorized_networks: diff --git a/test/integration/targets/gcp_sql_user/tasks/main.yml b/test/integration/targets/gcp_sql_user/tasks/main.yml index a481b394b7a..ac8f8b510e3 100644 --- a/test/integration/targets/gcp_sql_user/tasks/main.yml +++ b/test/integration/targets/gcp_sql_user/tasks/main.yml @@ -15,7 +15,7 @@ # Pre-test setup - name: create a instance gcp_sql_instance: - name: "instance-user" + name: "{{resource_name}}-1" settings: ip_configuration: authorized_networks: @@ -57,8 +57,6 @@ - "result.kind == 'sql#user'" - name: verify that user was created gcp_sql_user_facts: - filters: - - name = test-user instance: "{{ instance }}" project: "{{ gcp_project }}" auth_kind: "{{ gcp_cred_kind }}" @@ -69,7 +67,7 @@ - name: verify that command succeeded assert: that: - - results['items'] | length == 1 + - "'test-user' in \"{{ results['items'] | map(attribute='name') | list }}\"" # ---------------------------------------------------------------------------- - name: create a user that already exists gcp_sql_user: @@ -106,8 +104,6 @@ - result.has_key('kind') == False - name: verify that user was deleted gcp_sql_user_facts: - filters: - - name = test-user instance: "{{ instance }}" project: "{{ gcp_project }}" auth_kind: "{{ gcp_cred_kind }}" @@ -118,7 +114,7 @@ - name: verify that command succeeded assert: that: - - results['items'] | length == 0 + - "'test-user' not in \"{{ results['items'] | map(attribute='name') | list }}\"" # ---------------------------------------------------------------------------- - name: delete a user that does not exist gcp_sql_user: @@ -138,9 +134,10 @@ - result.has_key('kind') == False #--------------------------------------------------------- # Post-test teardown +# If errors happen, don't crash the playbook! - name: delete a instance gcp_sql_instance: - name: "instance-user" + name: "{{resource_name}}-1" settings: ip_configuration: authorized_networks: @@ -153,3 +150,4 @@ service_account_file: "{{ gcp_cred_file }}" state: absent register: instance + ignore_errors: true diff --git a/test/integration/targets/gcp_storage_bucket_access_control/tasks/main.yml b/test/integration/targets/gcp_storage_bucket_access_control/tasks/main.yml index b9b9e763b0f..c4a28f0c854 100644 --- a/test/integration/targets/gcp_storage_bucket_access_control/tasks/main.yml +++ b/test/integration/targets/gcp_storage_bucket_access_control/tasks/main.yml @@ -15,7 +15,7 @@ # Pre-test setup - name: create a bucket gcp_storage_bucket: - name: "bucket-bac" + name: "{{ resource_name }}" project: "{{ gcp_project }}" auth_kind: "{{ gcp_cred_kind }}" service_account_file: "{{ gcp_cred_file }}" @@ -96,11 +96,13 @@ - result.has_key('kind') == False #--------------------------------------------------------- # Post-test teardown +# If errors happen, don't crash the playbook! - name: delete a bucket gcp_storage_bucket: - name: "bucket-bac" + name: "{{ resource_name }}" project: "{{ gcp_project }}" auth_kind: "{{ gcp_cred_kind }}" service_account_file: "{{ gcp_cred_file }}" state: absent register: bucket + ignore_errors: true