diff --git a/.kokoro/lint/continuous.cfg.disabled b/.kokoro/lint/continuous.cfg similarity index 100% rename from .kokoro/lint/continuous.cfg.disabled rename to .kokoro/lint/continuous.cfg diff --git a/.kokoro/lint/periodic.cfg.disabled b/.kokoro/lint/periodic.cfg similarity index 100% rename from .kokoro/lint/periodic.cfg.disabled rename to .kokoro/lint/periodic.cfg diff --git a/.kokoro/lint/presubmit.cfg.disabled b/.kokoro/lint/presubmit.cfg similarity index 100% rename from .kokoro/lint/presubmit.cfg.disabled rename to .kokoro/lint/presubmit.cfg diff --git a/.kokoro/python3.10/continuous.cfg.disabled b/.kokoro/python3.10/continuous.cfg similarity index 100% rename from .kokoro/python3.10/continuous.cfg.disabled rename to .kokoro/python3.10/continuous.cfg diff --git a/.kokoro/python3.10/periodic.cfg.disabled b/.kokoro/python3.10/periodic.cfg similarity index 100% rename from .kokoro/python3.10/periodic.cfg.disabled rename to .kokoro/python3.10/periodic.cfg diff --git a/.kokoro/python3.10/presubmit.cfg.disabled b/.kokoro/python3.10/presubmit.cfg similarity index 100% rename from .kokoro/python3.10/presubmit.cfg.disabled rename to .kokoro/python3.10/presubmit.cfg diff --git a/.kokoro/python3.11/continuous.cfg.disabled b/.kokoro/python3.11/continuous.cfg similarity index 100% rename from .kokoro/python3.11/continuous.cfg.disabled rename to .kokoro/python3.11/continuous.cfg diff --git a/.kokoro/python3.11/periodic.cfg.disabled b/.kokoro/python3.11/periodic.cfg similarity index 100% rename from .kokoro/python3.11/periodic.cfg.disabled rename to .kokoro/python3.11/periodic.cfg diff --git a/.kokoro/python3.11/presubmit.cfg.disabled b/.kokoro/python3.11/presubmit.cfg similarity index 100% rename from .kokoro/python3.11/presubmit.cfg.disabled rename to .kokoro/python3.11/presubmit.cfg diff --git a/.kokoro/python3.12/continuous.cfg.disabled b/.kokoro/python3.12/continuous.cfg similarity index 100% rename from .kokoro/python3.12/continuous.cfg.disabled rename to .kokoro/python3.12/continuous.cfg diff --git a/.kokoro/python3.12/periodic.cfg.disabled b/.kokoro/python3.12/periodic.cfg similarity index 100% rename from .kokoro/python3.12/periodic.cfg.disabled rename to .kokoro/python3.12/periodic.cfg diff --git a/.kokoro/python3.12/presubmit.cfg.disabled b/.kokoro/python3.12/presubmit.cfg similarity index 100% rename from .kokoro/python3.12/presubmit.cfg.disabled rename to .kokoro/python3.12/presubmit.cfg diff --git a/.kokoro/python3.13/continuous.cfg.disabled b/.kokoro/python3.13/continuous.cfg similarity index 100% rename from .kokoro/python3.13/continuous.cfg.disabled rename to .kokoro/python3.13/continuous.cfg diff --git a/.kokoro/python3.13/periodic.cfg.disabled b/.kokoro/python3.13/periodic.cfg similarity index 100% rename from .kokoro/python3.13/periodic.cfg.disabled rename to .kokoro/python3.13/periodic.cfg diff --git a/.kokoro/python3.13/presubmit.cfg.disabled b/.kokoro/python3.13/presubmit.cfg similarity index 100% rename from .kokoro/python3.13/presubmit.cfg.disabled rename to .kokoro/python3.13/presubmit.cfg diff --git a/.kokoro/python3.14/continuous.cfg.disabled b/.kokoro/python3.14/continuous.cfg similarity index 100% rename from .kokoro/python3.14/continuous.cfg.disabled rename to .kokoro/python3.14/continuous.cfg diff --git a/.kokoro/python3.14/periodic.cfg.disabled b/.kokoro/python3.14/periodic.cfg similarity index 100% rename from .kokoro/python3.14/periodic.cfg.disabled rename to .kokoro/python3.14/periodic.cfg diff --git a/.kokoro/python3.14/presubmit.cfg.disabled b/.kokoro/python3.14/presubmit.cfg similarity index 100% rename from .kokoro/python3.14/presubmit.cfg.disabled rename to .kokoro/python3.14/presubmit.cfg diff --git a/.kokoro/python3.8/continuous.cfg.disabled b/.kokoro/python3.8/continuous.cfg similarity index 100% rename from .kokoro/python3.8/continuous.cfg.disabled rename to .kokoro/python3.8/continuous.cfg diff --git a/.kokoro/python3.8/periodic.cfg.disabled b/.kokoro/python3.8/periodic.cfg similarity index 100% rename from .kokoro/python3.8/periodic.cfg.disabled rename to .kokoro/python3.8/periodic.cfg diff --git a/.kokoro/python3.8/presubmit.cfg.disabled b/.kokoro/python3.8/presubmit.cfg similarity index 100% rename from .kokoro/python3.8/presubmit.cfg.disabled rename to .kokoro/python3.8/presubmit.cfg diff --git a/.kokoro/python3.9/continuous.cfg.disabled b/.kokoro/python3.9/continuous.cfg similarity index 100% rename from .kokoro/python3.9/continuous.cfg.disabled rename to .kokoro/python3.9/continuous.cfg diff --git a/.kokoro/python3.9/periodic.cfg.disabled b/.kokoro/python3.9/periodic.cfg similarity index 100% rename from .kokoro/python3.9/periodic.cfg.disabled rename to .kokoro/python3.9/periodic.cfg diff --git a/.kokoro/python3.9/presubmit.cfg.disabled b/.kokoro/python3.9/presubmit.cfg similarity index 100% rename from .kokoro/python3.9/presubmit.cfg.disabled rename to .kokoro/python3.9/presubmit.cfg diff --git a/storage/samples/snippets/snippets_test.py b/storage/samples/snippets/snippets_test.py index 1d3c8c1c442..1ac926a5623 100644 --- a/storage/samples/snippets/snippets_test.py +++ b/storage/samples/snippets/snippets_test.py @@ -15,10 +15,10 @@ import asyncio import io import os +import sys import tempfile import time import uuid -import sys from google.cloud import storage import google.cloud.exceptions @@ -668,7 +668,10 @@ def test_object_get_kms_key(test_bucket): def test_storage_compose_file(test_bucket): - source_files = ["test_upload_blob_1", "test_upload_blob_2"] + source_files = [ + f"test_upload_blob_1_{uuid.uuid4().hex}", + f"test_upload_blob_2_{uuid.uuid4().hex}", + ] for source in source_files: blob = test_bucket.blob(source) blob.upload_from_string(source) @@ -684,6 +687,35 @@ def test_storage_compose_file(test_bucket): assert composed.decode("utf-8") == source_files[0] + source_files[1] + # Verify sources are NOT deleted + assert test_bucket.blob(source_files[0]).exists() + assert test_bucket.blob(source_files[1]).exists() + + +def test_storage_compose_file_delete_source(test_bucket): + source_files = [ + f"test_upload_blob_1_{uuid.uuid4().hex}", + f"test_upload_blob_2_{uuid.uuid4().hex}", + ] + for source in source_files: + blob = test_bucket.blob(source) + blob.upload_from_string(source) + + with tempfile.NamedTemporaryFile() as dest_file: + destination = storage_compose_file.compose_file( + test_bucket.name, + source_files[0], + source_files[1], + dest_file.name, + delete_source_objects=True, + ) + composed = destination.download_as_bytes() + assert composed.decode("utf-8") == source_files[0] + source_files[1] + + # Verify sources are deleted + assert not test_bucket.blob(source_files[0]).exists() + assert not test_bucket.blob(source_files[1]).exists() + def test_cors_configuration(test_bucket, capsys): bucket = storage_cors_configuration.cors_configuration(test_bucket) diff --git a/storage/samples/snippets/storage_compose_file.py b/storage/samples/snippets/storage_compose_file.py index e673912725b..4c675da1e29 100644 --- a/storage/samples/snippets/storage_compose_file.py +++ b/storage/samples/snippets/storage_compose_file.py @@ -20,7 +20,13 @@ from google.cloud import storage -def compose_file(bucket_name, first_blob_name, second_blob_name, destination_blob_name): +def compose_file( + bucket_name, + first_blob_name, + second_blob_name, + destination_blob_name, + delete_source_objects=False, +): """Concatenate source blobs into destination blob.""" # bucket_name = "your-bucket-name" # first_blob_name = "first-object-name" @@ -44,11 +50,22 @@ def compose_file(bucket_name, first_blob_name, second_blob_name, destination_blo # There is also an `if_source_generation_match` parameter, which is not used in this example. destination_generation_match_precondition = 0 - destination.compose(sources, if_generation_match=destination_generation_match_precondition) + destination.compose( + sources, + if_generation_match=destination_generation_match_precondition, + delete_source_objects=delete_source_objects, + ) + deletion_message = ( + " and the source objects were deleted." if delete_source_objects else "." + ) print( - "New composite object {} in the bucket {} was created by combining {} and {}".format( - destination_blob_name, bucket_name, first_blob_name, second_blob_name + "New composite object {} in the bucket {} was created by combining {} and {}{}".format( + destination_blob_name, + bucket_name, + first_blob_name, + second_blob_name, + deletion_message, ) ) return destination