From 934a90d4c61ff66f99e5a46480047dec355b5d61 Mon Sep 17 00:00:00 2001 From: liu-sheng Date: Fri, 31 Oct 2014 14:13:26 +0800 Subject: [PATCH] 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 --- ceilometer/agent.py | 10 +++++++--- ceilometer/tests/agentbase.py | 12 ++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/ceilometer/agent.py b/ceilometer/agent.py index dad18f2e74..e8cbd651da 100644 --- a/ceilometer/agent.py +++ b/ceilometer/agent.py @@ -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: diff --git a/ceilometer/tests/agentbase.py b/ceilometer/tests/agentbase.py index aa12b13ea0..a3f23b0291 100644 --- a/ceilometer/tests/agentbase.py +++ b/ceilometer/tests/agentbase.py @@ -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)