Skip to content
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

ec2_vol: backport fix incorrectly returned changed result #486

Merged
merged 7 commits into from
Sep 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
bugfixes:
- >-
ec2_vol - Fixes ``changed`` status when ``modify_volume`` is used, but no new
disk is being attached. The module incorrectly reported that no change had
occurred even when disks had been modified (iops, throughput, type, etc.).
(https://github.com/ansible-collections/amazon.aws/issues/482).
8 changes: 5 additions & 3 deletions plugins/modules/ec2_vol.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,14 +740,16 @@ def main():
final_tags, tags_changed = ensure_tags(module, ec2_conn, volume['volume_id'], 'volume', tags, module.params.get('purge_tags'))

if detach_vol_flag:
volume, changed = detach_volume(module, ec2_conn, volume_dict=volume)
volume, attach_changed = detach_volume(module, ec2_conn, volume_dict=volume)
elif inst is not None:
volume, changed = attach_volume(module, ec2_conn, volume_dict=volume, instance_dict=inst, device_name=device_name)
volume, attach_changed = attach_volume(module, ec2_conn, volume_dict=volume, instance_dict=inst, device_name=device_name)
else:
attach_changed = False

# Add device, volume_id and volume_type parameters separately to maintain backward compatibility
volume_info = get_volume_info(volume, tags=final_tags)

if tags_changed:
if tags_changed or attach_changed:
changed = True

module.exit_json(changed=changed, volume=volume_info, device=volume_info['attachment_set']['device'],
Expand Down
48 changes: 24 additions & 24 deletions tests/integration/targets/ec2_vol/tasks/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@
assert:
that:
- "not vol_attach_result.changed"
- "vol_attach_result.volume.attachment_set.status == 'attached'"
- vol_attach_result.volume.attachment_set.status in ['attached', 'attaching']

- name: attach a new volume to an instance
ec2_vol:
Expand Down Expand Up @@ -330,29 +330,6 @@
that:
- ec2_vol_info.volumes | length == 4

- name: detach volume from the instance
ec2_vol:
id: "{{ new_vol_attach_result.volume_id }}"
instance: ""
register: new_vol_attach_result

- name: check task return attributes
assert:
that:
- new_vol_attach_result.changed
- new_vol_attach_result.volume.status == 'available'

- name: detach volume from the instance (idempotent)
ec2_vol:
id: "{{ new_vol_attach_result.volume_id }}"
instance: ""
register: new_vol_attach_result_idem

- name: check task return attributes
assert:
that:
- not new_vol_attach_result_idem.changed

- name: must not change because of missing parameter modify_volume
ec2_vol:
id: "{{ new_vol_attach_result.volume_id }}"
Expand Down Expand Up @@ -414,7 +391,30 @@
- v.type == 'gp3'
vars:
v: "{{ verify_gp3_change.volumes[0] }}"

- name: detach volume from the instance
ec2_vol:
id: "{{ new_vol_attach_result.volume_id }}"
instance: ""
register: new_vol_attach_result

- name: check task return attributes
assert:
that:
- new_vol_attach_result.changed
- new_vol_attach_result.volume.status == 'available'

- name: detach volume from the instance (idempotent)
ec2_vol:
id: "{{ new_vol_attach_result.volume_id }}"
instance: ""
register: new_vol_attach_result_idem

- name: check task return attributes
assert:
that:
- not new_vol_attach_result_idem.changed

- name: delete volume
ec2_vol:
id: "{{ volume2.volume_id }}"
Expand Down