Skip to content

Commit

Permalink
Merge branch 'nine' of git://github.com/delanne/buildbot into nine
Browse files Browse the repository at this point in the history
+autopep8
+pyflake (brdis vs. brids)
  • Loading branch information
djmitche committed Dec 20, 2013
2 parents ea55689 + 7f0cd56 commit ebd1904
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 27 deletions.
9 changes: 9 additions & 0 deletions master/buildbot/buildslave/base.py
Expand Up @@ -239,6 +239,9 @@ def reconfigService(self, new_config):

self.updateLocks()

bids = [b._builderid for b in self.botmaster.getBuildersForSlave(self.slavename)]
yield self.master.data.updates.buildslaveConfigured(self.buildslaveid, bids)

# update the attached slave's notion of which builders are attached.
# This assumes that the relevant builders have already been configured,
# which is why the reconfig_priority is set low in this class.
Expand Down Expand Up @@ -351,6 +354,7 @@ def attached(self, conn):
'access_uri': conn.info.get('access_uri'),
'version': conn.info.get('version')
}

yield self.master.data.updates.buildslaveConnected(
buildslaveid=self.buildslaveid,
masterid=self.master.masterid,
Expand All @@ -375,6 +379,7 @@ def messageReceivedFromSlave(self):
self.lastMessageReceived = now
self.slave_status.setLastMessageReceived(now)

@defer.inlineCallbacks
def detached(self):
metrics.MetricCountEvent.log("AbstractBuildSlave.attached_slaves", -1)
self.conn = None
Expand All @@ -384,6 +389,10 @@ def detached(self):
log.msg("BuildSlave.detached(%s)" % self.slavename)
self.master.status.slaveDisconnected(self.slavename)
self.releaseLocks()
yield self.master.data.updates.buildslaveDisconnected(
buildslaveid=self.buildslaveid,
masterid=self.master.masterid,
)

def disconnect(self):
"""Forcibly disconnect the slave.
Expand Down
4 changes: 2 additions & 2 deletions master/buildbot/data/builds.py
Expand Up @@ -151,7 +151,7 @@ def newBuild(self, builderid, buildrequestid, buildslaveid):
buildrequestid=buildrequestid,
buildslaveid=buildslaveid,
masterid=self.master.masterid,
state_strings=[u'starting'])
state_strings=[u'created'])
if res is not None:
_id, number = res
yield self.generateEvent(_id, "new")
Expand All @@ -170,5 +170,5 @@ def setBuildStateStrings(self, buildid, state_strings):
def finishBuild(self, buildid, results):
res = yield self.master.db.builds.finishBuild(
buildid=buildid, results=results)
yield self.generateEvent(buildid, "update")
yield self.generateEvent(buildid, "update") # Should be "finished" instead of "update" ???
defer.returnValue(res)
7 changes: 7 additions & 0 deletions master/buildbot/data/buildslaves.py
Expand Up @@ -103,6 +103,13 @@ class EntityType(types.Entity):
link = types.Link()
entityType = EntityType(name)

@base.updateMethod
@defer.inlineCallbacks
def buildslaveConfigured(self, buildslaveid, buildermasterids):
yield self.master.db.buildslaves.buildslaveConfigured(
buildslaveid=buildslaveid,
buildermasterids=buildermasterids)

@base.updateMethod
def findBuildslaveId(self, name):
return self.master.db.buildslaves.findBuildslaveId(name)
Expand Down
15 changes: 15 additions & 0 deletions master/buildbot/db/buildslaves.py
Expand Up @@ -35,6 +35,21 @@ def findBuildslaveId(self, name):
info={},
))

def buildslaveConfigured(self, buildslaveid, buildermasterids):
def thd(conn):
cfg_tbl = self.db.model.configured_buildslaves
for buildermasterid in buildermasterids:
q = cfg_tbl.insert()
try:
conn.execute(q,
{'buildslaveid': buildslaveid, 'buildermasterid': buildermasterid})
except (sa.exc.IntegrityError, sa.exc.ProgrammingError):
# TODO
# if the row is already present, silently fail..
pass

return self.db.pool.do(thd)

@defer.inlineCallbacks
def getBuildslave(self, buildslaveid=None, name=None, masterid=None,
builderid=None):
Expand Down
11 changes: 11 additions & 0 deletions master/buildbot/process/build.py
Expand Up @@ -90,6 +90,7 @@ def __init__(self, requests):
self.terminate = False

self._acquiringLock = None
self._dbid = None

def setBuilder(self, builder):
"""
Expand All @@ -108,6 +109,9 @@ def setLocks(self, lockList):
def setSlaveEnvironment(self, env):
self.slaveEnvironment = env

def setBuilDBId(self, dbid):
self._dbid = dbid

def getSourceStamp(self, codebase=''):
for source in self.sources:
if source.codebase == codebase:
Expand All @@ -117,6 +121,11 @@ def getSourceStamp(self, codebase=''):
def getAllSourceStamps(self):
return list(self.sources)

def getBuilDBId(self):
# TODO:
# Maybe is needed to implement a function in the DATA API to retreive the id
return self._dbid

def allChanges(self):
for s in self.sources:
for c in s.changes:
Expand Down Expand Up @@ -278,7 +287,9 @@ def _release_slave(res, slave, bs):
d.callback(self)
return d

self.master.data.updates.setBuildStateStrings(self.getBuilDBId(), [u'starting'])
self.build_status.buildStarted(self)

self.acquireLocks().addCallback(self._startBuild_2)
return d

Expand Down
22 changes: 12 additions & 10 deletions master/buildbot/process/builder.py
Expand Up @@ -410,12 +410,10 @@ def run_cleanups():
try:
bids = []
req = build.requests[-1]
# TODO: get id's for builder, slave
bid, number = yield self.master.db.builds.addBuild(
builderid=builderid, buildrequestid=req.id,
buildslaveid=buildslaveid, masterid=self.master.masterid,
state_strings=[u'created'])
bid, number = yield self.master.data.updates.newBuild(builderid=builderid,
buildrequestid=req.id, buildslaveid=buildslaveid)
bids.append(bid)
build.setBuilDBId(bid)
except:
log.err(failure.Failure(), 'while adding rows to build table:')
run_cleanups()
Expand Down Expand Up @@ -478,7 +476,11 @@ def buildFinished(self, build, sb, bids):

# mark the builds as finished, although since nothing ever reads this
# table, it's not too important that it complete successfully
d = self.master.db.builds.finishBuild(bids[0], results)
# TODO: The www service use this table
# So, I think it's important that it complete successfully.
# tardyp, djmitche do you confirm ?
d = self.master.data.updates.finishBuild(bids[0], results)
d.addCallback(lambda _: self.master.data.updates.setBuildStateStrings(bids[0], [u'finished']))
d.addErrback(log.err, 'while marking builds as finished (ignored)')

self.building.remove(build)
Expand All @@ -489,9 +491,8 @@ def buildFinished(self, build, sb, bids):
complete_at_epoch = reactor.seconds()
complete_at = epoch2datetime(complete_at_epoch)
brids = [br.id for br in build.requests]
db = self.master.db
d = db.buildrequests.completeBuildRequests(brids, results,
complete_at=complete_at)

d = self.master.data.updates.completeBuildRequests(brids, results, complete_at=complete_at)
d.addCallback(lambda _:
self._notify_completions(build.requests, results,
complete_at_epoch))
Expand Down Expand Up @@ -536,7 +537,7 @@ def _notify_completions(self, requests, results, complete_at_epoch):

def _resubmit_buildreqs(self, build):
brids = [br.id for br in build.requests]
d = self.master.db.buildrequests.unclaimBuildRequests(brids)
d = self.master.data.updates.unclaimBuildRequests(brids)

@d.addCallback
def notify(_):
Expand Down Expand Up @@ -617,6 +618,7 @@ def __init__(self, builder, control):
@defer.inlineCallbacks
def getPendingBuildRequestControls(self):
master = self.original.master
# TODO Use DATA API
brdicts = yield master.db.buildrequests.getBuildRequests(
buildername=self.original.name,
claimed=False)
Expand Down
5 changes: 5 additions & 0 deletions master/buildbot/test/fake/fakedata.py
Expand Up @@ -310,6 +310,11 @@ def buildslaveConnected(self, buildslaveid, masterid, slaveinfo):
masterid=masterid,
slaveinfo=slaveinfo)

def buildslaveConfigured(self, buildslaveid, buildermasterids):
return self.master.db.buildslaves.buildslaveConfigured(
buildslaveid=buildslaveid,
buildermasterids=buildermasterids)

def buildslaveDisconnected(self, buildslaveid, masterid):
return self.master.db.buildslaves.buildslaveDisconnected(
buildslaveid=buildslaveid,
Expand Down
5 changes: 5 additions & 0 deletions master/buildbot/test/fake/fakedb.py
Expand Up @@ -1299,6 +1299,11 @@ def buildslaveConnected(self, buildslaveid, masterid, slaveinfo):
self.connected[conn_id] = new_conn
return defer.succeed(None)

def buildslaveConfigured(self, buildslaveid, buildermasterids):
self.insertTestData([ConfiguredBuildslave(buildslaveid=buildslaveid,
buildermasterid=buildermasterid) for buildermasterid in buildermasterids])
return defer.succeed(None)

def buildslaveDisconnected(self, buildslaveid, masterid):
del_conn = dict(masterid=masterid, buildslaveid=buildslaveid)
for id, conn in self.connected.iteritems():
Expand Down
25 changes: 13 additions & 12 deletions master/buildbot/test/unit/test_buildslave_base.py
Expand Up @@ -195,16 +195,16 @@ def do_test_reconfigService(self, old, new, existingRegistration=True):

@defer.inlineCallbacks
def test_reconfigService_attrs(self):
old = ConcreteBuildSlave('bot', 'pass',
max_builds=2,
notify_on_missing=['me@me.com'],
missing_timeout=120,
properties={'a': 'b'})
new = ConcreteBuildSlave('bot', 'pass',
max_builds=3,
notify_on_missing=['her@me.com'],
missing_timeout=121,
properties={'a': 'c'})
old = self.createBuildslave('bot', 'pass',
max_builds=2,
notify_on_missing=['me@me.com'],
missing_timeout=120,
properties={'a': 'b'})
new = self.createBuildslave('bot', 'pass',
max_builds=3,
notify_on_missing=['her@me.com'],
missing_timeout=121,
properties={'a': 'c'})

old.updateSlave = mock.Mock(side_effect=lambda: defer.succeed(None))

Expand All @@ -219,13 +219,14 @@ def test_reconfigService_attrs(self):

@defer.inlineCallbacks
def test_reconfigService_has_properties(self):
old = ConcreteBuildSlave('bot', 'pass')
old = self.createBuildslave(name="bot", password="pass")

yield self.do_test_reconfigService(old, old)
self.assertTrue(old.properties.getProperty('slavename'), 'bot')

@defer.inlineCallbacks
def test_reconfigService_initial_registration(self):
old = ConcreteBuildSlave('bot', 'pass')
old = self.createBuildslave('bot', 'pass')
yield self.do_test_reconfigService(old, old,
existingRegistration=False)
self.assertIn('bot', self.master.buildslaves.registrations)
Expand Down
6 changes: 3 additions & 3 deletions master/buildbot/test/unit/test_data_builds.py
Expand Up @@ -132,7 +132,7 @@ class Build(interfaces.InterfaceTests, unittest.TestCase):
'number': 1,
'results': None,
'started_at': 1,
'state_strings': [u'starting']}
'state_strings': [u'created']}

def setUp(self):
self.master = fakemaster.make_master(testcase=self,
Expand Down Expand Up @@ -168,13 +168,13 @@ def test_newBuild(self):
builderid=10, buildrequestid=13, buildslaveid=20,
exp_kwargs=dict(builderid=10, buildrequestid=13,
buildslaveid=20, masterid=self.master.masterid,
state_strings=['starting']))
state_strings=['created']))

def test_newBuildEvent(self):
return self.do_test_event(self.rtype.newBuild,
builderid=10, buildrequestid=13, buildslaveid=20,
exp_events=[(('builder', '10', 'build', '1', 'new'), self.new_build_event),
(('build', '100', 'new'), self.new_build_event)])
(('build', '100', 'new'), self.new_build_event)])

def test_signature_setBuildStateStrings(self):
@self.assertArgSpecMatches(
Expand Down

0 comments on commit ebd1904

Please sign in to comment.