Skip to content

Commit

Permalink
Use name filter in GlanceImageService show_by_name
Browse files Browse the repository at this point in the history
Fixes bug 883289

Change-Id: Ie2e62aea55e6541dc4ad1a725130fbf0259362fb
  • Loading branch information
bcwaldon committed Jan 29, 2012
1 parent 6a239cb commit 755f660
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
12 changes: 5 additions & 7 deletions nova/image/glance.py
Expand Up @@ -227,13 +227,11 @@ def show(self, context, image_id):

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."""
Expand Down
4 changes: 0 additions & 4 deletions nova/tests/image/test_glance.py
Expand Up @@ -193,10 +193,6 @@ def test_create_and_show_non_existing_image(self):
'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,
Expand Down

0 comments on commit 755f660

Please sign in to comment.