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 0797115241)
This commit is contained in:
Kevin_Zheng 2017-03-03 14:54:11 +08:00 committed by Matt Riedemann
parent f6e0128f9a
commit 50e571c23d
2 changed files with 18 additions and 3 deletions

View File

@ -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)

View File

@ -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