Bug fixes for gcp_compute_url_map (#42828)
This commit is contained in:
parent
82678b9bac
commit
97b3845e89
2 changed files with 61 additions and 76 deletions
|
@ -49,7 +49,7 @@ options:
|
|||
default: 'present'
|
||||
default_service:
|
||||
description:
|
||||
- A reference to BackendService resource.
|
||||
- A reference to BackendService resource if none of the hostRules match.
|
||||
required: true
|
||||
description:
|
||||
description:
|
||||
|
@ -93,7 +93,8 @@ options:
|
|||
suboptions:
|
||||
default_service:
|
||||
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
|
||||
description:
|
||||
description:
|
||||
|
@ -116,7 +117,7 @@ options:
|
|||
required: false
|
||||
service:
|
||||
description:
|
||||
- A reference to BackendService resource.
|
||||
- A reference to the BackendService resource if this rule is matched.
|
||||
required: false
|
||||
tests:
|
||||
description:
|
||||
|
@ -138,7 +139,7 @@ options:
|
|||
required: false
|
||||
service:
|
||||
description:
|
||||
- A reference to BackendService resource.
|
||||
- A reference to expected BackendService resource the given URL should be mapped to.
|
||||
required: false
|
||||
extends_documentation_fragment: gcp
|
||||
'''
|
||||
|
@ -146,19 +147,17 @@ extends_documentation_fragment: gcp
|
|||
EXAMPLES = '''
|
||||
- name: create a instance group
|
||||
gcp_compute_instance_group:
|
||||
name: 'instancegroup-urlmap'
|
||||
zone: 'us-central1-a'
|
||||
name: "instancegroup-urlmap"
|
||||
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-urlmap'
|
||||
name: "httphealthcheck-urlmap"
|
||||
healthy_threshold: 10
|
||||
port: 8080
|
||||
timeout_sec: 2
|
||||
|
@ -166,36 +165,30 @@ 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-urlmap'
|
||||
name: "backendservice-urlmap"
|
||||
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: testObject
|
||||
name: "test_object"
|
||||
default_service: "{{ backendservice }}"
|
||||
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
|
||||
'''
|
||||
|
||||
|
@ -207,7 +200,7 @@ RETURN = '''
|
|||
type: str
|
||||
default_service:
|
||||
description:
|
||||
- A reference to BackendService resource.
|
||||
- A reference to BackendService resource if none of the hostRules match.
|
||||
returned: success
|
||||
type: dict
|
||||
description:
|
||||
|
@ -264,7 +257,8 @@ RETURN = '''
|
|||
contains:
|
||||
default_service:
|
||||
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
|
||||
type: dict
|
||||
description:
|
||||
|
@ -292,7 +286,7 @@ RETURN = '''
|
|||
type: list
|
||||
service:
|
||||
description:
|
||||
- A reference to BackendService resource.
|
||||
- A reference to the BackendService resource if this rule is matched.
|
||||
returned: success
|
||||
type: dict
|
||||
tests:
|
||||
|
@ -319,7 +313,7 @@ RETURN = '''
|
|||
type: str
|
||||
service:
|
||||
description:
|
||||
- A reference to BackendService resource.
|
||||
- A reference to expected BackendService resource the given URL should be mapped to.
|
||||
returned: success
|
||||
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']
|
||||
kind = 'compute#urlMap'
|
||||
|
||||
|
@ -378,10 +375,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:
|
||||
|
@ -401,12 +398,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))
|
||||
|
||||
|
@ -418,7 +415,7 @@ def resource_to_request(module):
|
|||
u'description': module.params.get('description'),
|
||||
u'hostRules': UrlMapHostRulesArray(module.params.get('host_rules', []), module).to_request(),
|
||||
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()
|
||||
}
|
||||
return_vals = {}
|
||||
|
@ -493,7 +490,7 @@ def response_to_hash(module, response):
|
|||
u'hostRules': UrlMapHostRulesArray(response.get(u'hostRules', []), module).from_response(),
|
||||
u'id': response.get(u'id'),
|
||||
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()
|
||||
}
|
||||
|
||||
|
@ -510,7 +507,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#urlMap')
|
||||
|
@ -570,7 +567,7 @@ class UrlMapHostRulesArray(object):
|
|||
})
|
||||
|
||||
|
||||
class UrlMapPathMatchArray(object):
|
||||
class UrlMapPathMatchersArray(object):
|
||||
def __init__(self, request, module):
|
||||
self.module = module
|
||||
if request:
|
||||
|
|
|
@ -15,18 +15,16 @@
|
|||
# Pre-test setup
|
||||
- name: create a instance group
|
||||
gcp_compute_instance_group:
|
||||
name: 'instancegroup-urlmap'
|
||||
zone: 'us-central1-a'
|
||||
name: "instancegroup-urlmap"
|
||||
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-urlmap'
|
||||
name: "httphealthcheck-urlmap"
|
||||
healthy_threshold: 10
|
||||
port: 8080
|
||||
timeout_sec: 2
|
||||
|
@ -34,23 +32,19 @@
|
|||
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-urlmap'
|
||||
name: "backendservice-urlmap"
|
||||
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: delete a url map
|
||||
|
@ -60,8 +54,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 url map
|
||||
|
@ -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: present
|
||||
register: result
|
||||
- name: assert changed is true
|
||||
|
@ -81,13 +71,19 @@
|
|||
- result.changed == true
|
||||
- "result.kind == 'compute#urlMap'"
|
||||
- name: verify that url_map was created
|
||||
shell: |
|
||||
gcloud compute url-maps describe --project="{{ gcp_project}}" "{{ resource_name }}"
|
||||
gcp_compute_url_map_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 url map that already exists
|
||||
gcp_compute_url_map:
|
||||
|
@ -96,8 +92,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
|
||||
|
@ -113,8 +107,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
|
||||
|
@ -123,15 +115,19 @@
|
|||
- result.changed == true
|
||||
- result.has_key('kind') == False
|
||||
- name: verify that url_map was deleted
|
||||
shell: |
|
||||
gcloud compute url-maps describe --project="{{ gcp_project}}" "{{ resource_name }}"
|
||||
gcp_compute_url_map_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/urlMaps/{{ resource_name }}' was not found\" in results.stderr"
|
||||
- results['items'] | length == 0
|
||||
# ----------------------------------------------------------------------------
|
||||
- name: delete a url map that does not exist
|
||||
gcp_compute_url_map:
|
||||
|
@ -140,8 +136,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
|
||||
|
@ -153,22 +147,20 @@
|
|||
# Post-test teardown
|
||||
- name: delete a backend service
|
||||
gcp_compute_backend_service:
|
||||
name: 'backendservice-urlmap'
|
||||
name: "backendservice-urlmap"
|
||||
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-urlmap'
|
||||
name: "httphealthcheck-urlmap"
|
||||
healthy_threshold: 10
|
||||
port: 8080
|
||||
timeout_sec: 2
|
||||
|
@ -176,18 +168,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-urlmap'
|
||||
zone: 'us-central1-a'
|
||||
name: "instancegroup-urlmap"
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue