Fix hardware pollster to inspect multiple resources

Closes-bug: #1292790
Change-Id: I9082131bb8c59b8a9e1a15073b7b32edb83e2552
This commit is contained in:
Balazs Gibizer 2014-03-21 17:05:39 +01:00
parent e0f83ff425
commit 2721e077f4
2 changed files with 9 additions and 8 deletions

View File

@ -21,7 +21,7 @@
"""Base class for plugins used by the hardware agent."""
import abc
import itertools
import six
from ceilometer.central import plugin
@ -52,6 +52,7 @@ class HardwarePollster(plugin.CentralPollster):
:param resources: end point to poll data from
"""
h_cache = cache.setdefault(self.CACHE_KEY, {})
sample_iters = []
for res in resources:
parsed_url = network_utils.urlsplit(res)
inspector = self._get_inspector(parsed_url)
@ -64,16 +65,15 @@ class HardwarePollster(plugin.CentralPollster):
i_cache[res] = list(func(parsed_url))
# Generate samples
if i_cache[res]:
return self.generate_samples(parsed_url, i_cache[res])
sample_iters.append(self.generate_samples(parsed_url,
i_cache[res]))
except Exception as err:
LOG.exception(_('inspector call %(func)r failed for '
'host %(host)s: %(err)s'),
dict(func=func,
host=parsed_url.hostname,
err=err))
# if no resources, we still need to return an iterable
# because of the interface requirement
return ()
return itertools.chain(*sample_iters)
def generate_samples(self, host_url, data):
"""Generate an iterable Sample from the data returned by inspector

View File

@ -58,7 +58,7 @@ class TestPollsterBase(test_base.BaseTestCase):
def setUp(self):
super(TestPollsterBase, self).setUp()
self.host = ["test://test"]
self.hosts = ["test://test", "test://test2"]
self.useFixture(fixtures.MonkeyPatch(
'ceilometer.hardware.inspector.get_inspector',
self.faux_get_inspector))
@ -69,10 +69,11 @@ class TestPollsterBase(test_base.BaseTestCase):
mgr = manager.AgentManager()
pollster = factory()
cache = {}
samples = list(pollster.get_samples(mgr, cache, self.host))
samples = list(pollster.get_samples(mgr, cache, self.hosts))
self.assertTrue(samples)
self.assertIn(pollster.CACHE_KEY, cache)
self.assertIn(self.host[0], cache[pollster.CACHE_KEY])
for host in self.hosts:
self.assertIn(host, cache[pollster.CACHE_KEY])
self.assertEqual(set([name]),
set([s.name for s in samples]))