Merge "Fix the return of statistic with getting no sample"

This commit is contained in:
Jenkins 2014-04-26 23:27:07 +00:00 committed by Gerrit Code Review
commit e63ee55317
2 changed files with 12 additions and 0 deletions

View File

@ -735,6 +735,10 @@ class Connection(base.Connection):
res = self._make_stats_query(sample_filter,
None,
aggregate).first()
if not res:
# NOTE(liusheng):The 'res' may be NoneType, because no
# sample has found with sample filter(s).
return
query = self._make_stats_query(sample_filter, groupby, aggregate)
# HACK(jd) This is an awful method to compute stats by period, but

View File

@ -1359,6 +1359,14 @@ class StatisticsTest(DBTestBase,
self.assertEqual(results.sum, 18)
self.assertEqual(results.avg, 6)
def test_with_no_sample(self):
f = storage.SampleFilter(
user='user-not-exists',
meter='volume.size',
)
results = list(self.conn.get_meter_statistics(f, period=1800))
self.assertEqual([], results)
class StatisticsGroupByTest(DBTestBase,
tests_db.MixinTestsWithBackendScenarios):