summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-02-01 21:12:40 +0000
committerGerrit Code Review <review@openstack.org>2012-02-01 21:12:40 +0000
commiteed008ea770adb952a1ec0b6af7f2afb177285ca (patch)
tree8725d1fe0938d6f30e5344df22f4b333bdbe83d3
parenta5e8f131c0b6b0e9d13d45503f6897cdf9dddae5 (diff)
parent755f660b7ca129f869da07db0cc4433106f47ff9 (diff)
downloadnova-eed008ea770adb952a1ec0b6af7f2afb177285ca.tar.gz
nova-eed008ea770adb952a1ec0b6af7f2afb177285ca.tar.xz
nova-eed008ea770adb952a1ec0b6af7f2afb177285ca.zip
Merge "Use name filter in GlanceImageService show_by_name"
-rw-r--r--nova/image/glance.py12
-rw-r--r--nova/tests/image/test_glance.py4
2 files changed, 5 insertions, 11 deletions
diff --git a/nova/image/glance.py b/nova/image/glance.py
index 2a24d534e..092dd832a 100644
--- a/nova/image/glance.py
+++ b/nova/image/glance.py
@@ -227,13 +227,11 @@ class GlanceImageService(object):
def show_by_name(self, context, name):
"""Returns a dict containing image data for the given name."""
- # TODO(vish): replace this with more efficient call when glance
- # supports it.
- image_metas = self.detail(context)
- for image_meta in image_metas:
- if name == image_meta.get('name'):
- return image_meta
- raise exception.ImageNotFound(image_id=name)
+ image_metas = self.detail(context, filters={'name': name})
+ try:
+ return image_metas[0]
+ except (IndexError, TypeError):
+ raise exception.ImageNotFound(image_id=name)
def get(self, context, image_id, data):
"""Calls out to Glance for metadata and data and writes data."""
diff --git a/nova/tests/image/test_glance.py b/nova/tests/image/test_glance.py
index 5e9f9d79b..7fac3982d 100644
--- a/nova/tests/image/test_glance.py
+++ b/nova/tests/image/test_glance.py
@@ -193,10 +193,6 @@ class TestGlanceImageService(test.TestCase):
'bad image id')
def test_create_and_show_non_existing_image_by_name(self):
- fixture = self._make_fixture(name='test image')
- image_id = self.service.create(self.context, fixture)['id']
-
- self.assertNotEquals(None, image_id)
self.assertRaises(exception.ImageNotFound,
self.service.show_by_name,
self.context,