Wait for AMI in volume_to_ami()
authorRail Aliiev <rail@mozilla.com>
Tue, 17 Jun 2014 08:04:03 -0400
changeset 447 af23152dc50d1cd381d635840d1242cabf151e4d
parent 446 c1f0610790267f019f71afa17d7ab5ca2ab10d3f
child 448 1a431afb91d7ee9e3c0a529cb21f9f65952c8a7f
push id442
push userraliiev@mozilla.com
push dateTue, 17 Jun 2014 12:04:08 +0000
Wait for AMI in volume_to_ami()
cloudtools/aws/ami.py
--- a/cloudtools/aws/ami.py
+++ b/cloudtools/aws/ami.py
@@ -65,20 +65,22 @@ def volume_to_ami(volume, ami_name, arch
         try:
             ami = volume.connection.get_image(ami_id)
             ami.add_tag('Name', ami_name)
             ami.add_tag('moz-created', int(time.mktime(time.gmtime())))
             for tag, value in tags.iteritems():
                 ami.add_tag(tag, value)
             log.info('AMI created')
             log.info('ID: {id}, name: {name}'.format(id=ami.id, name=ami.name))
-            return ami
+            break
         except:
             log.info('Wating for AMI')
             time.sleep(10)
+    wait_for_status(ami, "state", "available", "update")
+    return ami
 
 
 def copy_ami(source_ami, region_to_copy):
     log.info("Copying %s to %s", source_ami, region_to_copy)
     conn = get_aws_connection(region_to_copy)
     ami_copy = conn.copy_image(source_ami.region.name, source_ami.id,
                                source_ami.name, source_ami.description)
     while True:
@@ -89,18 +91,18 @@ def copy_ami(source_ami, region_to_copy)
             new_ami.update()
             log.info('AMI created')
             log.info('ID: {id}, name: {name}'.format(id=new_ami.id,
                                                      name=new_ami.name))
             break
         except:
             log.info('Wating for AMI')
             time.sleep(10)
-    wait_for_status(new_ami, "state", "available", "update")
-    return new_ami
+        else:
+            return new_ami
 
 
 def get_spot_amis(region, tags, name_glob="spot-*"):
     conn = get_aws_connection(region)
     filters = {}
     for tag, value in tags.iteritems():
         filters["tag:%s" % tag] = value
     # override Name tag