示例#1
0
def delete_checkpoints(manager: storage.StorageManager, to_delete: List[str],
                       dry_run: bool) -> None:
    """
    Delete some of the checkpoints associated with a single experiment.
    """
    logging.info("Deleting {} checkpoints".format(len(to_delete)))

    for storage_id in to_delete:
        if not dry_run:
            logging.info(f"Deleting checkpoint {storage_id}")
            manager.delete(storage_id)
        else:
            logging.info(f"Dry run: deleting checkpoint {storage_id}")
示例#2
0
def run_storage_lifecycle_test(
    manager: storage.StorageManager,
    post_delete_cb: Optional[Callable] = None,
) -> None:
    checkpoints = []
    for _ in range(2):
        storage_id = str(uuid.uuid4())
        with manager.store_path(storage_id) as path:
            create_checkpoint(path)
            checkpoints.append(storage_id)

    for storage_id in checkpoints:
        # Load checkpoint.
        with manager.restore_path(storage_id) as path:
            validate_checkpoint(path)
        # Delete.
        manager.delete(storage_id)
        # Ensure it is gone.
        with pytest.raises(errors.CheckpointNotFound):
            with manager.restore_path(storage_id) as path:
                pass
        # Allow for backend-specific inspection.
        if post_delete_cb is not None:
            post_delete_cb(storage_id)

    # Again, using upload/download instead of store_path/restore_path.
    checkpoints = []
    for _ in range(2):
        storage_id = str(uuid.uuid4())
        path = pathlib.Path(f"/tmp/storage_lifecycle_test-{storage_id}")
        try:
            create_checkpoint(path)
            manager.upload(path, storage_id)
            checkpoints.append(storage_id)
        finally:
            shutil.rmtree(path, ignore_errors=True)

    for storage_id in checkpoints:
        path = pathlib.Path(f"/tmp/storage_lifecycle_test-{storage_id}")
        try:
            manager.download(storage_id, path)
            validate_checkpoint(path)
        finally:
            shutil.rmtree(path, ignore_errors=True)
        manager.delete(storage_id)
        with pytest.raises(errors.CheckpointNotFound):
            manager.download(storage_id, path)
        if post_delete_cb is not None:
            post_delete_cb(storage_id)
示例#3
0
def delete_checkpoints(manager: storage.StorageManager,
                       to_delete: List[Dict[str, Any]], dry_run: bool) -> None:
    """
    Delete some of the checkpoints associated with a single
    experiment. `to_delete` is a list of two-element dicts,
    {"uuid": str, "resources": List[str]}.
    """
    logging.info("Deleting {} checkpoints".format(len(to_delete)))

    for record in to_delete:
        metadata = storage.StorageMetadata.from_json(record)
        if not dry_run:
            logging.info("Deleting checkpoint {}".format(metadata))
            manager.delete(metadata)
        else:
            logging.info("Dry run: deleting checkpoint {}".format(
                metadata.storage_id))