Пример #1
0
    def _batching_samples(self, expected_samples, call_count):
        self.useFixture(
            fixtures.MockPatchObject(manager.utils,
                                     'delayed',
                                     side_effect=fakedelayed))
        self.poll_cfg = {
            'sources': [{
                'name': 'test_pipeline',
                'interval': 1,
                'meters': ['testbatch'],
                'resources': ['alpha', 'beta', 'gamma', 'delta'],
                'sinks': ['test_sink']
            }],
            'sinks': [{
                'name': 'test_sink',
                'transformers': [],
                'publishers': ["test"]
            }]
        }
        self._build_and_set_new_polling()
        self.mgr.polling_manager = manager.PollingManager(self.CONF)
        polling_task = list(self.mgr.setup_polling_tasks().values())[0]

        self.mgr.interval_task(polling_task)
        samples = self.notified_samples
        self.assertEqual(expected_samples, len(samples))
        self.assertEqual(call_count, self.notifier.sample.call_count)
Пример #2
0
    def test_polling_novalike_exception(self, LOG):
        source_name = 'test_pollingexception'
        self.poll_cfg = {
            'sources': [{
                'name': source_name,
                'interval': 10,
                'meters': ['testpollingexception'],
                'sinks': ['test_sink']
            }],
            'sinks': [{
                'name': 'test_sink',
                'transformers': [],
                'publishers': ["test"]
            }]
        }
        self._build_and_set_new_polling()
        self.mgr.polling_manager = manager.PollingManager(self.CONF)
        polling_task = list(self.mgr.setup_polling_tasks().values())[0]
        pollster = list(polling_task.pollster_matches[source_name])[0]

        with mock.patch.object(polling_task.manager, 'discover') as disco:
            # NOTE(gordc): polling error on 3rd poll
            for __ in range(4):
                disco.return_value = ([
                    nova_discover.NovaLikeServer(**{'id': 1})
                ])
                self.mgr.interval_task(polling_task)
        LOG.error.assert_called_once_with(
            ('Prevent pollster %(name)s from '
             'polling %(res_list)s on source %(source)s anymore!'),
            dict(name=pollster.name,
                 res_list="[<NovaLikeServer: unknown-name>]",
                 source=source_name))
Пример #3
0
    def test_polling_exception(self, LOG):
        source_name = 'test_pollingexception'
        res_list = ['test://']
        self.poll_cfg = {
            'sources': [{
                'name': source_name,
                'interval': 10,
                'meters': ['testpollingexception'],
                'resources': res_list,
                'sinks': ['test_sink']
            }],
            'sinks': [{
                'name': 'test_sink',
                'transformers': [],
                'publishers': ["test"]
            }]
        }
        self._build_and_set_new_polling()
        self.mgr.polling_manager = manager.PollingManager(self.CONF)
        polling_task = list(self.mgr.setup_polling_tasks().values())[0]
        pollster = list(polling_task.pollster_matches[source_name])[0]

        # 2 samples after 4 pollings, as pollster got disabled upon exception
        for x in range(0, 4):
            self.mgr.interval_task(polling_task)
        samples = self.notified_samples
        self.assertEqual(2, len(samples))
        LOG.error.assert_called_once_with(
            ('Prevent pollster %(name)s from '
             'polling %(res_list)s on source %(source)s anymore!'),
            dict(name=pollster.name,
                 res_list=str(res_list),
                 source=source_name))
Пример #4
0
 def test_when_keystone_fail(self):
     """Test for bug 1316532."""
     self.useFixture(
         fixtures.MockPatch('keystoneclient.v2_0.client.Client',
                            side_effect=ka_exceptions.ClientException))
     self.poll_cfg = {
         'sources': [{
             'name': "test_keystone",
             'interval': 10,
             'meters': ['testkeystone'],
             'resources': ['test://'],
             'sinks': ['test_sink']
         }],
         'sinks': [{
             'name': 'test_sink',
             'transformers': [],
             'publishers': ["test"]
         }]
     }
     self._build_and_set_new_polling()
     self.mgr.polling_manager = manager.PollingManager(self.CONF)
     polling_tasks = self.mgr.setup_polling_tasks()
     self.mgr.interval_task(list(polling_tasks.values())[0])
     self.assertFalse(self.PollsterKeystone.samples)
     self.assertFalse(self.notified_samples)
Пример #5
0
    def test_hardware_discover_fail_minimize_logs(self, novalog, baselog):
        class PollsterHardware(agentbase.TestPollster):
            discovery = 'tripleo_overcloud_nodes'

        class PollsterHardwareAnother(agentbase.TestPollster):
            discovery = 'tripleo_overcloud_nodes'

        self.mgr.extensions.extend([
            extension.Extension(
                'testhardware',
                None,
                None,
                PollsterHardware(self.CONF),
            ),
            extension.Extension(
                'testhardware2',
                None,
                None,
                PollsterHardwareAnother(self.CONF),
            )
        ])
        ext = extension.Extension('tripleo_overcloud_nodes', None, None,
                                  discovery.NodesDiscoveryTripleO(self.CONF))
        self.mgr.discoveries = (extension.ExtensionManager.make_test_instance(
            [ext]))

        self.poll_cfg = {
            'sources': [{
                'name': "test_hardware",
                'interval': 10,
                'meters': ['testhardware', 'testhardware2'],
                'sinks': ['test_sink']
            }],
            'sinks': [{
                'name': 'test_sink',
                'transformers': [],
                'publishers': ["test"]
            }]
        }
        self._build_and_set_new_polling()
        self.mgr.polling_manager = manager.PollingManager(self.CONF)
        polling_tasks = self.mgr.setup_polling_tasks()
        self.mgr.interval_task(list(polling_tasks.values())[0])
        self.assertEqual(1, novalog.exception.call_count)
        self.assertFalse(baselog.exception.called)
Пример #6
0
 def setup_polling(self, poll_cfg=None):
     name = self.cfg2file(poll_cfg or self.polling_cfg)
     self.CONF.set_override('cfg_file', name, group='polling')
     self.mgr.polling_manager = manager.PollingManager(self.CONF)
Пример #7
0
 def test_no_resources(self):
     self._build_and_set_new_polling()
     poll_manager = manager.PollingManager(self.CONF)
     self.assertEqual(0, len(poll_manager.sources[0].resources))
Пример #8
0
 def test_resources(self):
     resources = ['test1://', 'test2://']
     self.poll_cfg['sources'][0]['resources'] = resources
     self._build_and_set_new_polling()
     poll_manager = manager.PollingManager(self.CONF)
     self.assertEqual(resources, poll_manager.sources[0].resources)
Пример #9
0
 def test_get_interval(self):
     self._build_and_set_new_polling()
     poll_manager = manager.PollingManager(self.CONF)
     source = poll_manager.sources[0]
     self.assertEqual(600, source.get_interval())