Example #1
0
    def create_rpc_dispatcher(self):
        '''Get the rpc dispatcher for this manager.

        If a manager would like to set an rpc API version, or support more than
        one class as the target of rpc messages, override this method.
        '''
        return rpc_dispatcher.RpcDispatcher([self])
Example #2
0
    def test_dispatch_no_version_uses_v1(self):
        v1 = self.API1()
        disp = dispatcher.RpcDispatcher([v1])

        disp.dispatch(self.ctxt, None, 'test_method', arg1=1)

        self.assertEqual(v1.test_method_ctxt, self.ctxt)
        self.assertEqual(v1.test_method_arg1, 1)
Example #3
0
 def setUp(self, supports_timeouts=True):
     super(BaseRpcTestCase, self).setUp()
     self.supports_timeouts = supports_timeouts
     self.context = context.get_admin_context()
     if self.rpc:
         self.conn = self.rpc.create_connection(FLAGS, True)
         receiver = TestReceiver()
         self.dispatcher = rpc_dispatcher.RpcDispatcher([receiver])
         self.conn.create_consumer('test', self.dispatcher, False)
         self.conn.consume_in_thread()
Example #4
0
    def _test_dispatch(self, version, expectations):
        v2 = self.API2()
        v3 = self.API3()
        disp = dispatcher.RpcDispatcher([v2, v3])

        disp.dispatch(self.ctxt, version, 'test_method', arg1=1)

        self.assertEqual(v2.test_method_ctxt, expectations[0])
        self.assertEqual(v2.test_method_arg1, expectations[1])
        self.assertEqual(v3.test_method_ctxt, expectations[2])
        self.assertEqual(v3.test_method_arg1, expectations[3])
Example #5
0
    def test_nested_calls(self):
        if not self.rpc:
            raise nose.SkipTest('rpc driver not available.')
        """Test that we can do an rpc.call inside another call."""
        class Nested(object):
            @staticmethod
            def echo(context, queue, value):
                """Calls echo in the passed queue"""
                LOG.debug(_("Nested received %(queue)s, %(value)s") % locals())
                # TODO(comstud):
                # so, it will replay the context and use the same REQID?
                # that's bizarre.
                ret = self.rpc.call(FLAGS, context, queue, {
                    "method": "echo",
                    "args": {
                        "value": value
                    }
                })
                LOG.debug(_("Nested return %s"), ret)
                return value

        nested = Nested()
        dispatcher = rpc_dispatcher.RpcDispatcher([nested])
        conn = self.rpc.create_connection(FLAGS, True)
        conn.create_consumer('nested', dispatcher, False)
        conn.consume_in_thread()
        value = 42
        result = self.rpc.call(FLAGS, self.context, 'nested', {
            "method": "echo",
            "args": {
                "queue": "test",
                "value": value
            }
        })
        conn.close()
        self.assertEqual(value, result)
Example #6
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()
Example #7
0
File: common.py Project: kiall/nova
 def _create_consumer(self, proxy, topic, fanout=False):
     dispatcher = rpc_dispatcher.RpcDispatcher([proxy])
     conn = self.rpc.create_connection(FLAGS, True)
     conn.create_consumer(topic, dispatcher, fanout)
     conn.consume_in_thread()
     return conn