Revert "Truncate encoded instance message to 255"

This reverts commit bd9c32289f.

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
This commit is contained in:
Qin Zhao 2014-11-14 23:17:22 +08:00
parent c54039c507
commit 1a82601238
2 changed files with 1 additions and 13 deletions

View File

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

View File

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