Merge "Remove exception declarations from replicator.py"
This commit is contained in:
commit
fe939409f9
|
@ -25,7 +25,9 @@ import sys
|
|||
|
||||
from oslo.serialization import jsonutils
|
||||
import six.moves.urllib.parse as urlparse
|
||||
from webob import exc
|
||||
|
||||
from glance.common import exception
|
||||
from glance.common import utils
|
||||
from glance.openstack.common import gettextutils
|
||||
from glance.openstack.common import log
|
||||
|
@ -62,22 +64,6 @@ IMAGE_ALREADY_PRESENT_MESSAGE = _('The image %s is already present on '
|
|||
'the images on the slave server.')
|
||||
|
||||
|
||||
class AuthenticationException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class ImageAlreadyPresentException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class ServerErrorException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class UploadException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class ImageService(object):
|
||||
def __init__(self, conn, auth_token):
|
||||
"""Initialize the ImageService.
|
||||
|
@ -121,14 +107,25 @@ class ImageService(object):
|
|||
'status': code_description,
|
||||
'headers': repr(headers)})
|
||||
|
||||
if code in [400, 500]:
|
||||
raise ServerErrorException(response.read())
|
||||
if code == 400:
|
||||
raise exc.HTTPBadRequest(
|
||||
explanation=response.read())
|
||||
|
||||
if code in [401, 403]:
|
||||
raise AuthenticationException(response.read())
|
||||
if code == 500:
|
||||
raise exc.HTTPInternalServerError(
|
||||
explanation=response.read())
|
||||
|
||||
if code == 401:
|
||||
raise exc.HTTPUnauthorized(
|
||||
explanation=response.read())
|
||||
|
||||
if code == 403:
|
||||
raise exc.HTTPForbidden(
|
||||
explanation=response.read())
|
||||
|
||||
if code == 409:
|
||||
raise ImageAlreadyPresentException(response.read())
|
||||
raise exc.HTTPConflict(
|
||||
explanation=response.read())
|
||||
|
||||
if ignore_result_body:
|
||||
# NOTE: because we are pipelining requests through a single HTTP
|
||||
|
@ -442,7 +439,7 @@ def replication_load(options, args):
|
|||
headers, body = client.add_image(meta, img_file)
|
||||
_check_upload_response_headers(headers, body)
|
||||
updated.append(meta['id'])
|
||||
except ImageAlreadyPresentException:
|
||||
except exc.HTTPConflict:
|
||||
LOG.error(_LE(IMAGE_ALREADY_PRESENT_MESSAGE)
|
||||
% image_uuid) # noqa
|
||||
|
||||
|
@ -514,7 +511,7 @@ def replication_livecopy(options, args):
|
|||
image_response)
|
||||
_check_upload_response_headers(headers, body)
|
||||
updated.append(image['id'])
|
||||
except ImageAlreadyPresentException:
|
||||
except exc.HTTPConflict:
|
||||
LOG.error(_LE(IMAGE_ALREADY_PRESENT_MESSAGE) % image['id']) # noqa
|
||||
|
||||
return updated
|
||||
|
@ -594,7 +591,7 @@ def _check_upload_response_headers(headers, body):
|
|||
return
|
||||
|
||||
except Exception:
|
||||
raise UploadException('Image upload problem: %s' % body)
|
||||
raise exception.UploadException(body)
|
||||
|
||||
|
||||
def _image_present(client, image_uuid):
|
||||
|
|
|
@ -106,6 +106,10 @@ class NotAuthenticated(GlanceException):
|
|||
message = _("You are not authenticated.")
|
||||
|
||||
|
||||
class UploadException(GlanceException):
|
||||
message = _('Image upload problem: %s')
|
||||
|
||||
|
||||
class Forbidden(GlanceException):
|
||||
message = _("You are not authorized to complete this action.")
|
||||
|
||||
|
|
|
@ -21,8 +21,10 @@ import uuid
|
|||
import fixtures
|
||||
from oslo.serialization import jsonutils
|
||||
import six
|
||||
import webob
|
||||
|
||||
from glance.cmd import replicator as glance_replicator
|
||||
from glance.common import exception
|
||||
from glance.tests.unit import utils as unit_test_utils
|
||||
from glance.tests import utils as test_utils
|
||||
|
||||
|
@ -124,12 +126,11 @@ class ImageServiceTestCase(test_utils.BaseTestCase):
|
|||
def test_rest_errors(self):
|
||||
c = glance_replicator.ImageService(FakeHTTPConnection(), 'noauth')
|
||||
|
||||
for code, exc in [(400, glance_replicator.ServerErrorException),
|
||||
(401, glance_replicator.AuthenticationException),
|
||||
(403, glance_replicator.AuthenticationException),
|
||||
(409,
|
||||
glance_replicator.ImageAlreadyPresentException),
|
||||
(500, glance_replicator.ServerErrorException)]:
|
||||
for code, exc in [(400, webob.exc.HTTPBadRequest),
|
||||
(401, webob.exc.HTTPUnauthorized),
|
||||
(403, webob.exc.HTTPForbidden),
|
||||
(409, webob.exc.HTTPConflict),
|
||||
(500, webob.exc.HTTPInternalServerError)]:
|
||||
c.conn.prime_request('GET',
|
||||
('v1/images/'
|
||||
'5dcddce0-cba5-4f18-9cf4-9853c7b207a6'), '',
|
||||
|
@ -552,7 +553,7 @@ class ReplicationUtilitiesTestCase(test_utils.BaseTestCase):
|
|||
jsonutils.dumps(d))
|
||||
|
||||
self.assertRaises(
|
||||
glance_replicator.UploadException,
|
||||
exception.UploadException,
|
||||
glance_replicator._check_upload_response_headers, {}, None)
|
||||
|
||||
def test_image_present(self):
|
||||
|
|
Loading…
Reference in New Issue