From 57fdb72c11f6d25e71788959b5fb054b692b60b0 Mon Sep 17 00:00:00 2001 From: Htut Khine Htay Win Date: Thu, 5 Sep 2024 00:46:13 +0000 Subject: [PATCH 1/6] Removed api files --- samples/samples/backup_sample.py | 133 ++++++++++++++++++++++++++ samples/samples/backup_sample_test.py | 47 +++++++++ samples/samples/snippets.py | 43 +++++++++ samples/samples/snippets_test.py | 9 ++ 4 files changed, 232 insertions(+) diff --git a/samples/samples/backup_sample.py b/samples/samples/backup_sample.py index d3c2c667c5..89afe9fabc 100644 --- a/samples/samples/backup_sample.py +++ b/samples/samples/backup_sample.py @@ -119,6 +119,55 @@ def create_backup_with_encryption_key( # [END spanner_create_backup_with_encryption_key] +# [START spanner_create_backup_with_MR_CMEK] +def create_backup_with_multiple_kms_keys( + instance_id, database_id, backup_id, kms_key_names +): + """Creates a backup for a database using multiple KMS keys(CMEK).""" + + from google.cloud.spanner_admin_database_v1 import \ + CreateBackupEncryptionConfig + from google.cloud.spanner_admin_database_v1.types import \ + backup as backup_pb + + spanner_client = spanner.Client() + database_admin_api = spanner_client.database_admin_api + + # Create a backup + expire_time = datetime.utcnow() + timedelta(days=14) + encryption_config = { + "encryption_type": CreateBackupEncryptionConfig.EncryptionType.CUSTOMER_MANAGED_ENCRYPTION, + "kms_key_names": kms_key_names, + } + request = backup_pb.CreateBackupRequest( + parent=database_admin_api.instance_path(spanner_client.project, instance_id), + backup_id=backup_id, + backup=backup_pb.Backup( + database=database_admin_api.database_path( + spanner_client.project, instance_id, database_id + ), + expire_time=expire_time, + ), + encryption_config=encryption_config, + ) + operation = database_admin_api.create_backup(request) + + # Wait for backup operation to complete. + backup = operation.result(2100) + + # Verify that the backup is ready. + assert backup.state == backup_pb.Backup.State.READY + + # Get the name, create time, backup size and encryption key. + print( + "Backup {} of size {} bytes was created at {} using encryption key {}".format( + backup.name, backup.size_bytes, backup.create_time, kms_key_names + ) + ) + + +# [END spanner_create_backup_with_MR_CMEK] + # [START spanner_restore_backup] def restore_database(instance_id, new_database_id, backup_id): @@ -200,6 +249,50 @@ def restore_database_with_encryption_key( # [END spanner_restore_backup_with_encryption_key] +# [START spanner_restore_backup_with_MR_CMEK] +def restore_database_with_multiple_kms_keys( + instance_id, new_database_id, backup_id, kms_key_names +): + """Restores a database from a backup using a Customer Managed Encryption Key (CMEK).""" + from google.cloud.spanner_admin_database_v1 import ( + RestoreDatabaseEncryptionConfig, RestoreDatabaseRequest) + + spanner_client = spanner.Client() + database_admin_api = spanner_client.database_admin_api + + # Start restoring an existing backup to a new database. + encryption_config = { + "encryption_type": RestoreDatabaseEncryptionConfig.EncryptionType.CUSTOMER_MANAGED_ENCRYPTION, + "kms_key_names": kms_key_names, + } + + request = RestoreDatabaseRequest( + parent=database_admin_api.instance_path(spanner_client.project, instance_id), + database_id=new_database_id, + backup=database_admin_api.backup_path( + spanner_client.project, instance_id, backup_id + ), + encryption_config=encryption_config, + ) + operation = database_admin_api.restore_database(request) + + # Wait for restore operation to complete. + db = operation.result(1600) + + # Newly created database has restore information. + restore_info = db.restore_info + print( + "Database {} restored to {} from backup {} with using encryption key {}.".format( + restore_info.backup_info.source_database, + new_database_id, + restore_info.backup_info.backup, + db.encryption_config.kms_key_names, + ) + ) + + +# [END spanner_restore_backup_with_MR_CMEK] + # [START spanner_cancel_backup_create] def cancel_backup(instance_id, database_id, backup_id): @@ -613,6 +706,46 @@ def copy_backup(instance_id, backup_id, source_backup_path): # [END spanner_copy_backup] +# [START spanner_copy_backup_with_MR_CMEK] +def copy_backup_with_multiple_kms_keys(instance_id, backup_id, source_backup_path, kms_key_names): + """Copies a backup.""" + + from google.cloud.spanner_admin_database_v1.types import \ + backup as backup_pb + + spanner_client = spanner.Client() + database_admin_api = spanner_client.database_admin_api + + # Create a backup object and wait for copy backup operation to complete. + expire_time = datetime.utcnow() + timedelta(days=14) + request = backup_pb.CopyBackupRequest( + parent=database_admin_api.instance_path(spanner_client.project, instance_id), + backup_id=backup_id, + source_backup=source_backup_path, + expire_time=expire_time, + kms_key_names=kms_key_names + ) + + operation = database_admin_api.copy_backup(request) + + # Wait for backup operation to complete. + copy_backup = operation.result(2100) + + # Verify that the copy backup is ready. + assert copy_backup.state == backup_pb.Backup.State.READY + + print( + "Backup {} of size {} bytes was created at {} with version time {}".format( + copy_backup.name, + copy_backup.size_bytes, + copy_backup.create_time, + copy_backup.version_time, + ) + ) + + +# [END spanner_copy_backup_with_MR_CMEK] + if __name__ == "__main__": # noqa: C901 parser = argparse.ArgumentParser( diff --git a/samples/samples/backup_sample_test.py b/samples/samples/backup_sample_test.py index 6d656c5545..9da82e5097 100644 --- a/samples/samples/backup_sample_test.py +++ b/samples/samples/backup_sample_test.py @@ -74,6 +74,19 @@ def test_copy_backup(capsys, instance_id, spanner_client): out, _ = capsys.readouterr() assert COPY_BACKUP_ID in out +@pytest.mark.dependency(name="copy_backup_with_multiple_kms_keys", depends=["create_backup"]) +def test_copy_backup_with_multiple_kms_keys(capsys, instance_id, spanner_client, kms_key_names): + source_backp_path = ( + spanner_client.project_name + + "/instances/" + + instance_id + + "/backups/" + + BACKUP_ID + ) + backup_sample.copy_backup_with_multiple_kms_keys(instance_id, COPY_BACKUP_ID, source_backup_path, kms_key_names) + out, _ = capsys.readouterr() + assert COPY_BACKUP_ID in out + @pytest.mark.dependency(name="create_backup_with_encryption_key") def test_create_backup_with_encryption_key( @@ -92,6 +105,23 @@ def test_create_backup_with_encryption_key( assert CMEK_BACKUP_ID in out assert kms_key_name in out +@pytest.mark.dependency(name="create_backup_with_multiple_kms_keys") +def test_create_backup_with_multiple_kms_keys( + capsys, + instance_id, + sample_database, + kms_key_names, +): + backup_sample.create_backup_with_multiple_kms_keys( + instance_id, + sample_database.database_id, + CMEK_BACKUP_ID, + kms_key_names, + ) + out, _ = capsys.readouterr() + assert CMEK_BACKUP_ID in out + assert kms_key_names in out + @pytest.mark.dependency(depends=["create_backup"]) @RetryErrors(exception=DeadlineExceeded, max_tries=2) @@ -120,6 +150,23 @@ def test_restore_database_with_encryption_key( assert CMEK_BACKUP_ID in out assert kms_key_name in out +@pytest.mark.dependency(depends=["restore_database_with_multiple_kms_keys"]) +@RetryErrors(exception=DeadlineExceeded, max_tries=2) +def test_restore_database_with_multiple_kms_keys( + capsys, + instance_id, + sample_database, + kms_key_names, +): + backup_sample.restore_database_with_multiple_kms_keys( + instance_id, CMEK_RESTORE_DB_ID, CMEK_BACKUP_ID, kms_key_name + ) + out, _ = capsys.readouterr() + assert (sample_database.database_id + " restored to ") in out + assert (CMEK_RESTORE_DB_ID + " from backup ") in out + assert CMEK_BACKUP_ID in out + assert kms_key_names in out + @pytest.mark.dependency(depends=["create_backup", "copy_backup"]) def test_list_backup_operations(capsys, instance_id, sample_database): diff --git a/samples/samples/snippets.py b/samples/samples/snippets.py index 93c8de4148..63755a26fa 100644 --- a/samples/samples/snippets.py +++ b/samples/samples/snippets.py @@ -341,6 +341,49 @@ def create_database_with_encryption_key(instance_id, database_id, kms_key_name): # [END spanner_create_database_with_encryption_key] +# [START spanner_create_database_with_MR_CMEK] +def spanner_create_database_with_multiple_kms_keys(instance_id, database_id, kms_key_names): + """Creates a database with tables using multiple KMS keys(CMEK).""" + from google.cloud.spanner_admin_database_v1 import EncryptionConfig + from google.cloud.spanner_admin_database_v1.types import \ + spanner_database_admin + + spanner_client = spanner.Client() + database_admin_api = spanner_client.database_admin_api + + request = spanner_database_admin.CreateDatabaseRequest( + parent=database_admin_api.instance_path(spanner_client.project, instance_id), + create_statement=f"CREATE DATABASE `{database_id}`", + extra_statements=[ + """CREATE TABLE Singers ( + SingerId INT64 NOT NULL, + FirstName STRING(1024), + LastName STRING(1024), + SingerInfo BYTES(MAX) + ) PRIMARY KEY (SingerId)""", + """CREATE TABLE Albums ( + SingerId INT64 NOT NULL, + AlbumId INT64 NOT NULL, + AlbumTitle STRING(MAX) + ) PRIMARY KEY (SingerId, AlbumId), + INTERLEAVE IN PARENT Singers ON DELETE CASCADE""", + ], + encryption_config=EncryptionConfig(kms_key_names=kms_key_names), + ) + + operation = database_admin_api.create_database(request=request) + + print("Waiting for operation to complete...") + database = operation.result(OPERATION_TIMEOUT_SECONDS) + + print( + "Database {} created with multiple KMS keys {}".format( + database.name, database.encryption_config.kms_key_names + ) + ) + + +# [END spanner_create_database_with_MR_CMEK] # [START spanner_create_database_with_default_leader] def create_database_with_default_leader(instance_id, database_id, default_leader): diff --git a/samples/samples/snippets_test.py b/samples/samples/snippets_test.py index 6657703fd1..0d05e681d5 100644 --- a/samples/samples/snippets_test.py +++ b/samples/samples/snippets_test.py @@ -227,6 +227,15 @@ def test_create_database_with_encryption_config( assert cmek_database_id in out assert kms_key_name in out +def test_spanner_create_database_with_multiple_kms_keys( + capsys, instance_id, cmek_database_id, kms_key_names +): + snippets.create_database_with_encryption_key( + instance_id, cmek_database_id, kms_key_names + ) + out, _ = capsys.readouterr() + assert cmek_database_id in out + assert kms_key_names in out def test_get_instance_config(capsys): instance_config = "nam6" From 88648752bd3e917995cf5aaacd317f3b434911c6 Mon Sep 17 00:00:00 2001 From: Htut Khine Htay Win Date: Thu, 5 Sep 2024 21:13:18 +0000 Subject: [PATCH 2/6] Fixed lint errors --- samples/samples/backup_sample.py | 58 ++++++++++++--------------- samples/samples/backup_sample_test.py | 21 +++++++--- 2 files changed, 40 insertions(+), 39 deletions(-) diff --git a/samples/samples/backup_sample.py b/samples/samples/backup_sample.py index 89afe9fabc..33962c4bb2 100644 --- a/samples/samples/backup_sample.py +++ b/samples/samples/backup_sample.py @@ -19,8 +19,8 @@ """ import argparse -import time from datetime import datetime, timedelta +import time from google.api_core import protobuf_helpers from google.cloud import spanner @@ -31,8 +31,7 @@ def create_backup(instance_id, database_id, backup_id, version_time): """Creates a backup for a database.""" - from google.cloud.spanner_admin_database_v1.types import \ - backup as backup_pb + from google.cloud.spanner_admin_database_v1.types import backup as backup_pb spanner_client = spanner.Client() database_admin_api = spanner_client.database_admin_api @@ -76,10 +75,8 @@ def create_backup_with_encryption_key( ): """Creates a backup for a database using a Customer Managed Encryption Key (CMEK).""" - from google.cloud.spanner_admin_database_v1 import \ - CreateBackupEncryptionConfig - from google.cloud.spanner_admin_database_v1.types import \ - backup as backup_pb + from google.cloud.spanner_admin_database_v1 import CreateBackupEncryptionConfig + from google.cloud.spanner_admin_database_v1.types import backup as backup_pb spanner_client = spanner.Client() database_admin_api = spanner_client.database_admin_api @@ -125,10 +122,8 @@ def create_backup_with_multiple_kms_keys( ): """Creates a backup for a database using multiple KMS keys(CMEK).""" - from google.cloud.spanner_admin_database_v1 import \ - CreateBackupEncryptionConfig - from google.cloud.spanner_admin_database_v1.types import \ - backup as backup_pb + from google.cloud.spanner_admin_database_v1 import CreateBackupEncryptionConfig + from google.cloud.spanner_admin_database_v1.types import backup as backup_pb spanner_client = spanner.Client() database_admin_api = spanner_client.database_admin_api @@ -211,7 +206,9 @@ def restore_database_with_encryption_key( ): """Restores a database from a backup using a Customer Managed Encryption Key (CMEK).""" from google.cloud.spanner_admin_database_v1 import ( - RestoreDatabaseEncryptionConfig, RestoreDatabaseRequest) + RestoreDatabaseEncryptionConfig, + RestoreDatabaseRequest, + ) spanner_client = spanner.Client() database_admin_api = spanner_client.database_admin_api @@ -255,7 +252,9 @@ def restore_database_with_multiple_kms_keys( ): """Restores a database from a backup using a Customer Managed Encryption Key (CMEK).""" from google.cloud.spanner_admin_database_v1 import ( - RestoreDatabaseEncryptionConfig, RestoreDatabaseRequest) + RestoreDatabaseEncryptionConfig, + RestoreDatabaseRequest, + ) spanner_client = spanner.Client() database_admin_api = spanner_client.database_admin_api @@ -296,8 +295,7 @@ def restore_database_with_multiple_kms_keys( # [START spanner_cancel_backup_create] def cancel_backup(instance_id, database_id, backup_id): - from google.cloud.spanner_admin_database_v1.types import \ - backup as backup_pb + from google.cloud.spanner_admin_database_v1.types import backup as backup_pb spanner_client = spanner.Client() database_admin_api = spanner_client.database_admin_api @@ -352,8 +350,7 @@ def cancel_backup(instance_id, database_id, backup_id): # [START spanner_list_backup_operations] def list_backup_operations(instance_id, database_id, backup_id): - from google.cloud.spanner_admin_database_v1.types import \ - backup as backup_pb + from google.cloud.spanner_admin_database_v1.types import backup as backup_pb spanner_client = spanner.Client() database_admin_api = spanner_client.database_admin_api @@ -407,8 +404,7 @@ def list_backup_operations(instance_id, database_id, backup_id): # [START spanner_list_database_operations] def list_database_operations(instance_id): - from google.cloud.spanner_admin_database_v1.types import \ - spanner_database_admin + from google.cloud.spanner_admin_database_v1.types import spanner_database_admin spanner_client = spanner.Client() database_admin_api = spanner_client.database_admin_api @@ -439,8 +435,7 @@ def list_database_operations(instance_id): # [START spanner_list_backups] def list_backups(instance_id, database_id, backup_id): - from google.cloud.spanner_admin_database_v1.types import \ - backup as backup_pb + from google.cloud.spanner_admin_database_v1.types import backup as backup_pb spanner_client = spanner.Client() database_admin_api = spanner_client.database_admin_api @@ -537,8 +532,7 @@ def list_backups(instance_id, database_id, backup_id): # [START spanner_delete_backup] def delete_backup(instance_id, backup_id): - from google.cloud.spanner_admin_database_v1.types import \ - backup as backup_pb + from google.cloud.spanner_admin_database_v1.types import backup as backup_pb spanner_client = spanner.Client() database_admin_api = spanner_client.database_admin_api @@ -579,8 +573,7 @@ def delete_backup(instance_id, backup_id): # [START spanner_update_backup] def update_backup(instance_id, backup_id): - from google.cloud.spanner_admin_database_v1.types import \ - backup as backup_pb + from google.cloud.spanner_admin_database_v1.types import backup as backup_pb spanner_client = spanner.Client() database_admin_api = spanner_client.database_admin_api @@ -619,8 +612,7 @@ def create_database_with_version_retention_period( ): """Creates a database with a version retention period.""" - from google.cloud.spanner_admin_database_v1.types import \ - spanner_database_admin + from google.cloud.spanner_admin_database_v1.types import spanner_database_admin spanner_client = spanner.Client() database_admin_api = spanner_client.database_admin_api @@ -671,8 +663,7 @@ def create_database_with_version_retention_period( def copy_backup(instance_id, backup_id, source_backup_path): """Copies a backup.""" - from google.cloud.spanner_admin_database_v1.types import \ - backup as backup_pb + from google.cloud.spanner_admin_database_v1.types import backup as backup_pb spanner_client = spanner.Client() database_admin_api = spanner_client.database_admin_api @@ -707,11 +698,12 @@ def copy_backup(instance_id, backup_id, source_backup_path): # [END spanner_copy_backup] # [START spanner_copy_backup_with_MR_CMEK] -def copy_backup_with_multiple_kms_keys(instance_id, backup_id, source_backup_path, kms_key_names): +def copy_backup_with_multiple_kms_keys( + instance_id, backup_id, source_backup_path, kms_key_names +): """Copies a backup.""" - from google.cloud.spanner_admin_database_v1.types import \ - backup as backup_pb + from google.cloud.spanner_admin_database_v1.types import backup as backup_pb spanner_client = spanner.Client() database_admin_api = spanner_client.database_admin_api @@ -723,7 +715,7 @@ def copy_backup_with_multiple_kms_keys(instance_id, backup_id, source_backup_pat backup_id=backup_id, source_backup=source_backup_path, expire_time=expire_time, - kms_key_names=kms_key_names + kms_key_names=kms_key_names, ) operation = database_admin_api.copy_backup(request) diff --git a/samples/samples/backup_sample_test.py b/samples/samples/backup_sample_test.py index 9da82e5097..1b12e8e36d 100644 --- a/samples/samples/backup_sample_test.py +++ b/samples/samples/backup_sample_test.py @@ -13,8 +13,8 @@ # limitations under the License. import uuid -import pytest from google.api_core.exceptions import DeadlineExceeded +import pytest from test_utils.retry import RetryErrors import backup_sample @@ -74,16 +74,23 @@ def test_copy_backup(capsys, instance_id, spanner_client): out, _ = capsys.readouterr() assert COPY_BACKUP_ID in out -@pytest.mark.dependency(name="copy_backup_with_multiple_kms_keys", depends=["create_backup"]) -def test_copy_backup_with_multiple_kms_keys(capsys, instance_id, spanner_client, kms_key_names): - source_backp_path = ( + +@pytest.mark.dependency( + name="copy_backup_with_multiple_kms_keys", depends=["create_backup"] +) +def test_copy_backup_with_multiple_kms_keys( + capsys, instance_id, spanner_client, kms_key_names +): + source_backup_path = ( spanner_client.project_name + "/instances/" + instance_id + "/backups/" + BACKUP_ID ) - backup_sample.copy_backup_with_multiple_kms_keys(instance_id, COPY_BACKUP_ID, source_backup_path, kms_key_names) + backup_sample.copy_backup_with_multiple_kms_keys( + instance_id, COPY_BACKUP_ID, source_backup_path, kms_key_names + ) out, _ = capsys.readouterr() assert COPY_BACKUP_ID in out @@ -105,6 +112,7 @@ def test_create_backup_with_encryption_key( assert CMEK_BACKUP_ID in out assert kms_key_name in out + @pytest.mark.dependency(name="create_backup_with_multiple_kms_keys") def test_create_backup_with_multiple_kms_keys( capsys, @@ -150,6 +158,7 @@ def test_restore_database_with_encryption_key( assert CMEK_BACKUP_ID in out assert kms_key_name in out + @pytest.mark.dependency(depends=["restore_database_with_multiple_kms_keys"]) @RetryErrors(exception=DeadlineExceeded, max_tries=2) def test_restore_database_with_multiple_kms_keys( @@ -159,7 +168,7 @@ def test_restore_database_with_multiple_kms_keys( kms_key_names, ): backup_sample.restore_database_with_multiple_kms_keys( - instance_id, CMEK_RESTORE_DB_ID, CMEK_BACKUP_ID, kms_key_name + instance_id, CMEK_RESTORE_DB_ID, CMEK_BACKUP_ID, kms_key_names ) out, _ = capsys.readouterr() assert (sample_database.database_id + " restored to ") in out From 8758cadf8250c247e7a66435932872d9351c5fa2 Mon Sep 17 00:00:00 2001 From: Htut Khine Htay Win Date: Wed, 11 Sep 2024 21:03:07 +0000 Subject: [PATCH 3/6] Fixed integration tests. --- samples/samples/backup_sample.py | 14 ++++- samples/samples/backup_sample_test.py | 68 +++++++++++---------- samples/samples/conftest.py | 43 ++++++++++++- samples/samples/snippets.py | 88 ++++++++++----------------- samples/samples/snippets_test.py | 28 ++++----- 5 files changed, 133 insertions(+), 108 deletions(-) diff --git a/samples/samples/backup_sample.py b/samples/samples/backup_sample.py index 33962c4bb2..fb90d266f0 100644 --- a/samples/samples/backup_sample.py +++ b/samples/samples/backup_sample.py @@ -704,18 +704,25 @@ def copy_backup_with_multiple_kms_keys( """Copies a backup.""" from google.cloud.spanner_admin_database_v1.types import backup as backup_pb + from google.cloud.spanner_admin_database_v1 import CopyBackupEncryptionConfig spanner_client = spanner.Client() database_admin_api = spanner_client.database_admin_api + encryption_config = { + "encryption_type": CopyBackupEncryptionConfig.EncryptionType.CUSTOMER_MANAGED_ENCRYPTION, + "kms_key_names": kms_key_names, + } + # Create a backup object and wait for copy backup operation to complete. expire_time = datetime.utcnow() + timedelta(days=14) request = backup_pb.CopyBackupRequest( - parent=database_admin_api.instance_path(spanner_client.project, instance_id), + parent=database_admin_api.instance_path(spanner_client.project, "hkw-nam3"), + # parent=database_admin_api.instance_path(spanner_client.project, instance_id), backup_id=backup_id, source_backup=source_backup_path, expire_time=expire_time, - kms_key_names=kms_key_names, + encryption_config=encryption_config, ) operation = database_admin_api.copy_backup(request) @@ -727,11 +734,12 @@ def copy_backup_with_multiple_kms_keys( assert copy_backup.state == backup_pb.Backup.State.READY print( - "Backup {} of size {} bytes was created at {} with version time {}".format( + "Backup {} of size {} bytes was created at {} with version time {} using encryption keys {}".format( copy_backup.name, copy_backup.size_bytes, copy_backup.create_time, copy_backup.version_time, + copy_backup.encryption_information, ) ) diff --git a/samples/samples/backup_sample_test.py b/samples/samples/backup_sample_test.py index 1b12e8e36d..9f9a65828a 100644 --- a/samples/samples/backup_sample_test.py +++ b/samples/samples/backup_sample_test.py @@ -75,26 +75,6 @@ def test_copy_backup(capsys, instance_id, spanner_client): assert COPY_BACKUP_ID in out -@pytest.mark.dependency( - name="copy_backup_with_multiple_kms_keys", depends=["create_backup"] -) -def test_copy_backup_with_multiple_kms_keys( - capsys, instance_id, spanner_client, kms_key_names -): - source_backup_path = ( - spanner_client.project_name - + "/instances/" - + instance_id - + "/backups/" - + BACKUP_ID - ) - backup_sample.copy_backup_with_multiple_kms_keys( - instance_id, COPY_BACKUP_ID, source_backup_path, kms_key_names - ) - out, _ = capsys.readouterr() - assert COPY_BACKUP_ID in out - - @pytest.mark.dependency(name="create_backup_with_encryption_key") def test_create_backup_with_encryption_key( capsys, @@ -114,21 +94,44 @@ def test_create_backup_with_encryption_key( @pytest.mark.dependency(name="create_backup_with_multiple_kms_keys") +@pytest.mark.skip(reason="skipped until backend changes are public") def test_create_backup_with_multiple_kms_keys( capsys, - instance_id, - sample_database, + multi_region_instance, + multi_region_instance_id, + sample_multi_region_database, kms_key_names, ): backup_sample.create_backup_with_multiple_kms_keys( - instance_id, - sample_database.database_id, + multi_region_instance_id, + sample_multi_region_database.database_id, CMEK_BACKUP_ID, kms_key_names, ) out, _ = capsys.readouterr() assert CMEK_BACKUP_ID in out - assert kms_key_names in out + assert kms_key_names[0] in out + assert kms_key_names[1] in out + assert kms_key_names[2] in out + + +@pytest.mark.dependency(depends=["create_backup_with_multiple_kms_keys"]) +@pytest.mark.skip(reason="skipped until backend changes are public") +def test_copy_backup_with_multiple_kms_keys( + capsys, multi_region_instance_id, spanner_client, kms_key_names +): + source_backup_path = ( + spanner_client.project_name + + "/instances/" + + multi_region_instance_id + + "/backups/" + + CMEK_BACKUP_ID + ) + backup_sample.copy_backup_with_multiple_kms_keys( + multi_region_instance_id, COPY_BACKUP_ID, source_backup_path, kms_key_names + ) + out, _ = capsys.readouterr() + assert COPY_BACKUP_ID in out @pytest.mark.dependency(depends=["create_backup"]) @@ -159,22 +162,25 @@ def test_restore_database_with_encryption_key( assert kms_key_name in out -@pytest.mark.dependency(depends=["restore_database_with_multiple_kms_keys"]) +@pytest.mark.dependency(depends=["create_backup_with_multiple_kms_keys"]) +@pytest.mark.skip(reason="skipped until backend changes are public") @RetryErrors(exception=DeadlineExceeded, max_tries=2) def test_restore_database_with_multiple_kms_keys( capsys, - instance_id, - sample_database, + multi_region_instance_id, + sample_multi_region_database, kms_key_names, ): backup_sample.restore_database_with_multiple_kms_keys( - instance_id, CMEK_RESTORE_DB_ID, CMEK_BACKUP_ID, kms_key_names + multi_region_instance_id, CMEK_RESTORE_DB_ID, CMEK_BACKUP_ID, kms_key_names ) out, _ = capsys.readouterr() - assert (sample_database.database_id + " restored to ") in out + assert (sample_multi_region_database.database_id + " restored to ") in out assert (CMEK_RESTORE_DB_ID + " from backup ") in out assert CMEK_BACKUP_ID in out - assert kms_key_names in out + assert kms_key_names[0] in out + assert kms_key_names[1] in out + assert kms_key_names[2] in out @pytest.mark.dependency(depends=["create_backup", "copy_backup"]) diff --git a/samples/samples/conftest.py b/samples/samples/conftest.py index 9810a41d45..9da852cfd9 100644 --- a/samples/samples/conftest.py +++ b/samples/samples/conftest.py @@ -16,11 +16,11 @@ import time import uuid -import pytest from google.api_core import exceptions from google.cloud import spanner_admin_database_v1 from google.cloud.spanner_admin_database_v1.types.common import DatabaseDialect from google.cloud.spanner_v1 import backup, client, database, instance +import pytest from test_utils import retry INSTANCE_CREATION_TIMEOUT = 560 # seconds @@ -240,8 +240,7 @@ def database_ddl(): return [] -@pytest.fixture(scope="module") -def sample_database( +def create_sample_database( spanner_client, sample_instance, database_id, database_ddl, database_dialect ): if database_dialect == DatabaseDialect.POSTGRESQL: @@ -281,6 +280,28 @@ def sample_database( sample_database.drop() +@pytest.fixture(scope="module") +def sample_database( + spanner_client, sample_instance, database_id, database_ddl, database_dialect +): + yield from create_sample_database( + spanner_client, sample_instance, database_id, database_ddl, database_dialect + ) + + +@pytest.fixture(scope="module") +def sample_multi_region_database( + spanner_client, multi_region_instance, database_id, database_ddl, database_dialect +): + yield from create_sample_database( + spanner_client, + multi_region_instance, + database_id, + database_ddl, + database_dialect, + ) + + @pytest.fixture(scope="module") def bit_reverse_sequence_database( spanner_client, sample_instance, bit_reverse_sequence_database_id, database_dialect @@ -321,3 +342,19 @@ def kms_key_name(spanner_client): "spanner-test-keyring", "spanner-test-cmek", ) + + +@pytest.fixture(scope="module") +def kms_key_names(spanner_client): + kms_key_names_list = [] + # this list of cloud-regions correspond to `nam3` + for cloud_region in ["us-east1", "us-east4", "us-central1"]: + kms_key_names_list.append( + "projects/{}/locations/{}/keyRings/{}/cryptoKeys/{}".format( + spanner_client.project, + cloud_region, + "spanner-test-keyring", + "spanner-test-cmek", + ) + ) + return kms_key_names_list diff --git a/samples/samples/snippets.py b/samples/samples/snippets.py index 63755a26fa..575beb38f1 100644 --- a/samples/samples/snippets.py +++ b/samples/samples/snippets.py @@ -33,6 +33,7 @@ from google.cloud.spanner_v1 import DirectedReadOptions, param_types from google.cloud.spanner_v1.data_types import JsonObject from google.protobuf import field_mask_pb2 # type: ignore + from testdata import singer_pb2 OPERATION_TIMEOUT_SECONDS = 240 @@ -41,8 +42,7 @@ # [START spanner_create_instance] def create_instance(instance_id): """Creates an instance.""" - from google.cloud.spanner_admin_instance_v1.types import \ - spanner_instance_admin + from google.cloud.spanner_admin_instance_v1.types import spanner_instance_admin spanner_client = spanner.Client() @@ -77,8 +77,7 @@ def create_instance(instance_id): # [START spanner_create_instance_with_processing_units] def create_instance_with_processing_units(instance_id, processing_units): """Creates an instance.""" - from google.cloud.spanner_admin_instance_v1.types import \ - spanner_instance_admin + from google.cloud.spanner_admin_instance_v1.types import spanner_instance_admin spanner_client = spanner.Client() @@ -137,8 +136,7 @@ def get_instance_config(instance_config): # [START spanner_list_instance_configs] def list_instance_config(): """Lists the available instance configurations.""" - from google.cloud.spanner_admin_instance_v1.types import \ - spanner_instance_admin + from google.cloud.spanner_admin_instance_v1.types import spanner_instance_admin spanner_client = spanner.Client() @@ -161,8 +159,7 @@ def list_instance_config(): # [START spanner_create_instance_partition] def create_instance_partition(instance_id, instance_partition_id): """Creates an instance partition.""" - from google.cloud.spanner_admin_instance_v1.types import \ - spanner_instance_admin + from google.cloud.spanner_admin_instance_v1.types import spanner_instance_admin spanner_client = spanner.Client() instance_admin_api = spanner_client.instance_admin_api @@ -191,8 +188,7 @@ def create_instance_partition(instance_id, instance_partition_id): # [START spanner_list_databases] def list_databases(instance_id): """Lists databases and their leader options.""" - from google.cloud.spanner_admin_database_v1.types import \ - spanner_database_admin + from google.cloud.spanner_admin_database_v1.types import spanner_database_admin spanner_client = spanner.Client() database_admin_api = spanner_client.database_admin_api @@ -215,8 +211,7 @@ def list_databases(instance_id): # [START spanner_create_database] def create_database(instance_id, database_id): """Creates a database and tables for sample data.""" - from google.cloud.spanner_admin_database_v1.types import \ - spanner_database_admin + from google.cloud.spanner_admin_database_v1.types import spanner_database_admin spanner_client = spanner.Client() database_admin_api = spanner_client.database_admin_api @@ -262,8 +257,7 @@ def create_database(instance_id, database_id): # [START spanner_update_database] def update_database(instance_id, database_id): """Updates the drop protection setting for a database.""" - from google.cloud.spanner_admin_database_v1.types import \ - spanner_database_admin + from google.cloud.spanner_admin_database_v1.types import spanner_database_admin spanner_client = spanner.Client() database_admin_api = spanner_client.database_admin_api @@ -301,8 +295,7 @@ def update_database(instance_id, database_id): def create_database_with_encryption_key(instance_id, database_id, kms_key_name): """Creates a database with tables using a Customer Managed Encryption Key (CMEK).""" from google.cloud.spanner_admin_database_v1 import EncryptionConfig - from google.cloud.spanner_admin_database_v1.types import \ - spanner_database_admin + from google.cloud.spanner_admin_database_v1.types import spanner_database_admin spanner_client = spanner.Client() database_admin_api = spanner_client.database_admin_api @@ -342,11 +335,10 @@ def create_database_with_encryption_key(instance_id, database_id, kms_key_name): # [END spanner_create_database_with_encryption_key] # [START spanner_create_database_with_MR_CMEK] -def spanner_create_database_with_multiple_kms_keys(instance_id, database_id, kms_key_names): +def create_database_with_multiple_kms_keys(instance_id, database_id, kms_key_names): """Creates a database with tables using multiple KMS keys(CMEK).""" from google.cloud.spanner_admin_database_v1 import EncryptionConfig - from google.cloud.spanner_admin_database_v1.types import \ - spanner_database_admin + from google.cloud.spanner_admin_database_v1.types import spanner_database_admin spanner_client = spanner.Client() database_admin_api = spanner_client.database_admin_api @@ -388,8 +380,7 @@ def spanner_create_database_with_multiple_kms_keys(instance_id, database_id, kms # [START spanner_create_database_with_default_leader] def create_database_with_default_leader(instance_id, database_id, default_leader): """Creates a database with tables with a default leader.""" - from google.cloud.spanner_admin_database_v1.types import \ - spanner_database_admin + from google.cloud.spanner_admin_database_v1.types import spanner_database_admin spanner_client = spanner.Client() database_admin_api = spanner_client.database_admin_api @@ -432,8 +423,7 @@ def create_database_with_default_leader(instance_id, database_id, default_leader # [START spanner_update_database_with_default_leader] def update_database_with_default_leader(instance_id, database_id, default_leader): """Updates a database with tables with a default leader.""" - from google.cloud.spanner_admin_database_v1.types import \ - spanner_database_admin + from google.cloud.spanner_admin_database_v1.types import spanner_database_admin spanner_client = spanner.Client() database_admin_api = spanner_client.database_admin_api @@ -725,8 +715,7 @@ def query_data_with_new_column(instance_id, database_id): def add_index(instance_id, database_id): """Adds a simple index to the example database.""" - from google.cloud.spanner_admin_database_v1.types import \ - spanner_database_admin + from google.cloud.spanner_admin_database_v1.types import spanner_database_admin spanner_client = spanner.Client() database_admin_api = spanner_client.database_admin_api @@ -829,8 +818,7 @@ def read_data_with_index(instance_id, database_id): def add_storing_index(instance_id, database_id): """Adds an storing index to the example database.""" - from google.cloud.spanner_admin_database_v1.types import \ - spanner_database_admin + from google.cloud.spanner_admin_database_v1.types import spanner_database_admin spanner_client = spanner.Client() database_admin_api = spanner_client.database_admin_api @@ -893,8 +881,7 @@ def read_data_with_storing_index(instance_id, database_id): def add_column(instance_id, database_id): """Adds a new column to the Albums table in the example database.""" - from google.cloud.spanner_admin_database_v1.types import \ - spanner_database_admin + from google.cloud.spanner_admin_database_v1.types import spanner_database_admin spanner_client = spanner.Client() database_admin_api = spanner_client.database_admin_api @@ -1056,8 +1043,7 @@ def read_only_transaction(instance_id, database_id): def create_table_with_timestamp(instance_id, database_id): """Creates a table with a COMMIT_TIMESTAMP column.""" - from google.cloud.spanner_admin_database_v1.types import \ - spanner_database_admin + from google.cloud.spanner_admin_database_v1.types import spanner_database_admin spanner_client = spanner.Client() database_admin_api = spanner_client.database_admin_api @@ -1124,8 +1110,7 @@ def insert_data_with_timestamp(instance_id, database_id): def add_timestamp_column(instance_id, database_id): """Adds a new TIMESTAMP column to the Albums table in the example database.""" - from google.cloud.spanner_admin_database_v1.types import \ - spanner_database_admin + from google.cloud.spanner_admin_database_v1.types import spanner_database_admin spanner_client = spanner.Client() database_admin_api = spanner_client.database_admin_api @@ -1228,8 +1213,7 @@ def query_data_with_timestamp(instance_id, database_id): def add_numeric_column(instance_id, database_id): """Adds a new NUMERIC column to the Venues table in the example database.""" - from google.cloud.spanner_admin_database_v1.types import \ - spanner_database_admin + from google.cloud.spanner_admin_database_v1.types import spanner_database_admin spanner_client = spanner.Client() database_admin_api = spanner_client.database_admin_api @@ -1296,8 +1280,7 @@ def add_json_column(instance_id, database_id): # instance_id = "your-spanner-instance" # database_id = "your-spanner-db-id" - from google.cloud.spanner_admin_database_v1.types import \ - spanner_database_admin + from google.cloud.spanner_admin_database_v1.types import spanner_database_admin spanner_client = spanner.Client() database_admin_api = spanner_client.database_admin_api @@ -2030,8 +2013,7 @@ def create_table_with_datatypes(instance_id, database_id): # instance_id = "your-spanner-instance" # database_id = "your-spanner-db-id" - from google.cloud.spanner_admin_database_v1.types import \ - spanner_database_admin + from google.cloud.spanner_admin_database_v1.types import spanner_database_admin spanner_client = spanner.Client() database_admin_api = spanner_client.database_admin_api @@ -2625,8 +2607,7 @@ def add_and_drop_database_roles(instance_id, database_id): # instance_id = "your-spanner-instance" # database_id = "your-spanner-db-id" - from google.cloud.spanner_admin_database_v1.types import \ - spanner_database_admin + from google.cloud.spanner_admin_database_v1.types import spanner_database_admin spanner_client = spanner.Client() database_admin_api = spanner_client.database_admin_api @@ -2692,8 +2673,7 @@ def list_database_roles(instance_id, database_id): # [START spanner_list_database_roles] # instance_id = "your-spanner-instance" # database_id = "your-spanner-db-id" - from google.cloud.spanner_admin_database_v1.types import \ - spanner_database_admin + from google.cloud.spanner_admin_database_v1.types import spanner_database_admin spanner_client = spanner.Client() database_admin_api = spanner_client.database_admin_api @@ -2775,8 +2755,7 @@ def enable_fine_grained_access( def create_table_with_foreign_key_delete_cascade(instance_id, database_id): """Creates a table with foreign key delete cascade action""" - from google.cloud.spanner_admin_database_v1.types import \ - spanner_database_admin + from google.cloud.spanner_admin_database_v1.types import spanner_database_admin spanner_client = spanner.Client() database_admin_api = spanner_client.database_admin_api @@ -2823,8 +2802,7 @@ def create_table_with_foreign_key_delete_cascade(instance_id, database_id): def alter_table_with_foreign_key_delete_cascade(instance_id, database_id): """Alters a table with foreign key delete cascade action""" - from google.cloud.spanner_admin_database_v1.types import \ - spanner_database_admin + from google.cloud.spanner_admin_database_v1.types import spanner_database_admin spanner_client = spanner.Client() database_admin_api = spanner_client.database_admin_api @@ -2862,8 +2840,7 @@ def alter_table_with_foreign_key_delete_cascade(instance_id, database_id): def drop_foreign_key_constraint_delete_cascade(instance_id, database_id): """Alter table to drop foreign key delete cascade action""" - from google.cloud.spanner_admin_database_v1.types import \ - spanner_database_admin + from google.cloud.spanner_admin_database_v1.types import spanner_database_admin spanner_client = spanner.Client() database_admin_api = spanner_client.database_admin_api @@ -2898,8 +2875,7 @@ def drop_foreign_key_constraint_delete_cascade(instance_id, database_id): def create_sequence(instance_id, database_id): """Creates the Sequence and insert data""" - from google.cloud.spanner_admin_database_v1.types import \ - spanner_database_admin + from google.cloud.spanner_admin_database_v1.types import spanner_database_admin spanner_client = spanner.Client() database_admin_api = spanner_client.database_admin_api @@ -2957,8 +2933,7 @@ def insert_customers(transaction): def alter_sequence(instance_id, database_id): """Alters the Sequence and insert data""" - from google.cloud.spanner_admin_database_v1.types import \ - spanner_database_admin + from google.cloud.spanner_admin_database_v1.types import spanner_database_admin spanner_client = spanner.Client() database_admin_api = spanner_client.database_admin_api @@ -3012,8 +2987,7 @@ def insert_customers(transaction): def drop_sequence(instance_id, database_id): """Drops the Sequence""" - from google.cloud.spanner_admin_database_v1.types import \ - spanner_database_admin + from google.cloud.spanner_admin_database_v1.types import spanner_database_admin spanner_client = spanner.Client() database_admin_api = spanner_client.database_admin_api @@ -3162,8 +3136,7 @@ def set_custom_timeout_and_retry(instance_id, database_id): # [START spanner_create_instance_with_autoscaling_config] def create_instance_with_autoscaling_config(instance_id): """Creates a Cloud Spanner instance with an autoscaling configuration.""" - from google.cloud.spanner_admin_instance_v1.types import \ - spanner_instance_admin + from google.cloud.spanner_admin_instance_v1.types import spanner_instance_admin spanner_client = spanner.Client() @@ -3226,6 +3199,7 @@ def add_proto_type_columns(instance_id, database_id): """Adds a new Proto Message column and Proto Enum column to the Singers table.""" import os + from google.cloud.spanner_admin_database_v1.types import spanner_database_admin dirname = os.path.dirname(__file__) diff --git a/samples/samples/snippets_test.py b/samples/samples/snippets_test.py index 0d05e681d5..c4242f63b8 100644 --- a/samples/samples/snippets_test.py +++ b/samples/samples/snippets_test.py @@ -15,10 +15,10 @@ import time import uuid -import pytest from google.api_core import exceptions from google.cloud import spanner from google.cloud.spanner_admin_database_v1.types.common import DatabaseDialect +import pytest from test_utils.retry import RetryErrors import snippets @@ -160,14 +160,6 @@ def test_create_instance_explicit(spanner_client, create_instance_id): retry_429(instance.delete)() -def test_create_database_explicit(sample_instance, create_database_id): - # Rather than re-use 'sample_database', we create a new database, to - # ensure that the 'create_database' snippet is tested. - snippets.create_database(sample_instance.instance_id, create_database_id) - database = sample_instance.database(create_database_id) - database.drop() - - def test_create_instance_with_processing_units(capsys, lci_instance_id): processing_units = 500 retry_429(snippets.create_instance_with_processing_units)( @@ -227,15 +219,23 @@ def test_create_database_with_encryption_config( assert cmek_database_id in out assert kms_key_name in out -def test_spanner_create_database_with_multiple_kms_keys( - capsys, instance_id, cmek_database_id, kms_key_names +@pytest.mark.skip(reason="skipped until backend changes are public") +def test_create_database_with_multiple_kms_keys( + capsys, + multi_region_instance, + multi_region_instance_id, + cmek_database_id, + kms_key_names, ): - snippets.create_database_with_encryption_key( - instance_id, cmek_database_id, kms_key_names + snippets.create_database_with_multiple_kms_keys( + multi_region_instance_id, cmek_database_id, kms_key_names ) out, _ = capsys.readouterr() assert cmek_database_id in out - assert kms_key_names in out + assert kms_key_names[0] in out + assert kms_key_names[1] in out + assert kms_key_names[2] in out + def test_get_instance_config(capsys): instance_config = "nam6" From ac9da9bc477473d304ff1c07d29c07b69601ddcf Mon Sep 17 00:00:00 2001 From: Htut Khine Htay Win Date: Wed, 11 Sep 2024 21:06:44 +0000 Subject: [PATCH 4/6] Fixed lint in snippets_test.py --- samples/samples/snippets_test.py | 1 + 1 file changed, 1 insertion(+) diff --git a/samples/samples/snippets_test.py b/samples/samples/snippets_test.py index c4242f63b8..815a9fb333 100644 --- a/samples/samples/snippets_test.py +++ b/samples/samples/snippets_test.py @@ -219,6 +219,7 @@ def test_create_database_with_encryption_config( assert cmek_database_id in out assert kms_key_name in out + @pytest.mark.skip(reason="skipped until backend changes are public") def test_create_database_with_multiple_kms_keys( capsys, From cd5830e36ccf4e1362a7beea80ad9e013dddf640 Mon Sep 17 00:00:00 2001 From: Htut Khine Htay Win Date: Thu, 12 Sep 2024 05:15:49 +0000 Subject: [PATCH 5/6] Resolved comments from reviewer --- samples/samples/backup_sample.py | 3 +-- samples/samples/backup_sample_test.py | 3 --- samples/samples/snippets_test.py | 9 ++++++++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/samples/samples/backup_sample.py b/samples/samples/backup_sample.py index fb90d266f0..e3a2b6957d 100644 --- a/samples/samples/backup_sample.py +++ b/samples/samples/backup_sample.py @@ -717,8 +717,7 @@ def copy_backup_with_multiple_kms_keys( # Create a backup object and wait for copy backup operation to complete. expire_time = datetime.utcnow() + timedelta(days=14) request = backup_pb.CopyBackupRequest( - parent=database_admin_api.instance_path(spanner_client.project, "hkw-nam3"), - # parent=database_admin_api.instance_path(spanner_client.project, instance_id), + parent=database_admin_api.instance_path(spanner_client.project, instance_id), backup_id=backup_id, source_backup=source_backup_path, expire_time=expire_time, diff --git a/samples/samples/backup_sample_test.py b/samples/samples/backup_sample_test.py index 9f9a65828a..a1969d2056 100644 --- a/samples/samples/backup_sample_test.py +++ b/samples/samples/backup_sample_test.py @@ -94,7 +94,6 @@ def test_create_backup_with_encryption_key( @pytest.mark.dependency(name="create_backup_with_multiple_kms_keys") -@pytest.mark.skip(reason="skipped until backend changes are public") def test_create_backup_with_multiple_kms_keys( capsys, multi_region_instance, @@ -116,7 +115,6 @@ def test_create_backup_with_multiple_kms_keys( @pytest.mark.dependency(depends=["create_backup_with_multiple_kms_keys"]) -@pytest.mark.skip(reason="skipped until backend changes are public") def test_copy_backup_with_multiple_kms_keys( capsys, multi_region_instance_id, spanner_client, kms_key_names ): @@ -163,7 +161,6 @@ def test_restore_database_with_encryption_key( @pytest.mark.dependency(depends=["create_backup_with_multiple_kms_keys"]) -@pytest.mark.skip(reason="skipped until backend changes are public") @RetryErrors(exception=DeadlineExceeded, max_tries=2) def test_restore_database_with_multiple_kms_keys( capsys, diff --git a/samples/samples/snippets_test.py b/samples/samples/snippets_test.py index 815a9fb333..8a4b571328 100644 --- a/samples/samples/snippets_test.py +++ b/samples/samples/snippets_test.py @@ -160,6 +160,14 @@ def test_create_instance_explicit(spanner_client, create_instance_id): retry_429(instance.delete)() +def test_create_database_explicit(sample_instance, create_database_id): + # Rather than re-use 'sample_database', we create a new database, to + # ensure that the 'create_database' snippet is tested. + snippets.create_database(sample_instance.instance_id, create_database_id) + database = sample_instance.database(create_database_id) + database.drop() + + def test_create_instance_with_processing_units(capsys, lci_instance_id): processing_units = 500 retry_429(snippets.create_instance_with_processing_units)( @@ -220,7 +228,6 @@ def test_create_database_with_encryption_config( assert kms_key_name in out -@pytest.mark.skip(reason="skipped until backend changes are public") def test_create_database_with_multiple_kms_keys( capsys, multi_region_instance, From 0764f83ad5668c8ff8b546660a6863d2361eb7a6 Mon Sep 17 00:00:00 2001 From: Sri Harsha CH Date: Wed, 16 Oct 2024 13:29:23 +0000 Subject: [PATCH 6/6] chore: skip tests since KMS keys are not added to test project --- samples/samples/backup_sample_test.py | 6 ++++++ samples/samples/snippets_test.py | 2 ++ 2 files changed, 8 insertions(+) diff --git a/samples/samples/backup_sample_test.py b/samples/samples/backup_sample_test.py index a1969d2056..5ab1e747ab 100644 --- a/samples/samples/backup_sample_test.py +++ b/samples/samples/backup_sample_test.py @@ -93,6 +93,8 @@ def test_create_backup_with_encryption_key( assert kms_key_name in out +@pytest.mark.skip(reason="skipped since the KMS keys are not added on test " + "project") @pytest.mark.dependency(name="create_backup_with_multiple_kms_keys") def test_create_backup_with_multiple_kms_keys( capsys, @@ -114,6 +116,8 @@ def test_create_backup_with_multiple_kms_keys( assert kms_key_names[2] in out +@pytest.mark.skip(reason="skipped since the KMS keys are not added on test " + "project") @pytest.mark.dependency(depends=["create_backup_with_multiple_kms_keys"]) def test_copy_backup_with_multiple_kms_keys( capsys, multi_region_instance_id, spanner_client, kms_key_names @@ -160,6 +164,8 @@ def test_restore_database_with_encryption_key( assert kms_key_name in out +@pytest.mark.skip(reason="skipped since the KMS keys are not added on test " + "project") @pytest.mark.dependency(depends=["create_backup_with_multiple_kms_keys"]) @RetryErrors(exception=DeadlineExceeded, max_tries=2) def test_restore_database_with_multiple_kms_keys( diff --git a/samples/samples/snippets_test.py b/samples/samples/snippets_test.py index 69944bcdb9..ba3c0bbfe7 100644 --- a/samples/samples/snippets_test.py +++ b/samples/samples/snippets_test.py @@ -233,6 +233,8 @@ def test_create_database_with_encryption_config( assert kms_key_name in out +@pytest.mark.skip(reason="skipped since the KMS keys are not added on test " + "project") def test_create_database_with_multiple_kms_keys( capsys, multi_region_instance,