summaryrefslogtreecommitdiff
path: root/glanceclient
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2015-09-30 18:10:40 +0000
committerGerrit Code Review <review@openstack.org>2015-09-30 18:10:40 +0000
commit8c0c3c9ed4666a4061b1a3d057ae0a2db851dc75 (patch)
treec231f69d274489df17f156e507196bb4a11d10a2 /glanceclient
parenta98ed220916a0cae022b35dcdc212ba65eacafd2 (diff)
parentc6addc722c99ce2688b335dd20c796c3a5dab1ba (diff)
downloadpython-glanceclient-8c0c3c9ed4666a4061b1a3d057ae0a2db851dc75.tar.gz
Merge "Replace exception_to_str with oslo.utils function"
Diffstat (limited to 'glanceclient')
-rw-r--r--glanceclient/common/utils.py12
-rwxr-xr-xglanceclient/shell.py2
-rw-r--r--glanceclient/tests/unit/test_utils.py18
-rw-r--r--glanceclient/v2/images.py4
-rw-r--r--glanceclient/v2/metadefs.py18
-rw-r--r--glanceclient/v2/tasks.py2
6 files changed, 13 insertions, 43 deletions
diff --git a/glanceclient/common/utils.py b/glanceclient/common/utils.py
index 31ed654..955a365 100644
--- a/glanceclient/common/utils.py
+++ b/glanceclient/common/utils.py
@@ -321,18 +321,6 @@ def make_size_human_readable(size):
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):
"""Analyze file-like object and attempt to determine its size.
diff --git a/glanceclient/shell.py b/glanceclient/shell.py
index f2a5cff..06b2c46 100755
--- a/glanceclient/shell.py
+++ b/glanceclient/shell.py
@@ -763,4 +763,4 @@ def main():
except KeyboardInterrupt:
utils.exit('... terminating glance client', exit_code=130)
except Exception as e:
- utils.exit(utils.exception_to_str(e))
+ utils.exit(encodeutils.exception_to_unicode(e))
diff --git a/glanceclient/tests/unit/test_utils.py b/glanceclient/tests/unit/test_utils.py
index 7e01ede..0b2d6d9 100644
--- a/glanceclient/tests/unit/test_utils.py
+++ b/glanceclient/tests/unit/test_utils.py
@@ -105,24 +105,6 @@ class TestUtils(testtools.TestCase):
''',
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):
# NOTE(flaper87): Regression for bug
# https://bugs.launchpad.net/python-glanceclient/+bug/1401032
diff --git a/glanceclient/v2/images.py b/glanceclient/v2/images.py
index 1399992..c126a35 100644
--- a/glanceclient/v2/images.py
+++ b/glanceclient/v2/images.py
@@ -230,7 +230,7 @@ class Controller(object):
try:
setattr(image, key, value)
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)
# NOTE(esheffield): remove 'self' for now until we have an elegant
@@ -250,7 +250,7 @@ class Controller(object):
try:
setattr(image, key, value)
except warlock.InvalidOperation as e:
- raise TypeError(utils.exception_to_str(e))
+ raise TypeError(encodeutils.exception_to_unicode(e))
if remove_props:
cur_props = image.keys()
diff --git a/glanceclient/v2/metadefs.py b/glanceclient/v2/metadefs.py
index 8d83af4..2344e33 100644
--- a/glanceclient/v2/metadefs.py
+++ b/glanceclient/v2/metadefs.py
@@ -45,7 +45,7 @@ class NamespaceController(object):
try:
namespace = self.model(kwargs)
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)
body.pop('self', None)
@@ -62,7 +62,7 @@ class NamespaceController(object):
try:
setattr(namespace, key, value)
except warlock.InvalidOperation as e:
- raise TypeError(utils.exception_to_str(e))
+ raise TypeError(encodeutils.exception_to_unicode(e))
# Remove read-only parameters.
read_only = ['schema', 'updated_at', 'created_at']
@@ -192,7 +192,7 @@ class ResourceTypeController(object):
try:
res_type = self.model(kwargs)
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,
res_type)
@@ -244,7 +244,7 @@ class PropertyController(object):
try:
prop = self.model(kwargs)
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)
@@ -264,7 +264,7 @@ class PropertyController(object):
try:
setattr(prop, key, value)
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,
prop_name)
@@ -324,7 +324,7 @@ class ObjectController(object):
try:
obj = self.model(kwargs)
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)
@@ -344,7 +344,7 @@ class ObjectController(object):
try:
setattr(obj, key, value)
except warlock.InvalidOperation as e:
- raise TypeError(utils.exception_to_str(e))
+ raise TypeError(encodeutils.exception_to_unicode(e))
# Remove read-only parameters.
read_only = ['schema', 'updated_at', 'created_at']
@@ -426,7 +426,7 @@ class TagController(object):
try:
md_tag_list.append(self.model(name=tag_name))
except (warlock.InvalidOperation) as e:
- raise TypeError(utils.exception_to_str(e))
+ raise TypeError(encodeutils.exception_to_unicode(e))
tags = {'tags': md_tag_list}
url = '/v2/metadefs/namespaces/{0}/tags'.format(namespace)
@@ -448,7 +448,7 @@ class TagController(object):
try:
setattr(tag, key, value)
except warlock.InvalidOperation as e:
- raise TypeError(utils.exception_to_str(e))
+ raise TypeError(encodeutils.exception_to_unicode(e))
# Remove read-only parameters.
read_only = ['updated_at', 'created_at']
diff --git a/glanceclient/v2/tasks.py b/glanceclient/v2/tasks.py
index 2f4aca5..4c06181 100644
--- a/glanceclient/v2/tasks.py
+++ b/glanceclient/v2/tasks.py
@@ -110,7 +110,7 @@ class Controller(object):
try:
setattr(task, key, value)
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)
# NOTE(flwang): remove 'self' for now until we have an elegant