Skip to content

Commit

Permalink
change build state_strings to state_string: Data API + consumers
Browse files Browse the repository at this point in the history
  • Loading branch information
djmitche committed Oct 19, 2014
1 parent e55d775 commit 532497b
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 37 deletions.
12 changes: 6 additions & 6 deletions master/buildbot/data/builds.py
Expand Up @@ -31,7 +31,7 @@ def db2data(self, dbdict):
'started_at': dbdict['started_at'],
'complete_at': dbdict['complete_at'],
'complete': dbdict['complete_at'] is not None,
'state_strings': dbdict['state_strings'],
'state_string': dbdict['state_string'],
'results': dbdict['results'],
}
return defer.succeed(data)
Expand Down Expand Up @@ -124,7 +124,7 @@ class EntityType(types.Entity):
complete = types.Boolean()
complete_at = types.NoneOk(types.DateTime())
results = types.NoneOk(types.Integer())
state_strings = types.List(of=types.String())
state_string = types.String()
entityType = EntityType(name)

@defer.inlineCallbacks
Expand All @@ -141,17 +141,17 @@ def newBuild(self, builderid, buildrequestid, buildslaveid):
buildrequestid=buildrequestid,
buildslaveid=buildslaveid,
masterid=self.master.masterid,
state_strings=[u'created'])
state_string=u'created')
if res is not None:
_id, number = res
yield self.generateEvent(_id, "new")
defer.returnValue(res)

@base.updateMethod
@defer.inlineCallbacks
def setBuildStateStrings(self, buildid, state_strings):
res = yield self.master.db.builds.setBuildStateStrings(
buildid=buildid, state_strings=state_strings)
def setBuildStateString(self, buildid, state_string):
res = yield self.master.db.builds.setBuildStateString(
buildid=buildid, state_string=state_string)
yield self.generateEvent(buildid, "update")
defer.returnValue(res)

Expand Down
8 changes: 4 additions & 4 deletions master/buildbot/process/build.py
Expand Up @@ -278,8 +278,8 @@ def startBuild(self, build_status, expectations, slavebuilder):
self.deferred = None
return

yield self.master.data.updates.setBuildStateStrings(self.buildid,
[u'starting'])
yield self.master.data.updates.setBuildStateString(self.buildid,
u'starting')
self.build_status.buildStarted(self)
yield self.acquireLocks()

Expand All @@ -290,8 +290,8 @@ def startBuild(self, build_status, expectations, slavebuilder):
finally:
metrics.MetricCountEvent.log('active_builds', -1)

yield self.master.data.updates.setBuildStateStrings(self.buildid,
[u'finished'])
yield self.master.data.updates.setBuildStateString(self.buildid,
u'finished')
yield self.master.data.updates.finishBuild(self.buildid, self.results)

# mark the build as finished
Expand Down
2 changes: 1 addition & 1 deletion master/buildbot/schedulers/trysched.py
Expand Up @@ -357,7 +357,7 @@ def remote_getResults(self):
def remote_getText(self):
buildid = self.builddict['buildid']
builddict = yield self.master.data.get(('builds', buildid))
defer.returnValue(builddict['state_strings'])
defer.returnValue([builddict['state_string']])


class Try_Userpass_Perspective(pbutil.NewCredPerspective):
Expand Down
6 changes: 3 additions & 3 deletions master/buildbot/status/words.py
Expand Up @@ -622,7 +622,7 @@ def watchedBuildFinished(self, build):
r = "Hey! build %s #%d is complete: %s" % \
(builder_name, buildnum, results[0])

r += ' [%s]' % maybeColorize(" ".join(build['state_strings']), results[1], self.useColors)
r += ' [%s]' % maybeColorize(build['state_string'], results[1], self.useColors)
self.send(r)

# FIXME: where do we get the base_url? Then do we use the build Link to make the URL?
Expand Down Expand Up @@ -769,7 +769,7 @@ def emit_status(self, which):
ago = self.convertTime(int(util.now() - complete_at))
else:
ago = "??"
status = " ".join(lastBuild['state_strings'])
status = lastBuild['state_string']
response += ' last build %s ago: %s' % (ago, status)
else:
response += "offline"
Expand Down Expand Up @@ -814,7 +814,7 @@ def command_LAST(self, args, who):
ago = self.convertTime(int(util.now() - complete_at))
else:
ago = "??"
status = " ".join(lastBuild['state_strings'])
status = lastBuild['state_string']
status = 'last build %s ago: %s' % (ago, status)
self.send("last build [%s]: %s" % (builder['name'], status))

Expand Down
6 changes: 3 additions & 3 deletions master/buildbot/test/fake/fakedata.py
Expand Up @@ -261,11 +261,11 @@ def newBuild(self, builderid, buildrequestid, buildslaveid):
validation.IntValidator())
return defer.succeed((10, 1))

def setBuildStateStrings(self, buildid, state_strings):
def setBuildStateString(self, buildid, state_string):
validation.verifyType(self.testcase, 'buildid', buildid,
validation.IntValidator())
validation.verifyType(self.testcase, 'state_strings', state_strings,
validation.ListValidator(validation.StringValidator()))
validation.verifyType(self.testcase, 'state_string', state_string,
validation.StringValidator())
return defer.succeed(None)

def finishBuild(self, buildid, results):
Expand Down
20 changes: 10 additions & 10 deletions master/buildbot/test/unit/test_data_builds.py
Expand Up @@ -133,7 +133,7 @@ class Build(interfaces.InterfaceTests, unittest.TestCase):
'number': 1,
'results': None,
'started_at': epoch2datetime(1),
'state_strings': [u'created']}
'state_string': u'created'}

def setUp(self):
self.master = fakemaster.make_master(testcase=self,
Expand Down Expand Up @@ -169,25 +169,25 @@ 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=['created']))
state_string=u'created'))

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

def test_signature_setBuildStateStrings(self):
def test_signature_setBuildStateString(self):
@self.assertArgSpecMatches(
self.master.data.updates.setBuildStateStrings, # fake
self.rtype.setBuildStateStrings) # real
def setBuildStateStrings(self, buildid, state_strings):
self.master.data.updates.setBuildStateString, # fake
self.rtype.setBuildStateString) # real
def setBuildStateString(self, buildid, state_string):
pass

def test_setBuildStateStrings(self):
return self.do_test_callthrough('setBuildStateStrings',
self.rtype.setBuildStateStrings,
buildid=10, state_strings=['a', 'b'])
def test_setBuildStateString(self):
return self.do_test_callthrough('setBuildStateString',
self.rtype.setBuildStateString,
buildid=10, state_string=u'a b')

def test_signature_finishBuild(self):
@self.assertArgSpecMatches(
Expand Down
2 changes: 1 addition & 1 deletion master/buildbot/test/unit/test_status_words.py
Expand Up @@ -464,7 +464,7 @@ def sendBuildFinishedMessage(self, buildid, results=0):
started_at=datetime2epoch(build['started_at']),
complete=True,
complete_at=datetime2epoch(build['complete_at']),
state_strings=[],
state_string=u'',
results=results,
))

Expand Down
9 changes: 4 additions & 5 deletions master/docs/developer/rtype-build.rst
Expand Up @@ -13,8 +13,7 @@ Builds
:attr boolean complete: true if this build is complete
:attr timestamp complete_at: time at which this build was complete, or None if it's still running
:attr integer results: the results of the build (see :ref:`Build-Result-Codes`), or None if not complete
:attr list state_strings: a list of strings giving progressively more detail on the state of the build.
The first is usually one word or phrase; the remainder are sized for one-line display.
:attr unicode state_string: a string giving detail on the state of the build.

.. todo::

Expand All @@ -39,7 +38,7 @@ Builds

.. bb:event:: build.$builderid.$buildid.newstate
The build's state (``state_strings``) has changed.
The build's state (``state_string``) has changed.

.. bb:rpath:: /build
Expand Down Expand Up @@ -87,10 +86,10 @@ All update methods are available as attributes of ``master.data.updates``.
Create a new build resource and return its ID.
The state strings for the new build will be set to 'starting'.

.. py:method:: setBuildStateStrings(buildid, state_strings)
.. py:method:: setBuildStateString(buildid, state_string)
:param integer buildid: the build to modify
:param list state_strings: new state strings for this build
:param list state_string: new state string for this build

Replace the existing state strings for a build with a new list.

Expand Down
4 changes: 2 additions & 2 deletions www/base/src/app/builders/builder/builder.tpl.jade
Expand Up @@ -45,5 +45,5 @@
td(width='200px')
td
ul.list-inline
li(ng-repeat='st in build.state_strings')
| {{st}}
li
| {{build.state_string}}
Expand Up @@ -7,8 +7,8 @@
| {{(build.complete_at - build.started_at)| durationformat:'LLL' }}
span(ng-show="!build.complete")
| {{(now - build.started_at)| durationformat:'LLL' }}
span(ng-repeat="s in build.state_strings")
|  {{s}} 
span
|  {{build.state_string}} 
.label(ng-class="results2class(build)")
| {{results2text(build)}}
ul.list-group.no-select
Expand Down

0 comments on commit 532497b

Please sign in to comment.