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
This commit is contained in:
Sylvain Afchain 2014-04-05 08:19:42 +02:00
parent 2633eb8c99
commit 91930ca89c
2 changed files with 12 additions and 1 deletions

View File

@ -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):

View File

@ -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)