Raise error when period with negative value
Based on current implement, when use launch below REST API: GET http://10.1.0.175:8777/v2/meters/port/statistics?period=-1 The result will be 200 OK. No any error reports. This query should not allow negative value setting but 400 error, and prompts like this: "Period must be positive.". Just like setting "Limit" to negative. Fixes bug 1212159 Change-Id: I8d547fdf8faae2094b24c81da6b233b432bc99ae
This commit is contained in:
parent
ac000155a0
commit
a6ca935665
@ -567,6 +567,11 @@ class MeterController(rest.RestController):
|
||||
:param period: Returned result will be an array of statistics for a
|
||||
period long of that number of seconds.
|
||||
"""
|
||||
if period and period < 0:
|
||||
error = _("Period must be positive.")
|
||||
pecan.response.translatable_error = error
|
||||
raise wsme.exc.ClientSideError(error)
|
||||
|
||||
kwargs = _query_to_kwargs(q, storage.SampleFilter.__init__)
|
||||
kwargs['meter'] = self._id
|
||||
f = storage.SampleFilter(**kwargs)
|
||||
|
@ -185,6 +185,13 @@ class TestMaxResourceVolume(base.FunctionalTest,
|
||||
u'2012-09-25T11:30:00',
|
||||
u'2012-09-25T12:30:00']))
|
||||
|
||||
def test_period_with_negative_value(self):
|
||||
resp = self.get_json(self.PATH, expect_errors=True,
|
||||
q=[{'field': 'resource_id',
|
||||
'value': 'resource-id'}],
|
||||
period=-1)
|
||||
self.assertEquals(400, resp.status_code)
|
||||
|
||||
def test_start_timestamp(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'resource_id',
|
||||
'value': 'resource-id',
|
||||
|
Loading…
x
Reference in New Issue
Block a user