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

View file

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