def test_dump_events_with_cisource(self): """Cisource file is read and parsed into a tuple of events and data.""" tmpfile = self.tmp_path('logfile') write_file(tmpfile, SAMPLE_LOGS) events, data = dump_events(cisource=open(tmpfile)) year = datetime.now().year dt1 = datetime.strptime('Nov 03 06:51:06.074410 %d' % year, '%b %d %H:%M:%S.%f %Y') timestamp1 = float(dt1.strftime('%s.%f')) expected_events = [{ 'description': 'starting search for local datasources', 'event_type': 'start', 'name': 'init-local', 'origin': 'cloudinit', 'timestamp': timestamp1 }, { 'description': 'running modules for final', 'event_type': 'finish', 'name': 'modules-final', 'origin': 'cloudinit', 'result': 'SUCCESS', 'timestamp': 1472594005.972 }] self.assertEqual(expected_events, events) self.assertEqual(SAMPLE_LOGS.splitlines(), [d.strip() for d in data])
def test_dump_events_with_rawdata(self, m_parse_from_date): """Rawdata is split and parsed into a tuple of events and data""" m_parse_from_date.return_value = "1472594005.972" events, data = dump_events(rawdata=SAMPLE_LOGS) expected_data = SAMPLE_LOGS.splitlines() self.assertEqual([mock.call("2016-08-30 21:53:25.972325+00:00")], m_parse_from_date.call_args_list) self.assertEqual(expected_data, data) year = datetime.now().year dt1 = datetime.strptime('Nov 03 06:51:06.074410 %d' % year, '%b %d %H:%M:%S.%f %Y') timestamp1 = float(dt1.strftime('%s.%f')) expected_events = [{ 'description': 'starting search for local datasources', 'event_type': 'start', 'name': 'init-local', 'origin': 'cloudinit', 'timestamp': timestamp1 }, { 'description': 'running modules for final', 'event_type': 'finish', 'name': 'modules-final', 'origin': 'cloudinit', 'result': 'SUCCESS', 'timestamp': 1472594005.972 }] self.assertEqual(expected_events, events)
def test_dump_events_with_cisource(self, m_parse_from_date): """Cisource file is read and parsed into a tuple of events and data.""" tmpfile = self.tmp_path("logfile") write_file(tmpfile, SAMPLE_LOGS) m_parse_from_date.return_value = 1472594005.972 events, data = dump_events(cisource=open(tmpfile)) year = datetime.now().year dt1 = datetime.strptime("Nov 03 06:51:06.074410 %d" % year, "%b %d %H:%M:%S.%f %Y") timestamp1 = float(dt1.strftime("%s.%f")) expected_events = [ { "description": "starting search for local datasources", "event_type": "start", "name": "init-local", "origin": "cloudinit", "timestamp": timestamp1, }, { "description": "running modules for final", "event_type": "finish", "name": "modules-final", "origin": "cloudinit", "result": "SUCCESS", "timestamp": 1472594005.972, }, ] self.assertEqual(expected_events, events) self.assertEqual(SAMPLE_LOGS.splitlines(), [d.strip() for d in data]) m_parse_from_date.assert_has_calls( [mock.call("2016-08-30 21:53:25.972325+00:00")])
def test_dump_events_with_rawdata(self, m_parse_from_date): """Rawdata is split and parsed into a tuple of events and data""" m_parse_from_date.return_value = "1472594005.972" events, data = dump_events(rawdata=SAMPLE_LOGS) expected_data = SAMPLE_LOGS.splitlines() self.assertEqual( [mock.call("2016-08-30 21:53:25.972325+00:00")], m_parse_from_date.call_args_list, ) self.assertEqual(expected_data, data) year = datetime.now().year dt1 = datetime.strptime("Nov 03 06:51:06.074410 %d" % year, "%b %d %H:%M:%S.%f %Y") timestamp1 = float(dt1.strftime("%s.%f")) expected_events = [ { "description": "starting search for local datasources", "event_type": "start", "name": "init-local", "origin": "cloudinit", "timestamp": timestamp1, }, { "description": "running modules for final", "event_type": "finish", "name": "modules-final", "origin": "cloudinit", "result": "SUCCESS", "timestamp": 1472594005.972, }, ] self.assertEqual(expected_events, events)
def test_dump_events_with_cisource(self, m_parse_from_date): """Cisource file is read and parsed into a tuple of events and data.""" tmpfile = self.tmp_path('logfile') write_file(tmpfile, SAMPLE_LOGS) m_parse_from_date.return_value = 1472594005.972 events, data = dump_events(cisource=open(tmpfile)) year = datetime.now().year dt1 = datetime.strptime( 'Nov 03 06:51:06.074410 %d' % year, '%b %d %H:%M:%S.%f %Y') timestamp1 = float(dt1.strftime('%s.%f')) expected_events = [{ 'description': 'starting search for local datasources', 'event_type': 'start', 'name': 'init-local', 'origin': 'cloudinit', 'timestamp': timestamp1}, { 'description': 'running modules for final', 'event_type': 'finish', 'name': 'modules-final', 'origin': 'cloudinit', 'result': 'SUCCESS', 'timestamp': 1472594005.972}] self.assertEqual(expected_events, events) self.assertEqual(SAMPLE_LOGS.splitlines(), [d.strip() for d in data]) m_parse_from_date.assert_has_calls( [mock.call("2016-08-30 21:53:25.972325+00:00")])
def test_dump_events_with_rawdata(self, m_parse_from_date): """Rawdata is split and parsed into a tuple of events and data""" m_parse_from_date.return_value = "1472594005.972" events, data = dump_events(rawdata=SAMPLE_LOGS) expected_data = SAMPLE_LOGS.splitlines() self.assertEqual( [mock.call("2016-08-30 21:53:25.972325+00:00")], m_parse_from_date.call_args_list) self.assertEqual(expected_data, data) year = datetime.now().year dt1 = datetime.strptime( 'Nov 03 06:51:06.074410 %d' % year, '%b %d %H:%M:%S.%f %Y') timestamp1 = float(dt1.strftime('%s.%f')) expected_events = [{ 'description': 'starting search for local datasources', 'event_type': 'start', 'name': 'init-local', 'origin': 'cloudinit', 'timestamp': timestamp1}, { 'description': 'running modules for final', 'event_type': 'finish', 'name': 'modules-final', 'origin': 'cloudinit', 'result': 'SUCCESS', 'timestamp': 1472594005.972}] self.assertEqual(expected_events, events)