diff options
author | Daniel Watkins <oddbloke@ubuntu.com> | 2020-05-06 13:17:37 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-06 13:17:37 -0400 |
commit | 73d8748e797134fa0a06415b6cb16be2e05abc7e (patch) | |
tree | 3f92d81cfa44f84923628c502a1dfd7fbe9c04f0 /cloudinit/analyze/tests | |
parent | f9b393bb4f15258de230884949e543e0f62f9abb (diff) | |
download | vyos-cloud-init-73d8748e797134fa0a06415b6cb16be2e05abc7e.tar.gz vyos-cloud-init-73d8748e797134fa0a06415b6cb16be2e05abc7e.zip |
analyze/dump: add support for Amazon Linux 2 log lines (#346)
Amazon Linux 2 is configured with a log format different to the one
shipped by upstream, which means analyze fails to parse any of the log
lines. This updates the code to know how to parse such lines.
LP: #1876323
Diffstat (limited to 'cloudinit/analyze/tests')
-rw-r--r-- | cloudinit/analyze/tests/test_dump.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/cloudinit/analyze/tests/test_dump.py b/cloudinit/analyze/tests/test_dump.py index db2a667b..d6fbd381 100644 --- a/cloudinit/analyze/tests/test_dump.py +++ b/cloudinit/analyze/tests/test_dump.py @@ -119,6 +119,23 @@ class TestParseCILogLine(CiTestCase): 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]:\ |