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:
Brian Haley 2016-12-13 14:35:26 -05:00 committed by Armando Migliaccio
parent 8a3d072f17
commit b4a596d8a3
2 changed files with 4 additions and 2 deletions

View File

@ -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)

View File

@ -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