def to_delete(request: Any, manager: storage.StorageManager) -> List[str]: storage_ids = [] for _ in range(request.param): storage_id = str(uuid.uuid4()) with manager.store_path(storage_id) as path: storage_util.create_checkpoint(path) storage_ids.append(storage_id) assert len(os.listdir(manager._base_path)) == request.param return storage_ids
def to_delete(request: Any, manager: storage.StorageManager) -> List[Dict[str, Any]]: metadata = [] for _ in range(request.param): with manager.store_path() as (storage_id, path): storage_util.create_checkpoint(path) metadata.append( storage.StorageMetadata(storage_id, manager._list_directory(path))) assert len(os.listdir(manager._base_path)) == request.param return [simplejson.loads(util.json_encode(m)) for m in metadata]
def test_s3_lifecycle(manager: storage.S3StorageManager) -> None: assert len(os.listdir(manager._base_path)) == 0 checkpoints = [] for _ in range(5): with manager.store_path() as (storage_id, path): # Ensure no checkpoint directories exist yet. assert len(os.listdir(manager._base_path)) == 0 util.create_checkpoint(path) metadata = storage.StorageMetadata(storage_id, manager._list_directory(path)) checkpoints.append(metadata) assert set(metadata.resources) == set(util.EXPECTED_FILES.keys()) for metadata in checkpoints: # Load every checkpoint: with manager.restore_path(metadata) as path: util.validate_checkpoint(path) manager.delete(metadata) with pytest.raises(KeyError): with manager.restore_path(metadata) as path: pass
def test_checkpoint_lifecycle(manager: storage.SharedFSStorageManager) -> None: assert len(os.listdir(manager._base_path)) == 0 checkpoints = [] for index in range(5): with manager.store_path() as (storage_id, path): # Ensure no checkpoint directories exist yet. assert len(os.listdir(manager._base_path)) == index util.create_checkpoint(path) metadata = storage.StorageMetadata(storage_id, manager._list_directory(path)) checkpoints.append(metadata) assert set(metadata.resources) == set(util.EXPECTED_FILES.keys()) assert len(os.listdir(manager._base_path)) == 5 for index in reversed(range(5)): metadata = checkpoints[index] assert metadata.storage_id in os.listdir(manager._base_path) with manager.restore_path(metadata) as path: util.validate_checkpoint(path) manager.delete(metadata) assert metadata.storage_id not in os.listdir(manager._base_path) assert len(os.listdir(manager._base_path)) == index