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_url_map (#42828)

This commit is contained in:
Alex Stephen 2018-08-15 11:28:24 -07:00 committed by Ryan Brown
parent 82678b9bac
commit 97b3845e89
2 changed files with 61 additions and 76 deletions

View file

@ -49,7 +49,7 @@ options:
default: 'present' default: 'present'
default_service: default_service:
description: description:
- A reference to BackendService resource. - A reference to BackendService resource if none of the hostRules match.
required: true required: true
description: description:
description: description:
@ -93,7 +93,8 @@ options:
suboptions: suboptions:
default_service: default_service:
description: description:
- A reference to BackendService resource. - A reference to a BackendService resource. This will be used if none of the pathRules
defined by this PathMatcher is matched by the URL's path portion.
required: false required: false
description: description:
description: description:
@ -116,7 +117,7 @@ options:
required: false required: false
service: service:
description: description:
- A reference to BackendService resource. - A reference to the BackendService resource if this rule is matched.
required: false required: false
tests: tests:
description: description:
@ -138,7 +139,7 @@ options:
required: false required: false
service: service:
description: description:
- A reference to BackendService resource. - A reference to expected BackendService resource the given URL should be mapped to.
required: false required: false
extends_documentation_fragment: gcp extends_documentation_fragment: gcp
''' '''
@ -146,19 +147,17 @@ extends_documentation_fragment: gcp
EXAMPLES = ''' EXAMPLES = '''
- name: create a instance group - name: create a instance group
gcp_compute_instance_group: gcp_compute_instance_group:
name: 'instancegroup-urlmap' name: "instancegroup-urlmap"
zone: 'us-central1-a' zone: us-central1-a
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/compute
state: present state: present
register: instancegroup register: instancegroup
- name: create a http health check - name: create a http health check
gcp_compute_http_health_check: gcp_compute_http_health_check:
name: 'httphealthcheck-urlmap' name: "httphealthcheck-urlmap"
healthy_threshold: 10 healthy_threshold: 10
port: 8080 port: 8080
timeout_sec: 2 timeout_sec: 2
@ -166,14 +165,12 @@ EXAMPLES = '''
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/compute
state: present state: present
register: healthcheck register: healthcheck
- name: create a backend service - name: create a backend service
gcp_compute_backend_service: gcp_compute_backend_service:
name: 'backendservice-urlmap' name: "backendservice-urlmap"
backends: backends:
- group: "{{ instancegroup }}" - group: "{{ instancegroup }}"
health_checks: health_checks:
@ -182,20 +179,16 @@ EXAMPLES = '''
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/compute
state: present state: present
register: backendservice register: backendservice
- name: create a url map - name: create a url map
gcp_compute_url_map: gcp_compute_url_map:
name: testObject name: "test_object"
default_service: "{{ backendservice }}" default_service: "{{ backendservice }}"
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/compute
state: present state: present
''' '''
@ -207,7 +200,7 @@ RETURN = '''
type: str type: str
default_service: default_service:
description: description:
- A reference to BackendService resource. - A reference to BackendService resource if none of the hostRules match.
returned: success returned: success
type: dict type: dict
description: description:
@ -264,7 +257,8 @@ RETURN = '''
contains: contains:
default_service: default_service:
description: description:
- A reference to BackendService resource. - A reference to a BackendService resource. This will be used if none of the pathRules
defined by this PathMatcher is matched by the URL's path portion.
returned: success returned: success
type: dict type: dict
description: description:
@ -292,7 +286,7 @@ RETURN = '''
type: list type: list
service: service:
description: description:
- A reference to BackendService resource. - A reference to the BackendService resource if this rule is matched.
returned: success returned: success
type: dict type: dict
tests: tests:
@ -319,7 +313,7 @@ RETURN = '''
type: str type: str
service: service:
description: description:
- A reference to BackendService resource. - A reference to expected BackendService resource the given URL should be mapped to.
returned: success returned: success
type: dict type: dict
''' '''
@ -369,6 +363,9 @@ def main():
) )
) )
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
state = module.params['state'] state = module.params['state']
kind = 'compute#urlMap' kind = 'compute#urlMap'
@ -378,10 +375,10 @@ def main():
if fetch: if fetch:
if state == 'present': if state == 'present':
if is_different(module, fetch): if is_different(module, fetch):
fetch = update(module, self_link(module), kind, fetch) fetch = update(module, self_link(module), kind)
changed = True changed = True
else: else:
delete(module, self_link(module), kind, fetch) delete(module, self_link(module), kind)
fetch = {} fetch = {}
changed = True changed = True
else: else:
@ -401,12 +398,12 @@ def create(module, link, kind):
return wait_for_operation(module, auth.post(link, resource_to_request(module))) 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') auth = GcpSession(module, 'compute')
return wait_for_operation(module, auth.put(link, resource_to_request(module))) 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') auth = GcpSession(module, 'compute')
return wait_for_operation(module, auth.delete(link)) return wait_for_operation(module, auth.delete(link))
@ -418,7 +415,7 @@ def resource_to_request(module):
u'description': module.params.get('description'), u'description': module.params.get('description'),
u'hostRules': UrlMapHostRulesArray(module.params.get('host_rules', []), module).to_request(), u'hostRules': UrlMapHostRulesArray(module.params.get('host_rules', []), module).to_request(),
u'name': module.params.get('name'), u'name': module.params.get('name'),
u'pathMatchers': UrlMapPathMatchArray(module.params.get('path_matchers', []), module).to_request(), u'pathMatchers': UrlMapPathMatchersArray(module.params.get('path_matchers', []), module).to_request(),
u'tests': UrlMapTestsArray(module.params.get('tests', []), module).to_request() u'tests': UrlMapTestsArray(module.params.get('tests', []), module).to_request()
} }
return_vals = {} return_vals = {}
@ -493,7 +490,7 @@ def response_to_hash(module, response):
u'hostRules': UrlMapHostRulesArray(response.get(u'hostRules', []), module).from_response(), u'hostRules': UrlMapHostRulesArray(response.get(u'hostRules', []), module).from_response(),
u'id': response.get(u'id'), u'id': response.get(u'id'),
u'name': response.get(u'name'), u'name': response.get(u'name'),
u'pathMatchers': UrlMapPathMatchArray(response.get(u'pathMatchers', []), module).from_response(), u'pathMatchers': UrlMapPathMatchersArray(response.get(u'pathMatchers', []), module).from_response(),
u'tests': UrlMapTestsArray(response.get(u'tests', []), module).from_response() u'tests': UrlMapTestsArray(response.get(u'tests', []), module).from_response()
} }
@ -510,7 +507,7 @@ def async_op_url(module, extra_data=None):
def wait_for_operation(module, response): def wait_for_operation(module, response):
op_result = return_if_object(module, response, 'compute#operation') op_result = return_if_object(module, response, 'compute#operation')
if op_result is None: if op_result is None:
return None return {}
status = navigate_hash(op_result, ['status']) status = navigate_hash(op_result, ['status'])
wait_done = wait_for_completion(status, op_result, module) wait_done = wait_for_completion(status, op_result, module)
return fetch_resource(module, navigate_hash(wait_done, ['targetLink']), 'compute#urlMap') return fetch_resource(module, navigate_hash(wait_done, ['targetLink']), 'compute#urlMap')
@ -570,7 +567,7 @@ class UrlMapHostRulesArray(object):
}) })
class UrlMapPathMatchArray(object): class UrlMapPathMatchersArray(object):
def __init__(self, request, module): def __init__(self, request, module):
self.module = module self.module = module
if request: if request:

View file

@ -15,18 +15,16 @@
# Pre-test setup # Pre-test setup
- name: create a instance group - name: create a instance group
gcp_compute_instance_group: gcp_compute_instance_group:
name: 'instancegroup-urlmap' name: "instancegroup-urlmap"
zone: 'us-central1-a' zone: us-central1-a
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/compute
state: present state: present
register: instancegroup register: instancegroup
- name: create a http health check - name: create a http health check
gcp_compute_http_health_check: gcp_compute_http_health_check:
name: 'httphealthcheck-urlmap' name: "httphealthcheck-urlmap"
healthy_threshold: 10 healthy_threshold: 10
port: 8080 port: 8080
timeout_sec: 2 timeout_sec: 2
@ -34,13 +32,11 @@
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/compute
state: present state: present
register: healthcheck register: healthcheck
- name: create a backend service - name: create a backend service
gcp_compute_backend_service: gcp_compute_backend_service:
name: 'backendservice-urlmap' name: "backendservice-urlmap"
backends: backends:
- group: "{{ instancegroup }}" - group: "{{ instancegroup }}"
health_checks: health_checks:
@ -49,8 +45,6 @@
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/compute
state: present state: present
register: backendservice register: backendservice
- name: delete a url map - name: delete a url map
@ -60,8 +54,6 @@
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/compute
state: absent state: absent
#---------------------------------------------------------- #----------------------------------------------------------
- name: create a url map - name: create a url map
@ -71,8 +63,6 @@
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/compute
state: present state: present
register: result register: result
- name: assert changed is true - name: assert changed is true
@ -81,13 +71,19 @@
- result.changed == true - result.changed == true
- "result.kind == 'compute#urlMap'" - "result.kind == 'compute#urlMap'"
- name: verify that url_map was created - name: verify that url_map was created
shell: | gcp_compute_url_map_facts:
gcloud compute url-maps describe --project="{{ gcp_project}}" "{{ resource_name }}" 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 register: results
- name: verify that command succeeded - name: verify that command succeeded
assert: assert:
that: that:
- results.rc == 0 - results['items'] | length == 1
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
- name: create a url map that already exists - name: create a url map that already exists
gcp_compute_url_map: gcp_compute_url_map:
@ -96,8 +92,6 @@
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/compute
state: present state: present
register: result register: result
- name: assert changed is false - name: assert changed is false
@ -113,8 +107,6 @@
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/compute
state: absent state: absent
register: result register: result
- name: assert changed is true - name: assert changed is true
@ -123,15 +115,19 @@
- result.changed == true - result.changed == true
- result.has_key('kind') == False - result.has_key('kind') == False
- name: verify that url_map was deleted - name: verify that url_map was deleted
shell: | gcp_compute_url_map_facts:
gcloud compute url-maps describe --project="{{ gcp_project}}" "{{ resource_name }}" 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 register: results
failed_when: results.rc == 0
- name: verify that command succeeded - name: verify that command succeeded
assert: assert:
that: that:
- results.rc == 1 - results['items'] | length == 0
- "\"'projects/{{ gcp_project }}/global/urlMaps/{{ resource_name }}' was not found\" in results.stderr"
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
- name: delete a url map that does not exist - name: delete a url map that does not exist
gcp_compute_url_map: gcp_compute_url_map:
@ -140,8 +136,6 @@
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/compute
state: absent state: absent
register: result register: result
- name: assert changed is false - name: assert changed is false
@ -153,7 +147,7 @@
# Post-test teardown # Post-test teardown
- name: delete a backend service - name: delete a backend service
gcp_compute_backend_service: gcp_compute_backend_service:
name: 'backendservice-urlmap' name: "backendservice-urlmap"
backends: backends:
- group: "{{ instancegroup }}" - group: "{{ instancegroup }}"
health_checks: health_checks:
@ -162,13 +156,11 @@
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/compute
state: absent state: absent
register: backendservice register: backendservice
- name: delete a http health check - name: delete a http health check
gcp_compute_http_health_check: gcp_compute_http_health_check:
name: 'httphealthcheck-urlmap' name: "httphealthcheck-urlmap"
healthy_threshold: 10 healthy_threshold: 10
port: 8080 port: 8080
timeout_sec: 2 timeout_sec: 2
@ -176,18 +168,14 @@
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/compute
state: absent state: absent
register: healthcheck register: healthcheck
- name: delete a instance group - name: delete a instance group
gcp_compute_instance_group: gcp_compute_instance_group:
name: 'instancegroup-urlmap' name: "instancegroup-urlmap"
zone: 'us-central1-a' zone: us-central1-a
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/compute
state: absent state: absent
register: instancegroup register: instancegroup