Просмотр исходного кода

Treat GCP 400 validation errors as not-found in get_resource

GCP returns 400 (not 404) when a resource identifier fails server-side
format validation, e.g. a non-UUID region name. Since get_resource()
issues a single .get(<id>).execute(), any 4xx on this call means "no
such resource" from the caller's perspective; check_get_non_existent
in the test suite expects None rather than a raised exception.
Nuwan Goonasekera 3 дней назад
Родитель
Сommit
8fccb96f8c
1 измененных файлов с 5 добавлено и 2 удалено
  1. 5 2
      cloudbridge/providers/gcp/provider.py

+ 5 - 2
cloudbridge/providers/gcp/provider.py

@@ -415,8 +415,11 @@ class GCPCloudProvider(BaseCloudProvider):
         try:
             return resource_url.get_resource()
         except googleapiclient.errors.HttpError as http_error:
-            if http_error.resp.status in [404]:
-                # 404 = not found
+            # 404: resource does not exist.
+            # 400: identifier failed server-side validation (e.g. a name
+            # whose format cannot match any real resource). Either way the
+            # answer to "fetch this resource" is no such resource.
+            if http_error.resp.status in (400, 404):
                 return None
             else:
                 raise