1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Bug fixes for gcp_compute_target_http_proxy (#42823)

This commit is contained in:
Alex Stephen 2018-08-14 06:53:29 -07:00 committed by Ryan Brown
parent 569e094efd
commit 97006cded2
2 changed files with 56 additions and 76 deletions

View file

@ -62,27 +62,28 @@ options:
required: true
url_map:
description:
- A reference to UrlMap resource.
- A reference to the UrlMap resource that defines the mapping from URL to the BackendService.
required: true
extends_documentation_fragment: gcp
notes:
- "API Reference: U(https://cloud.google.com/compute/docs/reference/latest/targetHttpProxies)"
- "Official Documentation: U(https://cloud.google.com/compute/docs/load-balancing/http/target-proxies)"
'''
EXAMPLES = '''
- name: create a instance group
gcp_compute_instance_group:
name: 'instancegroup-targethttpproxy'
zone: 'us-central1-a'
name: "instancegroup-targethttpproxy"
zone: us-central1-a
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/compute
state: present
register: instancegroup
- name: create a http health check
gcp_compute_http_health_check:
name: 'httphealthcheck-targethttpproxy'
name: "httphealthcheck-targethttpproxy"
healthy_threshold: 10
port: 8080
timeout_sec: 2
@ -90,48 +91,40 @@ EXAMPLES = '''
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/compute
state: present
register: healthcheck
- name: create a backend service
gcp_compute_backend_service:
name: 'backendservice-targethttpproxy'
name: "backendservice-targethttpproxy"
backends:
- group: "{{ instancegroup }}"
- group: "{{ instancegroup }}"
health_checks:
- "{{ healthcheck.selfLink }}"
- "{{ healthcheck.selfLink }}"
enable_cdn: true
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/compute
state: present
register: backendservice
- name: create a url map
gcp_compute_url_map:
name: 'urlmap-targethttpproxy'
name: "urlmap-targethttpproxy"
default_service: "{{ backendservice }}"
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/compute
state: present
register: urlmap
- name: create a target http proxy
gcp_compute_target_http_proxy:
name: testObject
name: "test_object"
url_map: "{{ urlmap }}"
project: testProject
auth_kind: service_account
service_account_file: /tmp/auth.pem
scopes:
- https://www.googleapis.com/auth/compute
project: "test_project"
auth_kind: "service_account"
service_account_file: "/tmp/auth.pem"
state: present
'''
@ -163,7 +156,7 @@ RETURN = '''
type: str
url_map:
description:
- A reference to UrlMap resource.
- A reference to the UrlMap resource that defines the mapping from URL to the BackendService.
returned: success
type: dict
'''
@ -193,6 +186,9 @@ def main():
)
)
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
state = module.params['state']
kind = 'compute#targetHttpProxy'
@ -202,10 +198,10 @@ def main():
if fetch:
if state == 'present':
if is_different(module, fetch):
fetch = update(module, self_link(module), kind, fetch)
fetch = update(module, self_link(module), kind)
changed = True
else:
delete(module, self_link(module), kind, fetch)
delete(module, self_link(module), kind)
fetch = {}
changed = True
else:
@ -225,12 +221,12 @@ def create(module, link, kind):
return wait_for_operation(module, auth.post(link, resource_to_request(module)))
def update(module, link, kind, fetch):
def update(module, link, kind):
auth = GcpSession(module, 'compute')
return wait_for_operation(module, auth.put(link, resource_to_request(module)))
def delete(module, link, kind, fetch):
def delete(module, link, kind):
auth = GcpSession(module, 'compute')
return wait_for_operation(module, auth.delete(link))
@ -328,7 +324,7 @@ def async_op_url(module, extra_data=None):
def wait_for_operation(module, response):
op_result = return_if_object(module, response, 'compute#operation')
if op_result is None:
return None
return {}
status = navigate_hash(op_result, ['status'])
wait_done = wait_for_completion(status, op_result, module)
return fetch_resource(module, navigate_hash(wait_done, ['targetLink']), 'compute#targetHttpProxy')

View file

@ -15,18 +15,16 @@
# Pre-test setup
- name: create a instance group
gcp_compute_instance_group:
name: 'instancegroup-targethttpproxy'
zone: 'us-central1-a'
name: "instancegroup-targethttpproxy"
zone: us-central1-a
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/compute
state: present
register: instancegroup
- name: create a http health check
gcp_compute_http_health_check:
name: 'httphealthcheck-targethttpproxy'
name: "httphealthcheck-targethttpproxy"
healthy_threshold: 10
port: 8080
timeout_sec: 2
@ -34,34 +32,28 @@
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/compute
state: present
register: healthcheck
- name: create a backend service
gcp_compute_backend_service:
name: 'backendservice-targethttpproxy'
name: "backendservice-targethttpproxy"
backends:
- group: "{{ instancegroup }}"
- group: "{{ instancegroup }}"
health_checks:
- "{{ healthcheck.selfLink }}"
- "{{ healthcheck.selfLink }}"
enable_cdn: true
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/compute
state: present
register: backendservice
- name: create a url map
gcp_compute_url_map:
name: 'urlmap-targethttpproxy'
name: "urlmap-targethttpproxy"
default_service: "{{ backendservice }}"
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/compute
state: present
register: urlmap
- name: delete a target http proxy
@ -71,8 +63,6 @@
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/compute
state: absent
#----------------------------------------------------------
- name: create a target http proxy
@ -82,8 +72,6 @@
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/compute
state: present
register: result
- name: assert changed is true
@ -92,13 +80,19 @@
- result.changed == true
- "result.kind == 'compute#targetHttpProxy'"
- name: verify that target_http_proxy was created
shell: |
gcloud compute target-http-proxies describe --project="{{ gcp_project}}" "{{ resource_name }}"
gcp_compute_target_http_proxy_facts:
filters:
- name = {{ resource_name }}
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/compute
register: results
- name: verify that command succeeded
assert:
that:
- results.rc == 0
- results['items'] | length == 1
# ----------------------------------------------------------------------------
- name: create a target http proxy that already exists
gcp_compute_target_http_proxy:
@ -107,8 +101,6 @@
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/compute
state: present
register: result
- name: assert changed is false
@ -124,8 +116,6 @@
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/compute
state: absent
register: result
- name: assert changed is true
@ -134,15 +124,19 @@
- result.changed == true
- result.has_key('kind') == False
- name: verify that target_http_proxy was deleted
shell: |
gcloud compute target-http-proxies describe --project="{{ gcp_project}}" "{{ resource_name }}"
gcp_compute_target_http_proxy_facts:
filters:
- name = {{ resource_name }}
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/compute
register: results
failed_when: results.rc == 0
- name: verify that command succeeded
assert:
that:
- results.rc == 1
- "\"'projects/{{ gcp_project }}/global/targetHttpProxies/{{ resource_name }}' was not found\" in results.stderr"
- results['items'] | length == 0
# ----------------------------------------------------------------------------
- name: delete a target http proxy that does not exist
gcp_compute_target_http_proxy:
@ -151,8 +145,6 @@
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/compute
state: absent
register: result
- name: assert changed is false
@ -164,33 +156,29 @@
# Post-test teardown
- name: delete a url map
gcp_compute_url_map:
name: 'urlmap-targethttpproxy'
name: "urlmap-targethttpproxy"
default_service: "{{ backendservice }}"
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/compute
state: absent
register: urlmap
- name: delete a backend service
gcp_compute_backend_service:
name: 'backendservice-targethttpproxy'
name: "backendservice-targethttpproxy"
backends:
- group: "{{ instancegroup }}"
- group: "{{ instancegroup }}"
health_checks:
- "{{ healthcheck.selfLink }}"
- "{{ healthcheck.selfLink }}"
enable_cdn: true
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/compute
state: absent
register: backendservice
- name: delete a http health check
gcp_compute_http_health_check:
name: 'httphealthcheck-targethttpproxy'
name: "httphealthcheck-targethttpproxy"
healthy_threshold: 10
port: 8080
timeout_sec: 2
@ -198,18 +186,14 @@
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/compute
state: absent
register: healthcheck
- name: delete a instance group
gcp_compute_instance_group:
name: 'instancegroup-targethttpproxy'
zone: 'us-central1-a'
name: "instancegroup-targethttpproxy"
zone: us-central1-a
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/compute
state: absent
register: instancegroup