Merge "Internal error with period overflow"

This commit is contained in:
Jenkins 2014-11-26 15:25:43 +00:00 committed by Gerrit Code Review
commit 85acec02b2
2 changed files with 27 additions and 12 deletions

View File

@ -988,25 +988,31 @@ class MeterController(rest.RestController):
g = _validate_groupby_fields(groupby) g = _validate_groupby_fields(groupby)
aggregate = utils.uniq(aggregate, ['func', 'param']) aggregate = utils.uniq(aggregate, ['func', 'param'])
computed = pecan.request.storage_conn.get_meter_statistics(f,
period,
g,
aggregate)
LOG.debug(_('computed value coming from %r'),
pecan.request.storage_conn)
# Find the original timestamp in the query to use for clamping # Find the original timestamp in the query to use for clamping
# the duration returned in the statistics. # the duration returned in the statistics.
start = end = None start = end = None
for i in q: for i in q:
if i.field == 'timestamp' and i.op in ('lt', 'le'): if i.field == 'timestamp' and i.op in ('lt', 'le'):
end = timeutils.parse_isotime(i.value).replace(tzinfo=None) end = timeutils.parse_isotime(i.value).replace(
tzinfo=None)
elif i.field == 'timestamp' and i.op in ('gt', 'ge'): elif i.field == 'timestamp' and i.op in ('gt', 'ge'):
start = timeutils.parse_isotime(i.value).replace(tzinfo=None) start = timeutils.parse_isotime(i.value).replace(
tzinfo=None)
return [Statistics(start_timestamp=start, try:
end_timestamp=end, computed = pecan.request.storage_conn.get_meter_statistics(
**c.as_dict()) f, period, g, aggregate)
for c in computed] LOG.debug(_('computed value coming from %r'),
pecan.request.storage_conn)
return [Statistics(start_timestamp=start,
end_timestamp=end,
**c.as_dict())
for c in computed]
except OverflowError as e:
params = dict(period=period, err=e)
raise ClientSideError(_("Invalid period %(period)s: %(err)s")
% params)
class Meter(_Base): class Meter(_Base):

View File

@ -180,6 +180,15 @@ class TestMaxResourceVolume(v2.FunctionalTest,
period=-1) period=-1)
self.assertEqual(400, resp.status_code) self.assertEqual(400, resp.status_code)
@tests_db.run_with('mysql', 'hbase', 'db2')
def test_period_with_large_value(self):
resp = self.get_json(self.PATH, expect_errors=True,
q=[{'field': 'user_id',
'value': 'user-id'}],
period=10000000000000)
self.assertEqual(400, resp.status_code)
self.assertIn("Invalid period", resp.body)
def test_start_timestamp(self): def test_start_timestamp(self):
data = self.get_json(self.PATH, q=[{'field': 'resource_id', data = self.get_json(self.PATH, q=[{'field': 'resource_id',
'value': 'resource-id', 'value': 'resource-id',