Skip to content

Commit

Permalink
fix: test cleanup stages with try finally (#212)
Browse files Browse the repository at this point in the history
* fix: test cleanup stages with try finally

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
Shabirmean and gcf-owl-bot[bot] authored Mar 22, 2022
1 parent cae7f4d commit 72c72db
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions container/snippets/create_cluster_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,23 @@ def setup_and_tear_down() -> None:
# run the tests here
yield

# delete the cluster
client = gke.ClusterManagerClient()
cluster_location = client.common_location_path(PROJECT_ID, ZONE)
cluster_name = f"{cluster_location}/clusters/{CLUSTER_NAME}"
op = client.delete_cluster({"name": cluster_name})
op_id = f"{cluster_location}/operations/{op.name}"

# schedule a retry to ensure the cluster is deleted
@backoff.on_predicate(
backoff.expo, lambda x: x != gke.Operation.Status.DONE, max_tries=20
)
def wait_for_delete() -> gke.Operation.Status:
return client.get_operation({"name": op_id}).status

wait_for_delete()
try:
# delete the cluster
client = gke.ClusterManagerClient()
cluster_location = client.common_location_path(PROJECT_ID, ZONE)
cluster_name = f"{cluster_location}/clusters/{CLUSTER_NAME}"
op = client.delete_cluster({"name": cluster_name})
op_id = f"{cluster_location}/operations/{op.name}"

finally:
# schedule a retry to ensure the cluster is deleted
@backoff.on_predicate(
backoff.expo, lambda x: x != gke.Operation.Status.DONE, max_tries=20
)
def wait_for_delete() -> gke.Operation.Status:
return client.get_operation({"name": op_id}).status

wait_for_delete()


def test_create_clusters(capsys: object) -> None:
Expand Down

0 comments on commit 72c72db

Please sign in to comment.