Merge lp:~raharper/curtin/trunk.fix-missing-install-log into lp:~curtin-dev/curtin/trunk

Proposed by Ryan Harper
Status: Merged
Merged at revision: 392
Proposed branch: lp:~raharper/curtin/trunk.fix-missing-install-log
Merge into: lp:~curtin-dev/curtin/trunk
Diff against target: 96 lines (+27/-15)
2 files modified
curtin/reporter/handlers.py (+4/-13)
tests/unittests/test_reporter.py (+23/-2)
To merge this branch: bzr merge lp:~raharper/curtin/trunk.fix-missing-install-log
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Approve
curtin developers Pending
Review via email: mp+297340@code.launchpad.net

Commit message

reporting: default webhook handler level to DEBUG, no filtering

The webhook handler in curtin reporting included a default level
of INFO and included a event filter which would not report events
that were of lower importance than what was set. The result was
for unconfigured WebHook handlers, some of the expected messages
including post_files used by maas to collect the curtin install
log were no longer sent.

This patch sets WebHookHandler level to DEBUG, the same level set for
LogHandler and PrintHandler, further we remove the event filtering.
The events themselves include the level value and the event collector
can apply their own filtering as needed. Along with the changes we
clean up some comments and include a new unittest which specifically
tests that a FinishReportingEvent with post_files is posted by the
WebHookHandler.

To post a comment you must log in.
391. By Ryan Harper

merge from trunk

Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Scott Moser (smoser) wrote :

I think this is fine. there is some cleanup to do there, where we'd like to avoid passing strings around explicitly (rather than level.DEBUG), but this is fine and will un-break some things.

feel free to do more if you want.

Revision history for this message
Ryan Harper (raharper) wrote :

vmtest passed on diglett, merging to trunk.

----------------------------------------------------------------------
Ran 610 tests in 9712.856s

OK
Tue, 14 Jun 2016 17:15:22 -0500: vmtest end [0] in 9713s

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'curtin/reporter/handlers.py'
2--- curtin/reporter/handlers.py 2016-04-04 19:09:47 +0000
3+++ curtin/reporter/handlers.py 2016-06-14 14:07:09 +0000
4@@ -23,7 +23,7 @@
5
6
7 class LogHandler(ReportingHandler):
8- """Publishes events to the cloud-init log at the ``INFO`` log level."""
9+ """Publishes events to the curtin log at the ``DEBUG`` log level."""
10
11 def __init__(self, level="DEBUG"):
12 super(LogHandler, self).__init__()
13@@ -39,9 +39,9 @@
14 self.level = level
15
16 def publish_event(self, event):
17- """Publish an event to the ``INFO`` log level."""
18+ """Publish an event to the ``DEBUG`` log level."""
19 logger = logging.getLogger(
20- '.'.join(['cloudinit', 'reporting', event.event_type, event.name]))
21+ '.'.join(['curtin', 'reporting', event.event_type, event.name]))
22 logger.log(self.level, event.as_string())
23
24
25@@ -55,7 +55,7 @@
26 class WebHookHandler(ReportingHandler):
27 def __init__(self, endpoint, consumer_key=None, token_key=None,
28 token_secret=None, consumer_secret=None, timeout=None,
29- retries=None, level="INFO"):
30+ retries=None, level="DEBUG"):
31 super(WebHookHandler, self).__init__()
32
33 self.oauth_helper = url_helper.OauthUrlHelper(
34@@ -72,15 +72,6 @@
35 self.headers = {'Content-Type': 'application/json'}
36
37 def publish_event(self, event):
38- if isinstance(event.level, int):
39- ev_level = event.level
40- else:
41- try:
42- ev_level = getattr(logging, event.level.upper())
43- except:
44- ev_level = logging.INFO
45- if ev_level < self.level:
46- return
47 try:
48 return self.oauth_helper.geturl(
49 url=self.endpoint, data=event.as_dict(),
50
51=== modified file 'tests/unittests/test_reporter.py'
52--- tests/unittests/test_reporter.py 2016-04-04 19:09:47 +0000
53+++ tests/unittests/test_reporter.py 2016-06-14 14:07:09 +0000
54@@ -128,7 +128,8 @@
55 def test_webhook_handler(self, mock_url_helper):
56 event = events.ReportingEvent(events.START_EVENT_TYPE, 'test_event',
57 'test event', level='INFO')
58- webhook_handler = handlers.WebHookHandler('127.0.0.1:8000')
59+ webhook_handler = handlers.WebHookHandler('127.0.0.1:8000',
60+ level='INFO')
61 webhook_handler.publish_event(event)
62 webhook_handler.oauth_helper.geturl.assert_called_with(
63 url='127.0.0.1:8000', data=event.as_dict(),
64@@ -136,7 +137,6 @@
65 event.level = 'DEBUG'
66 webhook_handler.oauth_helper.geturl.called = False
67 webhook_handler.publish_event(event)
68- self.assertFalse(webhook_handler.oauth_helper.geturl.called)
69 webhook_handler = handlers.WebHookHandler('127.0.0.1:8000',
70 level="INVALID")
71 self.assertEquals(webhook_handler.level, 30)
72@@ -194,3 +194,24 @@
73 base64.b64encode(test_data).decode())
74 finally:
75 os.remove(tmp[1])
76+
77+ @patch('curtin.url_helper.OauthUrlHelper')
78+ def test_webhook_handler_post_files(self, mock_url_helper):
79+ test_data = b'abcdefg'
80+ tmp = tempfile.mkstemp()
81+ tmpfname = tmp[1]
82+ try:
83+ with open(tmpfname, 'wb') as fp:
84+ fp.write(test_data)
85+ event = events.FinishReportingEvent('test_event_name',
86+ 'test event description',
87+ post_files=[tmpfname],
88+ level='INFO')
89+ webhook_handler = handlers.WebHookHandler('127.0.0.1:8000',
90+ level='INFO')
91+ webhook_handler.publish_event(event)
92+ webhook_handler.oauth_helper.geturl.assert_called_with(
93+ url='127.0.0.1:8000', data=event.as_dict(),
94+ headers=webhook_handler.headers, retries=None)
95+ finally:
96+ os.remove(tmpfname)

Subscribers

People subscribed via source and target branches