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_https_health_check (#42813)

This commit is contained in:
Alex Stephen 2018-08-13 09:08:42 -07:00 committed by Ryan Brown
parent 6b5f86a4aa
commit c239e6f045
2 changed files with 73 additions and 75 deletions

View file

@ -32,8 +32,8 @@ DOCUMENTATION = '''
--- ---
module: gcp_compute_https_health_check module: gcp_compute_https_health_check
description: description:
- An HttpsHealthCheck resource. This resource defines a template for how - An HttpsHealthCheck resource. This resource defines a template for how individual
individual VMs should be checked for health, via HTTPS. VMs should be checked for health, via HTTPS.
short_description: Creates a GCP HttpsHealthCheck short_description: Creates a GCP HttpsHealthCheck
version_added: 2.6 version_added: 2.6
author: Google Inc. (@googlecloudplatform) author: Google Inc. (@googlecloudplatform)
@ -45,39 +45,36 @@ options:
state: state:
description: description:
- Whether the given object should exist in GCP - Whether the given object should exist in GCP
required: true
choices: ['present', 'absent'] choices: ['present', 'absent']
default: 'present' default: 'present'
check_interval_sec: check_interval_sec:
description: description:
- How often (in seconds) to send a health check. The default value - How often (in seconds) to send a health check. The default value is 5 seconds.
is 5 seconds.
required: false required: false
description: description:
description: description:
- An optional description of this resource. Provide this property - An optional description of this resource. Provide this property when you create
when you create the resource. the resource.
required: false required: false
healthy_threshold: healthy_threshold:
description: description:
- A so-far unhealthy instance will be marked healthy after this many - A so-far unhealthy instance will be marked healthy after this many consecutive successes.
consecutive successes. The default value is 2. The default value is 2.
required: false required: false
host: host:
description: description:
- The value of the host header in the HTTPS health check request. If - The value of the host header in the HTTPS health check request. If left empty (default
left empty (default value), the public IP on behalf of which this value), the public IP on behalf of which this health check is performed will be
health check is performed will be used. used.
required: false required: false
name: name:
description: description:
- Name of the resource. Provided by the client when the resource is - Name of the resource. Provided by the client when the resource is created. The name
created. The name must be 1-63 characters long, and comply with must be 1-63 characters long, and comply with RFC1035. Specifically, the name must
RFC1035. Specifically, the name must be 1-63 characters long and be 1-63 characters long and match the regular expression `[a-z]([-a-z0-9]*[a-z0-9])?`
match the regular expression `[a-z]([-a-z0-9]*[a-z0-9])?` which which means the first character must be a lowercase letter, and all following characters
means the first character must be a lowercase letter, and all must be a dash, lowercase letter, or digit, except the last character, which cannot
following characters must be a dash, lowercase letter, or digit, be a dash.
except the last character, which cannot be a dash.
required: true required: true
port: port:
description: description:
@ -92,39 +89,39 @@ options:
timeout_sec: timeout_sec:
description: description:
- How long (in seconds) to wait before claiming failure. - How long (in seconds) to wait before claiming failure.
- The default value is 5 seconds. It is invalid for timeoutSec to - The default value is 5 seconds. It is invalid for timeoutSec to have greater value
have greater value than checkIntervalSec. than checkIntervalSec.
required: false required: false
aliases: [timeout_seconds] aliases: [timeout_seconds]
unhealthy_threshold: unhealthy_threshold:
description: description:
- A so-far healthy instance will be marked unhealthy after this many - A so-far healthy instance will be marked unhealthy after this many consecutive failures.
consecutive failures. The default value is 2. The default value is 2.
required: false required: false
extends_documentation_fragment: gcp extends_documentation_fragment: gcp
notes:
- "API Reference: U(https://cloud.google.com/compute/docs/reference/latest/httpsHealthChecks)"
- "Adding Health Checks: U(https://cloud.google.com/compute/docs/load-balancing/health-checks#legacy_health_checks)"
''' '''
EXAMPLES = ''' EXAMPLES = '''
- name: create a https health check - name: create a https health check
gcp_compute_https_health_check: gcp_compute_https_health_check:
name: testObject name: "test_object"
healthy_threshold: 10 healthy_threshold: 10
port: 8080 port: 8080
timeout_sec: 2 timeout_sec: 2
unhealthy_threshold: 5 unhealthy_threshold: 5
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
''' '''
RETURN = ''' RETURN = '''
check_interval_sec: check_interval_sec:
description: description:
- How often (in seconds) to send a health check. The default value - How often (in seconds) to send a health check. The default value is 5 seconds.
is 5 seconds.
returned: success returned: success
type: int type: int
creation_timestamp: creation_timestamp:
@ -134,38 +131,36 @@ RETURN = '''
type: str type: str
description: description:
description: description:
- An optional description of this resource. Provide this property - An optional description of this resource. Provide this property when you create
when you create the resource. the resource.
returned: success returned: success
type: str type: str
healthy_threshold: healthy_threshold:
description: description:
- A so-far unhealthy instance will be marked healthy after this many - A so-far unhealthy instance will be marked healthy after this many consecutive successes.
consecutive successes. The default value is 2. The default value is 2.
returned: success returned: success
type: int type: int
host: host:
description: description:
- The value of the host header in the HTTPS health check request. If - The value of the host header in the HTTPS health check request. If left empty (default
left empty (default value), the public IP on behalf of which this value), the public IP on behalf of which this health check is performed will be
health check is performed will be used. used.
returned: success returned: success
type: str type: str
id: id:
description: description:
- The unique identifier for the resource. This identifier is defined - The unique identifier for the resource. This identifier is defined by the server.
by the server.
returned: success returned: success
type: int type: int
name: name:
description: description:
- Name of the resource. Provided by the client when the resource is - Name of the resource. Provided by the client when the resource is created. The name
created. The name must be 1-63 characters long, and comply with must be 1-63 characters long, and comply with RFC1035. Specifically, the name must
RFC1035. Specifically, the name must be 1-63 characters long and be 1-63 characters long and match the regular expression `[a-z]([-a-z0-9]*[a-z0-9])?`
match the regular expression `[a-z]([-a-z0-9]*[a-z0-9])?` which which means the first character must be a lowercase letter, and all following characters
means the first character must be a lowercase letter, and all must be a dash, lowercase letter, or digit, except the last character, which cannot
following characters must be a dash, lowercase letter, or digit, be a dash.
except the last character, which cannot be a dash.
returned: success returned: success
type: str type: str
port: port:
@ -183,14 +178,14 @@ RETURN = '''
timeout_sec: timeout_sec:
description: description:
- How long (in seconds) to wait before claiming failure. - How long (in seconds) to wait before claiming failure.
- The default value is 5 seconds. It is invalid for timeoutSec to - The default value is 5 seconds. It is invalid for timeoutSec to have greater value
have greater value than checkIntervalSec. than checkIntervalSec.
returned: success returned: success
type: int type: int
unhealthy_threshold: unhealthy_threshold:
description: description:
- A so-far healthy instance will be marked unhealthy after this many - A so-far healthy instance will be marked unhealthy after this many consecutive failures.
consecutive failures. The default value is 2. The default value is 2.
returned: success returned: success
type: int type: int
''' '''
@ -226,6 +221,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#httpsHealthCheck' kind = 'compute#httpsHealthCheck'
@ -235,10 +233,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:
@ -258,12 +256,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))
@ -353,7 +351,7 @@ def response_to_hash(module, response):
u'healthyThreshold': response.get(u'healthyThreshold'), u'healthyThreshold': response.get(u'healthyThreshold'),
u'host': response.get(u'host'), u'host': response.get(u'host'),
u'id': response.get(u'id'), u'id': response.get(u'id'),
u'name': response.get(u'name'), u'name': module.params.get('name'),
u'port': response.get(u'port'), u'port': response.get(u'port'),
u'requestPath': response.get(u'requestPath'), u'requestPath': response.get(u'requestPath'),
u'timeoutSec': response.get(u'timeoutSec'), u'timeoutSec': response.get(u'timeoutSec'),
@ -373,7 +371,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#httpsHealthCheck') return fetch_resource(module, navigate_hash(wait_done, ['targetLink']), 'compute#httpsHealthCheck')

View file

@ -23,8 +23,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 https health check - name: create a https health check
@ -37,8 +35,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
@ -47,13 +43,19 @@
- result.changed == true - result.changed == true
- "result.kind == 'compute#httpsHealthCheck'" - "result.kind == 'compute#httpsHealthCheck'"
- name: verify that https_health_check was created - name: verify that https_health_check was created
shell: | gcp_compute_https_health_check_facts:
gcloud compute https-health-checks 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 https health check that already exists - name: create a https health check that already exists
gcp_compute_https_health_check: gcp_compute_https_health_check:
@ -65,8 +67,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
@ -85,8 +85,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
@ -95,15 +93,19 @@
- result.changed == true - result.changed == true
- result.has_key('kind') == False - result.has_key('kind') == False
- name: verify that https_health_check was deleted - name: verify that https_health_check was deleted
shell: | gcp_compute_https_health_check_facts:
gcloud compute https-health-checks 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/httpsHealthChecks/{{ resource_name }}' was not found\" in results.stderr"
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
- name: delete a https health check that does not exist - name: delete a https health check that does not exist
gcp_compute_https_health_check: gcp_compute_https_health_check:
@ -115,8 +117,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