Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions cloudinit/analyze/dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,11 @@ def parse_ci_logline(line):
#
# 2017-05-22 18:02:01,088 - util.py[DEBUG]: Cloud-init v. 0.7.9 running \
# 'init-local' at Mon, 22 May 2017 18:02:01 +0000. Up 2.0 seconds.
#
# Apr 30 19:39:11 cloud-init[2673]: handlers.py[DEBUG]: start: \
# init-local/check-cache: attempting to read from cache [check]

separators = [' - ', ' [CLOUDINIT] ']
separators = [' - ', ' [CLOUDINIT] ', ' cloud-init[']
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it's worth naming these separators ?

SEP1 = ' - '
SEP2 = ' [CLOUDINIT] ',
SEP3 = ' cloud-init['
separators = [SEP1, SEP2, SEP3]

and then the if sep == SEP3

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, good thinking, I'll submit that as a follow-up.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Submitted as #350.

found = False
for sep in separators:
if sep in line:
Expand All @@ -98,7 +101,14 @@ def parse_ci_logline(line):
hostname = extra.split()[-1]
else:
hostname = timehost.split()[-1]
timestampstr = timehost.split(hostname)[0].strip()
if sep == ' cloud-init[':
# This is an Amazon Linux style line, with no hostname and a PID.
# Use the whole of timehost as timestampstr, and strip off the PID
# from the start of eventstr.
timestampstr = timehost.strip()
eventstr = eventstr.split(maxsplit=1)[1]
else:
timestampstr = timehost.split(hostname)[0].strip()
if 'Cloud-init v.' in eventstr:
event_type = 'start'
if 'running' in eventstr:
Expand Down
17 changes: 17 additions & 0 deletions cloudinit/analyze/tests/test_dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,23 @@ def test_parse_logline_returns_event_for_finish_events(self,
m_parse_from_date.assert_has_calls(
[mock.call("2016-08-30 21:53:25.972325+00:00")])

def test_parse_logline_returns_event_for_amazon_linux_2_line(self):
line = (
"Apr 30 19:39:11 cloud-init[2673]: handlers.py[DEBUG]: start:"
" init-local/check-cache: attempting to read from cache [check]")
# Generate the expected value using `datetime`, so that TZ
# determination is consistent with the code under test.
timestamp_dt = datetime.strptime(
"Apr 30 19:39:11", "%b %d %H:%M:%S"
).replace(year=datetime.now().year)
expected = {
'description': 'attempting to read from cache [check]',
'event_type': 'start',
'name': 'init-local/check-cache',
'origin': 'cloudinit',
'timestamp': timestamp_dt.timestamp()}
self.assertEqual(expected, parse_ci_logline(line))


SAMPLE_LOGS = dedent("""\
Nov 03 06:51:06.074410 x2 cloud-init[106]: [CLOUDINIT] util.py[DEBUG]:\
Expand Down