From 0ca1c1943e6a07e7a107f38f56227768022de3dc Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Wed, 27 Jun 2012 08:29:40 -0700 Subject: Remove image service show_by_name method This method isn't worth keeping around. It's used in one place and consists of a try/except block. We also shouldn't encourage clients of GlanceImageService to depend on finding a single unique image by a non-unique attribute. Change-Id: I02347adef7bc7ac70407226ea150000e55a798bc --- nova/tests/api/ec2/test_cloud.py | 34 +++++++++++++++++++++++++++------ nova/tests/api/ec2/test_ec2_validate.py | 7 ++++++- nova/tests/image/fake.py | 8 -------- nova/tests/image/test_fake.py | 6 ------ nova/tests/image/test_glance.py | 6 ------ 5 files changed, 34 insertions(+), 27 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/api/ec2/test_cloud.py b/nova/tests/api/ec2/test_cloud.py index 180faeeaa..90724977a 100644 --- a/nova/tests/api/ec2/test_cloud.py +++ b/nova/tests/api/ec2/test_cloud.py @@ -103,8 +103,13 @@ class CloudTestCase(test.TestCase): 'type': 'machine', 'image_state': 'available'}} + def fake_detail(_self, context, **kwargs): + image = fake_show(None, context, None) + image['name'] = kwargs.get('filters', {}).get('name') + return [image] + self.stubs.Set(fake._FakeImageService, 'show', fake_show) - self.stubs.Set(fake._FakeImageService, 'show_by_name', fake_show) + self.stubs.Set(fake._FakeImageService, 'detail', fake_detail) fake.stub_out_image_service(self.stubs) def dumb(*args, **kwargs): @@ -1128,6 +1133,9 @@ class CloudTestCase(test.TestCase): def fake_show_none(meh, context, id): raise exception.ImageNotFound(image_id='bad_image_id') + def fake_detail_none(self, context, **kwargs): + return [] + self.stubs.Set(fake._FakeImageService, 'detail', fake_detail) # list all result1 = describe_images(self.context) @@ -1143,7 +1151,7 @@ class CloudTestCase(test.TestCase): # provide a non-existing image_id self.stubs.UnsetAll() self.stubs.Set(fake._FakeImageService, 'show', fake_show_none) - self.stubs.Set(fake._FakeImageService, 'show_by_name', fake_show_none) + self.stubs.Set(fake._FakeImageService, 'detail', fake_detail_none) self.assertRaises(exception.ImageNotFound, describe_images, self.context, ['ami-fake']) @@ -1211,7 +1219,7 @@ class CloudTestCase(test.TestCase): return i raise exception.ImageNotFound(image_id=image_id) - def fake_detail(meh, context): + def fake_detail(meh, context, **kwargs): return [copy.deepcopy(image1), copy.deepcopy(image2)] self.stubs.Set(fake._FakeImageService, 'show', fake_show) @@ -1313,8 +1321,13 @@ class CloudTestCase(test.TestCase): 'container_format': 'ami', 'is_public': True} + def fake_detail(self, context, **kwargs): + image = fake_show(None, context, None) + image['name'] = kwargs.get('filters', {}).get('name') + return [image] + self.stubs.Set(fake._FakeImageService, 'show', fake_show) - self.stubs.Set(fake._FakeImageService, 'show_by_name', fake_show) + self.stubs.Set(fake._FakeImageService, 'detail', fake_detail) result = describe_image_attribute(self.context, 'ami-00000001', 'launchPermission') self.assertEqual([{'group': 'all'}], result['launchPermission']) @@ -1360,6 +1373,11 @@ class CloudTestCase(test.TestCase): def fake_show(meh, context, id): return copy.deepcopy(fake_metadata) + def fake_detail(self, context, **kwargs): + image = fake_show(None, context, None) + image['name'] = kwargs.get('filters', {}).get('name') + return [image] + def fake_update(meh, context, image_id, metadata, data=None): self.assertEqual(metadata['properties']['kernel_id'], fake_metadata['properties']['kernel_id']) @@ -1371,7 +1389,7 @@ class CloudTestCase(test.TestCase): return image self.stubs.Set(fake._FakeImageService, 'show', fake_show) - self.stubs.Set(fake._FakeImageService, 'show_by_name', fake_show) + self.stubs.Set(fake._FakeImageService, 'detail', fake_detail) self.stubs.Set(fake._FakeImageService, 'update', fake_update) result = modify_image_attribute(self.context, 'ami-00000001', 'launchPermission', 'add', @@ -1473,7 +1491,7 @@ class CloudTestCase(test.TestCase): # invalid image self.stubs.UnsetAll() - def fake_detail_empty(self, context): + def fake_detail_empty(self, context, **kwargs): return [] self.stubs.Set(fake._FakeImageService, 'detail', fake_detail_empty) @@ -1727,7 +1745,11 @@ class CloudTestCase(test.TestCase): 'type': 'machine'}, 'status': 'active'} + def fake_id_to_glance_id(context, id): + return 'cedef40a-ed67-4d10-800e-17455edce175' + self.stubs.Set(fake._FakeImageService, 'show', fake_show_stat_active) + self.stubs.Set(ec2utils, 'id_to_glance_id', fake_id_to_glance_id) result = run_instances(self.context, **kwargs) self.assertEqual(len(result['instancesSet']), 1) diff --git a/nova/tests/api/ec2/test_ec2_validate.py b/nova/tests/api/ec2/test_ec2_validate.py index ad0de2ca0..cd213dd09 100644 --- a/nova/tests/api/ec2/test_ec2_validate.py +++ b/nova/tests/api/ec2/test_ec2_validate.py @@ -80,9 +80,14 @@ class EC2ValidateTestCase(test.TestCase): 'type': 'machine', 'image_state': 'available'}} + def fake_detail(self, context, **kwargs): + image = fake_show(self, context, None) + image['name'] = kwargs.get('name') + return [image] + fake.stub_out_image_service(self.stubs) self.stubs.Set(fake._FakeImageService, 'show', fake_show) - self.stubs.Set(fake._FakeImageService, 'show_by_name', fake_show) + self.stubs.Set(fake._FakeImageService, 'detail', fake_detail) # NOTE(comstud): Make 'cast' behave like a 'call' which will # ensure that operations complete diff --git a/nova/tests/image/fake.py b/nova/tests/image/fake.py index 017611aa9..4a3e0b931 100644 --- a/nova/tests/image/fake.py +++ b/nova/tests/image/fake.py @@ -182,14 +182,6 @@ class _FakeImageService(object): image_id, self.images) raise exception.ImageNotFound(image_id=image_id) - def show_by_name(self, context, name): - """Returns a dict containing image data for the given name.""" - images = copy.deepcopy(self.images.values()) - for image in images: - if name == image.get('name'): - return image - raise exception.ImageNotFound(image_id=name) - def create(self, context, metadata, data=None): """Store the image data and return the new image id. diff --git a/nova/tests/image/test_fake.py b/nova/tests/image/test_fake.py index eb1136894..e1925557e 100644 --- a/nova/tests/image/test_fake.py +++ b/nova/tests/image/test_fake.py @@ -77,12 +77,6 @@ class FakeImageServiceTestCase(test.TestCase): self.context, 'this image does not exist') - def test_show_by_name(self): - self.assertRaises(exception.ImageNotFound, - self.image_service.show_by_name, - self.context, - 'this image does not exist') - def test_create_adds_id(self): index = self.image_service.index(self.context) image_count = len(index) diff --git a/nova/tests/image/test_glance.py b/nova/tests/image/test_glance.py index 81f1beb60..29c867667 100644 --- a/nova/tests/image/test_glance.py +++ b/nova/tests/image/test_glance.py @@ -190,12 +190,6 @@ class TestGlanceImageService(test.TestCase): self.context, 'bad image id') - def test_create_and_show_non_existing_image_by_name(self): - self.assertRaises(exception.ImageNotFound, - self.service.show_by_name, - self.context, - 'bad image id') - def test_index(self): fixture = self._make_fixture(name='test image') image_id = self.service.create(self.context, fixture)['id'] -- cgit