Example #1
0
 def _publishDependentCell(self, block_id):
     low, high = self._biigraph._get_range_block(block_id)
     count = 0
     d = self.lbcn
     bcn = d[block_id]
     brl = self._getBlockBRL(bcn)
     for row in range(low, high + 1):
         r = SimpleCell(d[block_id])
         r.root = ID((0, bcn.block_name[-1:], 0))
         deps = DependencySet()
         dep_table = BlockVersionTable()
         for block in range(block_id):
             time = self._biigraph._get_dep_elem_offset(row, block)
             if time != -1:
                 deps.add_implicit(d[block])
                 dep_table[d[block].block_name] = \
                    BlockVersion(self._getBlockBRL(d[block]), time)
         r.dependencies = deps
         pack = PublishRequest(BlockVersion(brl, count - 1))
         pack.tag = STABLE
         count += 1
         pack.cells.append(r)
         pack.contents[r.name.cell_name] = Content(id_=None, load=Blob('hola {0}'.
                                                             format(r.name.cell_name)))
         pack.deptable = dep_table
         self.service.publish(pack)
Example #2
0
def make_published_resource(block, block_cell_name):
    if isinstance(block_cell_name, basestring):
        moduleCellName = BlockCellName(block_cell_name)
    sr = SimpleCell(block_cell_name)
    sr.type = BiiType.from_extension(moduleCellName.extension)
    sr.ID = UserID(1) + 1 + 2
    return sr
Example #3
0
    def publish(self, brl_block, resource_info, version_tag=STABLE, dep_versions=None):
        """ make a simple publication of a single file named block_cell_name to block
        brl_block. If block does not exist, it creates it. It mantains coherence of root Ids
        for the find checks
        param resource_info: {cell_name: (blob, explicits)}
        """
        try:
            block = self.store.read_block(brl_block)
            version = BlockVersion(brl_block, len(block.deltas) - 1)
        except NotInStoreException:
            version = BlockVersion(brl_block, -1)

        publish_request = PublishRequest(version)
        publish_request.tag = version_tag

        block_name = brl_block.block_name
        for cell_name, (blob, dependencies) in resource_info.iteritems():
            if dependencies is not None:
                cell = SimpleCell(block_name + cell_name)
                if isinstance(dependencies, DependencySet):
                    cell.dependencies = dependencies
                else:
                    cell.dependencies.explicit.update([BlockCellName(d) for d in dependencies])
                publish_request.cells.append(cell)
            if blob is not None:
                blob = Blob(blob) if isinstance(blob, str) else blob
                publish_request.contents[cell_name] = Content(id_=None, load=blob)

        if isinstance(dep_versions, BlockVersion):
            dep_versions = [dep_versions]
        publish_request.deptable = BlockVersionTable(dep_versions)
        self.service.publish(publish_request)
Example #4
0
def make_simple_cell(block_cell_name, hive=None):
    if isinstance(block_cell_name, basestring):
        block_cell_name = BlockCellName(block_cell_name)
    cell = SimpleCell(block_cell_name)
    cell.type = BiiType.from_extension(block_cell_name.extension)
    if hive:
        changes = ProcessorChanges()
        changes.upsert(cell.name, cell, None)
        hive.update(changes)
    return cell
    def test_simple_published_cell(self):
        # Simple publish resource
        simpleresource = SimpleCell("user/block/path/to/file.h")
        simpleresource.ID = ID()
        simpleresource.root = ID()

        # Include inside "a" the "kls" attribute
        s = simpleresource.serialize()

        self.assertEqual(s[Deserializer.POLIMORPHIC_KEYWORD],
                         ClassTypedSerializer.getValue(simpleresource.__class__))
        ob = CellDeserializer(ID).deserialize(s)
        self.assert_bii_equal(simpleresource, ob)
    def test_simple_edition_cell_with_container(self):
        virtual_cell = BlockCellName('user/block/path/file.h')
        simpleresource = SimpleCell("user/block/path/to/file.h")
        simpleresource.ID = BlockCellName("user/block/path/to/file.h")
        simpleresource.root = ID()
        simpleresource.dependencies.add_implicit(BlockCellName("user/block/path/file.h"))
        simpleresource.container = virtual_cell

        s = simpleresource.serialize()

        self.assertEqual(s[Deserializer.POLIMORPHIC_KEYWORD],
                         ClassTypedSerializer.getValue(SimpleCell))
        ob = CellDeserializer(BlockCellName).deserialize(s)
        self.assert_bii_equal(ob, simpleresource)
 def _process_leaves(self, virtual_cell, realizations, biiout):
     '''for a virtual cell, creates the leaves if they don't exist
     @param virtual_cell: the cell that serves as base
     @param realizations: a set to add the leaves BlockCellNames
     @param biiout: biiout
     '''
     block_cell_name = virtual_cell.name
     for leave in virtual_cell.resource_leaves:
         realizations.add(leave)
         try:
             cell = self.block_holder[leave.cell_name].cell
         except KeyError:
             #The leave it is pointing does not exist
             biiout.info('%s virtual realization not existing, creating it' % leave)
             cell = SimpleCell(leave)
             cell.type = virtual_cell.type
             content = Content(leave, Blob(""), created=True)
             content.parser = parser_factory(cell.type, cell.name.cell_name)
             self.block_holder.add_resource(Resource(cell, content))
         cell.container = block_cell_name
    def test_publish_concurrent_modification(self):
        self.store = TestingMemServerStore()
        brl = 'user'
        self.store.create_user(User(brl))
        self.service = BiiService(self.store, brl)

        self.brl_block = BRLBlock('user/user/block/master')
        request = PublishRequest(BlockVersion(self.brl_block, -1))
        request.cells.append(SimpleCell('user/block/r1.h'))
        request.contents['r1.h'] = Content(id_=None, load=Blob('hola'))
        request.deptable = BlockVersionTable()
        request.tag = DEV
        self.service.publish(request)
        '''Branch 1 (from master) creates new resource'''
        self.brl_block1 = BRLBlock('user/user/block/branch1')
        request = PublishRequest(BlockVersion(self.brl_block, 0))
        request.cells.append(SimpleCell('user/block/r2.h'))
        request.contents['r2.h'] = Content(id_=None, load=Blob('adios'))
        request.deptable = BlockVersionTable()
        with self.assertRaisesRegexp(BiiException, 'Concurrent modification'):
            self.service.publish(request)
Example #9
0
 def _process_leaves(self, virtual_cell, realizations, biiout):
     '''for a virtual cell, creates the leaves if they don't exist
     @param virtual_cell: the cell that serves as base
     @param realizations: a set to add the leaves BlockCellNames
     @param biiout: biiout
     '''
     block_cell_name = virtual_cell.name
     for leave in virtual_cell.resource_leaves:
         realizations.add(leave)
         try:
             cell = self.block_holder[leave.cell_name].cell
         except KeyError:
             #The leave it is pointing does not exist
             biiout.info('%s virtual realization not existing, creating it' % leave)
             cell = SimpleCell(leave)
             cell.type = virtual_cell.type
             content = Content(leave, Blob(""))
             content.parser = parser_factory(cell.type, cell.name.cell_name)
             self.block_holder.add_resource(Resource(cell, content))
             self.processor_changes.upsert(cell.name, content, blob_changed=True)
         cell.container = block_cell_name
Example #10
0
    def test_create_missing_simple_resources(self):
        resources = {'bii/virtual.bii': Resource(SimpleCell('user/block/bii/virtual.bii'),
                                                  Content(None, Blob(myConf1)))}
        self.block_holder = BlockHolder(BlockName('user/block'), resources)

        VirtualConfigurationProcessor().do_process(self.block_holder, OutputStream())

        self._sphere_os_checks('sphere.h')
        self._sphere_os_checks('sphere.cpp')

        self.assertEqual(None, self.block_holder['sphere.h'].content)
        self.assertEqual(None, self.block_holder['sphere.cpp'].content)
    def test_publish_no_contents(self, enqueuer):
        brl = BRLBlock('owner/user/block/branch')
        store = Mock(MongoServerStore)
        store.read_block_permissions = Mock(
            return_value=ElementPermissions(brl, private=False))

        p = PublishService(store, 'authUser')
        pack = PublishRequest(BlockVersion(brl, -1))
        pack.cells.append(SimpleCell('user/block/r1.h'))
        pack.contents['r1.h'] = Content(id_=None, load=Blob('hola'))
        pack.versiontag = 'mytag'
        with self.assertRaisesRegexp(PublishException, 'DEV'):
            p.publish(pack)
Example #12
0
    def test_mains_with_filter(self):
        r1 = SimpleCell('user/block/r1.h', CPP)
        r2 = SimpleCell('user/block/r2.cpp', CPP)
        r3 = SimpleCell('user/block/no_mains/r3.cpp', CPP)
        r4 = SimpleCell('user/block/no_mains/r4.cpp', CPP)
        r5 = SimpleCell('user/block/' + BIICODE_FILE)
        r6 = SimpleCell('user/block/new_mains/r6.cpp', CPP)
        r7 = SimpleCell('user/block/new_mains/r7.cpp', CPP)
        r8 = SimpleCell('user/block/exe_file1.hh', CPP)
        r9 = SimpleCell('user/block/exe_file2.hh', CPP)

        res = {r1.name: Resource(r1, Content(None, Blob(''))),
               r2.name: Resource(r2, Content(None, Blob(''))),
               r3.name: Resource(r3, Content(None, Blob('int main(char* argv){}'))),
               r4.name: Resource(r4, Content(None, Blob('int main(char* argv){}'))),
               r5.name: Resource(r5, Content(None, Blob('[mains]\n!no_mains/*\nnew_mains/*\n*.hh'))),
               r6.name: Resource(r6, Content(None, Blob(''))),
               r7.name: Resource(r7, Content(None, Blob(''))),
               r8.name: Resource(r8, Content(None, Blob(''))),
               r9.name: Resource(r9, Content(None, Blob('')))
               }

        block_holder = BlockHolder(BlockName('user/block'), res)

        process_holder(block_holder, ParseProcessor())
        self.assertTrue(res['user/block/no_mains/r3.cpp'].cell.hasMain)
        self.assertTrue(res['user/block/no_mains/r4.cpp'].cell.hasMain)
        self.assertFalse(res['user/block/new_mains/r6.cpp'].cell.hasMain)
        self.assertFalse(res['user/block/new_mains/r7.cpp'].cell.hasMain)
        self.assertFalse(res['user/block/exe_file1.hh'].cell.hasMain)
        self.assertFalse(res['user/block/exe_file2.hh'].cell.hasMain)

        process_holder(block_holder, MainConfigProcessor())

        # Checks
        self.assertFalse(res['user/block/r1.h'].cell.hasMain)
        self.assertFalse(res['user/block/r2.cpp'].cell.hasMain)
        self.assertFalse(res['user/block/no_mains/r3.cpp'].cell.hasMain)
        self.assertFalse(res['user/block/no_mains/r4.cpp'].cell.hasMain)
        self.assertTrue(res['user/block/new_mains/r6.cpp'].cell.hasMain)
        self.assertTrue(res['user/block/new_mains/r7.cpp'].cell.hasMain)
        self.assertTrue(res['user/block/exe_file1.hh'].cell.hasMain)
        self.assertTrue(res['user/block/exe_file2.hh'].cell.hasMain)
Example #13
0
    def test_add_modify_delete_cell(self):
        publish_request = PublishRequest(BlockVersion(self.brl, -1))
        publish_request.cells.append(SimpleCell('user/block/r1.h'))
        publish_request.cells.append(SimpleCell('user/block/r2.h'))
        publish_request.cells.append(SimpleCell('user/block/r3.h'))
        publish_request.contents['r1.h'] = Content(id_=None, load=None)
        publish_request.tag = STABLE
        self.block.add_publication(publish_request)

        ids0 = set(self.block.cells.get_all_ids(0).values())
        names0 = set(self.block.cells.get_all_ids(0).keys())
        expected_ids0 = set([
            ID(self.block_id + 0),
            ID(self.block_id + 1),
            ID(self.block_id + 2)
        ])
        expected_names0 = set(['r1.h', 'r2.h', 'r3.h'])
        self.assertEqual(expected_ids0, ids0)
        self.assertEqual(expected_names0, names0)

        publish_request = PublishRequest(BlockVersion(self.brl, 0))
        publish_request.deleted.append('r1.h')
        publish_request.cells.append(SimpleCell('user/block/r2.h'))
        publish_request.cells.append(SimpleCell('user/block/r4.h'))
        publish_request.tag = STABLE
        self.block.add_publication(publish_request)

        self.assertEqual(expected_ids0, ids0)
        self.assertEqual(expected_names0, names0)

        prev = self.block.cells.get_all_ids(0)
        id3 = prev['r3.h']
        expected = set([id3, ID(self.block_id + 3), ID(self.block_id + 4)])
        self.assertEqual(expected,
                         set(self.block.cells.get_all_ids(1).values()))
        expected = set(['r4.h', 'r2.h', 'r3.h'])
        self.assertEqual(expected, set(self.block.cells.get_all_ids(1).keys()))
        self.assertEqual(expected, set(self.block.last_version_cells().keys()))
Example #14
0
    def publish(self,
                brl_block,
                resource_info,
                version_tag=STABLE,
                dep_versions=None):
        """ make a simple publication of a single file named block_cell_name to block
        brl_block. If block does not exist, it creates it. It mantains coherence of root Ids
        for the find checks
        param resource_info: {cell_name: (blob, explicits)}
        """
        try:
            block = self.store.read_block(brl_block)
            version = BlockVersion(brl_block, len(block.deltas) - 1)
        except NotInStoreException:
            version = BlockVersion(brl_block, -1)

        publish_request = PublishRequest(version)
        publish_request.tag = version_tag

        block_name = brl_block.block_name
        for cell_name, (blob, dependencies) in resource_info.iteritems():
            if dependencies is not None:
                cell = SimpleCell(block_name + cell_name)
                if isinstance(dependencies, DependencySet):
                    cell.dependencies = dependencies
                else:
                    cell.dependencies.explicit.update(
                        [BlockCellName(d) for d in dependencies])
                publish_request.cells.append(cell)
            if blob is not None:
                blob = Blob(blob) if isinstance(blob, str) else blob
                publish_request.contents[cell_name] = Content(id_=None,
                                                              load=blob)

        if isinstance(dep_versions, BlockVersion):
            dep_versions = [dep_versions]
        publish_request.deptable = BlockVersionTable(dep_versions)
        self.service.publish(publish_request)
    def diamond_test(self, conflict):
        """ Blocks: C
        Deps: A, B, D1-D2
        C -> A, B; A->D1, B->D2
        """
        references = References()
        references[va].add('a.h')
        references[vb].add('b.h')

        b = Resource(SimpleCell('user/blockb/b.h'))
        a = Resource(SimpleCell('user/blocka/a.h'))
        d1 = Resource(SimpleCell('user/blockd/d.h'))
        if conflict:
            d2 = Resource(SimpleCell('user/blockd/d.h', CPP))
        else:
            d2 = Resource(SimpleCell('user/blockd/d.h'))
        a.cell.dependencies.explicit.add(d1.name)
        b.cell.dependencies.explicit.add(d2.name)

        tables = {va: [vd1], vb: [vd2], vd1: [], vd2: []}
        api = FakeApi(zip([va, vb, vd1, vd2], [a, b, d1, d2]), tables)
        base_table = BlockVersionTable([vc, va, vb])
        biiout = OutputStream()
        graph, closure, _ = build_closure(api,
                                          references,
                                          base_table,
                                          biiout=biiout)
        expected_graph = BlockVersionGraph()
        expected_graph.add_nodes([va, vb, vd1, vd2])
        expected_graph.add_edge(va, vd1)
        expected_graph.add_edge(vb, vd2)
        self.assertEqual(expected_graph, graph)
        self.assertEqual({a.name, b.name, d1.name}, set(closure.keys()))
        if conflict:
            self.assertIn('Incompatible dependency "user/blockd/d.h"',
                          str(biiout))
        else:
            self.assertEqual("", str(biiout))
Example #16
0
    def test_modify_content(self):
        '''just modify the content of a file'''
        r1 = SimpleCell(self.brl_block.block_name + 'r1.h')
        content = Content(id_=None, load=Blob('bye'))

        edition_resources = {'r1.h': Resource(r1, content)}

        changes = compare(self.last_version_resources, edition_resources)

        self.assertEqual(0, len(changes.deleted))
        self.assertEqual(0, len(changes.created))
        self.assertEqual(0, len(changes.renames))
        self.assertEqual(1, len(changes.modified))
        self.assertEqual(Resource(r1, content), changes.modified['r1.h'].new)
Example #17
0
    def test_check_publish_block(self):
        # 1. Onwer can write the block if its private
        brl = BRLBlock("goku/goku/block/master")
        self._add_block_to_user("goku", brl, True)

        ensure = Security("goku", self.store)
        self._subscribe("goku", "enterprise_275_50_x")

        pack = PublishRequest(BlockVersion(brl, -1))
        pack.cells.append(SimpleCell('user/block/r1.h'))
        pack.contents['r1.h'] = Content(id_=None, load=Blob('hola'))
        pack.versiontag = 'mytag'

        ensure.check_publish_block(brl, pack)

        # If the owner is not paying he can't write
        ensure = Security("goku", self.store)
        self._subscribe("goku", "free")
        self.assertRaises(ForbiddenException, ensure.check_publish_block, brl, pack)
        self._subscribe("goku", "enterprise_275_50_x")

        # 1b. But other not granted user can't write
        ensure = Security("freezer", self.store)
        self._subscribe("freezer", "enterprise_275_50_x")
        self.assertRaises(ForbiddenException, ensure.check_publish_block, brl, pack)

        # 2. If bulma is granted as administrator or write he can write
        ensure = Security("bulma", self.store)
        self._subscribe("bulma", "enterprise_275_50_x")
        goku = self.store.read_user("goku")
        goku.administrators.grant("bulma")
        self.store.update_user(goku)
        ensure.check_publish_block(brl, pack)
        goku.administrators.revoke("bulma")
        self.store.update_user(goku)
        self.assertRaises(ForbiddenException, ensure.check_publish_block, brl, pack)

        bper = ElementPermissions(brl, private=True)
        bper.write.grant("bulma")
        self.store.upsert_block_permissions(bper)
        ensure.check_publish_block(brl, pack)
        bper.write.remove("bulma")
        self.store.upsert_block_permissions(bper)
        self.assertRaises(ForbiddenException, ensure.check_publish_block, brl, pack)

        # 3. If we give read permissions only, user cant write
        bper = ElementPermissions(brl, private=True)
        bper.read.grant("bulma")
        self.store.upsert_block_permissions(bper)
        self.assertRaises(ForbiddenException, ensure.check_publish_block, brl, pack)
Example #18
0
    def _process_from_contents(self, contents):
        '''param contents: dict{name:code snippets}.
        Will create a HiveHolder, fill with the data and process it'''
        resources = []
        for name, content in contents.iteritems():
            cell = SimpleCell(name, CPP)
            block_name = cell.name.block_name
            resources.append(
                Resource(
                    cell,
                    Content(name, load=Blob(content), parser=DRLCPPParser())))

        block_holder = BlockHolder(block_name, resources)
        self._process(block_holder)
        return block_holder
Example #19
0
 def python_parse_failure_test(self, parser):
     """ Weird bug miguel found.
     Python parser failure was causing 'You're trying to parse a virtual file' message to appear
     """
     response = OutputStream()
     parser.side_effect = Exception
     cell = SimpleCell('usr/block/sort_controllers.py', biitype=PYTHON)
     content = Content(id_=1,
                       load=Blob('print "hello"'),
                       parser=None,
                       is_parsed=False)
     resource = Resource(cell, content)
     self.assertFalse(resource.parse(response))
     self.assertIn('Error parsing usr/block/sort_controllers.py file',
                   str(response))
 def _publishIndependentCell(self,
                             block_cell_name,
                             nVersions=10,
                             version_tag=None):
     '''publishes nVersions of each cell'''
     block_brl = self._getBlockBRL(block_cell_name)
     for v in range(0, nVersions):
         r = SimpleCell(block_cell_name)
         pack = PublishRequest(BlockVersion(block_brl, v - 1))
         pack.tag = version_tag if version_tag is not None else STABLE
         pack.cells.append(r)
         pack.deptable = BlockVersionTable()
         pack.contents[r.name.cell_name] = Content(
             id_=None, load=Blob('hola {0}'.format(v)))
         self.service.publish(pack)
    def setUp(self):
        self.conn.drop_database(self._testMethodName)
        self.store = MongoServerStore(self.conn, self._testMethodName)
        self.mother = ModelCreator(self.store)
        self.user = self.mother.make_test_user()
        self.p = PublishService(self.store, self.user.ID)
        self.brl = BRLBlock('%s/%s/block/master' %
                            (self.user.ID, self.user.ID))

        pack = PublishRequest(BlockVersion(self.brl, -1))
        pack.cells.append(SimpleCell('%s/block/r1.h' % self.user.ID))
        pack.cells.append(SimpleCell('%s/block/r2.h' % self.user.ID))
        pack.cells.append(SimpleCell('%s/block/r3.h' % self.user.ID))
        pack.contents['r1.h'] = Content(id_=None, load=Blob('r1'))
        pack.contents['r2.h'] = Content(id_=None, load=Blob('r2'))
        pack.contents['r3.h'] = Content(id_=None, load=Blob('r3'))
        pack.deptable = BlockVersionTable()
        self.pack = pack

        self.cell_collection = self.store.db[
            GenericServerStore.PUBLISHED_CELL_ST]
        self.content_collection = self.store.db[
            GenericServerStore.PUBLISHED_CONTENT_ST]
        self.block_collection = self.store.db[GenericServerStore.BLOCK_ST]
Example #22
0
    def commit_config(self):
        '''
        Returns:
            None if the config file didnt change. The config file Resource in case
            it was created or modified
        '''

        new_content = self.config.dumps()
        if new_content:
            name = self.block_name + BIICODE_FILE
            new_res = Resource(SimpleCell(name, TEXT),
                               Content(name, load=Blob(new_content)))
            self.add_resource(new_res)
            return new_res
        return None
Example #23
0
def get_block_holder(block_cell_names, biitype=BiiType(UNKNOWN)):
    '''Given a working set, a list of resources and a biitype constant
     - Adds every resource to the working set and assign given type
     - Read test files from disk as binary or systext depending on given type and creates contents
     - Fills a wsHolder with given resources and created contents
    '''

    resources = []
    for name in block_cell_names:
        cell = SimpleCell(name, biitype)
        content = make_content(name, biitype)
        resources.append(Resource(cell, content))

    block_name = BlockCellName(iter(block_cell_names).next()).block_name
    return BlockHolder(block_name, resources)
Example #24
0
    def test_has_main_and_dependency_declarations(self):
        processor = ParseProcessor()
        block_holder = mother.get_block_holder(['user/geom/main.cpp'], CPP)
        processor.do_process(block_holder, OutputStream())
        main = block_holder['main.cpp'].cell
        self.assertTrue(main.hasMain, 'Main method not detected by parse processor')
        self.check_dependency_set(main.dependencies, unresolved=['iostream', 'sphere.h'])

        # now remove #include
        load = block_holder['main.cpp'].content.load.bytes
        load = load.replace('#include "sphere.h"', '')
        block_holder.add_resource(Resource(SimpleCell('user/geom/main.cpp', CPP),
                                           Content('user/geom/main.cpp', Blob(load))))
        processor.do_process(block_holder, OutputStream())
        main = block_holder['main.cpp'].cell
        self.check_dependency_set(main.dependencies, unresolved=['iostream'])
    def test_publish_rejected(self):
        store = Mock(MongoServerStore)
        user = Mock()
        user.blocks = {}
        store.read_user = Mock(return_value=user)

        block = Mock(Block)
        block.add_publication.return_value = (Mock(), Mock())
        store.read_block.return_value = block
        brl = BRLBlock('user/user/block/branch')

        p = PublishService(store, 'authUser')
        pack = PublishRequest(BlockVersion(brl, -1))
        pack.cells.append(SimpleCell('user/block/r1.h'))
        pack.contents['r1.h'] = Content(id_=None, load=Blob('hola'))
        pack.deptable = BlockVersionTable()
        with self.assertRaises(ForbiddenException):
            p.publish(pack)
    def test_read_published_blocks_info(self, store_cls):
        """Insert a block and read all published blocks info (brl, lastpubdate)"""
        if store_cls == MongoServerStore:
            store = MongoServerStore(self.conn, self.__class__.__name__)
        else:
            store = TestingMemServerStore()
        block = Block(ID((23, 23)), BRLBlock("bonjovi/bonjovi/itsmylife/master"))
        ppack = PublishRequest(block.last_version())
        r1 = SimpleCell('user/block/r1.h')
        ppack.cells.append(r1)
        ppack.contents['r1.h'] = Content(id_=None, load=Blob('hola'))

        block.add_publication(ppack)
        store.create_block(block, False)
        ret = store.read_published_blocks_info()
        first = ret.next()

        self.assertEquals(first[0], "bonjovi/bonjovi/itsmylife/master")
        self.assertEquals(first[1].__class__, datetime.datetime)
Example #27
0
def checkin_block_files(hive_holder, block_name, files, processor_changes, biiout):
    '''
    Params:
        hive_holder: HiveHolder
        block_name: BlockName
        files: {cell_name: content}
        processor_changes: ProcessorChanges
        biiout: biiout
    '''
    block_name = BlockName(block_name)
    types_blobs = obtain_types_blobs(files)  # {cell_name: (TYPE, Content/CellType/None)}
    # FIXME: What happens if merge result is larger than individual files, reject???
    changevalidator.remove_large_cells(types_blobs, biiout)
    try:
        block_holder = hive_holder[block_name]
    except KeyError:
        block_holder = BlockHolder(block_name, [])
        hive_holder.add_holder(block_holder)

    for cell_name, (biitype, blob) in types_blobs.iteritems():
        block_cell_name = block_name + cell_name
        cell = SimpleCell(block_cell_name, biitype)
        try:
            resource = block_holder[cell_name]
        except KeyError:
            content = Content(block_cell_name, load=blob)
            processor_changes.upsert(block_cell_name, content)
        else:
            content = resource.content
            if content is None or blob != content.load:
                content = Content(block_cell_name, load=blob)
                processor_changes.upsert(block_cell_name, content)

        resource = Resource(cell, content)
        block_holder.add_resource(resource)

    for cell_name, resource in block_holder.resources.items():
        if cell_name not in types_blobs:
            if resource.content is not None:
                processor_changes.delete(resource.name)
            block_holder.delete_resource(cell_name)
    hive_holder.hive.update(processor_changes)
Example #28
0
    def test_modify_content_diff(self):
        r1 = SimpleCell(self.brl_block.block_name + 'r1.h')
        content = Content(id_=None, load=Blob('bye'))
        edition_resources = {'r1.h': Resource(r1, content)}
        changes = compare(self.last_version_resources, edition_resources)

        diff = compute_diff(changes, resource_diff_function)

        self.assertEqual(0, len(diff.deleted))
        self.assertEqual(0, len(diff.created))
        self.assertEqual(0, len(diff.renames))
        self.assertEqual(1, len(diff.modified))
        self.assertEqual(
            '--- base\n\n+++ other\n\n@@ -1 +1 @@\n\n-hello\n+bye',
            diff.modified['r1.h'].content)
        #print '--- base\n\n+++ other\n\n@@ -1 +1 @@\n\n-hello\n+bye'
        self.assertEqual(
            Resource(None,
                     '--- base\n\n+++ other\n\n@@ -1 +1 @@\n\n-hello\n+bye'),
            diff.modified['r1.h'])
Example #29
0
    def test_simple_edition_cell_with_container(self):
        virtual_cell = BlockCellName('user/block/path/file.h')
        simpleresource = SimpleCell("user/block/path/to/file.h")
        simpleresource.ID = BlockCellName("user/block/path/to/file.h")
        simpleresource.root = ID()
        simpleresource.dependencies.add_implicit(
            BlockCellName("user/block/path/file.h"))
        simpleresource.container = virtual_cell

        s = simpleresource.serialize()

        self.assertEqual(s[Deserializer.POLIMORPHIC_KEYWORD],
                         ClassTypedSerializer.getValue(SimpleCell))
        ob = CellDeserializer(BlockCellName).deserialize(s)
        self.assert_bii_equal(ob, simpleresource)
Example #30
0
def migrate_block_holder(block_holder, biiout):
    """ Necessary for bii-open, that has a different flow to process
    """
    block_name = block_holder.block_name
    resources = block_holder.resources
    files = {
        name: resource.content.load.load
        for name, resource in resources.iteritems()
        if isinstance(resource.cell, SimpleCell)
    }

    migration = migrate_block_files(block_name, files, biiout)
    if migration is None:
        return
    config_text, block_deleted = migration
    for deleted in block_deleted:
        block_holder.delete_resource(deleted)
    name = block_name + BIICODE_FILE
    new_res = Resource(SimpleCell(name, TEXT),
                       Content(name, load=Blob(config_text)))
    block_holder.add_resource(new_res)
Example #31
0
    def test_duplicated_first_level(self):
        brls = {'gtest1': 'dummy/block/include/gtest/gtest.h',
                'getest2': 'dummy/block/fused-src/gtest/gtest.h',
                'getest-all1': 'dummy/block/fused-src/gtest/gtest-all.cc',
                'getest-all2': 'dummy/block/src/gtest-all.cc',
                'sample': 'dummy/block/samples/sample_unittest.cc'
                }
        cells = {x: SimpleCell(x) for x in brls.values()}
        cells_names = [x.name.cell_name for x in cells.itervalues()]
        block_holder = self._cells_setup('dummy/block', cells_names, CPP)

        getest_all1 = block_holder['fused-src/gtest/gtest-all.cc'].cell
        getest_all1.dependencies.unresolved = {CPPDeclaration('gtest.h')}
        getest_all2 = block_holder['src/gtest-all.cc'].cell
        getest_all2.dependencies.unresolved = {CPPDeclaration('gtest.h')}
        sample = block_holder['samples/sample_unittest.cc'].cell
        sample.dependencies.unresolved = {CPPDeclaration('gtest.h')}
        process_holder(block_holder, DependenciesProcessor())
        # Checks
        self.assertEquals(0, len(getest_all1.dependencies.unresolved))
        self.assertEquals(1, len(getest_all2.dependencies.unresolved))
        self.assertEquals(1, len(sample.dependencies.unresolved))
Example #32
0
    def test_duplicated_n_level(self):
        brls = {'gtest1': 'dummy/block/a1/b/c/gtest/gtest.h',
                'getest2': 'dummy/block/a2/gtest/gtest.h',
                'getest-all1': 'dummy/block/a1/gtest-all.cc',
                'getest-all2': 'dummy/block/a3/gtest-all.cc',
                'getest-all3': 'dummy/block/a1/b2/gtest-all.cc',
                }
        cells = {x: SimpleCell(x) for x in brls.values()}
        cells_names = [x.name.cell_name for x in cells.itervalues()]
        block_holder = self._cells_setup('dummy/block', cells_names, CPP)

        getest_all1 = block_holder['a1/gtest-all.cc'].cell
        getest_all1.dependencies.unresolved = {CPPDeclaration('b/c/gtest/gtest.h')}
        getest_all2 = block_holder['a3/gtest-all.cc'].cell
        getest_all2.dependencies.unresolved = {CPPDeclaration('gtest.h')}
        getest_all3 = block_holder['a1/b2/gtest-all.cc'].cell
        getest_all3.dependencies.unresolved = {CPPDeclaration('../b/c/gtest/gtest.h')}
        process_holder(block_holder, DependenciesProcessor())
        # Checks
        self.assertEquals(0, len(getest_all1.dependencies.unresolved))
        self.assertEquals(1, len(getest_all2.dependencies.unresolved))
        self.assertEquals(0, len(getest_all3.dependencies.unresolved))
Example #33
0
    def test_include_partial(self):
        brls = {'main': 'dummy/block/main.cpp',
                'astar': 'dummy/block/algorithms/astar.h',
                'solver_h': 'dummy/block/solver/solver.h',
                'solver_cpp': 'dummy/block/solver/solver.cpp'
                }
        cells = {x: SimpleCell(x) for x in brls.values()}
        cells_names = [x.name.cell_name for x in cells.itervalues()]
        block_holder = self._cells_setup('dummy/block', cells_names, CPP)

        main = block_holder['main.cpp'].cell
        main.dependencies.unresolved = {CPPDeclaration('solver/solver.h')}
        solver_h = block_holder['solver/solver.h'].cell
        solver_h.dependencies.unresolved = {CPPDeclaration('../algorithms/astar.h')}
        solver_cpp = block_holder['solver/solver.cpp'].cell
        solver_cpp.dependencies.unresolved = {CPPDeclaration('solver.h')}

        process_holder(block_holder, DependenciesProcessor())
        # Checks
        self.assertEquals(set(), cells[brls['main']].dependencies.unresolved)
        self.assertEquals(set(), cells[brls['solver_h']].dependencies.unresolved)
        self.assertEquals(set(), cells[brls['solver_cpp']].dependencies.unresolved)
Example #34
0
 def get_holder(self):
     contents = self.read_edition_contents()
     # creation of cells
     cells = {name: SimpleCell(name) for name in contents}
     hive_holder = HiveHolder(cells, contents)
     return hive_holder
Example #35
0
def make_simple_cell(block_cell_name):
    if isinstance(block_cell_name, basestring):
        block_cell_name = BlockCellName(block_cell_name)
    cell = SimpleCell(block_cell_name)
    cell.type = BiiType.from_extension(block_cell_name.extension)
    return cell
    def test_publish(self, enqueuer):
        brl = BRLBlock('owner/user/block/branch')
        # moduleID=BlockID(UserID(123),456)
        store = Mock(MongoServerStore)
        store.read_block_permissions = Mock(
            return_value=ElementPermissions(brl, private=False))
        user = User("owner")
        user.numeric_id = 1
        user.blocks = {}
        store.read_user = Mock(return_value=user)
        block = Mock(Block)
        block.last_version.return_value = Mock(BlockVersion)
        block.add_publication.return_value = (Mock(list), Mock(list),
                                              Mock(list), Mock(list))
        block.deltas = []

        ensure = Security('authUser', store)
        ensure.check_create_block = Mock(return_value=True)
        ensure.check_write_block = Mock(return_value=True)
        ensure.check_read_block = Mock(return_value=True)

        store.read_block.return_value = block
        store.read_published_cells.return_value = {}
        p = PublishService(store, 'authUser')
        p.security = ensure

        pack = PublishRequest(BlockVersion(brl, -1))
        pack.cells.append(SimpleCell('user/block/r1.h'))
        pack.contents['r1.h'] = Content(id_=None, load=Blob('hola'))
        pack.cells.append(SimpleCell('user/block/r2.h'))
        pack.contents['r2.h'] = Content(id_=None, load=Blob('hola'))
        pack.cells.append(SimpleCell('user/block/r3.h'))
        pack.contents['r3.h'] = Content(id_=None, load=Blob('hola'))
        pack.deptable = BlockVersionTable()
        p.publish(pack)

        block.add_publication.assert_called_once_with(pack, p.auth_user)
        store.update_block.assert_called_once_with(block)
        self.assertEqual(1, store.create_published_cells.call_count)
        self.assertEqual(1, store.create_published_contents.call_count)

        # Check sizes
        self.assertEquals(user.blocks_bytes, 12)  # 12 bytes "hola" * 3

        # Publish again, see the size incremented
        pack._bytes = None  # Lazy computed
        p.publish(pack)
        self.assertEquals(user.blocks_bytes,
                          24)  # 24 bytes: "hola" * 3 * 2 publications

        # Max size exceeded for user
        user.max_workspace_size = 25
        self.assertRaises(ForbiddenException, p.publish, pack)

        # Try to publish only 1 byte
        pack._bytes = None  # Lazy computed
        pack.cells = []
        pack.contents = {}
        pack.cells.append(SimpleCell('user/block/r1.h'))
        pack.contents['r1.h'] = Content(id_=None, load=Blob('h'))
        p.publish(pack)
def make_simple_cell(block_cell_name):
    if isinstance(block_cell_name, basestring):
        block_cell_name = BlockCellName(block_cell_name)
    cell = SimpleCell(block_cell_name)
    cell.type = BiiType.from_extension(block_cell_name.extension)
    return cell