Ejemplo n.º 1
0
 def test_getProperty(self):
     bs = buildstep.BuildStep()
     bs.build = fakebuild.FakeBuild()
     props = bs.build.build_status.properties = mock.Mock()
     bs.getProperty("xyz", 'b')
     props.getProperty.assert_called_with("xyz", 'b')
     bs.getProperty("xyz")
     props.getProperty.assert_called_with("xyz", None)
Ejemplo n.º 2
0
 def test_setProperty(self):
     bs = buildstep.BuildStep()
     bs.build = fakebuild.FakeBuild()
     props = bs.build.build_status.properties = mock.Mock()
     bs.setProperty("x", "y", "t")
     props.setProperty.assert_called_with("x", "y", "t", runtime=True)
     bs.setProperty("x", "abc", "test", runtime=True)
     props.setProperty.assert_called_with("x", "abc", "test", runtime=True)
Ejemplo n.º 3
0
 def setup_summary_test(self):
     self.patch(NewStyleStep, 'getCurrentSummary',
                lambda self: defer.succeed({'step': 'C'}))
     self.patch(NewStyleStep, 'getResultSummary',
                lambda self: defer.succeed({'step': 'CS', 'build': 'CB'}))
     step = NewStyleStep()
     step.master = fakemaster.make_master(self, wantData=True, wantDb=True)
     step.stepid = 13
     step.build = fakebuild.FakeBuild()
     return step
Ejemplo n.º 4
0
    def test_TriggerStepMultiMasterMode(self):
        m = fakemaster.FakeMaster()
        m.maybeStartBuildsForSlave = lambda slave: True
        m.status = master.Status(m)
        m.config.buildbotURL = "baseurl/"
        m.config.multiMaster = True
        m.db = fakedb.FakeDBConnector(self)

        scheduler_a = FakeTriggerable(name='a')

        m.allSchedulers = lambda: [scheduler_a]

        def trigger_sch(sourcestamps = None, set_props=None, triggeredbybrid=None, reason=None):
            rows = [ fakedb.MasterConfig(id=1,  buildbotURL="build-master-01/", objectid=1),
                     fakedb.MasterConfig(id=2, buildbotURL="build-master-02/", objectid=2),
                     fakedb.SourceStampSet(id=1),
                     fakedb.SourceStamp(id=1, sourcestampsetid=1, codebase='c',
                                        branch="az", repository="xz", revision="ww"),
                     fakedb.Buildset(id=1, reason='because', sourcestampsetid=1),
                     fakedb.BuildRequest(id=1, buildsetid=1, buildername="builder1", submitted_at=130000),
                     fakedb.BuildRequest(id=2, buildsetid=1, buildername="builder2", submitted_at=130000),
                     fakedb.BuildRequestClaim(brid=1, objectid=2, claimed_at=130000),
                     fakedb.BuildRequestClaim(brid=2, objectid=1, claimed_at=130000),
                     fakedb.Build(id=1, number=1, brid=1),
                     fakedb.Build(id=2, number=1, brid=2)]

            d = m.db.insertTestData(rows)
            d.addCallback(lambda _: (SUCCESS,  {'builder1': 1L, 'builder2': 2L}))
            return d

        scheduler_a.trigger = trigger_sch
        self.step = trigger.Trigger(schedulerNames=['a'], waitForFinish=True)
        self.step.addCompleteLog = lambda x,y: True
        self.step.step_status = Mock()
        self.step.step_status.getLogs = lambda: []
        self.expected_urls = []
        self.step.step_status.addURL = lambda text, path, results=None: \
            self.expected_urls.append({'text': text, 'path': path})
        self.step.build = fakebuild.FakeBuild()
        self.step.build.builder.botmaster = m.botmaster

        self.step.build.getAllSourceStamps = lambda: []
        self.step.build.build_status.getAllGotRevisions = lambda: {}
        request = Mock()
        request.id = 1
        self.step.build.requests = [request]

        self.remote = Mock(name="SlaveBuilder(remote)")
        yield self.step.startStep(self.remote)

        self.assertEquals(len(self.expected_urls), 2)
        self.assertTrue({'text': 'builder1 #1', 'path': 'build-master-02/builders/builder1/builds/1'}
                         in self.expected_urls)
        self.assertTrue({'text': 'builder1 #1', 'path': 'build-master-02/builders/builder1/builds/1'}
                        in self.expected_urls)
Ejemplo n.º 5
0
 def setup_summary_test(self):
     self.clock = task.Clock()
     self.patch(NewStyleStep, 'getCurrentSummary',
                lambda self: defer.succeed({'step': u'C'}))
     self.patch(NewStyleStep, 'getResultSummary',
                lambda self: defer.succeed({'step': u'CS', 'build': u'CB'}))
     step = NewStyleStep()
     step.master = fakemaster.make_master(testcase=self,
                                          wantData=True, wantDb=True)
     step.master.reactor = self.clock
     step.stepid = 13
     step.step_status = mock.Mock()
     step.build = fakebuild.FakeBuild()
     return step
Ejemplo n.º 6
0
    def test_runCommand(self):
        bs = buildstep.BuildStep()
        bs.worker = worker.FakeWorker(master=None)  # master is not used here
        bs.remote = 'dummy'
        bs.build = fakebuild.FakeBuild()
        bs.build.builder.name = 'fake'
        cmd = remotecommand.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)
Ejemplo n.º 7
0
    def setupStep(self, step, worker_version=None, worker_env=None,
                  buildFiles=None, 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 factory
        arguments are handled correctly.  It then creates a comfortable
        environment for the worker to run in, replete with a fake build and a
        fake worker.

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

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

        @param worker_env: environment from the worker at worker 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.
        """
        if worker_version is None:
            worker_version = {
                '*': '99.99'
            }

        if worker_env is None:
            worker_env = dict()

        if buildFiles is None:
            buildFiles = list()

        factory = interfaces.IBuildStepFactory(step)

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

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

        # 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 getWorkerVersion(cmd, oldversion):
            if cmd in worker_version:
                return worker_version[cmd]
            if '*' in worker_version:
                return worker_version['*']
            return oldversion
        b.getWorkerCommandVersion = getWorkerVersion
        b.workerEnvironment = worker_env.copy()
        step.setBuild(b)

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

        # step.progress

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

        # step.worker

        self.worker = step.worker = worker.FakeWorker(self.master)

        # step overrides

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

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

        def addCompleteLog(name, text):
            _log = logfile.FakeLogFile(name, step)
            self.step.logs[name] = _log
            _log.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
        self.exp_exception = None

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

        return step
Ejemplo n.º 8
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
Ejemplo n.º 9
0
    def setupStep(self,
                  step,
                  worker_version=None,
                  worker_env=None,
                  buildFiles=None,
                  wantDefaultWorkdir=True):
        """
        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 factory
        arguments are handled correctly.  It then creates a comfortable
        environment for the worker to run in, replete with a fake build and a
        fake worker.

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

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

        @param worker_env: environment from the worker at worker startup
        """
        if worker_version is None:
            worker_version = {'*': '99.99'}

        if worker_env is None:
            worker_env = dict()

        if buildFiles is None:
            buildFiles = list()

        step = self.step = buildstep.create_step_from_step_or_factory(step)

        # 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 getWorkerVersion(cmd, oldversion):
            if cmd in worker_version:
                return worker_version[cmd]
            if '*' in worker_version:
                return worker_version['*']
            return oldversion

        b.getWorkerCommandVersion = getWorkerVersion
        b.workerEnvironment = worker_env.copy()
        step.setBuild(b)

        self.build.builder.config.env = worker_env.copy()

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

        # step.progress

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

        # step.worker

        self.worker = step.worker = worker.FakeWorker(self.master)
        self.worker.attached(None)

        # step overrides

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

        step.addLog = addLog

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

        step.addHTMLLog = addHTMLLog

        def addCompleteLog(name, text):
            _log = logfile.FakeLogFile(name)
            if name in self.step.logs:
                raise Exception(
                    'Attempt to add log {} twice to the logs'.format(name))
            self.step.logs[name] = _log
            _log.addStdout(text)
            return defer.succeed(None)

        step.addCompleteLog = addCompleteLog

        self._got_test_result_sets = []
        self._next_test_result_set_id = 1000

        def add_test_result_set(description, category, value_unit):
            self._got_test_result_sets.append(
                (description, category, value_unit))

            setid = self._next_test_result_set_id
            self._next_test_result_set_id += 1
            return defer.succeed(setid)

        step.addTestResultSet = add_test_result_set

        self._got_test_results = []

        def add_test_result(setid,
                            value,
                            test_name=None,
                            test_code_path=None,
                            line=None,
                            duration_ns=None):
            self._got_test_results.append(
                (setid, value, test_name, test_code_path, line, duration_ns))

        step.addTestResult = add_test_result

        self._got_build_data = {}

        def set_build_data(name, value, source):
            self._got_build_data[name] = (value, source)
            return defer.succeed(None)

        step.setBuildData = set_build_data

        # expectations

        self.exp_result = None
        self.exp_state_string = None
        self.exp_properties = {}
        self.exp_missing_properties = []
        self.exp_logfiles = {}
        self._exp_logfiles_stderr = {}
        self.exp_hidden = False
        self.exp_exception = None
        self._exp_test_result_sets = []
        self._exp_test_results = []
        self._exp_build_data = {}

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

        return step
Ejemplo n.º 10
0
    def setup_step(self, step, worker_version=None, worker_env=None,
                   build_files=None, want_default_work_dir=True):

        if worker_version is None:
            worker_version = {
                '*': '99.99'
            }

        if worker_env is None:
            worker_env = {}

        if build_files is None:
            build_files = []

        step = self.step = buildstep.create_step_from_step_or_factory(step)

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

        # step.build

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

        def getWorkerVersion(cmd, oldversion):
            if cmd in worker_version:
                return worker_version[cmd]
            if '*' in worker_version:
                return worker_version['*']
            return oldversion
        b.getWorkerCommandVersion = getWorkerVersion
        b.workerEnvironment = worker_env.copy()
        step.setBuild(b)

        self.build.builder.config.env = worker_env.copy()

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

        # step.progress

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

        # step.worker

        self.worker = step.worker = worker.FakeWorker(self.master)
        self.worker.attached(None)

        # step overrides

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

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

        def addCompleteLog(name, text):
            _log = logfile.FakeLogFile(name)
            if name in self.step.logs:
                raise Exception(f'Attempt to add log {name} twice to the logs')
            self.step.logs[name] = _log
            _log.addStdout(text)
            return defer.succeed(None)
        step.addCompleteLog = addCompleteLog

        self._got_test_result_sets = []
        self._next_test_result_set_id = 1000

        def add_test_result_set(description, category, value_unit):
            self._got_test_result_sets.append((description, category, value_unit))

            setid = self._next_test_result_set_id
            self._next_test_result_set_id += 1
            return defer.succeed(setid)

        step.addTestResultSet = add_test_result_set

        self._got_test_results = []

        def add_test_result(setid, value, test_name=None, test_code_path=None, line=None,
                            duration_ns=None):
            self._got_test_results.append((setid, value, test_name, test_code_path, line,
                                           duration_ns))
        step.addTestResult = add_test_result

        self._got_build_data = {}

        def set_build_data(name, value, source):
            self._got_build_data[name] = (value, source)
            return defer.succeed(None)

        step.setBuildData = set_build_data

        # expectations

        self.exp_result = None
        self.exp_state_string = None
        self.exp_properties = {}
        self.exp_missing_properties = []
        self.exp_logfiles = {}
        self._exp_logfiles_stderr = {}
        self.exp_hidden = False
        self.exp_exception = None
        self._exp_test_result_sets = []
        self._exp_test_results = []
        self._exp_build_data = {}

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

        return step
Ejemplo n.º 11
0
    def setupStep(self,
                  step,
                  slave_version={'*': "99.99"},
                  slave_env={},
                  buildFiles=[]):
        """
        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 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(wantData=True, testcase=self)

        # 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)

        # set defaults

        step.setDefaultWorkdir('wkdir')

        # expectations

        self.exp_result = None
        self.exp_state_strings = 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
Ejemplo n.º 12
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; defaults to "99.99"

        @param slave_env: environment from the slave at slave startup
        """
        # yes, Virginia, "factory" refers both to the tuple and its first
        # element TODO: fix that up
        factory, args = step.getStepFactory()
        step = self.step = factory(**args)

        # step.build

        b = self.build = fakebuild.FakeBuild()
        b.getSlaveCommandVersion = lambda command, oldversion: slave_version
        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

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

        # 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)
            ss.logs[name] = l
            return l

        step.addLog = addLog

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

        step.addHTMLLog = addHTMLLog

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

        step.addCompleteLog = addCompleteLog

        # set defaults

        step.setDefaultWorkdir('wkdir')

        # expectations

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

        return step