Exemplo n.º 1
0
 def test_runCommand(self):
     bs = buildstep.BuildStep()
     bs.buildslave = slave.FakeSlave()
     bs.remote = 'dummy'
     cmd = buildstep.RemoteShellCommand("build", ["echo", "hello"])
     cmd.run = lambda self, remote: SUCCESS
     bs.runCommand(cmd)
     self.assertEqual(bs.cmd, cmd)
Exemplo n.º 2
0
    def test_runCommand(self):
        bs = buildstep.BuildStep()
        bs.buildslave = slave.FakeSlave(master=None)  # master is not used here
        bs.remote = 'dummy'
        cmd = buildstep.RemoteShellCommand("build", ["echo", "hello"])

        def run(*args, **kwargs):
            # check that runCommand sets step.cmd
            self.assertIdentical(bs.cmd, cmd)
            return SUCCESS
        cmd.run = run
        yield bs.runCommand(cmd)
        # check that step.cmd is cleared after the command runs
        self.assertEqual(bs.cmd, None)
Exemplo n.º 3
0
    def setUp(self):
        r = FakeRequest()
        r.sources = [FakeSource()]
        r.sources[0].changes = [FakeChange()]
        r.sources[0].revision = "12345"

        self.request = r
        self.master = FakeMaster()

        self.master.botmaster = FakeBotMaster(master=self.master)

        self.slave = slave.FakeSlave(self.master)
        self.builder = self.createBuilder()
        self.build = Build([r])
        self.build.master = self.master
        self.build.setBuilder(self.builder)
Exemplo n.º 4
0
    def setUp(self):
        r = FakeRequest()
        r.sources = [FakeSource()]
        r.sources[0].changes = [FakeChange()]
        r.sources[0].revision = "12345"

        self.request = r
        self.master = fakemaster.make_master(wantData=True, testcase=self)

        self.slave = slave.FakeSlave(self.master)
        self.slave.attached(None)
        self.builder = FakeBuilder(self.master)
        self.build = Build([r])
        self.build.conn = fakeprotocol.FakeConnection(self.master, self.slave)

        self.slavebuilder = Mock(name='slavebuilder')
        self.slavebuilder.slave = self.slave

        self.build.setBuilder(self.builder)
Exemplo n.º 5
0
 def setUp(self):
     class FakeBuildStatus(Mock):
         implements(interfaces.IProperties)
     r = FakeRequest()
     r.sources = [FakeSource()]
     r.sources[0].changes = [FakeChange()]
     r.sources[0].revision = "12345"
     self.master = fakemaster.make_master(wantData=True, testcase=self)
     self.slave = slave.FakeSlave(self.master)
     self.slave.attached(None)
     self.slavebuilder = Mock(name='slavebuilder')
     self.slavebuilder.slave = self.slave
     self.build = Build([r])
     self.build.setStepFactories([])
     self.builder = FakeBuilder(
         fakemaster.make_master(wantData=True, testcase=self))
     self.build.setBuilder(self.builder)
     self.build_status = FakeBuildStatus()
     self.build.startBuild(self.build_status, None, self.slavebuilder)
Exemplo n.º 6
0
 def setUp(self):
     self.master = fakemaster.make_master(testcase=self)
     self.sl = slave.FakeSlave(self.master)
Exemplo n.º 7
0
    def setupStep(self, step, slave_version={'*': "99.99"}, slave_env={}):
        """
        Set up C{step} for testing.  This begins by using C{step} as a factory
        to create a I{new} step instance, thereby testing that the the factory
        arguments are handled correctly.  It then creates a comfortable
        environment for the slave to run in, repleate with a fake build and a
        fake slave.

        As a convenience, it calls the step's setDefaultWorkdir method with
        C{'wkdir'}.

        @param slave_version: slave version to present, as a dictionary mapping
            command name to version.  A command name of '*' will apply for all
            commands.

        @param slave_env: environment from the slave at slave startup
        """
        factory = interfaces.IBuildStepFactory(step)
        step = self.step = factory.buildStep()
        self.master = fakemaster.make_master(testcase=self)

        # step.build

        b = self.build = fakebuild.FakeBuild()
        b.master = self.master

        def getSlaveVersion(cmd, oldversion):
            if cmd in slave_version:
                return slave_version[cmd]
            if '*' in slave_version:
                return slave_version['*']
            return oldversion

        b.getSlaveCommandVersion = getSlaveVersion
        b.slaveEnvironment = slave_env.copy()
        step.setBuild(b)

        # watch for properties being set
        self.properties = interfaces.IProperties(b)

        # step.progress

        step.progress = mock.Mock(name="progress")

        # step.buildslave

        self.master = fakemaster.make_master(testcase=self)
        self.buildslave = step.buildslave = slave.FakeSlave(self.master)

        # step.step_status

        ss = self.step_status = mock.Mock(name="step_status")

        ss.status_text = None
        ss.logs = {}

        def ss_setText(strings):
            ss.status_text = strings

        ss.setText = ss_setText

        ss.getLogs = lambda: ss.logs.values()

        self.step_statistics = {}
        ss.setStatistic = self.step_statistics.__setitem__
        ss.getStatistic = self.step_statistics.get
        ss.hasStatistic = self.step_statistics.__contains__

        self.step.setStepStatus(ss)

        # step overrides

        def addLog(name):
            l = remotecommand.FakeLogFile(name, step)
            ss.logs[name] = l
            return l

        step.addLog = addLog

        def addHTMLLog(name, html):
            l = remotecommand.FakeLogFile(name, step)
            l.addStdout(html)
            ss.logs[name] = l
            return l

        step.addHTMLLog = addHTMLLog

        def addCompleteLog(name, text):
            l = remotecommand.FakeLogFile(name, step)
            l.addStdout(text)
            ss.logs[name] = l
            return l

        step.addCompleteLog = addCompleteLog

        step.logobservers = self.logobservers = {}

        def addLogObserver(logname, observer):
            self.logobservers.setdefault(logname, []).append(observer)
            observer.step = step

        step.addLogObserver = addLogObserver

        # add any observers defined in the constructor, before this monkey-patch
        for n, o in step._pendingLogObservers:
            addLogObserver(n, o)

        # set defaults

        step.setDefaultWorkdir('wkdir')

        # expectations

        self.exp_outcome = None
        self.exp_properties = {}
        self.exp_missing_properties = []
        self.exp_logfiles = {}
        self.exp_hidden = False

        # check that the step's name is not None
        self.assertNotEqual(step.name, None)

        return step
Exemplo n.º 8
0
    def setupStep(self,
                  step,
                  slave_version={'*': "99.99"},
                  slave_env={},
                  buildFiles=[],
                  wantDefaultWorkdir=True,
                  wantData=True,
                  wantDb=False,
                  wantMq=False):
        """
        Set up C{step} for testing.  This begins by using C{step} as a factory
        to create a I{new} step instance, thereby testing that the the factory
        arguments are handled correctly.  It then creates a comfortable
        environment for the slave to run in, replete with a fake build and a
        fake slave.

        As a convenience, it can set the step's workdir with C{'wkdir'}.

        @param slave_version: slave version to present, as a dictionary mapping
            command name to version.  A command name of '*' will apply for all
            commands.

        @param slave_env: environment from the slave at slave startup

        @param wantData(bool): Set to True to add data API connector to master.
            Default value: True.

        @param wantDb(bool): Set to True to add database connector to master.
            Default value: False.

        @param wantMq(bool): Set to True to add mq connector to master.
            Default value: False.
        """
        factory = interfaces.IBuildStepFactory(step)

        step = self.step = factory.buildStep()
        self.master = fakemaster.make_master(wantData=wantData,
                                             wantDb=wantDb,
                                             wantMq=wantMq,
                                             testcase=self)

        # set defaults
        if wantDefaultWorkdir:
            step.workdir = step._workdir or 'wkdir'

        # step.build

        b = self.build = fakebuild.FakeBuild(master=self.master)
        b.allFiles = lambda: buildFiles
        b.master = self.master

        def getSlaveVersion(cmd, oldversion):
            if cmd in slave_version:
                return slave_version[cmd]
            if '*' in slave_version:
                return slave_version['*']
            return oldversion

        b.getSlaveCommandVersion = getSlaveVersion
        b.slaveEnvironment = slave_env.copy()
        step.setBuild(b)

        # watch for properties being set
        self.properties = interfaces.IProperties(b)

        # step.progress

        step.progress = mock.Mock(name="progress")

        # step.buildslave

        self.buildslave = step.buildslave = slave.FakeSlave(self.master)

        # step overrides

        def addLog(name, type='s', logEncoding=None):
            l = logfile.FakeLogFile(name, step)
            self.step.logs[name] = l
            return defer.succeed(l)

        step.addLog = addLog
        step.addLog_newStyle = addLog

        def addHTMLLog(name, html):
            l = logfile.FakeLogFile(name, step)
            l.addStdout(html)
            return defer.succeed(None)

        step.addHTMLLog = addHTMLLog

        def addCompleteLog(name, text):
            l = logfile.FakeLogFile(name, step)
            self.step.logs[name] = l
            l.addStdout(text)
            return defer.succeed(None)

        step.addCompleteLog = addCompleteLog

        step.logobservers = self.logobservers = {}

        def addLogObserver(logname, observer):
            self.logobservers.setdefault(logname, []).append(observer)
            observer.step = step

        step.addLogObserver = addLogObserver

        # add any observers defined in the constructor, before this
        # monkey-patch
        for n, o in step._pendingLogObservers:
            addLogObserver(n, o)

        # expectations

        self.exp_result = None
        self.exp_state_string = None
        self.exp_properties = {}
        self.exp_missing_properties = []
        self.exp_logfiles = {}
        self.exp_hidden = False

        # check that the step's name is not None
        self.assertNotEqual(step.name, None)

        # mock out the reactor for updateSummary's debouncing
        self.debounceClock = task.Clock()
        step.updateSummary._reactor = self.debounceClock

        return step