From 0bc53f78876916d066e5c4382e74518dfb201501 Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Thu, 7 Mar 2013 11:53:20 -0500 Subject: [PATCH] Ensure the statistics are sorted Sort the statistics by the period start date before returning them, and restore the test that verifies this behavior. bug 1151345 Change-Id: I4f05ea049b7609cea9dab947738b7aabf3f062ef Signed-off-by: Doug Hellmann --- ceilometer/storage/impl_mongodb.py | 4 +++- tests/storage/base.py | 4 ---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/ceilometer/storage/impl_mongodb.py b/ceilometer/storage/impl_mongodb.py index f35471d5e..23a97b945 100644 --- a/ceilometer/storage/impl_mongodb.py +++ b/ceilometer/storage/impl_mongodb.py @@ -20,6 +20,7 @@ import copy import datetime +import operator import re import urlparse @@ -519,7 +520,8 @@ class Connection(base.Connection): query=q, ) - return [r['value'] for r in results['results']] + return sorted((r['value'] for r in results['results']), + key=operator.itemgetter('period_start')) def get_volume_sum(self, event_filter): """Return the sum of the volume field for the events diff --git a/tests/storage/base.py b/tests/storage/base.py index 3fad9af87..500de31f8 100644 --- a/tests/storage/base.py +++ b/tests/storage/base.py @@ -804,9 +804,6 @@ class StatisticsTest(DBTestBase): self.assertEqual(set(r['period_end'] for r in results), set([datetime.datetime(2012, 9, 25, 12, 28), datetime.datetime(2012, 9, 25, 14, 28)])) - ''' - # FXIME(llu) Temporary comment out to pass Jenkins unittest. - # Will resume this after bug #1151345 is fixed. r = results[0] self.assertEqual(r['period_start'], datetime.datetime(2012, 9, 25, 10, 28)) @@ -824,7 +821,6 @@ class StatisticsTest(DBTestBase): datetime.datetime(2012, 9, 25, 10, 30)) self.assertEqual(r['duration_end'], datetime.datetime(2012, 9, 25, 11, 31)) - ''' def test_by_project(self): f = storage.EventFilter(