Check if image_identifier is UUID
Check if image_identifier can be image UUID before calling glance-api. This could save some time if image name is supplied. Change-Id: Ied531f35d723a818ab3387582a53a2a96dfb7668
This commit is contained in:
parent
0a802728ed
commit
2a6dc1a3d0
|
@ -11,6 +11,8 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
from glanceclient import client as gc
|
||||
from glanceclient import exc
|
||||
|
||||
|
@ -91,10 +93,12 @@ class GlanceClientPlugin(client_plugin.ClientPlugin):
|
|||
:param image_identifier: image name
|
||||
:returns: an image object with name/id :image_identifier:
|
||||
"""
|
||||
try:
|
||||
return self.client().images.get(image_identifier)
|
||||
except exc.HTTPNotFound:
|
||||
return self._find_with_attr('images', name=image_identifier)
|
||||
if uuidutils.is_uuid_like(image_identifier):
|
||||
try:
|
||||
return self.client().images.get(image_identifier)
|
||||
except exc.HTTPNotFound:
|
||||
pass
|
||||
return self._find_with_attr('images', name=image_identifier)
|
||||
|
||||
|
||||
class ImageConstraint(constraints.BaseCustomConstraint):
|
||||
|
|
|
@ -1425,8 +1425,6 @@ class ValidateTest(common.HeatTestCase):
|
|||
t = template_format.parse(test_template_glance_client_exception)
|
||||
template = tmpl.Template(t)
|
||||
stack = parser.Stack(self.ctx, 'test_stack', template)
|
||||
self.m.StubOutWithMock(self.gc.images, 'get')
|
||||
self.gc.images.get('image_name').AndRaise(glance.exc.HTTPNotFound())
|
||||
self.m.StubOutWithMock(glance.GlanceClientPlugin, 'client')
|
||||
glance.GlanceClientPlugin.client().AndReturn(self.gc)
|
||||
self.stub_FlavorConstraint_validate()
|
||||
|
|
Loading…
Reference in New Issue