From 8dc4ac0db70cd36c78fc92c7318c04a64d82bbfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Wed, 15 Jun 2016 14:12:40 +0200 Subject: [PATCH] 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. --- pillar/application/modules/projects.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pillar/application/modules/projects.py b/pillar/application/modules/projects.py index 328a62e5..7c147a0c 100644 --- a/pillar/application/modules/projects.py +++ b/pillar/application/modules/projects.py @@ -178,11 +178,14 @@ def after_inserting_project(project, db_user): if current_app.config.get('TESTING'): log.warning('Not creating Google Cloud Storage bucket while running unit tests!') else: - gcs_storage = GoogleCloudStorageBucket(str(project_id)) - if gcs_storage.bucket.exists(): - log.info('Created CGS instance for project %s', project_id) - else: - log.warning('Unable to create CGS instance for project %s', project_id) + try: + gcs_storage = GoogleCloudStorageBucket(str(project_id)) + if gcs_storage.bucket.exists(): + log.info('Created GCS 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, # as the project doesn't have a valid permission structure.