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.
ec2_eni: change data type of
device_index
to str when passing it to…
… api as expected by api call (ansible-collections#877) ec2_eni: change data type of `device_index` to str when passing it to api as expected by api call SUMMARY Currently the data type for parameter device_index here while being passed to api call is integer but one of the API calls later used here in the module (describe_network_interfaces) expects it to be string as per boto3 api documentation. Fixes ansible-collections#870 ISSUE TYPE Bugfix Pull Request COMPONENT NAME ec2_eni Reviewed-by: Mark Chappell <None> Reviewed-by: Jill R <None> Reviewed-by: Alina Buzachis <None>
- Loading branch information
Showing
4 changed files
with
127 additions
and
1 deletion.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
changelogs/fragments/877-ec2_eni-device_index-data-change-type-to-str.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,2 @@ | ||
minor_changes: | ||
- ec2_eni - Change parameter ``device_index`` data type to string when passing to `describe_network_inter` api call (https://github.com/ansible-collections/amazon.aws/pull/877). |
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
121 changes: 121 additions & 0 deletions
121
tests/integration/targets/ec2_eni/tasks/test_create_attached_multiple.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,121 @@ | ||
--- | ||
- name: Create instance to test attaching and detaching network interfaces for this test | ||
ec2_instance: | ||
name: "{{ resource_prefix }}-instance" | ||
image_id: "{{ ec2_ami_id }}" | ||
vpc_subnet_id: "{{ vpc_subnet_id }}" | ||
instance_type: t2.micro | ||
register: ec2_instances | ||
|
||
- name: set variable for the instance ID | ||
set_fact: | ||
instance_id_3: "{{ ec2_instances.instances[0].instance_id }}" | ||
|
||
#================================================================= | ||
|
||
- name: Create and attach another interface to above instance - check_mode | ||
amazon.aws.ec2_eni: | ||
name: "{{ resource_prefix }}-eni" | ||
instance_id: "{{ instance_id_3 }}" | ||
device_index: 1 | ||
subnet_id: "{{ vpc_subnet_id }}" | ||
state: present | ||
attached: true | ||
delete_on_termination: true | ||
check_mode: true | ||
register: result | ||
|
||
# Get the instance info and ENI info to verify attachment of second eni | ||
- ec2_instance_info: | ||
instance_ids: | ||
- "{{ instance_id_3 }}" | ||
register: instance_info_result | ||
|
||
- assert: | ||
that: | ||
- result is changed | ||
- result is not failed | ||
- instance_info_result.instances[0].network_interfaces | length == 1 | ||
- '"Would have created ENI if not in check mode." in result.msg' | ||
- "'ec2:CreateNetworkInterface' not in {{ result.resource_actions }}" | ||
|
||
- name: Create and attach another interface to above instance | ||
amazon.aws.ec2_eni: | ||
name: "{{ resource_prefix }}-eni" | ||
instance_id: "{{ instance_id_3 }}" | ||
device_index: 1 | ||
subnet_id: "{{ vpc_subnet_id }}" | ||
state: present | ||
attached: true | ||
delete_on_termination: true | ||
register: result | ||
|
||
- name: Set variable for the ENI ID | ||
set_fact: | ||
eni_id_attached_multiple: "{{ result.interface.id }}" | ||
|
||
# Get the instance info and ENI info to verify attachment of second eni | ||
- ec2_instance_info: | ||
instance_ids: | ||
- "{{ instance_id_3 }}" | ||
register: instance_info_result | ||
- ec2_eni_info: | ||
eni_id: "{{ eni_id_attached_multiple }}" | ||
register: eni_info | ||
|
||
- name: Assert that the interface attachment was successful | ||
assert: | ||
that: | ||
- result is changed | ||
- result is not failed | ||
- instance_info_result.instances[0].network_interfaces | length == 2 | ||
- eni_info.network_interfaces[0].attachment.instance_id == instance_id_3 | ||
- eni_info.network_interfaces[0].attachment.device_index == 1 | ||
|
||
- name: Create and attach another interface to above instance - check_mode - idempotent | ||
amazon.aws.ec2_eni: | ||
name: "{{ resource_prefix }}-eni" | ||
instance_id: "{{ instance_id_3 }}" | ||
device_index: 1 | ||
subnet_id: "{{ vpc_subnet_id }}" | ||
state: present | ||
attached: true | ||
delete_on_termination: true | ||
check_mode: true | ||
register: result | ||
|
||
# Get the instance info and ENI info to verify attachment of second eni | ||
- ec2_instance_info: | ||
instance_ids: | ||
- "{{ instance_id_3 }}" | ||
register: instance_info_result | ||
|
||
- name: Assert that the interface would have been modified if not in check_mode | ||
assert: | ||
that: | ||
- result is changed | ||
- result is not failed | ||
- instance_info_result.instances[0].network_interfaces | length == 2 | ||
- '"Would have modified ENI: {{ eni_id_attached_multiple }} if not in check mode" in result.msg' | ||
- "'ec2:CreateNetworkInterface' not in {{ result.resource_actions }}" | ||
- "'ec2:ModifyNetworkInterfaceAttribute' not in {{ result.resource_actions }}" | ||
|
||
#================================================================= | ||
|
||
- name: remove the network interface created in this test | ||
ec2_eni: | ||
eni_id: "{{ eni_id_attached_multiple }}" | ||
force_detach: True | ||
state: absent | ||
ignore_errors: true | ||
retries: 5 | ||
|
||
- name: terminate the instance created in this test | ||
ec2_instance: | ||
state: absent | ||
instance_ids: | ||
- "{{ instance_id_3 }}" | ||
wait: True | ||
ignore_errors: true | ||
retries: 5 | ||
when: instance_id_3 is defined |