本文整理汇总了Python中eliot.testing.LoggedMessage类的典型用法代码示例。如果您正苦于以下问题:Python LoggedMessage类的具体用法?Python LoggedMessage怎么用?Python LoggedMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LoggedMessage类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_boto_ec2response_error
def test_boto_ec2response_error(self, logger):
"""
1. Test that invalid parameters to Boto's EBS API calls
raise the right exception after logging to Eliot.
2. Verify Eliot log output for expected message fields
from logging decorator for boto.exception.EC2Exception
originating from boto.ec2.connection.EC2Connection.
"""
# Test 1: Create volume with size 0.
# Raises: EC2ResponseError
self.assertRaises(EC2ResponseError, self.api.create_volume,
dataset_id=uuid4(), size=0,)
# Test 2: Set EC2 connection zone to an invalid string.
# Raises: EC2ResponseError
self.api.zone = u'invalid_zone'
self.assertRaises(
EC2ResponseError,
self.api.create_volume,
dataset_id=uuid4(),
size=self.minimum_allocatable_size,
)
# Validate decorated method for exception logging
# actually logged to ``Eliot`` logger.
expected_message_keys = {AWS_CODE.key, AWS_MESSAGE.key,
AWS_REQUEST_ID.key}
for logged in LoggedMessage.of_type(logger.messages,
BOTO_EC2RESPONSE_ERROR,):
key_subset = set(key for key in expected_message_keys
if key in logged.message.keys())
self.assertEqual(expected_message_keys, key_subset)
示例2: test_iterates
def test_iterates(self, logger):
"""
If the predicate returns something falsey followed by something truthy,
then ``loop_until`` returns it immediately.
"""
result = object()
results = [None, result]
def predicate():
return results.pop(0)
clock = Clock()
d = loop_until(clock, predicate)
self.assertNoResult(d)
clock.advance(0.1)
self.assertEqual(
self.successResultOf(d),
result)
action = LoggedAction.of_type(logger.messages, LOOP_UNTIL_ACTION)[0]
assertContainsFields(self, action.start_message, {
'predicate': predicate,
})
assertContainsFields(self, action.end_message, {
'result': result,
})
self.assertTrue(action.succeeded)
message = LoggedMessage.of_type(
logger.messages, LOOP_UNTIL_ITERATION_MESSAGE)[0]
self.assertEqual(action.children, [message])
assertContainsFields(self, message.message, {
'result': None,
})
示例3: test_multiple_iterations
def test_multiple_iterations(self, logger):
"""
If the predicate returns something falsey followed by something truthy,
then ``loop_until`` returns it immediately.
"""
result = object()
results = [None, False, result]
expected_results = results[:-1]
def predicate():
return results.pop(0)
clock = Clock()
d = loop_until(clock, predicate)
clock.advance(0.1)
self.assertNoResult(d)
clock.advance(0.1)
self.assertEqual(self.successResultOf(d), result)
action = LoggedAction.of_type(logger.messages, LOOP_UNTIL_ACTION)[0]
assertContainsFields(self, action.start_message, {"predicate": predicate})
assertContainsFields(self, action.end_message, {"result": result})
self.assertTrue(action.succeeded)
messages = LoggedMessage.of_type(logger.messages, LOOP_UNTIL_ITERATION_MESSAGE)
self.assertEqual(action.children, messages)
self.assertEqual([messages[0].message["result"], messages[1].message["result"]], expected_results)
示例4: test_novaclient_exception
def test_novaclient_exception(self, logger):
"""
The details of ``novaclient.exceptions.ClientException`` are logged
when it is raised by the decorated method and the exception is still
raised.
"""
result = NovaClientException(
code=INTERNAL_SERVER_ERROR,
message="Some things went wrong with some other things.",
details={"key": "value"},
request_id="abcdefghijklmnopqrstuvwxyz",
url="/foo/bar",
method="POST",
)
logging_dummy = LoggingDummy(Dummy(result))
self.assertRaises(NovaClientException, logging_dummy.raise_method)
logged = LoggedMessage.of_type(
logger.messages, NOVA_CLIENT_EXCEPTION,
)[0]
assertContainsFields(
self, logged.message, {
u"code": result.code,
u"message": result.message,
u"details": result.details,
u"request_id": result.request_id,
u"url": result.url,
u"method": result.method,
},
)
示例5: test_keystone_client_exception
def test_keystone_client_exception(self, logger):
"""
``keystoneclient.openstack.common.apiclient.exceptions.BadRequest`` is
treated similarly to ``novaclient.exceptions.ClientException``.
See ``test_novaclient_exception``.
"""
response = Response()
response._content = "hello world"
result = KeystoneHttpError(
message="Some things went wrong with some other things.",
details={"key": "value"},
response=response,
request_id="abcdefghijklmnopqrstuvwxyz",
url="/foo/bar",
method="POST",
http_status=INTERNAL_SERVER_ERROR,
)
logging_dummy = LoggingDummy(Dummy(result))
self.assertRaises(KeystoneHttpError, logging_dummy.raise_method)
logged = LoggedMessage.of_type(
logger.messages, KEYSTONE_HTTP_ERROR,
)[0]
assertContainsFields(
self, logged.message, {
u"code": result.http_status,
u"message": result.message,
u"details": result.details,
u"request_id": result.request_id,
u"url": result.url,
u"method": result.method,
u"response": "hello world",
},
)
示例6: assert_logged_multiple_iterations
def assert_logged_multiple_iterations(self, logger):
"""
Function passed to ``retry_failure`` is run in the context of a
``LOOP_UNTIL_ACTION``.
"""
iterations = LoggedMessage.of_type(logger.messages, ITERATION_MESSAGE)
loop = assertHasAction(self, logger, LOOP_UNTIL_ACTION, True)
self.assertEqual(sorted(iterations, key=lambda m: m.message["iteration"]), loop.children)
示例7: error_status_logged
def error_status_logged(case, logger):
"""
Validate the error logging behavior of ``_sync_command_error_squashed``.
"""
assertHasMessage(case, logger, ZFS_ERROR, {
'status': 1,
'zfs_command': 'python -c raise SystemExit(1)',
'output': ''})
case.assertEqual(len(LoggedMessage.ofType(logger.messages, ZFS_ERROR)), 1)
示例8: no_such_executable_logged
def no_such_executable_logged(case, logger):
"""
Validate the error logging behavior of ``_sync_command_error_squashed``.
"""
assertHasMessage(case, logger, ZFS_ERROR, {
'status': 1,
'zfs_command': 'nonsense garbage made up no such command',
'output': '[Errno 2] No such file or directory'})
case.assertEqual(len(LoggedMessage.ofType(logger.messages, ZFS_ERROR)), 1)
示例9: assertOutputLogging
def assertOutputLogging(self, logger):
"""
The L{IOutputExecutor} is invoked in the FSM's transition action
context.
"""
loggedTransition = LoggedAction.ofType(
logger.messages, LOG_FSM_TRANSITION)[0]
loggedAnimal = LoggedMessage.ofType(logger.messages, LOG_ANIMAL)[0]
self.assertIn(loggedAnimal, loggedTransition.children)
示例10: test_volume_busy_error_on_busy_state
def test_volume_busy_error_on_busy_state(self, logger):
"""
A ``VolumeBusy`` is raised if a volume's attachment state is "busy"
when attempting to detach the volume. This can occur if an attempt
is made to detach a volume that has not been unmounted.
"""
try:
config = get_blockdevice_config()
except InvalidConfig as e:
self.skipTest(str(e))
# Create a volume
dataset_id = uuid4()
flocker_volume = self.api.create_volume(
dataset_id=dataset_id,
size=self.minimum_allocatable_size,
)
ec2_client = get_ec2_client_for_test(config)
# Attach the volume.
instance_id = self.api.compute_instance_id()
self.api.attach_volume(flocker_volume.blockdevice_id, instance_id)
volume = ec2_client.connection.Volume(flocker_volume.blockdevice_id)
def clean_volume(volume):
volume.detach_from_instance()
_wait_for_volume_state_change(VolumeOperations.DETACH, volume)
volume.delete()
self.addCleanup(clean_volume, volume)
# Artificially set the volume's attachment state to "busy", by
# monkey-patching the EBS driver's ``_get_ebs_volume`` method.
def busy_ebs_volume(volume_id):
busy_volume = ec2_client.connection.Volume(volume_id)
busy_volume.load()
if busy_volume.attachments:
busy_volume.attachments[0]['State'] = "busy"
return busy_volume
self.patch(self.api, "_get_ebs_volume", busy_ebs_volume)
# Try to detach and get the VolumeBusy exception.
self.assertRaises(
VolumeBusy, self.api.detach_volume, flocker_volume.blockdevice_id)
expected_keys = set(["volume_id", "attachments"])
messages = [
message.message for message
in LoggedMessage.of_type(logger.messages, VOLUME_BUSY_MESSAGE)
]
self.assertThat(messages, AllMatch(ContainsAll(expected_keys)))
示例11: error_status_logged
def error_status_logged(case, logger):
"""
Validate the error logging behavior of ``_sync_command_error_squashed``.
"""
errors = LoggedMessage.ofType(logger.messages, ZFS_ERROR)
assertContainsFields(
case, errors[0].message,
{'status': 1,
'zfs_command': 'python -c raise SystemExit(1)',
'output': '',
u'message_type': 'filesystem:zfs:error',
u'task_level': u'/'})
case.assertEqual(1, len(errors))
示例12: no_such_executable_logged
def no_such_executable_logged(case, logger):
"""
Validate the error logging behavior of ``_sync_command_error_squashed``.
"""
errors = LoggedMessage.ofType(logger.messages, ZFS_ERROR)
assertContainsFields(
case, errors[0].message,
{'status': 1,
'zfs_command': 'nonsense garbage made up no such command',
'output': '[Errno 2] No such file or directory',
u'message_type': 'filesystem:zfs:error',
u'task_level': u'/'})
case.assertEqual(1, len(errors))