Correctly print --limit value passed via API
Passing an invalid limit value, for example '--limit -1'
in neutronclient, generates this error from the API:
Bad limit request: Limit must be an integer 0 or
greater and not '%d'.
It should print what was passed.
Closes-bug: #1649665
(cherry picked from commit e45d2a904d
)
Change-Id: I9b8bd67d344cd91e008f7c897f1ea6a020a9c30b
This commit is contained in:
parent
8a3d072f17
commit
b4a596d8a3
|
@ -121,13 +121,14 @@ def _get_pagination_max_limit():
|
|||
|
||||
def _get_limit_param(request):
|
||||
"""Extract integer limit from request or fail."""
|
||||
limit = request.GET.get('limit', 0)
|
||||
try:
|
||||
limit = int(request.GET.get('limit', 0))
|
||||
limit = int(limit)
|
||||
if limit >= 0:
|
||||
return limit
|
||||
except ValueError:
|
||||
pass
|
||||
msg = _("Limit must be an integer 0 or greater and not '%d'")
|
||||
msg = _("Limit must be an integer 0 or greater and not '%s'") % limit
|
||||
raise exceptions.BadRequest(resource='limit', msg=msg)
|
||||
|
||||
|
||||
|
|
|
@ -345,6 +345,7 @@ class APIv2TestCase(APIv2TestBase):
|
|||
res = self.api.get(_get_path('networks'),
|
||||
{'limit': 'abc'}, expect_errors=True)
|
||||
self.assertEqual(exc.HTTPBadRequest.code, res.status_int)
|
||||
self.assertIn('abc', res)
|
||||
|
||||
def test_limit_with_infinite_pagination_max_limit(self):
|
||||
instance = self.plugin.return_value
|
||||
|
|
Loading…
Reference in New Issue