mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
[GCP] Global Load Balancer Integration Test (#24704)
* Revert to using url_map internal to the module to allow parameter generation to work. module parameter is still url_map_name. * [GCP] Cross Region Load Balancer Integration Test
This commit is contained in:
parent
53180ebb57
commit
13f2d9222f
6 changed files with 370 additions and 1 deletions
|
@ -261,7 +261,7 @@ def main():
|
|||
params['state'] = module.params.get('state')
|
||||
params['target_proxy_name'] = module.params.get('target_proxy_name')
|
||||
params['target_proxy_type'] = module.params.get('target_proxy_type')
|
||||
params['url_map_name'] = module.params.get('url_map_name', None)
|
||||
params['url_map'] = module.params.get('url_map_name', None)
|
||||
|
||||
changed = False
|
||||
json_output = {'state': params['state']}
|
||||
|
|
|
@ -8,5 +8,6 @@
|
|||
- { 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_glb, tags: test_gcp_glb }
|
||||
- { role: test_gcp_healthcheck, tags: test_gcp_healthcheck }
|
||||
# TODO: tests for gce_lb, gc_storage
|
||||
|
|
18
test/integration/roles/test_gcp_glb/defaults/main.yml
Normal file
18
test/integration/roles/test_gcp_glb/defaults/main.yml
Normal file
|
@ -0,0 +1,18 @@
|
|||
---
|
||||
# defaults file for test_gcp_glb
|
||||
service_account_email: "{{ gce_service_account_email }}"
|
||||
credentials_file: "{{ gce_pem_file }}"
|
||||
project_id: "{{ gce_project_id }}"
|
||||
mig_one: ans-int-{{ resource_prefix|lower }}-mig-east
|
||||
mig_two: ans-int-{{ resource_prefix|lower }}-mig-west
|
||||
mig_one_zone: us-east1-c
|
||||
mig_two_zone: us-west1-b
|
||||
http_port_name: ans-int-{{ resource_prefix|lower }}-httpport
|
||||
http_port: 80
|
||||
bes: ans-int-{{ resource_prefix|lower }}-bes
|
||||
bes_healthcheck: ans-int-{{ resource_prefix|lower }}-bes-healthcheck
|
||||
urlmap: ans-int-{{ resource_prefix|lower }}-urlmap
|
||||
targethttpproxy: ans-int-{{ resource_prefix|lower }}-targethttproxy
|
||||
instance_template: ans-int-{{ resource_prefix|lower }}-template
|
||||
external_address_name: ans-int-{{ resource_prefix|lower }}-address
|
||||
gfr: ans-int-{{ resource_prefix|lower }}-gfr
|
6
test/integration/roles/test_gcp_glb/tasks/main.yml
Normal file
6
test/integration/roles/test_gcp_glb/tasks/main.yml
Normal file
|
@ -0,0 +1,6 @@
|
|||
# main driver for Cross Region HTTP load balancer test
|
||||
# this integration test uses multiple modules to create
|
||||
# the HTTP load balancer, then tears it down.
|
||||
- include: test.yml
|
||||
- pause: seconds=10
|
||||
- include: teardown.yml
|
172
test/integration/roles/test_gcp_glb/tasks/teardown.yml
Normal file
172
test/integration/roles/test_gcp_glb/tasks/teardown.yml
Normal file
|
@ -0,0 +1,172 @@
|
|||
# ============================================================
|
||||
- name: Delete Global Forwarding Rule
|
||||
# ============================================================
|
||||
gcp_forwarding_rule:
|
||||
service_account_email: "{{ service_account_email }}"
|
||||
credentials_file: "{{ credentials_file }}"
|
||||
project_id: "{{ project_id }}"
|
||||
forwarding_rule_name: "{{ gfr }}"
|
||||
target: "{{ targethttpproxy }}"
|
||||
address: "{{ external_address_name }}"
|
||||
port_range: 80
|
||||
region: global
|
||||
state: "absent"
|
||||
register: result
|
||||
ignore_errors: true
|
||||
- name: "assert gfr absent"
|
||||
assert:
|
||||
that:
|
||||
- 'result.state == "absent"'
|
||||
- pause: seconds=5
|
||||
# ============================================================
|
||||
- name: Delete Static Address
|
||||
# ============================================================
|
||||
gce_eip:
|
||||
service_account_email: "{{ service_account_email }}"
|
||||
credentials_file: "{{ credentials_file }}"
|
||||
project_id: "{{ project_id }}"
|
||||
name: "{{ external_address_name }}"
|
||||
region: global
|
||||
state: "absent"
|
||||
register: result
|
||||
ignore_errors: true
|
||||
- name: "assert static address absent"
|
||||
assert:
|
||||
that:
|
||||
- 'result.changed'
|
||||
- 'result.state == "absent"'
|
||||
|
||||
# ============================================================
|
||||
- name: Delete TargetHTTPProxy
|
||||
# ============================================================
|
||||
gcp_target_proxy:
|
||||
service_account_email: "{{ service_account_email }}"
|
||||
credentials_file: "{{ credentials_file }}"
|
||||
project_id: "{{ project_id }}"
|
||||
target_proxy_name: "{{ targethttpproxy }}"
|
||||
target_proxy_type: "HTTP"
|
||||
url_map_name: "{{ urlmap }}"
|
||||
state: "absent"
|
||||
register: result
|
||||
ignore_errors: true
|
||||
- name: "assert targethttpproxy absent"
|
||||
assert:
|
||||
that:
|
||||
- 'result.changed'
|
||||
- 'result.state == "absent"'
|
||||
- pause: seconds=5
|
||||
# ============================================================
|
||||
- name: Delete URLMap
|
||||
# ============================================================
|
||||
gcp_url_map:
|
||||
service_account_email: "{{ service_account_email }}"
|
||||
credentials_file: "{{ credentials_file }}"
|
||||
project_id: "{{ project_id }}"
|
||||
url_map_name: "{{ urlmap }}"
|
||||
default_service: "{{ bes }}"
|
||||
state: "absent"
|
||||
register: result
|
||||
ignore_errors: true
|
||||
- name: "assert urlmap absent"
|
||||
assert:
|
||||
that:
|
||||
- 'result.state == "absent"'
|
||||
- pause: seconds=10
|
||||
# ============================================================
|
||||
- name: Delete BES
|
||||
# ============================================================
|
||||
gcp_backend_service:
|
||||
service_account_email: "{{ service_account_email }}"
|
||||
credentials_file: "{{ credentials_file }}"
|
||||
project_id: "{{ project_id }}"
|
||||
backend_service_name: "{{ bes }}"
|
||||
backends:
|
||||
- instance_group: "{{ mig_one }}"
|
||||
- instance_group: "{{ mig_two }}"
|
||||
healthchecks:
|
||||
- "{{ bes_healthcheck }}"
|
||||
port_name: "{{ http_port_name }}"
|
||||
protocol: HTTP
|
||||
timeout: 60
|
||||
state: "absent"
|
||||
register: result
|
||||
- name: "assert backend service absent"
|
||||
assert:
|
||||
that:
|
||||
# - 'result.changed'
|
||||
- 'result.state == "absent"'
|
||||
# ============================================================
|
||||
- name: Delete Healthcheck
|
||||
# ============================================================
|
||||
gcp_healthcheck:
|
||||
service_account_email: "{{ service_account_email }}"
|
||||
credentials_file: "{{ credentials_file }}"
|
||||
project_id: "{{ project_id }}"
|
||||
healthcheck_name: "{{ bes_healthcheck }}"
|
||||
healthcheck_type: "HTTP"
|
||||
state: "absent"
|
||||
- name: "assert healthcheck absent"
|
||||
assert:
|
||||
that:
|
||||
- 'result.state == "absent"'
|
||||
# ============================================================
|
||||
- name: Delete MIG one
|
||||
# ============================================================
|
||||
gce_mig:
|
||||
service_account_email: "{{ service_account_email }}"
|
||||
credentials_file: "{{ credentials_file }}"
|
||||
project_id: "{{ project_id }}"
|
||||
name: "{{ mig_one }}"
|
||||
zone: "{{ mig_one_zone }}"
|
||||
state: "absent"
|
||||
size: 1
|
||||
template: "{{ instance_template }}"
|
||||
named_ports:
|
||||
- name: "{{ http_port_name }}"
|
||||
port: "{{ http_port }}"
|
||||
autoscaling:
|
||||
enabled: yes
|
||||
name: "{{ mig_one }}"
|
||||
policy:
|
||||
min_instances: 2
|
||||
max_instances: 10
|
||||
cool_down_period: 30
|
||||
cpu_utilization:
|
||||
target: 0.02
|
||||
# ============================================================
|
||||
- name: Delete MIG two
|
||||
# ============================================================
|
||||
gce_mig:
|
||||
service_account_email: "{{ service_account_email }}"
|
||||
credentials_file: "{{ credentials_file }}"
|
||||
project_id: "{{ project_id }}"
|
||||
name: "{{ mig_two }}"
|
||||
zone: "{{ mig_two_zone }}"
|
||||
state: "absent"
|
||||
size: 1
|
||||
template: "{{ instance_template }}"
|
||||
named_ports:
|
||||
- name: "{{ http_port_name }}"
|
||||
port: "{{ http_port }}"
|
||||
autoscaling:
|
||||
enabled: yes
|
||||
name: "{{ mig_two }}"
|
||||
policy:
|
||||
min_instances: 2
|
||||
max_instances: 10
|
||||
cool_down_period: 30
|
||||
cpu_utilization:
|
||||
target: 0.02
|
||||
- pause: seconds=30
|
||||
# ============================================================
|
||||
- name: Delete Instance template
|
||||
# ============================================================
|
||||
gce_instance_template:
|
||||
service_account_email: "{{ service_account_email }}"
|
||||
credentials_file: "{{ credentials_file }}"
|
||||
project_id: "{{ project_id }}"
|
||||
name: "{{ instance_template }}"
|
||||
image: rhel-7-v20170426
|
||||
state: "absent"
|
||||
tags:
|
||||
- http-server
|
172
test/integration/roles/test_gcp_glb/tasks/test.yml
Normal file
172
test/integration/roles/test_gcp_glb/tasks/test.yml
Normal file
|
@ -0,0 +1,172 @@
|
|||
# GCP Cross Region Load Balancer integration test
|
||||
# https://cloud.google.com/compute/docs/load-balancing/http/cross-region-example
|
||||
######
|
||||
# ============================================================
|
||||
- name: Create Instance template
|
||||
# ============================================================
|
||||
gce_instance_template:
|
||||
service_account_email: "{{ service_account_email }}"
|
||||
credentials_file: "{{ credentials_file }}"
|
||||
project_id: "{{ project_id }}"
|
||||
name: "{{ instance_template }}"
|
||||
image: rhel-7-v20170426
|
||||
state: "present"
|
||||
tags:
|
||||
- http-server
|
||||
metadata:
|
||||
startup-script: |
|
||||
#!/bin/bash
|
||||
yum install -y httpd curl
|
||||
systemctl start httpd
|
||||
zone=$(curl -sv -H "Metadata-flavor: Google" http://metadata/computeMetadata/v1/instance/zone)
|
||||
host=$(curl -sv -H "Metadata-flavor: Google" http://metadata/computeMetadata/v1/instance/name)
|
||||
echo "${host}-${zone}" > /var/www/html/index.html
|
||||
# ============================================================
|
||||
- name: Create MIG one
|
||||
# ============================================================
|
||||
gce_mig:
|
||||
service_account_email: "{{ service_account_email }}"
|
||||
credentials_file: "{{ credentials_file }}"
|
||||
project_id: "{{ project_id }}"
|
||||
name: "{{ mig_one }}"
|
||||
zone: "{{ mig_one_zone }}"
|
||||
state: "present"
|
||||
size: 1
|
||||
autoscaling:
|
||||
enabled: yes
|
||||
name: "{{ mig_one }}"
|
||||
policy:
|
||||
min_instances: 1
|
||||
max_instances: 3
|
||||
cool_down_period: 60
|
||||
cpu_utilization:
|
||||
target: 0.6
|
||||
template: "{{ instance_template }}"
|
||||
named_ports:
|
||||
- name: "{{ http_port_name }}"
|
||||
port: "{{ http_port }}"
|
||||
# ============================================================
|
||||
- name: Create MIG two
|
||||
# ============================================================
|
||||
gce_mig:
|
||||
service_account_email: "{{ service_account_email }}"
|
||||
credentials_file: "{{ credentials_file }}"
|
||||
project_id: "{{ project_id }}"
|
||||
name: "{{ mig_two }}"
|
||||
zone: "{{ mig_two_zone }}"
|
||||
state: "present"
|
||||
size: 1
|
||||
autoscaling:
|
||||
enabled: yes
|
||||
name: "{{ mig_two }}"
|
||||
policy:
|
||||
min_instances: 1
|
||||
max_instances: 3
|
||||
cool_down_period: 60
|
||||
cpu_utilization:
|
||||
target: 0.6
|
||||
template: "{{ instance_template }}"
|
||||
named_ports:
|
||||
- name: "{{ http_port_name }}"
|
||||
port: "{{ http_port }}"
|
||||
# ============================================================
|
||||
- name: Create Healthcheck
|
||||
# ============================================================
|
||||
gcp_healthcheck:
|
||||
service_account_email: "{{ service_account_email }}"
|
||||
credentials_file: "{{ credentials_file }}"
|
||||
project_id: "{{ project_id }}"
|
||||
healthcheck_name: "{{ bes_healthcheck }}"
|
||||
healthcheck_type: "HTTP"
|
||||
state: "present"
|
||||
# ============================================================
|
||||
- name: Create Backend Service
|
||||
# ============================================================
|
||||
gcp_backend_service:
|
||||
service_account_email: "{{ service_account_email }}"
|
||||
credentials_file: "{{ credentials_file }}"
|
||||
project_id: "{{ project_id }}"
|
||||
backend_service_name: "{{ bes }}"
|
||||
backends:
|
||||
- instance_group: "{{ mig_one }}"
|
||||
balancing_mode: RATE
|
||||
max_rate_per_instance: 10.00
|
||||
- instance_group: "{{ mig_two }}"
|
||||
healthchecks:
|
||||
- "{{ bes_healthcheck }}"
|
||||
port_name: "{{ http_port_name }}"
|
||||
protocol: HTTP
|
||||
timeout: 60
|
||||
state: "present"
|
||||
register: result
|
||||
- name: "assert backend service present"
|
||||
assert:
|
||||
that:
|
||||
- 'result.state == "present"'
|
||||
# ============================================================
|
||||
- name: Create URLMap
|
||||
# ============================================================
|
||||
gcp_url_map:
|
||||
service_account_email: "{{ service_account_email }}"
|
||||
credentials_file: "{{ credentials_file }}"
|
||||
project_id: "{{ project_id }}"
|
||||
url_map_name: "{{ urlmap }}"
|
||||
default_service: "{{ bes }}"
|
||||
state: "present"
|
||||
register: result
|
||||
- name: "assert urlmap present"
|
||||
assert:
|
||||
that:
|
||||
- 'result.state == "present"'
|
||||
- pause: seconds=10
|
||||
# ============================================================
|
||||
- name: Create TargetHTTPProxy
|
||||
# ============================================================
|
||||
gcp_target_proxy:
|
||||
service_account_email: "{{ service_account_email }}"
|
||||
credentials_file: "{{ credentials_file }}"
|
||||
project_id: "{{ project_id }}"
|
||||
target_proxy_name: "{{ targethttpproxy }}"
|
||||
target_proxy_type: "HTTP"
|
||||
url_map_name: "{{ urlmap }}"
|
||||
state: "present"
|
||||
register: result
|
||||
- name: "assert targethttpproxy present"
|
||||
assert:
|
||||
that:
|
||||
- 'result.state == "present"'
|
||||
|
||||
# ============================================================
|
||||
- name: Create Static Address
|
||||
# ============================================================
|
||||
gce_eip:
|
||||
service_account_email: "{{ service_account_email }}"
|
||||
credentials_file: "{{ credentials_file }}"
|
||||
project_id: "{{ project_id }}"
|
||||
name: "{{ external_address_name }}"
|
||||
region: global
|
||||
state: "present"
|
||||
register: result
|
||||
- name: "assert static address present"
|
||||
assert:
|
||||
that:
|
||||
- 'result.state == "present"'
|
||||
|
||||
# ============================================================
|
||||
- name: Create Global Forwarding Rule
|
||||
# ============================================================
|
||||
gcp_forwarding_rule:
|
||||
service_account_email: "{{ service_account_email }}"
|
||||
credentials_file: "{{ credentials_file }}"
|
||||
project_id: "{{ project_id }}"
|
||||
forwarding_rule_name: "{{ gfr }}"
|
||||
region: global
|
||||
target: "{{ targethttpproxy }}"
|
||||
address: "{{ external_address_name }}"
|
||||
port_range: 80
|
||||
state: "present"
|
||||
register: result
|
||||
- name: "assert gfr present"
|
||||
assert:
|
||||
that:
|
||||
- 'result.state == "present"'
|
Loading…
Reference in a new issue