Merge "Use oslo.utils exception encoding util"
This commit is contained in:
commit
82dd9da492
@ -18,8 +18,8 @@ import contextlib
|
||||
import futurist
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import encodeutils
|
||||
from oslo_utils import excutils
|
||||
import six
|
||||
from six.moves import urllib
|
||||
from stevedore import driver
|
||||
from taskflow import engines
|
||||
@ -138,7 +138,8 @@ class TaskExecutor(glance.async.TaskExecutor):
|
||||
except Exception as exc:
|
||||
with excutils.save_and_reraise_exception():
|
||||
LOG.error(_LE('Failed to execute task %(task_id)s: %(exc)s') %
|
||||
{'task_id': task_id, 'exc': six.text_type(exc)})
|
||||
{'task_id': task_id,
|
||||
'exc': encodeutils.exception_to_unicode(exc)})
|
||||
# TODO(sabari): Check for specific exceptions and update the
|
||||
# task failure message.
|
||||
task.fail(_('Task failed due to Internal Error'))
|
||||
|
@ -14,7 +14,7 @@
|
||||
# under the License.
|
||||
|
||||
from oslo_log import log as logging
|
||||
import six
|
||||
from oslo_utils import encodeutils
|
||||
from taskflow import task
|
||||
|
||||
from glance.i18n import _LW
|
||||
@ -61,6 +61,6 @@ class OptionalTask(task.Task):
|
||||
except Exception as exc:
|
||||
msg = (_LW("An optional task has failed, "
|
||||
"the failure was: %s") %
|
||||
six.text_type(exc))
|
||||
encodeutils.exception_to_unicode(exc))
|
||||
LOG.warn(msg)
|
||||
return wrapper
|
||||
|
@ -192,7 +192,8 @@ class Controller(object):
|
||||
module = cls.__module__
|
||||
if module not in CONF.allowed_rpc_exception_modules:
|
||||
cls = exception.RPCError
|
||||
val = six.text_type(exception.RPCError(cls=cls, val=val))
|
||||
val = encodeutils.exception_to_unicode(
|
||||
exception.RPCError(cls=cls, val=val))
|
||||
|
||||
cls_path = "%s.%s" % (cls.__module__, cls.__name__)
|
||||
result = {"_error": {"cls": cls_path, "val": val}}
|
||||
|
@ -21,7 +21,7 @@ import datetime
|
||||
|
||||
import iso8601
|
||||
from monotonic import monotonic as now # noqa
|
||||
import six
|
||||
from oslo_utils import encodeutils
|
||||
|
||||
# ISO 8601 extended time format with microseconds
|
||||
_ISO8601_TIME_FORMAT_SUBSECOND = '%Y-%m-%dT%H:%M:%S.%f'
|
||||
@ -46,9 +46,9 @@ def parse_isotime(timestr):
|
||||
try:
|
||||
return iso8601.parse_date(timestr)
|
||||
except iso8601.ParseError as e:
|
||||
raise ValueError(six.text_type(e))
|
||||
raise ValueError(encodeutils.exception_to_unicode(e))
|
||||
except TypeError as e:
|
||||
raise ValueError(six.text_type(e))
|
||||
raise ValueError(encodeutils.exception_to_unicode(e))
|
||||
|
||||
|
||||
def utcnow(with_timezone=False):
|
||||
|
@ -38,6 +38,7 @@ from oslo_concurrency import processutils
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import encodeutils
|
||||
from oslo_utils import strutils
|
||||
import routes
|
||||
import routes.middleware
|
||||
@ -899,7 +900,8 @@ class Resource(object):
|
||||
"decoded by Glance")
|
||||
raise webob.exc.HTTPBadRequest(explanation=msg)
|
||||
except Exception as e:
|
||||
LOG.exception(_LE("Caught error: %s"), six.text_type(e))
|
||||
LOG.exception(_LE("Caught error: %s"),
|
||||
encodeutils.exception_to_unicode(e))
|
||||
response = webob.exc.HTTPInternalServerError()
|
||||
return response
|
||||
|
||||
|
@ -17,8 +17,8 @@ import copy
|
||||
import glance_store as store
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import encodeutils
|
||||
from oslo_utils import excutils
|
||||
import six
|
||||
|
||||
import glance.api.common
|
||||
import glance.common.exception as exception
|
||||
@ -103,7 +103,7 @@ class ImageRepoProxy(glance.domain.proxy.Repo):
|
||||
if attempted > maximum:
|
||||
kwargs = {'attempted': attempted, 'maximum': maximum}
|
||||
exc = exception.ImagePropertyLimitExceeded(**kwargs)
|
||||
LOG.debug(six.text_type(exc))
|
||||
LOG.debug(encodeutils.exception_to_unicode(exc))
|
||||
raise exc
|
||||
|
||||
def save(self, image, from_state=None):
|
||||
|
@ -16,8 +16,9 @@ import uuid
|
||||
|
||||
import mock
|
||||
from mock import patch
|
||||
from oslo_utils import encodeutils
|
||||
from oslo_utils import units
|
||||
import six
|
||||
|
||||
# NOTE(jokke): simplified transition to py3, behaves like py2 xrange
|
||||
from six.moves import range
|
||||
|
||||
@ -377,7 +378,8 @@ class TestImagePropertyQuotas(test_utils.BaseTestCase):
|
||||
self.image.extra_properties = {'foo': 'bar', 'foo2': 'bar2'}
|
||||
exc = self.assertRaises(exception.ImagePropertyLimitExceeded,
|
||||
self.image_repo_proxy.save, self.image)
|
||||
self.assertIn("Attempted: 2, Maximum: 1", six.text_type(exc))
|
||||
self.assertIn("Attempted: 2, Maximum: 1",
|
||||
encodeutils.exception_to_unicode(exc))
|
||||
|
||||
def test_save_image_unlimited_image_properties(self):
|
||||
self.config(image_property_quota=-1)
|
||||
@ -402,7 +404,8 @@ class TestImagePropertyQuotas(test_utils.BaseTestCase):
|
||||
self.image.extra_properties = {'foo': 'bar', 'foo2': 'bar2'}
|
||||
exc = self.assertRaises(exception.ImagePropertyLimitExceeded,
|
||||
self.image_repo_proxy.add, self.image)
|
||||
self.assertIn("Attempted: 2, Maximum: 1", six.text_type(exc))
|
||||
self.assertIn("Attempted: 2, Maximum: 1",
|
||||
encodeutils.exception_to_unicode(exc))
|
||||
|
||||
def test_add_image_unlimited_image_properties(self):
|
||||
self.config(image_property_quota=-1)
|
||||
@ -512,7 +515,8 @@ class TestImageTagQuotas(test_utils.BaseTestCase):
|
||||
|
||||
exc = self.assertRaises(exception.ImageTagLimitExceeded,
|
||||
setattr, self.image, 'tags', ['foo', 'bar'])
|
||||
self.assertIn('Attempted: 2, Maximum: 0', six.text_type(exc))
|
||||
self.assertIn('Attempted: 2, Maximum: 0',
|
||||
encodeutils.exception_to_unicode(exc))
|
||||
self.assertEqual(0, len(self.image.tags))
|
||||
|
||||
def test_replace_unlimited_image_tags(self):
|
||||
@ -530,7 +534,8 @@ class TestImageTagQuotas(test_utils.BaseTestCase):
|
||||
self.image.tags.add('foo')
|
||||
exc = self.assertRaises(exception.ImageTagLimitExceeded,
|
||||
self.image.tags.add, 'bar')
|
||||
self.assertIn('Attempted: 2, Maximum: 1', six.text_type(exc))
|
||||
self.assertIn('Attempted: 2, Maximum: 1',
|
||||
encodeutils.exception_to_unicode(exc))
|
||||
|
||||
def test_add_unlimited_image_tags(self):
|
||||
self.config(image_tag_quota=-1)
|
||||
@ -560,7 +565,8 @@ class TestQuotaImageTagsProxy(test_utils.BaseTestCase):
|
||||
proxy = glance.quota.QuotaImageTagsProxy(set([]))
|
||||
exc = self.assertRaises(exception.ImageTagLimitExceeded,
|
||||
proxy.add, 'bar')
|
||||
self.assertIn('Attempted: 1, Maximum: 0', six.text_type(exc))
|
||||
self.assertIn('Attempted: 1, Maximum: 0',
|
||||
encodeutils.exception_to_unicode(exc))
|
||||
|
||||
def test_equals(self):
|
||||
proxy = glance.quota.QuotaImageTagsProxy(set([]))
|
||||
@ -661,7 +667,8 @@ class TestImageLocationQuotas(test_utils.BaseTestCase):
|
||||
]
|
||||
exc = self.assertRaises(exception.ImageLocationLimitExceeded,
|
||||
setattr, self.image, 'locations', locations)
|
||||
self.assertIn('Attempted: 3, Maximum: 1', six.text_type(exc))
|
||||
self.assertIn('Attempted: 3, Maximum: 1',
|
||||
encodeutils.exception_to_unicode(exc))
|
||||
self.assertEqual(1, len(self.image.locations))
|
||||
|
||||
def test_replace_unlimited_image_locations(self):
|
||||
@ -684,7 +691,8 @@ class TestImageLocationQuotas(test_utils.BaseTestCase):
|
||||
location2 = {"url": "file:///fake2.img.tar.gz", "metadata": {}}
|
||||
exc = self.assertRaises(exception.ImageLocationLimitExceeded,
|
||||
self.image.locations.append, location2)
|
||||
self.assertIn('Attempted: 2, Maximum: 1', six.text_type(exc))
|
||||
self.assertIn('Attempted: 2, Maximum: 1',
|
||||
encodeutils.exception_to_unicode(exc))
|
||||
|
||||
def test_add_unlimited_image_locations(self):
|
||||
self.config(image_location_quota=-1)
|
||||
|
Loading…
Reference in New Issue
Block a user