Bug fixes for gcp_compute_http_health_check (#42812)

This commit is contained in:
Alex Stephen 2018-08-15 10:52:00 -07:00 committed by Ryan Brown
parent 1db54dd6a1
commit 60e78f33ce
2 changed files with 74 additions and 75 deletions

View file

@ -32,8 +32,8 @@ DOCUMENTATION = '''
---
module: gcp_compute_http_health_check
description:
- An HttpHealthCheck resource. This resource defines a template for how
individual VMs should be checked for health, via HTTP.
- An HttpHealthCheck resource. This resource defines a template for how individual
VMs should be checked for health, via HTTP.
short_description: Creates a GCP HttpHealthCheck
version_added: 2.6
author: Google Inc. (@googlecloudplatform)
@ -45,40 +45,38 @@ 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
default: 5
aliases: [check_interval_seconds]
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 HTTP 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 HTTP 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:
@ -93,39 +91,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/httpHealthChecks)"
- "Adding Health Checks: U(https://cloud.google.com/compute/docs/load-balancing/health-checks#legacy_health_checks)"
'''
EXAMPLES = '''
- name: create a http health check
gcp_compute_http_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:
@ -135,38 +133,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 HTTP 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 HTTP 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:
@ -184,14 +180,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
'''
@ -215,7 +211,7 @@ def main():
module = GcpModule(
argument_spec=dict(
state=dict(default='present', choices=['present', 'absent'], type='str'),
check_interval_sec=dict(type='int', aliases=['check_interval_seconds']),
check_interval_sec=dict(default=5, type='int', aliases=['check_interval_seconds']),
description=dict(type='str'),
healthy_threshold=dict(type='int'),
host=dict(type='str'),
@ -227,6 +223,9 @@ def main():
)
)
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
state = module.params['state']
kind = 'compute#httpHealthCheck'
@ -236,10 +235,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:
@ -259,12 +258,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))
@ -374,7 +373,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#httpHealthCheck')

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 http 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#httpHealthCheck'"
- name: verify that http_health_check was created
shell: |
gcloud compute http-health-checks describe --project="{{gcp_project}}" "{{ resource_name }}"
gcp_compute_http_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 http health check that already exists
gcp_compute_http_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 http_health_check was deleted
shell: |
gcloud compute http-health-checks describe --project="{{gcp_project}}" "{{ resource_name }}"
gcp_compute_http_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/httpHealthChecks/{{ resource_name }}' was not found\" in results.stderr"
- results['items'] | length == 0
# ----------------------------------------------------------------------------
- name: delete a http health check that does not exist
gcp_compute_http_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