-
Notifications
You must be signed in to change notification settings - Fork 342
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor aws_az_region_info* modules (#2163)
SUMMARY Refactor aws_az_info,aws_region_info modules ISSUE TYPE Feature Pull Request COMPONENT NAME aws_az_info aws_region_info Reviewed-by: Alina Buzachis
- Loading branch information
Showing
7 changed files
with
124 additions
and
37 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
changelogs/fragments/20240107-refactor_aws_az_region_info-modules.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,3 @@ | ||
--- | ||
minor_changes: | ||
- aws_az_info - refactored code to use ``AnsibleEC2Error`` as well as moving shared code into module_utils.ec2 (https://github.com/ansible-collections/amazon.aws/pull/2163). - aws_region_info - refactored code to use ``AnsibleEC2Error`` as well as moving shared code into module_utils.ec2 (https://github.com/ansible-collections/amazon.aws/pull/2163). |
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
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
23 changes: 23 additions & 0 deletions
23
tests/integration/targets/ec2_instance_placement_options/tasks/select_availability_zone.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,23 @@ | ||
# aws regions supporting 't3.micro' instance type | ||
- ansible.builtin.set_fact: | ||
av_zones: | ||
- us-east-1a | ||
- us-east-1b | ||
- us-east-1c | ||
- us-east-1d | ||
- us-east-1f | ||
|
||
- name: List t3.micro instances | ||
amazon.aws.ec2_instance_info: | ||
filters: | ||
instance-type: t3.micro | ||
instance-state-name: | ||
- pending | ||
- running | ||
register: _instances | ||
|
||
- ansible.builtin.set_fact: | ||
instances_zones: "{{ _instances.instances | map(attribute='placement.availability_zone') | list | ansible.builtin.unique }}" | ||
|
||
- ansible.builtin.set_fact: | ||
ec2_availability_zone: "{{ av_zones | ansible.builtin.difference(instances_zones) | list | ansible.builtin.random }}" |
36 changes: 36 additions & 0 deletions
36
tests/unit/module_utils/transformation/test_sanitize_filters_to_boto3_filter_list.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,36 @@ | ||
# | ||
# (c) 2024 Red Hat Inc. | ||
# | ||
# This file is part of Ansible | ||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) | ||
|
||
from unittest.mock import patch | ||
|
||
from ansible_collections.amazon.aws.plugins.module_utils import transformation | ||
|
||
filters = { | ||
"tag:Test_Name": "ansible-test-units", | ||
"ansible_test_version": "milestone", | ||
} | ||
|
||
expected_no_ignore_keys = { | ||
"tag:Test-Name": "ansible-test-units", | ||
"ansible-test-version": "milestone", | ||
} | ||
|
||
expected_ignore_keys = { | ||
"tag:Test_Name": "ansible-test-units", | ||
"ansible-test-version": "milestone", | ||
} | ||
|
||
|
||
@patch("ansible_collections.amazon.aws.plugins.module_utils.transformation.ansible_dict_to_boto3_filter_list") | ||
def test_sanitize_filters_to_boto3_filter_list_no_ignore_keys(m_ansible_dict_to_boto3_filter_list): | ||
m_ansible_dict_to_boto3_filter_list.side_effect = lambda x: x | ||
assert expected_no_ignore_keys == transformation.sanitize_filters_to_boto3_filter_list(filters) | ||
|
||
|
||
@patch("ansible_collections.amazon.aws.plugins.module_utils.transformation.ansible_dict_to_boto3_filter_list") | ||
def test_sanitize_filters_to_boto3_filter_list_ignore_keys(m_ansible_dict_to_boto3_filter_list): | ||
m_ansible_dict_to_boto3_filter_list.side_effect = lambda x: x | ||
assert expected_ignore_keys == transformation.sanitize_filters_to_boto3_filter_list(filters, ignore_keys=["tag:"]) |