Skip to content

Commit

Permalink
Fix whitespace.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomprince committed Apr 14, 2013
1 parent 1a70a0f commit b050647
Show file tree
Hide file tree
Showing 32 changed files with 195 additions and 200 deletions.
1 change: 0 additions & 1 deletion common/generate_buildbot_api_documentation.sh
Expand Up @@ -19,4 +19,3 @@ tar -xzf buildbot-slave-0.8.7.tar.gz
git clone https://github.com/buildbot/buildbot.git
cd buildbot/apidocs
PYTHONPATH="/tmp/epydoc-3.0.1:/tmp/buildbot-0.8.7:/tmp/buildbot-slave-0.8.7${PYTHONPATH:+:}${PYTHONPATH}" make

2 changes: 1 addition & 1 deletion master/buildbot/buildslave/__init__.py
Expand Up @@ -974,7 +974,7 @@ def _soft_disconnect(self, fast=False):

def disconnect(self):
# This returns a Deferred but we don't use it
self._soft_disconnect()
self._soft_disconnect()
# this removes the slave from all builders. It won't come back
# without a restart (or maybe a sighup)
self.botmaster.slaveLost(self)
Expand Down
4 changes: 2 additions & 2 deletions master/buildbot/db/schedulers.py
Expand Up @@ -66,9 +66,9 @@ def thd(conn):
ch_tbl = self.db.model.changes

wc = (sch_ch_tbl.c.objectid == objectid)

# may need to filter further based on branch, etc
extra_wheres = []
extra_wheres = []
if branch is not self.Thunk:
extra_wheres.append(ch_tbl.c.branch == branch)
if repository is not self.Thunk:
Expand Down
4 changes: 2 additions & 2 deletions master/buildbot/master.py
Expand Up @@ -83,7 +83,7 @@ def __init__(self, basedir, configFileName="master.cfg", umask=None):
self.db_loop = None
# db configured values
self.configured_db_url = None
self.configured_poll_interval = None
self.configured_poll_interval = None

# configuration / reconfiguration handling
self.config = config.MasterConfig()
Expand Down Expand Up @@ -172,7 +172,7 @@ def startService(self, _reactor=reactor):
try:
self.config = config.MasterConfig.loadConfig(self.basedir,
self.configFileName)

except config.ConfigErrors, e:
log.msg("Configuration Errors:")
for msg in e.errors:
Expand Down
2 changes: 1 addition & 1 deletion master/buildbot/process/botmaster.py
Expand Up @@ -322,7 +322,7 @@ def maybeStartBuildsForSlave(self, slave_name):

def maybeStartBuildsForAllBuilders(self):
"""
Call this when something suggests that this would be a good time to
Call this when something suggests that this would be a good time to
start some builds, but nothing more specific.
"""
self.brd.maybeStartBuildsOn(self.builderNames)
Expand Down
2 changes: 1 addition & 1 deletion master/buildbot/process/build.py
Expand Up @@ -224,7 +224,7 @@ def startBuild(self, build_status, expectations, slavebuilder):
slavebuilder.slave.updateSlaveStatus(buildStarted=build_status)

# then narrow SlaveLocks down to the right slave
self.locks = [(l.getLock(self.slavebuilder.slave), a)
self.locks = [(l.getLock(self.slavebuilder.slave), a)
for l, a in self.locks ]
self.remote = slavebuilder.remote
self.remote.notifyOnDisconnect(self.lostRemote)
Expand Down
6 changes: 3 additions & 3 deletions master/buildbot/process/builder.py
Expand Up @@ -493,8 +493,8 @@ def setExpectations(self, progress):
@defer.inlineCallbacks
def maybeStartBuild(self, slavebuilder, breqs):
# This method is called by the botmaster whenever this builder should
# start a set of buildrequests on a slave. Do not call this method
# directly - use master.botmaster.maybeStartBuildsForBuilder, or one of
# start a set of buildrequests on a slave. Do not call this method
# directly - use master.botmaster.maybeStartBuildsForBuilder, or one of
# the other similar methods if more appropriate

# first, if we're not running, then don't start builds; stopService
Expand All @@ -507,7 +507,7 @@ def maybeStartBuild(self, slavebuilder, breqs):
# If the build fails from here on out (e.g., because a slave has failed),
# it will be handled outside of this function. TODO: test that!

build_started = yield self._startBuildFor(slavebuilder, breqs)
build_started = yield self._startBuildFor(slavebuilder, breqs)
defer.returnValue(build_started)

# a few utility functions to make the maybeStartBuild a bit shorter and
Expand Down
104 changes: 52 additions & 52 deletions master/buildbot/process/buildrequestdistributor.py
Expand Up @@ -27,12 +27,12 @@

class BuildChooserBase(object):
#
# WARNING: This API is experimental and in active development.
# WARNING: This API is experimental and in active development.
#
# This internal object selects a new build+slave pair. It acts as a
# This internal object selects a new build+slave pair. It acts as a
# generator, initializing its state on creation and offering up new
# pairs until exhaustion. The object can be destroyed at any time
# (eg, before the list exhausts), and can be "restarted" by abandoning
# (eg, before the list exhausts), and can be "restarted" by abandoning
# an old instance and creating a new one.
#
# The entry point is:
Expand All @@ -58,48 +58,48 @@ def chooseNextBuild(self):
if not slave or not breq:
defer.returnValue((None, None))
return

breqs = yield self.mergeRequests(breq)
for b in breqs:
self._removeBuildRequest(b)

defer.returnValue((slave, breqs))


# Must be implemented by subclass
def popNextBuild(self):
# Pick the next (slave, breq) pair; note this is pre-merge, so
# it's just one breq
raise NotImplementedError("Subclasses must implement this!")

# Must be implemented by subclass
def mergeRequests(self, breq):
# Merge the chosen breq with any other breqs that are compatible
# Returns a list of the breqs chosen (and should include the
# original breq as well!)
raise NotImplementedError("Subclasses must implement this!")


# - Helper functions that are generally useful to all subclasses -

@defer.inlineCallbacks
def _fetchUnclaimedBrdicts(self):
# Sets up a cache of all the unclaimed brdicts. The cache is
# saved at self.unclaimedBrdicts cache. If the cache already
# exists, this function does nothing. If a refetch is desired, set
# saved at self.unclaimedBrdicts cache. If the cache already
# exists, this function does nothing. If a refetch is desired, set
# the self.unclaimedBrdicts to None before calling."""

if self.unclaimedBrdicts is None:
brdicts = yield self.master.db.buildrequests.getBuildRequests(
buildername=self.bldr.name, claimed=False)
buildername=self.bldr.name, claimed=False)
# sort by submitted_at, so the first is the oldest
brdicts.sort(key=lambda brd : brd['submitted_at'])
self.unclaimedBrdicts = brdicts
defer.returnValue(self.unclaimedBrdicts)

@defer.inlineCallbacks
def _getBuildRequestForBrdict(self, brdict):
# Turn a brdict into a BuildRequest into a brdict. This is useful
# Turn a brdict into a BuildRequest into a brdict. This is useful
# for API like 'nextBuild', which operate on BuildRequest objects.

breq = self.breqCache.get(brdict['brid'])
Expand All @@ -110,12 +110,12 @@ def _getBuildRequestForBrdict(self, brdict):
defer.returnValue(breq)

def _getBrdictForBuildRequest(self, breq):
# Turn a BuildRequest back into a brdict. This operates from the
# Turn a BuildRequest back into a brdict. This operates from the
# cache, which must be set up once via _fetchUnclaimedBrdicts

if breq is None:
return None

brid = breq.id
for brdict in self.unclaimedBrdicts:
if brid == brdict['brid']:
Expand All @@ -128,7 +128,7 @@ def _removeBuildRequest(self, breq):

if breq is None:
return

brdict = self._getBrdictForBuildRequest(breq)
if brdict is not None:
self.unclaimedBrdicts.remove(brdict)
Expand All @@ -141,7 +141,7 @@ def _getUnclaimedBuildRequests(self):
return defer.gatherResults([
self._getBuildRequestForBrdict(brdict)
for brdict in self.unclaimedBrdicts ])

class BasicBuildChooser(BuildChooserBase):
# BasicBuildChooser generates build pairs via the configuration points:
# * config.nextSlave (or random.choice if not set)
Expand All @@ -151,14 +151,14 @@ class BasicBuildChooser(BuildChooserBase):
# returns a slave that cannot satisfy the build chosen by nextBuild,
# it will search for a slave that can satisfy the build. If one is found,
# the slaves that cannot be used are "recycled" back into a list
# to be tried, in order, for the next chosen build.
# to be tried, in order, for the next chosen build.
#
# There are two tests performed on the slave:
# * can the slave start a generic build for the Builder?
# * if so, can the slave start the chosen build on the Builder?
# Slaves that cannot meet the first criterion are saved into the
# Slaves that cannot meet the first criterion are saved into the
# self.rejectedSlaves list and will be used as a last resort. An example
# of this test is whether the slave can grab the Builder's locks.
# of this test is whether the slave can grab the Builder's locks.
#
# If all slaves fail the first test, then the algorithm will assign the
# slaves in the order originally generated. By setting self.rejectedSlaves
Expand All @@ -171,30 +171,30 @@ def __init__(self, bldr, master):
self.nextSlave = self.bldr.config.nextSlave
if not self.nextSlave:
self.nextSlave = lambda _,slaves: random.choice(slaves) if slaves else None

self.slavepool = self.bldr.getAvailableSlaves()

# Pick slaves one at a time from the pool, and if the Builder says
# they're usable (eg, locks can be satisfied), then prefer those slaves;
# otherwise they go in the 'last resort' bucket, and we'll use them if
# Pick slaves one at a time from the pool, and if the Builder says
# they're usable (eg, locks can be satisfied), then prefer those slaves;
# otherwise they go in the 'last resort' bucket, and we'll use them if
# we need to. (Setting rejectedSlaves to None disables that feature)
self.preferredSlaves = []
self.rejectedSlaves = []

self.nextBuild = self.bldr.config.nextBuild

self.mergeRequestsFn = self.bldr.getMergeRequestsFn()

@defer.inlineCallbacks
def popNextBuild(self):
nextBuild = (None, None)

while 1:
# 1. pick a slave
slave = yield self._popNextSlave()
if not slave:
break

# 2. pick a build
breq = yield self._getNextUnclaimedBuildRequest()
if not breq:
Expand All @@ -212,19 +212,19 @@ def popNextBuild(self):
# try a different slave
recycledSlaves.append(slave)
slave = yield self._popNextSlave()

# recycle the slaves that we didnt use to the head of the queue
# this helps ensure we run 'nextSlave' only once per slave choice
if recycledSlaves:
if recycledSlaves:
self._unpopSlaves(recycledSlaves)

# 4. done? otherwise we will try another build
if slave:
nextBuild = (slave, breq)
break

defer.returnValue(nextBuild)

@defer.inlineCallbacks
def mergeRequests(self, breq):
mergedRequests = [ breq ]
Expand Down Expand Up @@ -262,7 +262,7 @@ def _getNextUnclaimedBuildRequest(self):
if nextBreq not in breqs:
nextBreq = None
except Exception:
nextBreq = None
nextBreq = None
else:
# otherwise just return the first build
brdict = self.unclaimedBrdicts[0]
Expand All @@ -277,24 +277,24 @@ def _popNextSlave(self):
slave = self.preferredSlaves.pop(0)
defer.returnValue(slave)
return

while self.slavepool:
try:
slave = yield self.nextSlave(self.bldr, self.slavepool)
except Exception:
slave = None

if not slave or slave not in self.slavepool:
# bad slave or no slave returned
break

self.slavepool.remove(slave)

canStart = yield self.bldr.canStartWithSlavebuilder(slave)
if canStart:
defer.returnValue(slave)
return

# save as a last resort, just in case we need them later
if self.rejectedSlaves is not None:
self.rejectedSlaves.append(slave)
Expand All @@ -304,7 +304,7 @@ def _popNextSlave(self):
slave = self.rejectedSlaves.pop(0)
defer.returnValue(slave)
return

defer.returnValue(None)

def _unpopSlaves(self, slaves):
Expand All @@ -328,7 +328,7 @@ class BuildRequestDistributor(service.Service):
"""

BuildChooser = BasicBuildChooser

def __init__(self, botmaster):
self.botmaster = botmaster
self.master = botmaster.master
Expand Down Expand Up @@ -390,7 +390,7 @@ def _maybeStartBuildsOn(self, new_builders):
@defer.inlineCallbacks
def resetPendingBuildersList(new_builders):
try:
# re-fetch existing_pending, in case it has changed
# re-fetch existing_pending, in case it has changed
# while acquiring the lock
existing_pending = set(self._pending_builders)

Expand Down Expand Up @@ -494,7 +494,7 @@ def _activityLoop(self):
# get the actual builder object
bldr = self.botmaster.builders.get(bldr_name)
if bldr:
yield self._maybeStartBuildsOnBuilder(bldr)
yield self._maybeStartBuildsOnBuilder(bldr)
except Exception:
log.err(Failure(),
"from maybeStartBuild for builder '%s'" % (bldr_name,))
Expand All @@ -505,19 +505,19 @@ def _activityLoop(self):

self.active = False
self._quiet()

@defer.inlineCallbacks
def _maybeStartBuildsOnBuilder(self, bldr):
# create a chooser to give us our next builds
# this object is temporary and will go away when we're done

bc = self.createBuildChooser(bldr, self.master)

while 1:
slave, breqs = yield bc.chooseNextBuild()
if not slave or not breqs:
break

# claim brid's
brids = [ br.id for br in breqs ]
try:
Expand All @@ -526,20 +526,20 @@ def _maybeStartBuildsOnBuilder(self, bldr):
# some brids were already claimed, so start over
bc = self.createBuildChooser(bldr, self.master)
continue

buildStarted = yield bldr.maybeStartBuild(slave, breqs)

if not buildStarted:
yield self.master.db.buildrequests.unclaimBuildRequests(brids)

# and try starting builds again. If we still have a working slave,
# then this may re-claim the same buildrequests
self.botmaster.maybeStartBuildsForBuilder(self.name)

def createBuildChooser(self, bldr, master):
# just instantiate the build chooser requested
return self.BuildChooser(bldr, master)

def _quiet(self):
# shim for tests
pass # pragma: no cover

0 comments on commit b050647

Please sign in to comment.