From ad950dbcc3222f3dffb8f6536ce1b32a496ad876 Mon Sep 17 00:00:00 2001 From: Sayan Chowdhury Date: Wed, 18 Apr 2018 23:57:46 +0530 Subject: [PATCH] fedimg: Checkin the patch for PR#100. Check if the AMI is complete before proceeding Signed-off-by: Sayan Chowdhury --- files/hotfix/fedimg/ec2imgpublisher.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/files/hotfix/fedimg/ec2imgpublisher.py b/files/hotfix/fedimg/ec2imgpublisher.py index 6e62e045ee..b1eab4858d 100644 --- a/files/hotfix/fedimg/ec2imgpublisher.py +++ b/files/hotfix/fedimg/ec2imgpublisher.py @@ -90,6 +90,22 @@ class EC2ImagePublisher(EC2Base): return is_snapshot_public + def _retry_till_image_is_available(self, image_id): + driver = self._connect() + + while True: + try: + image = driver.get_image(image_id) + image_name = image.name + if image_name is None: + continue + return image + except Exception as e: + if 'InvalidAMIID.Unavailable' in str(e): + # The copy isn't completed yet, so wait for 20 seconds + # more. + sleep(20) + continue def _retry_till_snapshot_is_available(self, image): @@ -255,6 +271,8 @@ class EC2ImagePublisher(EC2Base): name=self.image_name, description=self.image_description) + copied_image = self._retry_till_image_is_available(copied_image.id) + virt_type = image.extra['virtualization_type'] volume_type = image.extra['block_device_mapping'][0]['ebs']['volume_type']