summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSrinivas Sakhamuri <srinivas.sakhamuri@hp.com>2014-11-14 00:51:19 +0000
committerEoghan Glynn <eglynn@redhat.com>2014-12-02 11:32:19 +0000
commit43718e84b93bd15353e4cce8002a974553bd1bbc (patch)
treecd61b7e1f038517addbb51f1a71895a3d4efe34f
parent6eb39a9a2c76cefc5a2c1af071516a68f1e0672f (diff)
downloadceilometer-43718e84b93bd15353e4cce8002a974553bd1bbc.tar.gz
Internal error with period overflow
When statistics queried with large period value the overflow causes error 500. This patch converts the overflow error to ClientSideError which is returned as 400 bad input error Change-Id: Iacf89c75428713a151fbe81aa1601df63785f942 Closes-Bug: 1396223 (cherry picked from commit 9f923ae928176ca36ad784fadeea56bfc806e7e1)
-rw-r--r--ceilometer/api/controllers/v2.py30
-rw-r--r--ceilometer/tests/api/v2/test_statistics_scenarios.py9
2 files changed, 27 insertions, 12 deletions
diff --git a/ceilometer/api/controllers/v2.py b/ceilometer/api/controllers/v2.py
index 36f6bec5..87c3d514 100644
--- a/ceilometer/api/controllers/v2.py
+++ b/ceilometer/api/controllers/v2.py
@@ -978,25 +978,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',