Navigation Menu

Skip to content

Commit

Permalink
Merge pull request #1505 from tardyp/housekeeping
Browse files Browse the repository at this point in the history
force master housekeeping after a db upgrade
  • Loading branch information
Mikhail Sobolev committed Jan 24, 2015
2 parents 4221031 + c6b47e4 commit 060b1e3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions master/buildbot/db/masters.py
Expand Up @@ -91,6 +91,13 @@ def thd(conn):
for row in conn.execute(tbl.select()).fetchall()]
return self.db.pool.do(thd)

def setAllMastersActiveLongTimeAgo(self, _reactor=reactor):
def thd(conn):
tbl = self.db.model.masters
q = tbl.update().values(active=1, last_active=0)
conn.execute(q)
return self.db.pool.do(thd)

def _masterdictFromRow(self, row):
return MasterDict(id=row.id, name=row.name,
active=bool(row.active),
Expand Down
1 change: 1 addition & 0 deletions master/buildbot/scripts/upgrade_master.py
Expand Up @@ -157,6 +157,7 @@ def upgradeDatabase(config, master_cfg):

yield db.setup(check_version=False, verbose=not config['quiet'])
yield db.model.upgrade()
yield db.masters.setAllMastersActiveLongTimeAgo()


@in_reactor
Expand Down
4 changes: 4 additions & 0 deletions master/buildbot/test/unit/test_scripts_upgrade_master.py
Expand Up @@ -20,6 +20,7 @@

from buildbot import config as config_module
from buildbot.db import connector
from buildbot.db import masters
from buildbot.db import model
from buildbot.scripts import upgrade_master
from buildbot.test.util import compat
Expand Down Expand Up @@ -274,6 +275,9 @@ def test_upgradeDatabase(self):
self.patch(connector.DBConnector, 'setup', setup)
upgrade = mock.Mock(side_effect=lambda **kwargs: defer.succeed(None))
self.patch(model.Model, 'upgrade', upgrade)
setAllMastersActiveLongTimeAgo = mock.Mock(side_effect=lambda **kwargs: defer.succeed(None))
self.patch(masters.MastersConnectorComponent,
'setAllMastersActiveLongTimeAgo', setAllMastersActiveLongTimeAgo)
yield upgrade_master.upgradeDatabase(
mkconfig(basedir='test', quiet=True),
config_module.MasterConfig())
Expand Down
6 changes: 6 additions & 0 deletions master/docs/developer/database.rst
Expand Up @@ -1413,6 +1413,12 @@ masters
Get a list of the masters, represented as dictionaries; masters are sorted
and paged using generic data query options

.. py:method:: setAllMastersActiveLongTimeAgo()
:returns: None via Deferred

This method is intended to be call by upgrade-master, and will effectively force housekeeping on all masters at next startup.
This method is not intended to be called outside of housekeeping scripts.

builders
~~~~~~~~
Expand Down

0 comments on commit 060b1e3

Please sign in to comment.