Esempio n. 1
0
    def __init__(self,
                 reactor,
                 master_id=fakedb.FakeBuildRequestsComponent.MASTER_ID):
        super().__init__()
        self._master_id = master_id
        self.reactor = reactor
        self.objectids = {}
        self.config = config.MasterConfig()
        self.caches = FakeCaches()
        self.pbmanager = pbmanager.FakePBManager()
        self.initLock = defer.DeferredLock()
        self.basedir = 'basedir'
        self.botmaster = FakeBotMaster()
        self.botmaster.setServiceParent(self)
        self.name = 'fake:/master'
        self.masterid = master_id
        self.workers = bworkermanager.FakeWorkerManager()
        self.workers.setServiceParent(self)
        self.machine_manager = FakeMachineManager()
        self.machine_manager.setServiceParent(self)
        self.log_rotation = FakeLogRotation()
        self.db = mock.Mock()
        self.next_objectid = 0
        self.config_version = 0

        def getObjectId(sched_name, class_name):
            k = (sched_name, class_name)
            try:
                rv = self.objectids[k]
            except KeyError:
                rv = self.objectids[k] = self.next_objectid
                self.next_objectid += 1
            return defer.succeed(rv)

        self.db.state.getObjectId = getObjectId
Esempio n. 2
0
    def __init__(self, master_id=fakedb.FakeBuildRequestsComponent.MASTER_ID):
        service.MasterService.__init__(self)
        self._master_id = master_id
        self.objectids = []
        self.config = config.MasterConfig()
        self.caches = FakeCaches()
        self.pbmanager = pbmanager.FakePBManager()
        self.basedir = 'basedir'
        self.botmaster = FakeBotMaster()
        self.botmaster.setServiceParent(self)
        self.status = FakeStatus()
        self.status.setServiceParent(self)
        self.name = 'fake:/master'
        self.masterid = master_id
        self.buildslaves = bslavemanager.FakeBuildslaveManager()
        self.buildslaves.setServiceParent(self)
        self.log_rotation = FakeLogRotation()
        self.db = mock.Mock()
        self.next_objectid = 0

        def getObjectId(sched_name, class_name):
            k = (sched_name, class_name)
            try:
                rv = self.objectids[k]
            except KeyError:
                rv = self.objectids[k] = self.next_objectid
                self.next_objectid += 1
            return defer.succeed(rv)
        self.db.state.getObjectId = getObjectId
Esempio n. 3
0
 def test_setServiceParent_started(self):
     master = self.master = fakemaster.make_master()
     botmaster = FakeBotMaster(master)
     botmaster.startService()
     bs = self.ConcreteBuildSlave('bot', 'pass')
     bs.setServiceParent(botmaster)
     self.assertEqual(bs.botmaster, botmaster)
     self.assertEqual(bs.master, master)
Esempio n. 4
0
 def test_setServiceParent_started(self):
     master = self.master
     botmaster = FakeBotMaster(master)
     botmaster.startService()
     bs = self.ConcreteBuildSlave('bot', 'pass')
     bs.setServiceParent(botmaster)
     self.assertEqual(bs.botmaster, botmaster)
     self.assertEqual(bs.master, master)
Esempio n. 5
0
 def test_setServiceParent_slaveLocks(self):
     """
     http://trac.buildbot.net/ticket/2278
     """
     master = self.master = fakemaster.make_master()
     botmaster = FakeBotMaster(master)
     botmaster.startService()
     lock = locks.SlaveLock('lock')
     bs = self.ConcreteBuildSlave('bot', 'pass', locks = [lock.access("counting")])
     bs.setServiceParent(botmaster)
Esempio n. 6
0
 def test_setServiceParent_slaveLocks(self):
     """
     http://trac.buildbot.net/ticket/2278
     """
     master = self.master = fakemaster.make_master()
     botmaster = FakeBotMaster(master)
     botmaster.startService()
     lock = locks.SlaveLock('lock')
     bs = self.ConcreteBuildSlave('bot', 'pass', locks=[lock])
     bs.setServiceParent(botmaster)
Esempio n. 7
0
 def test_setServiceParent_masterLocks(self):
     """
     http://trac.buildbot.net/ticket/2278
     """
     master = self.master
     botmaster = FakeBotMaster(master)
     botmaster.startService()
     lock = locks.MasterLock('masterlock')
     bs = self.ConcreteBuildSlave('bot', 'pass', locks = [lock.access("counting")])
     bs.setServiceParent(botmaster)
Esempio n. 8
0
class FakeMaster(service.MasterService):
    """
    Create a fake Master instance: a Mock with some convenience
    implementations:

    - Non-caching implementation for C{self.caches}
    """
    def __init__(self,
                 reactor,
                 master_id=fakedb.FakeBuildRequestsComponent.MASTER_ID):
        super().__init__()
        self._master_id = master_id
        self.reactor = reactor
        self.objectids = {}
        self.config = config.MasterConfig()
        self.caches = FakeCaches()
        self.pbmanager = pbmanager.FakePBManager()
        self.initLock = defer.DeferredLock()
        self.basedir = 'basedir'
        self.botmaster = FakeBotMaster()
        self.botmaster.setServiceParent(self)
        self.status = FakeStatus()
        self.status.setServiceParent(self)
        self.name = 'fake:/master'
        self.masterid = master_id
        self.workers = bworkermanager.FakeWorkerManager()
        self.workers.setServiceParent(self)
        self.machine_manager = FakeMachineManager()
        self.machine_manager.setServiceParent(self)
        self.log_rotation = FakeLogRotation()
        self.db = mock.Mock()
        self.next_objectid = 0
        self.config_version = 0

        def getObjectId(sched_name, class_name):
            k = (sched_name, class_name)
            try:
                rv = self.objectids[k]
            except KeyError:
                rv = self.objectids[k] = self.next_objectid
                self.next_objectid += 1
            return defer.succeed(rv)

        self.db.state.getObjectId = getObjectId

    def getObjectId(self):
        return defer.succeed(self._master_id)

    def subscribeToBuildRequests(self, callback):
        pass
Esempio n. 9
0
class FakeMaster(service.MasterService):

    """
    Create a fake Master instance: a Mock with some convenience
    implementations:

    - Non-caching implementation for C{self.caches}
    """

    def __init__(self, reactor,
                 master_id=fakedb.FakeBuildRequestsComponent.MASTER_ID):
        super().__init__()
        self._master_id = master_id
        self.reactor = reactor
        self.objectids = {}
        self.config = config.MasterConfig()
        self.caches = FakeCaches()
        self.pbmanager = pbmanager.FakePBManager()
        self.initLock = defer.DeferredLock()
        self.basedir = 'basedir'
        self.botmaster = FakeBotMaster()
        self.botmaster.setServiceParent(self)
        self.status = FakeStatus()
        self.status.setServiceParent(self)
        self.name = 'fake:/master'
        self.masterid = master_id
        self.workers = bworkermanager.FakeWorkerManager()
        self.workers.setServiceParent(self)
        self.machine_manager = FakeMachineManager()
        self.machine_manager.setServiceParent(self)
        self.log_rotation = FakeLogRotation()
        self.db = mock.Mock()
        self.next_objectid = 0

        def getObjectId(sched_name, class_name):
            k = (sched_name, class_name)
            try:
                rv = self.objectids[k]
            except KeyError:
                rv = self.objectids[k] = self.next_objectid
                self.next_objectid += 1
            return defer.succeed(rv)
        self.db.state.getObjectId = getObjectId

    def getObjectId(self):
        return defer.succeed(self._master_id)

    def subscribeToBuildRequests(self, callback):
        pass
Esempio n. 10
0
    def test_results_are_correctly_filtered_for_user(self):
        first_user_builds_count = 15
        second_user_builds_count = 30
        second_user_max_build_id = first_user_builds_count + second_user_builds_count

        example_data = [
            fakedb.Buildset(id=2, sourcestampsetid=2, reason='[ first_user ]'),
            fakedb.Buildset(id=3, sourcestampsetid=2,
                            reason='[ second_user ]'),
            fakedb.BuildRequest(id=3,
                                buildsetid=2,
                                buildername="builder2",
                                complete=1,
                                results=7),
            fakedb.BuildRequest(id=4,
                                buildsetid=3,
                                buildername="builder3",
                                complete=1,
                                results=7),
        ] + [
            fakedb.Build(id=i, number=i + 2, brid=3, slavename='slave-02')
            for i in xrange(first_user_builds_count)
        ] + [
            fakedb.Build(id=i, number=i + 2, brid=4, slavename='slave-02')
            for i in xrange(first_user_builds_count, second_user_max_build_id)
        ]

        yield self.insertTestData(example_data)

        second_user_builds = yield self.db.builds.getLastBuildsOwnedBy(
            "second_user", FakeBotMaster(self.master))
        self.assertEqual(len(second_user_builds), second_user_builds_count)
        self.assertEqual(
            self._collect_ids(second_user_builds, 'builds_id'),
            range(first_user_builds_count, second_user_max_build_id))
        def make_master(_):
            # don't create child services
            self.patch(master.BuildMaster, 'create_child_services',
                       lambda self: None)

            # patch out a few other annoying things the master likes to do
            self.patch(monkeypatches, 'patch_all', lambda: None)
            self.patch(signal, 'signal', lambda sig, hdlr: None)
            # XXX temporary
            self.patch(master, 'Status', lambda master: mock.Mock())

            master.BuildMaster.masterHeartbeatService = mock.Mock()
            self.reactor = self.make_reactor()
            self.master = master.BuildMaster(self.basedir,
                                             reactor=self.reactor,
                                             config_loader=DefaultLoader())
            self.master.sendBuildbotNetUsageData = mock.Mock()
            self.master.botmaster = FakeBotMaster()
            self.db = self.master.db = fakedb.FakeDBConnector(self)
            self.db.setServiceParent(self.master)
            self.mq = self.master.mq = fakemq.FakeMQConnector(self)
            self.mq.setServiceParent(self.master)
            self.data = self.master.data = fakedata.FakeDataConnector(
                self.master, self)
            self.data.setServiceParent(self.master)
Esempio n. 12
0
    def __init__(self, master_id=fakedb.FakeBuildRequestsComponent.MASTER_ID):
        service.MasterService.__init__(self)
        self._master_id = master_id
        self.objectids = []
        self.config = config.MasterConfig()
        self.caches = FakeCaches()
        self.pbmanager = pbmanager.FakePBManager()
        self.basedir = 'basedir'
        self.botmaster = FakeBotMaster()
        self.botmaster.setServiceParent(self)
        self.status = FakeStatus()
        self.status.setServiceParent(self)
        self.name = 'fake:/master'
        self.masterid = master_id
        self.workers = bworkermanager.FakeWorkerManager()
        self.workers.setServiceParent(self)
        self.log_rotation = FakeLogRotation()
        self.db = mock.Mock()
        self.next_objectid = 0

        def getObjectId(sched_name, class_name):
            k = (sched_name, class_name)
            try:
                rv = self.objectids[k]
            except KeyError:
                rv = self.objectids[k] = self.next_objectid
                self.next_objectid += 1
            return defer.succeed(rv)
        self.db.state.getObjectId = getObjectId
Esempio n. 13
0
    def setUp(self):
        self.setup_test_reactor()
        self.setUpLogging()
        self.basedir = os.path.abspath('basedir')
        yield self.setUpDirs(self.basedir)

        # don't create child services
        self.patch(master.BuildMaster, 'create_child_services',
                   lambda self: None)

        # patch out a few other annoying things the master likes to do
        self.patch(monkeypatches, 'patch_all', lambda: None)
        self.patch(signal, 'signal', lambda sig, hdlr: None)

        master.BuildMaster.masterHeartbeatService = mock.Mock()
        self.master = master.BuildMaster(self.basedir,
                                         reactor=self.reactor,
                                         config_loader=DefaultLoader())
        self.master.sendBuildbotNetUsageData = mock.Mock()
        self.master.botmaster = FakeBotMaster()
        self.db = self.master.db = fakedb.FakeDBConnector(self)
        yield self.db.setServiceParent(self.master)
        self.mq = self.master.mq = fakemq.FakeMQConnector(self)
        yield self.mq.setServiceParent(self.master)
        self.data = self.master.data = fakedata.FakeDataConnector(
            self.master, self)
        yield self.data.setServiceParent(self.master)
Esempio n. 14
0
    def setUp(self):
        self.master = fakemaster.make_master(wantDb=True, testcase=self)
        self.botmaster = FakeBotMaster(self.master)

        self.clock = task.Clock()
        self.patch(reactor, 'callLater', self.clock.callLater)
        self.patch(reactor, 'seconds', self.clock.seconds)
Esempio n. 15
0
 def __init__(self, master_id=fakedb.FakeBuildRequestsComponent.MASTER_ID):
     self._master_id = master_id
     self.config = config.MasterConfig()
     self.caches = FakeCaches()
     self.pbmanager = pbmanager.FakePBManager()
     self.basedir = 'basedir'
     self.botmaster = FakeBotMaster(master=self)
     self.botmaster.parent = self
     self.status = FakeStatus(self)
     self.status.master = self
Esempio n. 16
0
 def __init__(self, master_id=fakedb.FakeBuildRequestsComponent.MASTER_ID):
     self._master_id = master_id
     self.config = config.MasterConfig()
     self.caches = FakeCaches()
     self.pbmanager = pbmanager.FakePBManager()
     self.basedir = 'basedir'
     self.botmaster = FakeBotMaster(master=self)
     self.botmaster.parent = self
     self.status = FakeStatus()
     self.status.master = self
     self.buildrequest_merger = FakeBuildRequestMerger(master=self)
     self.locks = {}
     self.is_changing_services = None
Esempio n. 17
0
 def __init__(self, master_id=fakedb.FakeBuildRequestsComponent.MASTER_ID):
     self._master_id = master_id
     self.config = config.MasterConfig()
     self.caches = FakeCaches()
     self.pbmanager = pbmanager.FakePBManager()
     self.basedir = 'basedir'
     self.botmaster = FakeBotMaster(master=self)
     self.botmaster.parent = self
     self.status = FakeStatus(self)
     self.status.master = self
     self.name = 'fake:/master'
     self.masterid = master_id
     self.buildslaves = bslavemanager.FakeBuildslaveManager(self)
     self.log_rotation = FakeLogRotation()
Esempio n. 18
0
    def test_results_are_correctly_limited_by_builds_count(self):
        builds_count = self.mybuild_limit + 10
        example_data = [
            fakedb.Buildset(id=2, sourcestampsetid=2, reason='[ first_user ]'),
            fakedb.BuildRequest(id=3,
                                buildsetid=2,
                                buildername="builder2",
                                complete=1,
                                results=7),
        ] + [
            fakedb.Build(id=i, number=i + 2, brid=3, slavename='slave-02')
            for i in xrange(builds_count)
        ]
        yield self.insertTestData(example_data)

        first_user_builds = yield self.db.builds.getLastBuildsOwnedBy(
            "first_user", FakeBotMaster(self.master))
        self.assertEqual(len(first_user_builds), self.mybuild_limit)
        self.assertEqual(self._collect_ids(first_user_builds, 'builds_id'),
                         range(self.mybuild_limit))