Skip to content

Commit f42ade4

Browse files
committed
quota: Catch correct exception type for Compute quotas
There is a flaw (IMO) in the design of Nova's os-quota-sets API: despite project IDs forming the identifier for an individual resource, we get a HTTP 400 (Bad Request) error if you pass an ID that does not exist, rather than the HTTP 404 (Not Found) we would expect. Correct this, noting why we're doing what we're doing for readers from the future (hi!). Note that HTTP 400 is unfortunately quite broad and means we'll also catch things like invalid requests but the exception may have been translated so we can't rely on a string match. Change-Id: I720502930d50be8ead5f2033d9dbcab5d99a37a9 Signed-off-by: Stephen Finucane <stephenfin@redhat.com> Closes-bug: #2091086 (cherry picked from commit 99cef93)
1 parent 66a9708 commit f42ade4

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

openstackclient/common/quota.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,14 @@ def _list_quota_compute(self, parsed_args, project_ids):
249249
for project_id in project_ids:
250250
try:
251251
project_data = compute_client.get_quota_set(project_id)
252+
# NOTE(stephenfin): Unfortunately, Nova raises a HTTP 400 (Bad
253+
# Request) if the project ID is invalid, even though the project
254+
# ID is actually the resource's identifier which would normally
255+
# lead us to expect a HTTP 404 (Not Found).
252256
except (
253-
sdk_exceptions.NotFoundException,
257+
sdk_exceptions.BadRequestException,
254258
sdk_exceptions.ForbiddenException,
259+
sdk_exceptions.NotFoundException,
255260
) as exc:
256261
# Project not found, move on to next one
257262
LOG.warning(f"Project {project_id} not found: {exc}")
@@ -312,8 +317,8 @@ def _list_quota_volume(self, parsed_args, project_ids):
312317
try:
313318
project_data = volume_client.get_quota_set(project_id)
314319
except (
315-
sdk_exceptions.NotFoundException,
316320
sdk_exceptions.ForbiddenException,
321+
sdk_exceptions.NotFoundException,
317322
) as exc:
318323
# Project not found, move on to next one
319324
LOG.warning(f"Project {project_id} not found: {exc}")

0 commit comments

Comments
 (0)