Skip to content

Commit 78f02e9

Browse files
kk7dsmelwitt
authored andcommitted
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
1 parent b2ec3cd commit 78f02e9

File tree

3 files changed

+4
-6
lines changed

3 files changed

+4
-6
lines changed

nova/api/openstack/compute/keypairs.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
from nova.api import validation
2727
from nova.compute import api as compute_api
2828
from nova import exception
29-
from nova.i18n import _
3029
from nova.objects import keypair as keypair_obj
3130
from nova.policies import keypairs as kp_policies
3231

@@ -119,9 +118,8 @@ def _create(self, req, body, user_id=None, key_type=False):
119118
context, user_id, name, key_type_value)
120119
keypair['private_key'] = private_key
121120
return_priv_key = True
122-
except exception.KeypairLimitExceeded:
123-
msg = _("Quota exceeded, too many key pairs.")
124-
raise webob.exc.HTTPForbidden(explanation=msg)
121+
except exception.KeypairLimitExceeded as e:
122+
raise webob.exc.HTTPForbidden(explanation=str(e))
125123
except exception.InvalidKeypair as exc:
126124
raise webob.exc.HTTPBadRequest(explanation=exc.format_message())
127125
except exception.KeyPairExists as exc:

nova/exception.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1270,7 +1270,7 @@ class OnsetFileContentLimitExceeded(OnsetFileLimitExceeded):
12701270

12711271

12721272
class KeypairLimitExceeded(OverQuota):
1273-
msg_fmt = _("Maximum number of key pairs exceeded")
1273+
msg_fmt = _("Quota exceeded, too many key pairs.")
12741274

12751275

12761276
class SecurityGroupLimitExceeded(OverQuota):

nova/tests/unit/compute/test_keypairs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def db_key_pair_create_duplicate(context, keypair):
155155
return_value={'user': {
156156
'key_pairs': CONF.quota.key_pairs}})
157157
def test_quota_limit(self, mock_count_as_dict):
158-
msg = "Maximum number of key pairs exceeded"
158+
msg = "Quota exceeded, too many key pairs."
159159
self.assertKeypairRaises(exception.KeypairLimitExceeded, msg, 'foo')
160160

161161

0 commit comments

Comments
 (0)