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))
def pack_action_event_finish(context, instance_uuid, event_name, exc_val=None, exc_tb=None): values = { 'event': event_name, 'instance_uuid': instance_uuid, 'request_id': context.request_id, 'finish_time': timeutils.utcnow() } if exc_tb is None: values['result'] = 'Success' else: values['result'] = 'Error' # Store the details using the same logic as storing an instance # fault message. if exc_val: # If we got a string for exc_val it's probably because of # the serialize_args decorator on event_finish_with_failure # so pass that as the message to exception_to_dict otherwise # the details will just the exception class name since it # cannot format the message as a NovaException. message = exc_val if isinstance(exc_val, str) else None values['details'] = compute_utils.exception_to_dict( exc_val, message=message)['message'] values['traceback'] = exc_tb return values
def test_exception_to_dict_with_long_message_2_bytes(self): # Generate Russian byte string whose length is 300. This Russian UTF-8 # character occupies 2 bytes. After truncating, the byte string length # should be 254. msg = encodeutils.safe_decode('\xd0\x92' * 150) exc = exception.NovaException(message=msg) fault_dict = compute_utils.exception_to_dict(exc) byte_message = encodeutils.safe_encode(fault_dict["message"]) self.assertEqual(254, len(byte_message))
def test_exception_to_dict_with_long_message_3_bytes(self): # Generate Chinese byte string whose length is 300. This Chinese UTF-8 # character occupies 3 bytes. After truncating, the byte string length # should be 255. msg = encodeutils.safe_decode('\xe8\xb5\xb5' * 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))