Merge lp:~cjwatson/launchpad/remove-nul-from-logtail into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18978
Proposed branch: lp:~cjwatson/launchpad/remove-nul-from-logtail
Merge into: lp:launchpad
Diff against target: 68 lines (+34/-2)
2 files modified
lib/lp/buildmaster/model/buildqueue.py (+5/-1)
lib/lp/buildmaster/tests/test_manager.py (+29/-1)
To merge this branch: bzr merge lp:~cjwatson/launchpad/remove-nul-from-logtail
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+368308@code.launchpad.net

Commit message

Filter ASCII NUL characters out of build logtails.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/buildmaster/model/buildqueue.py'
--- lib/lp/buildmaster/model/buildqueue.py 2017-04-27 15:54:54 +0000
+++ lib/lp/buildmaster/model/buildqueue.py 2019-06-04 08:41:47 +0000
@@ -1,4 +1,4 @@
1# Copyright 2009-2017 Canonical Ltd. This software is licensed under the1# Copyright 2009-2019 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4__metaclass__ = type4__metaclass__ = type
@@ -192,6 +192,10 @@
192 # it into Unicode as best we can.192 # it into Unicode as best we can.
193 self.logtail = str(193 self.logtail = str(
194 slave_status.get("logtail")).decode("UTF-8", errors="replace")194 slave_status.get("logtail")).decode("UTF-8", errors="replace")
195 # PostgreSQL text columns can't contain \0 characters, and since
196 # we only use this for web UI display purposes there's no point
197 # in going through contortions to store them.
198 self.logtail = self.logtail.replace("\0", "")
195199
196 def suspend(self):200 def suspend(self):
197 """See `IBuildQueue`."""201 """See `IBuildQueue`."""
198202
=== modified file 'lib/lp/buildmaster/tests/test_manager.py'
--- lib/lp/buildmaster/tests/test_manager.py 2018-06-06 08:47:46 +0000
+++ lib/lp/buildmaster/tests/test_manager.py 2019-06-04 08:41:47 +0000
@@ -2,7 +2,7 @@
2# NOTE: The first line above must stay first; do not move the copyright2# NOTE: The first line above must stay first; do not move the copyright
3# notice to the top. See http://www.python.org/dev/peps/pep-0263/.3# notice to the top. See http://www.python.org/dev/peps/pep-0263/.
4#4#
5# Copyright 2009-2018 Canonical Ltd. This software is licensed under the5# Copyright 2009-2019 Canonical Ltd. This software is licensed under the
6# GNU Affero General Public License version 3 (see the file LICENSE).6# GNU Affero General Public License version 3 (see the file LICENSE).
77
8"""Tests for the renovated slave scanner aka BuilddManager."""8"""Tests for the renovated slave scanner aka BuilddManager."""
@@ -347,6 +347,34 @@
347 d.addCallback(347 d.addCallback(
348 self._checkJobUpdated, builder, job, logtail=u"\uFFFD\uFFFD──")348 self._checkJobUpdated, builder, job, logtail=u"\uFFFD\uFFFD──")
349349
350 def test_scan_of_logtail_containing_nul(self):
351 # PostgreSQL text columns can't store ASCII NUL (\0) characters, so
352 # we make sure to filter those out of the logtail.
353 class NULSlave(BuildingSlave):
354 @defer.inlineCallbacks
355 def status(self):
356 status = yield super(NULSlave, self).status()
357 status["logtail"] = xmlrpclib.Binary(b"foo\0bar\0baz")
358 defer.returnValue(status)
359
360 builder = getUtility(IBuilderSet)[BOB_THE_BUILDER_NAME]
361 login('foo.bar@canonical.com')
362 builder.builderok = True
363 self.patch(
364 BuilderSlave, 'makeBuilderSlave',
365 FakeMethod(NULSlave(build_id='PACKAGEBUILD-8')))
366 transaction.commit()
367 login(ANONYMOUS)
368
369 job = builder.currentjob
370 self.assertBuildingJob(job, builder)
371
372 switch_dbuser(config.builddmaster.dbuser)
373 scanner = self._getScanner()
374 d = defer.maybeDeferred(scanner.scan)
375 d.addCallback(
376 self._checkJobUpdated, builder, job, logtail=u"foobarbaz")
377
350 @defer.inlineCallbacks378 @defer.inlineCallbacks
351 def test_scan_calls_builder_factory_prescanUpdate(self):379 def test_scan_calls_builder_factory_prescanUpdate(self):
352 # SlaveScanner.scan() starts by calling380 # SlaveScanner.scan() starts by calling