Skip to content

Commit

Permalink
Merge pull request #1269 from djmitche/bug2818b
Browse files Browse the repository at this point in the history
Change state_strings to state_string

See ticket:2818
  • Loading branch information
Mikhail Sobolev committed Oct 21, 2014
2 parents d7badd3 + 69b22d2 commit 32a8eba
Show file tree
Hide file tree
Showing 28 changed files with 304 additions and 199 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
12 changes: 6 additions & 6 deletions master/buildbot/data/steps.py
Expand Up @@ -29,7 +29,7 @@ def db2data(self, dbdict):
'started_at': dbdict['started_at'],
'complete': dbdict['complete_at'] is not None,
'complete_at': dbdict['complete_at'],
'state_strings': dbdict['state_strings'],
'state_string': dbdict['state_string'],
'results': dbdict['results'],
'urls': dbdict['urls'],
}
Expand Down Expand Up @@ -117,7 +117,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()
urls = types.List(
of=types.Dict(
name=types.String(),
Expand All @@ -134,7 +134,7 @@ def generateEvent(self, stepid, event):
@defer.inlineCallbacks
def newStep(self, buildid, name):
stepid, num, name = yield self.master.db.steps.addStep(
buildid=buildid, name=name, state_strings=[u'pending'])
buildid=buildid, name=name, state_string=u'pending')
yield self.generateEvent(stepid, 'new')
defer.returnValue((stepid, num, name))

Expand All @@ -146,9 +146,9 @@ def startStep(self, stepid):

@base.updateMethod
@defer.inlineCallbacks
def setStepStateStrings(self, stepid, state_strings):
yield self.master.db.steps.setStepStateStrings(
stepid=stepid, state_strings=state_strings)
def setStepStateString(self, stepid, state_string):
yield self.master.db.steps.setStepStateString(
stepid=stepid, state_string=state_string)
yield self.generateEvent(stepid, 'updated')

@base.updateMethod
Expand Down
12 changes: 5 additions & 7 deletions master/buildbot/db/builds.py
Expand Up @@ -18,7 +18,6 @@
from buildbot.db import NULL
from buildbot.db import base
from buildbot.util import epoch2datetime
from buildbot.util import json
from twisted.internet import reactor


Expand Down Expand Up @@ -59,9 +58,8 @@ def thd(conn):
return self.db.pool.do(thd)

def addBuild(self, builderid, buildrequestid, buildslaveid, masterid,
state_strings, _reactor=reactor, _race_hook=None):
state_string, _reactor=reactor, _race_hook=None):
started_at = _reactor.seconds()
state_strings_json = json.dumps(state_strings)

def thd(conn):
tbl = self.db.model.builds
Expand All @@ -82,19 +80,19 @@ def thd(conn):
buildrequestid=buildrequestid,
buildslaveid=buildslaveid, masterid=masterid,
started_at=started_at, complete_at=None,
state_strings_json=state_strings_json))
state_string=state_string))
except (sa.exc.IntegrityError, sa.exc.ProgrammingError):
new_number += 1
continue
return r.inserted_primary_key[0], new_number
return self.db.pool.do(thd)

def setBuildStateStrings(self, buildid, state_strings):
def setBuildStateString(self, buildid, state_string):
def thd(conn):
tbl = self.db.model.builds

q = tbl.update(whereclause=(tbl.c.id == buildid))
conn.execute(q, state_strings_json=json.dumps(state_strings))
conn.execute(q, state_string=state_string)
return self.db.pool.do(thd)

def finishBuild(self, buildid, results, _reactor=reactor):
Expand Down Expand Up @@ -132,5 +130,5 @@ def mkdt(epoch):
masterid=row.masterid,
started_at=mkdt(row.started_at),
complete_at=mkdt(row.complete_at),
state_strings=json.loads(row.state_strings_json),
state_string=row.state_string,
results=row.results)
35 changes: 35 additions & 0 deletions master/buildbot/db/migrate/versions/038_state_string.py
@@ -0,0 +1,35 @@
# 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 sqlalchemy as sa


def upgrade(migrate_engine):
metadata = sa.MetaData()
metadata.bind = migrate_engine

steps_table = sa.Table('steps', metadata, autoload=True)
builds_table = sa.Table('builds', metadata, autoload=True)

# no attempt is made here to move data from one table to the other, since
# there was no released version of Buildbot with a 'steps' table yet.

col = sa.Column('state_string', sa.Text, nullable=False, server_default='')
col.create(steps_table)
steps_table.c.state_strings_json.drop()

col = sa.Column('state_string', sa.Text, nullable=False, server_default='')
col.create(builds_table)
builds_table.c.state_strings_json.drop()
6 changes: 2 additions & 4 deletions master/buildbot/db/model.py
Expand Up @@ -116,8 +116,7 @@ class Model(base.DBConnectorComponent):
# start/complete times
sa.Column('started_at', sa.Integer, nullable=False),
sa.Column('complete_at', sa.Integer),
# a list of strings describing the build's state
sa.Column('state_strings_json', sa.Text, nullable=False),
sa.Column('state_string', sa.Text, nullable=False, server_default=''),
sa.Column('results', sa.Integer),
)

Expand All @@ -130,8 +129,7 @@ class Model(base.DBConnectorComponent):
sa.Column('buildid', sa.Integer, sa.ForeignKey('builds.id')),
sa.Column('started_at', sa.Integer),
sa.Column('complete_at', sa.Integer),
# a list of strings describing the step's state
sa.Column('state_strings_json', sa.Text, nullable=False),
sa.Column('state_string', sa.Text, nullable=False, server_default=''),
sa.Column('results', sa.Integer),
sa.Column('urls_json', sa.Text, nullable=False),
)
Expand Down
12 changes: 5 additions & 7 deletions master/buildbot/db/steps.py
Expand Up @@ -63,9 +63,7 @@ def thd(conn):
return [self._stepdictFromRow(row) for row in res.fetchall()]
return self.db.pool.do(thd)

def addStep(self, buildid, name, state_strings):
state_strings_json = json.dumps(state_strings)

def addStep(self, buildid, name, state_string):
def thd(conn):
tbl = self.db.model.steps
# get the highest current number
Expand All @@ -79,7 +77,7 @@ def thd(conn):
# conflict, then the name is likely already taken.
insert_row = dict(buildid=buildid, number=number,
started_at=None, complete_at=None,
state_strings_json=state_strings_json,
state_string=state_string,
urls_json='[]', name=name)
try:
r = conn.execute(self.db.model.steps.insert(), insert_row)
Expand Down Expand Up @@ -118,11 +116,11 @@ def thd(conn):
conn.execute(q, started_at=started_at)
return self.db.pool.do(thd)

def setStepStateStrings(self, stepid, state_strings):
def setStepStateString(self, stepid, state_string):
def thd(conn):
tbl = self.db.model.steps
q = tbl.update(whereclause=(tbl.c.id == stepid))
conn.execute(q, state_strings_json=json.dumps(state_strings))
conn.execute(q, state_string=state_string)
return self.db.pool.do(thd)

def addURL(self, stepid, name, url, _racehook=None):
Expand Down Expand Up @@ -176,6 +174,6 @@ def mkdt(epoch):
buildid=row.buildid,
started_at=mkdt(row.started_at),
complete_at=mkdt(row.complete_at),
state_strings=json.loads(row.state_strings_json),
state_string=row.state_string,
results=row.results,
urls=json.loads(row.urls_json))
8 changes: 4 additions & 4 deletions master/buildbot/process/build.py
Expand Up @@ -276,8 +276,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 @@ -288,8 +288,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
6 changes: 2 additions & 4 deletions master/buildbot/process/buildstep.py
Expand Up @@ -362,8 +362,6 @@ def getResultSummary(self):

return {u'step': stepsumm}

# TODO: test those^^

@debounce.method(wait=1)
@defer.inlineCallbacks
def updateSummary(self):
Expand All @@ -384,8 +382,8 @@ def methodInfo(m):
if not isinstance(stepResult, unicode):
raise TypeError("step result string must be unicode (got %r)"
% (stepResult,))
yield self.master.data.updates.setStepStateStrings(self.stepid,
[stepResult])
yield self.master.data.updates.setStepStateString(self.stepid,
stepResult)

if not self._running:
buildResult = summary.get('build', None)
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
8 changes: 4 additions & 4 deletions master/buildbot/status/words.py
Expand Up @@ -619,7 +619,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 @@ -766,7 +766,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 All @@ -776,7 +776,7 @@ def emit_status(self, which):
for build in runningBuilds:
step = yield self.getCurrentBuildstep(build)
if step:
s = "(%s)" % " ".join(step['state_strings'])
s = "(%s)" % step['state_string']
else:
s = "(no current step)"
buildInfo.append("%d %s" % (build['number'], s))
Expand Down Expand Up @@ -811,7 +811,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
16 changes: 8 additions & 8 deletions master/buildbot/test/fake/fakedata.py
Expand Up @@ -48,7 +48,7 @@ def __init__(self, master, testcase):
# { logid : {'finished': .., 'name': .., 'type': .., 'content': [ .. ]} }
self.logs = {}
self.claimedBuildRequests = set([])
self.stepStateStrings = {} # { stepid : [strings] }
self.stepStateString = {} # { stepid : string }
self.stepUrls = {} # { stepid : [(name,url)] }

# extra assertions
Expand Down 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 Expand Up @@ -297,12 +297,12 @@ def startStep(self, stepid):
validation.IntValidator())
return defer.succeed(None)

def setStepStateStrings(self, stepid, state_strings):
def setStepStateString(self, stepid, state_string):
validation.verifyType(self.testcase, 'stepid', stepid,
validation.IntValidator())
validation.verifyType(self.testcase, 'state_strings', state_strings,
validation.ListValidator(validation.StringValidator()))
self.stepStateStrings[stepid] = state_strings
validation.verifyType(self.testcase, 'state_string', state_string,
validation.StringValidator())
self.stepStateString[stepid] = state_string
return defer.succeed(None)

def finishStep(self, stepid, results):
Expand Down

0 comments on commit 32a8eba

Please sign in to comment.