Merge "Implement a function to check the image status"
This commit is contained in:
@@ -183,6 +183,7 @@ class BaseImageService(object):
|
|||||||
:returns: A dict containing image metadata.
|
:returns: A dict containing image metadata.
|
||||||
|
|
||||||
:raises: ImageNotFound
|
:raises: ImageNotFound
|
||||||
|
:raises: ImageUnacceptable if the image status is not active
|
||||||
"""
|
"""
|
||||||
LOG.debug("Getting image metadata from glance. Image: %s",
|
LOG.debug("Getting image metadata from glance. Image: %s",
|
||||||
image_href)
|
image_href)
|
||||||
@@ -190,6 +191,11 @@ class BaseImageService(object):
|
|||||||
|
|
||||||
image = self.call(method, image_id)
|
image = self.call(method, image_id)
|
||||||
|
|
||||||
|
if not service_utils.is_image_active(image):
|
||||||
|
raise exception.ImageUnacceptable(
|
||||||
|
image_id=image_id,
|
||||||
|
reason=_("The image is required to be in an active state."))
|
||||||
|
|
||||||
if not service_utils.is_image_available(self.context, image):
|
if not service_utils.is_image_available(self.context, image):
|
||||||
raise exception.ImageNotFound(image_id=image_id)
|
raise exception.ImageNotFound(image_id=image_id)
|
||||||
|
|
||||||
|
|||||||
@@ -171,6 +171,15 @@ def is_image_available(context, image):
|
|||||||
return str(user_id) == str(context.user_id)
|
return str(user_id) == str(context.user_id)
|
||||||
|
|
||||||
|
|
||||||
|
def is_image_active(image):
|
||||||
|
"""Check the image status.
|
||||||
|
|
||||||
|
This check is needed in case the Glance image is stuck in queued status
|
||||||
|
or pending_delete.
|
||||||
|
"""
|
||||||
|
return str(getattr(image, 'status', None)) == "active"
|
||||||
|
|
||||||
|
|
||||||
def is_glance_image(image_href):
|
def is_glance_image(image_href):
|
||||||
if not isinstance(image_href, six.string_types):
|
if not isinstance(image_href, six.string_types):
|
||||||
return False
|
return False
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ class TestGlanceImageService(base.TestCase):
|
|||||||
def _make_fixture(**kwargs):
|
def _make_fixture(**kwargs):
|
||||||
fixture = {'name': None,
|
fixture = {'name': None,
|
||||||
'properties': {},
|
'properties': {},
|
||||||
'status': None,
|
'status': "active",
|
||||||
'is_public': None}
|
'is_public': None}
|
||||||
fixture.update(kwargs)
|
fixture.update(kwargs)
|
||||||
return stubs.FakeImage(fixture)
|
return stubs.FakeImage(fixture)
|
||||||
@@ -145,7 +145,7 @@ class TestGlanceImageService(base.TestCase):
|
|||||||
'updated_at': None,
|
'updated_at': None,
|
||||||
'deleted_at': None,
|
'deleted_at': None,
|
||||||
'deleted': None,
|
'deleted': None,
|
||||||
'status': None,
|
'status': "active",
|
||||||
'properties': {},
|
'properties': {},
|
||||||
'owner': None,
|
'owner': None,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user