forked from ansible-collections/community.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.
Ensure that waiters.get_waiter() can support a wrapped client (ansibl…
- Loading branch information
Showing
9 changed files
with
115 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
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,2 @@ | ||
cloud/aws | ||
shippable/aws/group2 |
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,6 @@ | ||
[tests] | ||
localhost | ||
|
||
[all:vars] | ||
ansible_connection=local | ||
ansible_python_interpreter="{{ ansible_playbook_python }}" |
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,7 @@ | ||
- hosts: all | ||
gather_facts: no | ||
collections: | ||
- amazon.aws | ||
roles: | ||
# Test the behaviour of module_utils.core.AnsibleAWSModule.client (boto3) | ||
- 'get_waiter' |
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 @@ | ||
dependencies: | ||
- prepare_tests | ||
- setup_ec2 |
44 changes: 44 additions & 0 deletions
44
tests/integration/targets/module_utils_waiter/roles/get_waiter/library/example_module.py
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,44 @@ | ||
#!/usr/bin/python | ||
# Copyright (c) 2017 Ansible Project | ||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) | ||
|
||
# A bare-minimum Ansible Module based on AnsibleAWSModule used for testing some | ||
# of the core behaviour around AWS/Boto3 connection details | ||
|
||
from __future__ import (absolute_import, division, print_function) | ||
__metaclass__ = type | ||
|
||
|
||
try: | ||
from botocore.exceptions import BotoCoreError, ClientError | ||
except ImportError: | ||
pass # Handled by AnsibleAWSModule | ||
|
||
from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule | ||
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry | ||
from ansible_collections.amazon.aws.plugins.module_utils.waiters import get_waiter | ||
|
||
|
||
def main(): | ||
argument_spec = dict( | ||
client=dict(required=True, type='str'), | ||
waiter_name=dict(required=True, type='str'), | ||
with_decorator=dict(required=False, type='bool', default=False), | ||
) | ||
module = AnsibleAWSModule( | ||
argument_spec=argument_spec, | ||
supports_check_mode=True, | ||
) | ||
|
||
decorator = None | ||
if module.params.get('with_decorator'): | ||
decorator = AWSRetry.jittered_backoff() | ||
|
||
client = module.client(module.params.get('client'), retry_decorator=decorator) | ||
waiter = get_waiter(client, module.params.get('waiter_name')) | ||
|
||
module.exit_json(changed=False, waiter_attributes=dir(waiter)) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
5 changes: 5 additions & 0 deletions
5
tests/integration/targets/module_utils_waiter/roles/get_waiter/meta/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,5 @@ | ||
dependencies: | ||
- prepare_tests | ||
- setup_ec2 | ||
collections: | ||
- amazon.aws |
36 changes: 36 additions & 0 deletions
36
tests/integration/targets/module_utils_waiter/roles/get_waiter/tasks/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,36 @@ | ||
--- | ||
- module_defaults: | ||
example_module: | ||
region: '{{ aws_region }}' | ||
access_key: '{{ aws_access_key }}' | ||
secret_key: '{{ aws_secret_key }}' | ||
security_token: '{{ security_token | default(omit) }}' | ||
block: | ||
- name: 'Attempt to get a waiter (no retry decorator)' | ||
example_module: | ||
client: 'ec2' | ||
waiter_name: 'internet_gateway_exists' | ||
register: test_no_decorator | ||
|
||
- assert: | ||
that: | ||
- test_no_decorator is succeeded | ||
# Standard methods on a boto3 wrapper | ||
- '"wait" in test_no_decorator.waiter_attributes' | ||
- '"name" in test_no_decorator.waiter_attributes' | ||
- '"config" in test_no_decorator.waiter_attributes' | ||
|
||
- name: 'Attempt to get a waiter (with decorator)' | ||
example_module: | ||
client: 'ec2' | ||
waiter_name: 'internet_gateway_exists' | ||
with_decorator: True | ||
register: test_with_decorator | ||
|
||
- assert: | ||
that: | ||
- test_with_decorator is succeeded | ||
# Standard methods on a boto3 wrapper | ||
- '"wait" in test_with_decorator.waiter_attributes' | ||
- '"name" in test_with_decorator.waiter_attributes' | ||
- '"config" in test_with_decorator.waiter_attributes' |
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,8 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eux | ||
|
||
ANSIBLE_ROLES_PATH="../" | ||
export ANSIBLE_ROLES_PATH | ||
|
||
ansible-playbook main.yml -i inventory "$@" |