diff options
author | Kevin_Zheng <zhengzhenyu@huawei.com> | 2017-03-03 14:54:11 +0800 |
---|---|---|
committer | Matt Riedemann <mriedem@us.ibm.com> | 2017-03-05 17:17:26 +0000 |
commit | 50e571c23d7cdee527826d9eaa70d467b3e63d25 (patch) | |
tree | a06a58c77dc3a1d96f74c265baa84877a141a12c | |
parent | f6e0128f9a66b48a24c10d532a9e4e8d7d7e94a5 (diff) | |
download | python-novaclient-50e571c23d7cdee527826d9eaa70d467b3e63d25.tar.gz |
Tags and Metadata fields with unicode cannot be correctly displayed
Currently, Tags(list) and Metadata(dict) fields of instance will
firstly transformed to str using jsondump first when display. And
cannot be correctly transfomed and displayed afterwards.
This patch adds ensure_ascii=False to the transform function thus
those fields can be correctly tranformed and displayed afterwards.
Change-Id: Ib4e7a34f3b19db89280cc73053acbac8c8816f85
Closes-Bug: #1669683
(cherry picked from commit 07971152413c3aa94e87b16f562acf686b9c5f48)
-rw-r--r-- | novaclient/tests/functional/v2/test_servers.py | 19 | ||||
-rw-r--r-- | novaclient/utils.py | 2 |
2 files changed, 18 insertions, 3 deletions
diff --git a/novaclient/tests/functional/v2/test_servers.py b/novaclient/tests/functional/v2/test_servers.py index 6adf1e05..7027413d 100644 --- a/novaclient/tests/functional/v2/test_servers.py +++ b/novaclient/tests/functional/v2/test_servers.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at @@ -134,9 +135,9 @@ class TestServersTagsV226(base.ClientTestBase): COMPUTE_API_VERSION = "2.26" - def _boot_server_with_tags(self): + def _boot_server_with_tags(self, tags=["t1", "t2"]): uuid = self._create_server().id - self.client.servers.set_tags(uuid, ["t1", "t2"]) + self.client.servers.set_tags(uuid, tags) return uuid def test_show(self): @@ -145,6 +146,20 @@ class TestServersTagsV226(base.ClientTestBase): self.assertEqual('["t1", "t2"]', self._get_value_from_the_table( output, "tags")) + def test_unicode_tag_correctly_displayed(self): + """Regression test for bug #1669683. + + List and dict fields with unicode cannot be correctly + displayed. + + Ensure that once we fix this it doesn't regress. + """ + # create an instance with chinese tag + uuid = self._boot_server_with_tags(tags=["中文标签"]) + output = self.nova("show %s" % uuid) + self.assertEqual('["中文标签"]', self._get_value_from_the_table( + output, "tags")) + def test_list(self): uuid = self._boot_server_with_tags() output = self.nova("server-tag-list %s" % uuid) diff --git a/novaclient/utils.py b/novaclient/utils.py index 7486ab29..e93df699 100644 --- a/novaclient/utils.py +++ b/novaclient/utils.py @@ -246,7 +246,7 @@ def print_dict(d, dict_property="Property", dict_value="Value", wrap=0): for k, v in sorted(d.items()): # convert dict to str to check length if isinstance(v, (dict, list)): - v = jsonutils.dumps(v) + v = jsonutils.dumps(v, ensure_ascii=False) if wrap > 0: v = textwrap.fill(six.text_type(v), wrap) # if value has a newline, add in multiple rows |