From 78f02e96eddd92d7a5eb5d793b6646f0e86ab272 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Mon, 7 Feb 2022 12:36:52 -0800 Subject: [PATCH] Move keypair quota error message into exception The KeypairLimitExceeded exception has a message string which is never used. We raise this exception and then return a different message to the API user. For the unified limit work, we want to move to using oslo.limit's better error messages when available, which means we need to honor the message in the exception. This just moves the legacy string into the exception and makes the API use that instead of overriding it. Related to bp/unified-limits-nova Change-Id: I217b3d0551291498191b556f62d78abf159778c2 --- nova/api/openstack/compute/keypairs.py | 6 ++---- nova/exception.py | 2 +- nova/tests/unit/compute/test_keypairs.py | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/nova/api/openstack/compute/keypairs.py b/nova/api/openstack/compute/keypairs.py index 1fa1684322..65dacfa638 100644 --- a/nova/api/openstack/compute/keypairs.py +++ b/nova/api/openstack/compute/keypairs.py @@ -26,7 +26,6 @@ from nova.api.openstack import wsgi from nova.api import validation from nova.compute import api as compute_api from nova import exception -from nova.i18n import _ from nova.objects import keypair as keypair_obj from nova.policies import keypairs as kp_policies @@ -119,9 +118,8 @@ class KeypairController(wsgi.Controller): context, user_id, name, key_type_value) keypair['private_key'] = private_key return_priv_key = True - except exception.KeypairLimitExceeded: - msg = _("Quota exceeded, too many key pairs.") - raise webob.exc.HTTPForbidden(explanation=msg) + except exception.KeypairLimitExceeded as e: + raise webob.exc.HTTPForbidden(explanation=str(e)) except exception.InvalidKeypair as exc: raise webob.exc.HTTPBadRequest(explanation=exc.format_message()) except exception.KeyPairExists as exc: diff --git a/nova/exception.py b/nova/exception.py index 136b3e865e..eeba922ced 100644 --- a/nova/exception.py +++ b/nova/exception.py @@ -1270,7 +1270,7 @@ class OnsetFileContentLimitExceeded(OnsetFileLimitExceeded): class KeypairLimitExceeded(OverQuota): - msg_fmt = _("Maximum number of key pairs exceeded") + msg_fmt = _("Quota exceeded, too many key pairs.") class SecurityGroupLimitExceeded(OverQuota): diff --git a/nova/tests/unit/compute/test_keypairs.py b/nova/tests/unit/compute/test_keypairs.py index 7860f3d529..c10a6ddd00 100644 --- a/nova/tests/unit/compute/test_keypairs.py +++ b/nova/tests/unit/compute/test_keypairs.py @@ -155,7 +155,7 @@ class CreateImportSharedTestMixIn(object): return_value={'user': { 'key_pairs': CONF.quota.key_pairs}}) def test_quota_limit(self, mock_count_as_dict): - msg = "Maximum number of key pairs exceeded" + msg = "Quota exceeded, too many key pairs." self.assertKeypairRaises(exception.KeypairLimitExceeded, msg, 'foo')