Ticket #100: builderWideEnvironnment-with-tests.diff

File builderWideEnvironnment-with-tests.diff, 6.6 KB (added by bhearsum, 13 years ago)

again, with tests + clarified ShellCommand?.setupEnviornment

  • buildbot/process/base.py

    RCS file: /cvsroot/buildbot/buildbot/buildbot/process/base.py,v
    retrieving revision 1.84
    diff -u -r1.84 base.py
     
    193193    def setLocks(self, locks):
    194194        self.locks = locks
    195195
     196    def setSlaveEnvironment(self, env):
     197        self.slaveEnvironment = env
     198
    196199    def getSourceStamp(self):
    197200        return self.source
    198201
  • buildbot/process/builder.py

    RCS file: /cvsroot/buildbot/buildbot/buildbot/process/builder.py,v
    retrieving revision 1.54
    diff -u -r1.54 builder.py
     
    278278        self.builddir = setup['builddir']
    279279        self.buildFactory = setup['factory']
    280280        self.locks = setup.get("locks", [])
     281        self.env = setup.get('env', {})
     282        assert isinstance(self.env, dict)
    281283        if setup.has_key('periodicBuildTime'):
    282284            raise ValueError("periodicBuildTime can no longer be defined as"
    283285                             " part of the Builder: use scheduler.Periodic"
     
    587589        build = self.buildFactory.newBuild(requests)
    588590        build.setBuilder(self)
    589591        build.setLocks(self.locks)
     592        if len(self.env) > 0:
     593            build.setSlaveEnvironment(self.env)
    590594
    591595        # start it
    592596        self.startBuild(build, sb)
  • buildbot/steps/shell.py

    RCS file: /cvsroot/buildbot/buildbot/buildbot/steps/shell.py,v
    retrieving revision 1.23
    diff -u -r1.23 shell.py
     
    133133        return ["'%s" % words[0], "%s" % words[1], "...'"]
    134134
    135135    def setupEnvironment(self, cmd):
    136         # XXX is this used? documented? replaced by properties?
    137         # merge in anything from Build.slaveEnvironment . Earlier steps
    138         # (perhaps ones which compile libraries or sub-projects that need to
    139         # be referenced by later steps) can add keys to
    140         # self.build.slaveEnvironment to affect later steps.
     136        # merge in anything from Build.slaveEnvironment
     137        # This can be set from a Builder-level environment, or from earlier
     138        # BuildSteps. The latter method is deprecated and superceded by
     139        # BuildProperties.
     140        # Environment variables passed in by a BuildStep override
     141        # those passed in at the Builder level.
    141142        properties = self.build.getProperties()
    142143        slaveEnv = self.build.slaveEnvironment
    143144        if slaveEnv:
    144145            if cmd.args['env'] is None:
    145146                cmd.args['env'] = {}
    146             cmd.args['env'].update(properties.render(slaveEnv))
     147            fullSlaveEnv = slaveEnv.copy()
     148            fullSlaveEnv = properties.render(fullSlaveEnv)
     149            fullSlaveEnv.update(cmd.args['env'])
     150            cmd.args['env'] = fullSlaveEnv
    147151            # note that each RemoteShellCommand gets its own copy of the
    148152            # dictionary, so we shouldn't be affecting anyone but ourselves.
    149153
  • buildbot/test/test_run.py

    RCS file: /cvsroot/buildbot/buildbot/buildbot/test/test_run.py,v
    retrieving revision 1.56
    diff -u -r1.56 test_run.py
     
    843843# of the bug where I forgot to make Waterfall inherit from StatusReceiver
    844844# such that buildSetSubmitted failed.
    845845
     846config_test_builder = config_base + """
     847from buildbot.scheduler import Scheduler
     848c['schedulers'] = [Scheduler('quick', 'dummy', 0.1, ['dummy']),
     849                   Scheduler('quick2', 'dummy2', 0.1, ['dummy2']),
     850                   Scheduler('quick3', 'dummy3', 0.1, ['dummy3'])]
     851
     852from buildbot.steps.shell import ShellCommand
     853f3 = factory.BuildFactory([
     854    s(ShellCommand, command="sleep 3", env={'blah':'blah'})
     855    ])
     856
     857c['builders'] = [{'name': 'dummy', 'slavename': 'bot1', 'env': {'foo':'bar'},
     858                  'builddir': 'dummy', 'factory': f3}]
     859
     860c['builders'].append({'name': 'dummy2', 'slavename': 'bot1',
     861                       'env': {'blah':'bar'}, 'builddir': 'dummy2',
     862                       'factory': f3})
     863
     864f4 = factory.BuildFactory([
     865    s(ShellCommand, command="sleep 3")
     866    ])
     867
     868c['builders'].append({'name': 'dummy3', 'slavename': 'bot1',
     869                       'env': {'blah':'bar'}, 'builddir': 'dummy3',
     870                       'factory': f4})
     871"""
     872
     873class TestBuilder(RunMixin, unittest.TestCase):
     874    def setUp(self):
     875        RunMixin.setUp(self)
     876        self.master.loadConfig(config_test_builder)
     877        self.master.readConfig = True
     878        self.master.startService()
     879        self.connectSlave(builders=["dummy", "dummy2", "dummy3"])
     880
     881    def doBuilderEnvTest(self, branch, cb):
     882        c = changes.Change("bob", ["Makefile", "foo/bar.c"], "changed",
     883                           branch=branch)
     884        self.master.change_svc.addChange(c)
     885
     886        d = defer.Deferred()
     887        reactor.callLater(0.5, d.callback, None)
     888        d.addCallback(cb)
     889
     890        return d
     891
     892    def testBuilderEnv(self):
     893        return self.doBuilderEnvTest("dummy", self._testBuilderEnv1)
     894
     895    def _testBuilderEnv1(self, res):
     896        b = self.master.botmaster.builders['dummy']
     897        build = b.building[0]
     898        s = build.currentStep
     899        self.failUnless('foo' in s.cmd.args['env'])
     900        self.failUnlessEqual('bar', s.cmd.args['env']['foo'])
     901        self.failUnless('blah' in s.cmd.args['env'])
     902        self.failUnlessEqual('blah', s.cmd.args['env']['blah'])
     903
     904    def testBuilderEnvOverride(self):
     905        return self.doBuilderEnvTest("dummy2", self._testBuilderEnvOverride1)
     906
     907    def _testBuilderEnvOverride1(self, res):
     908        b = self.master.botmaster.builders['dummy2']
     909        build = b.building[0]
     910        s = build.currentStep
     911        self.failUnless('blah' in s.cmd.args['env'])
     912        self.failUnlessEqual('blah', s.cmd.args['env']['blah'])
     913
     914    def testBuilderNoStepEnv(self):
     915        return self.doBuilderEnvTest("dummy3", self._testBuilderNoStepEnv1)
     916
     917    def _testBuilderNoStepEnv1(self, res):
     918        b = self.master.botmaster.builders['dummy3']
     919        build = b.building[0]
     920        s = build.currentStep
     921        self.failUnless('blah' in s.cmd.args['env'])
     922        self.failUnlessEqual('bar', s.cmd.args['env']['blah'])