diff --git a/ceilometer/api/controllers/v2.py b/ceilometer/api/controllers/v2.py index 883b0e4ba7..d12733b038 100644 --- a/ceilometer/api/controllers/v2.py +++ b/ceilometer/api/controllers/v2.py @@ -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): diff --git a/ceilometer/tests/api/v2/test_statistics_scenarios.py b/ceilometer/tests/api/v2/test_statistics_scenarios.py index a836f63467..fb7c978ffb 100644 --- a/ceilometer/tests/api/v2/test_statistics_scenarios.py +++ b/ceilometer/tests/api/v2/test_statistics_scenarios.py @@ -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',