def makeStatus(self): m = mock.Mock(name='master') self.db = m.db = fakedb.FakeDBConnector(m, self) m.basedir = r'C:\BASEDIR' m.botmaster.builderNames = [] s = master.Status(m) return s
def makeStatusClientPersp(self): m = mock.Mock(name='master') self.db = m.db = fakedb.FakeDBConnector(self) m.basedir = r'C:\BASEDIR' s = master.Status(m) persp = client.StatusClientPerspective(s) return persp
def setUp(self): self.master = fakemaster.make_master(testcase=self, wantMq=True, wantData=True, wantDb=True) # set the worker port to a loopback address with unspecified # port self.pbmanager = self.master.pbmanager = pbmanager.PBManager() self.pbmanager.setServiceParent(self.master) # remove the fakeServiceParent from fake service hierarchy, and replace by a real one yield self.master.workers.disownServiceParent() self.workers = self.master.workers = workermanager.WorkerManager( self.master) self.workers.setServiceParent(self.master) self.botmaster = botmaster.BotMaster() self.botmaster.setServiceParent(self.master) self.master.status = master.Status() self.master.status.setServiceParent(self.master) self.master.botmaster = self.botmaster self.master.data.updates.workerConfigured = lambda *a, **k: None yield self.master.startService() self.buildworker = None self.port = None self.workerworker = None self.connector = None self._detach_deferreds = [] # patch in our FakeBuilder for the regular Builder class self.patch(botmaster, 'Builder', FakeBuilder)
def test_change_consumer_cb_nobody_interested(self): m = mock.Mock(name='master') status = master.Status() yield status.change_consumer_cb('change.13.new', dict(changeid=13)) self.assertFalse(m.db.changes.getChange.called)
def setupStatus(self, b): m = Mock() m.buildbotURL = 'http://buildbot:8010/' m.basedir = '/basedir' s = master.Status(m) b.status = s return s
def setUp(self): self.master = fakemaster.make_master(testcase=self, wantMq=True, wantData=True, wantDb=True) # set the slave port to a loopback address with unspecified # port self.pbmanager = self.master.pbmanager = pbmanager.PBManager() self.pbmanager.setServiceParent(self.master) self.buildslaves = self.master.buildslaves = bslavemanager.BuildslaveManager(self.master) self.buildslaves.setServiceParent(self.master) self.botmaster = botmaster.BotMaster(self.master) self.botmaster.setServiceParent(self.master) self.master.status = master.Status(self.master) self.master.botmaster = self.botmaster self.master.data.updates.buildslaveConfigured = lambda *a, **k: None yield self.master.startService() self.buildslave = None self.port = None self.slavebuildslave = None self.connector = None self._detach_deferreds = [] # patch in our FakeBuilder for the regular Builder class self.patch(botmaster, 'Builder', FakeBuilder)
def setUp(self): self.setUpTestReactor() self.master = fakemaster.make_master(self, wantMq=True, wantData=True, wantDb=True) # set the worker port to a loopback address with unspecified # port self.pbmanager = self.master.pbmanager = pbmanager.PBManager() self.pbmanager.setServiceParent(self.master) # remove the fakeServiceParent from fake service hierarchy, and replace # by a real one yield self.master.workers.disownServiceParent() self.workers = self.master.workers = workermanager.WorkerManager( self.master) self.workers.setServiceParent(self.master) self.botmaster = botmaster.BotMaster() self.botmaster.setServiceParent(self.master) self.master.status = master.Status() self.master.status.setServiceParent(self.master) self.master.botmaster = self.botmaster self.master.data.updates.workerConfigured = lambda *a, **k: None yield self.master.startService() self.buildworker = None self.port = None self.workerworker = None # patch in our FakeBuilder for the regular Builder class self.patch(botmaster, 'Builder', FakeBuilder) self.client_connection_string_tpl = r"tcp:host=127.0.0.1:port={port}" self.tmpdirs = set()
def setupStep(self, *args, **kwargs): steps.BuildStepMixin.setupStep(self, *args, **kwargs) # This step reaches deeply into a number of parts of Buildbot. That # should be fixed! # set up a buildmaster that knows about two fake schedulers, a and b self.build.builder.botmaster.parent = m = fakemaster.make_master() m.db = fakedb.FakeDBConnector(self) m.status = master.Status(m) m.config.buildbotURL = "baseurl/" self.scheduler_a = a = FakeTriggerable(name='a', builderNames=['A']) self.scheduler_b = b = FakeTriggerable(name='b', builderNames=['B']) def allSchedulers(): return [a, b] m.allSchedulers = allSchedulers a.brids = {'A': 11} b.brids = {'B': 22} make_fake_br = lambda brid, name: fakedb.BuildRequest( id=brid, buildsetid=BRID_TO_BSID(brid), buildername=name) make_fake_build = lambda brid: fakedb.Build( brid=brid, id=BRID_TO_BID(brid), number=BRID_TO_BUILD_NUMBER(brid)) m.db.insertTestData([ make_fake_br(11, "A"), make_fake_br(22, "B"), make_fake_build(11), make_fake_build(22), ]) # the build has a getSourceStamp method def getSourceStamp(): return FakeSourceStamp(self.THIS_SSID, self.THIS_SS_SETID) self.build.getSourceStamp = getSourceStamp # the db has a addSourceStamp method def addSourceStamp(**kwargs): self.addSourceStamp_kwargs = kwargs return defer.succeed(self.NEW_SSID) m.db.sourcestamps.addSourceStamp = addSourceStamp # the db has a addSourceStampSet method def addSourceStampSet(): return defer.succeed(self.NEW_SS_SETID) m.db.sourcestampsets.addSourceStampSet = addSourceStampSet self.exp_add_sourcestamp = None self.exp_a_trigger = None self.exp_b_trigger = None self.exp_added_urls = []
def setupStep(self, step, sourcestampsInBuild=None, gotRevisionsInBuild=None, *args, **kwargs): sourcestamps = sourcestampsInBuild or [] got_revisions = gotRevisionsInBuild or {} steps.BuildStepMixin.setupStep(self, step, *args, **kwargs) # This step reaches deeply into a number of parts of Buildbot. That # should be fixed! # set up a buildmaster that knows about two fake schedulers, a and b m = fakemaster.make_master() self.build.builder.botmaster = m.botmaster m.db = fakedb.FakeDBConnector(self) m.status = master.Status(m) m.config.buildbotURL = "baseurl/" self.scheduler_a = a = FakeTriggerable(name='a') self.scheduler_b = b = FakeTriggerable(name='b') def allSchedulers(): return [a, b] m.allSchedulers = allSchedulers a.brids = {'A': 11} b.brids = {'B': 22} make_fake_br = lambda brid, name: fakedb.BuildRequest( id=brid, buildsetid=BRID_TO_BSID(brid), buildername=name) make_fake_build = lambda brid: fakedb.Build( brid=brid, id=BRID_TO_BID(brid), number=BRID_TO_BUILD_NUMBER(brid)) m.db.insertTestData([ make_fake_br(11, "A"), make_fake_br(22, "B"), make_fake_build(11), make_fake_build(22), ]) def getAllSourceStamps(): return sourcestamps self.build.getAllSourceStamps = getAllSourceStamps def getAllGotRevisions(): return got_revisions self.build.build_status.getAllGotRevisions = getAllGotRevisions self.exp_add_sourcestamp = None self.exp_a_trigger = None self.exp_b_trigger = None self.exp_added_urls = []
def makeStatus(self): m = fakemaster.make_master(wantData=True, testcase=self) self.db = m.db m.basedir = r'C:\BASEDIR' m.botmaster.builderNames = [] s = master.Status() s.setServiceParent(m) m.startService() return s
def setupStep(self, step, sourcestampsInBuild=None, gotRevisionsInBuild=None, *args, **kwargs): sourcestamps = sourcestampsInBuild or [] got_revisions = gotRevisionsInBuild or {} steps.BuildStepMixin.setupStep(self, step, *args, **kwargs) # This step reaches deeply into a number of parts of Buildbot. That # should be fixed! # set up a buildmaster that knows about two fake schedulers, a and b m = self.master m.db.checkForeignKeys = True self.build.builder.botmaster = m.botmaster m.status = master.Status() m.status.setServiceParent(m) m.config.buildbotURL = "baseurl/" m.scheduler_manager = FakeSchedulerManager() self.scheduler_a = a = FakeTriggerable(name='a') self.scheduler_b = b = FakeTriggerable(name='b') m.scheduler_manager.namedServices = dict(a=a, b=b) a.brids = {77: 11} b.brids = {78: 22} make_fake_br = lambda brid, builderid: fakedb.BuildRequest( id=brid, buildsetid=BRID_TO_BSID(brid), builderid=builderid) make_fake_build = lambda brid: fakedb.Build( buildrequestid=brid, id=BRID_TO_BID(brid), number=BRID_TO_BUILD_NUMBER(brid), masterid=9, buildslaveid=13) m.db.insertTestData([ fakedb.Builder(id=77, name='A'), fakedb.Builder(id=78, name='B'), fakedb.Master(id=9), fakedb.Buildset(id=2022), fakedb.Buildset(id=2011), fakedb.Buildslave(id=13, name="some:slave"), make_fake_br(11, 77), make_fake_br(22, 78), make_fake_build(11), make_fake_build(22), ]) def getAllSourceStamps(): return sourcestamps self.build.getAllSourceStamps = getAllSourceStamps def getAllGotRevisions(): return got_revisions self.build.build_status.getAllGotRevisions = getAllGotRevisions self.exp_add_sourcestamp = None self.exp_a_trigger = None self.exp_b_trigger = None self.exp_added_urls = []
def test_reconfigService(self): m = mock.Mock(name='master') status = master.Status(m) status.startService() config = mock.Mock() # add a status reciever sr0 = FakeStatusReceiver() config.status = [ sr0 ] wfd = defer.waitForDeferred( status.reconfigService(config)) yield wfd wfd.getResult() self.assertTrue(sr0.running) self.assertIdentical(sr0.master, m) # add a status reciever sr1 = FakeStatusReceiver() sr2 = FakeStatusReceiver() config.status = [ sr1, sr2 ] wfd = defer.waitForDeferred( status.reconfigService(config)) yield wfd wfd.getResult() self.assertFalse(sr0.running) self.assertIdentical(sr0.master, None) self.assertTrue(sr1.running) self.assertIdentical(sr1.master, m) self.assertTrue(sr2.running) self.assertIdentical(sr2.master, m) # reconfig with those two (a regression check) sr1 = FakeStatusReceiver() sr2 = FakeStatusReceiver() config.status = [ sr1, sr2 ] wfd = defer.waitForDeferred( status.reconfigService(config)) yield wfd wfd.getResult() # and back to nothing config.status = [ ] wfd = defer.waitForDeferred( status.reconfigService(config)) yield wfd wfd.getResult() self.assertIdentical(sr0.master, None) self.assertIdentical(sr1.master, None) self.assertIdentical(sr2.master, None)
def test_TriggerStepMultiMasterMode(self): m = fakemaster.FakeMaster() m.maybeStartBuildsForSlave = lambda slave: True m.status = master.Status(m) m.config.buildbotURL = "baseurl/" m.config.multiMaster = True m.db = fakedb.FakeDBConnector(self) scheduler_a = FakeTriggerable(name='a') m.allSchedulers = lambda: [scheduler_a] def trigger_sch(sourcestamps = None, set_props=None, triggeredbybrid=None, reason=None): rows = [ fakedb.MasterConfig(id=1, buildbotURL="build-master-01/", objectid=1), fakedb.MasterConfig(id=2, buildbotURL="build-master-02/", objectid=2), fakedb.SourceStampSet(id=1), fakedb.SourceStamp(id=1, sourcestampsetid=1, codebase='c', branch="az", repository="xz", revision="ww"), fakedb.Buildset(id=1, reason='because', sourcestampsetid=1), fakedb.BuildRequest(id=1, buildsetid=1, buildername="builder1", submitted_at=130000), fakedb.BuildRequest(id=2, buildsetid=1, buildername="builder2", submitted_at=130000), fakedb.BuildRequestClaim(brid=1, objectid=2, claimed_at=130000), fakedb.BuildRequestClaim(brid=2, objectid=1, claimed_at=130000), fakedb.Build(id=1, number=1, brid=1), fakedb.Build(id=2, number=1, brid=2)] d = m.db.insertTestData(rows) d.addCallback(lambda _: (SUCCESS, {'builder1': 1L, 'builder2': 2L})) return d scheduler_a.trigger = trigger_sch self.step = trigger.Trigger(schedulerNames=['a'], waitForFinish=True) self.step.addCompleteLog = lambda x,y: True self.step.step_status = Mock() self.step.step_status.getLogs = lambda: [] self.expected_urls = [] self.step.step_status.addURL = lambda text, path, results=None: \ self.expected_urls.append({'text': text, 'path': path}) self.step.build = fakebuild.FakeBuild() self.step.build.builder.botmaster = m.botmaster self.step.build.getAllSourceStamps = lambda: [] self.step.build.build_status.getAllGotRevisions = lambda: {} request = Mock() request.id = 1 self.step.build.requests = [request] self.remote = Mock(name="SlaveBuilder(remote)") yield self.step.startStep(self.remote) self.assertEquals(len(self.expected_urls), 2) self.assertTrue({'text': 'builder1 #1', 'path': 'build-master-02/builders/builder1/builds/1'} in self.expected_urls) self.assertTrue({'text': 'builder1 #1', 'path': 'build-master-02/builders/builder1/builds/1'} in self.expected_urls)
def setUp(self): self.master = fakemaster.make_master() # set the slave port to a loopback address with unspecified # port self.pbmanager = self.master.pbmanager = pbmanager.PBManager() self.pbmanager.startService() self.botmaster = botmaster.BotMaster(self.master) self.botmaster.startService() self.master.status = master.Status(self.master) self.buildslave = None self.port = None self.slavebuildslave = None self.connector = None self.detach_d = None
def test_reconfigServiceWithBuildbotConfig(self): m = mock.Mock(name='master') status = master.Status(m) status.startService() config = mock.Mock() # add a status reciever sr0 = FakeStatusReceiver() config.status = [sr0] yield status.reconfigServiceWithBuildbotConfig(config) self.assertTrue(sr0.running) self.assertIdentical(sr0.master, m) # add a status reciever sr1 = FakeStatusReceiver() sr2 = FakeStatusReceiver() config.status = [sr1, sr2] yield status.reconfigServiceWithBuildbotConfig(config) self.assertFalse(sr0.running) self.assertIdentical(sr0.master, None) self.assertTrue(sr1.running) self.assertIdentical(sr1.master, m) self.assertTrue(sr2.running) self.assertIdentical(sr2.master, m) # reconfig with those two (a regression check) sr1 = FakeStatusReceiver() sr2 = FakeStatusReceiver() config.status = [sr1, sr2] yield status.reconfigServiceWithBuildbotConfig(config) # and back to nothing config.status = [] yield status.reconfigServiceWithBuildbotConfig(config) self.assertIdentical(sr0.master, None) self.assertIdentical(sr1.master, None) self.assertIdentical(sr2.master, None)
def makeBuilder(self, name): self.bstatus = mock.Mock() self.factory = mock.Mock() self.master = fakemaster.make_master() self.master.status = master.Status(self.master) # only include the necessary required config builder_config = config.BuilderConfig(name=name, slavename="slv", builddir="bdir", slavebuilddir="sbdir", factory=self.factory) self.bldr = builder.Builder(builder_config.name, _addServices=False) self.master.db = self.db = fakedb.FakeDBConnector(self) self.bldr.master = self.master self.bldr.startService() mastercfg = config.MasterConfig() mastercfg.builders = [builder_config] return self.bldr.reconfigService(mastercfg)
def test_interruptConnectionLostShouldRetry(self): self.master = fakemaster.FakeMaster() self.master.maybeStartBuildsForSlave = lambda slave: True self.master.db = fakedb.FakeDBConnector(self) rows = [fakedb.SourceStampSet(id=1), fakedb.SourceStamp(id=1, sourcestampsetid=1, codebase='c', branch="az", repository="xz", revision="ww"), fakedb.Buildset(id=1, reason='because', sourcestampsetid=1), fakedb.BuildRequest(id=1, buildsetid=1, buildername="bldr", submitted_at=130000)] yield self.master.db.insertTestData(rows) self.master.status = master.Status(self.master) self.master.config.buildbotURL = "baseurl/" self.scheduler_a = a = FakeTriggerable(name='a') self.scheduler_b = b = FakeTriggerable(name='b') def allSchedulers(): return [a, b] self.master.allSchedulers = allSchedulers self.factory = factory.BuildFactory() self.step = trigger.Trigger(schedulerNames=['a'], waitForFinish=True) self.step.addCompleteLog = lambda x,y: True self.factory.addStep(self.step) config_args = dict(name="bldr", slavename="slv", builddir="bdir", slavebuilddir="sbdir", project='default', factory=self.factory) builder_config = config.BuilderConfig(**config_args) self.bldr = Builder(builder_config.name, _addServices=False) self.bldr.master = self.master self.bldr.botmaster = self.master.botmaster mastercfg = config.MasterConfig() mastercfg.builders = [ builder_config ] self.bldr.startService() yield self.bldr.reconfigService(mastercfg) def newBuild(buildrequests): self.build = Build(buildrequests) self.build.setStepFactories([fakebuild.FakeStepFactory(self.step)]) return self.build self.bldr.config.factory.newBuild = newBuild self.bldr.notifyRequestsRemoved = lambda x: True sb = Mock(spec=['isAvailable'], name='test-slave-1') sb.name = 'test-slave-1' sb.isAvailable.return_value = 1 sb.slave = Mock() sb.slave.updateStatusBuildFinished = lambda result, build: result sb.slave.properties = properties.Properties() sb.prepare = lambda x, y: True sb.ping = lambda timeout: True sb.buildStarted = lambda: True sb.buildFinished = lambda _: False sb.setSlaveIdle = lambda: False sb.remote = Mock() self.bldr.slaves.append(sb) self.assertEqual(self.master.db.buildrequests.claims, {}) from buildbot.process import buildrequestdistributor self.brd = buildrequestdistributor.BuildRequestDistributor(self.master.botmaster) self.brd.startService() yield self.brd._maybeStartBuildsOnBuilder(self.bldr) self.assertEqual(self.master.db.buildrequests.claims[1].brid, 1) self.build.build_status.saveYourself = lambda: True self.build.currentStep.start() self.build.lostRemote() self.assertEqual(self.master.db.buildrequests.claims, {}) if self.brd.running: self.brd.stopService()
def setupStep(self, step, sourcestampsInBuild=None, gotRevisionsInBuild=None, *args, **kwargs): sourcestamps = sourcestampsInBuild or [] got_revisions = gotRevisionsInBuild or {} steps.BuildStepMixin.setupStep(self, step, *args, **kwargs) # This step reaches deeply into a number of parts of Buildbot. That # should be fixed! # set up a buildmaster that knows about two fake schedulers, a and b m = self.master m.db.checkForeignKeys = True self.build.builder.botmaster = m.botmaster self.build.conn = object() m.status = master.Status() m.status.setServiceParent(m) m.config.buildbotURL = "baseurl/" m.scheduler_manager = FakeSchedulerManager() self.scheduler_a = a = FakeTriggerable(name='a') self.scheduler_b = b = FakeTriggerable(name='b') self.scheduler_c = c = FakeTriggerable(name='c') m.scheduler_manager.namedServices = dict(a=a, b=b, c=c) a.brids = {77: 11} b.brids = {78: 22} c.brids = {79: 33, 80: 44} def make_fake_br(brid, builderid): return fakedb.BuildRequest(id=brid, buildsetid=BRID_TO_BSID(brid), builderid=builderid) def make_fake_build(brid, builderid): return fakedb.Build(buildrequestid=brid, id=BRID_TO_BID(brid), number=BRID_TO_BUILD_NUMBER(brid), masterid=9, workerid=13, builderid=builderid) m.db.insertTestData([ fakedb.Builder(id=77, name='A'), fakedb.Builder(id=78, name='B'), fakedb.Builder(id=79, name='C1'), fakedb.Builder(id=80, name='C2'), fakedb.Master(id=9), fakedb.Buildset(id=2022), fakedb.Buildset(id=2011), fakedb.Buildset(id=2033), fakedb.Worker(id=13, name="some:worker"), make_fake_br(11, 77), make_fake_br(22, 78), fakedb.BuildRequest(id=33, buildsetid=2033, builderid=79), fakedb.BuildRequest(id=44, buildsetid=2033, builderid=80), make_fake_build(11, builderid=77), make_fake_build(22, builderid=78), make_fake_build(33, builderid=79), # builderid is 79 on purpose, changed, from the one of the buildrequest # to test the case of the virtual make_fake_build(44, builderid=79), ]) def getAllSourceStamps(): return sourcestamps self.build.getAllSourceStamps = getAllSourceStamps def getAllGotRevisions(): return got_revisions self.step.getAllGotRevisions = getAllGotRevisions self.exp_add_sourcestamp = None self.exp_a_trigger = None self.exp_b_trigger = None self.exp_c_trigger = None self.exp_added_urls = []
def setUpFakeMasterStatus(fakemaster): master_status = master.Status(fakemaster) slave = mock.Mock() slave.getFriendlyName = lambda: 'build-slave-01' master_status.getSlave = lambda x: slave return master_status
def makeStatus(self): m = mock.Mock(name='master') self.db = m.db = fakedb.FakeDBConnector(self) m.basedir = r'C:\BASEDIR' s = master.Status(m) return s
def setupStatus(self, b): s = master.Status(self.master) b.status = s return s
def setupStep(self, step, sourcestampsInBuild=None, force_rebuild=False, force_chain_rebuild=False, configuredMergeFnResponse=True, *args, **kwargs): sourcestamps = sourcestampsInBuild or [] got_revisions = {} steps.BuildStepMixin.setupStep(self, step, *args, **kwargs) m = fakemaster.make_master() self.build.builder.botmaster = m.botmaster m.db = fakedb.FakeDBConnector(self) m.status = master.Status(m) m.config.buildbotURL = "baseurl/" m.db.mastersconfig.setupMaster() if len(sourcestamps) < 1: ss = FakeSourceStamp(codebase='c', repository='https://url/project', branch='mybranch', revision=3, sourcestampsetid=3) sourcestamps.append(ss) def getAllSourceStamps(): return sourcestamps self.build.getAllSourceStamps = getAllSourceStamps self.build.build_status.getSourceStamps = getAllSourceStamps if force_rebuild: self.build.setProperty("force_rebuild", True, "FindPreviousBuildTest") if force_chain_rebuild: self.build.setProperty("force_chain_rebuild", True, "FindPreviousBuildTest") def getAllGotRevisions(): return got_revisions self.build.build_status.getAllGotRevisions = getAllGotRevisions def getSourceValues(): return [mock.Mock()] buildRequest = mock.Mock() buildRequest.id = 1 buildRequest.sources.values = getSourceValues self.build.requests = [ buildRequest ] self.build.builder.config.name = "A" self.build.builder.config.builddir = "build" def getConfiguredMergeRequestsFn(): return configuredMergeFnResponse self.build.builder.getConfiguredMergeRequestsFn = getConfiguredMergeRequestsFn self.build.builder.builder_status.getFriendlyName = lambda: "A" def addURL(name, url, results=None): self.step_status.urls[name] = url if results is not None: self.step_status.urls[name] = {'url': url, 'results': results} self.step_status.addURL = addURL fake_buildset = fakedb.Buildset(id=1, sourcestampsetid=1) fake_br = fakedb.BuildRequest(id=1, buildsetid=1, buildername="A", complete=1, results=0) fake_ss = fakedb.SourceStamp(id=1, branch='master', repository='https://url/project', codebase='c', revision='12', sourcestampsetid=1) fake_build = fakedb.Build(id=1, number=1, brid=1) m.db.insertTestData([fake_buildset, fake_br, fake_ss, fake_build]) m.db.buildrequests.setRelatedSourcestamps(1, [FakeSourceStamp(codebase='c', repository='https://url/project', branch='master', revision=12, sourcestampsetid=1)])