Merge "Skip to poll and publish when no resources found"

This commit is contained in:
Jenkins 2014-11-17 15:29:50 +00:00 committed by Gerrit Code Review
commit 2117ba760c
2 changed files with 19 additions and 3 deletions

View File

@ -113,14 +113,18 @@ class PollingTask(object):
[pollster.obj.default_discovery], discovery_cache)
key = Resources.key(source, pollster)
source_resources = list(self.resources[key].get(discovery_cache))
polling_resources = (source_resources or pollster_resources or
agent_resources)
if not polling_resources:
LOG.info(_("Skip polling pollster %s, no resources found"),
pollster.name)
continue
with self.publishers[source.name] as publisher:
try:
samples = list(pollster.obj.get_samples(
manager=self.manager,
cache=cache,
resources=(source_resources or
pollster_resources or
agent_resources)
resources=polling_resources
))
publisher(samples)
except Exception as err:

View File

@ -740,3 +740,15 @@ class BaseAgentManagerTestCase(base.BaseTestCase):
len(p_coord.extract_my_subset.call_args_list))
for c in expected:
self.assertIn(c, p_coord.extract_my_subset.call_args_list)
def test_skip_polling_and_publish_with_no_resources(self):
self.pipeline_cfg[0]['resources'] = []
self.setup_pipeline()
polling_task = self.mgr.setup_polling_tasks().values()[0]
pollster = list(polling_task.pollster_matches)[0][1]
LOG = mock.MagicMock()
with mock.patch('ceilometer.agent.LOG', LOG):
polling_task.poll_and_publish()
if not self.mgr.discover():
LOG.info.assert_called_with('Skip polling pollster %s, no '
'resources found', pollster.name)