Parcourir la source

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 il y a 2 jours
Parent
commit
8fccb96f8c
1 fichiers modifiés avec 5 ajouts et 2 suppressions
  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