Skip to poll and publish when no resources found

Currently, the polling agent will poll and publish even if no resources
found. Although no samples will be published in publishing process, the
polling record will be recorded in log files, this is easy to mislead.
This change skip to publish and record a clear skip-polling hint in
log if no resources found.

Change-Id: Ia0294d3308a1d709006f9cb772f35ea92badcb38
This commit is contained in:
liu-sheng 2014-10-31 14:13:26 +08:00 committed by LiuSheng
parent 6eac318612
commit 934a90d4c6
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)