Skip to content

Commit

Permalink
Merge branch 'master' into nine
Browse files Browse the repository at this point in the history
Conflicts:
	master/buildbot/status/logfile.py
	master/buildbot/status/web/logs.py
  • Loading branch information
djmitche committed Mar 14, 2014
2 parents 5138522 + 78dd5fd commit 026a406
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 38 deletions.
54 changes: 16 additions & 38 deletions master/buildbot/status/logfile.py
Expand Up @@ -16,6 +16,7 @@
import os

from bz2 import BZ2File
from cStringIO import StringIO
from gzip import GzipFile

from buildbot import interfaces
Expand Down Expand Up @@ -558,6 +559,7 @@ def finish(self):
for w in watchers:
w.callback(self)
self.watchers = []
return defer.succeed(None)

def compressLog(self):
logCompressionMethod = self.master.config.logCompressionMethod
Expand Down Expand Up @@ -630,51 +632,27 @@ def __setstate__(self, d):
self.finished = True


class HTMLLogFile:
filename = None
class HTMLLogFile(LogFile):

def __init__(self, parent, name, logfilename, html):
self.step = parent
self.name = name
self.filename = logfilename
self.html = html

def getName(self):
return self.name # set in BuildStepStatus.addLog

def old_getStep(self):
return self.step

def isFinished(self):
return True

def waitUntilFinished(self):
return defer.succeed(self)
LogFile.__init__(self, parent, name, logfilename)
self.addStderr(html)
self.finish()

def old_hasContents(self):
return True

def old_getText(self):
return self.html # looks kinda like text

def old_getChunks(self):
return [(STDERR, self.html)]

def subscribe(self, receiver, catchup):
pass

def unsubscribe(self, receiver):
pass

def finish(self):
pass
def __setstate__(self, d):
self.__dict__ = d
self.watchers = []
self.finishedWatchers = []
self.finished = True

def __getstate__(self):
d = self.__dict__.copy()
del d['step']
if "master" in d:
del d['master']
return d
# buildbot <= 0.8.8 stored all html logs in the html property
if 'html' in self.__dict__:
buf = "%d:%d%s," % (len(self.html) + 1, STDERR, self.html)
self.openfile = StringIO(buf)
del self.__dict__['html']


def _tryremove(filename, timeout, retries):
Expand Down
99 changes: 99 additions & 0 deletions master/buildbot/test/unit/test_status_logfile.py
Expand Up @@ -15,6 +15,7 @@

from __future__ import with_statement

import cPickle
import cStringIO
import mock
import os
Expand Down Expand Up @@ -311,3 +312,101 @@ def test_compressLog_bz2(self):
def test_compressLog_none(self):
self.config.logCompressionMethod = None
return self.do_test_compressLog('', expect_comp=False)


class TestHTMLLogFile(unittest.TestCase, dirs.DirsMixin):

# The following script was used to pickle an 0.8.8 logfile. It was then
# base64 encoded to be safely embedded in this test class.
#
# from buildbot.status import logfile
# import pickle
# lf = logfile.HTMLLogFile('error.html', '123-error_html', '<span>You lost the game</span>')
# with open('123-error_html', 'w') as f:
# pickle.dump(lf, f)
buildbot088pickle = '''
KGlidWlsZGJvdC5zdGF0dXMubG9nZmlsZQpIVE1MTG9nRmlsZQpwMAooZHAyClMnaHRtbCcKcD
MKUyc8c3Bhbj5Zb3UgbG9zdCB0aGUgZ2FtZTwvc3Bhbj4nCnA0CnNTJ25hbWUnCnA1ClMnZXJy
b3IuaHRtbCcKcDYKc1MnZmlsZW5hbWUnCnA3ClMnMTIzLWVycm9yX2h0bWwnCnA4CnNiLg==
'''

def setUp(self):
step = self.build_step_status = mock.Mock(name='build_step_status')
self.basedir = step.build.builder.basedir = os.path.abspath('basedir')
self.setUpDirs(self.basedir)
self.logfile = logfile.HTMLLogFile(step, 'error.html', '123-error_html', '<span>You lost the game</span>')
self.master = self.logfile.master = mock.Mock()
self.config = self.logfile.master.config = config.MasterConfig()

def tearDown(self):
if self.logfile.openfile:
try:
self.logfile.openfile.close()
except:
pass # oh well, we tried
self.tearDownDirs()

def pickle_and_restore(self):
pkl = cPickle.dumps(self.logfile)
self.logfile = cPickle.loads(pkl)
step = self.build_step_status
self.logfile.step = step
self.logfile.master = self.master
step.build.builder.basedir = self.basedir

def test_unpickle(self):
self.pickle_and_restore()

d = self.logfile.finish()

def check(_):
fn = os.path.join('basedir', '123-error_html')
self.assertTrue(os.path.exists(fn))
fp = open(fn, 'r')
self.assertEqual(fp.read(), '31:1<span>You lost the game</span>,')
fp.close()

d.addCallback(check)
return d

def test_unpickle_buildbot088pickle(self):
import base64
s = base64.b64decode(self.buildbot088pickle)
self.logfile = cPickle.loads(s)
step = self.build_step_status
self.logfile.step = step
self.logfile.master = self.master
step.build.builder.basedir = self.basedir

self.assertEqual(self.logfile.getName(), 'error.html')
self.assertEqual(self.logfile.old_getText(), '<span>You lost the game</span>')

def test_hasContents(self):
self.assertTrue(self.logfile.old_hasContents())

def test_getName(self):
self.assertEqual(self.logfile.getName(), 'error.html')

def test_getStep(self):
self.assertEqual(self.logfile.old_getStep(), self.build_step_status)

def test_isFinished(self):
self.assertTrue(self.logfile.isFinished())

def test_waitUntilFinished(self):
d = self.logfile.waitUntilFinished()
return d

def test_getText(self):
self.assertEqual(self.logfile.old_getText(), '<span>You lost the game</span>')

def test_getFile(self):
fp = self.logfile.getFile()
fp.seek(0, 0)
self.assertEqual(fp.read(), '31:1<span>You lost the game</span>,')

self.pickle_and_restore()

fp = self.logfile.getFile()
fp.seek(0, 0)
self.assertEqual(fp.read(), '31:1<span>You lost the game</span>,')

0 comments on commit 026a406

Please sign in to comment.