def test_map_log(self): """Map log as returned by SQL query to elasticsearch style output.""" sql_log = EventResult( timestamp='2017-05-22T00:00Z', reported_timestamp='2016-12-09T00:00Z', deployment_id='<deployment_id>', execution_id='<execution_id>', workflow_id='<workflow_id>', message='<message>', message_code=None, event_type=None, operation='<operation>', node_id='<node_id>', node_instance_id='<node_instance_id>', node_name='<node_name>', level='<level>', logger='<logger>', type='cloudify_log', ) expected_es_log = { 'context': { 'deployment_id': '<deployment_id>', 'execution_id': '<execution_id>', 'workflow_id': '<workflow_id>', 'operation': '<operation>', 'node_id': '<node_id>', 'node_name': '<node_name>', }, 'level': '<level>', 'timestamp': '2017-05-22T00:00Z', '@timestamp': '2017-05-22T00:00Z', 'message': { 'text': '<message>' }, 'message_code': None, 'type': 'cloudify_log', 'logger': '<logger>', } es_log = EventsV1._map_event_to_dict(None, sql_log) self.assertDictEqual(es_log, expected_es_log)
def test_map_event(self): """Map event as returned by SQL query to elasticsearch style output.""" sql_event = EventResult( timestamp='2016-12-09T00:00Z', deployment_id='<deployment_id>', execution_id='<execution_id>', workflow_id='<workflow_id>', message='<message>', message_code=None, event_type='<event_type>', operation='<operation>', node_id='<node_id>', node_instance_id='<node_instance_id>', node_name='<node_name>', logger=None, level=None, type='cloudify_event', ) expected_es_event = { 'context': { 'deployment_id': '<deployment_id>', 'execution_id': '<execution_id>', 'workflow_id': '<workflow_id>', 'operation': '<operation>', 'node_id': '<node_id>', 'node_name': '<node_name>', }, 'event_type': '<event_type>', 'timestamp': '2016-12-09T00:00Z', '@timestamp': '2016-12-09T00:00Z', 'message': { 'arguments': None, 'text': '<message>', }, 'message_code': None, 'type': 'cloudify_event', } es_event = EventsV1._map_event_to_dict(None, sql_event) self.assertDictEqual(es_event, expected_es_event)