Replace exception_to_str with oslo.utils function
The oslo.utils function has exception_to_unicode that can replace glance util function exception_to_str. So we don't to have this exception_to_str function in glance anymore. Change-Id: I332bc55558087920fdd6ae2d822bece5166f5ba6
This commit is contained in:
@@ -319,18 +319,6 @@ def make_size_human_readable(size):
|
|||||||
return '%s%s' % (stripped, suffix[index])
|
return '%s%s' % (stripped, suffix[index])
|
||||||
|
|
||||||
|
|
||||||
def exception_to_str(exc):
|
|
||||||
try:
|
|
||||||
error = six.text_type(exc)
|
|
||||||
except UnicodeError:
|
|
||||||
try:
|
|
||||||
error = str(exc)
|
|
||||||
except UnicodeError:
|
|
||||||
error = ("Caught '%(exception)s' exception." %
|
|
||||||
{"exception": exc.__class__.__name__})
|
|
||||||
return encodeutils.safe_decode(error, errors='ignore')
|
|
||||||
|
|
||||||
|
|
||||||
def get_file_size(file_obj):
|
def get_file_size(file_obj):
|
||||||
"""Analyze file-like object and attempt to determine its size.
|
"""Analyze file-like object and attempt to determine its size.
|
||||||
|
|
||||||
|
@@ -765,4 +765,4 @@ def main():
|
|||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
utils.exit('... terminating glance client', exit_code=130)
|
utils.exit('... terminating glance client', exit_code=130)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
utils.exit(utils.exception_to_str(e))
|
utils.exit(encodeutils.exception_to_unicode(e))
|
||||||
|
@@ -104,24 +104,6 @@ class TestUtils(testtools.TestCase):
|
|||||||
''',
|
''',
|
||||||
output_dict.getvalue())
|
output_dict.getvalue())
|
||||||
|
|
||||||
def test_exception_to_str(self):
|
|
||||||
class FakeException(Exception):
|
|
||||||
def __str__(self):
|
|
||||||
raise UnicodeError()
|
|
||||||
|
|
||||||
ret = utils.exception_to_str(Exception('error message'))
|
|
||||||
self.assertEqual('error message', ret)
|
|
||||||
|
|
||||||
ret = utils.exception_to_str(Exception('\xa5 error message'))
|
|
||||||
if six.PY2:
|
|
||||||
self.assertEqual(' error message', ret)
|
|
||||||
else:
|
|
||||||
self.assertEqual('\xa5 error message', ret)
|
|
||||||
|
|
||||||
ret = utils.exception_to_str(FakeException('\xa5 error message'))
|
|
||||||
self.assertEqual("Caught '%(exception)s' exception." %
|
|
||||||
{'exception': 'FakeException'}, ret)
|
|
||||||
|
|
||||||
def test_schema_args_with_list_types(self):
|
def test_schema_args_with_list_types(self):
|
||||||
# NOTE(flaper87): Regression for bug
|
# NOTE(flaper87): Regression for bug
|
||||||
# https://bugs.launchpad.net/python-glanceclient/+bug/1401032
|
# https://bugs.launchpad.net/python-glanceclient/+bug/1401032
|
||||||
|
@@ -230,7 +230,7 @@ class Controller(object):
|
|||||||
try:
|
try:
|
||||||
setattr(image, key, value)
|
setattr(image, key, value)
|
||||||
except warlock.InvalidOperation as e:
|
except warlock.InvalidOperation as e:
|
||||||
raise TypeError(utils.exception_to_str(e))
|
raise TypeError(encodeutils.exception_to_unicode(e))
|
||||||
|
|
||||||
resp, body = self.http_client.post(url, data=image)
|
resp, body = self.http_client.post(url, data=image)
|
||||||
# NOTE(esheffield): remove 'self' for now until we have an elegant
|
# NOTE(esheffield): remove 'self' for now until we have an elegant
|
||||||
@@ -250,7 +250,7 @@ class Controller(object):
|
|||||||
try:
|
try:
|
||||||
setattr(image, key, value)
|
setattr(image, key, value)
|
||||||
except warlock.InvalidOperation as e:
|
except warlock.InvalidOperation as e:
|
||||||
raise TypeError(utils.exception_to_str(e))
|
raise TypeError(encodeutils.exception_to_unicode(e))
|
||||||
|
|
||||||
if remove_props:
|
if remove_props:
|
||||||
cur_props = image.keys()
|
cur_props = image.keys()
|
||||||
|
@@ -45,7 +45,7 @@ class NamespaceController(object):
|
|||||||
try:
|
try:
|
||||||
namespace = self.model(kwargs)
|
namespace = self.model(kwargs)
|
||||||
except (warlock.InvalidOperation, ValueError) as e:
|
except (warlock.InvalidOperation, ValueError) as e:
|
||||||
raise TypeError(utils.exception_to_str(e))
|
raise TypeError(encodeutils.exception_to_unicode(e))
|
||||||
|
|
||||||
resp, body = self.http_client.post(url, data=namespace)
|
resp, body = self.http_client.post(url, data=namespace)
|
||||||
body.pop('self', None)
|
body.pop('self', None)
|
||||||
@@ -62,7 +62,7 @@ class NamespaceController(object):
|
|||||||
try:
|
try:
|
||||||
setattr(namespace, key, value)
|
setattr(namespace, key, value)
|
||||||
except warlock.InvalidOperation as e:
|
except warlock.InvalidOperation as e:
|
||||||
raise TypeError(utils.exception_to_str(e))
|
raise TypeError(encodeutils.exception_to_unicode(e))
|
||||||
|
|
||||||
# Remove read-only parameters.
|
# Remove read-only parameters.
|
||||||
read_only = ['schema', 'updated_at', 'created_at']
|
read_only = ['schema', 'updated_at', 'created_at']
|
||||||
@@ -192,7 +192,7 @@ class ResourceTypeController(object):
|
|||||||
try:
|
try:
|
||||||
res_type = self.model(kwargs)
|
res_type = self.model(kwargs)
|
||||||
except (warlock.InvalidOperation, ValueError) as e:
|
except (warlock.InvalidOperation, ValueError) as e:
|
||||||
raise TypeError(utils.exception_to_str(e))
|
raise TypeError(encodeutils.exception_to_unicode(e))
|
||||||
|
|
||||||
url = '/v2/metadefs/namespaces/{0}/resource_types'.format(namespace,
|
url = '/v2/metadefs/namespaces/{0}/resource_types'.format(namespace,
|
||||||
res_type)
|
res_type)
|
||||||
@@ -244,7 +244,7 @@ class PropertyController(object):
|
|||||||
try:
|
try:
|
||||||
prop = self.model(kwargs)
|
prop = self.model(kwargs)
|
||||||
except (warlock.InvalidOperation, ValueError) as e:
|
except (warlock.InvalidOperation, ValueError) as e:
|
||||||
raise TypeError(utils.exception_to_str(e))
|
raise TypeError(encodeutils.exception_to_unicode(e))
|
||||||
|
|
||||||
url = '/v2/metadefs/namespaces/{0}/properties'.format(namespace)
|
url = '/v2/metadefs/namespaces/{0}/properties'.format(namespace)
|
||||||
|
|
||||||
@@ -264,7 +264,7 @@ class PropertyController(object):
|
|||||||
try:
|
try:
|
||||||
setattr(prop, key, value)
|
setattr(prop, key, value)
|
||||||
except warlock.InvalidOperation as e:
|
except warlock.InvalidOperation as e:
|
||||||
raise TypeError(utils.exception_to_str(e))
|
raise TypeError(encodeutils.exception_to_unicode(e))
|
||||||
|
|
||||||
url = '/v2/metadefs/namespaces/{0}/properties/{1}'.format(namespace,
|
url = '/v2/metadefs/namespaces/{0}/properties/{1}'.format(namespace,
|
||||||
prop_name)
|
prop_name)
|
||||||
@@ -324,7 +324,7 @@ class ObjectController(object):
|
|||||||
try:
|
try:
|
||||||
obj = self.model(kwargs)
|
obj = self.model(kwargs)
|
||||||
except (warlock.InvalidOperation, ValueError) as e:
|
except (warlock.InvalidOperation, ValueError) as e:
|
||||||
raise TypeError(utils.exception_to_str(e))
|
raise TypeError(encodeutils.exception_to_unicode(e))
|
||||||
|
|
||||||
url = '/v2/metadefs/namespaces/{0}/objects'.format(namespace)
|
url = '/v2/metadefs/namespaces/{0}/objects'.format(namespace)
|
||||||
|
|
||||||
@@ -344,7 +344,7 @@ class ObjectController(object):
|
|||||||
try:
|
try:
|
||||||
setattr(obj, key, value)
|
setattr(obj, key, value)
|
||||||
except warlock.InvalidOperation as e:
|
except warlock.InvalidOperation as e:
|
||||||
raise TypeError(utils.exception_to_str(e))
|
raise TypeError(encodeutils.exception_to_unicode(e))
|
||||||
|
|
||||||
# Remove read-only parameters.
|
# Remove read-only parameters.
|
||||||
read_only = ['schema', 'updated_at', 'created_at']
|
read_only = ['schema', 'updated_at', 'created_at']
|
||||||
@@ -426,7 +426,7 @@ class TagController(object):
|
|||||||
try:
|
try:
|
||||||
md_tag_list.append(self.model(name=tag_name))
|
md_tag_list.append(self.model(name=tag_name))
|
||||||
except (warlock.InvalidOperation) as e:
|
except (warlock.InvalidOperation) as e:
|
||||||
raise TypeError(utils.exception_to_str(e))
|
raise TypeError(encodeutils.exception_to_unicode(e))
|
||||||
tags = {'tags': md_tag_list}
|
tags = {'tags': md_tag_list}
|
||||||
|
|
||||||
url = '/v2/metadefs/namespaces/{0}/tags'.format(namespace)
|
url = '/v2/metadefs/namespaces/{0}/tags'.format(namespace)
|
||||||
@@ -448,7 +448,7 @@ class TagController(object):
|
|||||||
try:
|
try:
|
||||||
setattr(tag, key, value)
|
setattr(tag, key, value)
|
||||||
except warlock.InvalidOperation as e:
|
except warlock.InvalidOperation as e:
|
||||||
raise TypeError(utils.exception_to_str(e))
|
raise TypeError(encodeutils.exception_to_unicode(e))
|
||||||
|
|
||||||
# Remove read-only parameters.
|
# Remove read-only parameters.
|
||||||
read_only = ['updated_at', 'created_at']
|
read_only = ['updated_at', 'created_at']
|
||||||
|
@@ -110,7 +110,7 @@ class Controller(object):
|
|||||||
try:
|
try:
|
||||||
setattr(task, key, value)
|
setattr(task, key, value)
|
||||||
except warlock.InvalidOperation as e:
|
except warlock.InvalidOperation as e:
|
||||||
raise TypeError(utils.exception_to_str(e))
|
raise TypeError(encodeutils.exception_to_unicode(e))
|
||||||
|
|
||||||
resp, body = self.http_client.post(url, data=task)
|
resp, body = self.http_client.post(url, data=task)
|
||||||
# NOTE(flwang): remove 'self' for now until we have an elegant
|
# NOTE(flwang): remove 'self' for now until we have an elegant
|
||||||
|
Reference in New Issue
Block a user