Skip to content

Commit

Permalink
Integration tests for custom buildsteps
Browse files Browse the repository at this point in the history
This includes updates to fakes and interface tests for them
  • Loading branch information
djmitche committed Dec 4, 2013
1 parent 3ffd18b commit 9d91398
Show file tree
Hide file tree
Showing 15 changed files with 592 additions and 101 deletions.
4 changes: 2 additions & 2 deletions master/buildbot/buildslave/base.py
Expand Up @@ -366,7 +366,7 @@ def attached(self, conn):
log.msg("bot attached")
self.messageReceivedFromSlave()
self.stopMissingTimer()
self.botmaster.master.status.slaveConnected(self.slavename)
self.master.status.slaveConnected(self.slavename)
yield self.updateSlave()
yield self.botmaster.maybeStartBuildsForSlave(self.slavename)

Expand All @@ -382,7 +382,7 @@ def detached(self):
self.slave_status.removeGracefulWatcher(self._gracefulChanged)
self.slave_status.setConnected(False)
log.msg("BuildSlave.detached(%s)" % self.slavename)
self.botmaster.master.status.slaveDisconnected(self.slavename)
self.master.status.slaveDisconnected(self.slavename)
self.releaseLocks()

def disconnect(self):
Expand Down
2 changes: 1 addition & 1 deletion master/buildbot/process/build.py
Expand Up @@ -173,7 +173,7 @@ def setupProperties(self):
props.build = self

# start with global properties from the configuration
master = self.builder.botmaster.master
master = self.builder.master
props.updateFromProperties(master.config.properties)

# from the SourceStamps, which have properties via Change
Expand Down
6 changes: 4 additions & 2 deletions master/buildbot/process/builder.py
Expand Up @@ -414,7 +414,7 @@ def run_cleanups():
bid, number = yield self.master.db.builds.addBuild(
builderid=builderid, buildrequestid=req.id,
buildslaveid=buildslaveid, masterid=self.master.masterid,
state_strings=['created'])
state_strings=[u'created'])
bids.append(bid)
except:
log.err(failure.Failure(), 'while adding rows to build table:')
Expand Down Expand Up @@ -520,7 +520,9 @@ def _notify_completions(self, requests, results, complete_at_epoch):
builderid=builderid,
complete_at=complete_at_epoch,
results=results)
self.master.mq.produce(key, msg)
# TODO: when buildrequests are defined in the data API
(key, msg)
#self.master.mq.produce(key, msg)

# check for completed buildsets -- one call for each build request with
# a unique bsid
Expand Down
9 changes: 5 additions & 4 deletions master/buildbot/process/buildstep.py
Expand Up @@ -141,6 +141,7 @@ class BuildStep(object, properties.PropertiesMixin):
progressMetrics = () # 'time' is implicit
useProgress = True # set to False if step is really unpredictable
build = None
buildslave = None
step_status = None
progress = None

Expand Down Expand Up @@ -461,10 +462,10 @@ def _connectPendingLogObservers(self):
def addURL(self, name, url):
self.step_status.addURL(name, url)

def runCommand(self, c):
self.cmd = c
c.buildslave = self.buildslave
d = c.run(self, self.remote, self.build.builder.name)
def runCommand(self, command):
self.cmd = command
command.buildslave = self.buildslave
d = command.run(self, self.remote, self.build.builder.name)
return d

components.registerAdapter(
Expand Down
1 change: 1 addition & 0 deletions master/buildbot/test/fake/fakedb.py
Expand Up @@ -1529,6 +1529,7 @@ def completeBuildRequests(self, brids, results, complete_at=None,
self.reqs[brid].complete = 1
self.reqs[brid].results = results
self.reqs[brid].complete_at = complete_at
return defer.succeed(None)

def unclaimExpiredRequests(self, old, _reactor=reactor):
old_epoch = _reactor.seconds() - old
Expand Down
35 changes: 33 additions & 2 deletions master/buildbot/test/fake/fakemaster.py
Expand Up @@ -14,16 +14,20 @@
# Copyright Buildbot Team Members

import mock
import os.path
import weakref

from buildbot import config
from buildbot import interfaces
from buildbot.status import build
from buildbot.test.fake import bslavemanager
from buildbot.test.fake import fakedata
from buildbot.test.fake import fakedb
from buildbot.test.fake import fakemq
from buildbot.test.fake import pbmanager
from buildbot.test.fake.botmaster import FakeBotMaster
from twisted.internet import defer
from zope.interface import implements


class FakeCache(object):
Expand Down Expand Up @@ -54,8 +58,14 @@ def get_cache(self, name, miss_fn):

class FakeStatus(object):

def __init__(self, master):
self.master = master
self.lastBuilderStatus = None

def builderAdded(self, name, basedir, category=None, description=None):
return FakeBuilderStatus()
bs = FakeBuilderStatus(self.master)
self.lastBuilderStatus = bs
return bs

def getBuilderNames(self):
return []
Expand All @@ -66,9 +76,19 @@ def getSlaveNames(self):
def slaveConnected(self, name):
pass

def build_started(self, brid, buildername, build_status):
pass


class FakeBuilderStatus(object):

implements(interfaces.IBuilderStatus)

def __init__(self, master):
self.master = master
self.basedir = os.path.join(master.basedir, 'bldr')
self.lastBuildStatus = None

def setDescription(self, description):
self._description = description

Expand All @@ -90,6 +110,17 @@ def setCacheSize(self, size):
def setBigState(self, state):
pass

def newBuild(self):
bld = build.BuildStatus(self, self.master, 3)
self.lastBuildStatus = bld
return bld

def buildStarted(self, builderStatus):
pass

def addPointEvent(self, text):
pass


class FakeMaster(object):

Expand All @@ -108,7 +139,7 @@ def __init__(self, master_id=fakedb.FakeBuildRequestsComponent.MASTER_ID):
self.basedir = 'basedir'
self.botmaster = FakeBotMaster(master=self)
self.botmaster.parent = self
self.status = FakeStatus()
self.status = FakeStatus(self)
self.status.master = self
self.name = 'fake:/master'
self.masterid = master_id
Expand Down
7 changes: 6 additions & 1 deletion master/buildbot/test/fake/fakeprotocol.py
Expand Up @@ -26,7 +26,12 @@ def __init__(self, master, buildslave):
self.builders = {} # { name : isBusy }

# users of the fake can add to this as desired
self.info = {'slave_commands': [], 'version': '0.8.2'}
self.info = {
'slave_commands': [],
'version': '0.8.2',
'basedir': '/sl',
'system': 'nt',
}

def remotePrint(self, message):
self.remoteCalls.append(('remotePrint', message))
Expand Down
42 changes: 40 additions & 2 deletions master/buildbot/test/fake/slave.py
Expand Up @@ -13,7 +13,45 @@
#
# Copyright Buildbot Team Members

import os

from buildbot.process import properties
from buildbot.test.fake import fakeprotocol
from twisted.internet import defer


class FakeSlave(object):
slave_system = 'posix'
slavename = 'fakeslave'
slavename = 'test'

def __init__(self, master):
self.master = master
self.conn = fakeprotocol.FakeConnection(master, self)
self.properties = properties.Properties()

def acquireLocks(self):
pass

def releaseLocks(self):
pass

def attached(self, conn):
self.slave_system = 'posix'
self.path_module = os.path
self.buildslaveid = 1234
self.slave_basedir = '/sl'
return defer.succeed(None)

def detached(self):
pass

def addSlaveBuilder(self, sb):
pass

def removeSlaveBuilder(self, sb):
pass

def buildFinished(self, sb):
pass

def canStartBuild(self):
pass

0 comments on commit 9d91398

Please sign in to comment.