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

[PR #1848/c510f26e backport][stable-6] Work on ec2_vpc_subnet related test flake #1870

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
4 changes: 4 additions & 0 deletions changelogs/fragments/1848-ec2_vpc_subnet-wait-creation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bugfixes:
- ec2_vpc_subnet - cleanly handle failure when subnet isn't created in time (https://github.com/ansible-collections/amazon.aws/pull/1848).
minor_changes:
- ec2_vpc_subnet - use ``wait_timeout`` to also control maximum time to wait for initial creation of subnets (https://github.com/ansible-collections/amazon.aws/pull/1848).
16 changes: 10 additions & 6 deletions plugins/modules/ec2_vpc_subnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,12 @@ def ensure_ipv6_cidr_block(conn, module, subnet, ipv6_cidr, check_mode, start_ti
return changed


def _matching_subnet_filters(vpc_id, cidr):
return ansible_dict_to_boto3_filter_list({"vpc-id": vpc_id, "cidr-block": cidr})


def get_matching_subnet(conn, module, vpc_id, cidr):
filters = ansible_dict_to_boto3_filter_list({"vpc-id": vpc_id, "cidr-block": cidr})
filters = _matching_subnet_filters(vpc_id, cidr)
try:
_subnets = conn.describe_subnets(aws_retry=True, Filters=filters)
subnets = get_subnet_info(_subnets)
Expand Down Expand Up @@ -481,11 +485,11 @@ def ensure_subnet_present(conn, module):

subnet = get_matching_subnet(conn, module, module.params["vpc_id"], module.params["cidr"])
if not module.check_mode and module.params["wait"]:
for _rewait in range(0, 5):
if subnet:
break
time.sleep(2)
subnet = get_matching_subnet(conn, module, module.params["vpc_id"], module.params["cidr"])
subnet_filter = _matching_subnet_filters(module.params["vpc_id"], module.params["cidr"])
handle_waiter(conn, module, "subnet_exists", {"Filters": subnet_filter}, start_time)
subnet = get_matching_subnet(conn, module, module.params["vpc_id"], module.params["cidr"])
if not subnet:
module.fail_json("Failed to describe newly created subnet")
# GET calls are not monotonic for map_public_ip_on_launch and assign_ipv6_address_on_creation
# so we only wait for those if necessary just before returning the subnet
subnet = ensure_final_subnet(conn, module, subnet, start_time)
Expand Down
Loading