Exemple #1
0
def main():
    database = accounting.db.connect()
    if (isinstance(database.connection, pymongo.MongoClient)
            and not pytransact.utils.is_localhost_primary(database.client)):
        sys.stderr.write('Run upgrade.py on the MongoDB primary.\n')
        raise SystemExit()

    ensure_indexes(database)
    cleanup_commits(database)
    pytransact.utils.update_bases(database, blm.accounting.User)
    pytransact.utils.update_bases(database, blm.members.PGPaymentFile)
    pytransact.utils.update_bases(database, blm.members.PGPayment)

    #cleanup_toirefs(database)

    interested = 'upgrade-%s' % ObjectId()
    with commit.CommitContext(database) as ctx:
        ops = [
            commit.CallBlm('accounting', 'bootstrap', []),
            commit.CallBlm('accounting', 'upgrade', []),
            commit.CallBlm('members', 'upgrade', [])
        ]
        ctx.runCommit(ops, interested=interested)
    result, error = commit.wait_for_commit(database, interested=interested)
    assert not error, error

    log.info('Done.')
Exemple #2
0
    def test_runCommit_createCommit_fail(self, monkeypatch):
        def createCommit(*args, **kw):
            kw['args'] = args
            kw['_id'] = ObjectId()
            return kw

        op = commit.CallBlm('testcommit', 'simple', [['bar']])
        cctx = self.newcontext()

        monkeypatch.setattr(cctx, 'createCommit', createCommit)

        op = commit.CallBlm('testcommit', 'broken', [])
        cctx = self.newcontext()
        cmt = cctx.runCommit([op], processCommits=False)
        assert cmt.error.message == 'broken'
Exemple #3
0
    def test_BlobVals(self):
        val = BlobVal('foo')
        op = commit.CallToi(ObjectId(), 'foo', [[val], ['apa']])
        assert set(op.blobVals()) == {val}

        op = commit.CallBlm('theblm', 'foo', [[val], ['apa']])
        assert set(op.blobVals()) == {val}
Exemple #4
0
    def test_createCommit_bad_doc(self):
        cctx = self.newcontext()
        toi1 = blm.testcommit.Test(name=['foo' * 8 * 1024 * 1024])  # 24MB
        cctx.newTois = {toi1.id[0]: toi1}

        ops = [commit.CallBlm('foo', 'bar', [])]

        cmt = cctx.createCommit(ops, [['result']], interested='interested')
Exemple #5
0
    def test_CallBlm_simple(self):
        cctx = self.newcontext()

        op = commit.CallBlm('testcommit', 'simple', [['bar']])
        commitDoc = cctx.runCommit([op])
        result = commitDoc.results

        assert result == [['foo', 'bar']]
Exemple #6
0
 def test_runCommit_error_with_interest(self):
     op = commit.CallBlm('testcommit', 'broken', [])
     cctx = self.newcontext()
     interested = ObjectId()
     cmt = cctx.runCommit([op], interested=interested)
     assert cmt.error
     self.sync()
     stored = mongo.find_one(self.database.commits, {'_id': cmt._id})
     assert type(cmt.error) == type(stored['error'])
     assert cmt.error.args == stored['error'].args
Exemple #7
0
def invoke(request, database, user, blmName, methodName):
    try:
        method = getattr(getattr(blm, blmName), methodName)
    except AttributeError:
        log.debug('No such method: %s.%s', blmName, methodName)
        flask.abort(httplib.NOT_FOUND)

    params = _get_params(request, method)
    op = commit.CallBlm(blmName, methodName, params)
    return _invoke(request, database, user, op)
Exemple #8
0
    def test_CallBlm_write(self):
        user = blm.fundamental.AccessHolder()
        toi = blm.testcommit.Test(name=['foo'], allowRead=[user])
        self.commit()
        self.sync()
        cctx = self.newcontext(user=user)

        op = commit.CallBlm('testcommit', 'write', [[toi], ['bar']])
        cmt = cctx.runCommit([op])
        # xxx find a better way of testing this
        assert 'AttrPermError' in repr(cmt.error)
Exemple #9
0
    def test_createCommit(self):
        cctx = self.newcontext()
        toi1 = blm.testcommit.Test(name=['foo'])
        toi2 = blm.testcommit.Test(name=['bar'])
        toi3 = blm.testcommit.Test(name=['baz'])
        toi1._orgAttrData = {'name': ['apa']}

        cctx.changedTois = {toi1.id[0]: toi1}
        cctx.newTois = {toi2.id[0]: toi2}
        cctx.deletedTois = {toi3.id[0]: toi3}
        cctx.indexData = [(toi1.id[0], {
            'toid': toi1.id[0],
            'data': ['foo', 'bar']
        })]
        bval1 = BlobVal('x')
        bval2 = BlobVal('y')
        bval3 = BlobVal('z')

        cctx.addedBlobVals = {str(toi1.id[0]): [bval1]}
        cctx.deletedBlobVals = {str(toi2.id[0]): [bval2]}

        ops = [commit.CallBlm('foo', 'bar', [[bval3]])]

        cmt = cctx.createCommit(ops, [['result']], interested='interested')

        assert cmt.user == cctx.user != None
        assert set(cmt.deletedTois) == set([toi3.id[0]])
        diff = DiffTOI()
        diff.setAttrDiff(toi2.__class__, toi2.id[0], {'name': []},
                         {'name': ['bar']})
        assert cmt.newTois == [diff]
        diff = DiffTOI()
        diff.setAttrDiff(toi1.__class__, toi1.id[0], {'name': ['apa']},
                         {'name': ['foo']})
        assert cmt.changedTois == [diff]
        assert cmt.indexData == [(toi1.id[0], {
            'toid': toi1.id[0],
            'data': ['foo', 'bar']
        })]
        assert cmt.addedBlobVals == {str(toi1.id[0]): [bval1]}
        assert cmt.deletedBlobVals == {str(toi2.id[0]): [bval2]}
        assert cmt.operations == ops
        assert cmt.results == [['result']]
        assert cmt.interested == 'interested'
        assert cmt.error is None

        assert bval1.references == {cmt._id}
        assert bval2.references == {cmt._id}
        assert bval3.references == {cmt._id}
Exemple #10
0
    def _run(self, params, state):
        me = self.clientId, self.linkId
        if state is None:
            toid = params.get('toid')
            blmName = params.get('blmName')
            if not (bool(toid) ^ bool(blmName)): # XOR
                raise RuntimeError("Only one of toid or blmName "
                                   "may be supplied.")

            if toid is not None and not isinstance(toid, blm.TO):
                toid = ObjectId(toid)

            methodName = params['methodName']
            args = params['args']
            self.save(None, 'processing') # arg only used in tests

            if toid:
                op = commit.CallToi(toid, methodName, args)
            else:
                op = commit.CallBlm(blmName, methodName, args)
            self.context.runCommit([op], interested=me)

        done = commit.Commit.fromquery(self.database,
                                       {'handled_by': me, 'state': 'done'})

        if done:
            error = done.error
            if error is None:
                result = done.results[0]
            else:
                result = []

            for obj in iterate.walk(result):
                if isinstance(obj, Attribute.BlobVal):
                    obj.addref(self.clientId)

            self.update({'result': result, 'error': error})
            done.delete(self.database)
            self.remove()
Exemple #11
0
 def test_runCommit_error(self):
     op = commit.CallBlm('testcommit', 'broken', [])
     cctx = self.newcontext()
     cmt = cctx.runCommit([op])
     assert cmt.error
Exemple #12
0
 def test_runCommit(self):
     op = commit.CallBlm('testcommit', 'simple', [['bar']])
     cctx = self.newcontext()
     cctx.runCommit([op])
Exemple #13
0
 def test_CallBlm_non_existant_toiref(self):
     op = commit.CallBlm('testcommit', 'write', [[ObjectId()], ['bar']])
     cctx = self.newcontext()
     print(py.test.raises(ClientError, op.operate, cctx))