Exemplo n.º 1
0
    def test_renames(self):
        publish_request = PublishRequest(BlockVersion(self.brl, -1))
        publish_request.cells.append(SimpleCell('user/block/r1.h'))
        publish_request.contents['r1.h'] = Content(id_=None, load=None)
        publish_request.cells.append(SimpleCell('user/block/r2.h'))
        publish_request.contents['r2.h'] = Content(id_=None, load=None)
        publish_request.cells.append(SimpleCell('user/block/r3.h'))
        publish_request.contents['r3.h'] = Content(id_=None, load=None)
        publish_request.tag = STABLE
        self.block.add_publication(publish_request)

        publish_request = PublishRequest(BlockVersion(self.brl, 0))
        publish_request.cells.append(SimpleCell('user/block/r11.h'))
        publish_request.deleted.append('r1.h')
        publish_request.renames = Renames({CellName('r1.h'): CellName('r11.h')})
        publish_request.tag = STABLE
        self.block.add_publication(publish_request)

        publish_request = PublishRequest(BlockVersion(self.brl, 1))
        publish_request.cells.append(SimpleCell('user/block/r21.h'))
        publish_request.deleted.append('r2.h')
        publish_request.renames = Renames({CellName('r2.h'): CellName('r21.h')})
        publish_request.tag = STABLE
        self.block.add_publication(publish_request)

        self.assertEquals({}, self.block.get_renames(0, 0))
        self.assertEquals({'r1.h': 'r11.h'}, self.block.get_renames(0, 1))
        self.assertEquals({'r2.h': 'r21.h', 'r1.h': 'r11.h'}, self.block.get_renames(0, 2))
Exemplo n.º 2
0
    def test_renames(self):
        publish_request = PublishRequest(BlockVersion(self.brl, -1))
        publish_request.cells.append(SimpleCell('user/block/r1.h'))
        publish_request.contents['r1.h'] = Content(id_=None, load=None)
        publish_request.cells.append(SimpleCell('user/block/r2.h'))
        publish_request.contents['r2.h'] = Content(id_=None, load=None)
        publish_request.cells.append(SimpleCell('user/block/r3.h'))
        publish_request.contents['r3.h'] = Content(id_=None, load=None)
        publish_request.tag = STABLE
        self.block.add_publication(publish_request)

        publish_request = PublishRequest(BlockVersion(self.brl, 0))
        publish_request.cells.append(SimpleCell('user/block/r11.h'))
        publish_request.deleted.append('r1.h')
        publish_request.renames = Renames(
            {CellName('r1.h'): CellName('r11.h')})
        publish_request.tag = STABLE
        self.block.add_publication(publish_request)

        publish_request = PublishRequest(BlockVersion(self.brl, 1))
        publish_request.cells.append(SimpleCell('user/block/r21.h'))
        publish_request.deleted.append('r2.h')
        publish_request.renames = Renames(
            {CellName('r2.h'): CellName('r21.h')})
        publish_request.tag = STABLE
        self.block.add_publication(publish_request)

        self.assertEquals({}, self.block.get_renames(0, 0))
        self.assertEquals({'r1.h': 'r11.h'}, self.block.get_renames(0, 1))
        self.assertEquals({
            'r2.h': 'r21.h',
            'r1.h': 'r11.h'
        }, self.block.get_renames(0, 2))
Exemplo n.º 3
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()))
Exemplo n.º 4
0
    def test_add_delete_cell(self):
        publish_request = PublishRequest(BlockVersion(self.brl, -1))
        publish_request.tag = STABLE
        publish_request.cells.append(SimpleCell('user/block/r1.h'))
        publish_request.contents['r1.h'] = Content(id_=None, load=None)
        self.block.add_publication(publish_request)

        self.assertEqual({'r1.h': ID(self.block_id + 0)},
                         self.block.cells.get_all_ids(0))
        self.assertEqual({'r1.h': ID(self.block_id + 0)},
                         self.block.contents.get_all_ids(0))

        publish_request = PublishRequest(BlockVersion(self.brl, 0))
        publish_request.tag = STABLE
        publish_request.deleted.append('r1.h')
        self.block.add_publication(publish_request)

        self.assertEqual({'r1.h': self.block_id + 0},
                         self.block.cells.get_all_ids(0))
        self.assertEqual({'r1.h': self.block_id + 0},
                         self.block.contents.get_all_ids(0))

        self.assertEqual({}, self.block.cells.get_all_ids(1))
        self.assertEqual({}, self.block.contents.get_all_ids(1))
        self.assertEqual({}, self.block.last_version_cells())
Exemplo n.º 5
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)
Exemplo n.º 6
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)
Exemplo n.º 7
0
    def test_add_modify_cell(self):
        publish_request = PublishRequest(BlockVersion(self.brl, -1))
        publish_request.cells.append(SimpleCell('user/block/r1.h'))
        publish_request.tag = STABLE
        self.block.add_publication(publish_request)

        self.assertEqual({'r1.h': ID(self.block_id + 0)}, self.block.cells.get_all_ids(0))

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

        self.assertEqual({'r1.h': ID(self.block_id + 0)}, self.block.cells.get_all_ids(0))
        self.assertEqual({'r1.h': ID(self.block_id + 1)}, self.block.cells.get_all_ids(1))
        self.assertEqual({'r1.h': ID(self.block_id + 1)}, self.block.last_version_cells())
Exemplo n.º 8
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)
Exemplo n.º 9
0
    def test_add_modify_cell(self):
        publish_request = PublishRequest(BlockVersion(self.brl, -1))
        publish_request.cells.append(SimpleCell('user/block/r1.h'))
        publish_request.tag = STABLE
        self.block.add_publication(publish_request)

        self.assertEqual({'r1.h': ID(self.block_id + 0)},
                         self.block.cells.get_all_ids(0))

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

        self.assertEqual({'r1.h': ID(self.block_id + 0)},
                         self.block.cells.get_all_ids(0))
        self.assertEqual({'r1.h': ID(self.block_id + 1)},
                         self.block.cells.get_all_ids(1))
        self.assertEqual({'r1.h': ID(self.block_id + 1)},
                         self.block.last_version_cells())
Exemplo n.º 10
0
    def test_get_version_by_tag(self):
        brl_block = BRLBlock('%s/%s/TestBlock/master' % (self.testUser.ID, self.testUser.ID))
        publish_request = PublishRequest(BlockVersion(brl_block, -1))
        publish_request.tag = STABLE
        publish_request.versiontag = 'mytag'
        publish_request.cells.append(SimpleCell(brl_block.block_name + 'r1.h'))
        publish_request.contents['r1.h'] = Content(id_=None, load=Blob('hola'))
        publish_request.deptable = BlockVersionTable()
        self.service.publish(publish_request)

        publish_request = PublishRequest(BlockVersion(brl_block, 0, 'mytag'))
        publish_request.tag = STABLE
        publish_request.versiontag = 'mytag'
        publish_request.cells.append(SimpleCell(brl_block.block_name + 'r12.h'))
        publish_request.contents['r2.h'] = Content(id_=None, load=Blob('hola'))
        publish_request.deptable = BlockVersionTable()
        self.service.publish(publish_request)

        block_version = self.service.get_version_by_tag(brl_block, 'mytag')
        self.assertEquals(1, block_version.time)
Exemplo n.º 11
0
    def test_add_delete_cell(self):
        publish_request = PublishRequest(BlockVersion(self.brl, -1))
        publish_request.tag = STABLE
        publish_request.cells.append(SimpleCell('user/block/r1.h'))
        publish_request.contents['r1.h'] = Content(id_=None, load=None)
        self.block.add_publication(publish_request)

        self.assertEqual({'r1.h': ID(self.block_id + 0)}, self.block.cells.get_all_ids(0))
        self.assertEqual({'r1.h': ID(self.block_id + 0)}, self.block.contents.get_all_ids(0))

        publish_request = PublishRequest(BlockVersion(self.brl, 0))
        publish_request.tag = STABLE
        publish_request.deleted.append('r1.h')
        self.block.add_publication(publish_request)

        self.assertEqual({'r1.h': self.block_id + 0}, self.block.cells.get_all_ids(0))
        self.assertEqual({'r1.h': self.block_id + 0}, self.block.contents.get_all_ids(0))

        self.assertEqual({}, self.block.cells.get_all_ids(1))
        self.assertEqual({}, self.block.contents.get_all_ids(1))
        self.assertEqual({}, self.block.last_version_cells())
Exemplo n.º 12
0
 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)
Exemplo n.º 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()))
Exemplo n.º 14
0
 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)
Exemplo n.º 15
0
def build_publish_request(biiapi, hive_holder, block_name, tag, msg,
                          versiontag, origin, biiout):
    block_name, dep_block_names = _check_input(hive_holder, block_name)
    _check_dep_blocks(biiapi, hive_holder, dep_block_names, biiout)
    block_holder = hive_holder[block_name]
    if not changevalidator.check_block_size(block_holder, biiout):
        raise PublishException("Block is too large to be published")

    parent = block_holder.parent
    _check_possible(parent, biiapi, biiout)

    if parent.time != -1:  # Update
        remote_block_holder = biiapi.get_block_holder(parent)
        base_resources = remote_block_holder.resources
        parent_delta_info = biiapi.get_version_delta_info(parent)
    else:  # New block
        base_resources = None
        parent_delta_info = None
        remote_block_holder = None

    changes = compare(base_resources, block_holder.resources)
    if not block_changed(changes, block_holder, remote_block_holder):
        if parent_delta_info and tag > parent_delta_info.tag:
            biiout.info('No changes, promoting tag %s -> %s' % (parent_delta_info.tag, tag))
            changes.modified.pop(BIICODE_FILE, None)
        else:
            raise UpToDatePublishException("Up to date, nothing to publish")
    changes.deduce_renames()

    request = PublishRequest()
    request.parent = parent
    request.changes = changes
    if parent_delta_info:
        request.parent_time = parent_delta_info.date
    assert all(bv.time is not None for bv in block_holder.requirements.itervalues())
    request.deptable = block_holder.requirements
    request.tag = tag
    request.msg = msg
    request.versiontag = versiontag
    request.origin = origin
    return request
Exemplo n.º 16
0
def build_publish_request(biiapi, hive_holder, block_name, tag, msg,
                          versiontag, origin, biiout):
    block_name, dep_block_names = _check_input(hive_holder, block_name)
    _check_dep_blocks(biiapi, hive_holder, dep_block_names, biiout)
    block_holder = hive_holder[block_name]
    if not changevalidator.check_block_size(block_holder, biiout):
        raise PublishException("Block is too large to be published")

    parent = block_holder.parent
    _check_possible(parent, biiapi, biiout)

    if parent.time != -1:  # Update
        remote_block_holder = biiapi.get_block_holder(parent)
        base_resources = remote_block_holder.resources
        parent_delta_info = biiapi.get_version_delta_info(parent)
    else:  # New block
        base_resources = None
        parent_delta_info = None
        remote_block_holder = None

    changes = compare(base_resources, block_holder.resources)
    if not block_changed(changes, block_holder, remote_block_holder):
        if parent_delta_info and tag > parent_delta_info.tag:
            biiout.info('No changes, promoting tag %s -> %s' % (parent_delta_info.tag, tag))
            changes.modified.pop(BIICODE_FILE, None)
        else:
            raise UpToDatePublishException("Up to date, nothing to publish")
    changes.deduce_renames()

    request = PublishRequest()
    request.parent = parent
    request.changes = changes
    if parent_delta_info:
        request.parent_time = parent_delta_info.date
    assert all(bv.time is not None for bv in block_holder.requirements.itervalues())
    request.deptable = block_holder.requirements
    request.tag = tag
    request.msg = msg
    request.versiontag = versiontag
    request.origin = origin
    return request
Exemplo n.º 17
0
    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)
Exemplo n.º 18
0
    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)
Exemplo n.º 19
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)