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

Add check for existing output files during validation #65

Merged
merged 1 commit into from
Feb 6, 2024
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
9 changes: 9 additions & 0 deletions buildstockbatch/gcp/gcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,18 @@ def validate_gcp_args(project_file):

# Check that GCP bucket exists
bucket = cfg["gcp"]["gcs"]["bucket"]
output_dir = os.path.join(cfg["gcp"]["gcs"]["prefix"], "results", "simulation_output")
storage_client = storage.Client(project=gcp_project)
assert storage_client.bucket(bucket).exists(), f"GCS bucket {bucket} does not exist in project {gcp_project}"

blobs = storage_client.bucket(bucket).list_blobs(prefix=os.path.join(output_dir, "results_job"))
for blob in blobs:
raise ValidationError(
f"Output files are already present in bucket {bucket}! For example, {blob.name} exists. "
"Remove these files or chose a different file prefix. "
f"https://console.cloud.google.com/storage/browser/{bucket}/{output_dir}"
)

# Check that artifact registry repository exists
repo = cfg["gcp"]["artifact_registry"]["repository"]
ar_client = artifactregistry_v1.ArtifactRegistryClient()
Expand Down
Loading