Merge "Check to skip to poll and publish when no resource"
This commit is contained in:
commit
ca62b8e33d
@ -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(
|
||||
|
@ -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()
|
||||
|
||||
|
@ -32,6 +32,8 @@ class InvalidSensorData(ValueError):
|
||||
|
||||
class SensorPollster(plugin_base.PollsterBase):
|
||||
|
||||
no_resources = True
|
||||
|
||||
METRIC = None
|
||||
|
||||
def __init__(self):
|
||||
|
@ -689,3 +689,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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user