Merge "Internal error with period overflow"
This commit is contained in:
commit
85acec02b2
@ -988,25 +988,31 @@ class MeterController(rest.RestController):
|
||||
g = _validate_groupby_fields(groupby)
|
||||
|
||||
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
|
||||
# the duration returned in the statistics.
|
||||
start = end = None
|
||||
for i in q:
|
||||
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'):
|
||||
start = timeutils.parse_isotime(i.value).replace(tzinfo=None)
|
||||
start = timeutils.parse_isotime(i.value).replace(
|
||||
tzinfo=None)
|
||||
|
||||
return [Statistics(start_timestamp=start,
|
||||
end_timestamp=end,
|
||||
**c.as_dict())
|
||||
for c in computed]
|
||||
try:
|
||||
computed = pecan.request.storage_conn.get_meter_statistics(
|
||||
f, period, g, aggregate)
|
||||
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):
|
||||
|
@ -180,6 +180,15 @@ class TestMaxResourceVolume(v2.FunctionalTest,
|
||||
period=-1)
|
||||
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):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'resource_id',
|
||||
'value': 'resource-id',
|
||||
|
Loading…
x
Reference in New Issue
Block a user