summaryrefslogtreecommitdiffstats
path: root/nova/tests/image
diff options
context:
space:
mode:
authorChris Behrens <cbehrens@codestud.com>2012-08-21 18:28:59 +0000
committerChris Behrens <cbehrens@codestud.com>2012-08-21 18:28:59 +0000
commit3c73cbf550ebb3d3b0869f4ebd3870530c92f721 (patch)
treeead856f2e14230dc99e1f9cdccd38d65f2feed00 /nova/tests/image
parent96e72e7295909cbe2ddb835283f68168cef883c1 (diff)
downloadnova-3c73cbf550ebb3d3b0869f4ebd3870530c92f721.tar.gz
nova-3c73cbf550ebb3d3b0869f4ebd3870530c92f721.tar.xz
nova-3c73cbf550ebb3d3b0869f4ebd3870530c92f721.zip
Make glance image service check base exception classes
Fixes bug 1039675 glanceclient can raise HTTPNotFound (as well as NotFound) it appears, but glance image service is only converting NotFound -> InstanceNotFound. Same applies to 'Forbidden' and other exceptions. This patch converts 'exc_type is NotFound'-like checks to use 'isinstance' instead, which will cover HTTPNotFound, etc. Change-Id: I0982875e667121cee3da3cfe0124499cad484fa6
Diffstat (limited to 'nova/tests/image')
-rw-r--r--nova/tests/image/test_glance.py43
1 files changed, 41 insertions, 2 deletions
diff --git a/nova/tests/image/test_glance.py b/nova/tests/image/test_glance.py
index f34e24c0b..5b695d2f7 100644
--- a/nova/tests/image/test_glance.py
+++ b/nova/tests/image/test_glance.py
@@ -464,9 +464,9 @@ class TestGlanceImageService(test.TestCase):
self.flags(glance_num_retries=1)
service.download(self.context, image_id, writer)
- def test_client_raises_forbidden(self):
+ def test_client_forbidden_converts_to_imagenotauthed(self):
class MyGlanceStubClient(glance_stubs.StubGlanceClient):
- """A client that fails the first time, then succeeds."""
+ """A client that raises a Forbidden exception."""
def get(self, image_id):
raise glanceclient.exc.Forbidden(image_id)
@@ -477,6 +477,45 @@ class TestGlanceImageService(test.TestCase):
self.assertRaises(exception.ImageNotAuthorized, service.download,
self.context, image_id, writer)
+ def test_client_httpforbidden_converts_to_imagenotauthed(self):
+ class MyGlanceStubClient(glance_stubs.StubGlanceClient):
+ """A client that raises a HTTPForbidden exception."""
+ def get(self, image_id):
+ raise glanceclient.exc.HTTPForbidden(image_id)
+
+ client = MyGlanceStubClient()
+ service = self._create_image_service(client)
+ image_id = 1 # doesn't matter
+ writer = NullWriter()
+ self.assertRaises(exception.ImageNotAuthorized, service.download,
+ self.context, image_id, writer)
+
+ def test_client_notfound_converts_to_imagenotfound(self):
+ class MyGlanceStubClient(glance_stubs.StubGlanceClient):
+ """A client that raises a NotFound exception."""
+ def get(self, image_id):
+ raise glanceclient.exc.NotFound(image_id)
+
+ client = MyGlanceStubClient()
+ service = self._create_image_service(client)
+ image_id = 1 # doesn't matter
+ writer = NullWriter()
+ self.assertRaises(exception.ImageNotFound, service.download,
+ self.context, image_id, writer)
+
+ def test_client_httpnotfound_converts_to_imagenotfound(self):
+ class MyGlanceStubClient(glance_stubs.StubGlanceClient):
+ """A client that raises a HTTPNotFound exception."""
+ def get(self, image_id):
+ raise glanceclient.exc.HTTPNotFound(image_id)
+
+ client = MyGlanceStubClient()
+ service = self._create_image_service(client)
+ image_id = 1 # doesn't matter
+ writer = NullWriter()
+ self.assertRaises(exception.ImageNotFound, service.download,
+ self.context, image_id, writer)
+
def test_glance_client_image_id(self):
fixture = self._make_fixture(name='test image')
image_id = self.service.create(self.context, fixture)['id']