Skip to content

Commit

Permalink
Prevent changing the db_url on a reconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris AtLee committed Feb 17, 2010
1 parent c175b81 commit d52a3dc
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
4 changes: 2 additions & 2 deletions buildbot/master.py
Expand Up @@ -627,6 +627,8 @@ def loadConfig(self, f, check_synchronously_only=False):
"reserved name '%s' used for a bot" % s.slavename)
if config.has_key('interlocks'):
raise KeyError("c['interlocks'] is no longer accepted")
assert self.db_url is None or db_url == self.db_url, \
"Cannot change db_url after master has started"

assert isinstance(change_sources, (list, tuple))
for s in change_sources:
Expand Down Expand Up @@ -783,7 +785,6 @@ def loadConfig(self, f, check_synchronously_only=False):
self.buildHorizon = buildHorizon

# Set up the database
# TODO: Warn if this changes
d.addCallback(lambda res: self.loadConfig_Database(db_url))

# self.slaves: Disconnect any that were attached and removed from the
Expand Down Expand Up @@ -873,7 +874,6 @@ def loadDatabase(self, db_spec):
# should we try to remove this? Periodic() requires at least one kick

def loadConfig_Database(self, db_url):
assert self.db_url is None or db_url == self.db_url, "Cannot change db_url after master has started"
self.db_url = db_url
db_spec = DB.from_url(db_url, self.basedir)
self.loadDatabase(db_spec)
Expand Down
44 changes: 44 additions & 0 deletions buildbot/test/unit/test_config.py
Expand Up @@ -400,6 +400,16 @@ def startService(self):
BuildmasterConfig = c
"""

dburlCfg = emptyCfg + \
"""
c['db_url'] = "sqlite:///orig.sqlite"
"""

dburlCfg1 = emptyCfg + \
"""
c['db_url'] = "sqlite:///new.sqlite"
"""

class TestDBUrl(unittest.TestCase):
def testSQLiteRelative(self):
basedir = "/foo/bar"
Expand Down Expand Up @@ -1272,6 +1282,40 @@ def _check1(res):
d.addCallback(_check1)
return d

def testDBUrl(self):
self.basedir = "config/configtest/DBUrl"
if not os.path.exists(self.basedir):
os.makedirs(self.basedir)
self.buildmaster = BuildMaster(self.basedir)
self.buildmaster.readConfig = True
self.buildmaster.setServiceParent(self.serviceparent)
spec = db.DB.from_url("sqlite:///orig.sqlite", basedir=self.basedir)
db.create_db(spec)
d = self.buildmaster.loadConfig(dburlCfg)
def _check(ign):
self.failUnlessEqual(self.buildmaster.db_url, "sqlite:///orig.sqlite")
d.addCallback(_check)
return d

def testDBUrlChange(self):
self.basedir = "config/configtest/DBUrlChange"
if not os.path.exists(self.basedir):
os.makedirs(self.basedir)
self.buildmaster = BuildMaster(self.basedir)
self.buildmaster.readConfig = True
self.buildmaster.setServiceParent(self.serviceparent)
spec = db.DB.from_url("sqlite:///orig.sqlite", basedir=self.basedir)
db.create_db(spec)
d = self.buildmaster.loadConfig(dburlCfg)
def _check(ign):
self.failUnlessEqual(self.buildmaster.db_url, "sqlite:///orig.sqlite")
d.addCallback(_check)

d.addCallback(lambda ign: self.shouldFail(AssertionError, "loadConfig",
"Cannot change db_url after master has started",
self.buildmaster.loadConfig, dburlCfg1))
return d

class ConfigElements(unittest.TestCase):
# verify that ComparableMixin is working
def testSchedulers(self):
Expand Down

0 comments on commit d52a3dc

Please sign in to comment.