Ejemplo n.º 1
0
 def test_configfile_default(self):
     """
     If neither configfile nor config_loader are specified, The default config_loader is a
     `FileLoader` pointing at `"master.cfg"`.
     """
     m = master.BuildMaster(".", reactor=reactor)
     self.assertEqual(m.config_loader, config.FileLoader(".", "master.cfg"))
 def test_0_9_0b5_config(self):
     with open(self.filename, "w") as f:
         f.write(sample_0_9_0b5)
     with assertProducesWarnings(
             DeprecatedWorkerNameWarning,
             messages_patterns=[
                 r"'buildbot\.plugins\.buildslave' plugins namespace is deprecated",
                 r"'slavenames' keyword argument is deprecated",
                 r"c\['slaves'\] key is deprecated"]):
         config.FileLoader(self.basedir, self.filename).loadConfig()
Ejemplo n.º 3
0
    def test_config_0_9_0b5_api_renamed(self):
        # Load configuration and start master.
        # TODO: check for expected warnings.

        self._write_config(sample_0_9_0b5_api_renamed)

        with assertNotProducesWarnings(DeprecatedWorkerAPIWarning):
            loaded_config = config.FileLoader(self.basedir,
                                              self.configfile).loadConfig()

        return self._run_master(loaded_config)
 def test_0_7_6_config(self):
     with open(self.filename, "w") as f:
         f.write(sample_0_7_6)
     with assertProducesWarnings(
             DeprecatedWorkerNameWarning,
             messages_patterns=[
                 r"BuildSlave was deprecated",
                 r"c\['slavePortnum'\] key is deprecated",
                 r"'slavename' keyword argument is deprecated",
                 r"c\['slaves'\] key is deprecated"]):
         config.FileLoader(self.basedir, self.filename).loadConfig()
Ejemplo n.º 5
0
def _loadConfig(basedir, configFile, quiet):
    try:
        config.FileLoader(basedir, configFile).loadConfig()
    except config.ConfigErrors as e:
        if not quiet:
            print("Configuration Errors:", file=sys.stderr)
            for e in e.errors:
                print("  " + e, file=sys.stderr)
        return 1

    if not quiet:
        print("Config file is good!")
    return 0
Ejemplo n.º 6
0
    def startMaster(self, sch, startWorker=False):
        BuildmasterConfig['schedulers'] = [sch]
        self.sch = sch

        BuildmasterConfig['status'] = []

        # mock reactor.stop (which trial *really* doesn't
        # like test code to call!)
        mock_reactor = mock.Mock(spec=reactor)
        mock_reactor.callWhenRunning = reactor.callWhenRunning
        mock_reactor.getThreadPool = reactor.getThreadPool
        mock_reactor.callFromThread = reactor.callFromThread

        # create the master and set its config
        m = self.master = master.BuildMaster(
            self.basedir, self.configfile, reactor=mock_reactor)
        m.config = config.FileLoader(
            self.basedir, self.configfile).loadConfig()

        # set up the db
        yield m.db.setup(check_version=False)
        yield m.db.model.create()

        # stub out m.db.setup since it was already called above
        m.db.setup = lambda: None

        # start the service
        yield m.startService()
        self.failIf(mock_reactor.stop.called,
                    "startService tried to stop the reactor; check logs")

        # wait until the scheduler is active
        yield waitFor(lambda: self.sch.active)

        # and, for Try_Userpass, until it's registered its port
        if isinstance(self.sch, trysched.Try_Userpass):
            def getSchedulerPort():
                if not self.sch.registrations:
                    return
                self.serverPort = self.sch.registrations[0].getPort()
                log.msg("Scheduler registered at port %d" % self.serverPort)
                return True
            yield waitFor(getSchedulerPort)

        # now start the fake worker
        if startWorker:
            self.worker = FakeRemoteWorker(self.serverPort)
            yield self.worker.start()
Ejemplo n.º 7
0
    def test_config_0_9_0b5(self):
        # Load configuration and start master.
        # TODO: check for expected warnings.
        self._write_config(sample_0_9_0b5)

        with assertProducesWarnings(
                DeprecatedWorkerNameWarning,
                messages_patterns=
            [
                r"'buildbot\.plugins\.buildslave' plugins namespace is deprecated",
                r"'slavenames' keyword argument is deprecated",
                r"c\['slaves'\] key is deprecated"
            ]):
            loaded_config = config.FileLoader(self.basedir,
                                              self.configfile).loadConfig()

        return self._run_master(loaded_config)
Ejemplo n.º 8
0
def loadConfig(config, configFileName='master.cfg'):
    if not config['quiet']:
        print("checking {}".format(configFileName))

    try:
        master_cfg = config_module.FileLoader(
            config['basedir'], configFileName).loadConfig()
    except config_module.ConfigErrors as e:
        print("Errors loading configuration:")

        for msg in e.errors:
            print("  " + msg)
        return None
    except Exception:
        print("Errors loading configuration:")
        traceback.print_exc(file=sys.stdout)
        return None

    return master_cfg
Ejemplo n.º 9
0
    def __init__(self,
                 basedir,
                 configFileName=None,
                 umask=None,
                 reactor=None,
                 config_loader=None):
        service.AsyncMultiService.__init__(self)

        if reactor is None:
            from twisted.internet import reactor
        self.reactor = reactor

        self.setName("buildmaster")

        self.umask = umask

        self.basedir = basedir
        if basedir is not None:  # None is used in tests
            assert os.path.isdir(self.basedir)

        if config_loader is not None and configFileName is not None:
            raise config.ConfigErrors([
                "Can't specify both `config_loader` and `configFilename`.",
            ])
        elif config_loader is None:
            if configFileName is None:
                configFileName = 'master.cfg'
            config_loader = config.FileLoader(self.basedir, configFileName)
        self.config_loader = config_loader
        self.configFileName = configFileName

        # flag so we don't try to do fancy things before the master is ready
        self._master_initialized = False

        # set up child services
        self.create_child_services()

        # db configured values
        self.configured_db_url = None

        # configuration / reconfiguration handling
        self.config = config.MasterConfig()
        self.reconfig_active = False
        self.reconfig_requested = False
        self.reconfig_notifier = None

        # this stores parameters used in the tac file, and is accessed by the
        # WebStatus to duplicate those values.
        self.log_rotation = LogRotation()

        # local cache for this master's object ID
        self._object_id = None

        # Check environment is sensible
        check_functional_environment(self.config)

        # figure out local hostname
        try:
            self.hostname = os.uname()[1]  # only on unix
        except AttributeError:
            self.hostname = socket.getfqdn()

        # public attributes
        self.name = ("%s:%s" %
                     (self.hostname, os.path.abspath(self.basedir or '.')))
        self.name = self.name.decode('ascii', 'replace')
        self.masterid = None
Ejemplo n.º 10
0
 def test_0_9_0b5_api_renamed_config(self):
     with open(self.filename, "w") as f:
         f.write(sample_0_9_0b5_api_renamed)
     with assertNotProducesWarnings(DeprecatedWorkerAPIWarning):
         config.FileLoader(self.basedir, self.filename).loadConfig()
Ejemplo n.º 11
0
 def test_sample_config(self):
     filename = util.sibpath(runner.__file__, 'sample.cfg')
     with assertNotProducesWarnings(DeprecatedWorkerAPIWarning):
         config.FileLoader(self.basedir, filename).loadConfig()