Route custom waiter (#36922)

This creates a way for us to use boto3's data-driven waiter support to use custom waiters where Boto3 hasn't implemented them yet.

The only waiter implemented so far is for VPC Route Tables to check that they exist, and this replaces some custom retry code.
This commit is contained in:
Ryan Brown 2018-03-05 17:22:16 -05:00 committed by Will Thames
parent 51558f12f4
commit c8ef07e015
2 changed files with 58 additions and 5 deletions

View file

@ -226,6 +226,7 @@ route_table:
import re
from time import sleep
from ansible.module_utils.aws.core import AnsibleAWSModule
from ansible.module_utils.aws.waiters import get_waiter
from ansible.module_utils.ec2 import ec2_argument_spec, boto3_conn, get_aws_connection_info
from ansible.module_utils.ec2 import ansible_dict_to_boto3_filter_list
from ansible.module_utils.ec2 import camel_dict_to_snake_dict, snake_dict_to_camel_dict
@ -649,11 +650,11 @@ def ensure_route_table_present(connection, module):
try:
route_table = connection.create_route_table(VpcId=vpc_id)['RouteTable']
# try to wait for route table to be present before moving on
for attempt in range(5):
if not get_route_table_by_id(connection, module, route_table['RouteTableId']):
sleep(2)
else:
break
get_waiter(
connection, 'route_table_exists'
).wait(
RouteTableIds=[route_table['RouteTableId']],
)
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
module.fail_json_aws(e, msg="Error creating route table")
else: