Exemplo n.º 1
0
    def start(self):
        super(Service, self).start()

        self.conn = rpc.create_connection(new=True)
        LOG.debug(
            _("Creating Consumer connection for Service %s") % self.topic)

        dispatcher = rpc_dispatcher.RpcDispatcher([self.manager],
                                                  self.serializer)

        # Share this same connection for these Consumers
        self.conn.create_consumer(self.topic, dispatcher, fanout=False)

        node_topic = '%s.%s' % (self.topic, self.host)
        self.conn.create_consumer(node_topic, dispatcher, fanout=False)

        self.conn.create_consumer(self.topic, dispatcher, fanout=True)

        # Hook to allow the manager to do other initializations after
        # the rpc connection is created.
        if callable(getattr(self.manager, 'initialize_service_hook', None)):
            self.manager.initialize_service_hook(self)

        # Consume from all consumers in a thread
        self.conn.consume_in_thread()
Exemplo n.º 2
0
    def test_dispatch_no_version_uses_v1(self):
        v1 = self.API1()
        disp = dispatcher.RpcDispatcher([v1])

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

        self.assertEqual(v1.test_method_ctxt, self.ctxt)
        self.assertEqual(v1.test_method_arg1, 1)
Exemplo n.º 3
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', None, 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])
Exemplo n.º 4
0
    def test_method_with_namespace(self):
        v1 = self.API1()
        v4 = self.API4()
        disp = dispatcher.RpcDispatcher([v1, v4])

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

        self.assertEqual(v1.test_method_ctxt, None)
        self.assertEqual(v1.test_method_arg1, None)
        self.assertEqual(v4.test_method_ctxt, self.ctxt)
        self.assertEqual(v4.test_method_arg1, 1)
Exemplo n.º 5
0
    def test_serializer(self):
        api = self.API1()
        serializer = rpc_serializer.NoOpSerializer()

        self.mox.StubOutWithMock(serializer, 'serialize_entity')
        self.mox.StubOutWithMock(serializer, 'deserialize_entity')

        serializer.deserialize_entity(self.ctxt, 1).AndReturn(1)
        serializer.serialize_entity(self.ctxt, 'fake-result').AndReturn(
            'worked!')

        self.mox.ReplayAll()

        disp = dispatcher.RpcDispatcher([api], serializer)
        result = disp.dispatch(self.ctxt, '1.0', 'test_method',
                               None, arg1=1)
        self.assertEqual(result, 'worked!')
Exemplo n.º 6
0
    def start(self):
        super(Service, self).start()

        self.conn = rpc.create_connection(new=True)
        LOG.debug(
            _("Creating Consumer connection for Service %s") % self.topic)

        dispatcher = rpc_dispatcher.RpcDispatcher([self.manager])

        # Share this same connection for these Consumers
        self.conn.create_consumer(self.topic, dispatcher, fanout=False)

        node_topic = '%s.%s' % (self.topic, self.host)
        self.conn.create_consumer(node_topic, dispatcher, fanout=False)

        self.conn.create_consumer(self.topic, dispatcher, fanout=True)

        # Consume from all consumers in a thread
        self.conn.consume_in_thread()
Exemplo n.º 7
0
 def test_missing_method_version_no_match(self):
     v1 = self.API1()
     disp = dispatcher.RpcDispatcher([v1])
     self.assertRaises(rpc_common.UnsupportedRpcVersion,
                       disp.dispatch,
                       self.ctxt, "2.0", "does_not_exist", None)
Exemplo n.º 8
0
 def test_missing_method_version_match(self):
     v1 = self.API1()
     disp = dispatcher.RpcDispatcher([v1])
     self.assertRaises(AttributeError,
                       disp.dispatch,
                       self.ctxt, "1.0", "does_not_exist", None)
Exemplo n.º 9
0
 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