Esempio n. 1
0
 def test_d_ini(self):
     self.setupSimple()
     c = Change('author', ['test-app/locales/l10n.ini'], 'comment',
                branch='test-branch')
     c.number = 1
     self.scheduler.addChange(c)
     c = Change('author', ['test-app/locales/en-US/app.dtd'], 'comment',
                branch='test-branch')
     c.number = 2
     self.scheduler.addChange(c)
     self.failUnlessEqual(len(self.master.sets), 1)
     bset = self.master.sets[0]
     self.failUnlessEqual(bset.builderNames, ['tree-builds'])
     ftb = FakeBuilder('tree-builds')
     bset.start([ftb])
     self.failUnlessEqual(len(ftb.requests), 1)
     st = bset.status
     self.failIf(st.isFinished())
     builder = builderstatus.BuilderStatus('tree-builds')
     build = builderstatus.BuildStatus(builder, 1)
     build.setResults(builderstatus.SUCCESS)
     ftb.requests[0].finished(build)
     self.failUnless(st.isFinished())
     self.failUnless(self.scheduler.dSubmitBuildsets)
     self.scheduler.dSubmitBuildsets.cancel()
     pendings = self.scheduler.pendings
     self.failUnlessEqual(len(pendings), 2)
     self.failUnlessEqual(len(pendings[('test','de')]), 1)
     self.failUnlessEqual(len(pendings[('test','fr')]), 1)
Esempio n. 2
0
    def testAnyBranch2(self):
        # like testAnyBranch but without fileIsImportant
        self.basedir = 'scheduler/Scheduling/AnyBranch2'
        self.create_master()
        s = scheduler.AnyBranchScheduler("b1", 2, ["a", "b"])

        d = self.setSchedulers(s)

        def _addChange(ign, c):
            self.master.change_svc.addChange(c)

        c1 = Change("alice", ["important", "not important"],
                    "some changes",
                    branch="branch1")
        d.addCallback(_addChange, c1)
        c2 = Change("bob", ["not important", "boring"],
                    "some more changes",
                    branch="branch1")
        d.addCallback(_addChange, c2)
        c3 = Change("carol", ["important", "dull"],
                    "even more changes",
                    branch="branch1")
        d.addCallback(_addChange, c3)

        c4 = Change("carol", ["important"], "other branch", branch="branch2")
        d.addCallback(_addChange, c4)

        d.addCallback(lambda ign: self.master.scheduler_manager.when_quiet())
        d.addCallback(self._testAnyBranch2_1)
        return d
    def test_notification_started(self):
        irc = MyContact()

        my_builder = MyBuilder("builder78")
        my_build = MyIrcBuild(my_builder, 23, builder.SUCCESS)
        my_build.changes = (
            Change(who='author1',
                   files=['file1'],
                   comments='comment1',
                   revision=123),
            Change(who='author2',
                   files=['file2'],
                   comments='comment2',
                   revision=456),
        )

        irc.command_NOTIFY("on started", "mynick")

        irc.message = ""
        irc.buildStarted(my_builder.getName(), my_build)
        self.failUnlessEqual(
            irc.message, "build #23 of builder78 started including [123, 456]",
            "Start notification generated with notify_events=['started']")

        irc.message = ""
        irc.buildFinished(my_builder.getName(), my_build, None)
        self.failUnlessEqual(
            irc.message, "",
            "No finished notification with notify_events=['started']")
Esempio n. 4
0
    def _getChangeByNumber_query_done(self, res, changeid):
        (rows, link_rows, file_rows, properties) = res
        if not rows:
            return None
        (who, comments, isdir, branch, revision, revlink, when, category,
         repository, project) = rows[0]
        branch = str_or_none(branch)
        revision = str_or_none(revision)
        links = [row[0] for row in link_rows]
        links.sort()
        files = [row[0] for row in file_rows]
        files.sort()

        c = Change(who=who,
                   files=files,
                   comments=comments,
                   isdir=isdir,
                   links=links,
                   revision=revision,
                   when=when,
                   branch=branch,
                   category=category,
                   revlink=revlink,
                   repository=repository,
                   project=project)
        c.properties.updateFromProperties(properties)
        c.number = changeid
        self._change_cache.add(changeid, c)
        return c
Esempio n. 5
0
    def testAnyBranch(self):
        s = scheduler.AnyBranchScheduler("b1",
                                         None,
                                         1, ["a", "b"],
                                         fileIsImportant=self.isImportant)
        self.addScheduler(s)

        c1 = Change("alice", ["important", "not important"],
                    "some changes",
                    branch="branch1")
        s.addChange(c1)
        c2 = Change("bob", ["not important", "boring"],
                    "some more changes",
                    branch="branch1")
        s.addChange(c2)
        c3 = Change("carol", ["important", "dull"],
                    "even more changes",
                    branch="branch1")
        s.addChange(c3)

        c4 = Change("carol", ["important"], "other branch", branch="branch2")
        s.addChange(c4)

        c5 = Change("carol", ["important"], "default branch", branch=None)
        s.addChange(c5)

        d = defer.Deferred()
        reactor.callLater(2, d.callback, None)
        d.addCallback(self._testAnyBranch_1)
        return d
Esempio n. 6
0
    def _testCheck3(self, res):
        self.assertEquals(len(self.changes), 3)
        self.assertEquals(self.t.last_change, 3)
        self.assert_(not self.t.working)

        # They're supposed to go oldest to newest, so this one must be first.
        self.assertEquals(
            self.changes[0].asText(),
            Change(who='slamb',
                   files=['whatbranch'],
                   comments=change_2_log,
                   revision='2',
                   when=self.makeTime("2006/04/13 21:46:23"),
                   branch='trunk').asText())

        # These two can happen in either order, since they're from the same
        # Perforce change.
        self.failUnlessIn(
            Change(who='bob',
                   files=['branch_b_file', 'whatbranch'],
                   comments=change_3_log,
                   revision='3',
                   when=self.makeTime("2006/04/13 21:51:39"),
                   branch='branch_b').asText(),
            [c.asText() for c in self.changes])
        self.failUnlessIn(
            Change(who='bob',
                   files=['whatbranch'],
                   comments=change_3_log,
                   revision='3',
                   when=self.makeTime("2006/04/13 21:51:39"),
                   branch='branch_c').asText(),
            [c.asText() for c in self.changes])
Esempio n. 7
0
    def _getChangeByNumber_query_done(self, res, changeid):
        (rows, link_rows, file_rows, properties) = res
        if not rows:
            return None
        (who, comments, isdir, branch, revision, revlink, when, category, repository, project) = rows[0]
        branch = str_or_none(branch)
        revision = str_or_none(revision)
        links = [row[0] for row in link_rows]
        links.sort()
        files = [row[0] for row in file_rows]
        files.sort()

        c = Change(
            who=who,
            files=files,
            comments=comments,
            isdir=isdir,
            links=links,
            revision=revision,
            when=when,
            branch=branch,
            category=category,
            revlink=revlink,
            repository=repository,
            project=project,
        )
        c.properties.updateFromProperties(properties)
        c.number = changeid
        self._change_cache.add(changeid, c)
        return c
Esempio n. 8
0
    def testBranch(self):
        s = scheduler.Scheduler("b1",
                                "branch1",
                                2, ["a", "b"],
                                fileIsImportant=self.isImportant)
        self.addScheduler(s)

        c0 = Change("carol", ["important"], "other branch", branch="other")
        s.addChange(c0)
        self.failIf(s.timer)
        self.failIf(s.importantChanges)

        c1 = Change("alice", ["important", "not important"],
                    "some changes",
                    branch="branch1")
        s.addChange(c1)
        c2 = Change("bob", ["not important", "boring"],
                    "some more changes",
                    branch="branch1")
        s.addChange(c2)
        c3 = Change("carol", ["important", "dull"],
                    "even more changes",
                    branch="branch1")
        s.addChange(c3)

        self.failUnlessEqual(s.importantChanges, [c1, c3])
        self.failUnlessEqual(s.allChanges, [c1, c2, c3])
        self.failUnless(s.timer)

        d = defer.Deferred()
        reactor.callLater(4, d.callback, None)
        d.addCallback(self._testBranch_1)
        return d
    def test_lastChange(self):
        # First, we need to add a few changes!
        c1 = Change(who='me!',
                    branch='b1',
                    revision='1',
                    files=[],
                    comments='really important',
                    revlink='from poller')
        c2 = Change(who='me!',
                    branch='b2',
                    revision='2',
                    files=[],
                    comments='really important',
                    revlink='from poller')
        c3 = Change(who='me!',
                    branch='b1',
                    revision='3',
                    files=[],
                    comments='really important',
                    revlink='from poller')
        for c in [c1, c2, c3]:
            self.dbc.addChangeToDatabase(c)

        c = self.dbc.runInteractionNow(lambda t: lastChange(self.dbc, t, 'b1'))
        self.assertEquals(c.revision, c3.revision)

        c = self.dbc.runInteractionNow(lambda t: lastChange(self.dbc, t, 'b2'))
        self.assertEquals(c.revision, c2.revision)
 def testAB(self):
     self.setupSimple()
     c = Change('author', ['some/file.dtd'],
                'comment',
                branch='dir',
                properties={'locale': 'ab'})
     c.number = 1
     self.scheduler.addChange(c)
     self.failUnlessEqual(len(self.master.sets), 1)
     bset = self.master.sets[0]
     props = bset.getProperties()
     self.assertEqual(props['locale'], 'ab')
     self.assertEqual(props['branch'], 'dir')
     self.assertEqual(props['tree'], 'dir-compare')
     self.failUnlessEqual(bset.builderNames, ['dir-compare'])
     ftb = FakeBuilder('dir-compare')
     bset.start([ftb])
     self.failUnlessEqual(len(ftb.requests), 1)
     st = bset.status
     self.failIf(st.isFinished())
     builder = builderstatus.BuilderStatus('dir-compare')
     build = builderstatus.BuildStatus(builder, 1)
     build.setResults(builderstatus.SUCCESS)
     ftb.requests[0].finished(build)
     self.failUnless(st.isFinished())
Esempio n. 11
0
 def testDE(self):
     self.setupSimple()
     c = Change('author', ['some/file.dtd'], 'comment',
                branch='dir', properties={'locale': 'de'})
     c.number = 1
     self.scheduler.addChange(c)
     self.failUnlessEqual(len(self.master.sets), 0)
 def testDE(self):
     self.setupSimple()
     c = Change('author', ['some/file.dtd'],
                'comment',
                branch='dir',
                properties={'locale': 'de'})
     c.number = 1
     self.scheduler.addChange(c)
     self.failUnlessEqual(len(self.master.sets), 0)
Esempio n. 13
0
 def test_a_L10n(self):
     self.setupSimple()
     c = Change('author', ['test-app/file.dtd'], 'comment',
                branch='l10n-test', properties={'locale':'de'})
     c.number = 1
     self.scheduler.addChange(c)
     self.failUnless(self.scheduler.dSubmitBuildsets)
     self.scheduler.dSubmitBuildsets.cancel()
     pendings = self.scheduler.pendings
     self.failUnlessEqual(len(pendings), 1)
Esempio n. 14
0
 def test_b_EnUS(self):
     self.setupSimple()
     c = Change('author', ['test-app/locales/en-US/file.dtd'], 'comment',
                branch='test-branch')
     c.number = 1
     self.scheduler.addChange(c)
     self.failUnless(self.scheduler.dSubmitBuildsets)
     self.scheduler.dSubmitBuildsets.cancel()
     pendings = self.scheduler.pendings
     self.failUnlessEqual(len(pendings), 2)
Esempio n. 15
0
 def __init__(self, who, revision_delta, revision_id, comments, files=[],  isdir=0, links=[],
              revision=None, when=None, branch=None):
     self.files_added = [f[0] for f in revision_delta.added]
     self.files_modified = [f[0] for f in revision_delta.modified]
     self.files_renamed = [(f[0],f[1]) for f in revision_delta.renamed]
     self.files_removed = [f[0] for f in revision_delta.removed]
     self.ch = revision_delta
     self.revision_id = revision_id
     files =  self.files_added + self.files_modified + [f[1] for f in self.files_renamed] + self.files_removed
     Change.__init__(self, who=who, files=files, comments=comments, isdir=isdir, links=links,revision=revision, when=when, branch=branch)
Esempio n. 16
0
 def test_en_US(self):
     self.setupSimple()
     c = Change('author', ['some/file.dtd'], 'comment',
                branch='dir', properties={'locale': 'en-US'})
     c.number = 1
     self.scheduler.addChange(c)
     self.failUnlessEqual(len(self.master.sets), 2)
     locs = sorted(map(lambda bset: bset.getProperties()['locale'],
                       self.master.sets))
     self.assertEqual(locs, ['ab', 'fr'])
Esempio n. 17
0
    def testAddChange(self):
        self.basedir = "changemaster/manager/addchange"
        self.create_master()

        m = self.master.change_svc

        change = Change('user', [], 'comments', revision="123")
        m.addChange(change)
        d = self.stall(None, 0.5)

        def _check(ign):
            events = list(m.eventGenerator())
            self.failUnlessEqual(len(events), 1)
            self.failUnlessEqual(events[0].who, "user")
            self.failUnlessEqual(events[0].files, [])
            self.failUnlessEqual(events[0].number, 1)
            c1 = m.getChangeNumberedNow(1)
            self.failUnlessIdentical(c1, events[0])  # should be cached
            r = m.getChangesGreaterThan(0)
            self.failUnlessEqual(r, [c1])
            self.c1 = c1

        d.addCallback(_check)
        d.addCallback(lambda ign: m.getChangeByNumber(1))
        d.addCallback(lambda r: self.failUnlessEqual(r, self.c1))
        d.addCallback(lambda ign: m.getChangesByNumber([1]))
        d.addCallback(lambda r: self.failUnlessEqual(r, [self.c1]))

        change2 = Change('otheruser', ["foo.c"], "comments2", revision="124")
        d.addCallback(lambda ign: m.addChange(change2))
        d.addCallback(self.stall, 0.5)

        def _then(ign):
            events = list(m.eventGenerator())
            self.failUnlessEqual(len(events), 2)
            self.failUnlessEqual(events[0].who, "otheruser")
            self.failUnlessEqual(events[0].files, ["foo.c"])
            self.failUnlessEqual(events[0].number, 2)
            self.failUnlessEqual(events[1], self.c1)
            c1a = m.getChangeNumberedNow(1)
            self.failUnlessIdentical(c1a, self.c1)
            c2 = m.getChangeNumberedNow(2)
            self.failUnlessIdentical(c2, events[0])
            r = m.getChangesGreaterThan(0)
            self.failUnlessEqual(r, [self.c1, c2])

            d = m.getChangeByNumber(2)
            d.addCallback(lambda r: self.failUnlessEqual(r, c2))
            d.addCallback(lambda ign: m.getChangesByNumber([2, 1]))
            d.addCallback(lambda r: self.failUnlessEqual(r, [c2, self.c1]))
            return d

        d.addCallback(_then)
        return d
 def test_b_EnUS(self):
     self.setupSimple()
     c = Change('author', ['test-app/locales/en-US/file.dtd'],
                'comment',
                branch='test-branch')
     c.number = 1
     self.scheduler.addChange(c)
     self.failUnless(self.scheduler.dSubmitBuildsets)
     self.scheduler.dSubmitBuildsets.cancel()
     pendings = self.scheduler.pendings
     self.failUnlessEqual(len(pendings), 2)
Esempio n. 19
0
 def testAsDictChanges(self):
     changes = [
         Change('nobody', [], 'Comment', branch='br2', revision='rev2'),
         Change('nob', ['file2', 'file3'],
                'Com',
                branch='br3',
                revision='rev3'),
     ]
     s = SourceStamp(branch='Br',
                     revision='Rev',
                     patch=(1, 'Pat'),
                     changes=changes)
     r = s.asDict()
     del r['changes'][0]['when']
     del r['changes'][1]['when']
     EXPECTED = {
         'revision':
         'rev3',
         'branch':
         'br3',
         'hasPatch':
         True,
         'project':
         '',
         'repository':
         '',
         'changes': [{
             'branch': 'br2',
             'category': None,
             'comments': 'Comment',
             'files': [],
             'number': None,
             'properties': [],
             'revision': 'rev2',
             'revlink': '',
             'project': '',
             'repository': '',
             'who': 'nobody'
         }, {
             'branch': 'br3',
             'category': None,
             'comments': 'Com',
             'files': ['file2', 'file3'],
             'number': None,
             'properties': [],
             'revision': 'rev3',
             'revlink': '',
             'who': 'nob',
             'project': '',
             'repository': '',
         }],
     }
     self.assertEqual(EXPECTED, r)
 def test_a_L10n(self):
     self.setupSimple()
     c = Change('author', ['test-app/file.dtd'],
                'comment',
                branch='l10n-test',
                properties={'locale': 'de'})
     c.number = 1
     self.scheduler.addChange(c)
     self.failUnless(self.scheduler.dSubmitBuildsets)
     self.scheduler.dSubmitBuildsets.cancel()
     pendings = self.scheduler.pendings
     self.failUnlessEqual(len(pendings), 1)
 def test_en_US(self):
     self.setupSimple()
     c = Change('author', ['some/file.dtd'],
                'comment',
                branch='dir',
                properties={'locale': 'en-US'})
     c.number = 1
     self.scheduler.addChange(c)
     self.failUnlessEqual(len(self.master.sets), 2)
     locs = sorted(
         map(lambda bset: bset.getProperties()['locale'], self.master.sets))
     self.assertEqual(locs, ['ab', 'fr'])
Esempio n. 22
0
 def __init__(self, **kwargs):
     self.branch_id = kwargs.pop('branch_id')
     self.filesb = kwargs.pop('filesb',[])
     self.hash = kwargs.pop('hash', None)
     self.number = kwargs.pop('id', None)
     self.authors = kwargs.pop('authors', [])
     files = kwargs.pop('files', False)
     if not files:
         files = [ x['filename'] for x in self.filesb ]
     who = kwargs.pop('who', '')
     comments = kwargs.pop('comments', '')
     # self.all_modules = list(set([ x.split('/')[0] for x in files]))
     Change.__init__(self, who, files, comments, **kwargs)
Esempio n. 23
0
    def testImportantChanges(self):
        self.basedir = 'scheduler/Scheduling/ImportantChanges'
        self.create_master()
        s = scheduler.Scheduler("b1",
                                branch="branch1",
                                treeStableTimer=2,
                                builderNames=["a", "b"],
                                fileIsImportant=self.isImportant)

        # Hijack run to prevent changes from being processed
        oldrun = s.run
        s.run = lambda: None

        d = self.setSchedulers(s)

        def _addChange(ign, c):
            self.master.change_svc.addChange(c)
            self.master.scheduler_manager.trigger()
            return self.master.db.runInteraction(s.classify_changes)

        c1 = Change("alice", ["important", "not important"],
                    "some changes",
                    branch="branch1")
        d.addCallback(_addChange, c1)
        c2 = Change("bob", ["not important", "boring"],
                    "some more changes",
                    branch="branch1")
        d.addCallback(_addChange, c2)
        c3 = Change("carol", ["important", "dull"],
                    "even more changes",
                    branch="branch1")
        d.addCallback(_addChange, c3)

        def _check(ign):
            important, unimportant = self.master.db.runInteractionNow(
                lambda t: self.master.db.scheduler_get_classified_changes(
                    s.schedulerid, t))
            important = [c.number for c in important]
            unimportant = [c.number for c in unimportant]
            self.failUnlessEqual(important, [c1.number, c3.number])
            self.failUnlessEqual(unimportant, [c2.number])
            s.run = oldrun
            d1 = s.run()
            d1.addCallback(lambda ign: self.master.scheduler_manager.trigger())
            d1.addCallback(
                lambda ign: self.master.scheduler_manager.when_quiet())
            return d1

        d.addCallback(_check)
        d.addCallback(self._testBranch_1)
        return d
 def change14(self):
     c = Change(**dict(category='devel',
                       isdir=0,
                       repository=u'git://warner',
                       who=u'warner',
                       when=266738404,
                       comments=u'fix whitespace',
                       project=u'Buildbot',
                       branch=u'warnerdb',
                       revlink=u'http://warner/0e92a098b',
                       properties={},
                       files=[u'master/buildbot/__init__.py'],
                       revision=u'0e92a098b'))
     c.number = 14
     return c
Esempio n. 25
0
 def test_repo_downloads_from_change_source(self):
     """basic repo download from change source, and check that repo_downloaded is updated"""
     self.mySetupStep(repoDownloads=repo.RepoDownloadsFromChangeSource())
     change = Change(None, None, None, properties={
         'event.change.owner.email': '*****@*****.**',
         'event.change.subject': 'fix 1234',
         'event.change.project': 'pr',
         'event.change.owner.name': 'Dustin',
         'event.change.number': '4321',
         'event.change.url': 'http://buildbot.net',
         'event.change.branch': 'br',
         'event.type': 'patchset-created',
         'event.patchSet.revision': 'abcdef',
         'event.patchSet.number': '12',
         'event.source': 'GerritChangeSource'
     })
     self.build.allChanges = lambda x=None: [change]
     self.expectnoClobber()
     self.expectRepoSync()
     self.expectCommands(
         self.ExpectShell(command=['repo', 'download', 'pr', '4321/12'])
         + 0
         + Expect.log(
             'stdio', stderr="test/bla refs/changes/64/564/12 -> FETCH_HEAD\n")
         + Expect.log('stdio', stderr="HEAD is now at 0123456789abcdef...\n"))
     self.expectProperty(
         "repo_downloaded", "564/12 0123456789abcdef ", "Source")
     return self.myRunStep()
Esempio n. 26
0
    def create_changes(self, new_logentries):
        changes = []

        for el in new_logentries:
            branch_files = [] # get oldest change first
            revision = str(el.getAttribute("revision"))
            dbgMsg("Adding change revision %s" % (revision,))
            # TODO: the rest of buildbot may not be ready for unicode 'who'
            # values
            author   = self._get_text(el, "author")
            comments = self._get_text(el, "msg")
            # there is a "date" field, but it provides localtime in the
            # repository's timezone, whereas we care about buildmaster's
            # localtime (since this will get used to position the boxes on
            # the Waterfall display, etc). So ignore the date field and use
            # our local clock instead.
            #when     = self._get_text(el, "date")
            #when     = time.mktime(time.strptime("%.19s" % when,
            #                                     "%Y-%m-%dT%H:%M:%S"))
            branches = {}
            pathlist = el.getElementsByTagName("paths")[0]
            for p in pathlist.getElementsByTagName("path"):
                action = p.getAttribute("action")
                path = "".join([t.data for t in p.childNodes])
                # the rest of buildbot is certaily not yet ready to handle
                # unicode filenames, because they get put in RemoteCommands
                # which get sent via PB to the buildslave, and PB doesn't
                # handle unicode.
                path = path.encode("ascii")
                if path.startswith("/"):
                    path = path[1:]
                where = self._transform_path(path)

                # if 'where' is None, the file was outside any project that
                # we care about and we should ignore it
                if where:
                    branch, filename = where
                    if not branch in branches:
                        branches[branch] = { 'files': []}
                    branches[branch]['files'].append(filename)

                    if not branches[branch].has_key('action'):
                        branches[branch]['action'] = action

            for branch in branches.keys():
                action = branches[branch]['action']
                files  = branches[branch]['files']
                number_of_files_changed = len(files)

                if action == u'D' and number_of_files_changed == 1 and files[0] == '':
                    log.msg("Ignoring deletion of branch '%s'" % branch)
                else:
                    c = Change(who=author,
                               files=files,
                               comments=comments,
                               revision=revision,
                               branch=branch)
                    changes.append(c)

        return changes
Esempio n. 27
0
 def test_Change_fromChdict_with_chdict(self):
     # test that the chdict getChange returns works with Change.fromChdict
     d = Change.fromChdict(mock.Mock(), self.change14_dict)
     def check(c):
         self.assertChangesEqual(c, self.change14())
     d.addCallback(check)
     return d
Esempio n. 28
0
 def change14(self):
     c = Change(**dict(
      category='devel',
      isdir=0,
      repository=u'git://warner',
      who=u'warner',
      when=266738404,
      comments=u'fix whitespace',
      project=u'Buildbot',
      branch=u'warnerdb',
      revlink=u'http://warner/0e92a098b',
      properties={},
      files=[u'master/buildbot/__init__.py'],
      revision=u'0e92a098b'))
     c.number = 14
     return c
Esempio n. 29
0
 def test_Change_fromChdict_with_chdict(self):
     # test that the chdict getChange returns works with Change.fromChdict
     d = Change.fromChdict(mock.Mock(), self.change14_dict)
     def check(c):
         self.assertChangesEqual(c, self.change14())
     d.addCallback(check)
     return d
    def testPropsScheduler(self):
        S = makePropertiesScheduler(
            Scheduler, propfuncs=[buildIDSchedFunc, buildUIDSchedFunc])
        s = S(name="s", builderNames=["b1"])
        s.parent = mock.Mock()
        s.parent.db = self.dbc

        c1 = Change(who='me!',
                    branch='b1',
                    revision='1',
                    files=[],
                    comments='really important')
        self.dbc.addChangeToDatabase(c1)
        s.parent.change_svc.getChangesGreaterThan.return_value = [c1]

        d = self.dbc.addSchedulers([s])

        d.addCallback(lambda ign: s.run())

        def check(ign):
            requests = self.dbc.runQueryNow("select * from buildrequests")
            self.assertEquals(len(requests), 1)
            props = self.dbc.runQueryNow("select * from buildset_properties")
            self.assertEquals(len(props), 3)
            # Make sure we haven't modifed the scheduler's internal set of
            # properties
            self.assertEquals(s.properties.asList(),
                              [("scheduler", "s", "Scheduler")])

        d.addCallback(check)
        return d
Esempio n. 31
0
    def test_create_scheduler_changes(self):
        s = timed.Nightly(name="tsched",
                          builderNames=['tbuild'],
                          onlyIfChanged=True)
        s.parent = DummyParent(self.dbc)

        d = self.dbc.addSchedulers([s])

        # Add some changes
        for i in range(10):
            c = Change(who='just a guy', files=[], comments="")
            d.addCallback(lambda res: self.dbc.addChangeToDatabase(c))

        def runScheduler(res):
            return s.run()

        d.addCallback(runScheduler)

        def checkTables(res):
            # Check that we have the number of changes we think we should have
            self.assertEquals(len(self.dbc.changes), 10)

            # Check that there are entries in scheduler_changes
            important, unimportant = self.dbc.classified_changes.get(
                s.schedulerid, ([], []))
            self.assertEquals(len(important + unimportant), 10)

        d.addCallback(checkTables)
        return d
    def test_lastRevFunc(self):
        createTestData(self.dbc)
        self.s.builderNames = ['builder1']

        # Check that ssFunc returns something for both branches
        ssFunc = lastRevFunc('b1')
        ss = self.dbc.runInteractionNow(lambda t: ssFunc(self.s, t))
        self.assertEquals(ss.revision, 'r1')

        ssFunc = lastRevFunc('b2')
        ss = self.dbc.runInteractionNow(lambda t: ssFunc(self.s, t))
        self.assertEquals(ss.revision, 'r234567890')

        # Check that ssFunc returns None if triggerBuildIfNoChanges=False
        # and we already built the revision
        ssFunc = lastRevFunc('b1', triggerBuildIfNoChanges=False)
        ss = self.dbc.runInteractionNow(lambda t: ssFunc(self.s, t))
        self.assertEquals(ss, None)

        # Check that ssFunc returns the later revision if we already built
        # something old
        c1 = Change(who='me!',
                    branch='b1',
                    revision='r345',
                    files=[],
                    comments='really important',
                    when=2,
                    revlink='from poller')
        self.dbc.addChangeToDatabase(c1)
        ssFunc = lastRevFunc('b1', triggerBuildIfNoChanges=False)
        ss = self.dbc.runInteractionNow(lambda t: ssFunc(self.s, t))
        self.assertEquals(ss.revision, 'r345')
Esempio n. 33
0
 def testChange(self):
     s = self.status
     c = Change("user", ["foo.c"], "comments")
     self.master.change_svc.addChange(c)
     # TODO: something more like s.getChanges(), requires IChange and
     # an accessor in IStatus. The HTML page exists already, though
     self.assertURLEqual(c, "changes/1")
Esempio n. 34
0
    def testUTF16Change(self):
        # Create changes.pck
        cm = OldChangeMaster()
        cm.changes = [
            Change(who=u"Frosty the \N{SNOWMAN}".encode("utf16"),
                   files=["foo"],
                   comments=u"Frosty the \N{SNOWMAN}".encode("utf16"),
                   branch="b1",
                   revision=12345)
        ]

        # instead of running contrib/fix_changes_pickle_encoding.py, we just call
        # the changemanager's recode_changes directly - it's the function at the
        # heart of the script anyway.
        cm.recode_changes('utf16', quiet=True)

        # and dump the recoded changemanager to changes.pck before trying a schema upgrade
        cPickle.dump(cm, open(os.path.join(self.basedir, "changes.pck"), "w"))

        sm = manager.DBSchemaManager(self.spec, self.basedir)
        sm.upgrade(quiet=True)

        c = self.db.getChangeNumberedNow(1)

        self.assertEquals(c.who, u"Frosty the \N{SNOWMAN}")
        self.assertEquals(c.comments, u"Frosty the \N{SNOWMAN}")
Esempio n. 35
0
    def testOffBranch(self):
        self.basedir = 'scheduler/Scheduling/OffBranch'
        self.create_master()
        s = scheduler.Scheduler("b1",
                                branch="branch1",
                                treeStableTimer=2,
                                builderNames=["a", "b"],
                                fileIsImportant=self.isImportant)
        d = self.setSchedulers(s)

        def _addChange(ign, c):
            self.master.change_svc.addChange(c)
            return self.master.scheduler_manager.when_quiet()

        c0 = Change("carol", ["important"], "other branch", branch="other")
        d.addCallback(_addChange, c0)

        def _check(ign):
            important, unimportant = self.master.db.runInteractionNow(
                lambda t: self.master.db.scheduler_get_classified_changes(
                    s.schedulerid, t))
            self.failIf(important)
            self.failIf(unimportant)

        d.addCallback(_check)
 def addChange(files=None, comments=None, author=None, revision=None,
               when_timestamp=None, branch=None, repository='', codebase='',
               category='', project='', src=None):
     self.changes_added.append(Change(revision=revision, files=files,
                          who=author, branch=branch, comments=comments,
                          when=datetime2epoch(when_timestamp), repository=repository, codebase=codebase))
     return defer.succeed(None)
Esempio n. 37
0
 def test_repo_downloads_from_change_source_codebase(self):
     """basic repo download from change source, and check that repo_downloaded is updated"""
     self.mySetupStep(
         repoDownloads=repo.RepoDownloadsFromChangeSource("mycodebase"))
     change = Change(None,
                     None,
                     None,
                     properties={
                         'event.change.owner.email': '*****@*****.**',
                         'event.change.subject': 'fix 1234',
                         'event.change.project': 'pr',
                         'event.change.owner.name': 'Dustin',
                         'event.change.number': '4321',
                         'event.change.url': 'http://buildbot.net',
                         'event.change.branch': 'br',
                         'event.type': 'patchset-created',
                         'event.patchSet.revision': 'abcdef',
                         'event.patchSet.number': '12',
                         'event.source': 'GerritChangeSource'
                     })
     # getSourceStamp is faked by SourceStepMixin
     ss = self.build.getSourceStamp("")
     ss.changes = [change]
     self.expectnoClobber()
     self.expectRepoSync()
     self.expect_commands(
         self.ExpectShell(
             command=['repo', 'download', 'pr', '4321/12']).exit(0).stderr(
                 "test/bla refs/changes/64/564/12 -> FETCH_HEAD\n").stderr(
                     "HEAD is now at 0123456789abcdef...\n"))
     self.expect_property("repo_downloaded", "564/12 0123456789abcdef ",
                          "Source")
     return self.myRunStep()
Esempio n. 38
0
 def notify(self, root, files, message, user):
     pathnames = []
     isdir = 0
     for f in files:
         if not isinstance(
                 f,
             (cvstoys.common.VersionedPatch, cvstoys.common.Directory)):
             continue
         pathname, filename = f.pathname, f.filename
         #r1, r2 = getattr(f, 'r1', None), getattr(f, 'r2', None)
         if isinstance(f, cvstoys.common.Directory):
             isdir = 1
         path = os.path.join(pathname, filename)
         log.msg("FreshCVS notify '%s'" % path)
         if self.prefix:
             if path.startswith(self.prefix):
                 path = path[len(self.prefix):]
             else:
                 continue
         pathnames.append(path)
     if pathnames:
         # now() is close enough: FreshCVS *is* realtime, after all
         when = util.now()
         c = Change(user, pathnames, message, isdir, when=when)
         self.parent.addChange(c)
Esempio n. 39
0
    def _txn_getChangeNumberedNow(self, t, changeid):
        q = self.quoteq(
            "SELECT author, comments,"
            " is_dir, branch, revision, revlink,"
            " when_timestamp, category,"
            " repository, project"
            " FROM changes WHERE changeid = ?"
        )
        t.execute(q, (changeid,))
        rows = t.fetchall()
        if not rows:
            return None
        (who, comments, isdir, branch, revision, revlink, when, category, repository, project) = rows[0]
        branch = str_or_none(branch)
        revision = str_or_none(revision)
        q = self.quoteq("SELECT link FROM change_links WHERE changeid=?")
        t.execute(q, (changeid,))
        rows = t.fetchall()
        links = [row[0] for row in rows]
        links.sort()

        q = self.quoteq("SELECT filename FROM change_files WHERE changeid=?")
        t.execute(q, (changeid,))
        rows = t.fetchall()
        files = [row[0] for row in rows]
        files.sort()

        p = self.get_properties_from_db("change_properties", "changeid", changeid, t)
        from buildbot.changes.changes import Change

        c = Change(
            who=who,
            files=files,
            comments=comments,
            isdir=isdir,
            links=links,
            revision=revision,
            when=when,
            branch=branch,
            category=category,
            revlink=revlink,
            repository=repository,
            project=project,
        )
        c.properties.updateFromProperties(p)
        c.number = changeid
        return c
Esempio n. 40
0
 def gci(id):
     chdict = yield master.db.changes.getChange(id)
     if chdict:
         change = yield Change.fromChdict(master, chdict)
         defer.returnValue(change)
     else:
         # change isn't in the DB, so ignore it
         return
Esempio n. 41
0
 def change13(self):
     c = Change(**dict(
      category=None,
      isdir=0,
      repository=u'',
      links=[u'http://buildbot.net', u'http://sf.net/projects/buildbot'],
      who=u'dustin',
      when=266738400,
      comments=u'fix spelling',
      project=u'',
      branch=u'master',
      revlink=None,
      properties={u'notest': u'no'},
      files=[u'master/README.txt', u'slave/README.txt'],
      revision=u'deadbeef'))
     c.number = 13
     return c
 def getExpectedChangesHg(self, repository, bookmark=True):
     return self.getExpectedChanges(repository, bookmark) + [
             # backwards compatibility
             Change(revision=u'68475k937dj69dk20567845jh9456726153hv47g7', files=None,
                    who=u'dev5 <*****@*****.**>', branch=u'1.0/devOld', comments=u'list of changes5',
                    when=1421667231, category=None, project='',
                    repository=repository, codebase=''),
             ]
Esempio n. 43
0
 def gci(id):
     chdict = yield master.db.changes.getChange(id)
     if chdict:
         change = yield Change.fromChdict(master, chdict)
         defer.returnValue(change)
     else:
         # change isn't in the DB, so ignore it
         return
Esempio n. 44
0
 def change14(self):
     c = Change(
         **dict(
             category="devel",
             isdir=0,
             repository=u"git://warner",
             links=[],
             who=u"warner",
             when=266738404,
             comments=u"fix whitespace",
             project=u"Buildbot",
             branch=u"warnerdb",
             revlink=u"http://warner/0e92a098b",
             properties={},
             files=[u"master/buildbot/__init__.py"],
             revision=u"0e92a098b",
         )
     )
     c.number = 14
     return c
Esempio n. 45
0
 def asDict(self):
     res = Change.asDict(self)
     res['branch_id'] = self.branch_id
     if self.hash:
         res['hash'] = self.hash
     if self.filesb:
         res['filesb'] = self.filesb
     res['authors'] = self.authors
     if (not res.get('revlink',False)) and self.branch and self.revision:
         if self.branch.startswith('lp:'):
             res['revlink'] = "http://bazaar.launchpad.net/%s/revision/%s" % \
                             (self.branch[3:], self.revision)
     return res
Esempio n. 46
0
 def testAB(self):
     self.setupSimple()
     c = Change('author', ['some/file.dtd'], 'comment',
                branch='dir', properties={'locale': 'ab'})
     c.number = 1
     self.scheduler.addChange(c)
     self.failUnlessEqual(len(self.master.sets), 1)
     bset = self.master.sets[0]
     props = bset.getProperties()
     self.assertEqual(props['locale'], 'ab')
     self.assertEqual(props['branch'], 'dir')
     self.assertEqual(props['tree'], 'dir-compare')
     self.failUnlessEqual(bset.builderNames, ['dir-compare'])
     ftb = FakeBuilder('dir-compare')
     bset.start([ftb])
     self.failUnlessEqual(len(ftb.requests), 1)
     st = bset.status
     self.failIf(st.isFinished())
     builder = builderstatus.BuilderStatus('dir-compare')
     build = builderstatus.BuildStatus(builder, 1)
     build.setResults(builderstatus.SUCCESS)
     ftb.requests[0].finished(build)
     self.failUnless(st.isFinished())
Esempio n. 47
0
    def create_changes(self, info):
        if info is None:
            # Got no consistent revision
            log.msg('TarPoller: got no consistent revision')
            return None
        (revision, links) = info
        if self.last_revision is None:
            log.msg('TarPoller: start revision is %r' % (revision,))
            self.last_revision = revision
            return None
        if self.last_revision == revision:
            # No change from last revision
            log.msg('TarPoller: still at previous revision: %r' % (revision,))
            return None
        self.last_revision = revision

        log.msg('TarPoller: new revision found: %r' % (revision,))
        c = Change(who='',
                   files=[],
                   comments='',
                   revision=revision,
                   branch=self.branch)
        c.links = links
        return c
Esempio n. 48
0
 def get_change_by_id(self, change_id):
   """Returns buildot.changes.changes.Change as Deferred for |change_id|."""
   chdict = yield self.master.db.changes.getChange(change_id)
   change = yield Change.fromChdict(self.master, chdict)
   returnValue(change)
Esempio n. 49
0
 def _change_from_chdict(self, chdict):
     # create a Change object, given a chdict
     changeid = chdict.pop('number')
     c = Change(**chdict)
     c.number = changeid
     return c
Esempio n. 50
0
 def gci(id):
     d = master.db.changes.getChange(id)
     d.addCallback(lambda chdict :
         Change.fromChdict(master, chdict))
     return d