Split waiting for images into its own method
Nodepool got bit by incorrectly waiting for images. So let's copy the wait_for_server pattern and make a wait_for_image method that knows how to properly wait for an image to become ready. Change-Id: Icac2606ae4d51c6fde5066e767b53a6baa14dd50
This commit is contained in:
parent
d9867f4922
commit
de364270bc
@ -2064,20 +2064,30 @@ class OpenStackCloud(object):
|
|||||||
return image.id
|
return image.id
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def create_image_snapshot(self, name, server, wait=False, timeout=3600,
|
def create_image_snapshot(
|
||||||
**metadata):
|
self, name, server, wait=False, timeout=3600, **metadata):
|
||||||
image_id = str(self.manager.submitTask(_tasks.ImageSnapshotCreate(
|
image_id = str(self.manager.submitTask(_tasks.ImageSnapshotCreate(
|
||||||
image_name=name, server=server, metadata=metadata)))
|
image_name=name, server=server, metadata=metadata)))
|
||||||
self.list_images.invalidate(self)
|
self.list_images.invalidate(self)
|
||||||
|
image = self.get_image(image_id)
|
||||||
|
|
||||||
if not wait:
|
if not wait:
|
||||||
return self.get_image(image_id)
|
return image
|
||||||
for count in _utils._iterate_timeout(timeout,
|
return self.wait_for_image(image, timeout=timeout)
|
||||||
"Timeout waiting for image to "
|
|
||||||
"snapshot"):
|
def wait_for_image(self, image, timeout=3600):
|
||||||
|
image_id = image['id']
|
||||||
|
for count in _utils._iterate_timeout(
|
||||||
|
timeout, "Timeout waiting for image to snapshot"):
|
||||||
self.list_images.invalidate(self)
|
self.list_images.invalidate(self)
|
||||||
image = self.get_image(image_id)
|
image = self.get_image(image_id)
|
||||||
|
if not image:
|
||||||
|
continue
|
||||||
if image['status'] == 'active':
|
if image['status'] == 'active':
|
||||||
return image
|
return image
|
||||||
|
elif image['status'] == 'error':
|
||||||
|
raise OpenStackCloudException(
|
||||||
|
'Image {image} hit error state'.format(image=image_id))
|
||||||
|
|
||||||
def delete_image(self, name_or_id, wait=False, timeout=3600):
|
def delete_image(self, name_or_id, wait=False, timeout=3600):
|
||||||
image = self.get_image(name_or_id)
|
image = self.get_image(name_or_id)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user