Skip to content

Commit

Permalink
Updating create-master/upgrade-master to use DB urls
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris AtLee committed Feb 17, 2010
1 parent d52a3dc commit cb3d1f5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 21 deletions.
29 changes: 10 additions & 19 deletions buildbot/scripts/runner.py
Expand Up @@ -269,8 +269,8 @@ def public_html(self, files):
f.close()

def create_db(self):
dbspec = make_dbspec(self.config["db"], self.basedir)
from buildbot.db import create_db
from buildbot.db import create_db, DB
dbspec = DB.from_url(self.config["db"], self.basedir)
if not self.config['quiet']: print "creating database"
create_db(dbspec)

Expand Down Expand Up @@ -378,27 +378,19 @@ def check_master_cfg(self):
BASEDIR/state.sqlite) is equivalent to:
--db='DB("sqlite3", basedir+"/state.sqlite"))'
--db='sqlite:///state.sqlite'
To use a remote MySQL database instead, use something like:
--db='DB("MySQLdb", host="dbhost", user="bbuser", passwd="bbpasswd", db="bbdb")'
--db='mysql://bbuser:bbpasswd@dbhost/bbdb'
"""

def make_dbspec(dbstring, basedir):
from buildbot.master import DB
localsyms = {"basedir": basedir, "DB": DB}
exec "db = %s" % dbstring in localsyms
dbspec = localsyms["db"]
if dbspec is None:
dbspec = DB("sqlite3", os.path.join(basedir, "state.sqlite"))
return dbspec

class UpgradeMasterOptions(MakerBase):
optFlags = [
["replace", "r", "Replace any modified files without confirmation."],
]
optParameters = [
["db", None, "None",
["db", None, "sqlite:///state.sqlite",
"which DB to use for scheduler/status state. See below for syntax."],
]

Expand Down Expand Up @@ -461,9 +453,9 @@ def upgradeMaster(config):
m.move_if_present(os.path.join(basedir, "public_html/index.html"),
os.path.join(basedir, "templates/root.html"))

dbspec = make_dbspec(config["db"], basedir)
from buildbot.db import create_or_upgrade_db, DB
dbspec = DB.from_url(config["db"], basedir)
# TODO: check that TAC file specifies the right spec
from buildbot.db import create_or_upgrade_db
db = create_or_upgrade_db(dbspec)
db.start()
# if we still have a changes.pck, then we need to migrate it
Expand Down Expand Up @@ -493,7 +485,7 @@ class MasterOptions(MakerBase):
"size at which to rotate twisted log files"],
["log-count", "l", "None",
"limit the number of kept old twisted log files"],
["db", None, "None # use default sqlite",
["db", None, "sqlite:///state.sqlite",
"which DB to use for scheduler/status state. See below for syntax."],
]
def getSynopsis(self):
Expand Down Expand Up @@ -527,7 +519,7 @@ def postOptions(self):

masterTAC = """
from twisted.application import service
from buildbot.master import BuildMaster, DB
from buildbot.master import BuildMaster
rotateLength = %(log-size)s
maxRotatedFiles = %(log-count)s
Expand All @@ -545,9 +537,8 @@ def postOptions(self):
basedir = r'%(basedir)s'
configfile = r'%(config)s'
db = %(db)s
m = BuildMaster(basedir, configfile, db)
m = BuildMaster(basedir, configfile)
m.setServiceParent(application)
"""
Expand Down
6 changes: 6 additions & 0 deletions buildbot/scripts/sample.cfg
Expand Up @@ -14,6 +14,12 @@
# a shorter alias to save typing.
c = BuildmasterConfig = {}

####### DB URL

# This specifies what database buildbot uses to store change and scheduler
# state
c['db_url'] = "sqlite:///state.sqlite"

####### BUILDSLAVES

# the 'slaves' list defines the set of allowable buildslaves. Each element is
Expand Down
2 changes: 1 addition & 1 deletion buildbot/test/runs/test_runner.py
Expand Up @@ -101,7 +101,7 @@ def testMaster(self):
tacfile = open(tac,"rt").read()
self.failUnlessIn("basedir", tacfile)
self.failUnlessIn("configfile = r'master.cfg'", tacfile)
self.failUnlessIn("BuildMaster(basedir, configfile, db)", tacfile)
self.failUnlessIn("BuildMaster(basedir, configfile)", tacfile)

cfg = os.path.join(basedir, "master.cfg")
self.failIfExists(cfg)
Expand Down
2 changes: 1 addition & 1 deletion buildbot/test/runs/test_webparts.py
Expand Up @@ -38,7 +38,7 @@ def startMaster(self, extraconfig):
self.master = m = SimpleMaster(self.basedir)
# use upgradeMaster to populate public_html/ with default.css
runner.upgradeMaster({'basedir': self.basedir, 'quiet': True,
'db': None})
'db': "sqlite:///state.sqlite"})
m.startService()
d = m.loadConfig(config)
def _started(ign):
Expand Down

0 comments on commit cb3d1f5

Please sign in to comment.