Ejemplo n.º 1
0
    def test_large_cell_reject(self):
        self.load.binary = bytearray(BII_FILE_SIZE_LIMIT)
        files = {"user/block/file": (None, self.load)}

        biiout = OutputStream()
        changevalidator.remove_large_cells(files, biiout)
        self.assertEquals(0, len(files))
        self.assertEquals("WARN: File user/block/file is bigger "
                          "than %s: discarded\n" % BII_FILE_SIZE_LIMIT_STR,
                          str(biiout))
    def test_size_reject_accept(self):
        load = Blob("x" * BII_FILE_SIZE_LIMIT)
        load2 = Blob("x" * (BII_FILE_SIZE_LIMIT - 1))
        files = {"user/block/filelarge":  (None, load),
                 "user/block/filesmall": (None, load2)}

        biiout = OutputStream()
        changevalidator.remove_large_cells(files, biiout)
        self.assertEquals(1, len(files))
        self.assertEquals("WARN: File user/block/filelarge is "
                          "bigger than %s: discarded\n" % BII_FILE_SIZE_LIMIT_STR,
                          str(biiout))
        self.assertIn("user/block/filesmall", files)
Ejemplo n.º 3
0
    def test_size_reject_accept(self):
        self.load.binary = bytearray(BII_FILE_SIZE_LIMIT)
        load2 = Blob()
        load2.binary = bytearray(BII_FILE_SIZE_LIMIT - 1)
        files = {"user/block/filelarge":  (None, self.load),
                 "user/block/filesmall": (None, load2)}

        biiout = OutputStream()
        changevalidator.remove_large_cells(files, biiout)
        self.assertEquals(1, len(files))
        self.assertEquals("WARN: File user/block/filelarge is "
                          "bigger than %s: discarded\n" % BII_FILE_SIZE_LIMIT_STR,
                          str(biiout))
        self.assertIn("user/block/filesmall", files)
Ejemplo n.º 4
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)