Esempio n. 1
0
    def init_host(self):
        # Use the nova configuration flags to get
        # a connection to the RPC mechanism nova
        # is using.
        self.connection = rpc.create_connection()

        storage.register_opts(cfg.CONF)
        self.storage_engine = storage.get_engine(cfg.CONF)
        self.storage_conn = self.storage_engine.get_connection(cfg.CONF)

        self.handler = dispatcher.NotificationDispatcher(
            COLLECTOR_NAMESPACE,
            self._publish_counter,
        )
        # FIXME(dhellmann): Should be using create_worker(), except
        # that notification messages do not conform to the RPC
        # invocation protocol (they do not include a "method"
        # parameter).
        for topic in self.handler.topics:
            self.connection.declare_topic_consumer(
                topic=topic,
                queue_name="ceilometer.notifications",
                callback=functools.partial(self.handler.notify, topic))

        # Set ourselves up as a separate worker for the metering data,
        # since the default for manager is to use create_consumer().
        self.connection.create_worker(
            cfg.CONF.metering_topic,
            rpc_dispatcher.RpcDispatcher([self]),
            'ceilometer.collector.' + cfg.CONF.metering_topic,
        )

        self.connection.consume_in_thread()
Esempio n. 2
0
def test_notify_through_plugin():
    results = []
    d = dispatcher.NotificationDispatcher('ceilometer.collector.compute',
                                          lambda x: results.append(x))
    d.notify(TEST_NOTICE)
    assert len(results) == 1
    counter = results[0]
    assert counter.name == 'instance'
Esempio n. 3
0
def test_notify_through_plugin():
    results = []
    d = dispatcher.NotificationDispatcher('ceilometer.collector',
                                          lambda x: results.append(x))
    d.notify("notifications.info", TEST_NOTICE)
    assert len(results) >= 1
    results_name = [result.name for result in results]
    assert 'instance' in results_name
    assert 'memory' in results_name
Esempio n. 4
0
    def init_host(self):
        self.connection = rpc.Connection(flags.FLAGS)

        self.compute_handler = dispatcher.NotificationDispatcher(
            COMPUTE_COLLECTOR_NAMESPACE,
            self._publish_counter,
            )
        # FIXME(dhellmann): Should be using create_worker(), except
        # that notification messages do not conform to the RPC
        # invocation protocol (they do not include a "method"
        # parameter).
        self.connection.declare_topic_consumer(
            topic='%s.info' % flags.FLAGS.notification_topics[0],
            callback=self.compute_handler.notify)

        # Set ourselves up as a separate worker for the metering data,
        # since the default for manager is to use create_consumer().
        self.connection.create_worker(
            cfg.CONF.metering_topic,
            rpc_dispatcher.RpcDispatcher([self]),
            'ceilometer.collector.' + cfg.CONF.metering_topic,
            )

        self.connection.consume_in_thread()
Esempio n. 5
0
def test_notify_topics():
    results = []
    d = dispatcher.NotificationDispatcher('ceilometer.collector',
                                          lambda x: results.append(x))
    d.notify("dont.care", TEST_NOTICE)
    assert len(results) == 0
Esempio n. 6
0
def test_load_no_plugins():
    results = []
    d = dispatcher.NotificationDispatcher('ceilometer.collector.none',
                                          lambda x: results.append(x))
    assert not d.handlers, 'Handlers were loaded'