-
Notifications
You must be signed in to change notification settings - Fork 342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
aws_collection_constants #1344
Merged
softwarefactory-project-zuul
merged 1 commit into
ansible-collections:main
from
tremble:constants
Jan 24, 2023
Merged
aws_collection_constants #1344
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,2 @@ | ||
trivial: | ||
- Update integration tests to use lookup plugin when pulling the default AWS SDK versions |
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,81 @@ | ||
# (c) 2023 Ansible Project | ||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) | ||
|
||
DOCUMENTATION = ''' | ||
name: aws_collection_constants | ||
author: | ||
- Mark Chappell (@tremble) | ||
short_description: expose various collection related constants | ||
version_added: 6.0.0 | ||
description: | ||
- Exposes various collection related constants for use in integration tests. | ||
options: | ||
_terms: | ||
description: Name of the constant. | ||
choices: | ||
- MINIMUM_BOTOCORE_VERSION | ||
- MINIMUM_BOTO3_VERSION | ||
- HAS_BOTO3 | ||
- AMAZON_AWS_COLLECTION_VERSION | ||
- AMAZON_AWS_COLLECTION_NAME | ||
- COMMUNITY_AWS_COLLECTION_VERSION | ||
- COMMUNITY_AWS_COLLECTION_NAME | ||
required: True | ||
''' | ||
|
||
EXAMPLES = """ | ||
""" | ||
|
||
RETURN = """ | ||
_raw: | ||
description: value | ||
type: str | ||
""" | ||
|
||
from ansible.errors import AnsibleLookupError | ||
from ansible.plugins.lookup import LookupBase | ||
|
||
import ansible_collections.amazon.aws.plugins.module_utils.botocore as botocore_utils | ||
import ansible_collections.amazon.aws.plugins.module_utils.common as common_utils | ||
|
||
try: | ||
import ansible_collections.community.aws.plugins.module_utils.common as community_utils | ||
HAS_COMMUNITY = True | ||
except ImportError: | ||
HAS_COMMUNITY = False | ||
|
||
|
||
class LookupModule(LookupBase): | ||
def lookup_constant(self, name): | ||
if name == 'MINIMUM_BOTOCORE_VERSION': | ||
return botocore_utils.MINIMUM_BOTOCORE_VERSION | ||
if name == 'MINIMUM_BOTO3_VERSION': | ||
return botocore_utils.MINIMUM_BOTO3_VERSION | ||
if name == 'HAS_BOTO3': | ||
return botocore_utils.HAS_BOTO3 | ||
|
||
if name == 'AMAZON_AWS_COLLECTION_VERSION': | ||
return common_utils.AMAZON_AWS_COLLECTION_VERSION | ||
if name == 'AMAZON_AWS_COLLECTION_NAME': | ||
return common_utils.AMAZON_AWS_COLLECTION_NAME | ||
|
||
if name == 'COMMUNITY_AWS_COLLECTION_VERSION': | ||
if not HAS_COMMUNITY: | ||
raise AnsibleLookupError( | ||
'Unable to load ansible_collections.community.aws.plugins.module_utils.common') | ||
return community_utils.COMMUNITY_AWS_COLLECTION_VERSION | ||
if name == 'COMMUNITY_AWS_COLLECTION_NAME': | ||
if not HAS_COMMUNITY: | ||
raise AnsibleLookupError( | ||
'Unable to load ansible_collections.community.aws.plugins.module_utils.common') | ||
return community_utils.COMMUNITY_AWS_COLLECTION_NAME | ||
|
||
def run(self, terms, variables, **kwargs): | ||
self.set_options(var_options=variables, direct=kwargs) | ||
if not terms: | ||
raise AnsibleLookupError("Constant name not provided") | ||
if len(terms) > 1: | ||
raise AnsibleLookupError("Multiple constant names provided") | ||
name = terms[0].upper() | ||
|
||
return [self.lookup_constant(name)] |
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/lookup_aws_collection_constants/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 @@ | ||
cloud/aws |
1 change: 1 addition & 0 deletions
1
tests/integration/targets/lookup_aws_collection_constants/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 @@ | ||
dependencies: [] |
47 changes: 47 additions & 0 deletions
47
tests/integration/targets/lookup_aws_collection_constants/tasks/main.yaml
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,47 @@ | ||
- name: 'MINIMUM_BOTOCORE_VERSION' | ||
set_fact: | ||
MINIMUM_BOTOCORE_VERSION: "{{ lookup('amazon.aws.aws_collection_constants', 'MINIMUM_BOTOCORE_VERSION') }}" | ||
|
||
- assert: | ||
that: | ||
- MINIMUM_BOTOCORE_VERSION.startswith("1.") | ||
|
||
- name: 'MINIMUM_BOTO3_VERSION' | ||
set_fact: | ||
MINIMUM_BOTO3_VERSION: "{{ lookup('amazon.aws.aws_collection_constants', 'MINIMUM_BOTO3_VERSION') }}" | ||
|
||
- assert: | ||
that: | ||
- MINIMUM_BOTO3_VERSION.startswith("1.") | ||
|
||
- name: 'HAS_BOTO3' | ||
set_fact: | ||
HAS_BOTO3: "{{ lookup('amazon.aws.aws_collection_constants', 'HAS_BOTO3') }}" | ||
|
||
- assert: | ||
that: | ||
- HAS_BOTO3 | bool | ||
|
||
- name: 'AMAZON_AWS_COLLECTION_VERSION' | ||
set_fact: | ||
AMAZON_AWS_COLLECTION_VERSION: "{{ lookup('amazon.aws.aws_collection_constants', 'AMAZON_AWS_COLLECTION_VERSION') }}" | ||
|
||
- name: 'AMAZON_AWS_COLLECTION_NAME' | ||
set_fact: | ||
AMAZON_AWS_COLLECTION_NAME: "{{ lookup('amazon.aws.aws_collection_constants', 'AMAZON_AWS_COLLECTION_NAME') }}" | ||
|
||
- assert: | ||
that: | ||
- AMAZON_AWS_COLLECTION_NAME == "amazon.aws" | ||
|
||
- name: 'COMMUNITY_AWS_COLLECTION_VERSION' | ||
set_fact: | ||
COMMUNITY_AWS_COLLECTION_VERSION: "{{ lookup('amazon.aws.aws_collection_constants', 'COMMUNITY_AWS_COLLECTION_VERSION') }}" | ||
|
||
- name: 'COMMUNITY_AWS_COLLECTION_NAME' | ||
set_fact: | ||
COMMUNITY_AWS_COLLECTION_NAME: "{{ lookup('amazon.aws.aws_collection_constants', 'COMMUNITY_AWS_COLLECTION_NAME') }}" | ||
|
||
- assert: | ||
that: | ||
- COMMUNITY_AWS_COLLECTION_NAME == "community.aws" |
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 |
---|---|---|
@@ -1,2 +1 @@ | ||
dependencies: | ||
- role: setup_botocore_pip | ||
dependencies: [] |
4 changes: 2 additions & 2 deletions
4
tests/integration/targets/setup_botocore_pip/defaults/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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
default_botocore_version: '1.21.0' | ||
default_boto3_version: '1.18.0' | ||
default_botocore_version: "{{ lookup('amazon.aws.aws_collection_constants', 'MINIMUM_BOTOCORE_VERSION') }}" | ||
default_boto3_version: "{{ lookup('amazon.aws.aws_collection_constants', 'MINIMUM_BOTO3_VERSION') }}" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of raising an error, why not return all constant values?
this needs to change the return format as dictionnary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't think of a use case where we'd want to dump out all of them, so was trying to follow the KISS Principle