ec2_vol: fix race conditions because we handle errors before actually deleting

Just try to delete the volume and handle the error amazon sends
reviewable/pr18780/r1
Hagai Kariti 9 years ago
parent 5983373f29
commit fb4732fad2

@ -239,15 +239,14 @@ def get_volumes(module, ec2):
return vols
def delete_volume(module, ec2):
vol = get_volume(module, ec2)
if not vol:
module.exit_json(changed=False)
else:
if vol.attachment_state() is not None:
adata = vol.attach_data
module.fail_json(msg="Volume %s is attached to an instance %s." % (vol.id, adata.instance_id))
ec2.delete_volume(vol.id)
module.exit_json(changed=True)
volume_id = module.params['id']
try:
ec2.delete_volume(volume_id)
module.exit_json(changed=True)
except boto.exception.EC2ResponseError as ec2_error:
if ec2_error.code == 'InvalidVolume.NotFound':
module.exit_json(changed=False)
module.fail_json(msg=ec2_error.message)
def boto_supports_volume_encryption():
"""

Loading…
Cancel
Save