From 91930ca89c6ae6cb583bd63ebf7f153e0fd9fe54 Mon Sep 17 00:00:00 2001 From: Sylvain Afchain Date: Sat, 5 Apr 2014 08:19:42 +0200 Subject: [PATCH] Check if samples returned by get_sample_data are not None Check if samples returned by the method get_sample_data of a network statistics driver are not None. As described in the docstring of the abstract method if a driver is not able to return samples for a meter_name it has to return None. Closes-bug: #1304327 Change-Id: Id4b2000adc20078631cb8ce1ed7f84fce1a3165d --- ceilometer/network/statistics/__init__.py | 3 ++- ceilometer/tests/network/statistics/test_statistics.py | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ceilometer/network/statistics/__init__.py b/ceilometer/network/statistics/__init__.py index 29df6e993..d3afe737c 100644 --- a/ceilometer/network/statistics/__init__.py +++ b/ceilometer/network/statistics/__init__.py @@ -71,7 +71,8 @@ class _Base(plugin.CentralPollster): parse_url, params, cache) - for data in sample_data: + + for data in sample_data or []: if data is None: continue if not isinstance(data, list): diff --git a/ceilometer/tests/network/statistics/test_statistics.py b/ceilometer/tests/network/statistics/test_statistics.py index 5656290cb..df258f1e8 100644 --- a/ceilometer/tests/network/statistics/test_statistics.py +++ b/ceilometer/tests/network/statistics/test_statistics.py @@ -175,3 +175,13 @@ class TestBaseGetSamples(test.BaseTestCase): samples = self._get_samples('http://foo') self.assertEqual(len(samples), 0) + + def test_get_samples_return_no_generator(self): + class NoneFakeDriver(driver.Driver): + + def get_sample_data(self, meter_name, parse_url, params, cache): + return None + + self._setup_ext_mgr(http=NoneFakeDriver()) + samples = self._get_samples('http://foo') + self.assertFalse(samples)