forked from ansible-collections/amazon.aws
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ability to record and replay module for testing purpose (ansible-…
…collections#998) add ability to record and replay module for testing purpose Depends-On: ansible/ansible-zuul-jobs#1619 Use lib placebo (https://pypi.org/project/placebo/) to record the API interaction. This allow us to replay later a previous interaction offline and cover some cases that are hard to reproduce in a CI. Reviewed-by: Mark Chappell <None> Reviewed-by: Gonéri Le Bouder <[email protected]>
- Loading branch information
Showing
7 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
minor_changes: | ||
- Ability to record and replay the API interaction of a module for testing purpose. Show case the feature with an example (https://github.com/ansible-collections/amazon.aws/pull/998). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
tests/integration/targets/module_utils_botocore_recorder/aliases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module_utils_botocore |
12 changes: 12 additions & 0 deletions
12
tests/integration/targets/module_utils_botocore_recorder/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
- hosts: localhost | ||
tasks: | ||
- name: Call aws_az_info | ||
amazon.aws.aws_az_info: | ||
register: result | ||
- name: Get called information | ||
amazon.aws.aws_caller_info: | ||
register: result | ||
- assert: | ||
that: | ||
- lookup('ansible.builtin.env', '_ANSIBLE_PLACEBO_RECORD') or (lookup('ansible.builtin.env', '_ANSIBLE_PLACEBO_REPLAY') and result.user_id == "AWZBREIZHEOMABRONIFVGFS6GH") |
23 changes: 23 additions & 0 deletions
23
tests/integration/targets/module_utils_botocore_recorder/record.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/env bash | ||
# | ||
set -eux | ||
|
||
if [ -d recording ]; then | ||
echo "Please check and remove the 'recording' directory." | ||
exit 1 | ||
fi | ||
if [ -v ANSIBLE_TEST_PYTHON_VERSION ]; then | ||
echo "Please call ./runme.sh directly without ansible-test" | ||
exit 1 | ||
fi | ||
export _ANSIBLE_PLACEBO_RECORD=recording | ||
|
||
mkdir recording | ||
ansible-playbook main.yml -vvv | ||
account_id=$(aws sts get-caller-identity --query "Account" --output text) | ||
user_id=$(aws sts get-caller-identity --query "UserId" --output text) | ||
find recording -type f -exec sed -i "s,$account_id,1111111111111,g" "{}" \; | ||
find recording -type f -exec sed -i "s,$user_id,AWZBREIZHEOMABRONIFVGFS6GH,g" "{}" \; | ||
find recording -type f -exec sed -i "s,$USER,george,g" "{}" \; | ||
tar cfzv recording.tar.gz recording | ||
rm -r recording |
Binary file added
BIN
+967 Bytes
tests/integration/targets/module_utils_botocore_recorder/recording.tar.gz
Binary file not shown.
15 changes: 15 additions & 0 deletions
15
tests/integration/targets/module_utils_botocore_recorder/runme.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/env bash | ||
# | ||
|
||
set -eux | ||
|
||
export ANSIBLE_ROLES_PATH=../ | ||
|
||
|
||
tar xfzv recording.tar.gz | ||
export _ANSIBLE_PLACEBO_REPLAY=${PWD}/recording | ||
export AWS_ACCESS_KEY_ID=disabled | ||
export AWS_SECRET_ACCESS_KEY=disabled | ||
export AWS_SESSION_TOKEN=disabled | ||
export AWS_DEFAULT_REGION=us-east-2 | ||
ansible-playbook main.yml -vvv |