def setup(self, check_version=True, verbose=True): db_url = self.configured_url = self.master.config.db['db_url'] log.msg("Setting up database with URL %r" % util.stripUrlPassword(db_url)) # set up the engine and pool self._engine = enginestrategy.create_engine(db_url, basedir=self.basedir) self.pool = pool.DBThreadPool(self._engine, verbose=verbose) # make sure the db is up to date, unless specifically asked not to if check_version: d = self.model.is_current() @d.addCallback def check_current(res): if not res: for l in upgrade_message.format(basedir=self.master.basedir).split('\n'): log.msg(l) raise exceptions.DatabaseNotReadyError() else: d = defer.succeed(None) return d
def upgradeDatabase(config, master_cfg): if not config['quiet']: print("upgrading database (%s)" % (stripUrlPassword(master_cfg.db['db_url']))) print("Warning: Stopping this process might cause data loss") def sighandler(signum, frame): msg = " ".join(""" WARNING: ignoring signal %s. This process should not be interrupted to avoid database corruption. If you really need to terminate it, use SIGKILL. """.split()) print(msg % signum) prev_handlers = {} try: for signame in ("SIGTERM", "SIGINT", "SIGQUIT", "SIGHUP", "SIGUSR1", "SIGUSR2", "SIGBREAK"): if hasattr(signal, signame): signum = getattr(signal, signame) prev_handlers[signum] = signal.signal(signum, sighandler) master = BuildMaster(config['basedir']) master.config = master_cfg master.db.disownServiceParent() db = connector.DBConnector(basedir=config['basedir']) db.setServiceParent(master) yield db.setup(check_version=False, verbose=not config['quiet']) yield db.model.upgrade() yield db.masters.setAllMastersActiveLongTimeAgo() finally: # restore previous signal handlers for signum, handler in prev_handlers.items(): signal.signal(signum, handler)
def upgradeDatabase(config, master_cfg): if not config["quiet"]: print("upgrading database (%s)" % (stripUrlPassword(master_cfg.db["db_url"]))) master = BuildMaster(config["basedir"]) master.config = master_cfg master.db.disownServiceParent() db = connector.DBConnector(basedir=config["basedir"]) db.setServiceParent(master) yield db.setup(check_version=False, verbose=not config["quiet"]) yield db.model.upgrade() yield db.masters.setAllMastersActiveLongTimeAgo()
def setup(self, check_version=True, verbose=True): db_url = self.configured_url = self.master.config.db["db_url"] log.msg("Setting up database with URL %r" % util.stripUrlPassword(db_url)) # set up the engine and pool self._engine = enginestrategy.create_engine(db_url, basedir=self.basedir) self.pool = pool.DBThreadPool(self._engine, verbose=verbose) # make sure the db is up to date, unless specifically asked not to if check_version: current = yield self.model.is_current() if not current: for l in upgrade_message.format(basedir=self.master.basedir).split("\n"): log.msg(l) raise exceptions.DatabaseNotReadyError()
def setup(self, check_version=True, verbose=True): db_url = self.configured_url = self.master.config.db['db_url'] log.msg("Setting up database with URL %r" % util.stripUrlPassword(db_url)) # set up the engine and pool self._engine = enginestrategy.create_engine(db_url, basedir=self.basedir) self.pool = pool.DBThreadPool( self._engine, reactor=self.master.reactor, verbose=verbose) # make sure the db is up to date, unless specifically asked not to if check_version: if db_url == 'sqlite://': # Using in-memory database. Since it is reset after each process # restart, `buildbot upgrade-master` cannot be used (data is not # persistent). Upgrade model here to allow startup to continue. self.model.upgrade() current = yield self.model.is_current() if not current: for l in upgrade_message.format(basedir=self.master.basedir).split('\n'): log.msg(l) raise exceptions.DatabaseNotReadyError()
def test_username_pass_with_at(self): self.assertEqual( util.stripUrlPassword('http://[email protected]:[email protected]/bar'), 'http://[email protected]:[email protected]/bar')
def test_username_pass(self): self.assertEqual(util.stripUrlPassword('http://*****:*****@foo.com/bar'), 'http://*****:*****@foo.com/bar')
def test_username(self): self.assertEqual(util.stripUrlPassword('http://[email protected]/bar'), 'http://[email protected]/bar')
def test_simple_url(self): self.assertEqual(util.stripUrlPassword('http://foo.com/bar'), 'http://foo.com/bar')