summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Tran <jtran@attinteractive.com>2011-03-28 11:29:23 -0700
committerJohn Tran <jtran@attinteractive.com>2011-03-28 11:29:23 -0700
commit9ce24afab007a9b5144c8c8a8f2fcc4157ba34d7 (patch)
treed98c265d658272dad3b6cb6eb917cd243cde6c23
parentc400024de45073ccc23a6738c78518365a511562 (diff)
when image_id provided cannot be found, returns more informative error message.
-rw-r--r--nova/api/ec2/cloud.py6
-rw-r--r--nova/tests/test_cloud.py15
2 files changed, 20 insertions, 1 deletions
diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py
index e257e44e7..2f47f0927 100644
--- a/nova/api/ec2/cloud.py
+++ b/nova/api/ec2/cloud.py
@@ -909,7 +909,11 @@ class CloudController(object):
def deregister_image(self, context, image_id, **kwargs):
LOG.audit(_("De-registering image %s"), image_id, context=context)
- image = self._get_image(context, image_id)
+ try:
+ image = self._get_image(context, image_id)
+ except exception.NotFound:
+ raise exception.NotFound(_('Image %s not found') %
+ image_id)
internal_id = image['id']
self.image_service.delete(context, internal_id)
return {'imageId': image_id}
diff --git a/nova/tests/test_cloud.py b/nova/tests/test_cloud.py
index 2f0571ca3..8043d4670 100644
--- a/nova/tests/test_cloud.py
+++ b/nova/tests/test_cloud.py
@@ -41,6 +41,7 @@ from nova.api.ec2 import cloud
from nova.api.ec2 import ec2utils
from nova.image import local
from nova.objectstore import image
+from nova.exception import NotEmpty, NotFound
FLAGS = flags.FLAGS
@@ -85,8 +86,12 @@ class CloudTestCase(test.TestCase):
return [{'id': 1, 'properties': {'kernel_id': 1, 'ramdisk_id': 1,
'type':'machine'}}]
+ def fake_delete(meh, context, id):
+ return None
+
self.stubs.Set(local.LocalImageService, 'show', fake_show)
self.stubs.Set(local.LocalImageService, 'detail', fake_detail)
+ self.stubs.Set(local.LocalImageService, 'delete', fake_delete)
self.stubs.Set(local.LocalImageService, 'show_by_name', fake_show)
def tearDown(self):
@@ -234,6 +239,16 @@ class CloudTestCase(test.TestCase):
result = result['imagesSet'][0]
self.assertEqual(result['imageId'], 'ami-00000001')
+ def test_deregister_image(self):
+ deregister_image = self.cloud.deregister_image
+ """When provided a valid image, should be successful"""
+ result1 = deregister_image(self.context, 'ami-00000001')
+ self.assertEqual(result1['imageId'], 'ami-00000001')
+ """Invalid image should throw an NotFound exception"""
+ self.stubs.UnsetAll()
+ self.assertRaises(NotFound, deregister_image,
+ self.context, 'ami-bad001')
+
def test_console_output(self):
instance_type = FLAGS.default_instance_type
max_count = 1