Skip to content

Commit

Permalink
Fix DebugClient's pbmanager factory
Browse files Browse the repository at this point in the history
Also: add some tests, remove non-working code

Fixes #1789
  • Loading branch information
djmitche committed Mar 15, 2011
1 parent c8d1ee6 commit 10ca099
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 43 deletions.
5 changes: 2 additions & 3 deletions master/buildbot/master.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,9 +596,8 @@ def loadConfig_DebugClient(self, debugPassword):
# and register the new one
def reg(_):
if debugPassword:
self.debugClientRegistration = self.pbmanager.register(
self.slavePortnum, "debug", debugPassword,
lambda : debug.makeDebugPerspective(self))
self.debugClientRegistration = debug.registerDebugClient(
self, self.slavePortnum, debugPassword, self.pmanager)
d.addCallback(reg)
return d

Expand Down
35 changes: 14 additions & 21 deletions master/buildbot/process/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
#
# Copyright Buildbot Team Members

from twisted.python import log
from buildbot.pbutil import NewCredPerspective
from buildbot import interfaces
from buildbot.process.properties import Properties
from buildbot.util import now

class DebugPerspective(NewCredPerspective):
def attached(self, mind):
Expand All @@ -38,22 +38,12 @@ def perspective_pingBuilder(self, buildername):
bc = c.getBuilder(buildername)
bc.ping()

def perspective_setCurrentState(self, buildername, state):
builder = self.botmaster.builders.get(buildername)
if not builder: return
if state == "offline":
builder.statusbag.currentlyOffline()
if state == "idle":
builder.statusbag.currentlyIdle()
if state == "waiting":
builder.statusbag.currentlyWaiting(now()+10)
if state == "building":
builder.statusbag.currentlyBuilding(None)
def perspective_reload(self):
print "doing reload of the config file"
log.msg("doing reload of the config file")
self.master.loadTheConfigFile()

def perspective_pokeIRC(self):
print "saying something on IRC"
log.msg("saying something on IRC")
from buildbot.status import words
for s in self.master:
if isinstance(s, words.IRC):
Expand All @@ -63,11 +53,14 @@ def perspective_pokeIRC(self):
bot.p.msg(channel, "Ow, quit it")

def perspective_print(self, msg):
print "debug", msg

def makeDebugPerspective(master):
persp = DebugPerspective()
persp.master = master
persp.botmaster = master
return persp
log.msg("debug %s" % msg)

def registerDebugClient(master, slavePortnum, debugPassword, pbmanager):
def perspFactory(master, mind, username):
persp = DebugPerspective()
persp.master = master
persp.botmaster = master
return persp
return pbmanager.register(
slavePortnum, "debug", debugPassword,
lambda mind, username : perspFactory(master, mind, username))
19 changes: 0 additions & 19 deletions master/buildbot/status/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2096,24 +2096,6 @@ def _buildFinished(self, s):
# pushed to the clients.

# publish to clients
def sendLastBuildStatus(self, client):
#client.newLastBuildStatus(self.lastBuildStatus)
pass
def sendCurrentActivityBigToEveryone(self):
for s in self.subscribers:
self.sendCurrentActivityBig(s)
def sendCurrentActivityBig(self, client):
state = self.currentBigState
if state == "offline":
client.currentlyOffline()
elif state == "idle":
client.currentlyIdle()
elif state == "building":
client.currentlyBuilding()
else:
log.msg("Hey, self.currentBigState is weird:", state)


## HTML display interface

def getEventNumbered(self, num):
Expand Down Expand Up @@ -2156,7 +2138,6 @@ def saveYourOldEvents(self):
def addClient(self, client):
if client not in self.subscribers:
self.subscribers.append(client)
self.sendLastBuildStatus(client)
self.sendCurrentActivityBig(client)
client.newEvent(self.currentSmall)
def removeClient(self, client):
Expand Down
65 changes: 65 additions & 0 deletions master/buildbot/test/unit/test_process_debug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# This file is part of Buildbot. Buildbot is free software: you can
# redistribute it and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation, version 2.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright Buildbot Team Members

import mock
from twisted.trial import unittest
from twisted.internet import defer
from buildbot.process import debug

class TestRegisterDebugClient(unittest.TestCase):

def test_registerDebugClient(self):
pbmanager = mock.Mock()
pbmanager.register.return_value = mock.Mock()
master = mock.Mock()
slavePortnum = 9824
debugPassword = 'seeeekrt'

rv = debug.registerDebugClient(master, slavePortnum,
debugPassword, pbmanager)

# test return value and that the register method was called
self.assertIdentical(rv, pbmanager.register.return_value)
self.assertEqual(pbmanager.register.call_args[0][0], slavePortnum)
self.assertEqual(pbmanager.register.call_args[0][1], "debug")
self.assertEqual(pbmanager.register.call_args[0][2], debugPassword)

# test the lambda
mind = mock.Mock()
username = "hush"
dc = pbmanager.register.call_args[0][3](mind, username)
self.assertIsInstance(dc, debug.DebugPerspective)

class TestDebugPerspective(unittest.TestCase):

def setUp(self):
self.persp = debug.DebugPerspective()
self.master = self.persp.master = mock.Mock()
self.botmaster = self.persp.botmaster = mock.Mock()

def test_attached(self):
self.assertIdentical(self.persp.attached(mock.Mock()), self.persp)

def test_detached(self):
self.persp.detached(mock.Mock()) # just shouldn't crash

def test_perspective_reload(self):
d = defer.maybeDeferred(lambda : self.persp.perspective_reload())
def check(_):
self.master.loadTheConfigFile.assert_called_with()
d.addCallback(check)
return d

# remaining methods require IControl adapters or other weird stuff.. TODO

0 comments on commit 10ca099

Please sign in to comment.