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

Just try to delete the volume and handle the error amazon sends
This commit is contained in:
Hagai Kariti 2015-06-04 11:41:02 +03:00 committed by Matt Clay
parent 9babe9b07d
commit b154ad4cbb

View file

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