Skip to content

Commit

Permalink
rebase branch with main
Browse files Browse the repository at this point in the history
  • Loading branch information
rahul2393 committed Feb 19, 2024
1 parent 4ec3c25 commit c1676a7
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
For more information, see the README.rst under /spanner.
"""

from datetime import datetime, timedelta
import time
from datetime import datetime, timedelta

from google.cloud import spanner
from google.cloud.spanner_admin_database_v1.types import backup as backup_pb
Expand Down Expand Up @@ -67,7 +67,8 @@ def create_backup_with_encryption_key(
instance_id, database_id, backup_id, kms_key_name
):
"""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 import \
CreateBackupEncryptionConfig

spanner_client = spanner.Client()
instance = spanner_client.instance(instance_id)
Expand Down Expand Up @@ -146,7 +147,8 @@ def restore_database_with_encryption_key(
instance_id, new_database_id, backup_id, kms_key_name
):
"""Restores a database from a backup using a Customer Managed Encryption Key (CMEK)."""
from google.cloud.spanner_admin_database_v1 import RestoreDatabaseEncryptionConfig
from google.cloud.spanner_admin_database_v1 import \
RestoreDatabaseEncryptionConfig

spanner_client = spanner.Client()
instance = spanner_client.instance(instance_id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
# limitations under the License.
import uuid

from google.api_core.exceptions import DeadlineExceeded
import backup_snippet
import pytest

import backup_sample
from google.api_core.exceptions import DeadlineExceeded
from test_utils.retry import RetryErrors


Expand Down Expand Up @@ -50,7 +49,7 @@ def test_create_backup(capsys, instance_id, sample_database):
results = snapshot.execute_sql("SELECT CURRENT_TIMESTAMP()")
version_time = list(results)[0][0]

backup_sample.create_backup(
backup_snippet.create_backup(
instance_id,
sample_database.database_id,
BACKUP_ID,
Expand All @@ -67,7 +66,7 @@ def test_create_backup_with_encryption_key(
sample_database,
kms_key_name,
):
backup_sample.create_backup_with_encryption_key(
backup_snippet.create_backup_with_encryption_key(
instance_id,
sample_database.database_id,
CMEK_BACKUP_ID,
Expand All @@ -81,8 +80,26 @@ def test_create_backup_with_encryption_key(
# @pytest.mark.dependency(depends=["create_backup"])
@RetryErrors(exception=DeadlineExceeded, max_tries=2)
def test_restore_database(capsys, instance_id, sample_database):
backup_sample.restore_database(instance_id, RESTORE_DB_ID, BACKUP_ID)
backup_snippet.restore_database(instance_id, RESTORE_DB_ID, BACKUP_ID)
out, _ = capsys.readouterr()
assert (sample_database.database_id + " restored to ") in out
assert (RESTORE_DB_ID + " from backup ") in out
assert BACKUP_ID in out


@pytest.mark.dependency(depends=["create_backup_with_encryption_key"])
@RetryErrors(exception=DeadlineExceeded, max_tries=2)
def test_restore_database_with_encryption_key(
capsys,
instance_id,
sample_database,
kms_key_name,
):
backup_snippet.restore_database_with_encryption_key(
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_name in out
5 changes: 2 additions & 3 deletions samples/samples/admin/pg_samples_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@

import uuid

import pg_samples as samples
import pytest
from google.api_core import exceptions
from google.cloud.spanner_admin_database_v1.types.common import DatabaseDialect
import pytest
from test_utils.retry import RetryErrors

import pg_samples as samples

CREATE_TABLE_SINGERS = """\
CREATE TABLE Singers (
SingerId BIGINT NOT NULL,
Expand Down
2 changes: 1 addition & 1 deletion samples/samples/admin/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import time

from google.cloud import spanner
from google.cloud.spanner_admin_instance_v1.types import spanner_instance_admin
from google.cloud.spanner_admin_database_v1.types import spanner_database_admin
from google.cloud.spanner_admin_instance_v1.types import spanner_instance_admin

OPERATION_TIMEOUT_SECONDS = 240

Expand Down
2 changes: 1 addition & 1 deletion samples/samples/admin/samples_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

import uuid

import pytest
from google.api_core import exceptions
from google.cloud.spanner_admin_database_v1.types.common import DatabaseDialect
import pytest
from test_utils.retry import RetryErrors

import samples
Expand Down

0 comments on commit c1676a7

Please sign in to comment.