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)