From 2518c6e97d744a34d268684e45f4371e416f4f2a Mon Sep 17 00:00:00 2001 From: Lena Novokshonova Date: Fri, 19 Dec 2014 16:44:53 +0400 Subject: [PATCH] Check to skip to poll and publish when no resource This fix checks if pollster must have resources or not. Currently only ipmi pollsters do not require resources. Change-Id: I8e047acbc3c55184dcac99f8e73e3060ecd02507 Closes-bug: 1403505 --- ceilometer/agent/base.py | 5 +++++ ceilometer/ipmi/pollsters/node.py | 3 +++ ceilometer/ipmi/pollsters/sensor.py | 2 ++ ceilometer/tests/agent/agentbase.py | 26 ++++++++++++++++++++++++++ 4 files changed, 36 insertions(+) diff --git a/ceilometer/agent/base.py b/ceilometer/agent/base.py index 241da325c..9a415af36 100644 --- a/ceilometer/agent/base.py +++ b/ceilometer/agent/base.py @@ -128,6 +128,11 @@ class PollingTask(object): self.resources[key].get(discovery_cache)) polling_resources = (source_resources or pollster_resources) + if not polling_resources and not getattr( + pollster.obj, 'no_resources', False): + LOG.info(_("Skip polling pollster %s, no resources" + " found"), pollster.name) + continue try: samples = list(pollster.obj.get_samples( diff --git a/ceilometer/ipmi/pollsters/node.py b/ceilometer/ipmi/pollsters/node.py index a765d9089..180fe7cfe 100644 --- a/ceilometer/ipmi/pollsters/node.py +++ b/ceilometer/ipmi/pollsters/node.py @@ -30,6 +30,9 @@ CONF.import_opt('host', 'ceilometer.service') @six.add_metaclass(abc.ABCMeta) class _Base(plugin_base.PollsterBase): + + no_resources = True + def __init__(self): self.nodemanager = node_manager.NodeManager() diff --git a/ceilometer/ipmi/pollsters/sensor.py b/ceilometer/ipmi/pollsters/sensor.py index 0230a3a28..7d2ce6908 100644 --- a/ceilometer/ipmi/pollsters/sensor.py +++ b/ceilometer/ipmi/pollsters/sensor.py @@ -32,6 +32,8 @@ class InvalidSensorData(ValueError): class SensorPollster(plugin_base.PollsterBase): + no_resources = True + METRIC = None def __init__(self): diff --git a/ceilometer/tests/agent/agentbase.py b/ceilometer/tests/agent/agentbase.py index 991832f94..bd186bad7 100644 --- a/ceilometer/tests/agent/agentbase.py +++ b/ceilometer/tests/agent/agentbase.py @@ -688,3 +688,29 @@ class BaseAgentManagerTestCase(base.BaseTestCase): self.assertEqual(1, len(samples)) self.assertEqual('test_sum', samples[0].name) self.assertEqual(11, samples[0].volume) + + @mock.patch('ceilometer.agent.base.LOG') + @mock.patch('ceilometer.tests.agent.agentbase.TestPollster.get_samples') + def test_skip_polling_and_publish_with_no_resources( + self, get_samples, LOG): + self.pipeline_cfg[0]['resources'] = [] + self.setup_pipeline() + polling_task = self.mgr.setup_polling_tasks().values()[0] + pollster = list(polling_task.pollster_matches['test_pipeline'])[0] + + polling_task.poll_and_publish() + LOG.info.assert_called_with( + 'Skip polling pollster %s, no resources found', pollster.name) + self.assertEqual(0, get_samples._mock_call_count) + + setattr(pollster.obj, 'no_resources', False) + polling_task.poll_and_publish() + LOG.info.assert_called_with( + 'Skip polling pollster %s, no resources found', pollster.name) + self.assertEqual(0, get_samples._mock_call_count) + + setattr(pollster.obj, 'no_resources', True) + polling_task.poll_and_publish() + LOG.info.not_assert_called_with( + 'Skip polling pollster %s, no resources found', pollster.name) + self.assertEqual(1, get_samples._mock_call_count) \ No newline at end of file