summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Waldon <bcwaldon@gmail.com>2012-01-28 21:47:06 -0800
committerBrian Waldon <bcwaldon@gmail.com>2012-01-28 22:19:21 -0800
commit755f660b7ca129f869da07db0cc4433106f47ff9 (patch)
tree93dd09af3ac71ceb3005c4e1e9659d51939781ce
parent6a239cb7a2ea05a9382ed71469ca770afbb12212 (diff)
downloadnova-755f660b7ca129f869da07db0cc4433106f47ff9.tar.gz
nova-755f660b7ca129f869da07db0cc4433106f47ff9.tar.xz
nova-755f660b7ca129f869da07db0cc4433106f47ff9.zip
Use name filter in GlanceImageService show_by_name
Fixes bug 883289 Change-Id: Ie2e62aea55e6541dc4ad1a725130fbf0259362fb
-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,