Skip to content

Commit

Permalink
remove capacity commitment from tests and conftest.py
Browse files Browse the repository at this point in the history
  • Loading branch information
dizcology authored and dandhlee committed Jul 24, 2023
1 parent fbda09d commit 090a200
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 54 deletions.
34 changes: 0 additions & 34 deletions bigquery-reservation/snippets/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,6 @@
import pytest


@pytest.fixture(scope="session", autouse=True)
def cleanup_commitments(
reservation_client: reservation_service.ReservationServiceClient, location_path: str
) -> None:
for commitment in reservation_client.list_capacity_commitments(
parent=location_path
):
if commitment.state == reservation_types.CapacityCommitment.State.FAILED or (
commitment.commitment_start_time is not None
and commitment.commitment_start_time
< datetime.datetime.now(datetime.timezone.utc) - datetime.timedelta(days=1)
):
reservation_client.delete_capacity_commitment(name=commitment.name)


@pytest.fixture(scope="session")
def project_id() -> str:
return os.environ["GOOGLE_CLOUD_PROJECT"]
Expand All @@ -58,22 +43,3 @@ def location_path(project_id: str, location: str) -> str:
return reservation_service.ReservationServiceClient.common_location_path(
project_id, location
)


@pytest.fixture(scope="session", autouse=True)
def capacity_commitment(
location_path: str, reservation_client: reservation_service.ReservationServiceClient
) -> reservation_types.CapacityCommitment:
commitment = reservation_types.CapacityCommitment()
commitment.slot_count = 100
commitment.plan = reservation_types.CapacityCommitment.CommitmentPlan.FLEX
commitment = reservation_client.create_capacity_commitment(
parent=location_path, capacity_commitment=commitment
)
yield commitment
# Commitments can only be removed after 1 minute.
now = datetime.datetime.now(datetime.timezone.utc)
delta = commitment.commitment_end_time - now
sleep_seconds = max(0, delta.total_seconds()) + 5
time.sleep(sleep_seconds)
reservation_client.delete_capacity_commitment(name=commitment.name)
20 changes: 0 additions & 20 deletions bigquery-reservation/snippets/quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,9 @@ def main(
# Constructs the client for interacting with the service.
client = bigquery_reservation_v1.ReservationServiceClient(transport=transport)

report_capacity_commitments(client, project_id, location)
report_reservations(client, project_id, location)


def report_capacity_commitments(
client: bigquery_reservation_v1.ReservationServiceClient,
project_id: str,
location: str,
) -> None:
"""Prints details and summary information about capacity commitments for
a given admin project and location.
"""
print(f"Capacity commitments in project {project_id} in location {location}")
req = bigquery_reservation_v1.ListCapacityCommitmentsRequest(
parent=client.common_location_path(project_id, location)
)
total_commitments = 0
for commitment in client.list_capacity_commitments(request=req):
print(f"\tCommitment {commitment.name} in state {commitment.state}")
total_commitments = total_commitments + 1
print(f"\n{total_commitments} commitments processed.")


def report_reservations(
client: bigquery_reservation_v1.ReservationServiceClient,
project_id: str,
Expand Down

0 comments on commit 090a200

Please sign in to comment.