Exemplo n.º 1
0
    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
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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()
Exemplo n.º 4
0
    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()
Exemplo n.º 5
0
    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()
Exemplo n.º 6
0
 def test_username_pass_with_at(self):
     self.assertEqual(
         util.stripUrlPassword('http://[email protected]:[email protected]/bar'),
         'http://[email protected]:[email protected]/bar')
Exemplo n.º 7
0
 def test_username_pass(self):
     self.assertEqual(util.stripUrlPassword('http://*****:*****@foo.com/bar'),
                      'http://*****:*****@foo.com/bar')
Exemplo n.º 8
0
 def test_username(self):
     self.assertEqual(util.stripUrlPassword('http://[email protected]/bar'),
                      'http://[email protected]/bar')
Exemplo n.º 9
0
 def test_simple_url(self):
     self.assertEqual(util.stripUrlPassword('http://foo.com/bar'),
                      'http://foo.com/bar')
Exemplo n.º 10
0
 def test_username(self):
     self.assertEqual(util.stripUrlPassword('http://[email protected]/bar'),
                      'http://[email protected]/bar')
Exemplo n.º 11
0
 def test_simple_url(self):
     self.assertEqual(util.stripUrlPassword('http://foo.com/bar'),
                      'http://foo.com/bar')
Exemplo n.º 12
0
 def test_username_pass_with_at(self):
     self.assertEqual(
         util.stripUrlPassword('http://[email protected]:[email protected]/bar'),
         'http://[email protected]:[email protected]/bar')
Exemplo n.º 13
0
 def test_username_pass(self):
     self.assertEqual(util.stripUrlPassword('http://*****:*****@foo.com/bar'),
                      'http://*****:*****@foo.com/bar')