Ejemplo n.º 1
0
    def __init__(self, master, testcase):
        service.AsyncMultiService.__init__(self)
        self.setServiceParent(master)
        self.updates = FakeUpdates(testcase)
        self.updates.setServiceParent(self)

        # get and control are delegated to a real connector,
        # after some additional assertions
        self.realConnector = connector.DataConnector()
        self.realConnector.setServiceParent(self)
        self.rtypes = self.realConnector.rtypes
Ejemplo n.º 2
0
    def create_child_services(self):
        # note that these are order-dependent.  If you get the order wrong,
        # you'll know it, as the master will fail to start.

        self.metrics = metrics.MetricLogObserver()
        self.metrics.setServiceParent(self)

        self.caches = cache.CacheManager()
        self.caches.setServiceParent(self)

        self.pbmanager = buildbot.pbmanager.PBManager()
        self.pbmanager.setServiceParent(self)

        self.buildslaves = bslavemanager.BuildslaveManager(self)
        self.buildslaves.setServiceParent(self)

        self.change_svc = ChangeManager(self)
        self.change_svc.setServiceParent(self)

        self.botmaster = BotMaster(self)
        self.botmaster.setServiceParent(self)

        self.scheduler_manager = SchedulerManager(self)
        self.scheduler_manager.setServiceParent(self)

        self.user_manager = UserManagerManager(self)
        self.user_manager.setServiceParent(self)

        self.db = dbconnector.DBConnector(self, self.basedir)
        self.db.setServiceParent(self)

        self.mq = mqconnector.MQConnector(self)
        self.mq.setServiceParent(self)

        self.data = dataconnector.DataConnector(self)
        self.data.setServiceParent(self)

        self.www = wwwservice.WWWService(self)
        self.www.setServiceParent(self)

        self.debug = debug.DebugServices(self)
        self.debug.setServiceParent(self)

        self.status = Status(self)
        self.status.setServiceParent(self)

        @defer.inlineCallbacks
        def heartbeat():
            if self.masterid is not None:
                yield self.data.updates.masterActive(name=self.name,
                                                     masterid=self.masterid)
            yield self.data.updates.expireMasters()
        self.masterHeartbeatService = internet.TimerService(60, heartbeat)
Ejemplo n.º 3
0
 def test_start_stop(self):
     self.master = fakemaster.make_master(self)
     self.master.data = self.data = connector.DataConnector()
     yield self.data.setServiceParent(self.master)
     self.graphql = GraphQLConnector()
     yield self.graphql.setServiceParent(self.master)
     yield self.master.startService()
     self.master.config.www = {'graphql': {}}
     self.graphql.reconfigServiceWithBuildbotConfig(self.master.config)
     self.assertIsNotNone(self.graphql.asyncio_loop)
     yield self.master.stopService()
     self.assertIsNone(self.graphql.asyncio_loop)
Ejemplo n.º 4
0
    def setUp(self):
        # set up a full master serving HTTP
        yield self.setUpRealDatabase(table_names=['masters', 'objects', 'object_state'],
                                     sqlite_memory=False)

        master = fakemaster.FakeMaster(reactor)

        master.config.db = dict(db_url=self.db_url)
        master.db = dbconnector.DBConnector('basedir')
        yield master.db.setServiceParent(master)
        yield master.db.setup(check_version=False)

        master.config.mq = dict(type='simple')
        master.mq = mqconnector.MQConnector()
        yield master.mq.setServiceParent(master)
        yield master.mq.setup()

        master.data = dataconnector.DataConnector()
        yield master.data.setServiceParent(master)

        master.config.www = dict(
            port='tcp:0:interface=127.0.0.1',
            debug=True,
            auth=auth.NoAuth(),
            authz=authz.Authz(),
            avatar_methods=[],
            logfileName='http.log')
        master.www = wwwservice.WWWService()
        yield master.www.setServiceParent(master)
        yield master.www.startService()
        yield master.www.reconfigServiceWithBuildbotConfig(master.config)
        session = mock.Mock()
        session.uid = "0"
        master.www.site.sessionFactory = mock.Mock(return_value=session)

        # now that we have a port, construct the real URL and insert it into
        # the config.  The second reconfig isn't really required, but doesn't
        # hurt.
        self.url = 'http://127.0.0.1:%d/' % master.www.getPortnum()
        self.url = unicode2bytes(self.url)
        master.config.buildbotURL = self.url
        yield master.www.reconfigServiceWithBuildbotConfig(master.config)

        self.master = master

        # build an HTTP agent, using an explicit connection pool if Twisted
        # supports it (Twisted 13.0.0 and up)
        if hasattr(client, 'HTTPConnectionPool'):
            self.pool = client.HTTPConnectionPool(reactor)
            self.agent = client.Agent(reactor, pool=self.pool)
        else:
            self.pool = None
            self.agent = client.Agent(reactor)
Ejemplo n.º 5
0
 def setUp(self):
     if not graphql:
         raise unittest.SkipTest(
             'Test requires graphql-core module installed')
     self.setup_test_reactor(use_asyncio=True)
     self.master = fakemaster.make_master(self)
     # don't load by default
     self.all_submodules = connector.DataConnector.submodules
     self.patch(connector.DataConnector, 'submodules', [])
     self.master.data = self.data = connector.DataConnector()
     yield self.data.setServiceParent(self.master)
     self.graphql = GraphQLConnector()
     yield self.graphql.setServiceParent(self.master)
Ejemplo n.º 6
0
def dataspec(config):
    master = yield fakemaster.make_master()
    data = connector.DataConnector(master)

    dirs = os.path.dirname(config['out'])
    if dirs and not os.path.exists(dirs):
        os.makedirs(dirs)

    with open(config['out'], "w") as f:
        if config['global'] is not None:
            f.write("window." + config['global'] + '=')
        f.write(json.dumps(data.allEndpoints(), indent=2))
    print "written", config['out']
    defer.returnValue(0)
Ejemplo n.º 7
0
def dataspec(config):
    master = yield fakemaster.make_master()
    data = connector.DataConnector(master)
    if config['out'] != '--':
        dirs = os.path.dirname(config['out'])
        if dirs and not os.path.exists(dirs):
            os.makedirs(dirs)
        f = open(config['out'], "w")
    else:
        f = sys.stdout
    if config['global'] is not None:
        f.write("window." + config['global'] + '=')
    f.write(json.dumps(data.allEndpoints(), indent=2))
    f.close()
    defer.returnValue(0)
Ejemplo n.º 8
0
def gengraphql(config):
    master = yield fakemaster.make_master(None, wantRealReactor=True)
    data = connector.DataConnector()
    yield data.setServiceParent(master)

    if config['out'] != '--':
        dirs = os.path.dirname(config['out'])
        if dirs and not os.path.exists(dirs):
            os.makedirs(dirs)
        f = open(config['out'], "w")
    else:
        f = sys.stdout
    schema = data.genGraphQLSchema()
    f.write(schema)
    return 0
Ejemplo n.º 9
0
    def setUp(self):
        # set up a full master serving HTTP
        yield self.setUpRealDatabase(table_names=['masters'],
                                     sqlite_memory=False)

        master = fakemaster.FakeMaster()

        master.config.db = dict(db_url=self.db_url)
        master.db = dbconnector.DBConnector(master, 'basedir')
        yield master.db.setup(check_version=False)

        master.config.mq = dict(type='simple')
        master.mq = mqconnector.MQConnector(master)
        master.mq.setup()

        master.data = dataconnector.DataConnector(master)

        master.config.www = dict(port='tcp:0:interface=127.0.0.1',
                                 debug=True,
                                 auth=auth.NoAuth(),
                                 url="not yet known",
                                 avatar_methods=[])
        master.www = wwwservice.WWWService(master)
        yield master.www.startService()
        yield master.www.reconfigService(master.config)

        # now that we have a port, construct the real URL and insert it into
        # the config.  The second reconfig isn't really required, but doesn't
        # hurt.
        self.url = 'http://127.0.0.1:%d/' % master.www.getPortnum()
        master.config.www['url'] = self.url
        yield master.www.reconfigService(master.config)

        self.master = master

        # build an HTTP agent, using an explicit connection pool if Twisted
        # supports it (Twisted 13.0.0 and up)
        if hasattr(client, 'HTTPConnectionPool'):
            self.pool = client.HTTPConnectionPool(reactor)
            self.agent = client.Agent(reactor, pool=self.pool)
        else:
            self.pool = None
            self.agent = client.Agent(reactor)
Ejemplo n.º 10
0
def gengraphql(config):
    master = yield fakemaster.make_master(None, wantRealReactor=True)
    data = connector.DataConnector()
    yield data.setServiceParent(master)
    graphql = GraphQLConnector()
    yield graphql.setServiceParent(master)
    graphql.data = data
    master.config.www = dict(graphql={"debug": True})
    graphql.reconfigServiceWithBuildbotConfig(master.config)
    yield master.startService()
    if config['out'] != '--':
        dirs = os.path.dirname(config['out'])
        if dirs and not os.path.exists(dirs):
            os.makedirs(dirs)
        f = open(config['out'], "w", encoding='utf-8')  # noqa pylint: disable=consider-using-with
    else:
        f = sys.stdout
    schema = graphql.get_schema()
    f.write(schema)
    f.close()
    yield master.stopService()
    return 0
Ejemplo n.º 11
0
 def setUp(self):
     self.master = fakemaster.make_master()
     # don't load by default
     self.patch(connector.DataConnector, 'submodules', [])
     self.data = connector.DataConnector()
     self.data.setServiceParent(self.master)
Ejemplo n.º 12
0
 def setUp(self):
     self.setup_test_reactor()
     self.master = fakemaster.make_master(self, wantMq=True)
     self.data = connector.DataConnector()
     yield self.data.setServiceParent(self.master)
Ejemplo n.º 13
0
    def create_child_services(self):
        # note that these are order-dependent.  If you get the order wrong,
        # you'll know it, as the master will fail to start.

        self.metrics = metrics.MetricLogObserver()
        self.metrics.setServiceParent(self)

        self.caches = cache.CacheManager()
        self.caches.setServiceParent(self)

        self.pbmanager = buildbot.pbmanager.PBManager()
        self.pbmanager.setServiceParent(self)

        self.workers = workermanager.WorkerManager(self)
        self.workers.setServiceParent(self)

        self.change_svc = ChangeManager()
        self.change_svc.setServiceParent(self)

        self.botmaster = BotMaster()
        self.botmaster.setServiceParent(self)

        self.scheduler_manager = SchedulerManager()
        self.scheduler_manager.setServiceParent(self)

        self.user_manager = UserManagerManager(self)
        self.user_manager.setServiceParent(self)

        self.db = dbconnector.DBConnector(self.basedir)
        self.db.setServiceParent(self)

        self.wamp = wampconnector.WampConnector()
        self.wamp.setServiceParent(self)

        self.mq = mqconnector.MQConnector()
        self.mq.setServiceParent(self)

        self.data = dataconnector.DataConnector()
        self.data.setServiceParent(self)

        self.www = wwwservice.WWWService()
        self.www.setServiceParent(self)

        self.debug = debug.DebugServices()
        self.debug.setServiceParent(self)

        self.status = Status()
        self.status.setServiceParent(self)

        self.service_manager = service.BuildbotServiceManager()
        self.service_manager.setServiceParent(self)
        self.service_manager.reconfig_priority = 1000

        self.masterHouskeepingTimer = 0

        @defer.inlineCallbacks
        def heartbeat():
            if self.masterid is not None:
                yield self.data.updates.masterActive(name=self.name,
                                                     masterid=self.masterid)
            # force housekeeping once a day
            yield self.data.updates.expireMasters(
                (self.masterHouskeepingTimer % (24 * 60)) == 0)
            self.masterHouskeepingTimer += 1

        self.masterHeartbeatService = internet.TimerService(60, heartbeat)
Ejemplo n.º 14
0
 def setUp(self):
     self.setUpEndpoint()
     # replace fakeConnector with real DataConnector
     self.master.data.disownServiceParent()
     self.master.data = connector.DataConnector()
     self.master.data.setServiceParent(self.master)
Ejemplo n.º 15
0
 def setUp(self):
     self.setUpTestReactor()
     self.master = fakemaster.make_master(self)
     self.data = connector.DataConnector()
     yield self.data.setServiceParent(self.master)
Ejemplo n.º 16
0
 def setUp(self):
     self.master = fakemaster.make_master(testcase=self,
                                          wantMq=True)
     self.data = connector.DataConnector()
     self.data.setServiceParent(self.master)
Ejemplo n.º 17
0
    def setUp(self):
        yield self.setUpRealDatabase(table_names=[
            'objects', 'object_state', 'masters', 'workers',
            'configured_workers', 'connected_workers', 'builder_masters',
            'builders'
        ],
                                     sqlite_memory=False)
        master = fakemaster.FakeMaster(reactor)

        master.data = dataconnector.DataConnector()
        master.data.setServiceParent(master)

        master.config.db = dict(db_url=self.db_url)
        master.db = dbconnector.DBConnector('basedir')
        master.db.setServiceParent(master)
        yield master.db.setup(check_version=False)

        master.config.mq = dict(type='simple')
        master.mq = mqconnector.MQConnector()
        master.mq.setServiceParent(master)
        master.mq.setup()

        master.config.www = dict(port='tcp:0:interface=127.0.0.1',
                                 debug=True,
                                 auth=auth.NoAuth(),
                                 authz=authz.Authz(),
                                 avatar_methods=[],
                                 logfileName='http.log')
        master.www = wwwservice.WWWService()
        master.www.setServiceParent(master)
        yield master.www.startService()
        yield master.www.reconfigServiceWithBuildbotConfig(master.config)
        session = mock.Mock()
        session.uid = "0"
        master.www.site.sessionFactory = mock.Mock(return_value=session)

        # now that we have a port, construct the real URL and insert it into
        # the config.  The second reconfig isn't really required, but doesn't
        # hurt.
        self.url = 'http://127.0.0.1:%d/' % master.www.getPortnum()
        self.url = unicode2bytes(self.url)
        master.config.buildbotURL = self.url
        yield master.www.reconfigServiceWithBuildbotConfig(master.config)

        self.master = master

        self.agent = client.Agent(reactor)

        # create a telegram bot service
        tb = master.config.services['TelegramBot'] = telegram.TelegramBot(
            bot_token='12345:secret',
            useWebhook=True,
            chat_ids=[-123456],
            notify_events=['worker'])
        tb._get_http = self.get_http
        tb.setServiceParent(self.master)
        self.bot_url = self.url + b"telegram12345:secret"

        yield tb.startService()

        self.sent_messages = []

        def send_message(chat, message, **kwargs):
            self.sent_messages.append((chat, message))

        tb.bot.send_message = send_message
Ejemplo n.º 18
0
 def setUp(self):
     self.setUpEndpoint()
     # replace fakeConnector with real DataConnector
     self.master.data = connector.DataConnector(self.master)