Skip to content

Commit 8269047

Browse files
tswastgcf-owl-bot[bot]parthea
authored andcommitted
test: cleanup capacity commitments leftover from failed samples tests (#224)
* test: cleanup capacity commitments leftover from failed samples tests * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * try session scope * handle failed commitments in cleanup Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Anthonios Partheniou <[email protected]>
1 parent 9540599 commit 8269047

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

bigquery-reservation/snippets/conftest.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,21 @@
2121
import pytest
2222

2323

24+
@pytest.fixture(scope="session", autouse=True)
25+
def cleanup_commitments(
26+
reservation_client: reservation_service.ReservationServiceClient, location_path: str
27+
) -> None:
28+
for commitment in reservation_client.list_capacity_commitments(
29+
parent=location_path
30+
):
31+
if commitment.state == reservation_types.CapacityCommitment.State.FAILED or (
32+
commitment.commitment_start_time is not None
33+
and commitment.commitment_start_time
34+
< datetime.datetime.now(datetime.timezone.utc) - datetime.timedelta(days=1)
35+
):
36+
reservation_client.delete_capacity_commitment(name=commitment.name)
37+
38+
2439
@pytest.fixture(scope="session")
2540
def project_id() -> str:
2641
return os.environ["GOOGLE_CLOUD_PROJECT"]
@@ -47,8 +62,6 @@ def location_path(project_id: str, location: str) -> str:
4762
def capacity_commitment(
4863
location_path: str, reservation_client: reservation_service.ReservationServiceClient
4964
) -> reservation_types.CapacityCommitment:
50-
# TODO(b/196082966): If custom names or creation date property are added,
51-
# do pre-test cleanup of past commitments.
5265
commitment = reservation_types.CapacityCommitment()
5366
commitment.slot_count = 100
5467
commitment.plan = reservation_types.CapacityCommitment.CommitmentPlan.FLEX

0 commit comments

Comments
 (0)