示例#1
0
 def setUp(self):
     self.setUpEndpoint()
     self.db.insertTestData([
         fakedb.Builder(id=77),
         fakedb.Master(id=88),
         fakedb.Worker(id=13, name='sl'),
         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=5, name='make'),
         fakedb.Log(id=60,
                    stepid=50,
                    name=u'stdio',
                    slug=u'stdio',
                    type='s'),
         fakedb.Log(id=61,
                    stepid=50,
                    name=u'errors',
                    slug=u'errors',
                    type='t'),
     ])
示例#2
0
 def test_getLogs(self):
     yield self.insertTestData(self.backgroundData + [
         fakedb.Log(id=201,
                    stepid=101,
                    name=u'stdio',
                    slug=u'stdio',
                    complete=0,
                    num_lines=200,
                    type=u's'),
         fakedb.Log(id=202,
                    stepid=101,
                    name=u'dbg.log',
                    slug=u'dbg_log',
                    complete=1,
                    num_lines=300,
                    type=u't'),
         fakedb.Log(id=203,
                    stepid=102,
                    name=u'stdio',
                    slug=u'stdio',
                    complete=0,
                    num_lines=200,
                    type=u'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])
示例#3
0
 def test_getLogBySlug(self):
     yield self.insertTestData(self.backgroundData + [
         fakedb.Log(id=201, stepid=101, name=u'stdio', slug=u'stdio',
                    complete=0, num_lines=200, type=u's'),
         fakedb.Log(id=202, stepid=101, name=u'dbg.log', slug=u'dbg_log',
                    complete=1, num_lines=200, type=u's'),
     ])
     logdict = yield self.db.logs.getLogBySlug(101, u'dbg_log')
     validation.verifyDbDict(self, 'logdict', logdict)
     self.assertEqual(logdict['id'], 202)
示例#4
0
 def test_getLogLines_empty(self):
     yield self.insertTestData(self.backgroundData + [
         fakedb.Log(id=201, stepid=101, name=u'stdio', slug=u'stdio',
                    complete=0, num_lines=200, type=u's'),
     ])
     self.assertEqual((yield self.db.logs.getLogLines(201, 9, 99)), '')
     self.assertEqual((yield self.db.logs.getLogLines(999, 9, 99)), '')
示例#5
0
    def setupDb(self, current, previous):
        super().setupDb(current, previous)

        job = self.load_fixture('crossbow-job.yaml')

        self.db.insertTestData([
            fakedb.Step(id=50, buildid=21, number=0, name='compile'),
            fakedb.Step(id=51,
                        buildid=21,
                        number=1,
                        name='benchmark',
                        results=current),
            fakedb.Log(id=60,
                       stepid=51,
                       name='result',
                       slug='result',
                       type='t',
                       num_lines=len(job)),
            fakedb.LogChunk(logid=60,
                            first_line=0,
                            last_line=len(job),
                            compressed=0,
                            content=job)
        ])
        for _id in (20, 21):
            self.db.insertTestData([
                fakedb.BuildProperty(buildid=_id,
                                     name='crossbow_repo',
                                     value='ursa-labs/crossbow')
            ])
示例#6
0
    def do_addLogLines_huge_log(self, NUM_CHUNKS=3000, chunk=('xy' * 70 + '\n') * 3):
        if chunk.endswith("\n"):
            chunk = chunk[:-1]
        linesperchunk = chunk.count("\n") + 1
        test_data = [
            fakedb.LogChunk(logid=201, first_line=i * linesperchunk,
                            last_line=i * linesperchunk + linesperchunk - 1, compressed=0,
                            content=chunk)
            for i in range(NUM_CHUNKS)
        ]
        yield self.insertTestData(
            self.backgroundData + [
                fakedb.Log(id=201, stepid=101, name='stdio', slug='stdio',
                           complete=0, num_lines=NUM_CHUNKS * 3, type='s')] +
            test_data)
        wholeLog = yield self.db.logs.getLogLines(201, 0, NUM_CHUNKS * 3)
        for i in range(10):
            yield self.db.logs.compressLog(201)
            wholeLog2 = yield self.db.logs.getLogLines(201, 0, NUM_CHUNKS * 3)
            self.assertEqual(wholeLog, wholeLog2)
        self.assertEqual(wholeLog, wholeLog2)

        def countChunk(conn):
            tbl = self.db.model.logchunks
            q = sa.select([sa.func.count(tbl.c.content)])
            q = q.where(tbl.c.logid == 201)
            return conn.execute(q).fetchone()[0]

        chunks = yield self.db.pool.do(countChunk)
        # make sure MAX_CHUNK_LINES is taken in account
        self.assertGreaterEqual(
            chunks, NUM_CHUNKS * linesperchunk / logs.LogsConnectorComponent.MAX_CHUNK_LINES)
示例#7
0
 def insertTestData(self, buildResults, finalResult):
     self.db = self.master.db
     self.db.insertTestData([
         fakedb.Master(id=92),
         fakedb.Worker(id=13, name='sl'),
         fakedb.Builder(id=79, name='Builder0'),
         fakedb.Builder(id=80, name='Builder1'),
         fakedb.Buildset(id=98, results=finalResult, reason="testReason1"),
         fakedb.BuildsetSourceStamp(buildsetid=98, sourcestampid=234),
         fakedb.SourceStamp(id=234,
                            project=self.TEST_PROJECT,
                            revision=self.TEST_REVISION,
                            repository=self.TEST_REPO),
         fakedb.Change(changeid=13, branch=u'master', revision=u'9283', author='me@foo',
                       repository=self.TEST_REPO, codebase=u'cbgerrit',
                       project=u'world-domination', sourcestampid=234),
     ])
     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=u"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=u'Unicode log with non-ascii (\u00E5\u00E4\u00F6).'),
             fakedb.BuildProperty(buildid=20 + i, name="workername", value="sl"),
             fakedb.BuildProperty(buildid=20 + i, name="reason", value="because"),
         ])
         for k, v in iteritems(self.TEST_PROPS):
             self.db.insertTestData([
                 fakedb.BuildProperty(buildid=20 + i, name=k, value=v)
             ])
示例#8
0
 def test_getLogBySlug_missing(self):
     yield self.insertTestData(self.backgroundData + [
         fakedb.Log(id=201, stepid=101, name=u'stdio', slug=u'stdio',
                    complete=0, num_lines=200, type=u's'),
     ])
     logdict = yield self.db.logs.getLogBySlug(102, u'stdio')
     self.assertEqual(logdict, None)
示例#9
0
    def setupDb(self, current, previous):
        # License note:
        #    Copied from the original buildbot implementation with
        #    minor changes and additions.
        super().setupDb(current, previous)

        log1 = self.load_fixture('archery-benchmark-diff.jsonl')
        log2 = self.load_fixture('archery-benchmark-diff-empty-lines.jsonl')

        self.db.insertTestData([
            fakedb.Step(id=50, buildid=21, number=0, name='compile'),
            fakedb.Step(id=51,
                        buildid=21,
                        number=1,
                        name='benchmark',
                        results=current),
            fakedb.Step(id=52, buildid=20, number=0, name='compile'),
            fakedb.Step(id=53,
                        buildid=20,
                        number=1,
                        name='benchmark',
                        results=current),
            fakedb.Log(id=60,
                       stepid=51,
                       name='result',
                       slug='result',
                       type='t',
                       num_lines=4),
            fakedb.Log(id=61,
                       stepid=53,
                       name='result',
                       slug='result',
                       type='t',
                       num_lines=6),
            fakedb.LogChunk(logid=60,
                            first_line=0,
                            last_line=4,
                            compressed=0,
                            content=log1),
            fakedb.LogChunk(logid=61,
                            first_line=0,
                            last_line=6,
                            compressed=0,
                            content=log2)
        ])
示例#10
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'),
     ])
示例#11
0
    def setupDb(self, current, previous):
        super().setupDb(current, previous)

        log1 = self.load_fixture('archery-benchmark-diff.jsonl')
        log2 = self.load_fixture('archery-benchmark-diff-empty-lines.jsonl')

        self.db.insertTestData([
            fakedb.Step(id=50, buildid=21, number=0, name='compile'),
            fakedb.Step(id=51,
                        buildid=21,
                        number=1,
                        name='benchmark',
                        results=current),
            fakedb.Step(id=52, buildid=20, number=0, name='compile'),
            fakedb.Step(id=53,
                        buildid=20,
                        number=1,
                        name='benchmark',
                        results=current),
            fakedb.Log(id=60,
                       stepid=51,
                       name='result',
                       slug='result',
                       type='t',
                       num_lines=4),
            fakedb.Log(id=61,
                       stepid=53,
                       name='result',
                       slug='result',
                       type='t',
                       num_lines=6),
            fakedb.LogChunk(logid=60,
                            first_line=0,
                            last_line=4,
                            compressed=0,
                            content=log1),
            fakedb.LogChunk(logid=61,
                            first_line=0,
                            last_line=6,
                            compressed=0,
                            content=log2)
        ])
示例#12
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=u'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='%s._masterDeactivated' % 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)),
        ])
示例#13
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.Builder(id=80, name='Builder1'),
            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.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.BuildsetSourceStamp(buildsetid=98, sourcestampid=234),
            fakedb.SourceStamp(id=234),
            fakedb.Change(changeid=13, branch=u'trunk', revision=u'9283', author='me@foo',
                          repository=u'svn://...', codebase=u'cbsvn',
                          project=u'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)
            defer.returnValue([ch])

        self.master.db.changes.getChangesForBuild = getChangesForBuild
示例#14
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=98, results=results, reason="testReason1"),
            fakedb.Builder(id=80, name='Builder1'),
            fakedb.BuildRequest(id=11, buildsetid=98, builderid=80),
            fakedb.Build(id=20, number=0, 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=u'trunk', revision=u'9283', author='me@foo',
                          repository=u'svn://...', codebase=u'cbsvn',
                          project=u'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=u'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)
            defer.returnValue([ch])

        self.master.db.changes.getChangesForBuild = getChangesForBuild
        defer.returnValue((buildset, builds))
示例#15
0
 def setUp(self):
     self.setUpEndpoint()
     self.db.insertTestData([
         fakedb.Builder(id=77),
         fakedb.Worker(id=13, name='sl'),
         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="%08d" % i)
         for i in range(100)
     ] + [
         fakedb.Log(id=62, stepid=50, name='notes', slug='notes', type='t',
                    num_lines=0),
         # logid 62 is empty
     ])
示例#16
0
 def test_compressLog_empty_log(self):
     yield self.insertTestData(self.backgroundData + [
         fakedb.Log(id=201, stepid=101, name='stdio', slug='stdio',
                    complete=1, num_lines=0, type='s'),
     ])
     yield self.db.logs.compressLog(201)
     logdict = yield self.db.logs.getLog(201)
     self.assertEqual(logdict, {
         'stepid': 101,
         'num_lines': 0,
         'name': 'stdio',
         'id': 201,
         'type': 's',
         'slug': 'stdio',
         'complete': True})
示例#17
0
    def setupBuildResults(self, buildResults, finalResult):
        # 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='sl'),
            fakedb.Builder(id=79, name='Builder0'),
            fakedb.Builder(id=80, name='Builder1'),
            fakedb.Buildset(id=98, results=finalResult, reason="testReason1"),
            fakedb.BuildsetSourceStamp(buildsetid=98, sourcestampid=234),
            fakedb.SourceStamp(id=234),
            fakedb.Change(changeid=13, branch=u'master', revision=u'9283', author='me@foo',
                          repository=u'https://...', codebase=u'cbgerrit',
                          project=u'world-domination', sourcestampid=234),
        ])
        i = 0
        for results in 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=u"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=u'Unicode log with non-ascii (\u00E5\u00E4\u00F6).'),
                fakedb.BuildProperty(buildid=20 + i, name="workername", value="sl"),
                fakedb.BuildProperty(buildid=20 + i, name="reason", value="because"),
            ])
            for k, v in iteritems(self.TEST_PROPS):
                self.db.insertTestData([
                    fakedb.BuildProperty(buildid=20 + i, name=k, value=v)
                    ])
            i += 1
        res = yield utils.getDetailsForBuildset(self.master, 98, wantProperties=True)
        builds = res['builds']
        buildset = res['buildset']

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

        self.master.db.changes.getChangesForBuild = getChangesForBuild
        defer.returnValue((buildset, builds))
示例#18
0
 def test_getLog(self):
     yield self.insertTestData(self.backgroundData + [
         fakedb.Log(id=201, stepid=101, name=u'stdio', slug=u'stdio',
                    complete=0, num_lines=200, type=u's'),
     ])
     logdict = yield self.db.logs.getLog(201)
     validation.verifyDbDict(self, 'logdict', logdict)
     self.assertEqual(logdict, {
         'id': 201,
         'stepid': 101,
         'name': u'stdio',
         'slug': u'stdio',
         'complete': False,
         'num_lines': 200,
         'type': 's',
     })
示例#19
0
class Tests(interfaces.InterfaceTests):

    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'),
        fakedb.Step(id=102, buildid=30, number=2, name='two'),
    ]

    testLogLines = [
        fakedb.Log(id=201,
                   stepid=101,
                   name=u'stdio',
                   slug=u'stdio',
                   complete=0,
                   num_lines=7,
                   type=u'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=u'problems',
                   slug=u'problems',
                   complete=1,
                   num_lines=11,
                   type=u'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

    # method tests

    @defer.inlineCallbacks
    def test_getLog(self):
        yield self.insertTestData(self.backgroundData + [
            fakedb.Log(id=201,
                       stepid=101,
                       name=u'stdio',
                       slug=u'stdio',
                       complete=0,
                       num_lines=200,
                       type=u's'),
        ])
        logdict = yield self.db.logs.getLog(201)
        validation.verifyDbDict(self, 'logdict', logdict)
        self.assertEqual(
            logdict, {
                'id': 201,
                'stepid': 101,
                'name': u'stdio',
                'slug': u'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=u'stdio',
                       slug=u'stdio',
                       complete=0,
                       num_lines=200,
                       type=u's'),
            fakedb.Log(id=202,
                       stepid=101,
                       name=u'dbg.log',
                       slug=u'dbg_log',
                       complete=1,
                       num_lines=200,
                       type=u's'),
        ])
        logdict = yield self.db.logs.getLogBySlug(101, u'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=u'stdio',
                       slug=u'stdio',
                       complete=0,
                       num_lines=200,
                       type=u's'),
        ])
        logdict = yield self.db.logs.getLogBySlug(102, u'stdio')
        self.assertEqual(logdict, None)

    @defer.inlineCallbacks
    def test_getLogs(self):
        yield self.insertTestData(self.backgroundData + [
            fakedb.Log(id=201,
                       stepid=101,
                       name=u'stdio',
                       slug=u'stdio',
                       complete=0,
                       num_lines=200,
                       type=u's'),
            fakedb.Log(id=202,
                       stepid=101,
                       name=u'dbg.log',
                       slug=u'dbg_log',
                       complete=1,
                       num_lines=300,
                       type=u't'),
            fakedb.Log(id=203,
                       stepid=102,
                       name=u'stdio',
                       slug=u'stdio',
                       complete=0,
                       num_lines=200,
                       type=u'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=u'stdio',
                       slug=u'stdio',
                       complete=0,
                       num_lines=200,
                       type=u'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 = bytes2NativeString(self.bug3101Content + b'\n')
        self.assertEqual((yield self.db.logs.getLogLines(1470, 0, 99)),
                         expected)
        # try to fetch just one line
        expected = bytes2NativeString(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=u'config.log',
                                          slug=u'config_log',
                                          type=u't')
        logdict = yield self.db.logs.getLog(logid)
        validation.verifyDbDict(self, 'logdict', logdict)
        self.assertEqual(
            logdict, {
                'id': logid,
                'stepid': 101,
                'name': u'config.log',
                'slug': u'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=u'another',
                                          slug=u'another',
                                          type=u's')
        self.assertEqual((yield self.db.logs.appendLog(logid, u'xyz\n')),
                         (0, 0))
        self.assertEqual((yield self.db.logs.appendLog(201, u'abc\ndef\n')),
                         (7, 8))
        self.assertEqual((yield self.db.logs.appendLog(logid, u'XYZ\n')),
                         (1, 1))
        self.assertEqual((yield self.db.logs.getLogLines(201, 6, 7)),
                         u"yet another line\nabc\n")
        self.assertEqual((yield self.db.logs.getLogLines(201, 7, 8)),
                         u"abc\ndef\n")
        self.assertEqual((yield self.db.logs.getLogLines(201, 8, 8)), u"def\n")
        self.assertEqual((yield self.db.logs.getLogLines(logid, 0, 1)),
                         u"xyz\nXYZ\n")
        self.assertEqual(
            (yield self.db.logs.getLog(logid)), {
                'complete': False,
                'id': logid,
                'name': u'another',
                'slug': u'another',
                'num_lines': 2,
                'stepid': 102,
                'type': u'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, u'abc\n' * 20000)),  # 80k
            (7, 20006))
        lines = yield self.db.logs.getLogLines(201, 7, 50000)
        self.assertEqual(len(lines), 80000)
        self.assertEqual(lines, (u'abc\n' * 20000))

    @defer.inlineCallbacks
    def test_addLogLines_big_chunk_big_lines(self):
        yield self.insertTestData(self.backgroundData + self.testLogLines)
        line = u'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))
示例#20
0
    def setupDb(self, current, previous, log1=None, log2=None):
        # License note:
        #    Copied from the original buildbot implementation with
        #    minor changes and additions.
        super().setupDb(current, previous)

        self.db.insertTestData([
            fakedb.Step(id=50, buildid=21, number=0, name='Compile'),
            fakedb.Step(id=51,
                        buildid=21,
                        number=1,
                        name='Benchmark',
                        results=current,
                        state_string='/bin/run-benchmark'),
            fakedb.Step(id=52, buildid=20, number=0, name='Compile'),
            fakedb.Step(id=53,
                        buildid=20,
                        number=1,
                        name='Benchmark',
                        results=current,
                        state_string='/bin/run-benchmark')
        ])

        if current == SUCCESS:
            self.db.insertTestData([
                fakedb.Log(id=60,
                           stepid=51,
                           name='stdio',
                           slug='stdio',
                           type='s',
                           num_lines=len(log1)),
                fakedb.Log(id=61,
                           stepid=53,
                           name='stdio',
                           slug='stdio',
                           type='s',
                           num_lines=len(log2)),
                fakedb.LogChunk(logid=60,
                                first_line=0,
                                last_line=4,
                                compressed=0,
                                content='\n'.join(log1)),
                fakedb.LogChunk(logid=61,
                                first_line=0,
                                last_line=6,
                                compressed=0,
                                content='\n'.join(log2))
            ])
        elif current == FAILURE:
            self.db.insertTestData([
                fakedb.Log(id=60,
                           stepid=51,
                           name='stdio',
                           slug='stdio',
                           type='s',
                           num_lines=len(log1)),
                fakedb.Log(id=61,
                           stepid=53,
                           name='stdio',
                           slug='stdio',
                           type='s',
                           num_lines=len(log2)),
                fakedb.LogChunk(logid=60,
                                first_line=0,
                                last_line=4,
                                compressed=0,
                                content='\n'.join(log1)),
                fakedb.LogChunk(logid=61,
                                first_line=0,
                                last_line=6,
                                compressed=0,
                                content='\n'.join(log2))
            ])
        elif current == EXCEPTION:
            self.db.insertTestData([
                fakedb.Log(id=60,
                           stepid=51,
                           name='err.text',
                           slug='err_text',
                           type='t',
                           num_lines=len(log1)),
                fakedb.Log(id=61,
                           stepid=53,
                           name='err.text',
                           slug='err_text',
                           type='t',
                           num_lines=len(log2)),
                fakedb.LogChunk(logid=60,
                                first_line=0,
                                last_line=4,
                                compressed=0,
                                content='\n'.join(log1)),
                fakedb.LogChunk(logid=61,
                                first_line=0,
                                last_line=6,
                                compressed=0,
                                content='\n'.join(log2))
            ])
示例#21
0
class Tests(interfaces.InterfaceTests):

    backgroundData = [
        fakedb.Buildslave(id=47, name='linux'),
        fakedb.Buildset(id=20),
        fakedb.Builder(id=88, name='b1'),
        fakedb.BuildRequest(id=41, buildsetid=20, buildername='b1'),
        fakedb.Master(id=88),
        fakedb.Build(id=30,
                     buildrequestid=41,
                     number=7,
                     masterid=88,
                     builderid=88,
                     buildslaveid=47),
        fakedb.Step(id=101, buildid=30, number=1, name='one'),
        fakedb.Step(id=102, buildid=30, number=2, name='two'),
    ]

    testLogLines = [
        fakedb.Log(id=201,
                   stepid=101,
                   name=u'stdio',
                   slug=u'stdio',
                   complete=0,
                   num_lines=7,
                   type=u's'),
        fakedb.LogChunk(logid=201,
                        first_line=0,
                        last_line=1,
                        compressed=0,
                        content=textwrap.dedent("""\
                    line zero
                    line 1""")),
        fakedb.LogChunk(logid=201,
                        first_line=2,
                        last_line=4,
                        compressed=0,
                        content=textwrap.dedent("""\
                    line TWO
                    line 3
                    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"),
    ]

    def checkTestLogLines(self):
        expLines = [
            'line zero', 'line 1', 'line TWO', 'line 3', '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] + "\n"))
        # check overflow
        self.assertEqual((yield self.db.logs.getLogLines(201, 5, 20)),
                         "\n".join(expLines[5:7] + "\n"))

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

    # method tests

    @defer.inlineCallbacks
    def test_getLog(self):
        yield self.insertTestData(self.backgroundData + [
            fakedb.Log(id=201,
                       stepid=101,
                       name=u'stdio',
                       slug=u'stdio',
                       complete=0,
                       num_lines=200,
                       type=u's'),
        ])
        logdict = yield self.db.logs.getLog(201)
        validation.verifyDbDict(self, 'logdict', logdict)
        self.assertEqual(
            logdict, {
                'id': 201,
                'stepid': 101,
                'name': u'stdio',
                'slug': u'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=u'stdio',
                       slug=u'stdio',
                       complete=0,
                       num_lines=200,
                       type=u's'),
            fakedb.Log(id=202,
                       stepid=101,
                       name=u'dbg.log',
                       slug=u'dbg_log',
                       complete=1,
                       num_lines=200,
                       type=u's'),
        ])
        logdict = yield self.db.logs.getLogBySlug(101, u'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=u'stdio',
                       slug=u'stdio',
                       complete=0,
                       num_lines=200,
                       type=u's'),
        ])
        logdict = yield self.db.logs.getLogBySlug(102, u'stdio')
        self.assertEqual(logdict, None)

    @defer.inlineCallbacks
    def test_getLogs(self):
        yield self.insertTestData(self.backgroundData + [
            fakedb.Log(id=201,
                       stepid=101,
                       name=u'stdio',
                       slug=u'stdio',
                       complete=0,
                       num_lines=200,
                       type=u's'),
            fakedb.Log(id=202,
                       stepid=101,
                       name=u'dbg.log',
                       slug=u'dbg_log',
                       complete=1,
                       num_lines=300,
                       type=u't'),
            fakedb.Log(id=203,
                       stepid=102,
                       name=u'stdio',
                       slug=u'stdio',
                       complete=0,
                       num_lines=200,
                       type=u'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)
        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=u'stdio',
                       slug=u'stdio',
                       complete=0,
                       num_lines=200,
                       type=u'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_addLog_getLog(self):
        yield self.insertTestData(self.backgroundData)
        logid = yield self.db.logs.addLog(stepid=101,
                                          name=u'config.log',
                                          slug=u'config_log',
                                          type=u't')
        logdict = yield self.db.logs.getLog(logid)
        validation.verifyDbDict(self, 'logdict', logdict)
        self.assertEqual(
            logdict, {
                'id': logid,
                'stepid': 101,
                'name': u'config.log',
                'slug': u'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=u'another',
                                          slug=u'another',
                                          type=u's')
        self.assertEqual((yield self.db.logs.appendLog(logid, u'xyz\n')),
                         (0, 0))
        self.assertEqual((yield self.db.logs.appendLog(201, u'abc\ndef\n')),
                         (7, 8))
        self.assertEqual((yield self.db.logs.appendLog(logid, u'XYZ\n')),
                         (1, 1))
        self.assertEqual((yield self.db.logs.getLogLines(201, 6, 7)),
                         u"yet another line\nabc\n")
        self.assertEqual((yield self.db.logs.getLogLines(201, 7, 8)),
                         u"abc\ndef\n")
        self.assertEqual((yield self.db.logs.getLogLines(201, 8, 8)), u"def\n")
        self.assertEqual((yield self.db.logs.getLogLines(logid, 0, 1)),
                         u"xyz\nXYZ\n")
        self.assertEqual(
            (yield self.db.logs.getLog(logid)), {
                'complete': False,
                'id': logid,
                'name': u'another',
                'slug': u'another',
                'num_lines': 2,
                'stepid': 102,
                'type': u'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
        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, u'abc\n' * 20000)),  # 80k
            (7, 20006))
        lines = yield self.db.logs.getLogLines(201, 7, 50000)
        self.assertEqual(len(lines), 80000)
        self.assertEqual(lines, (u'abc\n' * 20000))

    @defer.inlineCallbacks
    def test_addLogLines_big_chunk_big_lines(self):
        yield self.insertTestData(self.backgroundData + self.testLogLines)
        line = u'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))