From 140ea7f5ff8a0fb706020e83fffa09b0aef0c713 Mon Sep 17 00:00:00 2001 From: mikedlr Date: Wed, 20 Sep 2017 20:10:06 +0100 Subject: [PATCH] lambda integration tests - test to show that environment config has an effect (#28815) --- .../targets/aws_lambda/files/mini_lambda.py | 12 +++++- .../targets/aws_lambda/tasks/main.yml | 43 ++++++++++++++++++- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/test/integration/targets/aws_lambda/files/mini_lambda.py b/test/integration/targets/aws_lambda/files/mini_lambda.py index 790225c28ad..b499888ed94 100644 --- a/test/integration/targets/aws_lambda/files/mini_lambda.py +++ b/test/integration/targets/aws_lambda/files/mini_lambda.py @@ -1,5 +1,6 @@ from __future__ import print_function import json +import os def handler(event, context): @@ -17,7 +18,16 @@ def handler(event, context): name = event["name"] - return {"message": "hello " + name} + # we can use environment variables as part of the configuration of the lambda + # which can change the behaviour of the lambda without needing a new upload + + extra = os.environ.get("EXTRA_MESSAGE") + if extra is not None and len(extra) > 0: + greeting = "hello {0}. {1}".format(name, extra) + else: + greeting = "hello " + name + + return {"message": greeting} def main(): diff --git a/test/integration/targets/aws_lambda/tasks/main.yml b/test/integration/targets/aws_lambda/tasks/main.yml index 204c9efe3e8..2fab6e9c383 100644 --- a/test/integration/targets/aws_lambda/tasks/main.yml +++ b/test/integration/targets/aws_lambda/tasks/main.yml @@ -185,12 +185,53 @@ dead_letter_arn: register: result - - name: assert lambda was updated as expected + - name: assert lambda remains as before assert: that: - 'not result|failed' - 'result.changed == False' + + + # ============================================================ + - name: test putting an environment variable changes lambda + lambda: + name: "{{lambda_function_name}}" + runtime: "python2.7" + handler: "mini_lambda.handler" + role: "ansible_lambda_role" + ec2_region: '{{ec2_region}}' + ec2_access_key: '{{ec2_access_key}}' + ec2_secret_key: '{{ec2_secret_key}}' + security_token: '{{security_token}}' + zip_file: "{{zip_res.dest}}" + environment_variables: + EXTRA_MESSAGE: "I think you are great!!" + register: result + + - name: assert lambda upload succeeded + assert: + that: + - 'not result|failed' + - 'result.changed == True' + + - name: test lambda works + execute_lambda: + name: "{{lambda_function_name}}" + payload: + name: "Mr Ansible Tests" + ec2_region: '{{ec2_region}}' + ec2_access_key: '{{ec2_access_key}}' + ec2_secret_key: '{{ec2_secret_key}}' + security_token: '{{security_token}}' + register: result + + - name: assert lambda manages to respond as expected + assert: + that: + - 'not result|failed' + - 'result.result.output.message == "hello Mr Ansible Tests. I think you are great!!"' + # ============================================================ - name: test state=present triggering a network exception due to bad url lambda: