示例#1
0
 def setUp(self):
     self.setUpEndpoint()
     self.db.insertTestData([
         fakedb.Worker(id=47, name='linux'),
         fakedb.Builder(id=77, name='builder77'),
         fakedb.Master(id=88),
         fakedb.Buildset(id=8822),
         fakedb.BuildRequest(id=82, buildsetid=8822),
         fakedb.Build(id=30, builderid=77, number=7, masterid=88,
                      buildrequestid=82, workerid=47),
         fakedb.Build(id=31, builderid=77, number=8, masterid=88,
                      buildrequestid=82, workerid=47),
         fakedb.Step(id=70, number=0, name='one', buildid=30,
                     started_at=TIME1, complete_at=TIME2, results=0),
         fakedb.Step(id=71, number=1, name='two', buildid=30,
                     started_at=TIME2, complete_at=TIME3, results=2,
                     urls_json='[{"name":"url","url":"http://url"}]'),
         fakedb.Step(id=72, number=2, name='three', buildid=30,
                     started_at=TIME3),
         fakedb.Step(id=73, number=0, name='otherbuild', buildid=31,
                     started_at=TIME2),
     ])
示例#2
0
 def setUp(self):
     self.setUpEndpoint()
     self.db.insertTestData([
         fakedb.Builder(id=77),
         fakedb.Master(id=88),
         fakedb.Worker(id=13, name='wrk'),
         fakedb.Buildset(id=8822),
         fakedb.BuildRequest(id=82, buildsetid=8822),
         fakedb.Build(id=13,
                      builderid=77,
                      masterid=88,
                      workerid=13,
                      buildrequestid=82,
                      number=3),
         fakedb.Step(id=50, buildid=13, number=9, name='make'),
         fakedb.Log(id=60, stepid=50, name='stdio', type='s'),
         fakedb.Log(id=61, stepid=50, name='errors', type='t'),
         fakedb.Step(id=51, buildid=13, number=10, name='make_install'),
         fakedb.Log(id=70, stepid=51, name='stdio', type='s'),
         fakedb.Log(id=71, stepid=51, name='results_html', type='h'),
         fakedb.Step(id=52, buildid=13, number=11, name='nothing'),
     ])
    def test_setBuildProperties(self):
        self.master.db.insertTestData([
            fakedb.Buildset(id=28),
            fakedb.BuildRequest(id=5, buildsetid=28),
            fakedb.Master(id=3),
            fakedb.Worker(id=42, name="Friday"),
            fakedb.Build(id=1234, buildrequestid=5, masterid=3, workerid=42),
        ])

        self.master.db.builds.setBuildProperty = mock.Mock(
            wraps=self.master.db.builds.setBuildProperty)
        props = processProperties.fromDict(
            dict(a=(1, 't'), b=(['abc', 9], 't')))
        yield self.rtype.setBuildProperties(1234, props)
        setBuildPropertiesCalls = sorted(self.master.db.builds.setBuildProperty.mock_calls)
        self.assertEqual(setBuildPropertiesCalls, [
            mock.call(1234, 'a', 1, 't'),
            mock.call(1234, 'b', ['abc', 9], 't')])
        self.master.mq.assertProductions([
            (('builds', '1234', 'properties', 'update'),
             {'a': (1, 't'), 'b': (['abc', 9], 't')}),
        ])
        # sync without changes: no db write
        self.master.db.builds.setBuildProperty.reset_mock()
        self.master.mq.clearProductions()
        yield self.rtype.setBuildProperties(1234, props)
        self.master.db.builds.setBuildProperty.assert_not_called()
        self.master.mq.assertProductions([])

        # sync with one changes: one db write
        props.setProperty('b', 2, 'step')
        self.master.db.builds.setBuildProperty.reset_mock()
        yield self.rtype.setBuildProperties(1234, props)

        self.master.db.builds.setBuildProperty.assert_called_with(
            1234, 'b', 2, 'step')
        self.master.mq.assertProductions([
            (('builds', '1234', 'properties', 'update'), {'b': (2, 'step')})
        ])
示例#4
0
    def test_attached_workerInfoUpdates(self):
        # put in stale info:
        self.master.db.insertTestData([
            fakedb.Worker(name='bot',
                          info={
                              'admin': 'WrongAdmin',
                              'host': 'WrongHost',
                              'access_uri': 'WrongURI',
                              'version': 'WrongVersion'
                          })
        ])
        worker = yield self.createWorker()
        yield worker.startService()

        conn = fakeprotocol.FakeConnection(worker)
        conn.info = {
            'admin': 'TheAdmin',
            'host': 'TheHost',
            'access_uri': 'TheURI',
            'version': 'TheVersion',
        }
        yield worker.attached(conn)

        self.assertEqual(
            worker.info.asDict(), {
                'version': ('TheVersion', 'Worker'),
                'admin': ('TheAdmin', 'Worker'),
                'host': ('TheHost', 'Worker'),
                'access_uri': ('TheURI', 'Worker'),
            })

        # and the db is updated too:
        db_worker = yield self.master.db.workers.getWorker(name="bot")

        self.assertEqual(db_worker['workerinfo']['admin'], 'TheAdmin')
        self.assertEqual(db_worker['workerinfo']['host'], 'TheHost')
        self.assertEqual(db_worker['workerinfo']['access_uri'], 'TheURI')
        self.assertEqual(db_worker['workerinfo']['version'], 'TheVersion')
示例#5
0
    def testMissingWorker(self):
        yield self.insertTestData([fakedb.Worker(id=1, name='local1')])

        tb = self.master.config.services['TelegramBot']
        channel = tb.bot.getChannel(-123456)
        self.assertEquals(channel.notify_events, {'worker'})

        yield self.master.data.updates.workerMissing(
            workerid=1,
            masterid=self.master.masterid,
            last_connection='long time ago',
            notify=['*****@*****.**'],
        )
        self.assertEquals(self.sent_messages[0][1],
                          "Worker `local1` is missing. It was seen last on long time ago.")

        yield self.master.data.updates.workerConnected(
            workerid=1,
            masterid=self.master.masterid,
            workerinfo={},
        )
        self.assertEquals(self.sent_messages[1][1],
                          "Worker `local1` is back online.")
示例#6
0
    def insert_test_data(self):
        self.master.db.insertTestData([
            fakedb.Master(id=92),
            fakedb.Worker(id=13, name='wrk'),
            fakedb.Builder(id=79, name='builder1'),
            fakedb.Builder(id=80, name='builder2'),

            fakedb.Buildset(id=98, results=None, reason="reason98"),
            fakedb.BuildsetSourceStamp(buildsetid=98, sourcestampid=234),
            fakedb.SourceStamp(id=234, revision='revision1', project='project1',
                               codebase='codebase1', repository='repository1', branch='branch1'),
            fakedb.BuildRequest(id=10, buildsetid=98, builderid=79),
            fakedb.Build(id=19, number=1, builderid=79, buildrequestid=10, workerid=13,
                         masterid=92, results=None, state_string="state1"),

            fakedb.Buildset(id=99, results=None, reason="reason99"),
            fakedb.BuildsetSourceStamp(buildsetid=99, sourcestampid=235),
            fakedb.SourceStamp(id=235, revision='revision2', project='project2',
                               codebase='codebase2', repository='repository2', branch='branch2'),
            fakedb.BuildRequest(id=11, buildsetid=99, builderid=80),
            fakedb.Build(id=20, number=1, builderid=80, buildrequestid=11, workerid=13,
                         masterid=92, results=None, state_string="state2"),
        ])
示例#7
0
 def setUp(self):
     self.setUpEndpoint()
     self.db.insertTestData([
         fakedb.Builder(id=77, name='builder77'),
         fakedb.Builder(id=78, name='builder78'),
         fakedb.Builder(id=79, name='builder79'),
         fakedb.Master(id=88),
         fakedb.Worker(id=13, name='wrk'),
         fakedb.Buildset(id=8822),
         fakedb.BuildRequest(id=82, buildsetid=8822),
         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=78,
                      masterid=88,
                      workerid=12,
                      buildrequestid=83,
                      number=5,
                      complete_at=1),
         fakedb.Build(id=16,
                      builderid=79,
                      masterid=88,
                      workerid=12,
                      buildrequestid=84,
                      number=6,
                      complete_at=1),
     ])
示例#8
0
 def setUp(self):
     self.setUpEndpoint()
     self.db.insertTestData([
         fakedb.Builder(id=77),
         fakedb.Worker(id=13, name='wrk'),
         fakedb.Master(id=88),
         fakedb.Buildset(id=8822),
         fakedb.BuildRequest(id=82, buildsetid=8822),
         fakedb.Build(id=13, builderid=77, masterid=88, workerid=13,
                      buildrequestid=82, number=3),
         fakedb.Step(id=50, buildid=13, number=9, name='make'),
         fakedb.Log(id=60, stepid=50, name='stdio', slug='stdio', type='s',
                    num_lines=7),
         fakedb.LogChunk(logid=60, first_line=0, last_line=1, compressed=0,
                         content=textwrap.dedent("""\
                     line zero
                     line 1""")),
         fakedb.LogChunk(logid=60, first_line=2, last_line=4, compressed=0,
                         content=textwrap.dedent("""\
                     line TWO
                     line 3
                     line 2**2""")),
         fakedb.LogChunk(logid=60, first_line=5, last_line=5, compressed=0,
                         content="another line"),
         fakedb.LogChunk(logid=60, first_line=6, last_line=6, compressed=0,
                         content="yet another line"),
         fakedb.Log(id=61, stepid=50, name='errors', slug='errors',
                    type='t', num_lines=100),
     ] + [
         fakedb.LogChunk(logid=61, first_line=i, last_line=i, compressed=0,
                         content=f"{i:08d}")
         for i in range(100)
     ] + [
         fakedb.Log(id=62, stepid=50, name='notes', slug='notes', type='t',
                    num_lines=0),
         # logid 62 is empty
     ])
示例#9
0
 def setUp(self):
     self.setUpEndpoint()
     self.db.insertTestData([
         fakedb.Worker(id=47, name='linux'),
         fakedb.Buildset(id=20),
         fakedb.Builder(id=88, name='b1'),
         fakedb.BuildRequest(id=41, buildsetid=20, builderid=88),
         fakedb.Master(id=88),
         fakedb.Build(id=30,
                      buildrequestid=41,
                      number=7,
                      masterid=88,
                      builderid=88,
                      workerid=47),
         fakedb.Step(id=131, number=132, name='step132', buildid=30),
         fakedb.TestResultSet(id=13,
                              builderid=88,
                              buildid=30,
                              stepid=131,
                              description='desc',
                              category='cat',
                              value_unit='ms',
                              complete=1),
     ])
示例#10
0
    def test_startService_getWorkerInfo_fromDb(self):
        self.master.db.insertTestData([
            fakedb.Worker(id=9292,
                          name='bot',
                          info={
                              'admin': 'TheAdmin',
                              'host': 'TheHost',
                              'access_uri': 'TheURI',
                              'version': 'TheVersion'
                          })
        ])
        worker = yield self.createWorker()

        yield worker.startService()

        self.assertEqual(worker.workerid, 9292)

        self.assertEqual(
            worker.info.asDict(), {
                'version': ('TheVersion', 'Worker'),
                'admin': ('TheAdmin', 'Worker'),
                'host': ('TheHost', 'Worker'),
                'access_uri': ('TheURI', 'Worker'),
            })
示例#11
0
    def setUp(self):
        self.setup_test_reactor()
        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"),
                # finally deny any control endpoint for non-admin users
                AnyControlEndpointMatcher(role="admins")
            ],
            roleMatchers=[
                RolesFromGroups(groupPrefix="buildbot-"),
                RolesFromEmails(admins=["*****@*****.**"],
                                agents=["*****@*****.**"]),
                RolesFromOwner(role="owner"),
                RolesFromDomain(admins=["mi7.uk"])
            ])
        self.users = dict(homer=dict(email="*****@*****.**"),
                          bond=dict(email="*****@*****.**"),
                          moneypenny=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),
        ])
示例#12
0
from buildbot.test import fakedb
from buildbot.test.fake import fakemaster
from buildbot.test.util import endpoint
from buildbot.test.util import interfaces
from buildbot.test.util.misc import TestReactorMixin

testData = [
    fakedb.Builder(id=40, name='b1'),
    fakedb.Builder(id=41, name='b2'),
    fakedb.Master(id=13),
    fakedb.Master(id=14),
    fakedb.BuilderMaster(id=4013, builderid=40, masterid=13),
    fakedb.BuilderMaster(id=4014, builderid=40, masterid=14),
    fakedb.BuilderMaster(id=4113, builderid=41, masterid=13),

    fakedb.Worker(id=1, name='linux', info={}),
    fakedb.ConfiguredWorker(id=14013,
                            workerid=1, buildermasterid=4013),
    fakedb.ConfiguredWorker(id=14014,
                            workerid=1, buildermasterid=4014),
    fakedb.ConnectedWorker(id=113, masterid=13, workerid=1),

    fakedb.Worker(id=2, name='windows', info={"a": "b"}),
    fakedb.ConfiguredWorker(id=24013,
                            workerid=2, buildermasterid=4013),
    fakedb.ConfiguredWorker(id=24014,
                            workerid=2, buildermasterid=4014),
    fakedb.ConfiguredWorker(id=24113,
                            workerid=2, buildermasterid=4113),
    fakedb.ConnectedWorker(id=214, masterid=14, workerid=2),
]
示例#13
0
class Tests(interfaces.InterfaceTests):

    common_data = [
        fakedb.Worker(id=47, name='linux'),
        fakedb.Buildset(id=20),
        fakedb.Builder(id=88, name='b1'),
        fakedb.BuildRequest(id=41, buildsetid=20, builderid=88),
        fakedb.Master(id=88),
        fakedb.Build(id=30,
                     buildrequestid=41,
                     number=7,
                     masterid=88,
                     builderid=88,
                     workerid=47),
        fakedb.Step(id=131, number=132, name='step132', buildid=30),
        fakedb.TestResultSet(id=13,
                             builderid=88,
                             buildid=30,
                             stepid=131,
                             description='desc',
                             category='cat',
                             value_unit='ms',
                             complete=1),
    ]

    def test_signature_get_test_code_paths(self):
        @self.assertArgSpecMatches(self.db.test_results.getTestCodePaths)
        def getTestCodePaths(self,
                             builderid,
                             path_prefix=None,
                             result_spec=None):
            pass

    def test_signature_get_test_names(self):
        @self.assertArgSpecMatches(self.db.test_results.getTestNames)
        def getTestNames(self, builderid, name_prefix=None, result_spec=None):
            pass

    def test_signature_add_test_results(self):
        @self.assertArgSpecMatches(self.db.test_results.addTestResults)
        def addTestResults(self, builderid, test_result_setid, result_values):
            pass

    def test_signature_get_test_result(self):
        @self.assertArgSpecMatches(self.db.test_results.getTestResult)
        def getTestResult(self, test_resultid):
            pass

    def test_signature_get_test_results(self):
        @self.assertArgSpecMatches(self.db.test_results.getTestResults)
        def getTestResults(self,
                           builderid,
                           test_result_setid,
                           result_spec=None):
            pass

    @defer.inlineCallbacks
    def test_add_set_results(self):
        yield self.insertTestData(self.common_data)

        result_values = [
            {
                'test_name': 'name1',
                'value': '1'
            },
            {
                'test_name': 'name1',
                'duration_ns': 1000,
                'value': '2'
            },
            {
                'test_name': 'name2',
                'test_code_path': 'path2',
                'value': '3'
            },
            {
                'test_name': 'name3',
                'test_code_path': 'path3',
                'value': '4'
            },
            {
                'test_name': 'name4',
                'test_code_path': 'path4',
                'line': 4,
                'value': '5'
            },
            {
                'test_code_path': 'path5',
                'line': 5,
                'value': '6'
            },
        ]

        yield self.db.test_results.addTestResults(builderid=88,
                                                  test_result_setid=13,
                                                  result_values=result_values)

        result_dicts = yield self.db.test_results.getTestResults(
            builderid=88, test_result_setid=13)
        for d in result_dicts:
            validation.verifyDbDict(self, 'test_resultdict', d)

        result_dicts = sorted(result_dicts, key=lambda x: x['id'])
        resultid = result_dicts[0]['id']
        self.assertEqual(result_dicts, [
            {
                'id': resultid,
                'builderid': 88,
                'test_result_setid': 13,
                'test_name': 'name1',
                'test_code_path': None,
                'line': None,
                'duration_ns': None,
                'value': '1'
            },
            {
                'id': resultid + 1,
                'builderid': 88,
                'test_result_setid': 13,
                'test_name': 'name1',
                'test_code_path': None,
                'line': None,
                'duration_ns': 1000,
                'value': '2'
            },
            {
                'id': resultid + 2,
                'builderid': 88,
                'test_result_setid': 13,
                'test_name': 'name2',
                'test_code_path': 'path2',
                'line': None,
                'duration_ns': None,
                'value': '3'
            },
            {
                'id': resultid + 3,
                'builderid': 88,
                'test_result_setid': 13,
                'test_name': 'name3',
                'test_code_path': 'path3',
                'line': None,
                'duration_ns': None,
                'value': '4'
            },
            {
                'id': resultid + 4,
                'builderid': 88,
                'test_result_setid': 13,
                'test_name': 'name4',
                'test_code_path': 'path4',
                'line': 4,
                'duration_ns': None,
                'value': '5'
            },
            {
                'id': resultid + 5,
                'builderid': 88,
                'test_result_setid': 13,
                'test_name': None,
                'test_code_path': 'path5',
                'line': 5,
                'duration_ns': None,
                'value': '6'
            },
        ])

        result_dict = yield self.db.test_results.getTestResult(
            test_resultid=resultid)
        self.assertEqual(
            result_dict, {
                'id': resultid,
                'builderid': 88,
                'test_result_setid': 13,
                'test_name': 'name1',
                'test_code_path': None,
                'line': None,
                'duration_ns': None,
                'value': '1'
            })

    @defer.inlineCallbacks
    def test_get_names(self):
        yield self.insertTestData(self.common_data + [
            fakedb.TestName(id=103, builderid=88, name='name103'),
            fakedb.TestName(id=104, builderid=88, name='name104'),
            fakedb.TestName(id=105, builderid=88, name='name105'),
            fakedb.TestName(id=116, builderid=88, name='name116'),
            fakedb.TestName(id=117, builderid=88, name='name117'),
        ])

        name_dicts = yield self.db.test_results.getTestNames(builderid=88)
        self.assertEqual(
            name_dicts,
            ['name103', 'name104', 'name105', 'name116', 'name117'])

        name_dicts = yield self.db.test_results.getTestNames(
            builderid=88, name_prefix='non_existing')
        self.assertEqual(name_dicts, [])

        name_dicts = yield self.db.test_results.getTestNames(
            builderid=88, name_prefix='name10')
        self.assertEqual(name_dicts, ['name103', 'name104', 'name105'])

        name_dicts = yield self.db.test_results.getTestNames(
            builderid=88, name_prefix='name11')
        self.assertEqual(name_dicts, ['name116', 'name117'])

    @defer.inlineCallbacks
    def test_get_code_paths(self):
        yield self.insertTestData(self.common_data + [
            fakedb.TestCodePath(id=103, builderid=88, path='path103'),
            fakedb.TestCodePath(id=104, builderid=88, path='path104'),
            fakedb.TestCodePath(id=105, builderid=88, path='path105'),
            fakedb.TestCodePath(id=116, builderid=88, path='path116'),
            fakedb.TestCodePath(id=117, builderid=88, path='path117'),
        ])

        path_dicts = yield self.db.test_results.getTestCodePaths(builderid=88)
        self.assertEqual(
            path_dicts,
            ['path103', 'path104', 'path105', 'path116', 'path117'])

        path_dicts = yield self.db.test_results.getTestCodePaths(
            builderid=88, path_prefix='non_existing')
        self.assertEqual(path_dicts, [])

        path_dicts = yield self.db.test_results.getTestCodePaths(
            builderid=88, path_prefix='path10')
        self.assertEqual(path_dicts, ['path103', 'path104', 'path105'])

        path_dicts = yield self.db.test_results.getTestCodePaths(
            builderid=88, path_prefix='path11')
        self.assertEqual(path_dicts, ['path116', 'path117'])
示例#14
0
    def test_multiple_source_stamps_no_props(self):
        repository = 'http://test_repo'
        project = 'test_user/test_project'
        codebase1 = 'test_codebase1'
        codebase2 = 'test_codebase2'
        codebase3 = 'test_codebase3'
        branch2 = 'refs/pull/4192/merge'
        branch3 = 'refs/pull/4193/merge'

        self._http.expect('post',
                          '/repos/test_user/test_project/issues/4192/comments',
                          json={'body': 'Build done.'})
        self._http.expect('post',
                          '/repos/test_user/test_project/issues/4192/comments',
                          json={'body': 'Build done.'})
        self._http.expect('post',
                          '/repos/test_user/test_project/issues/4192/comments',
                          json={'body': 'Build done.'})
        self._http.expect('post',
                          '/repos/test_user/test_project/issues/4192/comments',
                          json={'body': 'Build done.'})

        # note that the first sourcestamp only has revision, second only branch and only the third
        # has both
        self.master.db.insertTestData([
            fakedb.Master(id=92),
            fakedb.Worker(id=13, name='wrk'),
            fakedb.Builder(id=79, name='Builder0'),
            fakedb.Buildset(id=98, results=SUCCESS, reason="test_reason1"),
            fakedb.BuildsetSourceStamp(buildsetid=98, sourcestampid=234),
            fakedb.BuildsetSourceStamp(buildsetid=98, sourcestampid=235),
            fakedb.BuildsetSourceStamp(buildsetid=98, sourcestampid=236),
            fakedb.SourceStamp(id=234,
                               project=project,
                               branch=None,
                               revision='rev1',
                               repository=repository,
                               codebase=codebase1),
            fakedb.SourceStamp(id=235,
                               project=project,
                               branch=branch2,
                               revision=None,
                               repository=repository,
                               codebase=codebase2),
            fakedb.SourceStamp(id=236,
                               project=project,
                               branch=branch3,
                               revision='rev3',
                               repository=repository,
                               codebase=codebase3),
            fakedb.BuildRequest(id=11, buildsetid=98, builderid=79),
            fakedb.Build(id=20,
                         number=0,
                         builderid=79,
                         buildrequestid=11,
                         workerid=13,
                         masterid=92,
                         results=SUCCESS,
                         state_string="build_text"),
            fakedb.BuildProperty(buildid=20,
                                 name="buildername",
                                 value="Builder0"),
            fakedb.BuildProperty(buildid=20, name="branch", value=branch2),
        ])

        build = yield self.master.data.get(("builds", 20))

        build['complete'] = False
        self.sp.buildStarted(("build", 20, "started"), build)
        build['complete'] = True
        self.sp.buildFinished(("build", 20, "finished"), build)
        build['results'] = SUCCESS
        self.sp.buildFinished(("build", 20, "finished"), build)
示例#15
0
    def test_getChangesForBuild(self):
        rows = [fakedb.Master(id=88, name="bar"),
                fakedb.Worker(id=13, name='one'),
                fakedb.Builder(id=77, name='A')]
        lastID = {"changeid": 0,
                  "sourcestampid": 0,
                  "buildsetid": 0,
                  "buildsetSourceStampid": 0,
                  "buildrequestid": 0,
                  "buildid": 0}

        codebase_ss = {}  # shared state between addChange and addBuild

        def addChange(codebase, revision, author, committer, comments, branch='master',
                      category='cat', project='proj', repository='repo'):
            lastID["sourcestampid"] += 1
            lastID["changeid"] += 1
            parent_changeids = codebase_ss.get(codebase, None)

            codebase_ss[codebase] = lastID["sourcestampid"]

            changeRows = [fakedb.SourceStamp(id=lastID["sourcestampid"],
                                             codebase=codebase,
                                             revision=revision),
                          fakedb.Change(changeid=lastID["changeid"],
                                        author=author,
                                        committer=committer,
                                        comments=comments,
                                        revision=revision,
                                        sourcestampid=lastID["sourcestampid"],
                                        parent_changeids=parent_changeids,
                                        when_timestamp=SOMETIME +
                                        lastID["changeid"],
                                        branch=branch,
                                        category=category,
                                        project=project,
                                        repository=repository)]
            return changeRows

        def addBuild(codebase_ss, results=0):

            lastID["buildid"] += 1
            lastID["buildsetid"] += 1
            lastID["buildrequestid"] += 1

            buildRows = [fakedb.Buildset(id=lastID["buildsetid"],
                                         reason='foo',
                                         submitted_at=1300305012, results=-1)]
            for cb, ss in codebase_ss.items():
                lastID["buildsetSourceStampid"] += 1
                buildRows.append(
                    fakedb.BuildsetSourceStamp(id=lastID["buildsetSourceStampid"],
                                               sourcestampid=ss,
                                               buildsetid=lastID["buildsetid"]))
            codebase_ss.clear()
            buildRows.extend([
                fakedb.BuildRequest(id=lastID["buildrequestid"],
                                    buildsetid=lastID["buildsetid"],
                                    builderid=77,
                                    priority=13, submitted_at=1300305712, results=-1),
                fakedb.Build(id=lastID["buildid"],
                             buildrequestid=lastID["buildrequestid"],
                             number=lastID["buildid"],
                             masterid=88,
                             builderid=77,
                             state_string="test",
                             workerid=13,
                             started_at=SOMETIME + lastID["buildid"],
                             complete_at=SOMETIME + 2 * lastID["buildid"],
                             results=results)])
            return buildRows

        # Build1 has 1 change per code base
        rows.extend(addChange('A', 1, 'franck', 'franck', '1st commit'))
        rows.extend(addChange('B', 1, 'alice', 'alice', '2nd commit'))
        rows.extend(addChange('C', 1, 'bob', 'bob', '3rd commit'))
        rows.extend(addBuild(codebase_ss))
        # Build 2 has only one change for codebase A
        rows.extend(addChange('A', 2, 'delanne', 'delanne', '4th commit'))
        rows.extend(addBuild(codebase_ss))
        # Build 3 has only one change for codebase B
        rows.extend(addChange('B', 2, 'bob', 'bob', '6th commit'))
        rows.extend(addBuild(codebase_ss))
        # Build 4 has no change
        rows.extend(addBuild(codebase_ss))
        # Build 5 has 2 changes for codebase A and 1 change for codebase C
        rows.extend(addChange('A', 3, 'franck', 'franck', '7th commit'))
        rows.extend(addChange('A', 4, 'alice', 'alice', '8th commit'))
        rows.extend(addChange('B', 3, 'bob', 'bob', '9th commit'))
        rows.extend(addBuild(codebase_ss))
        # Build 6 has only one change for codebase C
        rows.extend(addChange('C', 2, 'bob', 'bob', '10th commit'))
        rows.extend(addBuild(codebase_ss, 2))
        # Build 7 has only one change for codebase C
        rows.extend(addChange('C', 3, 'bob', 'bob', '11th commit'))
        rows.extend(addBuild(codebase_ss, 2))
        yield self.insertTestData(rows)

        @defer.inlineCallbacks
        def expect(buildid, commits):
            got = yield self.db.changes.getChangesForBuild(buildid)
            got_commits = [c['comments'] for c in got]
            self.assertEqual(sorted(got_commits), sorted(commits))

        yield expect(1, ['2nd commit', '3rd commit', '1st commit'])
        yield expect(2, ['4th commit'])
        yield expect(3, ['6th commit'])
        yield expect(4, [])
        yield expect(5, ['8th commit', '9th commit', '7th commit'])
        yield expect(6, ['10th commit'])
        yield expect(7, ['11th commit'])
示例#16
0
    def test_masterDeactivated(self):
        self.master.db.insertTestData([
            fakedb.Master(id=14, name='other', active=0, last_active=0),

            # set up a running build with some steps
            fakedb.Builder(id=77, name='b1'),
            fakedb.Worker(id=13, name='wrk'),
            fakedb.Buildset(id=8822),
            fakedb.BuildRequest(id=82, builderid=77, buildsetid=8822),
            fakedb.BuildRequestClaim(brid=82, masterid=14,
                                     claimed_at=SOMETIME),
            fakedb.Build(id=13,
                         builderid=77,
                         masterid=14,
                         workerid=13,
                         buildrequestid=82,
                         number=3,
                         results=None),
            fakedb.Step(id=200, buildid=13),
            fakedb.Log(id=2000, stepid=200, num_lines=2),
            fakedb.LogChunk(logid=2000,
                            first_line=1,
                            last_line=2,
                            content='ab\ncd')
        ])

        # mock out the _masterDeactivated methods this will call
        for rtype in 'builder', 'scheduler', 'changesource':
            rtype_obj = getattr(self.master.data.rtypes, rtype)
            m = mock.Mock(name='{}._masterDeactivated'.format(rtype),
                          spec=rtype_obj._masterDeactivated)
            m.side_effect = lambda masterid: defer.succeed(None)
            rtype_obj._masterDeactivated = m

        # and the update methods..
        for meth in 'finishBuild', 'finishStep', 'finishLog':
            m = mock.create_autospec(getattr(self.master.data.updates, meth))
            m.side_effect = lambda *args, **kwargs: defer.succeed(None)
            setattr(self.master.data.updates, meth, m)

        yield self.rtype._masterDeactivated(14, 'other')

        self.master.data.rtypes.builder._masterDeactivated. \
            assert_called_with(masterid=14)
        self.master.data.rtypes.scheduler._masterDeactivated. \
            assert_called_with(masterid=14)
        self.master.data.rtypes.changesource._masterDeactivated. \
            assert_called_with(masterid=14)

        # see that we finished off that build and its steps and logs
        updates = self.master.data.updates
        updates.finishLog.assert_called_with(logid=2000)
        updates.finishStep.assert_called_with(stepid=200,
                                              results=RETRY,
                                              hidden=False)
        updates.finishBuild.assert_called_with(buildid=13, results=RETRY)

        self.assertEqual(self.master.mq.productions, [
            (('masters', '14', 'stopped'),
             dict(masterid=14, name='other', active=False)),
        ])
示例#17
0
    def insertTestData(self,
                       buildResults,
                       finalResult,
                       insertSS=True,
                       parentPlan=False,
                       insert_patch=False):
        self.db = self.master.db
        self.db.insertTestData([
            fakedb.Master(id=92),
            fakedb.Worker(id=13, name='wrk'),
            fakedb.Builder(id=79, name='Builder0'),
            fakedb.Builder(id=80, name='Builder1'),
            fakedb.Buildset(id=98,
                            results=finalResult,
                            reason="testReason1",
                            parent_buildid=19 if parentPlan else None),
            fakedb.Change(changeid=13,
                          branch=self.TEST_BRANCH,
                          revision='9283',
                          author='me@foo',
                          repository=self.TEST_REPO,
                          codebase=self.TEST_CODEBASE,
                          project='world-domination',
                          sourcestampid=234),
        ])

        if parentPlan:
            self.db.insertTestData([
                fakedb.Worker(id=12, name='wrk_parent'),
                fakedb.Builder(id=78, name='Builder_parent'),
                fakedb.Buildset(id=97,
                                results=finalResult,
                                reason="testReason0"),
                fakedb.BuildRequest(id=10, buildsetid=98, builderid=78),
                fakedb.Build(id=19,
                             number=1,
                             builderid=78,
                             buildrequestid=10,
                             workerid=12,
                             masterid=92,
                             results=finalResult,
                             state_string="buildText"),
            ])

        if insertSS:
            patchid = 99 if insert_patch else None

            self.db.insertTestData([
                fakedb.BuildsetSourceStamp(buildsetid=98, sourcestampid=234),
                fakedb.SourceStamp(id=234,
                                   branch=self.TEST_BRANCH,
                                   project=self.TEST_PROJECT,
                                   revision=self.TEST_REVISION,
                                   repository=self.TEST_REPO,
                                   codebase=self.TEST_CODEBASE,
                                   patchid=patchid),
                fakedb.Patch(id=99,
                             patch_base64='aGVsbG8sIHdvcmxk',
                             patch_author='him@foo',
                             patch_comment='foo',
                             subdir='/foo',
                             patchlevel=3),
            ])

        for i, results in enumerate(buildResults):
            started_at = 10000001
            complete_at = None if results is None else 10000005
            self.db.insertTestData([
                fakedb.BuildRequest(id=11 + i, buildsetid=98,
                                    builderid=79 + i),
                fakedb.Build(id=20 + i,
                             number=i,
                             builderid=79 + i,
                             buildrequestid=11 + i,
                             workerid=13,
                             masterid=92,
                             results=results,
                             state_string="buildText",
                             started_at=started_at,
                             complete_at=complete_at),
                fakedb.Step(id=50 + i, buildid=20 + i, number=5, name='make'),
                fakedb.Log(id=60 + i,
                           stepid=50 + i,
                           name='stdio',
                           slug='stdio',
                           type='s',
                           num_lines=7),
                fakedb.LogChunk(
                    logid=60 + i,
                    first_line=0,
                    last_line=1,
                    compressed=0,
                    content='Unicode log with non-ascii (\u00E5\u00E4\u00F6).'
                ),
                fakedb.BuildProperty(buildid=20 + i,
                                     name="workername",
                                     value="wrk"),
                fakedb.BuildProperty(buildid=20 + i,
                                     name="reason",
                                     value="because"),
                fakedb.BuildProperty(buildid=20 + i,
                                     name="buildername",
                                     value="Builder0"),
                fakedb.BuildProperty(buildid=20 + i,
                                     name="buildnumber",
                                     value="{}".format(i)),
                fakedb.BuildProperty(buildid=20 + i,
                                     name="scheduler",
                                     value="checkin"),
            ])
            for k, v in self.TEST_PROPS.items():
                self.db.insertTestData(
                    [fakedb.BuildProperty(buildid=20 + i, name=k, value=v)])

            @defer.inlineCallbacks
            def getChangesForBuild(buildid):
                assert buildid == 20
                ch = yield self.master.db.changes.getChange(13)
                return [ch]

            self.master.db.changes.getChangesForBuild = getChangesForBuild
示例#18
0
class Tests(interfaces.InterfaceTests):

    # common sample data

    baseRows = [
        fakedb.Master(id=10, name='m10'),
        fakedb.Master(id=11, name='m11'),
        fakedb.Builder(id=20, name='a'),
        fakedb.Builder(id=21, name='b'),
        fakedb.Builder(id=22, name='c'),
        fakedb.Worker(id=30, name='zero'),
        fakedb.Worker(id=31, name='one'),
    ]

    multipleMasters = [
        fakedb.BuilderMaster(id=12, builderid=20, masterid=10),
        fakedb.BuilderMaster(id=13, builderid=21, masterid=10),
        fakedb.BuilderMaster(id=14, builderid=20, masterid=11),
        fakedb.BuilderMaster(id=15, builderid=22, masterid=11),
        fakedb.BuilderMaster(id=16, builderid=22, masterid=10),
        fakedb.ConfiguredWorker(id=3012, workerid=30, buildermasterid=12),
        fakedb.ConfiguredWorker(id=3013, workerid=30, buildermasterid=13),
        fakedb.ConfiguredWorker(id=3014, workerid=30, buildermasterid=14),
        fakedb.ConfiguredWorker(id=3114, workerid=31, buildermasterid=14),
        fakedb.ConfiguredWorker(id=3115, workerid=31, buildermasterid=15),
        fakedb.ConnectedWorker(id=3010, workerid=30, masterid=10),
        fakedb.ConnectedWorker(id=3111, workerid=31, masterid=11),
    ]

    # sample worker data, with id's avoiding the postgres id sequence

    BOGUS_NAME = 'bogus'

    W1_NAME, W1_ID, W1_INFO = 'w1', 100, {'a': 1}
    worker1_rows = [
        fakedb.Worker(id=W1_ID, name=W1_NAME, info=W1_INFO),
    ]

    W2_NAME, W2_ID, W2_INFO = 'w2', 200, {'a': 1, 'b': 2}
    worker2_rows = [
        fakedb.Worker(id=W2_ID, name=W2_NAME, info=W2_INFO),
    ]

    # tests

    def test_signature_findWorkerId(self):
        @self.assertArgSpecMatches(self.db.workers.findWorkerId)
        def findWorkerId(self, name):
            pass

    def test_signature_getWorker(self):
        @self.assertArgSpecMatches(self.db.workers.getWorker)
        def getWorker(self,
                      workerid=None,
                      name=None,
                      masterid=None,
                      builderid=None):
            pass

    def test_signature_getWorkers(self):
        @self.assertArgSpecMatches(self.db.workers.getWorkers)
        def getWorkers(self,
                       masterid=None,
                       builderid=None,
                       paused=None,
                       graceful=None):
            pass

    def test_signature_workerConnected(self):
        @self.assertArgSpecMatches(self.db.workers.workerConnected)
        def workerConnected(self, workerid, masterid, workerinfo):
            pass

    def test_signature_workerDisconnected(self):
        @self.assertArgSpecMatches(self.db.workers.workerDisconnected)
        def workerDisconnected(self, workerid, masterid):
            pass

    def test_signature_workerConfigured(self):
        @self.assertArgSpecMatches(self.db.workers.workerConfigured)
        def workerConfigured(self, workerid, masterid, builderids):
            pass

    def test_signature_deconfigureAllWorkersForMaster(self):
        @self.assertArgSpecMatches(
            self.db.workers.deconfigureAllWorkersForMaster)
        def deconfigureAllWorkersForMaster(self, masterid):
            pass

    def test_signature_setWorkerState(self):
        @self.assertArgSpecMatches(self.db.workers.setWorkerState)
        def setWorkerState(self, workerid, paused, graceful):
            pass

    @defer.inlineCallbacks
    def test_findWorkerId_insert(self):
        id = yield self.db.workers.findWorkerId(name="xyz")
        worker = yield self.db.workers.getWorker(workerid=id)
        self.assertEqual(worker['name'], 'xyz')
        self.assertEqual(worker['workerinfo'], {})

    @defer.inlineCallbacks
    def test_findWorkerId_existing(self):
        yield self.insertTestData(self.baseRows)
        id = yield self.db.workers.findWorkerId(name="one")
        self.assertEqual(id, 31)

    @defer.inlineCallbacks
    def test_getWorker_no_such(self):
        yield self.insertTestData(self.baseRows)
        workerdict = yield self.db.workers.getWorker(workerid=99)
        self.assertEqual(workerdict, None)

    @defer.inlineCallbacks
    def test_getWorker_by_name_no_such(self):
        yield self.insertTestData(self.baseRows)
        workerdict = yield self.db.workers.getWorker(name='NOSUCH')
        self.assertEqual(workerdict, None)

    @defer.inlineCallbacks
    def test_getWorker_not_configured(self):
        yield self.insertTestData(self.baseRows)
        workerdict = yield self.db.workers.getWorker(workerid=30)
        validation.verifyDbDict(self, 'workerdict', workerdict)
        self.assertEqual(
            workerdict,
            dict(id=30,
                 name='zero',
                 workerinfo={'a': 'b'},
                 paused=False,
                 graceful=False,
                 connected_to=[],
                 configured_on=[]))

    @defer.inlineCallbacks
    def test_getWorker_connected_not_configured(self):
        yield self.insertTestData(self.baseRows + [
            # the worker is connected to this master, but not configured.
            # weird, but the DB should represent it.
            fakedb.Worker(id=32, name='two'),
            fakedb.ConnectedWorker(workerid=32, masterid=11),
        ])
        workerdict = yield self.db.workers.getWorker(workerid=32)
        validation.verifyDbDict(self, 'workerdict', workerdict)
        self.assertEqual(
            workerdict,
            dict(id=32,
                 name='two',
                 workerinfo={'a': 'b'},
                 paused=False,
                 graceful=False,
                 connected_to=[11],
                 configured_on=[]))

    @defer.inlineCallbacks
    def test_getWorker_multiple_connections(self):
        yield self.insertTestData(self.baseRows + [
            # the worker is connected to two masters at once.
            # weird, but the DB should represent it.
            fakedb.Worker(id=32, name='two'),
            fakedb.ConnectedWorker(workerid=32, masterid=10),
            fakedb.ConnectedWorker(workerid=32, masterid=11),
            fakedb.BuilderMaster(id=24, builderid=20, masterid=10),
            fakedb.BuilderMaster(id=25, builderid=20, masterid=11),
            fakedb.ConfiguredWorker(workerid=32, buildermasterid=24),
            fakedb.ConfiguredWorker(workerid=32, buildermasterid=25),
        ])
        workerdict = yield self.db.workers.getWorker(workerid=32)
        validation.verifyDbDict(self, 'workerdict', workerdict)
        self.assertEqual(
            workerdict,
            dict(id=32,
                 name='two',
                 workerinfo={'a': 'b'},
                 paused=False,
                 graceful=False,
                 connected_to=[10, 11],
                 configured_on=[
                     {
                         'builderid': 20,
                         'masterid': 10
                     },
                     {
                         'builderid': 20,
                         'masterid': 11
                     },
                 ]))

    @defer.inlineCallbacks
    def test_getWorker_by_name_not_configured(self):
        yield self.insertTestData(self.baseRows)
        workerdict = yield self.db.workers.getWorker(name='zero')
        validation.verifyDbDict(self, 'workerdict', workerdict)
        self.assertEqual(
            workerdict,
            dict(id=30,
                 name='zero',
                 workerinfo={'a': 'b'},
                 paused=False,
                 graceful=False,
                 connected_to=[],
                 configured_on=[]))

    @defer.inlineCallbacks
    def test_getWorker_not_connected(self):
        yield self.insertTestData(self.baseRows + [
            fakedb.BuilderMaster(id=12, builderid=20, masterid=10),
            fakedb.ConfiguredWorker(workerid=30, buildermasterid=12),
        ])
        workerdict = yield self.db.workers.getWorker(workerid=30)
        validation.verifyDbDict(self, 'workerdict', workerdict)
        self.assertEqual(
            workerdict,
            dict(id=30,
                 name='zero',
                 workerinfo={'a': 'b'},
                 paused=False,
                 graceful=False,
                 configured_on=[{
                     'masterid': 10,
                     'builderid': 20
                 }],
                 connected_to=[]))

    @defer.inlineCallbacks
    def test_getWorker_connected(self):
        yield self.insertTestData(self.baseRows + [
            fakedb.BuilderMaster(id=12, builderid=20, masterid=10),
            fakedb.ConfiguredWorker(workerid=30, buildermasterid=12),
            fakedb.ConnectedWorker(workerid=30, masterid=10),
        ])
        workerdict = yield self.db.workers.getWorker(workerid=30)
        validation.verifyDbDict(self, 'workerdict', workerdict)
        self.assertEqual(
            workerdict,
            dict(id=30,
                 name='zero',
                 workerinfo={'a': 'b'},
                 paused=False,
                 graceful=False,
                 configured_on=[{
                     'masterid': 10,
                     'builderid': 20
                 }],
                 connected_to=[10]))

    @defer.inlineCallbacks
    def test_getWorker_with_multiple_masters(self):
        yield self.insertTestData(self.baseRows + self.multipleMasters)
        workerdict = yield self.db.workers.getWorker(workerid=30)
        validation.verifyDbDict(self, 'workerdict', workerdict)
        workerdict['configured_on'] = sorted(workerdict['configured_on'],
                                             key=configuredOnKey)
        self.assertEqual(
            workerdict,
            dict(id=30,
                 name='zero',
                 workerinfo={'a': 'b'},
                 paused=False,
                 graceful=False,
                 configured_on=sorted([
                     {
                         'masterid': 10,
                         'builderid': 20
                     },
                     {
                         'masterid': 10,
                         'builderid': 21
                     },
                     {
                         'masterid': 11,
                         'builderid': 20
                     },
                 ],
                                      key=configuredOnKey),
                 connected_to=[10]))

    @defer.inlineCallbacks
    def test_getWorker_with_multiple_masters_builderid(self):
        yield self.insertTestData(self.baseRows + self.multipleMasters)
        workerdict = yield self.db.workers.getWorker(workerid=30, builderid=20)
        validation.verifyDbDict(self, 'workerdict', workerdict)
        workerdict['configured_on'] = sorted(workerdict['configured_on'],
                                             key=configuredOnKey)
        self.assertEqual(
            workerdict,
            dict(id=30,
                 name='zero',
                 workerinfo={'a': 'b'},
                 paused=False,
                 graceful=False,
                 configured_on=sorted([
                     {
                         'masterid': 10,
                         'builderid': 20
                     },
                     {
                         'masterid': 11,
                         'builderid': 20
                     },
                 ],
                                      key=configuredOnKey),
                 connected_to=[10]))

    @defer.inlineCallbacks
    def test_getWorker_with_multiple_masters_masterid(self):
        yield self.insertTestData(self.baseRows + self.multipleMasters)
        workerdict = yield self.db.workers.getWorker(workerid=30, masterid=11)
        validation.verifyDbDict(self, 'workerdict', workerdict)
        self.assertEqual(
            workerdict,
            dict(id=30,
                 name='zero',
                 workerinfo={'a': 'b'},
                 paused=False,
                 graceful=False,
                 configured_on=[
                     {
                         'masterid': 11,
                         'builderid': 20
                     },
                 ],
                 connected_to=[]))

    @defer.inlineCallbacks
    def test_getWorker_with_multiple_masters_builderid_masterid(self):
        yield self.insertTestData(self.baseRows + self.multipleMasters)
        workerdict = yield self.db.workers.getWorker(workerid=30,
                                                     builderid=20,
                                                     masterid=11)
        validation.verifyDbDict(self, 'workerdict', workerdict)
        self.assertEqual(
            workerdict,
            dict(id=30,
                 name='zero',
                 workerinfo={'a': 'b'},
                 paused=False,
                 graceful=False,
                 configured_on=[
                     {
                         'masterid': 11,
                         'builderid': 20
                     },
                 ],
                 connected_to=[]))

    @defer.inlineCallbacks
    def test_getWorker_by_name_with_multiple_masters_builderid_masterid(self):
        yield self.insertTestData(self.baseRows + self.multipleMasters)
        workerdict = yield self.db.workers.getWorker(name='zero',
                                                     builderid=20,
                                                     masterid=11)
        validation.verifyDbDict(self, 'workerdict', workerdict)
        self.assertEqual(
            workerdict,
            dict(id=30,
                 name='zero',
                 workerinfo={'a': 'b'},
                 paused=False,
                 graceful=False,
                 configured_on=[
                     {
                         'masterid': 11,
                         'builderid': 20
                     },
                 ],
                 connected_to=[]))

    @defer.inlineCallbacks
    def test_getWorkers_no_config(self):
        yield self.insertTestData(self.baseRows)
        workerdicts = yield self.db.workers.getWorkers()
        [
            validation.verifyDbDict(self, 'workerdict', workerdict)
            for workerdict in workerdicts
        ]
        self.assertEqual(
            sorted(workerdicts, key=workerKey),
            sorted([
                dict(id=30,
                     name='zero',
                     workerinfo={'a': 'b'},
                     paused=False,
                     graceful=False,
                     configured_on=[],
                     connected_to=[]),
                dict(id=31,
                     name='one',
                     workerinfo={'a': 'b'},
                     paused=False,
                     graceful=False,
                     configured_on=[],
                     connected_to=[]),
            ],
                   key=workerKey))

    @defer.inlineCallbacks
    def test_getWorkers_with_config(self):
        yield self.insertTestData(self.baseRows + self.multipleMasters)
        workerdicts = yield self.db.workers.getWorkers()
        for workerdict in workerdicts:
            validation.verifyDbDict(self, 'workerdict', workerdict)
            workerdict['configured_on'] = sorted(workerdict['configured_on'],
                                                 key=configuredOnKey)
        self.assertEqual(
            sorted(workerdicts, key=workerKey),
            sorted([
                dict(id=30,
                     name='zero',
                     workerinfo={'a': 'b'},
                     paused=False,
                     graceful=False,
                     configured_on=sorted([
                         {
                             'masterid': 10,
                             'builderid': 20
                         },
                         {
                             'masterid': 10,
                             'builderid': 21
                         },
                         {
                             'masterid': 11,
                             'builderid': 20
                         },
                     ],
                                          key=configuredOnKey),
                     connected_to=[10]),
                dict(id=31,
                     name='one',
                     workerinfo={'a': 'b'},
                     paused=False,
                     graceful=False,
                     configured_on=sorted([
                         {
                             'masterid': 11,
                             'builderid': 20
                         },
                         {
                             'masterid': 11,
                             'builderid': 22
                         },
                     ],
                                          key=configuredOnKey),
                     connected_to=[11]),
            ],
                   key=workerKey))

    @defer.inlineCallbacks
    def test_getWorkers_empty(self):
        yield self.insertTestData(self.baseRows + self.multipleMasters)
        workerdicts = yield self.db.workers.getWorkers(masterid=11,
                                                       builderid=21)
        for workerdict in workerdicts:
            validation.verifyDbDict(self, 'workerdict', workerdict)
            workerdict['configured_on'] = sorted(workerdict['configured_on'],
                                                 key=configuredOnKey)
        self.assertEqual(sorted(workerdicts, key=workerKey), [])

    @defer.inlineCallbacks
    def test_getWorkers_with_config_builderid(self):
        yield self.insertTestData(self.baseRows + self.multipleMasters)
        workerdicts = yield self.db.workers.getWorkers(builderid=20)
        for workerdict in workerdicts:
            validation.verifyDbDict(self, 'workerdict', workerdict)
            workerdict['configured_on'] = sorted(workerdict['configured_on'],
                                                 key=configuredOnKey)
        self.assertEqual(
            sorted(workerdicts, key=workerKey),
            sorted([
                dict(id=30,
                     name='zero',
                     workerinfo={'a': 'b'},
                     paused=False,
                     graceful=False,
                     configured_on=sorted([
                         {
                             'masterid': 10,
                             'builderid': 20
                         },
                         {
                             'masterid': 11,
                             'builderid': 20
                         },
                     ],
                                          key=configuredOnKey),
                     connected_to=[10]),
                dict(id=31,
                     name='one',
                     workerinfo={'a': 'b'},
                     paused=False,
                     graceful=False,
                     configured_on=sorted([
                         {
                             'masterid': 11,
                             'builderid': 20
                         },
                     ],
                                          key=configuredOnKey),
                     connected_to=[11]),
            ],
                   key=workerKey))

    @defer.inlineCallbacks
    def test_getWorkers_with_config_masterid_10(self):
        yield self.insertTestData(self.baseRows + self.multipleMasters)
        workerdicts = yield self.db.workers.getWorkers(masterid=10)
        for workerdict in workerdicts:
            validation.verifyDbDict(self, 'workerdict', workerdict)
            workerdict['configured_on'] = sorted(workerdict['configured_on'],
                                                 key=configuredOnKey)
        self.assertEqual(
            sorted(workerdicts, key=workerKey),
            sorted([
                dict(id=30,
                     name='zero',
                     workerinfo={'a': 'b'},
                     paused=False,
                     graceful=False,
                     configured_on=sorted([
                         {
                             'masterid': 10,
                             'builderid': 20
                         },
                         {
                             'masterid': 10,
                             'builderid': 21
                         },
                     ],
                                          key=configuredOnKey),
                     connected_to=[10]),
            ],
                   key=workerKey))

    @defer.inlineCallbacks
    def test_getWorkers_with_config_masterid_11(self):
        yield self.insertTestData(self.baseRows + self.multipleMasters)
        workerdicts = yield self.db.workers.getWorkers(masterid=11)
        for workerdict in workerdicts:
            validation.verifyDbDict(self, 'workerdict', workerdict)
            workerdict['configured_on'] = sorted(workerdict['configured_on'],
                                                 key=configuredOnKey)
        self.assertEqual(
            sorted(workerdicts, key=workerKey),
            sorted([
                dict(id=30,
                     name='zero',
                     workerinfo={'a': 'b'},
                     paused=False,
                     graceful=False,
                     configured_on=sorted([
                         {
                             'masterid': 11,
                             'builderid': 20
                         },
                     ],
                                          key=configuredOnKey),
                     connected_to=[]),
                dict(id=31,
                     name='one',
                     workerinfo={'a': 'b'},
                     paused=False,
                     graceful=False,
                     configured_on=sorted([
                         {
                             'masterid': 11,
                             'builderid': 20
                         },
                         {
                             'masterid': 11,
                             'builderid': 22
                         },
                     ],
                                          key=configuredOnKey),
                     connected_to=[11]),
            ],
                   key=workerKey))

    @defer.inlineCallbacks
    def test_getWorkers_with_config_masterid_11_builderid_22(self):
        yield self.insertTestData(self.baseRows + self.multipleMasters)
        workerdicts = yield self.db.workers.getWorkers(masterid=11,
                                                       builderid=22)
        for workerdict in workerdicts:
            validation.verifyDbDict(self, 'workerdict', workerdict)
            workerdict['configured_on'] = sorted(workerdict['configured_on'],
                                                 key=configuredOnKey)
        self.assertEqual(
            sorted(workerdicts, key=workerKey),
            sorted([
                dict(id=31,
                     name='one',
                     workerinfo={'a': 'b'},
                     paused=False,
                     graceful=False,
                     configured_on=sorted([
                         {
                             'masterid': 11,
                             'builderid': 22
                         },
                     ],
                                          key=configuredOnKey),
                     connected_to=[11]),
            ],
                   key=workerKey))

    @defer.inlineCallbacks
    def test_getWorkers_with_paused(self):
        yield self.insertTestData(self.baseRows + self.multipleMasters)
        yield self.db.workers.setWorkerState(31, paused=True, graceful=False)
        workerdicts = yield self.db.workers.getWorkers(paused=True)
        for workerdict in workerdicts:
            validation.verifyDbDict(self, 'workerdict', workerdict)
            workerdict['configured_on'] = []
        self.assertEqual(workerdicts, [
            dict(id=31,
                 name='one',
                 workerinfo={'a': 'b'},
                 paused=True,
                 graceful=False,
                 configured_on=[],
                 connected_to=[11]),
        ])

    @defer.inlineCallbacks
    def test_getWorkers_with_graceful(self):
        yield self.insertTestData(self.baseRows + self.multipleMasters)
        yield self.db.workers.setWorkerState(31, paused=False, graceful=True)
        workerdicts = yield self.db.workers.getWorkers(graceful=True)
        for workerdict in workerdicts:
            validation.verifyDbDict(self, 'workerdict', workerdict)
            workerdict['configured_on'] = []
        self.assertEqual(workerdicts, [
            dict(id=31,
                 name='one',
                 workerinfo={'a': 'b'},
                 paused=False,
                 graceful=True,
                 configured_on=[],
                 connected_to=[11]),
        ])

    @defer.inlineCallbacks
    def test_workerConnected_existing(self):
        yield self.insertTestData(self.baseRows + self.worker1_rows)

        NEW_INFO = {'other': [1, 2, 3]}

        yield self.db.workers.workerConnected(workerid=self.W1_ID,
                                              masterid=11,
                                              workerinfo=NEW_INFO)

        w = yield self.db.workers.getWorker(self.W1_ID)
        self.assertEqual(
            w, {
                'id': self.W1_ID,
                'name': self.W1_NAME,
                'workerinfo': NEW_INFO,
                'paused': False,
                'graceful': False,
                'configured_on': [],
                'connected_to': [11]
            })

    @defer.inlineCallbacks
    def test_workerConnected_already_connected(self):
        yield self.insertTestData(self.baseRows + self.worker1_rows + [
            fakedb.ConnectedWorker(id=888, workerid=self.W1_ID, masterid=11),
        ])
        yield self.db.workers.workerConnected(workerid=self.W1_ID,
                                              masterid=11,
                                              workerinfo={})

        w = yield self.db.workers.getWorker(self.W1_ID)
        self.assertEqual(w['connected_to'], [11])

    @defer.inlineCallbacks
    def test_workerDisconnected(self):
        yield self.insertTestData(self.baseRows + self.worker1_rows + [
            fakedb.ConnectedWorker(id=888, workerid=self.W1_ID, masterid=10),
            fakedb.ConnectedWorker(id=889, workerid=self.W1_ID, masterid=11),
        ])
        yield self.db.workers.workerDisconnected(workerid=self.W1_ID,
                                                 masterid=11)

        w = yield self.db.workers.getWorker(self.W1_ID)
        self.assertEqual(w['connected_to'], [10])

    @defer.inlineCallbacks
    def test_workerDisconnected_already_disconnected(self):
        yield self.insertTestData(self.baseRows + self.worker1_rows)
        yield self.db.workers.workerDisconnected(workerid=self.W1_ID,
                                                 masterid=11)

        w = yield self.db.workers.getWorker(self.W1_ID)
        self.assertEqual(w['connected_to'], [])

    @defer.inlineCallbacks
    def test_setWorkerState_existing(self):
        yield self.insertTestData(self.baseRows + self.worker1_rows)

        yield self.db.workers.setWorkerState(workerid=self.W1_ID,
                                             paused=False,
                                             graceful=True)

        w = yield self.db.workers.getWorker(self.W1_ID)
        self.assertEqual(
            w, {
                'id': self.W1_ID,
                'name': self.W1_NAME,
                'workerinfo': self.W1_INFO,
                'paused': False,
                'graceful': True,
                'configured_on': [],
                'connected_to': []
            })

        yield self.db.workers.setWorkerState(workerid=self.W1_ID,
                                             paused=True,
                                             graceful=False)

        w = yield self.db.workers.getWorker(self.W1_ID)
        self.assertEqual(
            w, {
                'id': self.W1_ID,
                'name': self.W1_NAME,
                'workerinfo': self.W1_INFO,
                'paused': True,
                'graceful': False,
                'configured_on': [],
                'connected_to': []
            })

    @defer.inlineCallbacks
    def test_workerConfigured(self):
        yield self.insertTestData(self.baseRows + self.multipleMasters)

        # should remove builder 21, and add 22
        yield self.db.workers.deconfigureAllWorkersForMaster(masterid=10)

        yield self.db.workers.workerConfigured(workerid=30,
                                               masterid=10,
                                               builderids=[20, 22])

        w = yield self.db.workers.getWorker(30)
        self.assertEqual(
            sorted(w['configured_on'], key=configuredOnKey),
            sorted([{
                'builderid': 20,
                'masterid': 11
            }, {
                'builderid': 20,
                'masterid': 10
            }, {
                'builderid': 22,
                'masterid': 10
            }],
                   key=configuredOnKey))

    @defer.inlineCallbacks
    def test_workerConfiguredTwice(self):
        yield self.insertTestData(self.baseRows + self.multipleMasters)

        # should remove builder 21, and add 22
        yield self.db.workers.deconfigureAllWorkersForMaster(masterid=10)

        yield self.db.workers.workerConfigured(workerid=30,
                                               masterid=10,
                                               builderids=[20, 22])

        # configure again (should eat the duplicate insertion errors)
        yield self.db.workers.workerConfigured(workerid=30,
                                               masterid=10,
                                               builderids=[20, 21, 22])

        w = yield self.db.workers.getWorker(30)
        x1 = sorted(w['configured_on'], key=configuredOnKey)
        x2 = sorted([{
            'builderid': 20,
            'masterid': 11
        }, {
            'builderid': 20,
            'masterid': 10
        }, {
            'builderid': 21,
            'masterid': 10
        }, {
            'builderid': 22,
            'masterid': 10
        }],
                    key=configuredOnKey)
        self.assertEqual(x1, x2)

    @defer.inlineCallbacks
    def test_workerReConfigured(self):
        yield self.insertTestData(self.baseRows + self.multipleMasters)

        # should remove builder 21, and add 22
        yield self.db.workers.workerConfigured(workerid=30,
                                               masterid=10,
                                               builderids=[20, 22])

        w = yield self.db.workers.getWorker(30)
        w['configured_on'] = sorted(w['configured_on'], key=configuredOnKey)
        self.assertEqual(
            w['configured_on'],
            sorted([{
                'builderid': 20,
                'masterid': 11
            }, {
                'builderid': 20,
                'masterid': 10
            }, {
                'builderid': 22,
                'masterid': 10
            }],
                   key=configuredOnKey))

    @defer.inlineCallbacks
    def test_workerReConfigured_should_not_affect_other_worker(self):
        yield self.insertTestData(self.baseRows + self.multipleMasters)

        # should remove all the builders in master 11
        yield self.db.workers.workerConfigured(workerid=30,
                                               masterid=11,
                                               builderids=[])

        w = yield self.db.workers.getWorker(30)
        x1 = sorted(w['configured_on'], key=configuredOnKey)
        x2 = sorted([{
            'builderid': 20,
            'masterid': 10
        }, {
            'builderid': 21,
            'masterid': 10
        }],
                    key=configuredOnKey)
        self.assertEqual(x1, x2)

        # ensure worker 31 is not affected (see GitHub issue#3392)
        w = yield self.db.workers.getWorker(31)
        x1 = sorted(w['configured_on'], key=configuredOnKey)
        x2 = sorted([{
            'builderid': 20,
            'masterid': 11
        }, {
            'builderid': 22,
            'masterid': 11
        }],
                    key=configuredOnKey)
        self.assertEqual(x1, x2)

    @defer.inlineCallbacks
    def test_workerUnconfigured(self):
        yield self.insertTestData(self.baseRows + self.multipleMasters)

        # should remove all builders from master 10
        yield self.db.workers.workerConfigured(workerid=30,
                                               masterid=10,
                                               builderids=[])

        w = yield self.db.workers.getWorker(30)
        w['configured_on'] = sorted(w['configured_on'], key=configuredOnKey)
        expected = sorted([{
            'builderid': 20,
            'masterid': 11
        }],
                          key=configuredOnKey)
        self.assertEqual(w['configured_on'], expected)

    @defer.inlineCallbacks
    def test_nothingConfigured(self):
        yield self.insertTestData(self.baseRows + self.multipleMasters)

        # should remove builder 21, and add 22
        yield self.db.workers.deconfigureAllWorkersForMaster(masterid=10)
        yield self.db.workers.workerConfigured(workerid=30,
                                               masterid=10,
                                               builderids=[])

        # should only keep builder for master 11
        w = yield self.db.workers.getWorker(30)
        self.assertEqual(sorted(w['configured_on']),
                         sorted([{
                             'builderid': 20,
                             'masterid': 11
                         }]))

    @defer.inlineCallbacks
    def test_deconfiguredAllWorkers(self):
        yield self.insertTestData(self.baseRows + self.multipleMasters)

        res = yield self.db.workers.getWorkers(masterid=11)
        self.assertEqual(len(res), 2)

        # should remove all worker configured for masterid 11
        yield self.db.workers.deconfigureAllWorkersForMaster(masterid=11)

        res = yield self.db.workers.getWorkers(masterid=11)
        self.assertEqual(len(res), 0)
示例#19
0
    def setupStep(self,
                  step,
                  sourcestampsInBuild=None,
                  gotRevisionsInBuild=None,
                  *args,
                  **kwargs):
        sourcestamps = sourcestampsInBuild or []
        got_revisions = gotRevisionsInBuild or {}

        yield super().setupStep(step, *args, **kwargs)

        # This step reaches deeply into a number of parts of Buildbot.  That
        # should be fixed!

        # set up a buildmaster that knows about two fake schedulers, a and b
        m = self.master
        m.db.checkForeignKeys = True
        self.build.builder.botmaster = m.botmaster
        self.build.conn = object()
        m.config.buildbotURL = "baseurl/"
        m.scheduler_manager = FakeSchedulerManager()

        self.scheduler_a = a = FakeTriggerable(name='a')
        self.scheduler_b = b = FakeTriggerable(name='b')
        self.scheduler_c = c = FakeTriggerable(name='c')
        m.scheduler_manager.namedServices = dict(a=a, b=b, c=c)

        a.brids = {77: 11}
        b.brids = {78: 22}
        c.brids = {79: 33, 80: 44}

        def make_fake_br(brid, builderid):
            return fakedb.BuildRequest(id=brid,
                                       buildsetid=BRID_TO_BSID(brid),
                                       builderid=builderid)

        def make_fake_build(brid, builderid):
            return fakedb.Build(buildrequestid=brid,
                                id=BRID_TO_BID(brid),
                                number=BRID_TO_BUILD_NUMBER(brid),
                                masterid=9,
                                workerid=13,
                                builderid=builderid)

        m.db.insertTestData([
            fakedb.Builder(id=77, name='A'),
            fakedb.Builder(id=78, name='B'),
            fakedb.Builder(id=79, name='C1'),
            fakedb.Builder(id=80, name='C2'),
            fakedb.Master(id=9),
            fakedb.Buildset(id=2022),
            fakedb.Buildset(id=2011),
            fakedb.Buildset(id=2033),
            fakedb.Worker(id=13, name="some:worker"),
            make_fake_br(11, 77),
            make_fake_br(22, 78),
            fakedb.BuildRequest(id=33, buildsetid=2033, builderid=79),
            fakedb.BuildRequest(id=44, buildsetid=2033, builderid=80),
            make_fake_build(11, builderid=77),
            make_fake_build(22, builderid=78),
            make_fake_build(33, builderid=79),
            # builderid is 79 on purpose, changed, from the one of the buildrequest
            # to test the case of the virtual
            make_fake_build(44, builderid=79),
        ])

        def getAllSourceStamps():
            return sourcestamps

        self.build.getAllSourceStamps = getAllSourceStamps

        def getAllGotRevisions():
            return got_revisions

        self.step.getAllGotRevisions = getAllGotRevisions

        self.exp_add_sourcestamp = None
        self.exp_a_trigger = None
        self.exp_b_trigger = None
        self.exp_c_trigger = None
        self.exp_added_urls = []
示例#20
0
    def setupBuildResults(self, results, wantPreviousBuild=False):
        # this testsuite always goes through setupBuildResults so that
        # the data is sure to be the real data schema known coming from data
        # api

        self.db = self.master.db
        self.db.insertTestData([
            fakedb.Master(id=92),
            fakedb.Worker(id=13, name='wrk'),
            fakedb.Buildset(id=97, results=SUCCESS, reason="testReason0"),
            fakedb.Buildset(id=98, results=results, reason="testReason1"),
            fakedb.Builder(id=80, name='Builder1'),
            fakedb.BuildRequest(id=10, buildsetid=97, builderid=80),
            fakedb.BuildRequest(id=11, buildsetid=98, builderid=80),
            fakedb.Build(id=19,
                         number=0,
                         builderid=80,
                         buildrequestid=10,
                         workerid=13,
                         masterid=92,
                         results=SUCCESS),
            fakedb.Build(id=20,
                         number=1,
                         builderid=80,
                         buildrequestid=11,
                         workerid=13,
                         masterid=92,
                         results=results),
            fakedb.Step(id=50, buildid=20, number=5, name='make'),
            fakedb.BuildsetSourceStamp(buildsetid=98, sourcestampid=234),
            fakedb.SourceStamp(id=234, patchid=99),
            fakedb.Change(changeid=13,
                          branch='trunk',
                          revision='9283',
                          author='me@foo',
                          repository='svn://...',
                          codebase='cbsvn',
                          project='world-domination',
                          sourcestampid=234),
            fakedb.Log(id=60,
                       stepid=50,
                       name='stdio',
                       slug='stdio',
                       type='s',
                       num_lines=7),
            fakedb.LogChunk(
                logid=60,
                first_line=0,
                last_line=1,
                compressed=0,
                content='Unicode log with non-ascii (\u00E5\u00E4\u00F6).'),
            fakedb.Patch(id=99,
                         patch_base64='aGVsbG8sIHdvcmxk',
                         patch_author='him@foo',
                         patch_comment='foo',
                         subdir='/foo',
                         patchlevel=3),
        ])
        for _id in (20, ):
            self.db.insertTestData([
                fakedb.BuildProperty(buildid=_id,
                                     name="workername",
                                     value="wrk"),
                fakedb.BuildProperty(buildid=_id,
                                     name="reason",
                                     value="because"),
                fakedb.BuildProperty(buildid=_id,
                                     name="scheduler",
                                     value="checkin"),
                fakedb.BuildProperty(buildid=_id,
                                     name="branch",
                                     value="master"),
            ])
        res = yield utils.getDetailsForBuildset(
            self.master,
            98,
            wantProperties=True,
            wantPreviousBuild=wantPreviousBuild)
        builds = res['builds']
        buildset = res['buildset']

        @defer.inlineCallbacks
        def getChangesForBuild(buildid):
            assert buildid == 20
            ch = yield self.master.db.changes.getChange(13)
            return [ch]

        self.master.db.changes.getChangesForBuild = getChangesForBuild
        return (buildset, builds)
示例#21
0
class Tests(interfaces.InterfaceTests):

    common_data = [
        fakedb.Worker(id=47, name='linux'),
        fakedb.Buildset(id=20),
        fakedb.Builder(id=88, name='b1'),
        fakedb.Builder(id=89, name='b2'),
        fakedb.BuildRequest(id=41, buildsetid=20, builderid=88),
        fakedb.BuildRequest(id=42, buildsetid=20, builderid=88),
        fakedb.BuildRequest(id=43, buildsetid=20, builderid=88),
        fakedb.Master(id=88),
        fakedb.Build(id=30,
                     buildrequestid=41,
                     number=7,
                     masterid=88,
                     builderid=88,
                     workerid=47),
        fakedb.Build(id=31,
                     buildrequestid=42,
                     number=8,
                     masterid=88,
                     builderid=88,
                     workerid=47),
        fakedb.Build(id=40,
                     buildrequestid=43,
                     number=9,
                     masterid=88,
                     builderid=89,
                     workerid=47),
        fakedb.Step(id=131, number=231, name='step231', buildid=30),
        fakedb.Step(id=132, number=232, name='step232', buildid=30),
        fakedb.Step(id=141, number=241, name='step241', buildid=31),
        fakedb.Step(id=142, number=242, name='step242', buildid=40),
    ]

    common_test_result_set_data = [
        fakedb.TestResultSet(id=91,
                             builderid=88,
                             buildid=30,
                             stepid=131,
                             description='desc1',
                             category='cat',
                             value_unit='ms',
                             tests_failed=None,
                             tests_passed=None,
                             complete=0),
        fakedb.TestResultSet(id=92,
                             builderid=88,
                             buildid=30,
                             stepid=131,
                             description='desc2',
                             category='cat',
                             value_unit='ms',
                             tests_failed=None,
                             tests_passed=None,
                             complete=1),
    ]

    def test_signature_add_test_result_set(self):
        @self.assertArgSpecMatches(self.db.test_result_sets.addTestResultSet)
        def addTestResultSet(self, builderid, buildid, stepid, description,
                             category, value_unit):
            pass

    def test_signature_get_test_result_set(self):
        @self.assertArgSpecMatches(self.db.test_result_sets.getTestResultSet)
        def getTestResultSet(self, test_result_setid):
            pass

    def test_signature_get_test_result_sets(self):
        @self.assertArgSpecMatches(self.db.test_result_sets.getTestResultSets)
        def getTestResultSets(self,
                              builderid,
                              buildid=None,
                              stepid=None,
                              complete=None,
                              result_spec=None):
            pass

    def test_signature_complete_test_result_set(self):
        @self.assertArgSpecMatches(
            self.db.test_result_sets.completeTestResultSet)
        def completeTestResultSet(self,
                                  test_result_setid,
                                  tests_passed=None,
                                  tests_failed=None):
            pass

    @defer.inlineCallbacks
    def test_add_set_get_set(self):
        yield self.insertTestData(self.common_data)
        set_id = yield self.db.test_result_sets.addTestResultSet(
            builderid=88,
            buildid=30,
            stepid=131,
            description='desc',
            category='cat',
            value_unit='ms')
        set_dict = yield self.db.test_result_sets.getTestResultSet(set_id)
        validation.verifyDbDict(self, 'test_result_setdict', set_dict)
        self.assertEqual(
            set_dict, {
                'id': set_id,
                'builderid': 88,
                'buildid': 30,
                'stepid': 131,
                'description': 'desc',
                'category': 'cat',
                'value_unit': 'ms',
                'tests_failed': None,
                'tests_passed': None,
                'complete': False
            })

    @defer.inlineCallbacks
    def test_get_sets(self):
        yield self.insertTestData(self.common_data + [
            fakedb.TestResultSet(id=91,
                                 builderid=88,
                                 buildid=30,
                                 stepid=131,
                                 description='desc1',
                                 category='cat',
                                 value_unit='ms',
                                 tests_failed=None,
                                 tests_passed=None,
                                 complete=0),
            fakedb.TestResultSet(id=92,
                                 builderid=89,
                                 buildid=40,
                                 stepid=142,
                                 description='desc2',
                                 category='cat',
                                 value_unit='ms',
                                 tests_failed=None,
                                 tests_passed=None,
                                 complete=1),
            fakedb.TestResultSet(id=93,
                                 builderid=88,
                                 buildid=31,
                                 stepid=141,
                                 description='desc3',
                                 category='cat',
                                 value_unit='ms',
                                 tests_failed=None,
                                 tests_passed=None,
                                 complete=1),
            fakedb.TestResultSet(id=94,
                                 builderid=88,
                                 buildid=30,
                                 stepid=132,
                                 description='desc4',
                                 category='cat',
                                 value_unit='ms',
                                 tests_failed=None,
                                 tests_passed=None,
                                 complete=1),
            fakedb.TestResultSet(id=95,
                                 builderid=88,
                                 buildid=30,
                                 stepid=131,
                                 description='desc4',
                                 category='cat',
                                 value_unit='ms',
                                 tests_failed=None,
                                 tests_passed=None,
                                 complete=0),
        ])

        set_dicts = yield self.db.test_result_sets.getTestResultSets(
            builderid=88)
        self.assertEqual([d['id'] for d in set_dicts], [91, 93, 94, 95])
        for d in set_dicts:
            validation.verifyDbDict(self, 'test_result_setdict', d)

        set_dicts = yield self.db.test_result_sets.getTestResultSets(
            builderid=89)
        self.assertEqual([d['id'] for d in set_dicts], [92])
        set_dicts = yield self.db.test_result_sets.getTestResultSets(
            builderid=88, buildid=30)
        self.assertEqual([d['id'] for d in set_dicts], [91, 94, 95])
        set_dicts = yield self.db.test_result_sets.getTestResultSets(
            builderid=88, buildid=31)
        self.assertEqual([d['id'] for d in set_dicts], [93])
        set_dicts = yield self.db.test_result_sets.getTestResultSets(
            builderid=88, stepid=131)
        self.assertEqual([d['id'] for d in set_dicts], [91, 95])
        set_dicts = yield self.db.test_result_sets.getTestResultSets(
            builderid=88, stepid=132)
        self.assertEqual([d['id'] for d in set_dicts], [94])
        set_dicts = yield self.db.test_result_sets.getTestResultSets(
            builderid=88, complete=True)
        self.assertEqual([d['id'] for d in set_dicts], [93, 94])
        set_dicts = yield self.db.test_result_sets.getTestResultSets(
            builderid=88, complete=False)
        self.assertEqual([d['id'] for d in set_dicts], [91, 95])

    @defer.inlineCallbacks
    def test_get_set_from_data(self):
        yield self.insertTestData(self.common_data +
                                  self.common_test_result_set_data)

        set_dict = yield self.db.test_result_sets.getTestResultSet(91)
        self.assertEqual(
            set_dict, {
                'id': 91,
                'builderid': 88,
                'buildid': 30,
                'stepid': 131,
                'description': 'desc1',
                'category': 'cat',
                'value_unit': 'ms',
                'tests_failed': None,
                'tests_passed': None,
                'complete': False
            })

    @defer.inlineCallbacks
    def test_get_non_existing_set(self):
        set_dict = yield self.db.test_result_sets.getTestResultSet(91)
        self.assertEqual(set_dict, None)

    @defer.inlineCallbacks
    def test_complete_already_completed_set(self):
        yield self.insertTestData(self.common_data +
                                  self.common_test_result_set_data)
        with self.assertRaises(test_result_sets.TestResultSetAlreadyCompleted):
            yield self.db.test_result_sets.completeTestResultSet(92)
        self.flushLoggedErrors(test_result_sets.TestResultSetAlreadyCompleted)

    @defer.inlineCallbacks
    def test_complete_set_with_test_counts(self):
        yield self.insertTestData(self.common_data +
                                  self.common_test_result_set_data)

        yield self.db.test_result_sets.completeTestResultSet(91,
                                                             tests_passed=12,
                                                             tests_failed=2)

        set_dict = yield self.db.test_result_sets.getTestResultSet(91)
        self.assertEqual(
            set_dict, {
                'id': 91,
                'builderid': 88,
                'buildid': 30,
                'stepid': 131,
                'description': 'desc1',
                'category': 'cat',
                'value_unit': 'ms',
                'tests_failed': 2,
                'tests_passed': 12,
                'complete': True
            })

    @defer.inlineCallbacks
    def test_complete_set_without_test_counts(self):
        yield self.insertTestData(self.common_data +
                                  self.common_test_result_set_data)

        yield self.db.test_result_sets.completeTestResultSet(91)

        set_dict = yield self.db.test_result_sets.getTestResultSet(91)
        self.assertEqual(
            set_dict, {
                'id': 91,
                'builderid': 88,
                'buildid': 30,
                'stepid': 131,
                'description': 'desc1',
                'category': 'cat',
                'value_unit': 'ms',
                'tests_failed': None,
                'tests_passed': None,
                'complete': True
            })
示例#22
0
 def insert_initial_data(self):
     self.master.db.insertTestData([
         fakedb.Master(id=1),
         fakedb.Worker(id=1, name='example-worker'),
         fakedb.Scheduler(id=1, name='custom', enabled=1),
         fakedb.Scheduler(id=2, name='all', enabled=2),
         fakedb.Scheduler(id=3, name='force', enabled=3),
         fakedb.SchedulerMaster(schedulerid=1, masterid=1),
         fakedb.SchedulerMaster(schedulerid=2, masterid=1),
         fakedb.SchedulerMaster(schedulerid=3, masterid=1),
         fakedb.Builder(id=1, name='runtests1'),
         fakedb.Builder(id=2, name='runtests2'),
         fakedb.Builder(id=3, name='runtests3'),
         fakedb.BuilderMaster(id=1, builderid=1, masterid=1),
         fakedb.BuilderMaster(id=2, builderid=2, masterid=1),
         fakedb.BuilderMaster(id=3, builderid=3, masterid=1),
         fakedb.Tag(id=1, name='tag1'),
         fakedb.Tag(id=2, name='tag12'),
         fakedb.Tag(id=3, name='tag23'),
         fakedb.BuildersTags(id=1, builderid=1, tagid=1),
         fakedb.BuildersTags(id=2, builderid=1, tagid=2),
         fakedb.BuildersTags(id=3, builderid=2, tagid=2),
         fakedb.BuildersTags(id=4, builderid=2, tagid=3),
         fakedb.BuildersTags(id=5, builderid=3, tagid=3),
         fakedb.Buildset(id=1,
                         results=SUCCESS,
                         reason="Force reason 1",
                         submitted_at=100000,
                         complete_at=100110,
                         complete=1),
         fakedb.Buildset(id=2,
                         results=SUCCESS,
                         reason="Force reason 2",
                         submitted_at=100200,
                         complete_at=100330,
                         complete=1),
         fakedb.Buildset(id=3,
                         results=SUCCESS,
                         reason="Force reason 3",
                         submitted_at=100400,
                         complete_at=100550,
                         complete=1),
         fakedb.BuildsetProperty(buildsetid=1,
                                 property_name='scheduler',
                                 property_value='["custom", "Scheduler"]'),
         fakedb.BuildsetProperty(buildsetid=2,
                                 property_name='scheduler',
                                 property_value='["all", "Scheduler"]'),
         fakedb.BuildsetProperty(buildsetid=3,
                                 property_name='scheduler',
                                 property_value='["force", "Scheduler"]'),
         fakedb.BuildsetProperty(
             buildsetid=3,
             property_name='owner',
             property_value='["*****@*****.**", "Force Build Form"]'),
         fakedb.SourceStamp(id=1, branch='master', revision='1234abcd'),
         fakedb.Change(changeid=1,
                       branch='master',
                       revision='1234abcd',
                       sourcestampid=1),
         fakedb.ChangeProperty(
             changeid=1,
             property_name="owner",
             property_value='["*****@*****.**", "change"]'),
         fakedb.ChangeProperty(changeid=1,
                               property_name="other_prop",
                               property_value='["value", "change"]'),
         fakedb.BuildsetSourceStamp(id=1, buildsetid=1, sourcestampid=1),
         fakedb.BuildsetSourceStamp(id=2, buildsetid=2, sourcestampid=1),
         fakedb.BuildsetSourceStamp(id=3, buildsetid=3, sourcestampid=1),
         fakedb.BuildRequest(id=1,
                             buildsetid=1,
                             builderid=1,
                             results=SUCCESS,
                             submitted_at=100001,
                             complete_at=100109,
                             complete=1),
         fakedb.BuildRequest(id=2,
                             buildsetid=2,
                             builderid=1,
                             results=SUCCESS,
                             submitted_at=100201,
                             complete_at=100329,
                             complete=1),
         fakedb.BuildRequest(id=3,
                             buildsetid=3,
                             builderid=2,
                             results=SUCCESS,
                             submitted_at=100401,
                             complete_at=100549,
                             complete=1),
         fakedb.Build(id=1,
                      number=1,
                      buildrequestid=1,
                      builderid=1,
                      workerid=1,
                      masterid=1001,
                      started_at=100002,
                      complete_at=100108,
                      state_string='build successful',
                      results=SUCCESS),
         fakedb.Build(id=2,
                      number=2,
                      buildrequestid=2,
                      builderid=1,
                      workerid=1,
                      masterid=1001,
                      started_at=100202,
                      complete_at=100328,
                      state_string='build successful',
                      results=SUCCESS),
         fakedb.Build(id=3,
                      number=1,
                      buildrequestid=3,
                      builderid=2,
                      workerid=1,
                      masterid=1001,
                      started_at=100402,
                      complete_at=100548,
                      state_string='build successful',
                      results=SUCCESS),
         fakedb.BuildProperty(buildid=3,
                              name='reason',
                              value='"force build"',
                              source="Force Build Form"),
         fakedb.BuildProperty(buildid=3,
                              name='owner',
                              value='"*****@*****.**"',
                              source="Force Build Form"),
         fakedb.BuildProperty(buildid=3,
                              name='scheduler',
                              value='"force"',
                              source="Scheduler"),
         fakedb.BuildProperty(buildid=3,
                              name='buildername',
                              value='"runtests3"',
                              source="Builder"),
         fakedb.BuildProperty(buildid=3,
                              name='workername',
                              value='"example-worker"',
                              source="Worker"),
         fakedb.Step(id=1,
                     number=1,
                     name='step1',
                     buildid=1,
                     started_at=100010,
                     complete_at=100019,
                     state_string='step1 done'),
         fakedb.Step(id=2,
                     number=2,
                     name='step2',
                     buildid=1,
                     started_at=100020,
                     complete_at=100029,
                     state_string='step2 done'),
         fakedb.Step(id=3,
                     number=3,
                     name='step3',
                     buildid=1,
                     started_at=100030,
                     complete_at=100039,
                     state_string='step3 done'),
         fakedb.Step(id=11,
                     number=1,
                     name='step1',
                     buildid=2,
                     started_at=100210,
                     complete_at=100219,
                     state_string='step1 done'),
         fakedb.Step(id=12,
                     number=2,
                     name='step2',
                     buildid=2,
                     started_at=100220,
                     complete_at=100229,
                     state_string='step2 done'),
         fakedb.Step(id=13,
                     number=3,
                     name='step3',
                     buildid=2,
                     started_at=100230,
                     complete_at=100239,
                     state_string='step3 done'),
         fakedb.Step(id=21,
                     number=1,
                     name='step1',
                     buildid=3,
                     started_at=100410,
                     complete_at=100419,
                     state_string='step1 done'),
         fakedb.Step(id=22,
                     number=2,
                     name='step2',
                     buildid=3,
                     started_at=100420,
                     complete_at=100429,
                     state_string='step2 done'),
         fakedb.Step(id=23,
                     number=3,
                     name='step3',
                     buildid=3,
                     started_at=100430,
                     complete_at=100439,
                     state_string='step3 done'),
         fakedb.Log(id=1,
                    name='stdio',
                    slug='stdio',
                    stepid=1,
                    complete=1,
                    num_lines=10),
         fakedb.Log(id=2,
                    name='stdio',
                    slug='stdio',
                    stepid=2,
                    complete=1,
                    num_lines=20),
         fakedb.Log(id=3,
                    name='stdio',
                    slug='stdio',
                    stepid=3,
                    complete=1,
                    num_lines=30),
         fakedb.Log(id=11,
                    name='stdio',
                    slug='stdio',
                    stepid=11,
                    complete=1,
                    num_lines=30),
         fakedb.Log(id=12,
                    name='stdio',
                    slug='stdio',
                    stepid=12,
                    complete=1,
                    num_lines=40),
         fakedb.Log(id=13,
                    name='stdio',
                    slug='stdio',
                    stepid=13,
                    complete=1,
                    num_lines=50),
         fakedb.Log(id=21,
                    name='stdio',
                    slug='stdio',
                    stepid=21,
                    complete=1,
                    num_lines=50),
         fakedb.Log(id=22,
                    name='stdio',
                    slug='stdio',
                    stepid=22,
                    complete=1,
                    num_lines=60),
         fakedb.Log(id=23,
                    name='stdio',
                    slug='stdio',
                    stepid=23,
                    complete=1,
                    num_lines=70),
         fakedb.LogChunk(logid=1,
                         first_line=0,
                         last_line=2,
                         content='o line1\no line2\n'),
         fakedb.LogChunk(logid=1,
                         first_line=2,
                         last_line=3,
                         content='o line3\n'),
         fakedb.LogChunk(logid=2,
                         first_line=0,
                         last_line=4,
                         content='o line1\no line2\no line3\no line4\n'),
     ])
示例#23
0
class Tests(interfaces.InterfaceTests):

    common_data = [
        fakedb.Worker(id=47, name='linux'),
        fakedb.Buildset(id=20),
        fakedb.Builder(id=88, name='b1'),
        fakedb.Builder(id=89, name='b2'),
        fakedb.BuildRequest(id=41, buildsetid=20, builderid=88),
        fakedb.BuildRequest(id=42, buildsetid=20, builderid=88),
        fakedb.BuildRequest(id=43, buildsetid=20, builderid=89),
        fakedb.Master(id=88),
        fakedb.Build(id=30,
                     buildrequestid=41,
                     number=7,
                     masterid=88,
                     builderid=88,
                     workerid=47),
        fakedb.Build(id=31,
                     buildrequestid=42,
                     number=8,
                     masterid=88,
                     builderid=88,
                     workerid=47),
        fakedb.Build(id=40,
                     buildrequestid=43,
                     number=9,
                     masterid=88,
                     builderid=89,
                     workerid=47),
    ]

    def test_signature_add_build_data(self):
        @self.assertArgSpecMatches(self.db.build_data.setBuildData)
        def setBuildData(self, buildid, name, value, source):
            pass

    def test_signature_get_build_data(self):
        @self.assertArgSpecMatches(self.db.build_data.getBuildData)
        def getBuildData(self, buildid, name):
            pass

    def test_signature_get_build_data_no_value(self):
        @self.assertArgSpecMatches(self.db.build_data.getBuildDataNoValue)
        def getBuildDataNoValue(self, buildid, name):
            pass

    def test_signature_get_all_build_data_no_values(self):
        @self.assertArgSpecMatches(self.db.build_data.getAllBuildDataNoValues)
        def getAllBuildDataNoValues(self, buildid):
            pass

    @defer.inlineCallbacks
    def test_add_data_get_data(self):
        yield self.insertTestData(self.common_data)
        yield self.db.build_data.setBuildData(buildid=30,
                                              name='mykey',
                                              value=b'myvalue',
                                              source='mysource')
        data_dict = yield self.db.build_data.getBuildData(buildid=30,
                                                          name='mykey')
        validation.verifyDbDict(self, 'build_datadict', data_dict)
        self.assertEqual(
            data_dict, {
                'buildid': 30,
                'name': 'mykey',
                'value': b'myvalue',
                'source': 'mysource'
            })

    @defer.inlineCallbacks
    def test_get_data_non_existing(self):
        yield self.insertTestData(self.common_data)
        data_dict = yield self.db.build_data.getBuildData(buildid=30,
                                                          name='mykey')
        self.assertIsNone(data_dict)

    @defer.inlineCallbacks
    def test_add_data_replace_value(self):
        yield self.insertTestData(self.common_data)
        yield self.db.build_data.setBuildData(buildid=30,
                                              name='mykey',
                                              value=b'myvalue',
                                              source='mysource')
        yield self.db.build_data.setBuildData(buildid=30,
                                              name='mykey',
                                              value=b'myvalue2',
                                              source='mysource2')

        data_dict = yield self.db.build_data.getBuildData(buildid=30,
                                                          name='mykey')
        validation.verifyDbDict(self, 'build_datadict', data_dict)
        self.assertEqual(
            data_dict, {
                'buildid': 30,
                'name': 'mykey',
                'value': b'myvalue2',
                'source': 'mysource2'
            })

    @defer.inlineCallbacks
    def test_add_data_insert_race(self):
        yield self.insertTestData(self.common_data)

        def hook(conn):
            insert_values = {
                'buildid': 30,
                'name': 'mykey',
                'value': b'myvalue_old',
                'source': 'mysourec_old'
            }
            q = self.db.model.build_data.insert().values(insert_values)
            conn.execute(q)

        self.db.build_data._test_timing_hook = hook

        yield self.db.build_data.setBuildData(buildid=30,
                                              name='mykey',
                                              value=b'myvalue',
                                              source='mysource')

        data_dict = yield self.db.build_data.getBuildData(buildid=30,
                                                          name='mykey')
        validation.verifyDbDict(self, 'build_datadict', data_dict)
        self.assertEqual(
            data_dict, {
                'buildid': 30,
                'name': 'mykey',
                'value': b'myvalue',
                'source': 'mysource'
            })

    @defer.inlineCallbacks
    def test_add_data_get_data_no_value(self):
        yield self.insertTestData(self.common_data)
        yield self.db.build_data.setBuildData(buildid=30,
                                              name='mykey',
                                              value=b'myvalue',
                                              source='mysource')
        data_dict = yield self.db.build_data.getBuildDataNoValue(buildid=30,
                                                                 name='mykey')
        validation.verifyDbDict(self, 'build_datadict', data_dict)
        self.assertEqual(data_dict, {
            'buildid': 30,
            'name': 'mykey',
            'value': None,
            'source': 'mysource'
        })

    @defer.inlineCallbacks
    def test_get_data_no_values_non_existing(self):
        yield self.insertTestData(self.common_data)
        data_dict = yield self.db.build_data.getBuildDataNoValue(buildid=30,
                                                                 name='mykey')
        self.assertIsNone(data_dict)

    @defer.inlineCallbacks
    def test_get_all_build_data_no_values(self):
        yield self.insertTestData(self.common_data + [
            fakedb.BuildData(id=91,
                             buildid=30,
                             name='name1',
                             value=b'value1',
                             source='source1'),
            fakedb.BuildData(id=92,
                             buildid=30,
                             name='name2',
                             value=b'value2',
                             source='source2'),
            fakedb.BuildData(id=93,
                             buildid=31,
                             name='name3',
                             value=b'value3',
                             source='source3'),
        ])

        data_dicts = yield self.db.build_data.getAllBuildDataNoValues(30)
        self.assertEqual([d['name'] for d in data_dicts], ['name1', 'name2'])
        for d in data_dicts:
            validation.verifyDbDict(self, 'build_datadict', d)

        # note that value is not in dict
        self.assertEqual(data_dicts[0], {
            'buildid': 30,
            'name': 'name1',
            'value': None,
            'source': 'source1'
        })

        data_dicts = yield self.db.build_data.getAllBuildDataNoValues(31)
        self.assertEqual([d['name'] for d in data_dicts], ['name3'])
        data_dicts = yield self.db.build_data.getAllBuildDataNoValues(32)
        self.assertEqual([d['name'] for d in data_dicts], [])

    @parameterized.expand([
        (1000000, 0, ['name1', 'name2', 'name3', 'name4', 'name5', 'name6']),
        (1000001, 0, ['name1', 'name2', 'name3', 'name4', 'name5', 'name6']),
        (1000002, 2, ['name1', 'name2', 'name5', 'name6']),
        (1000003, 3, ['name1', 'name2', 'name6']),
        (1000004, 4, ['name1', 'name2']),
        (1000005, 4, ['name1', 'name2']),
    ])
    @defer.inlineCallbacks
    def test_remove_old_build_data(self, older_than_timestamp, exp_num_deleted,
                                   exp_remaining_names):
        yield self.insertTestData(self.common_data + [
            fakedb.Build(id=50,
                         buildrequestid=41,
                         number=17,
                         masterid=88,
                         builderid=88,
                         workerid=47,
                         complete_at=None),
            fakedb.Build(id=51,
                         buildrequestid=42,
                         number=18,
                         masterid=88,
                         builderid=88,
                         workerid=47,
                         complete_at=1000001),
            fakedb.Build(id=52,
                         buildrequestid=43,
                         number=19,
                         masterid=88,
                         builderid=89,
                         workerid=47,
                         complete_at=1000002),
            fakedb.Build(id=53,
                         buildrequestid=43,
                         number=20,
                         masterid=88,
                         builderid=89,
                         workerid=47,
                         complete_at=1000003),
            fakedb.BuildData(id=91,
                             buildid=50,
                             name='name1',
                             value=b'value1',
                             source='src1'),
            fakedb.BuildData(id=92,
                             buildid=50,
                             name='name2',
                             value=b'value2',
                             source='src2'),
            fakedb.BuildData(id=93,
                             buildid=51,
                             name='name3',
                             value=b'value3',
                             source='src3'),
            fakedb.BuildData(id=94,
                             buildid=51,
                             name='name4',
                             value=b'value4',
                             source='src4'),
            fakedb.BuildData(id=95,
                             buildid=52,
                             name='name5',
                             value=b'value5',
                             source='src5'),
            fakedb.BuildData(id=96,
                             buildid=53,
                             name='name6',
                             value=b'value6',
                             source='src6'),
        ])

        num_deleted = yield self.db.build_data.deleteOldBuildData(
            older_than_timestamp)
        self.assertEqual(num_deleted, exp_num_deleted)

        remaining_names = []
        for buildid in [50, 51, 52, 53]:
            data_dicts = yield self.db.build_data.getAllBuildDataNoValues(
                buildid)
            remaining_names += [d['name'] for d in data_dicts]

        self.assertEqual(sorted(remaining_names), sorted(exp_remaining_names))
示例#24
0
    def insertTestData(self, buildResults, finalResult, insertSS=True):
        self.db = self.master.db
        self.db.insertTestData([
            fakedb.Master(id=92),
            fakedb.Worker(id=13, name='wrk'),
            fakedb.Builder(id=79, name='Builder0'),
            fakedb.Builder(id=80, name='Builder1'),
            fakedb.Buildset(id=98, results=finalResult, reason="testReason1"),
            fakedb.Change(changeid=13,
                          branch='master',
                          revision='9283',
                          author='me@foo',
                          repository=self.TEST_REPO,
                          codebase=self.TEST_CODEBASE,
                          project='world-domination',
                          sourcestampid=234),
        ])

        if insertSS:
            self.db.insertTestData([
                fakedb.BuildsetSourceStamp(buildsetid=98, sourcestampid=234),
                fakedb.SourceStamp(id=234,
                                   project=self.TEST_PROJECT,
                                   revision=self.TEST_REVISION,
                                   repository=self.TEST_REPO,
                                   codebase=self.TEST_CODEBASE)
            ])

        for i, results in enumerate(buildResults):
            self.db.insertTestData([
                fakedb.BuildRequest(id=11 + i, buildsetid=98,
                                    builderid=79 + i),
                fakedb.Build(id=20 + i,
                             number=i,
                             builderid=79 + i,
                             buildrequestid=11 + i,
                             workerid=13,
                             masterid=92,
                             results=results,
                             state_string="buildText"),
                fakedb.Step(id=50 + i, buildid=20 + i, number=5, name='make'),
                fakedb.Log(id=60 + i,
                           stepid=50 + i,
                           name='stdio',
                           slug='stdio',
                           type='s',
                           num_lines=7),
                fakedb.LogChunk(
                    logid=60 + i,
                    first_line=0,
                    last_line=1,
                    compressed=0,
                    content='Unicode log with non-ascii (\u00E5\u00E4\u00F6).'
                ),
                fakedb.BuildProperty(buildid=20 + i,
                                     name="workername",
                                     value="wrk"),
                fakedb.BuildProperty(buildid=20 + i,
                                     name="reason",
                                     value="because"),
                fakedb.BuildProperty(buildid=20 + i,
                                     name="buildername",
                                     value="Builder0"),
            ])
            for k, v in self.TEST_PROPS.items():
                self.db.insertTestData(
                    [fakedb.BuildProperty(buildid=20 + i, name=k, value=v)])
示例#25
0
    def setupDb(self):
        self.db = self.master.db
        self.db.insertTestData([
            fakedb.Master(id=92),
            fakedb.Worker(id=13, name='wrk'),
            fakedb.Buildset(id=98, results=SUCCESS, reason="testReason1"),
            fakedb.Buildset(id=99,
                            results=SUCCESS,
                            reason="testReason2",
                            parent_buildid=21),
            fakedb.Builder(id=80, name='Builder1'),
            fakedb.Builder(id=81, name='Builder2'),
            fakedb.BuildRequest(id=9, buildsetid=97, builderid=80),
            fakedb.BuildRequest(id=10, buildsetid=97, builderid=80),
            fakedb.BuildRequest(id=11, buildsetid=98, builderid=80),
            fakedb.BuildRequest(id=12, buildsetid=98, builderid=80),
            fakedb.BuildRequest(id=13, buildsetid=99, builderid=81),
            fakedb.Build(id=18,
                         number=0,
                         builderid=80,
                         buildrequestid=9,
                         workerid=13,
                         masterid=92,
                         results=FAILURE),
            fakedb.Build(id=19,
                         number=1,
                         builderid=80,
                         buildrequestid=10,
                         workerid=13,
                         masterid=92,
                         results=RETRY),
            fakedb.Build(id=20,
                         number=2,
                         builderid=80,
                         buildrequestid=11,
                         workerid=13,
                         masterid=92,
                         results=SUCCESS),
            fakedb.Build(id=21,
                         number=3,
                         builderid=80,
                         buildrequestid=12,
                         workerid=13,
                         masterid=92,
                         results=SUCCESS),
            fakedb.Build(id=22,
                         number=1,
                         builderid=81,
                         buildrequestid=13,
                         workerid=13,
                         masterid=92,
                         results=SUCCESS),
            fakedb.BuildsetSourceStamp(buildsetid=98, sourcestampid=234),
            fakedb.SourceStamp(id=234),
            fakedb.Change(changeid=13,
                          branch='trunk',
                          revision='9283',
                          author='me@foo',
                          repository='svn://...',
                          codebase='cbsvn',
                          project='world-domination',
                          sourcestampid=234),
            fakedb.Patch(id=99,
                         patch_base64='aGVsbG8sIHdvcmxk',
                         patch_author='him@foo',
                         patch_comment='foo',
                         subdir='/foo',
                         patchlevel=3),
            fakedb.SourceStamp(id=235, patchid=99),
        ])
        for _id in (20, 21):
            self.db.insertTestData([
                fakedb.BuildProperty(buildid=_id,
                                     name="workername",
                                     value="wrk"),
                fakedb.BuildProperty(buildid=_id,
                                     name="reason",
                                     value="because"),
                fakedb.BuildProperty(buildid=_id, name="owner", value="him"),
                fakedb.Step(id=100 + _id, buildid=_id, name="step1"),
                fakedb.Step(id=200 + _id, buildid=_id, name="step2"),
                fakedb.Log(id=60 + _id,
                           stepid=100 + _id,
                           name='stdio',
                           slug='stdio',
                           type='s',
                           num_lines=2),
                fakedb.LogChunk(logid=60 + _id,
                                first_line=0,
                                last_line=1,
                                compressed=0,
                                content=self.LOGCONTENT),
            ])

        @defer.inlineCallbacks
        def getChangesForBuild(buildid):
            assert buildid == 20
            ch = yield self.master.db.changes.getChange(13)
            return [ch]

        self.master.db.changes.getChangesForBuild = getChangesForBuild
示例#26
0
    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.assertEqual(
            buildrequest, {
                'buildrequestid': 1001,
                'complete': False,
                'waited_for': False,
                'claimed_at': None,
                'results': -1,
                'claimed': False,
                'buildsetid': 200,
                'complete_at': None,
                'submitted_at': epoch2datetime(0),
                '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.assertEqual(
            buildset, {
                'bsid': 200,
                'complete_at': None,
                'submitted_at': 0,
                'sourcestamps': None,
                'parent_buildid': None,
                'results': -1,
                'parent_relationship': None,
                'reason': 'rebuild',
                'external_idstring': 'extid',
                'complete': False
            })

        properties = yield self.master.data.get(
            ('buildsets', new_bsid, 'properties'))
        self.assertEqual(properties, {
            'prop1': ('one', 'fake1'),
            'prop2': ('two', 'fake2')
        })
示例#27
0
    def test_multiple_source_stamps_no_props(self):
        repository = 'http://test_repo'
        project = 'test_user/test_project'
        codebase1 = 'test_codebase1'
        codebase2 = 'test_codebase2'
        codebase3 = 'test_codebase3'

        self._http.expect('post',
                          '/repos/test_user/test_project/statuses/rev1',
                          json={
                              'state': 'pending',
                              'target_url':
                              'http://localhost:8080/#builders/79/builds/0',
                              'description': 'Build started.',
                              'context': 'buildbot/Builder0'
                          })
        self._http.expect('post',
                          '/repos/test_user/test_project/statuses/rev3',
                          json={
                              'state': 'pending',
                              'target_url':
                              'http://localhost:8080/#builders/79/builds/0',
                              'description': 'Build started.',
                              'context': 'buildbot/Builder0'
                          })
        self._http.expect('post',
                          '/repos/test_user/test_project/statuses/rev1',
                          json={
                              'state': 'success',
                              'target_url':
                              'http://localhost:8080/#builders/79/builds/0',
                              'description': 'Build done.',
                              'context': 'buildbot/Builder0'
                          })
        self._http.expect('post',
                          '/repos/test_user/test_project/statuses/rev3',
                          json={
                              'state': 'success',
                              'target_url':
                              'http://localhost:8080/#builders/79/builds/0',
                              'description': 'Build done.',
                              'context': 'buildbot/Builder0'
                          })
        self._http.expect('post',
                          '/repos/test_user/test_project/statuses/rev1',
                          json={
                              'state': 'success',
                              'target_url':
                              'http://localhost:8080/#builders/79/builds/0',
                              'description': 'Build done.',
                              'context': 'buildbot/Builder0'
                          })
        self._http.expect('post',
                          '/repos/test_user/test_project/statuses/rev3',
                          json={
                              'state': 'success',
                              'target_url':
                              'http://localhost:8080/#builders/79/builds/0',
                              'description': 'Build done.',
                              'context': 'buildbot/Builder0'
                          })

        # note that the first sourcestamp only has revision, second only branch and only the third
        # has both
        self.master.db.insertTestData([
            fakedb.Master(id=92),
            fakedb.Worker(id=13, name='wrk'),
            fakedb.Builder(id=79, name='Builder0'),
            fakedb.Buildset(id=98, results=SUCCESS, reason="test_reason1"),
            fakedb.BuildsetSourceStamp(buildsetid=98, sourcestampid=234),
            fakedb.BuildsetSourceStamp(buildsetid=98, sourcestampid=235),
            fakedb.BuildsetSourceStamp(buildsetid=98, sourcestampid=236),
            fakedb.SourceStamp(id=234,
                               project=project,
                               branch=None,
                               revision='rev1',
                               repository=repository,
                               codebase=codebase1),
            fakedb.SourceStamp(id=235,
                               project=project,
                               branch='branch2',
                               revision=None,
                               repository=repository,
                               codebase=codebase2),
            fakedb.SourceStamp(id=236,
                               project=project,
                               branch='branch3',
                               revision='rev3',
                               repository=repository,
                               codebase=codebase3),
            fakedb.BuildRequest(id=11, buildsetid=98, builderid=79),
            fakedb.Build(id=20,
                         number=0,
                         builderid=79,
                         buildrequestid=11,
                         workerid=13,
                         masterid=92,
                         results=SUCCESS,
                         state_string="build_text"),
            fakedb.BuildProperty(buildid=20,
                                 name="buildername",
                                 value="Builder0"),
        ])

        build = yield self.master.data.get(("builds", 20))

        build['complete'] = False
        self.sp.buildStarted(("build", 20, "started"), build)
        build['complete'] = True
        self.sp.buildFinished(("build", 20, "finished"), build)
        build['results'] = SUCCESS
        self.sp.buildFinished(("build", 20, "finished"), build)
示例#28
0
    def setup_db(self,
                 results1,
                 results2,
                 with_steps=False,
                 extra_build_properties=None):
        if extra_build_properties is None:
            extra_build_properties = {}

        self.db = self.master.db
        self.db.insertTestData([
            fakedb.Master(id=92),
            fakedb.Worker(id=13, name='wrkr'),
            fakedb.Buildset(id=98, results=results1, reason="testReason1"),
            fakedb.Buildset(id=99, results=results2, reason="testReason2"),
            fakedb.Builder(id=80, name='Builder1'),
            fakedb.BuildRequest(id=11, buildsetid=98, builderid=80),
            fakedb.BuildRequest(id=12, buildsetid=99, builderid=80),
            fakedb.Build(id=20,
                         number=0,
                         builderid=80,
                         buildrequestid=11,
                         workerid=13,
                         masterid=92,
                         results=results1),
            fakedb.Build(id=21,
                         number=1,
                         builderid=80,
                         buildrequestid=12,
                         workerid=13,
                         masterid=92,
                         results=results2),
        ])
        for build_id in (20, 21):
            self.db.insertTestData([
                fakedb.BuildProperty(buildid=build_id,
                                     name="workername",
                                     value="wrkr"),
                fakedb.BuildProperty(buildid=build_id,
                                     name="reason",
                                     value="because"),
            ])

            for name, value in extra_build_properties.items():
                self.db.insertTestData([
                    fakedb.BuildProperty(buildid=build_id,
                                         name=name,
                                         value=value),
                ])

        if with_steps:
            self.db.insertTestData([
                fakedb.Step(id=151,
                            buildid=21,
                            number=1,
                            results=SUCCESS,
                            name='first step'),
                fakedb.Step(id=152,
                            buildid=21,
                            number=2,
                            results=results2,
                            name='second step'),
                fakedb.Step(id=153,
                            buildid=21,
                            number=3,
                            results=SUCCESS,
                            name='third step'),
                fakedb.Log(id=251,
                           stepid=152,
                           name='stdio',
                           slug='stdio',
                           type='s',
                           num_lines=7),
                fakedb.Log(id=252,
                           stepid=152,
                           name='stderr',
                           slug='stderr',
                           type='s',
                           num_lines=7),
                fakedb.Log(id=253,
                           stepid=153,
                           name='stdio',
                           slug='stdio',
                           type='s',
                           num_lines=7),
            ])
示例#29
0
class Tests(interfaces.InterfaceTests):
    TIMESTAMP_STEP101 = 100000
    TIMESTAMP_STEP102 = 200000
    backgroundData = [
        fakedb.Worker(id=47, name='linux'),
        fakedb.Buildset(id=20),
        fakedb.Builder(id=88, name='b1'),
        fakedb.BuildRequest(id=41, buildsetid=20, builderid=88),
        fakedb.Master(id=88),
        fakedb.Build(id=30,
                     buildrequestid=41,
                     number=7,
                     masterid=88,
                     builderid=88,
                     workerid=47),
        fakedb.Step(id=101,
                    buildid=30,
                    number=1,
                    name='one',
                    started_at=TIMESTAMP_STEP101),
        fakedb.Step(id=102,
                    buildid=30,
                    number=2,
                    name='two',
                    started_at=TIMESTAMP_STEP102),
    ]

    testLogLines = [
        fakedb.Log(id=201,
                   stepid=101,
                   name='stdio',
                   slug='stdio',
                   complete=0,
                   num_lines=7,
                   type='s'),
        fakedb.LogChunk(logid=201,
                        first_line=0,
                        last_line=1,
                        compressed=0,
                        content=textwrap.dedent("""\
                    line zero
                    line 1""" + "x" * 200)),
        fakedb.LogChunk(logid=201,
                        first_line=2,
                        last_line=4,
                        compressed=0,
                        content=textwrap.dedent("""\
                    line TWO

                    line 2**2""")),
        fakedb.LogChunk(logid=201,
                        first_line=5,
                        last_line=5,
                        compressed=0,
                        content="another line"),
        fakedb.LogChunk(logid=201,
                        first_line=6,
                        last_line=6,
                        compressed=0,
                        content="yet another line"),
    ]
    bug3101Content = base64.b64decode("""
        PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0
        9PT09PT09PT09PT09PT09PT09PT09PT09PT09PQpbU0tJUFBFRF0Kbm90IGEgd2luMz
        IgcGxhdGZvcm0KCmJ1aWxkc2xhdmUudGVzdC51bml0LnRlc3RfcnVucHJvY2Vzcy5UZ
        XN0UnVuUHJvY2Vzcy50ZXN0UGlwZVN0cmluZwotLS0tLS0tLS0tLS0tLS0tLS0tLS0t
        LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0
        tLS0tLS0tClJhbiAyNjcgdGVzdHMgaW4gNS4zNzhzCgpQQVNTRUQgKHNraXBzPTEsIH
        N1Y2Nlc3Nlcz0yNjYpCnByb2dyYW0gZmluaXNoZWQgd2l0aCBleGl0IGNvZGUgMAplb
        GFwc2VkVGltZT04LjI0NTcwMg==""")

    bug3101Rows = [
        fakedb.Log(id=1470,
                   stepid=101,
                   name='problems',
                   slug='problems',
                   complete=1,
                   num_lines=11,
                   type='t'),
        fakedb.LogChunk(logid=1470,
                        first_line=0,
                        last_line=10,
                        compressed=0,
                        content=bug3101Content),
    ]

    @defer.inlineCallbacks
    def checkTestLogLines(self):
        expLines = [
            'line zero', 'line 1' + "x" * 200, 'line TWO', '', 'line 2**2',
            'another line', 'yet another line'
        ]
        for first_line in range(0, 7):
            for last_line in range(first_line, 7):
                got_lines = yield self.db.logs.getLogLines(
                    201, first_line, last_line)
                self.assertEqual(
                    got_lines,
                    "\n".join(expLines[first_line:last_line + 1] + [""]))
        # check overflow
        self.assertEqual((yield self.db.logs.getLogLines(201, 5, 20)),
                         "\n".join(expLines[5:7] + [""]))

    # signature tests

    def test_signature_getLog(self):
        @self.assertArgSpecMatches(self.db.logs.getLog)
        def getLog(self, logid):
            pass

    def test_signature_getLogBySlug(self):
        @self.assertArgSpecMatches(self.db.logs.getLogBySlug)
        def getLogBySlug(self, stepid, slug):
            pass

    def test_signature_getLogs(self):
        @self.assertArgSpecMatches(self.db.logs.getLogs)
        def getLogs(self, stepid=None):
            pass

    def test_signature_getLogLines(self):
        @self.assertArgSpecMatches(self.db.logs.getLogLines)
        def getLogLines(self, logid, first_line, last_line):
            pass

    def test_signature_addLog(self):
        @self.assertArgSpecMatches(self.db.logs.addLog)
        def addLog(self, stepid, name, slug, type):
            pass

    def test_signature_appendLog(self):
        @self.assertArgSpecMatches(self.db.logs.appendLog)
        def appendLog(self, logid, content):
            pass

    def test_signature_finishLog(self):
        @self.assertArgSpecMatches(self.db.logs.finishLog)
        def finishLog(self, logid):
            pass

    def test_signature_compressLog(self):
        @self.assertArgSpecMatches(self.db.logs.compressLog)
        def compressLog(self, logid, force=False):
            pass

    def test_signature_deleteOldLogChunks(self):
        @self.assertArgSpecMatches(self.db.logs.deleteOldLogChunks)
        def deleteOldLogChunks(self, older_than_timestamp):
            pass

    # method tests

    @defer.inlineCallbacks
    def test_getLog(self):
        yield self.insertTestData(self.backgroundData + [
            fakedb.Log(id=201,
                       stepid=101,
                       name='stdio',
                       slug='stdio',
                       complete=0,
                       num_lines=200,
                       type='s'),
        ])
        logdict = yield self.db.logs.getLog(201)
        validation.verifyDbDict(self, 'logdict', logdict)
        self.assertEqual(
            logdict, {
                'id': 201,
                'stepid': 101,
                'name': 'stdio',
                'slug': 'stdio',
                'complete': False,
                'num_lines': 200,
                'type': 's',
            })

    @defer.inlineCallbacks
    def test_getLog_missing(self):
        logdict = yield self.db.logs.getLog(201)
        self.assertEqual(logdict, None)

    @defer.inlineCallbacks
    def test_getLogBySlug(self):
        yield self.insertTestData(self.backgroundData + [
            fakedb.Log(id=201,
                       stepid=101,
                       name='stdio',
                       slug='stdio',
                       complete=0,
                       num_lines=200,
                       type='s'),
            fakedb.Log(id=202,
                       stepid=101,
                       name='dbg.log',
                       slug='dbg_log',
                       complete=1,
                       num_lines=200,
                       type='s'),
        ])
        logdict = yield self.db.logs.getLogBySlug(101, 'dbg_log')
        validation.verifyDbDict(self, 'logdict', logdict)
        self.assertEqual(logdict['id'], 202)

    @defer.inlineCallbacks
    def test_getLogBySlug_missing(self):
        yield self.insertTestData(self.backgroundData + [
            fakedb.Log(id=201,
                       stepid=101,
                       name='stdio',
                       slug='stdio',
                       complete=0,
                       num_lines=200,
                       type='s'),
        ])
        logdict = yield self.db.logs.getLogBySlug(102, 'stdio')
        self.assertEqual(logdict, None)

    @defer.inlineCallbacks
    def test_getLogs(self):
        yield self.insertTestData(self.backgroundData + [
            fakedb.Log(id=201,
                       stepid=101,
                       name='stdio',
                       slug='stdio',
                       complete=0,
                       num_lines=200,
                       type='s'),
            fakedb.Log(id=202,
                       stepid=101,
                       name='dbg.log',
                       slug='dbg_log',
                       complete=1,
                       num_lines=300,
                       type='t'),
            fakedb.Log(id=203,
                       stepid=102,
                       name='stdio',
                       slug='stdio',
                       complete=0,
                       num_lines=200,
                       type='s'),
        ])
        logdicts = yield self.db.logs.getLogs(101)
        for logdict in logdicts:
            validation.verifyDbDict(self, 'logdict', logdict)
        self.assertEqual(sorted([ld['id'] for ld in logdicts]), [201, 202])

    @defer.inlineCallbacks
    def test_getLogLines(self):
        yield self.insertTestData(self.backgroundData + self.testLogLines)
        yield self.checkTestLogLines()

        # check line number reversal
        self.assertEqual((yield self.db.logs.getLogLines(201, 6, 3)), '')

    @defer.inlineCallbacks
    def test_getLogLines_empty(self):
        yield self.insertTestData(self.backgroundData + [
            fakedb.Log(id=201,
                       stepid=101,
                       name='stdio',
                       slug='stdio',
                       complete=0,
                       num_lines=200,
                       type='s'),
        ])
        self.assertEqual((yield self.db.logs.getLogLines(201, 9, 99)), '')
        self.assertEqual((yield self.db.logs.getLogLines(999, 9, 99)), '')

    @defer.inlineCallbacks
    def test_getLogLines_bug3101(self):
        # regression test for #3101
        content = self.bug3101Content
        yield self.insertTestData(self.backgroundData + self.bug3101Rows)
        # overall content is the same, with '\n' padding at the end
        expected = bytes2unicode(self.bug3101Content + b'\n')
        self.assertEqual((yield self.db.logs.getLogLines(1470, 0, 99)),
                         expected)
        # try to fetch just one line
        expected = bytes2unicode(content.split(b'\n')[0] + b'\n')
        self.assertEqual((yield self.db.logs.getLogLines(1470, 0, 0)),
                         expected)

    @defer.inlineCallbacks
    def test_addLog_getLog(self):
        yield self.insertTestData(self.backgroundData)
        logid = yield self.db.logs.addLog(stepid=101,
                                          name='config.log',
                                          slug='config_log',
                                          type='t')
        logdict = yield self.db.logs.getLog(logid)
        validation.verifyDbDict(self, 'logdict', logdict)
        self.assertEqual(
            logdict, {
                'id': logid,
                'stepid': 101,
                'name': 'config.log',
                'slug': 'config_log',
                'complete': False,
                'num_lines': 0,
                'type': 't',
            })

    @defer.inlineCallbacks
    def test_appendLog_getLogLines(self):
        yield self.insertTestData(self.backgroundData + self.testLogLines)
        logid = yield self.db.logs.addLog(stepid=102,
                                          name='another',
                                          slug='another',
                                          type='s')
        self.assertEqual((yield self.db.logs.appendLog(logid, 'xyz\n')),
                         (0, 0))
        self.assertEqual((yield self.db.logs.appendLog(201, 'abc\ndef\n')),
                         (7, 8))
        self.assertEqual((yield self.db.logs.appendLog(logid, 'XYZ\n')),
                         (1, 1))
        self.assertEqual((yield self.db.logs.getLogLines(201, 6, 7)),
                         "yet another line\nabc\n")
        self.assertEqual((yield self.db.logs.getLogLines(201, 7, 8)),
                         "abc\ndef\n")
        self.assertEqual((yield self.db.logs.getLogLines(201, 8, 8)), "def\n")
        self.assertEqual((yield self.db.logs.getLogLines(logid, 0, 1)),
                         "xyz\nXYZ\n")
        self.assertEqual(
            (yield self.db.logs.getLog(logid)), {
                'complete': False,
                'id': logid,
                'name': 'another',
                'slug': 'another',
                'num_lines': 2,
                'stepid': 102,
                'type': 's',
            })

    @defer.inlineCallbacks
    def test_compressLog(self):
        yield self.insertTestData(self.backgroundData + self.testLogLines)
        yield self.db.logs.compressLog(201)
        # test log lines should still be readable just the same
        yield self.checkTestLogLines()

    @defer.inlineCallbacks
    def test_addLogLines_big_chunk(self):
        yield self.insertTestData(self.backgroundData + self.testLogLines)
        self.assertEqual(
            (yield self.db.logs.appendLog(201, 'abc\n' * 20000)),  # 80k
            (7, 20006))
        lines = yield self.db.logs.getLogLines(201, 7, 50000)
        self.assertEqual(len(lines), 80000)
        self.assertEqual(lines, ('abc\n' * 20000))

    @defer.inlineCallbacks
    def test_addLogLines_big_chunk_big_lines(self):
        yield self.insertTestData(self.backgroundData + self.testLogLines)
        line = 'x' * 33000 + '\n'
        self.assertEqual((yield self.db.logs.appendLog(201, line * 3)),
                         (7, 9))  # three long lines, all truncated
        lines = yield self.db.logs.getLogLines(201, 7, 100)
        self.assertEqual(len(lines), 99003)
        self.assertEqual(lines, (line * 3))
示例#30
0
class Tests(interfaces.InterfaceTests):

    # common sample data

    backgroundData = [
        fakedb.Buildset(id=20),
        fakedb.Builder(id=77, name="b1"),
        fakedb.Builder(id=88, name="b2"),
        fakedb.BuildRequest(id=40, buildsetid=20, builderid=77),
        fakedb.BuildRequest(id=41, buildsetid=20, builderid=77),
        fakedb.BuildRequest(id=42, buildsetid=20, builderid=88),
        fakedb.Master(id=88),
        fakedb.Master(id=89, name="bar"),
        fakedb.Worker(id=13, name='wrk'),
        fakedb.Worker(id=12, name='sl2'),
    ]

    threeBuilds = [
        fakedb.Build(id=50, buildrequestid=42, number=5, masterid=88,
                     builderid=77, workerid=13, state_string="build 5",
                     started_at=TIME1),
        fakedb.Build(id=51, buildrequestid=41, number=6, masterid=88,
                     builderid=88, workerid=13, state_string="build 6",
                     started_at=TIME2),
        fakedb.Build(id=52, buildrequestid=42, number=7, masterid=88,
                     builderid=77, workerid=12, state_string="build 7",
                     started_at=TIME3, complete_at=TIME4, results=5),
    ]

    threeBdicts = {
        50: {'id': 50, 'buildrequestid': 42, 'builderid': 77,
             'masterid': 88, 'number': 5, 'workerid': 13,
             'started_at': epoch2datetime(TIME1),
             'complete_at': None, 'state_string': 'build 5',
             'results': None},
        51: {'id': 51, 'buildrequestid': 41, 'builderid': 88,
             'masterid': 88, 'number': 6, 'workerid': 13,
             'started_at': epoch2datetime(TIME2),
             'complete_at': None, 'state_string': 'build 6',
             'results': None},
        52: {'id': 52, 'buildrequestid': 42, 'builderid': 77,
             'masterid': 88, 'number': 7, 'workerid': 12,
             'started_at': epoch2datetime(TIME3),
             'complete_at': epoch2datetime(TIME4),
             'state_string': 'build 7',
             'results': 5},
    }

    # signature tests

    def test_signature_getBuild(self):
        @self.assertArgSpecMatches(self.db.builds.getBuild)
        def getBuild(self, buildid):
            pass

    def test_signature_getBuildByNumber(self):
        @self.assertArgSpecMatches(self.db.builds.getBuildByNumber)
        def getBuild(self, builderid, number):
            pass

    def test_signature_getBuilds(self):
        @self.assertArgSpecMatches(self.db.builds.getBuilds)
        def getBuilds(self, builderid=None, buildrequestid=None, workerid=None,
                      complete=None, resultSpec=None):
            pass

    def test_signature_addBuild(self):
        @self.assertArgSpecMatches(self.db.builds.addBuild)
        def addBuild(self, builderid, buildrequestid, workerid, masterid,
                     state_string):
            pass

    def test_signature_setBuildStateString(self):
        @self.assertArgSpecMatches(self.db.builds.setBuildStateString)
        def setBuildStateString(self, buildid, state_string):
            pass

    def test_signature_finishBuild(self):
        @self.assertArgSpecMatches(self.db.builds.finishBuild)
        def finishBuild(self, buildid, results):
            pass

    def test_signature_getBuildProperties(self):
        @self.assertArgSpecMatches(self.db.builds.getBuildProperties)
        def getBuildProperties(self, bid):
            pass

    def test_signature_setBuildProperty(self):
        @self.assertArgSpecMatches(self.db.builds.setBuildProperty)
        def setBuildProperty(self, bid, name, value, source):
            pass

    # method tests

    @defer.inlineCallbacks
    def test_getBuild(self):
        yield self.insertTestData(self.backgroundData + [self.threeBuilds[0]])
        bdict = yield self.db.builds.getBuild(50)
        validation.verifyDbDict(self, 'dbbuilddict', bdict)
        self.assertEqual(bdict, dict(id=50, number=5, buildrequestid=42,
                                     masterid=88, builderid=77, workerid=13,
                                     started_at=epoch2datetime(TIME1), complete_at=None,
                                     state_string='build 5', results=None))

    @defer.inlineCallbacks
    def test_getBuild_missing(self):
        bdict = yield self.db.builds.getBuild(50)
        self.assertEqual(bdict, None)

    @defer.inlineCallbacks
    def test_getBuildByNumber(self):
        yield self.insertTestData(self.backgroundData + [self.threeBuilds[0]])
        bdict = yield self.db.builds.getBuildByNumber(builderid=77, number=5)
        validation.verifyDbDict(self, 'dbbuilddict', bdict)
        self.assertEqual(bdict['id'], 50)

    @defer.inlineCallbacks
    def test_getBuilds(self):
        yield self.insertTestData(self.backgroundData + self.threeBuilds)
        bdicts = yield self.db.builds.getBuilds()
        for bdict in bdicts:
            validation.verifyDbDict(self, 'dbbuilddict', bdict)
        self.assertEqual(sorted(bdicts, key=lambda bd: bd['id']),
                         [self.threeBdicts[50], self.threeBdicts[51],
                          self.threeBdicts[52]])

    @defer.inlineCallbacks
    def test_getBuilds_builderid(self):
        yield self.insertTestData(self.backgroundData + self.threeBuilds)
        bdicts = yield self.db.builds.getBuilds(builderid=88)
        for bdict in bdicts:
            validation.verifyDbDict(self, 'dbbuilddict', bdict)
        self.assertEqual(sorted(bdicts, key=lambda bd: bd['id']),
                         [self.threeBdicts[51]])

    @defer.inlineCallbacks
    def test_getBuilds_buildrequestid(self):
        yield self.insertTestData(self.backgroundData + self.threeBuilds)
        bdicts = yield self.db.builds.getBuilds(buildrequestid=42)
        for bdict in bdicts:
            validation.verifyDbDict(self, 'dbbuilddict', bdict)
        self.assertEqual(sorted(bdicts, key=lambda bd: bd['id']),
                         [self.threeBdicts[50], self.threeBdicts[52]])

    @defer.inlineCallbacks
    def test_getBuilds_workerid(self):
        yield self.insertTestData(self.backgroundData + self.threeBuilds)
        bdicts = yield self.db.builds.getBuilds(workerid=13)
        for bdict in bdicts:
            validation.verifyDbDict(self, 'dbbuilddict', bdict)
        self.assertEqual(sorted(bdicts, key=lambda bd: bd['id']),
                         [self.threeBdicts[50], self.threeBdicts[51]])

    def test_signature_getBuildsForChange(self):
        @self.assertArgSpecMatches(self.db.builds.getBuildsForChange)
        def getBuildsForChange(self, changeid):
            pass

    @defer.inlineCallbacks
    def do_test_getBuildsForChange(self, rows, changeid, expected):
        yield self.insertTestData(rows)

        builds = yield self.db.builds.getBuildsForChange(changeid)

        self.assertEqual(sorted(builds), sorted(expected))

    def test_getBuildsForChange_OneCodebase(self):
        rows = [fakedb.Master(id=88, name="bar"),
                fakedb.Worker(id=13, name='one'),
                fakedb.Builder(id=77, name='A'),
                fakedb.SourceStamp(id=234, created_at=CREATED_AT,
                                   revision="aaa"),
                fakedb.Change(changeid=14, codebase='A', sourcestampid=234),
                fakedb.Buildset(id=30, reason='foo',
                                submitted_at=1300305712, results=1),
                fakedb.BuildsetSourceStamp(sourcestampid=234, buildsetid=30),
                fakedb.BuildRequest(id=19, buildsetid=30, builderid=77,
                                    priority=13, submitted_at=1300305712, results=1,
                                    complete=0, complete_at=None),
                fakedb.Build(id=50, buildrequestid=19, number=5, masterid=88,
                             builderid=77, state_string="test", workerid=13,
                             started_at=1304262222, results=1), ]

        expected = [{
            'id': 50,
            'number': 5,
            'builderid': 77,
            'buildrequestid': 19,
            'workerid': 13,
            'masterid': 88,
            'started_at': epoch2datetime(1304262222),
            'complete_at': None,
            'state_string': 'test',
            'results': 1}]

        return self.do_test_getBuildsForChange(rows, 14, expected)

    @defer.inlineCallbacks
    def test_getBuilds_complete(self):
        yield self.insertTestData(self.backgroundData + self.threeBuilds)
        bdicts = yield self.db.builds.getBuilds(complete=True)
        for bdict in bdicts:
            validation.verifyDbDict(self, 'dbbuilddict', bdict)
        self.assertEqual(sorted(bdicts, key=lambda bd: bd['id']),
                         [self.threeBdicts[52]])

    @defer.inlineCallbacks
    def test_addBuild_first(self):
        self.reactor.advance(TIME1)
        yield self.insertTestData(self.backgroundData)
        id, number = yield self.db.builds.addBuild(builderid=77,
                                                   buildrequestid=41,
                                                   workerid=13, masterid=88,
                                                   state_string='test test2')
        bdict = yield self.db.builds.getBuild(id)
        validation.verifyDbDict(self, 'dbbuilddict', bdict)
        self.assertEqual(bdict, {'buildrequestid': 41, 'builderid': 77,
                                 'id': id, 'masterid': 88, 'number': number, 'workerid': 13,
                                 'started_at': epoch2datetime(TIME1),
                                 'complete_at': None, 'state_string': 'test test2',
                                 'results': None})

    @defer.inlineCallbacks
    def test_addBuild_existing(self):
        self.reactor.advance(TIME1)
        yield self.insertTestData(self.backgroundData + [
            fakedb.Build(number=10, buildrequestid=41, builderid=77,
                         masterid=88, workerid=13),
        ])
        id, number = yield self.db.builds.addBuild(builderid=77,
                                                   buildrequestid=41,
                                                   workerid=13, masterid=88,
                                                   state_string='test test2')
        bdict = yield self.db.builds.getBuild(id)
        validation.verifyDbDict(self, 'dbbuilddict', bdict)
        self.assertEqual(number, 11)
        self.assertEqual(bdict, {'buildrequestid': 41, 'builderid': 77,
                                 'id': id, 'masterid': 88, 'number': number, 'workerid': 13,
                                 'started_at': epoch2datetime(TIME1),
                                 'complete_at': None, 'state_string': 'test test2',
                                 'results': None})

    @defer.inlineCallbacks
    def test_setBuildStateString(self):
        yield self.insertTestData(self.backgroundData + [self.threeBuilds[0]])
        yield self.db.builds.setBuildStateString(buildid=50,
                                                 state_string='test test2')
        bdict = yield self.db.builds.getBuild(50)
        validation.verifyDbDict(self, 'dbbuilddict', bdict)
        self.assertEqual(bdict, dict(id=50, number=5, buildrequestid=42,
                                     masterid=88, builderid=77, workerid=13,
                                     started_at=epoch2datetime(TIME1), complete_at=None,
                                     state_string='test test2', results=None))

    @defer.inlineCallbacks
    def test_finishBuild(self):
        self.reactor.advance(TIME4)
        yield self.insertTestData(self.backgroundData + [self.threeBuilds[0]])
        yield self.db.builds.finishBuild(buildid=50, results=7)
        bdict = yield self.db.builds.getBuild(50)
        validation.verifyDbDict(self, 'dbbuilddict', bdict)
        self.assertEqual(bdict, dict(id=50, number=5, buildrequestid=42,
                                     masterid=88, builderid=77, workerid=13,
                                     started_at=epoch2datetime(TIME1),
                                     complete_at=epoch2datetime(TIME4),
                                     state_string='build 5',
                                     results=7))

    @defer.inlineCallbacks
    def testgetBuildPropertiesEmpty(self):
        yield self.insertTestData(self.backgroundData + self.threeBuilds)
        for buildid in (50, 51, 52):
            props = yield self.db.builds.getBuildProperties(buildid)
            self.assertEqual(0, len(props))

    @defer.inlineCallbacks
    def testsetandgetProperties(self):
        yield self.insertTestData(self.backgroundData + self.threeBuilds)
        yield self.db.builds.setBuildProperty(50, 'prop', 42, 'test')
        props = yield self.db.builds.getBuildProperties(50)
        self.assertEqual(props, {'prop': (42, 'test')})

    @defer.inlineCallbacks
    def testsetgetsetProperties(self):
        yield self.insertTestData(self.backgroundData + self.threeBuilds)
        props = yield self.db.builds.getBuildProperties(50)
        self.assertEqual(props, {})
        yield self.db.builds.setBuildProperty(50, 'prop', 42, 'test')
        props = yield self.db.builds.getBuildProperties(50)
        self.assertEqual(props, {'prop': (42, 'test')})
        # set a new value
        yield self.db.builds.setBuildProperty(50, 'prop', 45, 'test')
        props = yield self.db.builds.getBuildProperties(50)
        self.assertEqual(props, {'prop': (45, 'test')})
        # set a new source
        yield self.db.builds.setBuildProperty(50, 'prop', 45, 'test_source')
        props = yield self.db.builds.getBuildProperties(50)
        self.assertEqual(props, {'prop': (45, 'test_source')})
        # set the same
        yield self.db.builds.setBuildProperty(50, 'prop', 45, 'test_source')
        props = yield self.db.builds.getBuildProperties(50)
        self.assertEqual(props, {'prop': (45, 'test_source')})