From 0f9feaf51c06a4f86ab695269f9506cb86f95556 Mon Sep 17 00:00:00 2001 From: Jeremy Cline Date: Feb 03 2025 16:33:26 +0000 Subject: aws: Convert WaiterError to a Nack and bump wait times Occasionally an AWS region is slow and fails an import/copy before the timeout (30 minutes). This exception wasn't handled in the outer exception handling block which led to the fedora_messaging consumer catching and logging the error. This bumps the timeout to 1 hour and adds an except block to log and Nack a message when the timeout is hit. Fixes #36 Signed-off-by: Jeremy Cline --- diff --git a/fedora-image-uploader/fedora_image_uploader/aws.py b/fedora-image-uploader/fedora_image_uploader/aws.py index cb85247..4fd9a31 100644 --- a/fedora-image-uploader/fedora_image_uploader/aws.py +++ b/fedora-image-uploader/fedora_image_uploader/aws.py @@ -88,6 +88,10 @@ class Aws: else: raise regions_to_amis = self.aws_copy_image_to_regions(image, ffrel, image_id, ami_name) + except boto_exceptions.WaiterError as e: + # Typically this is because the region is slow; we'll retry. + _log.warning("Failed while waiting for AWS image registration: %s", str(e)) + raise fm_exceptions.Nack() except boto_exceptions.ClientError as e: _log.warning("Failed to import image: %s", str(e)) raise fm_exceptions.Nack() @@ -152,7 +156,7 @@ class Aws: snapshot_import_waiter = self.ec2_client.get_waiter("snapshot_imported") snapshot_import_waiter.wait( ImportTaskIds=[snapshot_import_task["ImportTaskId"]], - WaiterConfig={"Delay": 30, "MaxAttempts": 60}, + WaiterConfig={"Delay": 30, "MaxAttempts": 120}, ) snapshot_imports = self.ec2_client.describe_import_snapshot_tasks( ImportTaskIds=[snapshot_import_task["ImportTaskId"]], @@ -264,7 +268,10 @@ class Aws: # Wait for EC2 to mark the image as available before returning since copying # to other regions will fail if the image isn't available. waiter = self.ec2_client.get_waiter("image_available") - waiter.wait(ImageIds=[aws_image_id]) + waiter.wait( + ImageIds=[aws_image_id], + WaiterConfig={"Delay": 30, "MaxAttempts": 120}, + ) return aws_image_id def aws_copy_image_to_regions( @@ -323,7 +330,10 @@ class Aws: for region, image_id in image_ids.items(): region_client = boto3.client("ec2", region_name=region, config=self.boto_config) waiter = region_client.get_waiter("image_available") - waiter.wait(ImageIds=[image_id]) + waiter.wait( + ImageIds=[image_id], + WaiterConfig={"Delay": 30, "MaxAttempts": 120}, + ) _log.info("Image finished copying to %s as %s, marking as public", region, image_id) try: region_client.modify_image_attribute(