def test_rebuild_old_chunk(self): for c in self.chunks: convert_to_old_chunk( self._chunk_path(c), self.account, self.container, self.path, self.version, self.content_id) chunk = random.choice(self.chunks) chunk_volume = chunk['url'].split('/')[2] chunk_id = chunk['url'].split('/')[3] chunk_headers, chunk_stream = self.blob_client.chunk_get( chunk['url'], check_headers=False) os.remove(self._chunk_path(chunk)) chunks_kept = list(self.chunks) chunks_kept.remove(chunk) conf = self.conf.copy() conf['allow_same_rawx'] = True rebuilder = BlobRebuilder(conf, service_id=chunk_volume) rebuilder_worker = rebuilder.create_worker(None, None) rebuilder_worker._process_item( (self.ns, self.cid, self.content_id, chunk_id)) _, new_chunks = self.api.object_locate( self.account, self.container, self.path) new_chunk = list(new_chunks) self.assertEqual(len(new_chunks), len(chunks_kept) + 1) url_kept = [c['url'] for c in chunks_kept] new_chunk = None for c in new_chunks: if c['url'] not in url_kept: self.assertIsNone(new_chunk) new_chunk = c self.assertNotEqual(chunk['real_url'], new_chunk['real_url']) self.assertNotEqual(chunk['url'], new_chunk['url']) self.assertEqual(chunk['pos'], new_chunk['pos']) self.assertEqual(chunk['size'], new_chunk['size']) self.assertEqual(chunk['hash'], new_chunk['hash']) new_chunk_headers, new_chunk_stream = self.blob_client.chunk_get( new_chunk['url']) chunk_data = b''.join(chunk_stream) new_chunk_data = b''.join(new_chunk_stream) self.assertEqual(chunk_data, new_chunk_data) fullpath = encode_fullpath(self.account, self.container, self.path, self.version, self.content_id) self.assertEqual(fullpath, new_chunk_headers['full_path']) del new_chunk_headers['full_path'] self.assertNotEqual(chunk_headers['chunk_id'], new_chunk_headers['chunk_id']) new_chunk_id = new_chunk['url'].split('/')[3] self.assertEqual(new_chunk_id, new_chunk_headers['chunk_id']) del chunk_headers['chunk_id'] del new_chunk_headers['chunk_id'] self.assertEqual(OIO_VERSION, new_chunk_headers['oio_version']) del chunk_headers['oio_version'] del new_chunk_headers['oio_version'] self.assertEqual(chunk_headers, new_chunk_headers)
def test_rebuild_old_chunk(self): for c in self.chunks: convert_to_old_chunk(self._chunk_path(c), self.account, self.container, self.path, self.version, self.content_id) chunk = random.choice(self.chunks) chunk_volume = chunk['url'].split('/')[2] chunk_id = chunk['url'].split('/')[3] chunk_headers, chunk_stream = self.blob_client.chunk_get( chunk['url'], check_headers=False) os.remove(self._chunk_path(chunk)) chunks_kept = list(self.chunks) chunks_kept.remove(chunk) conf = self.conf.copy() conf['allow_same_rawx'] = True rebuilder = BlobRebuilder(conf, service_id=chunk_volume) rebuilder_worker = rebuilder.create_worker(None, None) rebuilder_worker._process_item( (self.ns, self.cid, self.content_id, chunk_id)) _, new_chunks = self.api.object_locate(self.account, self.container, self.path) new_chunk = list(new_chunks) self.assertEqual(len(new_chunks), len(chunks_kept) + 1) url_kept = [c['url'] for c in chunks_kept] new_chunk = None for c in new_chunks: if c['url'] not in url_kept: self.assertIsNone(new_chunk) new_chunk = c # Cannot check if the URL is different: it may be the same since we # generate predictible chunk IDs. # self.assertNotEqual(chunk['real_url'], new_chunk['real_url']) # self.assertNotEqual(chunk['url'], new_chunk['url']) self.assertEqual(chunk['pos'], new_chunk['pos']) self.assertEqual(chunk['size'], new_chunk['size']) self.assertEqual(chunk['hash'], new_chunk['hash']) new_chunk_headers, new_chunk_stream = self.blob_client.chunk_get( new_chunk['url']) chunk_data = b''.join(chunk_stream) new_chunk_data = b''.join(new_chunk_stream) self.assertEqual(chunk_data, new_chunk_data) fullpath = encode_fullpath(self.account, self.container, self.path, self.version, self.content_id) self.assertEqual(fullpath, new_chunk_headers['full_path']) del new_chunk_headers['full_path'] # Since we generate predictible chunk IDs, they can be equal # self.assertNotEqual(chunk_headers['chunk_id'], # new_chunk_headers['chunk_id']) # We could compare the modification time of the chunks, # but unfortunately they have a 1s resolution... # self.assertNotEqual(chunk_headers['chunk_mtime'], # new_chunk_headers['chunk_mtime']) new_chunk_id = new_chunk['url'].split('/')[3] self.assertEqual(new_chunk_id, new_chunk_headers['chunk_id']) del chunk_headers['chunk_id'] del new_chunk_headers['chunk_id'] self.assertEqual(OIO_VERSION, new_chunk_headers['oio_version']) del chunk_headers['oio_version'] del new_chunk_headers['oio_version'] del chunk_headers['chunk_mtime'] del new_chunk_headers['chunk_mtime'] self.assertEqual(chunk_headers, new_chunk_headers)