Пример #1
0
    def test_fromBrdict_multiple_sourcestamps(self):
        master = fakemaster.make_master(testcase=self,
                                        wantData=True,
                                        wantDb=True)
        master.db.insertTestData([
            fakedb.Builder(id=77, name='bldr'),
            fakedb.SourceStamp(id=234,
                               branch='trunk',
                               revision='9283',
                               repository='svn://a..',
                               codebase='A',
                               project='world-domination'),
            fakedb.Change(changeid=13,
                          branch='trunk',
                          revision='9283',
                          repository='svn://a..',
                          codebase='A',
                          project='world-domination',
                          sourcestampid=234),
            fakedb.SourceStamp(id=235,
                               branch='trunk',
                               revision='9284',
                               repository='svn://b..',
                               codebase='B',
                               project='world-domination'),
            fakedb.Change(changeid=14,
                          branch='trunk',
                          revision='9284',
                          repository='svn://b..',
                          codebase='B',
                          project='world-domination',
                          sourcestampid=235),
            fakedb.Buildset(id=539, reason='triggered'),
            fakedb.BuildsetSourceStamp(buildsetid=539, sourcestampid=234),
            fakedb.BuildsetProperty(buildsetid=539,
                                    property_name='x',
                                    property_value='[1, "X"]'),
            fakedb.BuildsetProperty(buildsetid=539,
                                    property_name='y',
                                    property_value='[2, "Y"]'),
            fakedb.BuildRequest(id=288,
                                buildsetid=539,
                                builderid=77,
                                priority=13,
                                submitted_at=1200000000),
        ])
        # use getBuildRequest to minimize the risk from changes to the format
        # of the brdict
        brdict = yield master.db.buildrequests.getBuildRequest(288)
        br = yield buildrequest.BuildRequest.fromBrdict(master, brdict)

        self.assertEqual(br.reason, 'triggered')

        self.assertEqual(br.properties.getProperty('x'), 1)
        self.assertEqual(br.properties.getProperty('y'), 2)
        self.assertEqual(br.submittedAt, 1200000000)
        self.assertEqual(br.buildername, 'bldr')
        self.assertEqual(br.priority, 13)
        self.assertEqual(br.id, 288)
        self.assertEqual(br.bsid, 539)
Пример #2
0
 def test_getBuildsetProperties_multiple(self):
     return self.do_test_getBuildsetProperties(91, [
         fakedb.Buildset(id=91, complete=0, results=-1, submitted_at=0),
         fakedb.BuildsetProperty(buildsetid=91, property_name='prop1',
                                 property_value='["one", "fake1"]'),
         fakedb.BuildsetProperty(buildsetid=91, property_name='prop2',
                                 property_value='["two", "fake2"]'),
     ], dict(prop1=("one", "fake1"), prop2=("two", "fake2")))
Пример #3
0
    def test_fromBrdict(self):
        master = fakemaster.make_master(testcase=self,
                                        wantData=True,
                                        wantDb=True)
        master.db.insertTestData([
            fakedb.Builder(id=77, name='bldr'),
            fakedb.SourceStamp(id=234,
                               branch='trunk',
                               revision='9284',
                               repository='svn://...',
                               project='world-domination'),
            fakedb.Change(changeid=13,
                          branch='trunk',
                          revision='9283',
                          repository='svn://...',
                          project='world-domination',
                          sourcestampid=234),
            fakedb.Buildset(id=539, reason='triggered'),
            fakedb.BuildsetSourceStamp(buildsetid=539, sourcestampid=234),
            fakedb.BuildsetProperty(buildsetid=539,
                                    property_name='x',
                                    property_value='[1, "X"]'),
            fakedb.BuildsetProperty(buildsetid=539,
                                    property_name='y',
                                    property_value='[2, "Y"]'),
            fakedb.BuildRequest(id=288,
                                buildsetid=539,
                                builderid=77,
                                priority=13,
                                submitted_at=1200000000),
        ])
        # use getBuildRequest to minimize the risk from changes to the format
        # of the brdict
        d = master.db.buildrequests.getBuildRequest(288)
        d.addCallback(lambda brdict: buildrequest.BuildRequest.fromBrdict(
            master, brdict))

        def check(br):
            # check enough of the source stamp to verify it found the changes
            self.assertEqual([ss.ssid for ss in itervalues(br.sources)], [234])

            self.assertEqual(br.reason, 'triggered')

            self.assertEqual(br.properties.getProperty('x'), 1)
            self.assertEqual(br.properties.getProperty('y'), 2)
            self.assertEqual(br.submittedAt, 1200000000)
            self.assertEqual(br.buildername, 'bldr')
            self.assertEqual(br.priority, 13)
            self.assertEqual(br.id, 288)
            self.assertEqual(br.bsid, 539)

        d.addCallback(check)
        return d
    def test_fromBrdict(self):
        master = mock.Mock()
        master.db = fakedb.FakeDBConnector(self)
        master.db.insertTestData([
            fakedb.Change(changeid=13,
                          branch='trunk',
                          revision='9283',
                          repository='svn://...',
                          project='world-domination'),
            fakedb.SourceStamp(id=234,
                               branch='trunk',
                               revision='9284',
                               repository='svn://...',
                               project='world-domination'),
            fakedb.SourceStampChange(sourcestampid=234, changeid=13),
            fakedb.Buildset(id=539, reason='triggered', sourcestampid=234),
            fakedb.BuildsetProperty(buildsetid=539,
                                    property_name='x',
                                    property_value='[1, "X"]'),
            fakedb.BuildsetProperty(buildsetid=539,
                                    property_name='y',
                                    property_value='[2, "Y"]'),
            fakedb.BuildRequest(id=288,
                                buildsetid=539,
                                buildername='bldr',
                                priority=13,
                                submitted_at=1200000000),
        ])
        # use getBuildRequest to minimize the risk from changes to the format
        # of the brdict
        d = master.db.buildrequests.getBuildRequest(288)
        d.addCallback(lambda brdict: buildrequest.BuildRequest.fromBrdict(
            master, brdict))

        def check(br):
            # check enough of the source stamp to verify it found the changes
            self.assertEqual(br.source.ssid, 234)
            self.assertEqual([ch.number for ch in br.source.changes], [13])

            self.assertEqual(br.reason, 'triggered')

            self.assertEqual(br.properties.getProperty('x'), 1)
            self.assertEqual(br.properties.getProperty('y'), 2)
            self.assertEqual(br.submittedAt, 1200000000)
            self.assertEqual(br.buildername, 'bldr')
            self.assertEqual(br.priority, 13)
            self.assertEqual(br.id, 288)
            self.assertEqual(br.bsid, 539)

        d.addCallback(check)
        return d
 def testGetProperties(self):
     self.master.db.insertTestData([
         fakedb.BuildsetProperty(buildsetid=8822, property_name='prop1',
                                 property_value='["one", "fake1"]'),
         fakedb.BuildsetProperty(buildsetid=8822, property_name='prop2',
                                 property_value='["two", "fake2"]'),
     ])
     prop = resultspec.Property(b'property', 'eq', '*')
     buildrequests = yield self.callGet(('builders', 78, 'buildrequests'),
                        resultSpec=resultspec.ResultSpec(properties=[prop]))
     self.assertEqual(len(buildrequests), 1)
     self.assertEqual(buildrequests[0]['buildrequestid'], 46)
     self.assertEqual(buildrequests[0]['properties'],
         {u'prop1': (u'one', u'fake1'), u'prop2': (u'two', u'fake2')})
 def setUp(self):
     self.setUpEndpoint()
     self.db.insertTestData([
         fakedb.Builder(id=77, name='bbb'),
         fakedb.Master(id=fakedb.FakeBuildRequestsComponent.MASTER_ID),
         fakedb.Worker(id=13, name='wrk'),
         fakedb.Buildset(id=8822),
         fakedb.BuildRequest(id=44, buildsetid=8822, builderid=77,
                             priority=7, submitted_at=self.SUBMITTED_AT_EPOCH,
                             waited_for=1),
         fakedb.BuildsetProperty(buildsetid=8822, property_name='prop1',
                                 property_value='["one", "fake1"]'),
         fakedb.BuildsetProperty(buildsetid=8822, property_name='prop2',
                                 property_value='["two", "fake2"]'),
     ])
    def testRebuildBuildrequest(self):
        self.master.db.insertTestData([
            fakedb.Builder(id=77, name='builder'),
            fakedb.Master(id=88),
            fakedb.Worker(id=13, name='wrk'),
            fakedb.Buildset(id=8822),
            fakedb.SourceStamp(id=234),
            fakedb.BuildsetSourceStamp(buildsetid=8822, sourcestampid=234),
            fakedb.BuildRequest(id=82, buildsetid=8822, builderid=77),
            fakedb.BuildsetProperty(buildsetid=8822, property_name='prop1',
                                    property_value='["one", "fake1"]'),
            fakedb.BuildsetProperty(buildsetid=8822, property_name='prop2',
                                    property_value='["two", "fake2"]'),
        ])
        buildrequest = yield self.master.data.get(('buildrequests', 82))
        new_bsid, brid_dict = yield self.rtype.rebuildBuildrequest(buildrequest)

        self.assertEqual(list(brid_dict.keys()), [77])
        buildrequest = yield self.master.data.get(('buildrequests', brid_dict[77]))
        # submitted_at is the time of the test, so better not depend on it
        self.assertTrue(buildrequest['submitted_at'] is not None)
        buildrequest['submitted_at'] = None
        self.assertEqual(buildrequest, {'buildrequestid': 1001, 'complete': False, 'waited_for': False,
                                        'claimed_at': None, 'results': -1, 'claimed': False,
                                        'buildsetid': 200, 'complete_at': None, 'submitted_at': None,
                                        'builderid': 77, 'claimed_by_masterid': None, 'priority': 0,
                                        'properties': None})
        buildset = yield self.master.data.get(('buildsets', new_bsid))
        oldbuildset = yield self.master.data.get(('buildsets', 8822))

        # assert same sourcestamp
        self.assertEqual(buildset['sourcestamps'], oldbuildset['sourcestamps'])
        buildset['sourcestamps'] = None
        self.assertTrue(buildset['submitted_at'] is not None)
        buildset['submitted_at'] = None
        self.assertEqual(buildset, {'bsid': 200, 'complete_at': None, 'submitted_at': None,
                                    'sourcestamps': None, 'parent_buildid': None,
                                    'results': -1, 'parent_relationship': None,
                                    'reason': u'rebuild',
                                    'external_idstring': u'extid',
                                    'complete': False})

        properties = yield self.master.data.get(('buildsets', new_bsid, 'properties'))
        self.assertEqual(
            properties, {u'prop1': (u'one', u'fake1'), u'prop2': (u'two', u'fake2')})
Пример #8
0
 def setUp(self):
     self.setUpEndpoint()
     self.db.insertTestData([
         fakedb.Buildset(id=13, reason='because I said so'),
         fakedb.SourceStamp(id=92),
         fakedb.SourceStamp(id=93),
         fakedb.BuildsetSourceStamp(buildsetid=13, sourcestampid=92),
         fakedb.BuildsetSourceStamp(buildsetid=13, sourcestampid=93),
         fakedb.Buildset(id=14, reason='no sourcestamps'),
         fakedb.BuildsetProperty(buildsetid=14)
     ])
Пример #9
0
    def test_getPropertiesFromDb(self):
        d = self.insertTestData([
            fakedb.Change(changeid=13),
            fakedb.ChangeProperty(changeid=13,
                                  property_name='foo',
                                  property_value='"my prop"'),
            fakedb.SourceStamp(id=23),
            fakedb.Buildset(id=33, sourcestampid=23),
            fakedb.BuildsetProperty(buildsetid=33,
                                    property_name='bar',
                                    property_value='["other prop", "BS"]'),
        ])

        def do_test(_):
            cprops = self.dbc.get_properties_from_db("change_properties",
                                                     "changeid", 13)
            bprops = self.dbc.get_properties_from_db("buildset_properties",
                                                     "buildsetid", 33)
            self.assertEqual(cprops.asList() + bprops.asList(),
                             [('foo', 'my prop', 'Change'),
                              ('bar', 'other prop', 'BS')])

        d.addCallback(do_test)
        return d
Пример #10
0
    def setUp(self):
        authzcfg = authz.Authz(
            # simple matcher with '*' glob character
            stringsMatcher=authz.fnmatchStrMatcher,
            # stringsMatcher = authz.Authz.reStrMatcher,  # if you prefer
            # regular expressions
            allowRules=[
                # admins can do anything,
                # defaultDeny=False: if user does not have the admin role, we
                # continue parsing rules
                AnyEndpointMatcher(role="admins", defaultDeny=False),

                # rules for viewing builds, builders, step logs
                # depending on the sourcestamp or buildername
                ViewBuildsEndpointMatcher(branch="secretbranch",
                                          role="agents"),
                ViewBuildsEndpointMatcher(project="secretproject",
                                          role="agents"),
                ViewBuildsEndpointMatcher(branch="*", role="*"),
                ViewBuildsEndpointMatcher(project="*", role="*"),
                StopBuildEndpointMatcher(role="owner"),
                RebuildBuildEndpointMatcher(role="owner"),

                # nine-* groups can do stuff on the nine branch
                BranchEndpointMatcher(branch="nine", role="nine-*"),
                # eight-* groups can do stuff on the eight branch
                BranchEndpointMatcher(branch="eight", role="eight-*"),

                # *-try groups can start "try" builds
                ForceBuildEndpointMatcher(builder="try", role="*-developers"),
                # *-mergers groups can start "merge" builds
                ForceBuildEndpointMatcher(builder="merge", role="*-mergers"),
                # *-releasers groups can start "release" builds
                ForceBuildEndpointMatcher(builder="release",
                                          role="*-releasers"),
            ],
            roleMatchers=[
                RolesFromGroups(groupPrefix="buildbot-"),
                RolesFromEmails(admins=["*****@*****.**"],
                                agents=["*****@*****.**"]),
                RolesFromOwner(role="owner")
            ])
        self.users = dict(homer=dict(email="*****@*****.**"),
                          bond=dict(email="*****@*****.**"),
                          nineuser=dict(email="*****@*****.**",
                                        groups=[
                                            "buildbot-nine-mergers",
                                            "buildbot-nine-developers"
                                        ]),
                          eightuser=dict(email="*****@*****.**",
                                         groups=["buildbot-eight-deverlopers"
                                                 ]))
        self.master = self.make_master(url='h:/a/b/', authz=authzcfg)
        self.authz = self.master.authz
        self.master.db.insertTestData([
            fakedb.Builder(id=77, name="mybuilder"),
            fakedb.Master(id=88),
            fakedb.Worker(id=13, name='wrk'),
            fakedb.Buildset(id=8822),
            fakedb.BuildsetProperty(
                buildsetid=8822,
                property_name='owner',
                property_value='["*****@*****.**", "force"]'),
            fakedb.BuildRequest(id=82, buildsetid=8822, builderid=77),
            fakedb.Build(id=13,
                         builderid=77,
                         masterid=88,
                         workerid=13,
                         buildrequestid=82,
                         number=3),
            fakedb.Build(id=14,
                         builderid=77,
                         masterid=88,
                         workerid=13,
                         buildrequestid=82,
                         number=4),
            fakedb.Build(id=15,
                         builderid=77,
                         masterid=88,
                         workerid=13,
                         buildrequestid=82,
                         number=5),
        ])
    def insertBuildrequests(self,
                            buildername,
                            priority,
                            xrange,
                            submitted_at=1449578391,
                            results=BEGINNING,
                            complete=0,
                            mergebrid=None,
                            artifactbrid=None,
                            startbrid=None,
                            selected_slave=None,
                            sources=None):
        self.testdata += [
            fakedb.BuildRequest(id=self.lastbrid + idx,
                                buildsetid=self.lastbrid + idx,
                                buildername=buildername,
                                priority=priority,
                                results=results,
                                complete=complete,
                                mergebrid=mergebrid,
                                artifactbrid=artifactbrid,
                                startbrid=startbrid,
                                submitted_at=submitted_at) for idx in xrange
        ]

        if results == RESUME:
            breqsclaim = [
                fakedb.BuildRequestClaim(brid=self.lastbrid + idx,
                                         objectid=self.MASTER_ID,
                                         claimed_at=1449578391)
                for idx in xrange
            ]
            self.testdata += breqsclaim

        if selected_slave:
            self.testdata += [
                fakedb.BuildsetProperty(
                    buildsetid=self.lastbrid + idx,
                    property_name='selected_slave',
                    property_value='["%s", "Force Build Form"]' %
                    selected_slave) for idx in xrange
            ]

        self.testdata += [
            fakedb.Buildset(id=self.lastbrid + idx,
                            sourcestampsetid=self.lastbrid + idx)
            for idx in xrange
        ]

        if not sources:
            self.testdata += [
                fakedb.SourceStamp(sourcestampsetid=self.lastbrid + idx,
                                   branch='branch_%d' % (self.lastbrid + idx))
                for idx in xrange
            ]

        else:
            self.testdata += [
                fakedb.SourceStampSet(id=self.lastbrid + idx) for idx in xrange
            ]
            for ss in sources:
                self.testdata += [
                    fakedb.SourceStamp(sourcestampsetid=self.lastbrid + idx,
                                       repository=ss['repository'],
                                       codebase=ss['codebase'],
                                       branch=ss['branch'],
                                       revision=ss['revision'])
                    for idx in xrange
                ]

        self.lastbrid += len(xrange)