From 950d76af0b73aff58ab0b9042ee8789b0d1f7dfb Mon Sep 17 00:00:00 2001 From: Allen Sanabria Date: Thu, 4 Aug 2016 18:14:36 -0700 Subject: fixed error message for releasing an ip when not waiting for the nat gateway to delete successfully 1st --- cloud/amazon/ec2_vpc_nat_gateway.py | 25 ++++++++++++++-------- test/unit/cloud/amazon/test_ec2_vpc_nat_gateway.py | 2 +- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/cloud/amazon/ec2_vpc_nat_gateway.py b/cloud/amazon/ec2_vpc_nat_gateway.py index b5874128..ee53d7bb 100644 --- a/cloud/amazon/ec2_vpc_nat_gateway.py +++ b/cloud/amazon/ec2_vpc_nat_gateway.py @@ -62,6 +62,7 @@ options: description: - Deallocate the EIP from the VPC. - Option is only valid with the absent state. + - You should use this with the wait option. Since you can not release an address while a delete operation is happening. required: false default: true wait: @@ -159,6 +160,8 @@ EXAMPLES = ''' state: absent nat_gateway_id: nat-12345678 release_eip: yes + wait: yes + wait_timeout: 300 region: ap-southeast-2 ''' @@ -648,10 +651,11 @@ def release_address(client, allocation_id, check_mode=False): True Returns: - Boolean + Boolean, string """ + err_msg = '' if check_mode: - return True + return True, '' ip_released = False params = { @@ -660,10 +664,10 @@ def release_address(client, allocation_id, check_mode=False): try: client.release_address(**params) ip_released = True - except botocore.exceptions.ClientError: - pass + except botocore.exceptions.ClientError as e: + err_msg = str(e) - return ip_released + return ip_released, err_msg def create(client, subnet_id, allocation_id, client_token=None, @@ -973,11 +977,15 @@ def remove(client, nat_gateway_id, wait=False, wait_timeout=0, err_msg = str(e) if release_eip: - eip_released = ( - release_address(client, allocation_id, check_mode=check_mode) + eip_released, eip_err = ( + release_address(client, allocation_id, check_mode) ) if not eip_released: - err_msg = "Failed to release EIP %s".format(allocation_id) + err_msg = ( + "{0}: Failed to release EIP {1}: {2}" + .format(err_msg, allocation_id, eip_err) + ) + success = False return success, changed, err_msg, results @@ -1037,7 +1045,6 @@ def main(): changed = False err_msg = '' - #Ensure resource is present if state == 'present': if not subnet_id: module.fail_json(msg='subnet_id is required for creation') diff --git a/test/unit/cloud/amazon/test_ec2_vpc_nat_gateway.py b/test/unit/cloud/amazon/test_ec2_vpc_nat_gateway.py index 7c4f163a..1b75c88a 100644 --- a/test/unit/cloud/amazon/test_ec2_vpc_nat_gateway.py +++ b/test/unit/cloud/amazon/test_ec2_vpc_nat_gateway.py @@ -392,7 +392,7 @@ class AnsibleEc2VpcNatGatewayFunctions(unittest.TestCase): def test_release_address(self): client = boto3.client('ec2', region_name=aws_region) - success = ( + success, _ = ( ng.release_address( client, 'eipalloc-1234567', check_mode=True ) -- cgit v1.2.1