[Buildbot-commits] buildbot/buildbot/test test_control.py,NONE,1.1 test_vc.py,1.13,1.14 test_run.py,1.15,1.16

Brian Warner warner at users.sourceforge.net
Tue Sep 28 17:51:41 UTC 2004


Update of /cvsroot/buildbot/buildbot/buildbot/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1975/buildbot/test

Modified Files:
	test_vc.py test_run.py 
Added Files:
	test_control.py 
Log Message:
* buildbot/test/test_control.py: test new interfaces
* buildbot/test/test_run.py (Status): handle new interfaces
* buildbot/test/test_vc.py (SetupMixin.doBuild): same

* buildbot/process/base.py (BuildControl): implement IBuildControl
and its lonely getStatus() method

* buildbot/process/builder.py (BuilderControl): implement
IBuilderControl, obtained by adapting the Builder instance
(Builder.startBuild): return a BuilderControl instead of a
Deferred. The caller can use bc.getStatus().waitUntilFinished() to
accomplish the same thing.

* buildbot/master.py: move all import statements to the top
(Control): implement IControl, obtained by adapting the
BuildMaster instance.

* buildbot/interfaces.py: add IControl, IBuilderControl, and
IBuildControl. These are used to force builds. Eventually they
will provide ways to reconfigure the Builders, pause or abandon a
Build, and perhaps control the BuildMaster itself.


--- NEW FILE: test_control.py ---
#! /usr/bin/python

import sys, os, signal, shutil, time

from twisted.trial import unittest
dr = unittest.deferredResult
from twisted.internet import defer, reactor
from twisted.python.components import implements

from buildbot import master, interfaces
from buildbot.slave import bot
from buildbot.status import builder
from buildbot.status.builder import SUCCESS

config = """
from buildbot.process import factory, step

def s(klass, **kwargs):
    return (klass, kwargs)

f1 = factory.BuildFactory([
    s(step.Dummy, timeout=1),
    ])
c = {}
c['bots'] = [['bot1', 'sekrit']]
c['sources'] = []
c['builders'] = [{'name': 'force', 'slavename': 'bot1',
                  'builddir': 'force-dir', 'factory': f1}]
c['slavePortnum'] = 0
BuildmasterConfig = c
"""

class FakeBuilder:
    name = "fake"
    def getSlaveCommandVersion(self, command, oldversion=None):
        return "1.10"

class SignalMixin:
    sigchldHandler = None
    
    def setUpClass(self):
        # make sure SIGCHLD handler is installed, as it should be on
        # reactor.run(). problem is reactor may not have been run when this
        # test runs.
        if hasattr(reactor, "_handleSigchld") and hasattr(signal, "SIGCHLD"):
            self.sigchldHandler = signal.signal(signal.SIGCHLD,
                                                reactor._handleSigchld)
    
    def tearDownClass(self):
        if self.sigchldHandler:
            signal.signal(signal.SIGCHLD, self.sigchldHandler)

class Force(unittest.TestCase):
    master = None
    slave = None

    def setUp(self):
        self.master = master.BuildMaster("control_basedir")
        self.slavebase = os.path.abspath("control_slavebase")
        shutil.rmtree(self.slavebase, ignore_errors=1)
        os.mkdir("control_slavebase")

    def connectSlave(self):
        port = self.master.slavePort._port.getHost().port
        slave = bot.BuildSlave("localhost", port, "bot1", "sekrit",
                               self.slavebase, keepalive=0, usePTY=1)
        self.slave = slave
        slave.startService()
        d = self.master.botmaster.waitUntilBuilderAttached("force")
        dr(d)

    def loadConfig(self, config):
        # reloading the config file causes a new 'listDirs' command to be
        # sent to the slave. To synchronize on this properly, it is easiest
        # to stop and restart the slave.
        if self.slave:
            d = self.master.botmaster.waitUntilBuilderDetached("force")
            dr(defer.maybeDeferred(self.slave.stopService))
            dr(d)
        self.master.loadConfig(config)
        self.connectSlave()

    def tearDown(self):
        if self.slave:
            d = self.master.botmaster.waitUntilBuilderDetached("force")
            dr(defer.maybeDeferred(self.slave.stopService))
            dr(d)
        if self.master:
            dr(defer.maybeDeferred(self.master.stopService))

    def testForce(self):
        m = self.master
        m.loadConfig(config)
        m.readConfig = True
        m.startService()
        self.connectSlave()

        c = interfaces.IControl(m)
        builder_control = c.getBuilder("force")
        build_control = builder_control.forceBuild("bob", "I was bored")
        self.failUnless(implements(build_control, interfaces.IBuildControl))
        d = build_control.getStatus().waitUntilFinished()
        bs = dr(d)
        print bs

        self.failUnless(implements(bs, interfaces.IBuildStatus))
        self.failUnless(bs.isFinished())
        self.failUnlessEqual(bs.getResults(), SUCCESS)
        #self.failUnlessEqual(bs.getResponsibleUsers(), ["bob"]) # TODO
        self.failUnlessEqual(bs.getChanges(), [])
        #self.failUnlessEqual(bs.getReason(), "forced") # TODO







More information about the Commits mailing list