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])
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
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.
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -765,4 +765,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))
 | 
			
		||||
 
 | 
			
		||||
@@ -104,24 +104,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
 | 
			
		||||
 
 | 
			
		||||
@@ -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()
 | 
			
		||||
 
 | 
			
		||||
@@ -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']
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user