Beispiel #1
0
    def setup_environment(self):
        super(_Base, self).setup_environment()
        self.nodemanager = node_manager.NodeManager(self.conf)
        self.polling_failures = 0

        # Do not load this extension if no NM support
        if self.nodemanager.nm_version == 0:
            raise plugin_base.ExtensionLoadError()
Beispiel #2
0
    def setup_environment(self):
        super(SensorPollster, self).setup_environment()
        self.ipmi = ipmi_sensor.IPMISensor()
        self.polling_failures = 0

        # Do not load this extension if no IPMI support
        if not self.ipmi.ipmi_support:
            raise plugin_base.ExtensionLoadError()
Beispiel #3
0
class TestManager(base.BaseTestCase):
    def setUp(self):
        super(TestManager, self).setUp()
        self.conf = service.prepare_service([], [])

    def test_hash_of_set(self):
        x = ['a', 'b']
        y = ['a', 'b', 'a']
        z = ['a', 'c']
        self.assertEqual(manager.hash_of_set(x), manager.hash_of_set(y))
        self.assertNotEqual(manager.hash_of_set(x), manager.hash_of_set(z))
        self.assertNotEqual(manager.hash_of_set(y), manager.hash_of_set(z))

    def test_load_plugins(self):
        mgr = manager.AgentManager(0, self.conf)
        self.assertIsNotNone(list(mgr.extensions))

    # Test plugin load behavior based on Node Manager pollsters.
    @mock.patch('ceilometer.ipmi.pollsters.node._Base.__init__',
                mock.Mock(return_value=None))
    @mock.patch('ceilometer.ipmi.pollsters.sensor.SensorPollster.__init__',
                mock.Mock(return_value=None))
    def test_load_normal_plugins(self):
        mgr = manager.AgentManager(0, self.conf,
                                   namespaces=['ipmi'])
        # 8 pollsters for Node Manager
        self.assertEqual(12, len(mgr.extensions))

    # Skip loading pollster upon ExtensionLoadError
    @mock.patch('ceilometer.ipmi.pollsters.node._Base.__init__',
                mock.Mock(side_effect=plugin_base.ExtensionLoadError(
                    'NodeManager not supported on host')))
    @mock.patch('ceilometer.polling.manager.LOG')
    def test_load_failed_plugins(self, LOG):
        # Here we additionally check that namespaces will be converted to the
        # list if param was not set as a list.
        manager.AgentManager(0, self.conf, namespaces='ipmi')
        err_msg = 'Skip loading extension for %s: %s'
        pollster_names = [
            'power', 'temperature', 'outlet_temperature',
            'airflow', 'cups', 'cpu_util', 'mem_util', 'io_util']
        calls = [mock.call(err_msg, 'hardware.ipmi.node.%s' % n,
                           'NodeManager not supported on host')
                 for n in pollster_names]
        LOG.debug.assert_has_calls(calls=calls[:2], any_order=True)

    # Skip loading pollster upon ImportError
    @mock.patch('ceilometer.ipmi.pollsters.node._Base.__init__',
                mock.Mock(side_effect=ImportError))
    @mock.patch('ceilometer.ipmi.pollsters.sensor.SensorPollster.__init__',
                mock.Mock(side_effect=ImportError))
    @mock.patch('ceilometer.polling.manager.LOG')
    def test_import_error_in_plugin(self, LOG):
        namespaces = ['ipmi']
        manager.AgentManager(0, self.conf, namespaces=namespaces)
        LOG.warning.assert_called_with(
            'No valid pollsters can be loaded from %s namespaces', namespaces)

    # Exceptions other than ExtensionLoadError are propagated
    @mock.patch('ceilometer.ipmi.pollsters.node._Base.__init__',
                mock.Mock(side_effect=PollingException))
    @mock.patch('ceilometer.ipmi.pollsters.sensor.SensorPollster.__init__',
                mock.Mock(side_effect=PollingException))
    def test_load_exceptional_plugins(self):
        self.assertRaises(PollingException,
                          manager.AgentManager,
                          0, self.conf,
                          ['ipmi'])

    def test_builder(self):
        @staticmethod
        def fake_get_ext_mgr(namespace, *args, **kwargs):
            if 'builder' in namespace:
                return extension.ExtensionManager.make_test_instance(
                    [
                        extension.Extension('builder',
                                            None,
                                            TestPollsterBuilder,
                                            None),
                    ]
                )
            else:
                return extension.ExtensionManager.make_test_instance(
                    [
                        extension.Extension('test',
                                            None,
                                            None,
                                            TestPollster(self.conf)),
                    ]
                )

        with mock.patch.object(manager.AgentManager, '_get_ext_mgr',
                               new=fake_get_ext_mgr):
            mgr = manager.AgentManager(0, self.conf, namespaces=['central'])
            self.assertEqual(3, len(mgr.extensions))
            for ext in mgr.extensions:
                self.assertIn(ext.name, ['builder1', 'builder2', 'test'])
                self.assertIsInstance(ext.obj, TestPollster)