diff options
author | Jenkins <jenkins@review.openstack.org> | 2014-12-03 17:45:02 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2014-12-03 17:45:02 +0000 |
commit | f1318ec3e840b870635b13ed99d9064693589b16 (patch) | |
tree | 44fc7aaa3272c494f8ee5e50458283839df68d64 | |
parent | 61ca6900f4f4f583c43015306ac28f949f44fbad (diff) | |
parent | 43718e84b93bd15353e4cce8002a974553bd1bbc (diff) | |
download | ceilometer-f1318ec3e840b870635b13ed99d9064693589b16.tar.gz |
Merge "Internal error with period overflow" into stable/juno
-rw-r--r-- | ceilometer/api/controllers/v2.py | 30 | ||||
-rw-r--r-- | ceilometer/tests/api/v2/test_statistics_scenarios.py | 9 |
2 files changed, 27 insertions, 12 deletions
diff --git a/ceilometer/api/controllers/v2.py b/ceilometer/api/controllers/v2.py index 0f28ed72..9cf793c8 100644 --- a/ceilometer/api/controllers/v2.py +++ b/ceilometer/api/controllers/v2.py @@ -982,25 +982,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 478b6447..5d8a51c1 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', |