Skip to content

Commit

Permalink
Add integration tests for aws_resource_actions (ansible-collections#876)
Browse files Browse the repository at this point in the history
Add integration tests for aws_resource_actions

SUMMARY
Add some minimal integration tests for the aws_resource_actions callback plugin.
ISSUE TYPE

Feature Pull Request

COMPONENT NAME
plugins/callback/aws_resource_actions.py
ADDITIONAL INFORMATION
Combined with ansible-collections#873 we've got a full set...

Reviewed-by: Alina Buzachis <None>
  • Loading branch information
tremble authored and jatorcasso committed Jun 24, 2022
1 parent 14f571e commit 397ca06
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cloud/aws
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[tests]
localhost

[all:vars]
ansible_connection=local
ansible_python_interpreter="{{ ansible_playbook_python }}"
35 changes: 35 additions & 0 deletions tests/integration/targets/callback_aws_resource_actions/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
- hosts: localhost
gather_facts: no
collections:
- amazon.aws
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 }}"
tasks:
- ec2_instance_info:
register: ec2_info

- assert:
that:
- '"resource_actions" in ec2_info'
- '"ec2:DescribeInstances" in ec2_info.resource_actions'

- aws_az_info:
register: az_info

- assert:
that:
- '"resource_actions" in az_info'
- '"ec2:DescribeAvailabilityZones" in az_info.resource_actions'

- aws_caller_info:
register: caller_info

- assert:
that:
- '"resource_actions" in caller_info'
- '"sts:GetCallerIdentity" in caller_info.resource_actions'
- '"iam:ListAccountAliases" in caller_info.resource_actions'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dependencies: []
19 changes: 19 additions & 0 deletions tests/integration/targets/callback_aws_resource_actions/runme.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

set -eux

export ANSIBLE_CALLBACK_WHITELIST="aws_resource_actions"

OUTFILE="callback_aws_resource_actions.out"
trap 'rm -rvf "${OUTFILE}" "${OUTFILE}.actions"' EXIT

# Tests that the resource_actions are added to each task
ansible-playbook main.yml -i localhost "$@" | tee "${OUTFILE}"

# There should be a summary at the end of the run with the actions performed:
# AWS ACTIONS: ['ec2:DescribeAvailabilityZones', 'ec2:DescribeInstances', 'iam:ListAccountAliases', 'sts:GetCallerIdentity']
grep -E "AWS ACTIONS: \[" "${OUTFILE}" > "${OUTFILE}.actions"
for action in 'ec2:DescribeAvailabilityZones' 'ec2:DescribeInstances' 'iam:ListAccountAliases' 'sts:GetCallerIdentity'
do
grep "${action}" "${OUTFILE}.actions"
done
3 changes: 0 additions & 3 deletions tests/integration/targets/legacy_missing_tests/aliases
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,3 @@ disabled

# Lookup plugins
aws_ssm

# Callback plugin
aws_resource_actions

0 comments on commit 397ca06

Please sign in to comment.