def test_savedProperties(self):
        sched = self.makeScheduler(name='test', builderNames=['test'],
                minute=[5], codebases={'cb':{'repository':'annoying'}})
        self.db.insertTestData([
            fakedb.Object(id=self.SCHEDULERID, name='test', class_name='NightlyTriggerable'),
            fakedb.ObjectState(objectid=self.SCHEDULERID, name='lastTrigger',
                value_json='[ {"cb": {"project": "p", "repository": "r", "branch": "br", "revision": "myrev"}} , {"testprop": ["test", "TEST"]} ]'),
        ])

        sched.startService()

        self.clock.advance(60*60) # Run for 1h

        self.db.buildsets.assertBuildset('?',
                dict(external_idstring=None,
                     properties=[
                         ('scheduler', ('test', 'Scheduler')),
                         ('testprop', ('test', 'TEST')),
                     ],
                     reason="The NightlyTriggerable scheduler named 'test' triggered this build",
                     sourcestampsetid=100),
                {'cb':
                 dict(branch='br', project='p', repository='r', codebase='cb',
                     revision='myrev', sourcestampsetid=100)
                })
Exemplo n.º 2
0
    def test_preStartConsumingChanges_existing(self):
        sched = self.makeFullScheduler(name='test',
                                       builderNames=['test'],
                                       treeStableTimer=None,
                                       branch='master',
                                       codebases=self.codebases,
                                       createAbsoluteSourceStamps=True)

        self.db.insertTestData([
            fakedb.Object(id=self.OBJECTID,
                          name='test',
                          class_name='SingleBranchScheduler'),
            fakedb.ObjectState(
                objectid=self.OBJECTID,
                name='lastCodebases',
                value_json='{"a": {"branch": "master", "repository": "A", '
                '"revision": "1234:abc",  "lastChange": 13}}')
        ])

        yield sched.preStartConsumingChanges()
        self.assertEqual(
            sched._lastCodebases, {
                'a': {
                    'branch': 'master',
                    'lastChange': 13,
                    'repository': 'A',
                    'revision': '1234:abc'
                }
            })
Exemplo n.º 3
0
 def test_getState_badjson(self):
     d = self.insertTestData([
         fakedb.Object(id=10, name='x', class_name='y'),
         fakedb.ObjectState(objectid=10, name='x', value_json='ff[1'),
     ])
     d.addCallback(lambda _: self.db.state.getState(10, 'x'))
     return self.assertFailure(d, TypeError)
    def test_savedProperties(self):
        sched = self.makeScheduler(
            name='test',
            builderNames=['test'],
            minute=[5],
            codebases={'cb': {
                'repository': 'annoying'
            }})
        self.db.insertTestData([
            fakedb.Object(id=self.SCHEDULERID,
                          name='test',
                          class_name='NightlyTriggerable'),
            fakedb.ObjectState(
                objectid=self.SCHEDULERID,
                name='lastTrigger',
                value_json=
                '[ [ {"codebase": "cb", "project": "p", "repository": "r", "branch": "br", "revision": "myrev"} ], {"testprop": ["test", "TEST"]}, null, null ]'
            ),
        ])

        sched.activate()

        self.clock.advance(60 * 60)  # Run for 1h

        self.assertBuildsetAdded(properties={'testprop': (u'test', u'TEST')},
                                 sourcestamps=[
                                     dict(codebase='cb',
                                          branch='br',
                                          project='p',
                                          repository='r',
                                          revision='myrev'),
                                 ])
Exemplo n.º 5
0
 def test_bot_loadState(self):
     boid = yield self.bot._get_object_id()
     self.master.db.insertTestData([
         fakedb.ObjectState(objectid=boid, name='notify_events',
                            value_json='[["#channel1", ["warnings"]]]'),
     ])
     yield self.bot.loadState()
     self.assertEqual(self.bot.channels['#channel1'].notify_events, {'warnings'})
Exemplo n.º 6
0
    def test_getState_present(self):
        yield self.insertTestData([
            fakedb.Object(id=10, name='x', class_name='y'),
            fakedb.ObjectState(objectid=10, name='x', value_json='[1,2]'),
        ])
        val = yield self.db.state.getState(10, 'x')

        self.assertEqual(val, [1, 2])
Exemplo n.º 7
0
    def testLoadState(self):
        tboid = yield self.master.db.state.getObjectId(
            'testbot', 'buildbot.reporters.telegram.TelegramWebhookBot')
        yield self.insertTestData([
            fakedb.ObjectState(
                objectid=tboid,
                name='notify_events',
                value_json='[[123456789, ["started", "finished"]]]'),
            fakedb.ObjectState(objectid=tboid,
                               name='missing_workers',
                               value_json='[[123456789, [12]]]'),
        ])

        tb = self.master.config.services['TelegramBot']
        yield tb.bot.loadState()
        c = tb.bot.getContact({'id': 123456789}, {'id': 123456789})
        self.assertEquals(c.channel.notify_events, {'started', 'finished'})
        self.assertEquals(c.channel.missing_workers, {12})
Exemplo n.º 8
0
    def test_getState_present(self):
        d = self.insertTestData([
            fakedb.Object(id=10, name='x', class_name='y'),
            fakedb.ObjectState(objectid=10, name='x', value_json='[1,2]'),
        ])
        d.addCallback(lambda _:
                      self.db.state.getState(10, 'x'))

        def check(val):
            self.assertEqual(val, [1, 2])
        d.addCallback(check)
        return d
Exemplo n.º 9
0
    def test_setState_existing(self):
        yield self.insertTestData([
            fakedb.Object(id=10, name='-', class_name='-'),
            fakedb.ObjectState(objectid=10, name='x', value_json='99'),
        ])
        yield self.db.state.setState(10, 'x', [1, 2])

        def thd(conn):
            q = self.db.model.object_state.select()
            rows = conn.execute(q).fetchall()
            self.assertEqual([(r.objectid, r.name, r.value_json)
                              for r in rows], [(10, 'x', '[1, 2]')])

        yield self.db.pool.do(thd)
Exemplo n.º 10
0
    def test_getState_badjson(self):
        d = self.insertTestData([
            fakedb.Object(id=10, name='x', class_name='y'),
            fakedb.ObjectState(objectid=10, name='x', value_json='ff[1'),
        ])
        d.addCallback(lambda _: self.db.state.getState(10, 'x'))

        def cb(_):
            self.fail("should not have succeeded!")

        def eb(f):
            f.trap(TypeError)

        d.addCallbacks(cb, eb)
        return d
Exemplo n.º 11
0
    def test_startService_createAbsoluteSourceStamps_loadCodebase(self):
        # check codebase is loaded and used on startup.
        sched = self.makeFullScheduler(name='test',
                                       builderNames=['test'],
                                       treeStableTimer=None,
                                       branch='master',
                                       codebases=self.codebases,
                                       createAbsoluteSourceStamps=True)
        self.db.insertTestData([
            fakedb.Object(id=self.OBJECTID,
                          name='test',
                          class_name='SingleBranchScheduler'),
            fakedb.ObjectState(
                objectid=self.OBJECTID,
                name='lastCodebases',
                value_json=
                '{"a": {"branch": "master", "repository": "A", "revision": "1234:abc",  "lastChange": 13}}'
            )
        ])

        d = sched.startService(_returnDeferred=True)

        d.addCallback(lambda _: sched.gotChange(
            self.mkch(
                codebase='b', revision='2345:bcd', repository='B', number=14),
            True))

        def check(xxx_todo_changeme):
            (bsid, brids) = xxx_todo_changeme
            self.db.buildsets.assertBuildset(
                bsid=bsid,
                expected_buildset=self.mkbs(brids=brids),
                expected_sourcestamps={
                    'a':
                    self.mkss(codebase='a',
                              revision='1234:abc',
                              repository='A'),
                    'b':
                    self.mkss(codebase='b',
                              revision='2345:bcd',
                              repository='B',
                              changeids=set([14]))
                })

        d.addCallback(check)

        d.addCallback(lambda _: sched.stopService())
        return d
Exemplo n.º 12
0
 def test_pollDatabaseChanges_nothing_new(self):
     self.db.insertTestData([
         fakedb.Object(id=53, name='master',
                       class_name='buildbot.master.BuildMaster'),
         fakedb.ObjectState(objectid=53, name='last_processed_change',
                            value_json='10'),
         fakedb.Change(changeid=10),
     ])
     d = self.master.pollDatabaseChanges()
     def check(_):
         self.assertEqual(self.gotten_changes, [])
         self.assertEqual(self.gotten_buildset_additions, [])
         self.assertEqual(self.gotten_buildset_completions, [])
         self.db.state.assertState(53, last_processed_change=10)
     d.addCallback(check)
     return d
Exemplo n.º 13
0
    def test_gotChange_createAbsoluteSourceStamps_older_change(self):
        # check codebase is not stored if it's older than the most recent
        sched = self.makeFullScheduler(name='test',
                                       builderNames=['test'],
                                       treeStableTimer=None,
                                       branch='master',
                                       codebases=self.codebases,
                                       createAbsoluteSourceStamps=True)
        self.db.insertTestData([
            fakedb.Object(id=self.OBJECTID,
                          name='test',
                          class_name='SingleBranchScheduler'),
            fakedb.ObjectState(
                objectid=self.OBJECTID,
                name='lastCodebases',
                value_json='{"a": {"branch": "master", "repository": "A", '
                '"revision": "5555:def",  "lastChange": 20}}')
        ])

        d = sched.activate()

        d.addCallback(
            lambda _:
            # this change is not recorded, since it's older than
            # change 20
            sched.gotChange(
                self.mkch(codebase='a',
                          revision='1234:abc',
                          repository='A',
                          number=10), True))

        def check(_):
            self.db.state.assertState(self.OBJECTID,
                                      lastCodebases={
                                          'a':
                                          dict(branch='master',
                                               repository='A',
                                               revision=u'5555:def',
                                               lastChange=20)
                                      })

        d.addCallback(check)

        d.addCallback(lambda _: sched.deactivate())
        return d
Exemplo n.º 14
0
    def test_preStartConsumingChanges_no_createAbsoluteSourceStamps(self):
        sched = self.makeFullScheduler(name='test',
                                       builderNames=['test'],
                                       treeStableTimer=None,
                                       branch='master',
                                       codebases=self.codebases)

        self.db.insertTestData([
            fakedb.Object(id=self.OBJECTID,
                          name='test',
                          class_name='SingleBranchScheduler'),
            fakedb.ObjectState(objectid=self.OBJECTID,
                               name='lastCodebases',
                               value_json='{"a": {"branch": "master"}}')
        ])

        yield sched.preStartConsumingChanges()
        self.assertEqual(sched._lastCodebases, {})
Exemplo n.º 15
0
 def test_pollDatabaseChanges_multiple(self):
     self.db.insertTestData([
         fakedb.Object(id=53, name=self.master_name,
                       class_name='buildbot.master.BuildMaster'),
         fakedb.ObjectState(objectid=53, name='last_processed_change',
                            value_json='10'),
         fakedb.Change(changeid=10),
         fakedb.Change(changeid=11),
         fakedb.Change(changeid=12),
     ])
     d = self.master.pollDatabaseChanges()
     def check(_):
         self.assertEqual([ ch.number for ch in self.gotten_changes],
                          [ 11, 12 ]) # note 10 was already seen
         self.assertEqual(self.gotten_buildset_additions, [])
         self.assertEqual(self.gotten_buildset_completions, [])
         self.db.state.assertState(53, last_processed_change=12)
     d.addCallback(check)
     return d
Exemplo n.º 16
0
    def test_getUpstreamBuildsets_missing(self):
        sched = self.makeScheduler()

        # insert some state, with more bsids than exist
        self.db.insertTestData([
            fakedb.SourceStampSet(id=99),
            fakedb.Buildset(id=11, sourcestampsetid=99),
            fakedb.Buildset(id=13, sourcestampsetid=99),
            fakedb.Object(id=self.OBJECTID),
            fakedb.ObjectState(objectid=self.OBJECTID,
                name='upstream_bsids', value_json='[11,12,13]'),
        ])

        # check return value (missing 12)
        self.assertEqual((yield sched._getUpstreamBuildsets()),
                [(11, 99, False, -1), (13, 99, False, -1)])

        # and check that it wrote the correct value back to the state
        self.db.state.assertState(self.OBJECTID, upstream_bsids=[11, 13])
Exemplo n.º 17
0
    def test_iterations_onlyIfChanged_createAbsoluteSourceStamps_oneChanged_loadOther(self):
        # Test createAbsoluteSourceStamps=True when only one codebase has changed,
        # but the other was previously changed
        fII = mock.Mock(name='fII')
        self.makeScheduler(name='test', builderNames=['test'], branch=None,
                           minute=[5, 25, 45], onlyIfChanged=True,
                           fileIsImportant=fII,
                           codebases={'a': {'repository': "", 'branch': 'master'},
                                      'b': {'repository': "", 'branch': 'master'}},
                           createAbsoluteSourceStamps=True)

        self.db.insertTestData([
            fakedb.Object(id=self.OBJECTID, name='test', class_name='Nightly'),
            fakedb.ObjectState(objectid=self.OBJECTID, name='lastCodebases',
                               value_json='{"b": {"branch": "master", "repository": "B", "revision": "1234:abc",  "lastChange": 2}}')])

        yield self.do_test_iterations_onlyIfChanged_test(fII,
                                                         (120, self.makeFakeChange(number=3, codebase='a', revision='2345:bcd'), True))

        self.db.state.assertStateByClass('test', 'Nightly',
                                         last_build=1500 + self.localtime_offset)
        # addBuildsetForChanges calls getCodebase, so this isn't too
        # interesting
        self.assertEqual(self.addBuildsetCallTimes, [300])
        self.assertEqual(self.addBuildsetCalls, [
            ('addBuildsetForChanges', {
                'builderNames': None,
                'changeids': [3],
                'external_idstring': None,
                'properties': None,
                'reason': u"The Nightly scheduler named 'test' triggered this build",
                'waited_for': False})])
        self.db.state.assertStateByClass('test', 'Nightly', lastCodebases={
            'a': dict(revision='2345:bcd', branch=None, repository='', lastChange=3),
            'b': dict(revision='1234:abc', branch="master", repository='B', lastChange=2)})
        yield self.sched.deactivate()
Exemplo n.º 18
0
    def test_iterations_onlyIfChanged_createAbsoluteSourceStamps_oneChanged_loadOther(
            self):
        # Test createAbsoluteSourceStamps=True when only one codebase has changed,
        # but the other was previously changed
        fII = mock.Mock(name='fII')
        self.makeScheduler(name='test',
                           builderNames=['test'],
                           branch=None,
                           minute=[5, 25, 45],
                           onlyIfChanged=True,
                           fileIsImportant=fII,
                           codebases={
                               'a': {
                                   'repository': "",
                                   'branch': 'master'
                               },
                               'b': {
                                   'repository': "",
                                   'branch': 'master'
                               }
                           },
                           createAbsoluteSourceStamps=True)

        self.db.insertTestData([
            fakedb.Object(id=self.OBJECTID, name='test', class_name='Nightly'),
            fakedb.ObjectState(
                objectid=self.OBJECTID,
                name='lastCodebases',
                value_json=
                '{"b": {"branch": "master", "repository": "B", "revision": "1234:abc",  "lastChange": 2}}'
            )
        ])

        self.do_test_iterations_onlyIfChanged_test(
            fII, (120,
                  self.makeFakeChange(
                      number=3, codebase='a', revision='2345:bcd'), True))

        self.assertEqual(self.events, ['B[3]@300'])
        self.db.state.assertStateByClass('test',
                                         'Nightly',
                                         last_build=1500 +
                                         self.localtime_offset)
        self.db.buildsets.assertBuildset(bsid='?',
                                         expected_buildset=self.mkbs(),
                                         expected_sourcestamps={
                                             'a':
                                             self.mkss(codebase='a',
                                                       revision='2345:bcd',
                                                       changeids=set([3]),
                                                       branch=None),
                                             'b':
                                             self.mkss(codebase='b',
                                                       revision='1234:abc',
                                                       repository='B',
                                                       branch="master")
                                         })
        self.db.state.assertStateByClass('test',
                                         'Nightly',
                                         lastCodebases={
                                             'a':
                                             dict(revision='2345:bcd',
                                                  branch=None,
                                                  repository='',
                                                  lastChange=3),
                                             'b':
                                             dict(revision='1234:abc',
                                                  branch="master",
                                                  repository='B',
                                                  lastChange=2)
                                         })
        return self.sched.stopService()