Skip to content

Commit

Permalink
Merge "Handle Forbidden and NotAuthenticated glance exc."
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Mar 27, 2012
2 parents a003e45 + 42585a3 commit 2483dbf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
6 changes: 4 additions & 2 deletions nova/image/glance.py
Expand Up @@ -485,7 +485,8 @@ def _reraise_translated_exception():


def _translate_image_exception(image_id, exc_type, exc_value):
if exc_type in (glance_exception.NotAuthorized,
if exc_type in (glance_exception.Forbidden,
glance_exception.NotAuthenticated,
glance_exception.MissingCredentialError):
return exception.ImageNotAuthorized(image_id=image_id)
if exc_type is glance_exception.NotFound:
Expand All @@ -496,7 +497,8 @@ def _translate_image_exception(image_id, exc_type, exc_value):


def _translate_plain_exception(exc_type, exc_value):
if exc_type in (glance_exception.NotAuthorized,
if exc_type in (glance_exception.Forbidden,
glance_exception.NotAuthenticated,
glance_exception.MissingCredentialError):
return exception.NotAuthorized(exc_value)
if exc_type is glance_exception.NotFound:
Expand Down
13 changes: 13 additions & 0 deletions nova/tests/image/test_glance.py
Expand Up @@ -556,6 +556,19 @@ def get_image(self, image_id):
self.flags(glance_num_retries=1)
service.get(self.context, image_id, writer)

def test_client_raises_forbidden(self):
class MyGlanceStubClient(glance_stubs.StubGlanceClient):
"""A client that fails the first time, then succeeds."""
def get_image(self, image_id):
raise glance_exception.Forbidden()

client = MyGlanceStubClient()
service = glance.GlanceImageService(client=client)
image_id = 1 # doesn't matter
writer = NullWriter()
self.assertRaises(exception.ImageNotAuthorized, service.get,
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']
Expand Down

0 comments on commit 2483dbf

Please sign in to comment.