Allow project creation when GCS fails.

Without this exception handler, the project would be invalid, as the
after_inserting_project() hook would be half-run.
This commit is contained in:
Sybren A. Stüvel 2016-06-15 14:12:40 +02:00
parent 9ed73eb7dd
commit 8dc4ac0db7

View File

@ -178,11 +178,14 @@ def after_inserting_project(project, db_user):
if current_app.config.get('TESTING'): if current_app.config.get('TESTING'):
log.warning('Not creating Google Cloud Storage bucket while running unit tests!') log.warning('Not creating Google Cloud Storage bucket while running unit tests!')
else: else:
gcs_storage = GoogleCloudStorageBucket(str(project_id)) try:
if gcs_storage.bucket.exists(): gcs_storage = GoogleCloudStorageBucket(str(project_id))
log.info('Created CGS instance for project %s', project_id) if gcs_storage.bucket.exists():
else: log.info('Created GCS instance for project %s', project_id)
log.warning('Unable to create CGS instance for project %s', project_id) else:
log.warning('Unable to create GCS instance for project %s', project_id)
except gcs_exceptions.Forbidden as ex:
log.warning('GCS forbids me to create CGS instance for project %s: %s', project_id, ex)
# Commit the changes directly to the MongoDB; a PUT is not allowed yet, # Commit the changes directly to the MongoDB; a PUT is not allowed yet,
# as the project doesn't have a valid permission structure. # as the project doesn't have a valid permission structure.