Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: harden old instance cleanup against NotFound #471

Merged
merged 1 commit into from
Jul 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions samples/samples/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ def spanner_client():
return client.Client()


def scrub_instance_ignore_not_found(to_scrub):
"""Helper for func:`cleanup_old_instances`"""
try:
for backup_pb in to_scrub.list_backups():
backup.Backup.from_pb(backup_pb, to_scrub).delete()

to_scrub.delete()
except exceptions.NotFound:
pass


@pytest.fixture(scope="session")
def cleanup_old_instances(spanner_client):
"""Delete instances, created by samples, that are older than an hour."""
Expand All @@ -54,11 +65,7 @@ def cleanup_old_instances(spanner_client):
create_time = int(inst.labels["created"])

if create_time <= cutoff:

for backup_pb in inst.list_backups():
backup.Backup.from_pb(backup_pb, inst).delete()

inst.delete()
scrub_instance_ignore_not_found(inst)


@pytest.fixture(scope="module")
Expand All @@ -76,19 +83,15 @@ def instance_config(spanner_client):

@pytest.fixture(scope="module")
def sample_instance(
spanner_client,
cleanup_old_instances,
instance_id,
instance_config,
sample_name,
spanner_client, cleanup_old_instances, instance_id, instance_config, sample_name,
):
sample_instance = spanner_client.instance(
instance_id,
instance_config,
labels={
"cloud_spanner_samples": "true",
"sample_name": sample_name,
"created": str(int(time.time()))
"created": str(int(time.time())),
},
)
retry_429 = retry.RetryErrors(exceptions.ResourceExhausted, delay=15)
Expand Down