Bug fixes for gcp_pubsub_subscription (#42833)

This commit is contained in:
Alex Stephen 2018-08-13 09:14:11 -07:00 committed by Ryan Brown
parent 3dc363d135
commit dd3c4b0d39
2 changed files with 21 additions and 36 deletions

View file

@ -53,7 +53,7 @@ options:
required: false required: false
topic: topic:
description: description:
- A reference to Topic resource. - A reference to a Topic resource.
required: false required: false
push_config: push_config:
description: description:
@ -90,27 +90,23 @@ extends_documentation_fragment: gcp
EXAMPLES = ''' EXAMPLES = '''
- name: create a topic - name: create a topic
gcp_pubsub_topic: gcp_pubsub_topic:
name: 'topic-subscription' name: "topic-subscription"
project: "{{ gcp_project }}" project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}" auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}" service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/pubsub
state: present state: present
register: topic register: topic
- name: create a subscription - name: create a subscription
gcp_pubsub_subscription: gcp_pubsub_subscription:
name: testObject name: "test_object"
topic: "{{ topic }}" topic: "{{ topic }}"
push_config: push_config:
push_endpoint: 'https://myapp.graphite.cloudnativeapp.com/webhook/sub1' push_endpoint: https://myapp.graphite.cloudnativeapp.com/webhook/sub1
ack_deadline_seconds: 300 ack_deadline_seconds: 300
project: testProject project: "test_project"
auth_kind: service_account auth_kind: "service_account"
service_account_file: /tmp/auth.pem service_account_file: "/tmp/auth.pem"
scopes:
- https://www.googleapis.com/auth/pubsub
state: present state: present
''' '''
@ -122,7 +118,7 @@ RETURN = '''
type: str type: str
topic: topic:
description: description:
- A reference to Topic resource. - A reference to a Topic resource.
returned: success returned: success
type: dict type: dict
push_config: push_config:
@ -186,6 +182,9 @@ def main():
) )
) )
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/pubsub']
state = module.params['state'] state = module.params['state']
fetch = fetch_resource(module, self_link(module)) fetch = fetch_resource(module, self_link(module))
@ -230,7 +229,7 @@ def resource_to_request(module):
request = { request = {
u'name': module.params.get('name'), u'name': module.params.get('name'),
u'topic': replace_resource_dict(module.params.get(u'topic', {}), 'name'), u'topic': replace_resource_dict(module.params.get(u'topic', {}), 'name'),
u'pushConfig': SubscriPushConfig(module.params.get('push_config', {}), module).to_request(), u'pushConfig': SubscriptionPushConfig(module.params.get('push_config', {}), module).to_request(),
u'ackDeadlineSeconds': module.params.get('ack_deadline_seconds') u'ackDeadlineSeconds': module.params.get('ack_deadline_seconds')
} }
request = encode_request(request, module) request = encode_request(request, module)
@ -303,7 +302,7 @@ def response_to_hash(module, response):
return { return {
u'name': response.get(u'name'), u'name': response.get(u'name'),
u'topic': response.get(u'topic'), u'topic': response.get(u'topic'),
u'pushConfig': SubscriPushConfig(response.get(u'pushConfig', {}), module).from_response(), u'pushConfig': SubscriptionPushConfig(response.get(u'pushConfig', {}), module).from_response(),
u'ackDeadlineSeconds': response.get(u'ackDeadlineSeconds') u'ackDeadlineSeconds': response.get(u'ackDeadlineSeconds')
} }
@ -327,7 +326,7 @@ def encode_request(request, module):
return request return request
class SubscriPushConfig(object): class SubscriptionPushConfig(object):
def __init__(self, request, module): def __init__(self, request, module):
self.module = module self.module = module
if request: if request:

View file

@ -15,12 +15,10 @@
# Pre-test setup # Pre-test setup
- name: create a topic - name: create a topic
gcp_pubsub_topic: gcp_pubsub_topic:
name: 'topic-subscription' name: "topic-subscription"
project: "{{ gcp_project }}" project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}" auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}" service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/pubsub
state: present state: present
register: topic register: topic
- name: delete a subscription - name: delete a subscription
@ -28,13 +26,11 @@
name: "{{ resource_name }}" name: "{{ resource_name }}"
topic: "{{ topic }}" topic: "{{ topic }}"
push_config: push_config:
push_endpoint: 'https://myapp.graphite.cloudnativeapp.com/webhook/sub1' push_endpoint: https://myapp.graphite.cloudnativeapp.com/webhook/sub1
ack_deadline_seconds: 300 ack_deadline_seconds: 300
project: "{{ gcp_project }}" project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}" auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}" service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/pubsub
state: absent state: absent
#---------------------------------------------------------- #----------------------------------------------------------
- name: create a subscription - name: create a subscription
@ -42,13 +38,11 @@
name: "{{ resource_name }}" name: "{{ resource_name }}"
topic: "{{ topic }}" topic: "{{ topic }}"
push_config: push_config:
push_endpoint: 'https://myapp.graphite.cloudnativeapp.com/webhook/sub1' push_endpoint: https://myapp.graphite.cloudnativeapp.com/webhook/sub1
ack_deadline_seconds: 300 ack_deadline_seconds: 300
project: "{{ gcp_project }}" project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}" auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}" service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/pubsub
state: present state: present
register: result register: result
- name: assert changed is true - name: assert changed is true
@ -69,13 +63,11 @@
name: "{{ resource_name }}" name: "{{ resource_name }}"
topic: "{{ topic }}" topic: "{{ topic }}"
push_config: push_config:
push_endpoint: 'https://myapp.graphite.cloudnativeapp.com/webhook/sub1' push_endpoint: https://myapp.graphite.cloudnativeapp.com/webhook/sub1
ack_deadline_seconds: 300 ack_deadline_seconds: 300
project: "{{ gcp_project }}" project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}" auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}" service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/pubsub
state: present state: present
register: result register: result
- name: assert changed is false - name: assert changed is false
@ -88,13 +80,11 @@
name: "{{ resource_name }}" name: "{{ resource_name }}"
topic: "{{ topic }}" topic: "{{ topic }}"
push_config: push_config:
push_endpoint: 'https://myapp.graphite.cloudnativeapp.com/webhook/sub1' push_endpoint: https://myapp.graphite.cloudnativeapp.com/webhook/sub1
ack_deadline_seconds: 300 ack_deadline_seconds: 300
project: "{{ gcp_project }}" project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}" auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}" service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/pubsub
state: absent state: absent
register: result register: result
- name: assert changed is true - name: assert changed is true
@ -117,13 +107,11 @@
name: "{{ resource_name }}" name: "{{ resource_name }}"
topic: "{{ topic }}" topic: "{{ topic }}"
push_config: push_config:
push_endpoint: 'https://myapp.graphite.cloudnativeapp.com/webhook/sub1' push_endpoint: https://myapp.graphite.cloudnativeapp.com/webhook/sub1
ack_deadline_seconds: 300 ack_deadline_seconds: 300
project: "{{ gcp_project }}" project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}" auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}" service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/pubsub
state: absent state: absent
register: result register: result
- name: assert changed is false - name: assert changed is false
@ -134,11 +122,9 @@
# Post-test teardown # Post-test teardown
- name: delete a topic - name: delete a topic
gcp_pubsub_topic: gcp_pubsub_topic:
name: 'topic-subscription' name: "topic-subscription"
project: "{{ gcp_project }}" project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}" auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}" service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/pubsub
state: absent state: absent
register: topic register: topic