From 1a826012387838cbf741242047c8c622f635cb73 Mon Sep 17 00:00:00 2001 From: Qin Zhao Date: Fri, 14 Nov 2014 23:17:22 +0800 Subject: [PATCH] Revert "Truncate encoded instance message to 255" This reverts commit bd9c32289ff8cf1bc67c1395ad921c703aa4c489. UTF-8 character bytes size varies from 1 to 6. If truncating a long bytes string to 255, the last character may be cut in the middle, so that UnicodeDecodeError will occur when converting it back to unicode. Need to revert this code change and make a new patch. Related-Bug: 1389102 Change-Id: Ie439cffe11d657e77397c9070a3923a61f68a678 --- nova/compute/utils.py | 3 +-- nova/tests/unit/compute/test_compute_utils.py | 11 ----------- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/nova/compute/utils.py b/nova/compute/utils.py index a446d41a3889..620742f96291 100644 --- a/nova/compute/utils.py +++ b/nova/compute/utils.py @@ -19,7 +19,6 @@ import string import traceback from oslo.config import cfg -from oslo.utils import encodeutils from nova import block_device from nova.compute import flavors @@ -65,7 +64,7 @@ def exception_to_dict(fault): # NOTE(dripton) The message field in the database is limited to 255 chars. # MySQL silently truncates overly long messages, but PostgreSQL throws an # error if we don't truncate it. - u_message = encodeutils.safe_decode(encodeutils.safe_encode(message)[:255]) + u_message = unicode(message)[:255] fault_dict = dict(exception=fault) fault_dict["message"] = u_message diff --git a/nova/tests/unit/compute/test_compute_utils.py b/nova/tests/unit/compute/test_compute_utils.py index af7f72e803fe..6234ae30f624 100644 --- a/nova/tests/unit/compute/test_compute_utils.py +++ b/nova/tests/unit/compute/test_compute_utils.py @@ -22,7 +22,6 @@ import string import mock from oslo.config import cfg from oslo.serialization import jsonutils -from oslo.utils import encodeutils from oslo.utils import importutils import six import testtools @@ -826,13 +825,3 @@ class ComputeUtilsGetRebootTypes(test.TestCase): def test_get_reboot_not_running_hard(self): reboot_type = compute_utils.get_reboot_type('foo', 'bar') self.assertEqual(reboot_type, 'HARD') - - -class ComputeUtilsTestCase(test.NoDBTestCase): - def test_exception_to_dict_with_long_message(self): - # Generate Russian byte message whose length is 300 - msg = encodeutils.safe_decode(' \xd0\xb2' * 100) - exc = exception.NovaException(message=msg) - fault_dict = compute_utils.exception_to_dict(exc) - byte_message = encodeutils.safe_encode(fault_dict["message"]) - self.assertEqual(255, len(byte_message))