[GCP] Healthcheck module (#24564)

* [GCP] Healthcheck module

* fix return YAML block

* removed update_ return value; removed python26 check; typos and docs updates

* doc fix

* Updated int test for no-update conditions

* added filter_gcp_fields test

* fixed bug in update where dictionary wasn't built correctly and port was not being set.

* added default values to documentation block
This commit is contained in:
Tom Melendez 2017-05-18 09:49:50 -07:00 committed by Ryan Brown
commit c99c3b2b5d
5 changed files with 682 additions and 0 deletions

View file

@ -8,4 +8,5 @@
- { role: test_gce_tag, tags: test_gce_tag }
- { role: test_gce_net, tags: test_gce_net }
- { role: test_gcp_url_map, tags: test_gcp_url_map }
- { role: test_gcp_healthcheck, tags: test_gcp_healthcheck }
# TODO: tests for gce_lb, gc_storage

View file

@ -0,0 +1,7 @@
---
# defaults file for test_gcp_healthcheck
service_account_email: "{{ gce_service_account_email }}"
credentials_file: "{{ gce_pem_file }}"
project_id: "{{ gce_project_id }}"
http_healthcheck: "ans-int-healthcheck-http-{{ resource_prefix|lower }}"
https_healthcheck: "ans-int-healthcheck-https-{{ resource_prefix|lower }}"

View file

@ -0,0 +1,176 @@
# GCP Healthcheck Integration Tests.
######
# ============================================================
- name: param check
# ============================================================
gcp_healthcheck:
service_account_email: "{{ service_account_email }}"
credentials_file: "{{ credentials_file }}"
project_id: "{{ project_id }}"
healthcheck_name: "{{ http_healthcheck }}"
healthcheck_type: HTTP
host_header: my-host
request_path: /hc
check_interval: 10
timeout: 30
unhealthy_threshold: 2
healthy_threshold: 1
state: present
ignore_errors: True
register: result
- name: check interval
assert:
that:
'result.msg == "timeout (30) is greater than check_interval (10)"'
# ============================================================
- name: create "{{ http_healthcheck }}"
# ============================================================
gcp_healthcheck:
service_account_email: "{{ service_account_email }}"
credentials_file: "{{ credentials_file }}"
project_id: "{{ project_id }}"
healthcheck_name: "{{ http_healthcheck }}"
healthcheck_type: HTTP
host_header: my-host
request_path: /hc
check_interval: 5
timeout: 5
unhealthy_threshold: 2
healthy_threshold: 1
state: present
register: result
- name: assert create
assert:
that:
- 'result.state == "present"'
- 'result.changed'
# ============================================================
- name: "update {{ http_healthcheck }}, no change"
# ============================================================
gcp_healthcheck:
service_account_email: "{{ service_account_email }}"
credentials_file: "{{ credentials_file }}"
project_id: "{{ project_id }}"
healthcheck_name: "{{ http_healthcheck }}"
healthcheck_type: HTTP
host_header: my-host
request_path: /hc
check_interval: 5
timeout: 5
unhealthy_threshold: 2
healthy_threshold: 1
state: present
register: result
- name: assert update no change
assert:
that:
- 'result.state == "present"'
- 'not result.changed'
- 'result.port == 80'
# ============================================================
- name: create minimum "{{ https_healthcheck }}"
# ============================================================
gcp_healthcheck:
service_account_email: "{{ service_account_email }}"
credentials_file: "{{ credentials_file }}"
project_id: "{{ project_id }}"
healthcheck_name: "{{ https_healthcheck }}"
healthcheck_type: HTTPS
state: present
register: result
- name: assert create
assert:
that:
- 'result.state == "present"'
- 'result.changed'
# ============================================================
- name: "update {{ https_healthcheck }}, no change"
# ============================================================
gcp_healthcheck:
service_account_email: "{{ service_account_email }}"
credentials_file: "{{ credentials_file }}"
project_id: "{{ project_id }}"
healthcheck_name: "{{ https_healthcheck }}"
healthcheck_type: HTTPS
state: present
register: result
- name: assert not updated
assert:
that:
- 'result.state == "present"'
- 'result.port == 443'
- 'not result.changed'
# ============================================================
- name: update "{{ https_healthcheck }}"
# ============================================================
gcp_healthcheck:
service_account_email: "{{ service_account_email }}"
credentials_file: "{{ credentials_file }}"
project_id: "{{ project_id }}"
healthcheck_name: "{{ https_healthcheck }}"
healthcheck_type: HTTPS
host_header: my-host
request_path: /hc
check_interval: 5
timeout: 5
unhealthy_threshold: 2
healthy_threshold: 1
port: 444
state: present
register: result
- name: assert update "{{ https_healthcheck }}"
assert:
that:
- 'result.state == "present"'
- 'result.changed'
- 'result.port == 444'
# ============================================================
- pause: seconds=5
# ============================================================
- name: delete "{{ http_healthcheck }}"
# ============================================================
gcp_healthcheck:
service_account_email: "{{ service_account_email }}"
credentials_file: "{{ credentials_file }}"
project_id: "{{ project_id }}"
healthcheck_name: "{{ http_healthcheck }}"
healthcheck_type: HTTP
host_header: my-host
request_path: /hc
check_interval: 5
timeout: 5
unhealthy_threshold: 2
healthy_threshold: 1
state: absent
register: result
tags:
- delete
- name: assert absent
assert:
that:
- 'result.state == "absent"'
- 'result.changed'
# ============================================================
- name: delete "{{ https_healthcheck }}"
# ============================================================
gcp_healthcheck:
service_account_email: "{{ service_account_email }}"
credentials_file: "{{ credentials_file }}"
project_id: "{{ project_id }}"
healthcheck_name: "{{ https_healthcheck }}"
healthcheck_type: HTTPS
host_header: my-host
request_path: /hc
check_interval: 5
timeout: 5
unhealthy_threshold: 2
healthy_threshold: 1
state: absent
register: result
tags:
- delete
- name: assert absent
assert:
that:
- 'result.state == "absent"'
- 'result.changed'

View file

@ -342,3 +342,32 @@ class GCPUtilsTestCase(unittest.TestCase):
# params1 has exclude fields, params2 doesn't. Should be equal
actual = GCPUtils.are_params_equal(params1, params2)
self.assertTrue(actual)
def test_filter_gcp_fields(self):
input_data = {
u'kind': u'compute#httpsHealthCheck',
u'description': u'',
u'timeoutSec': 5,
u'checkIntervalSec': 5,
u'port': 443,
u'healthyThreshold': 2,
u'host': u'',
u'requestPath': u'/',
u'unhealthyThreshold': 2,
u'creationTimestamp': u'2017-05-16T15:09:36.546-07:00',
u'id': u'8727093129334146639',
u'selfLink': u'https://www.googleapis.com/compute/v1/projects/myproject/global/httpsHealthChecks/myhealthcheck',
u'name': u'myhealthcheck'}
expected = {
'name': 'myhealthcheck',
'checkIntervalSec': 5,
'port': 443,
'unhealthyThreshold': 2,
'healthyThreshold': 2,
'host': '',
'timeoutSec': 5,
'requestPath': '/'}
actual = GCPUtils.filter_gcp_fields(input_data)
self.assertEquals(expected, actual)