Repository navigation
Conversation
Restoring a Spanner backup into a multi-region CMEK database passes regional KMS keys via RestoreDatabaseEncryptionConfig.kms_key_names. Add spanner_restore_backup_with_mr_cmek.
|
Here is the summary of changes. You are about to add 1 region tag.
This comment is generated by snippet-bot.
|
There was a problem hiding this comment.
Code Review
This pull request introduces a new script and associated tests for restoring a Spanner backup into a multi-region CMEK database. The implementation includes CLI entry points and comprehensive unit and live integration tests. The feedback recommends safely retrieving environment variables in the live integration test using os.environ.get and skipping the test if they are missing, preventing potential KeyError exceptions in environments where these variables are not configured.
| mr_inst = os.environ["SPANNER_MR_INSTANCE_ID"] | ||
| mr_bkp = os.environ["SPANNER_MR_BACKUP_ID"] | ||
| mr_keys = [k for k in os.environ["SPANNER_MR_KMS_KEY_NAMES"].split(",") if k] |
There was a problem hiding this comment.
The live integration test directly accesses os.environ for multi-region CMEK variables (SPANNER_MR_INSTANCE_ID, SPANNER_MR_BACKUP_ID, SPANNER_MR_KMS_KEY_NAMES). If these are not set (which is common in standard/single-region test environments), the test will fail with a KeyError and block the test suite. It is safer to check for their presence and skip the test if they are missing.
mr_inst = os.environ.get("SPANNER_MR_INSTANCE_ID")
mr_bkp = os.environ.get("SPANNER_MR_BACKUP_ID")
mr_keys_env = os.environ.get("SPANNER_MR_KMS_KEY_NAMES")
if not mr_inst or not mr_bkp or not mr_keys_env:
pytest.skip(
"SPANNER_MR_INSTANCE_ID, SPANNER_MR_BACKUP_ID, and "
"SPANNER_MR_KMS_KEY_NAMES environment variables must be set "
"to run this live test."
)
mr_keys = [k for k in mr_keys_env.split(",") if k]There was a problem hiding this comment.
Good catch, done: the live test now checks for its required environment variables up front and skips with a clear message when one is missing, instead of failing with a KeyError (99ce713).
Problem: review of this sample identified correctness and robustness improvements in the sample and its tests. Solution: apply the accepted review suggestions and extend the tests to cover the updated behavior. Details are in the review thread replies. Files updated: - spanner/backups/tests/restore_backup_with_mr_cmek_test.py
Description
Adds
spanner_restore_backup_with_mr_cmekrestoring a backup into a multi-region CMEK Spanner database.Checklist
Testing
Compliance & Style
spanner/, which the default repository owners cover.Post-Approval Actions