Exemplo n.º 1
0
def convert_to_old_chunk(chunk_path,
                         account,
                         container,
                         path,
                         version,
                         content_id,
                         add_old_fullpath=False):
    chunk_id = chunk_path.rsplit('/', 1)[1]
    cid = cid_from_name(account, container)
    with open(chunk_path) as fd:
        xattr.setxattr(fd, 'user.' + CHUNK_XATTR_KEYS['chunk_id'],
                       chunk_id.encode('utf-8'))
        xattr.setxattr(fd, 'user.' + CHUNK_XATTR_KEYS['container_id'],
                       cid.encode('utf-8'))
        xattr.setxattr(fd, 'user.' + CHUNK_XATTR_KEYS['content_path'],
                       path.encode('utf-8'))
        xattr.setxattr(fd, 'user.' + CHUNK_XATTR_KEYS['content_version'],
                       str(version).encode('utf-8'))
        xattr.setxattr(fd, 'user.' + CHUNK_XATTR_KEYS['content_id'],
                       content_id.encode('utf-8'))
        if add_old_fullpath:
            old_fullpath = encode_old_fullpath(account, container, path,
                                               version).encode('utf-8')
            hasher = sha256()
            hasher.update(old_fullpath)
            hash_old_fullpath = hasher.hexdigest().upper()
            xattr.setxattr(fd, 'user.oio:' + hash_old_fullpath, old_fullpath)
        xattr.setxattr(fd, 'user.' + CHUNK_XATTR_KEYS['oio_version'], b'4.0')
        try:
            xattr.removexattr(
                fd, 'user.' + CHUNK_XATTR_CONTENT_FULLPATH_PREFIX + chunk_id)
        except IOError:
            pass
Exemplo n.º 2
0
def remove_fullpath_xattr(chunk_path):
    key = 'user.%s%s' % (CHUNK_XATTR_CONTENT_FULLPATH_PREFIX,
                         chunk_path.rsplit('/', 1)[-1])
    with open(chunk_path, 'w') as fd:
        try:
            xattr.removexattr(fd, key)
        except IOError as err:
            print('Failed to remove fullpath: %s' % err)
Exemplo n.º 3
0
    def test_xattr_bad_xattr_chunk_id(self):
        self.init_content()
        xattr.removexattr(
            self.chunk.path,
            'user.' + CHUNK_XATTR_CONTENT_FULLPATH_PREFIX + str(self.chunk.id))
        xattr.setxattr(
            self.chunk.path,
            'user.' + CHUNK_XATTR_CONTENT_FULLPATH_PREFIX + 'WRONG_ID',
            self.content.fullpath.encode('utf-8'))

        self.assertRaises(exc.FaultyChunk, self.auditor.chunk_audit,
                          self.chunk.path, self.chunk.id)
Exemplo n.º 4
0
    def test_index_chunk_missing_xattr(self):
        # create a fake chunk
        chunk_path, container_id, content_id, chunk_id = self._create_chunk(
            self.rawx_conf['path'])

        # remove mandatory xattr
        xattr.removexattr(chunk_path,
                          'user.' + chunk_xattr_keys['container_id'])

        # try to index the chunk
        indexer = BlobIndexer(self.conf)

        self.assertRaises(FaultyChunk, indexer.update_index, chunk_path)
        os.remove(chunk_path)
Exemplo n.º 5
0
    def test_index_chunk_missing_xattr(self):
        # create a fake chunk
        chunk_path, container_id, content_id, chunk_id = self._create_chunk(
            self.rawx_conf['path'])

        # remove mandatory xattr
        # pylint: disable=no-member
        xattr.removexattr(
            chunk_path, 'user.' + CHUNK_XATTR_KEYS['chunk_pos'])

        # try to index the chunk
        indexer = BlobIndexer(self.conf)

        self.assertRaises(FaultyChunk, indexer.update_index, chunk_path,
                          chunk_id)
        os.remove(chunk_path)
Exemplo n.º 6
0
def remove_xattr(chunk_path, key):
    with open(chunk_path, 'w') as fd:
        try:
            xattr.removexattr(fd, key)
        except IOError as err:
            print('Failed to remove fullpath: %s' % err)