def startService(self): BuildSlave.startService(self) self._shutdown_callback_handle = reactor.addSystemEventTrigger( 'before', 'shutdown', self._stopInstance) self.master.subscribeToBuildRequests(self.requestSubmitted)
def startService(self): BuildSlave.startService(self) self._shutdown_callback_handle = reactor.addSystemEventTrigger( 'before', 'shutdown', self._stopInstance) self.master.subscribeToBuildRequests(self.requestSubmitted)
class RunSteps(unittest.TestCase): @defer.inlineCallbacks def setUp(self): self.master = fakemaster.make_master(testcase=self, wantDb=True) self.builder = builder.Builder('test', _addServices=False) self.builder.master = self.master yield self.builder.startService() self.factory = factory.BuildFactory() # will have steps added later new_config = config.MasterConfig() new_config.builders.append( config.BuilderConfig(name='test', slavename='testsl', factory=self.factory)) yield self.builder.reconfigService(new_config) self.slave = BuildSlave('bsl', 'pass') self.slave.sendBuilderList = lambda: defer.succeed(None) self.slave.botmaster = mock.Mock() self.slave.botmaster.maybeStartBuildsForSlave = lambda sl: None self.slave.master = self.master self.slave.startService() self.remote = FakeBot() yield self.slave.attached(self.remote) sb = self.slavebuilder = slavebuilder.SlaveBuilder() sb.setBuilder(self.builder) yield sb.attached(self.slave, self.remote, {}) # add the buildset/request sssid = yield self.master.db.sourcestampsets.addSourceStampSet() yield self.master.db.sourcestamps.addSourceStamp(branch='br', revision='1', repository='r://', project='', sourcestampsetid=sssid) self.bsid, brids = yield self.master.db.buildsets.addBuildset( sourcestampsetid=sssid, reason=u'x', properties={}, builderNames=['test']) self.brdict = \ yield self.master.db.buildrequests.getBuildRequest(brids['test']) self.buildrequest = \ yield buildrequest.BuildRequest.fromBrdict(self.master, self.brdict) def tearDown(self): self.slave.stopKeepaliveTimer() return self.builder.stopService() @defer.inlineCallbacks def do_test_step(self): # patch builder.buildFinished to signal us with a deferred bfd = defer.Deferred() old_buildFinished = self.builder.buildFinished def buildFinished(*args): old_buildFinished(*args) bfd.callback(None) self.builder.buildFinished = buildFinished # start the builder self.failUnless((yield self.builder.maybeStartBuild( self.slavebuilder, [self.buildrequest]))) # and wait for completion yield bfd # then get the BuildStatus and return it defer.returnValue(self.master.status.lastBuilderStatus.lastBuildStatus) def assertLogs(self, exp_logs): bs = self.master.status.lastBuilderStatus.lastBuildStatus # tell the steps they're not new-style anymore, so they don't assert for l in bs.getLogs(): l._isNewStyle = False got_logs = dict((l.name, l.getText()) for l in bs.getLogs()) self.assertEqual(got_logs, exp_logs) @defer.inlineCallbacks def test_OldStyleCustomBuildStep(self): self.factory.addStep(OldStyleCustomBuildStep(arg1=1, arg2=2)) yield self.do_test_step() self.assertLogs({ u'compl.html': u'<blink>A very short logfile</blink>\n', # this is one of the things that differs independently of # new/old style: encoding of logs and newlines u'foo': 'stdout\n\xe2\x98\x83\nstderr\n', # u'ostdout\no\N{SNOWMAN}\nestderr\n', u'obs': 'Observer saw [\'stdout\\n\', \'\\xe2\\x98\\x83\\n\']', #u'Observer saw [u\'stdout\\n\', u\'\\u2603\\n\']\n', }) @defer.inlineCallbacks def test_OldStyleCustomBuildStep_failure(self): self.factory.addStep(OldStyleCustomBuildStep(arg1=1, arg2=2, doFail=1)) bs = yield self.do_test_step() self.assertEqual(len(self.flushLoggedErrors(RuntimeError)), 1) self.assertEqual(bs.getResults(), results.EXCEPTION) @defer.inlineCallbacks def test_NewStyleCustomBuildStep(self): self.factory.addStep(NewStyleCustomBuildStep()) yield self.do_test_step() self.assertLogs({ 'foo.html': '<head>\n', 'testlog': 'stdout\nfromcmd\n', 'obs': "Observer saw [u'stdout\\n']", 'stdio': "stdio\nstderr\n", }) @defer.inlineCallbacks def test_step_raising_buildstepfailed_in_start(self): self.factory.addStep(FailingCustomStep()) bs = yield self.do_test_step() self.assertEqual(bs.getResults(), results.FAILURE) @defer.inlineCallbacks def test_step_raising_exception_in_start(self): self.factory.addStep(FailingCustomStep(exception=ValueError)) bs = yield self.do_test_step() self.assertEqual(bs.getResults(), results.EXCEPTION) #self.expectOutcome(result=EXCEPTION, status_text=["generic", "exception"]) self.assertEqual(len(self.flushLoggedErrors(ValueError)), 1) @defer.inlineCallbacks def test_step_raising_connectionlost_in_start(self): self.factory.addStep(FailingCustomStep(exception=error.ConnectionLost)) bs = yield self.do_test_step() self.assertEqual(bs.getResults(), results.RETRY) @defer.inlineCallbacks def test_Latin1ProducingCustomBuildStep(self): self.factory.addStep(Latin1ProducingCustomBuildStep(logEncoding='latin-1')) yield self.do_test_step() self.assertLogs({ u'xx': u'o\N{CENT SIGN}\n', }) test_Latin1ProducingCustomBuildStep.skip = "logEncoding not supported in 0.8.x" @defer.inlineCallbacks def test_OldBuildEPYDoc(self): # test old-style calls to log.getText, figuring readlines will be ok self.factory.addStep(OldBuildEPYDoc()) bs = yield self.do_test_step() self.assertEqual(bs.getResults(), results.FAILURE) @defer.inlineCallbacks def test_OldPerlModuleTest(self): # test old-style calls to self.getLog self.factory.addStep(OldPerlModuleTest()) bs = yield self.do_test_step() self.assertEqual(bs.getResults(), results.SUCCESS)
class RunSteps(unittest.TestCase): @defer.inlineCallbacks def setUp(self): self.master = fakemaster.make_master(testcase=self, wantData=True, wantMq=True, wantDb=True) self.master.db.insertTestData([ fakedb.Builder(id=80, name='test'), ]) self.builder = builder.Builder('test', _addServices=False) self.builder._builderid = 80 self.builder.master = self.master yield self.builder.startService() self.factory = factory.BuildFactory() # will have steps added later new_config = config.MasterConfig() new_config.builders.append( config.BuilderConfig(name='test', slavename='testsl', factory=self.factory)) yield self.builder.reconfigService(new_config) self.slave = BuildSlave('bsl', 'pass') self.slave.sendBuilderList = lambda: defer.succeed(None) self.slave.botmaster = mock.Mock() self.slave.botmaster.maybeStartBuildsForSlave = lambda sl: None self.slave.master = self.master self.slave.startService() self.conn = fakeprotocol.FakeConnection(self.master, self.slave) yield self.slave.attached(self.conn) sb = self.slavebuilder = slavebuilder.SlaveBuilder() sb.setBuilder(self.builder) yield sb.attached(self.slave, {}) # add the buildset/request self.bsid, brids = yield self.master.db.buildsets.addBuildset( sourcestamps=[{}], reason=u'x', properties={}, builderids=[80], waited_for=False) self.brdict = \ yield self.master.db.buildrequests.getBuildRequest(brids[80]) self.buildrequest = \ yield buildrequest.BuildRequest.fromBrdict(self.master, self.brdict) def tearDown(self): return self.builder.stopService() @defer.inlineCallbacks def do_test_step(self): # patch builder.buildFinished to signal us with a deferred bfd = defer.Deferred() old_buildFinished = self.builder.buildFinished def buildFinished(*args): old_buildFinished(*args) bfd.callback(None) self.builder.buildFinished = buildFinished # start the builder self.failUnless((yield self.builder.maybeStartBuild( self.slavebuilder, [self.buildrequest]))) # and wait for completion yield bfd # then get the BuildStatus and return it defer.returnValue(self.master.status.lastBuilderStatus.lastBuildStatus) def assertLogs(self, exp_logs): got_logs = {} for id, l in self.master.data.updates.logs.iteritems(): self.failUnless(l['finished']) got_logs[l['name']] = ''.join(l['content']) self.assertEqual(got_logs, exp_logs) @defer.inlineCallbacks def test_OldStyleCustomBuildStep(self): self.factory.addStep(OldStyleCustomBuildStep(arg1=1, arg2=2)) yield self.do_test_step() self.assertLogs({ u'compl.html': u'<blink>A very short logfile</blink>\n', # this is one of the things that differs independently of # new/old style: encoding of logs and newlines u'foo': # 'stdout\n\xe2\x98\x83\nstderr\n', u'ostdout\no\N{SNOWMAN}\nestderr\n', u'obs': # 'Observer saw [\'stdout\\n\', \'\\xe2\\x98\\x83\\n\']', u'Observer saw [u\'stdout\\n\', u\'\\u2603\\n\']\n', }) @defer.inlineCallbacks def test_OldStyleCustomBuildStep_failure(self): self.factory.addStep(OldStyleCustomBuildStep(arg1=1, arg2=2, doFail=1)) bs = yield self.do_test_step() self.assertEqual(len(self.flushLoggedErrors(RuntimeError)), 1) self.assertEqual(bs.getResults(), results.EXCEPTION) @defer.inlineCallbacks def test_step_raising_buildstepfailed_in_start(self): self.factory.addStep(FailingCustomStep()) bs = yield self.do_test_step() self.assertEqual(bs.getResults(), results.FAILURE) @defer.inlineCallbacks def test_step_raising_exception_in_start(self): self.factory.addStep(FailingCustomStep(exception=ValueError)) bs = yield self.do_test_step() self.assertEqual(bs.getResults(), results.EXCEPTION) self.assertEqual(len(self.flushLoggedErrors(ValueError)), 1) @defer.inlineCallbacks def test_step_raising_connectionlost_in_start(self): self.factory.addStep(FailingCustomStep(exception=error.ConnectionLost)) bs = yield self.do_test_step() self.assertEqual(bs.getResults(), results.RETRY) @defer.inlineCallbacks def test_Latin1ProducingCustomBuildStep(self): self.factory.addStep(Latin1ProducingCustomBuildStep(logEncoding='latin-1')) yield self.do_test_step() self.assertLogs({ u'xx': u'o\N{CENT SIGN}\n', }) @defer.inlineCallbacks def test_OldBuildEPYDoc(self): # test old-style calls to log.getText, figuring readlines will be ok self.factory.addStep(OldBuildEPYDoc()) bs = yield self.do_test_step() self.assertEqual(bs.getResults(), results.FAILURE) @defer.inlineCallbacks def test_OldPerlModuleTest(self): # test old-style calls to self.getLog self.factory.addStep(OldPerlModuleTest()) bs = yield self.do_test_step() self.assertEqual(bs.getResults(), results.SUCCESS)
class RunSteps(unittest.TestCase): @defer.inlineCallbacks def setUp(self): self.master = fakemaster.make_master(testcase=self, wantData=True, wantMq=True, wantDb=True) self.master.db.insertTestData([ fakedb.Builder(id=80, name='test'), ]) self.builder = builder.Builder('test', _addServices=False) self.builder._builderid = 80 self.builder.master = self.master yield self.builder.startService() self.factory = factory.BuildFactory() # will have steps added later new_config = config.MasterConfig() new_config.builders.append( config.BuilderConfig(name='test', slavename='testsl', factory=self.factory)) yield self.builder.reconfigServiceWithBuildbotConfig(new_config) self.slave = BuildSlave('bsl', 'pass') self.slave.sendBuilderList = lambda: defer.succeed(None) self.slave.parent = mock.Mock() self.slave.master.botmaster = mock.Mock() self.slave.botmaster.maybeStartBuildsForSlave = lambda sl: None self.slave.botmaster.getBuildersForSlave = lambda sl: [] self.slave.parent = self.master self.slave.startService() self.conn = fakeprotocol.FakeConnection(self.master, self.slave) yield self.slave.attached(self.conn) sb = self.slavebuilder = slavebuilder.SlaveBuilder() sb.setBuilder(self.builder) yield sb.attached(self.slave, {}) # add the buildset/request self.bsid, brids = yield self.master.db.buildsets.addBuildset( sourcestamps=[{}], reason=u'x', properties={}, builderids=[80], waited_for=False) self.brdict = \ yield self.master.db.buildrequests.getBuildRequest(brids[80]) self.buildrequest = \ yield buildrequest.BuildRequest.fromBrdict(self.master, self.brdict) def tearDown(self): return self.builder.stopService() @defer.inlineCallbacks def do_test_step(self): # patch builder.buildFinished to signal us with a deferred bfd = defer.Deferred() old_buildFinished = self.builder.buildFinished def buildFinished(*args): old_buildFinished(*args) bfd.callback(None) self.builder.buildFinished = buildFinished # start the builder self.failUnless((yield self.builder.maybeStartBuild( self.slavebuilder, [self.buildrequest]))) # and wait for completion yield bfd # then get the BuildStatus and return it defer.returnValue(self.master.status.lastBuilderStatus.lastBuildStatus) def assertLogs(self, exp_logs): got_logs = {} for id, l in self.master.data.updates.logs.iteritems(): self.failUnless(l['finished']) got_logs[l['name']] = ''.join(l['content']) self.assertEqual(got_logs, exp_logs) @defer.inlineCallbacks def doOldStyleCustomBuildStep(self, slowDB=False): # patch out addLog to delay until we're ready newLogDeferreds = [] oldNewLog = self.master.data.updates.addLog def finishNewLog(self): for d in newLogDeferreds: reactor.callLater(0, d.callback, None) def delayedNewLog(*args, **kwargs): d = defer.Deferred() d.addCallback(lambda _: oldNewLog(*args, **kwargs)) newLogDeferreds.append(d) return d if slowDB: self.patch(self.master.data.updates, "addLog", delayedNewLog) self.patch(OldStyleCustomBuildStep, "_run_finished_hook", finishNewLog) self.factory.addStep(OldStyleCustomBuildStep(arg1=1, arg2=2)) yield self.do_test_step() self.assertLogs({ u'compl.html': u'<blink>A very short logfile</blink>\n', # this is one of the things that differs independently of # new/old style: encoding of logs and newlines u'foo': # 'stdout\n\xe2\x98\x83\nstderr\n', u'ostdout\no\N{SNOWMAN}\nestderr\n', u'obs': # if slowDB, the observer wont see anything before the end of this instant step u'Observer saw []\n' if slowDB else # 'Observer saw [\'stdout\\n\', \'\\xe2\\x98\\x83\\n\']', u'Observer saw [u\'stdout\\n\', u\'\\u2603\\n\']\n', }) def test_OldStyleCustomBuildStep(self): return self.doOldStyleCustomBuildStep(False) def test_OldStyleCustomBuildStepSlowDB(self): return self.doOldStyleCustomBuildStep(True) @defer.inlineCallbacks def test_OldStyleCustomBuildStep_failure(self): self.factory.addStep(OldStyleCustomBuildStep(arg1=1, arg2=2, doFail=1)) bs = yield self.do_test_step() self.assertEqual(len(self.flushLoggedErrors(RuntimeError)), 1) self.assertEqual(bs.getResults(), results.EXCEPTION) @defer.inlineCallbacks def test_step_raising_buildstepfailed_in_start(self): self.factory.addStep(FailingCustomStep()) bs = yield self.do_test_step() self.assertEqual(bs.getResults(), results.FAILURE) @defer.inlineCallbacks def test_step_raising_exception_in_start(self): self.factory.addStep(FailingCustomStep(exception=ValueError)) bs = yield self.do_test_step() self.assertEqual(bs.getResults(), results.EXCEPTION) self.assertEqual(len(self.flushLoggedErrors(ValueError)), 1) @defer.inlineCallbacks def test_step_raising_connectionlost_in_start(self): self.factory.addStep(FailingCustomStep(exception=error.ConnectionLost)) bs = yield self.do_test_step() self.assertEqual(bs.getResults(), results.RETRY) @defer.inlineCallbacks def test_Latin1ProducingCustomBuildStep(self): self.factory.addStep(Latin1ProducingCustomBuildStep(logEncoding='latin-1')) yield self.do_test_step() self.assertLogs({ u'xx': u'o\N{CENT SIGN}\n', }) @defer.inlineCallbacks def test_OldBuildEPYDoc(self): # test old-style calls to log.getText, figuring readlines will be ok self.factory.addStep(OldBuildEPYDoc()) bs = yield self.do_test_step() self.assertEqual(bs.getResults(), results.FAILURE) @defer.inlineCallbacks def test_OldPerlModuleTest(self): # test old-style calls to self.getLog self.factory.addStep(OldPerlModuleTest()) bs = yield self.do_test_step() self.assertEqual(bs.getResults(), results.SUCCESS)
class RunSteps(unittest.TestCase): @defer.inlineCallbacks def setUp(self): self.master = fakemaster.make_master(testcase=self, wantDb=True) self.builder = builder.Builder('test', _addServices=False) self.builder.master = self.master yield self.builder.startService() self.factory = factory.BuildFactory() # will have steps added later new_config = config.MasterConfig() new_config.builders.append( config.BuilderConfig(name='test', slavename='testsl', factory=self.factory)) yield self.builder.reconfigService(new_config) self.slave = BuildSlave('bsl', 'pass') self.slave.sendBuilderList = lambda: defer.succeed(None) self.slave.botmaster = mock.Mock() self.slave.botmaster.maybeStartBuildsForSlave = lambda sl: None self.slave.master = self.master self.slave.startService() self.remote = FakeBot() yield self.slave.attached(self.remote) sb = self.slavebuilder = slavebuilder.SlaveBuilder() sb.setBuilder(self.builder) yield sb.attached(self.slave, self.remote, {}) # add the buildset/request sssid = yield self.master.db.sourcestampsets.addSourceStampSet() yield self.master.db.sourcestamps.addSourceStamp( branch='br', revision='1', repository='r://', project='', sourcestampsetid=sssid) self.bsid, brids = yield self.master.db.buildsets.addBuildset( sourcestampsetid=sssid, reason=u'x', properties={}, builderNames=['test']) self.brdict = \ yield self.master.db.buildrequests.getBuildRequest(brids['test']) self.buildrequest = \ yield buildrequest.BuildRequest.fromBrdict(self.master, self.brdict) def tearDown(self): self.slave.stopKeepaliveTimer() return self.builder.stopService() @defer.inlineCallbacks def do_test_step(self): # patch builder.buildFinished to signal us with a deferred bfd = defer.Deferred() old_buildFinished = self.builder.buildFinished def buildFinished(*args): old_buildFinished(*args) bfd.callback(None) self.builder.buildFinished = buildFinished # start the builder self.failUnless((yield self.builder.maybeStartBuild(self.slavebuilder, [self.buildrequest]))) # and wait for completion yield bfd # then get the BuildStatus and return it defer.returnValue(self.master.status.lastBuilderStatus.lastBuildStatus) def assertLogs(self, exp_logs): bs = self.master.status.lastBuilderStatus.lastBuildStatus # tell the steps they're not new-style anymore, so they don't assert for l in bs.getLogs(): l._isNewStyle = False got_logs = dict((l.name, l.getText()) for l in bs.getLogs()) self.assertEqual(got_logs, exp_logs) @defer.inlineCallbacks def test_OldStyleCustomBuildStep(self): self.factory.addStep(OldStyleCustomBuildStep(arg1=1, arg2=2)) yield self.do_test_step() self.assertLogs({ u'compl.html': u'<blink>A very short logfile</blink>\n', # this is one of the things that differs independently of # new/old style: encoding of logs and newlines u'foo': 'stdout\n\xe2\x98\x83\nstderr\n', # u'ostdout\no\N{SNOWMAN}\nestderr\n', u'obs': 'Observer saw [\'stdout\\n\', \'\\xe2\\x98\\x83\\n\']', # u'Observer saw [u\'stdout\\n\', u\'\\u2603\\n\']\n', }) @defer.inlineCallbacks def test_OldStyleCustomBuildStep_failure(self): self.factory.addStep(OldStyleCustomBuildStep(arg1=1, arg2=2, doFail=1)) bs = yield self.do_test_step() self.assertEqual(len(self.flushLoggedErrors(RuntimeError)), 1) self.assertEqual(bs.getResults(), results.EXCEPTION) @defer.inlineCallbacks def test_NewStyleCustomBuildStep(self): self.factory.addStep(NewStyleCustomBuildStep()) yield self.do_test_step() self.assertLogs({ 'foo.html': '<head>\n', 'testlog': 'stdout\nfromcmd\n', 'obs': "Observer saw [u'stdout\\n']", 'stdio': "stdio\nstderr\n", }) @defer.inlineCallbacks def test_step_raising_buildstepfailed_in_start(self): self.factory.addStep(FailingCustomStep()) bs = yield self.do_test_step() self.assertEqual(bs.getResults(), results.FAILURE) @defer.inlineCallbacks def test_step_raising_exception_in_start(self): self.factory.addStep(FailingCustomStep(exception=ValueError)) bs = yield self.do_test_step() self.assertEqual(bs.getResults(), results.EXCEPTION) # self.expectOutcome(result=EXCEPTION, status_text=["generic", "exception"]) self.assertEqual(len(self.flushLoggedErrors(ValueError)), 1) @defer.inlineCallbacks def test_step_raising_connectionlost_in_start(self): self.factory.addStep(FailingCustomStep(exception=error.ConnectionLost)) bs = yield self.do_test_step() self.assertEqual(bs.getResults(), results.RETRY) @defer.inlineCallbacks def test_Latin1ProducingCustomBuildStep(self): self.factory.addStep( Latin1ProducingCustomBuildStep(logEncoding='latin-1')) yield self.do_test_step() self.assertLogs({ u'xx': u'o\N{CENT SIGN}\n', }) test_Latin1ProducingCustomBuildStep.skip = "logEncoding not supported in 0.8.x" @defer.inlineCallbacks def test_OldBuildEPYDoc(self): # test old-style calls to log.getText, figuring readlines will be ok self.factory.addStep(OldBuildEPYDoc()) bs = yield self.do_test_step() self.assertEqual(bs.getResults(), results.FAILURE) @defer.inlineCallbacks def test_OldPerlModuleTest(self): # test old-style calls to self.getLog self.factory.addStep(OldPerlModuleTest()) bs = yield self.do_test_step() self.assertEqual(bs.getResults(), results.SUCCESS)
class BuildStepIntegrationMixin(object): """Support for *integration* testing of buildsteps. This class runs as much "real" code as possible, unlike BuildStepMixin which focuses on the step itself.""" @defer.inlineCallbacks def setUpBuildStepIntegration(self): self.master = fakemaster.make_master(testcase=self, wantDb=True) self.builder = builder.Builder("test", _addServices=False) self.builder.master = self.master yield self.builder.startService() self.factory = factory.BuildFactory() # will have steps added later new_config = config.MasterConfig() new_config.builders.append(config.BuilderConfig(name="test", slavename="testsl", factory=self.factory)) yield self.builder.reconfigService(new_config) self.slave = BuildSlave("bsl", "pass") self.slave.sendBuilderList = lambda: defer.succeed(None) self.slave.botmaster = mock.Mock() self.slave.botmaster.maybeStartBuildsForSlave = lambda sl: None self.slave.master = self.master self.slave.startService() self.remote = FakeBot() yield self.slave.attached(self.remote) sb = self.slavebuilder = slavebuilder.SlaveBuilder() sb.setBuilder(self.builder) yield sb.attached(self.slave, self.remote, {}) # add the buildset/request sssid = yield self.master.db.sourcestampsets.addSourceStampSet() yield self.master.db.sourcestamps.addSourceStamp( branch="br", revision="1", repository="r://", project="", sourcestampsetid=sssid ) self.bsid, brids = yield self.master.db.buildsets.addBuildset( sourcestampsetid=sssid, reason=u"x", properties={}, builderNames=["test"] ) self.brdict = yield self.master.db.buildrequests.getBuildRequest(brids["test"]) self.buildrequest = yield buildrequest.BuildRequest.fromBrdict(self.master, self.brdict) def tearDownBuildStepIntegration(self): self.slave.stopKeepaliveTimer() return self.builder.stopService() def setupStep(self, step): self.factory.addStep(step) @defer.inlineCallbacks def runStep(self): # patch builder.buildFinished to signal us with a deferred bfd = defer.Deferred() old_buildFinished = self.builder.buildFinished def buildFinished(*args): old_buildFinished(*args) bfd.callback(None) self.builder.buildFinished = buildFinished # start the builder self.failUnless((yield self.builder.maybeStartBuild(self.slavebuilder, [self.buildrequest]))) # and wait for completion yield bfd # then get the BuildStatus and return it defer.returnValue(self.master.status.lastBuilderStatus.lastBuildStatus)
class BuildStepIntegrationMixin(object): """Support for *integration* testing of buildsteps. This class runs as much "real" code as possible, unlike BuildStepMixin which focuses on the step itself.""" @defer.inlineCallbacks def setUpBuildStepIntegration(self): self.master = fakemaster.make_master(testcase=self, wantDb=True) self.builder = builder.Builder('test', _addServices=False) self.builder.master = self.master yield self.builder.startService() self.factory = factory.BuildFactory() # will have steps added later new_config = config.MasterConfig() new_config.builders.append( config.BuilderConfig(name='test', slavename='testsl', factory=self.factory)) yield self.builder.reconfigService(new_config) self.slave = BuildSlave('bsl', 'pass') self.slave.sendBuilderList = lambda: defer.succeed(None) self.slave.botmaster = mock.Mock() self.slave.botmaster.maybeStartBuildsForSlave = lambda sl: None self.slave.master = self.master self.slave.startService() self.remote = FakeBot() yield self.slave.attached(self.remote) sb = self.slavebuilder = slavebuilder.SlaveBuilder() sb.setBuilder(self.builder) yield sb.attached(self.slave, self.remote, {}) # add the buildset/request sssid = yield self.master.db.sourcestampsets.addSourceStampSet() yield self.master.db.sourcestamps.addSourceStamp( branch='br', revision='1', repository='r://', project='', sourcestampsetid=sssid) self.bsid, brids = yield self.master.db.buildsets.addBuildset( sourcestampsetid=sssid, reason=u'x', properties={}, builderNames=['test']) self.brdict = \ yield self.master.db.buildrequests.getBuildRequest(brids['test']) self.buildrequest = \ yield buildrequest.BuildRequest.fromBrdict(self.master, self.brdict) def tearDownBuildStepIntegration(self): self.slave.stopKeepaliveTimer() return self.builder.stopService() def setupStep(self, step): self.factory.addStep(step) @defer.inlineCallbacks def runStep(self): # patch builder.buildFinished to signal us with a deferred bfd = defer.Deferred() old_buildFinished = self.builder.buildFinished def buildFinished(*args): old_buildFinished(*args) bfd.callback(None) self.builder.buildFinished = buildFinished # start the builder self.failUnless((yield self.builder.maybeStartBuild(self.slavebuilder, [self.buildrequest]))) # and wait for completion yield bfd # then get the BuildStatus and return it defer.returnValue(self.master.status.lastBuilderStatus.lastBuildStatus)