summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-01-23 16:43:40 +0000
committerGerrit Code Review <review@openstack.org>2017-01-23 16:43:40 +0000
commit3743fec49b69dc0ec23d92d7a41f0aa69f7b5581 (patch)
treeaf47a903d503250f78f62324eba4268aae1b96ef
parent9b63d007d769d874b7e912c081661b4b3de00733 (diff)
parentd8a621015259eaafd8d1fee99db3ca663cd4be5c (diff)
downloadpython-cinderclient-3743fec49b69dc0ec23d92d7a41f0aa69f7b5581.tar.gz
Merge "Fix adding non-ascii attrs to Resource objects error"
-rw-r--r--cinderclient/apiclient/base.py3
-rw-r--r--cinderclient/tests/unit/test_base.py10
2 files changed, 12 insertions, 1 deletions
diff --git a/cinderclient/apiclient/base.py b/cinderclient/apiclient/base.py
index 3ae5dff..e1f611c 100644
--- a/cinderclient/apiclient/base.py
+++ b/cinderclient/apiclient/base.py
@@ -31,6 +31,7 @@ import six
from six.moves.urllib import parse
from cinderclient.apiclient import exceptions
+from oslo_utils import encodeutils
from oslo_utils import strutils
@@ -496,7 +497,7 @@ class Resource(RequestIdMixin):
# In this case we already defined the attribute on the class
continue
except UnicodeEncodeError:
- pass
+ setattr(self, encodeutils.safe_encode(k), v)
self._info[k] = v
def __getattr__(self, k):
diff --git a/cinderclient/tests/unit/test_base.py b/cinderclient/tests/unit/test_base.py
index 91f96ba..ce8d9e4 100644
--- a/cinderclient/tests/unit/test_base.py
+++ b/cinderclient/tests/unit/test_base.py
@@ -48,6 +48,16 @@ class BaseTest(utils.TestCase):
self.assertEqual("<Resource baz=spam, foo=bar>", repr(r))
self.assertNotIn("x_openstack_request_ids", repr(r))
+ def test_add_non_ascii_attr_to_resource(self):
+ info = {'gigabytes_тест': -1,
+ 'volumes_тест': -1,
+ 'id': 'admin'}
+
+ res = base.Resource(None, info)
+
+ for key, value in info.items():
+ self.assertEqual(value, getattr(res, key, None))
+
def test_getid(self):
self.assertEqual(4, base.getid(4))