2017-05-16 15:26:55 +02:00
|
|
|
---
|
2019-10-22 17:17:01 +02:00
|
|
|
# tasks file for aws_lambda test
|
2017-05-16 15:26:55 +02:00
|
|
|
|
2019-10-22 17:17:01 +02:00
|
|
|
- name: set connection information for AWS modules and run tests
|
|
|
|
module_defaults:
|
|
|
|
group/aws:
|
|
|
|
aws_access_key: "{{ aws_access_key }}"
|
|
|
|
aws_secret_key: "{{ aws_secret_key }}"
|
|
|
|
security_token: "{{ security_token | default(omit) }}"
|
|
|
|
region: "{{ aws_region }}"
|
|
|
|
|
|
|
|
block:
|
2017-05-16 15:26:55 +02:00
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
- name: test with no parameters
|
|
|
|
lambda:
|
|
|
|
register: result
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
|
|
- name: assert failure when called with no parameters
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- 'result.failed'
|
|
|
|
- 'result.msg.startswith("missing required arguments: name")'
|
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
- name: test with no parameters except state absent
|
|
|
|
lambda:
|
2019-10-22 17:17:01 +02:00
|
|
|
state: absent
|
2017-05-16 15:26:55 +02:00
|
|
|
register: result
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
|
|
- name: assert failure when called with no parameters
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- 'result.failed'
|
|
|
|
- 'result.msg.startswith("missing required arguments: name")'
|
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
- name: test with no role or handler
|
|
|
|
lambda:
|
2019-10-22 17:17:01 +02:00
|
|
|
name: ansible-testing-fake-should-not-be-created
|
|
|
|
runtime: "python2.7"
|
2017-05-16 15:26:55 +02:00
|
|
|
register: result
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
|
|
- name: assert failure when called with no parameters
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- 'result.failed'
|
2017-10-03 16:17:12 +02:00
|
|
|
- 'result.msg.startswith("state is present but all of the following are missing: handler")'
|
2017-05-16 15:26:55 +02:00
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
- name: test with all module required variables but no region
|
|
|
|
lambda:
|
2019-10-22 17:17:01 +02:00
|
|
|
name: ansible-testing-fake-should-not-be-created
|
|
|
|
runtime: "python2.7"
|
|
|
|
handler: "no-handler"
|
|
|
|
role: "arn:fake-role-doesnt-exist"
|
|
|
|
region:
|
2017-05-16 15:26:55 +02:00
|
|
|
register: result
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
|
|
- name: assert failure when called with only 'name'
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- 'result.failed'
|
|
|
|
- 'result.msg == "region must be specified"'
|
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
- name: test with all module required variables, no region and all possible variables set to blank
|
|
|
|
lambda:
|
|
|
|
name: ansible-testing-fake-should-not-be-created
|
|
|
|
state: present
|
|
|
|
runtime: "python2.7"
|
|
|
|
role: arn:fake-role-doesnt-exist
|
|
|
|
handler:
|
|
|
|
s3_bucket:
|
|
|
|
s3_key:
|
|
|
|
s3_object_version:
|
|
|
|
description:
|
|
|
|
vpc_subnet_ids:
|
|
|
|
vpc_security_group_ids:
|
|
|
|
environment_variables:
|
|
|
|
dead_letter_arn:
|
2019-10-22 17:17:01 +02:00
|
|
|
region:
|
2017-05-16 15:26:55 +02:00
|
|
|
register: result
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
|
|
- name: assert failure when called with only 'name'
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- 'result.failed'
|
|
|
|
- 'result.msg == "region must be specified"'
|
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
# direct zip file upload
|
|
|
|
- name: move lambda into place for archive module
|
|
|
|
copy:
|
|
|
|
src: "mini_lambda.py"
|
|
|
|
dest: "{{output_dir}}/mini_lambda.py"
|
|
|
|
|
|
|
|
- name: bundle lambda into a zip
|
|
|
|
archive:
|
|
|
|
format: zip
|
|
|
|
path: "{{output_dir}}/mini_lambda.py"
|
|
|
|
dest: "{{output_dir}}/mini_lambda.zip"
|
|
|
|
register: zip_res
|
|
|
|
|
|
|
|
- name: test state=present - upload the lambda
|
|
|
|
lambda:
|
2019-10-22 17:17:01 +02:00
|
|
|
name: "{{lambda_function_name}}"
|
|
|
|
runtime: "python2.7"
|
|
|
|
handler: "mini_lambda.handler"
|
|
|
|
role: "ansible_lambda_role"
|
|
|
|
zip_file: "{{zip_res.dest}}"
|
2017-05-16 15:26:55 +02:00
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert lambda upload succeeded
|
|
|
|
assert:
|
|
|
|
that:
|
2019-10-22 17:17:01 +02:00
|
|
|
- result is not failed
|
|
|
|
- result.configuration.tracing_config.mode == "PassThrough"
|
2017-05-16 15:26:55 +02:00
|
|
|
|
|
|
|
- name: test lambda works
|
|
|
|
execute_lambda:
|
|
|
|
name: "{{lambda_function_name}}"
|
|
|
|
payload:
|
|
|
|
name: "Mr Ansible Tests"
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert lambda manages to respond as expected
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 23:58:08 +01:00
|
|
|
- 'result is not failed'
|
2017-05-16 15:26:55 +02:00
|
|
|
- 'result.result.output.message == "hello Mr Ansible Tests"'
|
|
|
|
|
2019-10-22 17:17:01 +02:00
|
|
|
- name: test lambda config updates
|
|
|
|
lambda:
|
|
|
|
name: "{{lambda_function_name}}"
|
|
|
|
runtime: "nodejs10.x"
|
|
|
|
tracing_mode: 'Active'
|
|
|
|
handler: "mini_lambda.handler"
|
|
|
|
role: "ansible_lambda_role"
|
|
|
|
register: update_result
|
|
|
|
|
|
|
|
- name: assert that update succeeded
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- update_result is not failed
|
|
|
|
- update_result.changed == True
|
|
|
|
- update_result.configuration.runtime == 'nodejs10.x'
|
|
|
|
- update_result.configuration.tracing_config.mode == 'Active'
|
|
|
|
|
|
|
|
- name: test no changes are made with the same parameters
|
|
|
|
lambda:
|
|
|
|
name: "{{lambda_function_name}}"
|
|
|
|
runtime: "nodejs10.x"
|
|
|
|
tracing_mode: 'Active'
|
|
|
|
handler: "mini_lambda.handler"
|
|
|
|
role: "ansible_lambda_role"
|
|
|
|
register: update_result
|
|
|
|
|
|
|
|
- name: assert that update succeeded
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- update_result is not failed
|
|
|
|
- update_result.changed == False
|
|
|
|
- update_result.configuration.runtime == 'nodejs10.x'
|
|
|
|
- update_result.configuration.tracing_config.mode == 'Active'
|
|
|
|
|
|
|
|
- name: reset config updates for the following tests
|
|
|
|
lambda:
|
|
|
|
name: "{{lambda_function_name}}"
|
|
|
|
runtime: "python2.7"
|
|
|
|
tracing_mode: 'PassThrough'
|
|
|
|
handler: "mini_lambda.handler"
|
|
|
|
role: "ansible_lambda_role"
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert that reset succeeded
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- result is not failed
|
|
|
|
- result.changed == True
|
|
|
|
- result.configuration.runtime == 'python2.7'
|
|
|
|
- result.configuration.tracing_config.mode == 'PassThrough'
|
|
|
|
|
2017-05-16 15:26:55 +02:00
|
|
|
# ============================================================
|
|
|
|
- name: test state=present with security group but no vpc
|
|
|
|
lambda:
|
|
|
|
name: "{{lambda_function_name}}"
|
|
|
|
runtime: "python2.7"
|
|
|
|
role: "ansible_lambda_role"
|
|
|
|
zip_file: "{{zip_res.dest}}"
|
|
|
|
handler:
|
|
|
|
description:
|
|
|
|
vpc_subnet_ids:
|
|
|
|
vpc_security_group_ids: sg-FA6E
|
|
|
|
environment_variables:
|
|
|
|
dead_letter_arn:
|
|
|
|
register: result
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
|
|
- name: assert lambda fails with proper message
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 23:58:08 +01:00
|
|
|
- 'result is failed'
|
2017-05-16 15:26:55 +02:00
|
|
|
- 'result.msg != "MODULE FAILURE"'
|
|
|
|
- 'result.changed == False'
|
|
|
|
- '"requires at least one security group and one subnet" in result.msg'
|
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
- name: test state=present with all nullable variables explicitly set to null
|
|
|
|
lambda:
|
|
|
|
name: "{{lambda_function_name}}"
|
|
|
|
runtime: "python2.7"
|
|
|
|
role: "ansible_lambda_role"
|
|
|
|
zip_file: "{{zip_res.dest}}"
|
|
|
|
handler: "mini_lambda.handler"
|
|
|
|
# These are not allowed because of mutually exclusive.
|
|
|
|
# s3_bucket:
|
|
|
|
# s3_key:
|
|
|
|
# s3_object_version:
|
|
|
|
description:
|
|
|
|
vpc_subnet_ids:
|
|
|
|
vpc_security_group_ids:
|
|
|
|
environment_variables:
|
|
|
|
dead_letter_arn:
|
|
|
|
register: result
|
|
|
|
|
2017-09-20 21:10:06 +02:00
|
|
|
- name: assert lambda remains as before
|
2017-05-16 15:26:55 +02:00
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 23:58:08 +01:00
|
|
|
- 'result is not failed'
|
2017-05-16 15:26:55 +02:00
|
|
|
- 'result.changed == False'
|
|
|
|
|
2017-09-20 21:10:06 +02:00
|
|
|
# ============================================================
|
|
|
|
- name: test putting an environment variable changes lambda
|
|
|
|
lambda:
|
|
|
|
name: "{{lambda_function_name}}"
|
|
|
|
runtime: "python2.7"
|
|
|
|
handler: "mini_lambda.handler"
|
|
|
|
role: "ansible_lambda_role"
|
|
|
|
zip_file: "{{zip_res.dest}}"
|
|
|
|
environment_variables:
|
|
|
|
EXTRA_MESSAGE: "I think you are great!!"
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert lambda upload succeeded
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 23:58:08 +01:00
|
|
|
- 'result is not failed'
|
2017-09-20 21:10:06 +02:00
|
|
|
- 'result.changed == True'
|
|
|
|
|
|
|
|
- name: test lambda works
|
|
|
|
execute_lambda:
|
|
|
|
name: "{{lambda_function_name}}"
|
|
|
|
payload:
|
|
|
|
name: "Mr Ansible Tests"
|
|
|
|
security_token: '{{security_token}}'
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert lambda manages to respond as expected
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 23:58:08 +01:00
|
|
|
- 'result is not failed'
|
2017-09-20 21:10:06 +02:00
|
|
|
- 'result.result.output.message == "hello Mr Ansible Tests. I think you are great!!"'
|
|
|
|
|
2017-05-16 15:26:55 +02:00
|
|
|
# ============================================================
|
|
|
|
- name: test state=present triggering a network exception due to bad url
|
|
|
|
lambda:
|
|
|
|
name: "{{lambda_function_name}}"
|
|
|
|
runtime: "python2.7"
|
|
|
|
role: "ansible_lambda_role"
|
|
|
|
ec2_url: https://noexist.example.com
|
|
|
|
ec2_region: '{{ec2_region}}'
|
|
|
|
ec2_access_key: 'iamnotreallyanaccesskey'
|
|
|
|
ec2_secret_key: 'thisisabadsecretkey'
|
|
|
|
security_token: 'andthisisabadsecuritytoken'
|
|
|
|
zip_file: "{{zip_res.dest}}"
|
|
|
|
register: result
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
|
|
- name: assert lambda manages to respond as expected
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 23:58:08 +01:00
|
|
|
- 'result is failed'
|
2017-05-16 15:26:55 +02:00
|
|
|
- 'result.changed == False'
|
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
- name: test state=absent (expect changed=False)
|
|
|
|
lambda:
|
2019-10-22 17:17:01 +02:00
|
|
|
name: "{{lambda_function_name}}"
|
|
|
|
state: absent
|
2017-05-16 15:26:55 +02:00
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert state=absent
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 23:58:08 +01:00
|
|
|
- 'result is not failed'
|
2017-05-16 15:26:55 +02:00
|
|
|
- 'result.changed == True'
|
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
# parallel lambda creation
|
|
|
|
|
2018-02-08 07:44:50 +01:00
|
|
|
- name: parallel lambda creation 1/4
|
|
|
|
lambda:
|
|
|
|
name: "{{lambda_function_name}}_1"
|
|
|
|
runtime: "python2.7"
|
|
|
|
handler: "mini_lambda.handler"
|
|
|
|
role: "ansible_lambda_role"
|
|
|
|
zip_file: "{{zip_res.dest}}"
|
|
|
|
async: 1000
|
|
|
|
register: async_1
|
|
|
|
|
|
|
|
- name: parallel lambda creation 2/4
|
|
|
|
lambda:
|
|
|
|
name: "{{lambda_function_name}}_2"
|
|
|
|
runtime: "python2.7"
|
|
|
|
handler: "mini_lambda.handler"
|
|
|
|
role: "ansible_lambda_role"
|
|
|
|
zip_file: "{{zip_res.dest}}"
|
|
|
|
async: 1000
|
|
|
|
register: async_2
|
|
|
|
|
|
|
|
- name: parallel lambda creation 3/4
|
|
|
|
lambda:
|
|
|
|
name: "{{lambda_function_name}}_3"
|
|
|
|
runtime: "python2.7"
|
|
|
|
handler: "mini_lambda.handler"
|
|
|
|
role: "ansible_lambda_role"
|
|
|
|
zip_file: "{{zip_res.dest}}"
|
|
|
|
async: 1000
|
|
|
|
register: async_3
|
|
|
|
|
|
|
|
- name: parallel lambda creation 4/4
|
|
|
|
lambda:
|
|
|
|
name: "{{lambda_function_name}}_4"
|
|
|
|
runtime: "python2.7"
|
|
|
|
handler: "mini_lambda.handler"
|
|
|
|
role: "ansible_lambda_role"
|
|
|
|
zip_file: "{{zip_res.dest}}"
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert lambda manages to respond as expected
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- 'result is not failed'
|
|
|
|
|
|
|
|
- name: wait for async job 1
|
|
|
|
async_status: jid={{ async_1.ansible_job_id }}
|
|
|
|
register: job_result
|
2018-07-30 10:41:49 +02:00
|
|
|
until: job_result is finished
|
2018-02-08 07:44:50 +01:00
|
|
|
retries: 30
|
|
|
|
|
|
|
|
- name: wait for async job 2
|
|
|
|
async_status: jid={{ async_1.ansible_job_id }}
|
|
|
|
register: job_result
|
2018-07-30 10:41:49 +02:00
|
|
|
until: job_result is finished
|
2018-02-08 07:44:50 +01:00
|
|
|
retries: 30
|
|
|
|
|
|
|
|
- name: wait for async job 3
|
|
|
|
async_status: jid={{ async_3.ansible_job_id }}
|
|
|
|
register: job_result
|
2018-07-30 10:41:49 +02:00
|
|
|
until: job_result is finished
|
2018-02-08 07:44:50 +01:00
|
|
|
retries: 30
|
|
|
|
|
|
|
|
|
|
|
|
- name: parallel lambda deletion 1/4
|
|
|
|
lambda:
|
|
|
|
name: "{{lambda_function_name}}_1"
|
|
|
|
state: absent
|
|
|
|
zip_file: "{{zip_res.dest}}"
|
|
|
|
async: 1000
|
|
|
|
register: async_1
|
|
|
|
|
|
|
|
- name: parallel lambda deletion 2/4
|
|
|
|
lambda:
|
|
|
|
name: "{{lambda_function_name}}_2"
|
|
|
|
state: absent
|
|
|
|
zip_file: "{{zip_res.dest}}"
|
|
|
|
async: 1000
|
|
|
|
register: async_2
|
|
|
|
|
|
|
|
- name: parallel lambda deletion 3/4
|
|
|
|
lambda:
|
|
|
|
name: "{{lambda_function_name}}_3"
|
|
|
|
state: absent
|
|
|
|
zip_file: "{{zip_res.dest}}"
|
|
|
|
async: 1000
|
|
|
|
register: async_3
|
|
|
|
|
|
|
|
- name: parallel lambda deletion 4/4
|
|
|
|
lambda:
|
|
|
|
name: "{{lambda_function_name}}_4"
|
|
|
|
state: absent
|
|
|
|
zip_file: "{{zip_res.dest}}"
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert lambda creation has succeeded
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- 'result is not failed'
|
|
|
|
|
|
|
|
- name: wait for async job 1
|
|
|
|
async_status: jid={{ async_1.ansible_job_id }}
|
|
|
|
register: job_result
|
2018-07-30 10:41:49 +02:00
|
|
|
until: job_result is finished
|
2018-02-08 07:44:50 +01:00
|
|
|
retries: 30
|
|
|
|
|
|
|
|
- name: wait for async job 2
|
|
|
|
async_status: jid={{ async_1.ansible_job_id }}
|
|
|
|
register: job_result
|
2018-07-30 10:41:49 +02:00
|
|
|
until: job_result is finished
|
2018-02-08 07:44:50 +01:00
|
|
|
retries: 30
|
|
|
|
|
|
|
|
- name: wait for async job 3
|
|
|
|
async_status: jid={{ async_3.ansible_job_id }}
|
|
|
|
register: job_result
|
2018-07-30 10:41:49 +02:00
|
|
|
until: job_result is finished
|
2018-02-08 07:44:50 +01:00
|
|
|
retries: 30
|
2017-05-16 15:26:55 +02:00
|
|
|
|
2019-10-22 17:17:01 +02:00
|
|
|
# ============================================================
|
2017-05-16 15:26:55 +02:00
|
|
|
always:
|
|
|
|
|
2019-10-22 17:17:01 +02:00
|
|
|
- name: ensure function is absent at end of test
|
2017-05-16 15:26:55 +02:00
|
|
|
lambda:
|
2019-10-22 17:17:01 +02:00
|
|
|
name: "{{lambda_function_name}}"
|
|
|
|
state: absent
|
|
|
|
ignore_errors: true
|