[Buildbot-devel] Determining steps based on what's checked out...

Tom Prince tom.prince at ualberta.net
Mon Apr 9 03:04:41 UTC 2012


# Does the following do something like you want?
# This will certainly require some customizing,
# but it should demonstrate how to go about writting
# this kind of step.

from twisted.internet import defer
from buildbot.process import buildstep
from buildbot.status.results import SUCCESS, FAILURE

class MultiComponent(buildstep.LoggingBuildStep):
    def __init__(self, **kwargs):
        buildstep.LoggingBuildStep.__init__(self, **kwargs)

    @defer.inlineCallbacks
    def start(self):
        # Get components
        stdioLog = self.addLog("stdio")
        cmd = buildstep.RemoteShellCommand(workdir="build",
                command=["get", "components"],
                collectStdout=True)
        cmd.useLog(stdioLog, False)
        yield self.runCommand(cmd)
        if cmd.rc != 0:
            raise buildstep.BuildStepFailed()
        components = cmd.stdout.splitlines()


        result = SUCCESS

        for component in components:
            stdioLog = self.addLog(component + " log")
            cmd = buildstep.RemoteShellCommand(workdir="build",
                    command=["test", component])
            cmd.useLog(stdioLog, False)
            yield self.runCommand(cmd)
            if cmd.rc != 0:
                result = FAILURE

        self.finished(result)
        defer.returnValue(None)


from twisted.trial import unittest

from buildbot.test.util import steps
from buildbot.test.fake.remotecommand import ExpectShell

class TestMultiComponent(steps.BuildStepMixin, unittest.TestCase):
    def setUp(self):
        return self.setUpBuildStep()

    def tearDown(self):
        return self.tearDownBuildStep()

    def test_MultiComponent(self):
        self.setupStep(MultiComponent())
        self.expectCommands(
                ExpectShell(workdir="build", command=["get", "components"])
                + ExpectShell.log('stdio', stdout='one\ntwo\n')
                + 0,
                ExpectShell(workdir="build", command=["test", "one"])
                + ExpectShell.log('one log', stdout='one')
                + 0,
                ExpectShell(workdir="build", command=["test", "two"])
                + ExpectShell.log('two log', stdout='one')
                + 0
                )
        self.expectOutcome(result=SUCCESS, status_text=["generic"])
        return self.runStep()
                
    def test_MultiComponent_failed(self):
        self.setupStep(MultiComponent())
        self.expectCommands(
                ExpectShell(workdir="build", command=["get", "components"])
                + ExpectShell.log('stdio', stdout='one\ntwo\n')
                + 0,
                ExpectShell(workdir="build", command=["test", "one"])
                + ExpectShell.log('one log', stdout='one')
                + 1,
                ExpectShell(workdir="build", command=["test", "two"])
                + ExpectShell.log('two log', stdout='one')
                + 0
                )
        self.expectOutcome(result=FAILURE, status_text=["generic"])
        return self.runStep()





More information about the devel mailing list