コード例 #1
0
    def start(self):
        vcs_string = version.version_string_with_vcs()
        logging.audit(_('Starting %(topic)s node (version %(vcs_string)s)'),
                      {'topic': self.topic, 'vcs_string': vcs_string})
        self.manager.init_host()

        conn1 = rpc.Connection.instance(new=True)
        conn2 = rpc.Connection.instance(new=True)
        conn3 = rpc.Connection.instance(new=True)
        if self.report_interval:
            consumer_all = rpc.TopicAdapterConsumer(
                    connection=conn1,
                    topic=self.topic,
                    proxy=self)
            consumer_node = rpc.TopicAdapterConsumer(
                    connection=conn2,
                    topic='%s.%s' % (self.topic, self.host),
                    proxy=self)
            fanout = rpc.FanoutAdapterConsumer(
                    connection=conn3,
                    topic=self.topic,
                    proxy=self)

            self.timers.append(consumer_all.attach_to_eventlet())
            self.timers.append(consumer_node.attach_to_eventlet())
            self.timers.append(fanout.attach_to_eventlet())

            pulse = utils.LoopingCall(self.report_state)
            pulse.start(interval=self.report_interval, now=False)
            self.timers.append(pulse)

        if self.periodic_interval:
            periodic = utils.LoopingCall(self.periodic_tasks)
            periodic.start(interval=self.periodic_interval, now=False)
            self.timers.append(periodic)
コード例 #2
0
    def test_create(self):
        host = 'foo'
        binary = 'nova-fake'
        topic = 'fake'

        # NOTE(vish): Create was moved out of mox replay to make sure that
        #             the looping calls are created in StartService.
        app = service.Service.create(host=host, binary=binary)

        self.mox.StubOutWithMock(rpc,
                                 'TopicAdapterConsumer',
                                 use_mock_anything=True)
        self.mox.StubOutWithMock(rpc,
                                 'FanoutAdapterConsumer',
                                 use_mock_anything=True)
        rpc.TopicAdapterConsumer(connection=mox.IgnoreArg(),
                                 topic=topic,
                                 proxy=mox.IsA(service.Service)).AndReturn(
                                     rpc.TopicAdapterConsumer)

        rpc.TopicAdapterConsumer(connection=mox.IgnoreArg(),
                                 topic='%s.%s' % (topic, host),
                                 proxy=mox.IsA(service.Service)).AndReturn(
                                     rpc.TopicAdapterConsumer)

        rpc.FanoutAdapterConsumer(connection=mox.IgnoreArg(),
                                  topic=topic,
                                  proxy=mox.IsA(service.Service)).AndReturn(
                                      rpc.FanoutAdapterConsumer)

        rpc.TopicAdapterConsumer.attach_to_eventlet()
        rpc.TopicAdapterConsumer.attach_to_eventlet()
        rpc.FanoutAdapterConsumer.attach_to_eventlet()

        service_create = {
            'host': host,
            'binary': binary,
            'topic': topic,
            'report_count': 0,
            'availability_zone': 'nova'
        }
        service_ref = {
            'host': host,
            'binary': binary,
            'report_count': 0,
            'id': 1
        }

        service.db.service_get_by_args(mox.IgnoreArg(), host,
                                       binary).AndRaise(exception.NotFound())
        service.db.service_create(mox.IgnoreArg(),
                                  service_create).AndReturn(service_ref)
        self.mox.ReplayAll()

        app.start()
        app.stop()
        self.assert_(app)
コード例 #3
0
    def test_nested_calls(self):
        """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())
                ret = rpc.call(context, queue, {
                    "method": "echo",
                    "args": {
                        "value": value
                    }
                })
                LOG.debug(_("Nested return %s"), ret)
                return value

        nested = Nested()
        conn = rpc.Connection.instance(True)
        consumer = rpc.TopicAdapterConsumer(connection=conn,
                                            topic='nested',
                                            proxy=nested)
        consumer.attach_to_eventlet()
        value = 42
        result = rpc.call(self.context, 'nested', {
            "method": "echo",
            "args": {
                "queue": "test",
                "value": value
            }
        })
        self.assertEqual(value, result)
コード例 #4
0
ファイル: service.py プロジェクト: termie/nova-migration-demo
    def start(self):
        vcs_string = version.version_string_with_vcs()
        logging.audit(_('Starting %(topic)s node (version %(vcs_string)s)'), {
            'topic': self.topic,
            'vcs_string': vcs_string
        })
        self.manager.init_host()
        self.model_disconnected = False
        ctxt = context.get_admin_context()
        try:
            service_ref = db.service_get_by_args(ctxt, self.host, self.binary)
            self.service_id = service_ref['id']
        except exception.NotFound:
            self._create_service_ref(ctxt)

        if 'nova-compute' == self.binary:
            self.manager.update_available_resource(ctxt)

        conn1 = rpc.Connection.instance(new=True)
        conn2 = rpc.Connection.instance(new=True)
        conn3 = rpc.Connection.instance(new=True)
        if self.report_interval:
            consumer_all = rpc.TopicAdapterConsumer(connection=conn1,
                                                    topic=self.topic,
                                                    proxy=self)
            consumer_node = rpc.TopicAdapterConsumer(connection=conn2,
                                                     topic='%s.%s' %
                                                     (self.topic, self.host),
                                                     proxy=self)
            fanout = rpc.FanoutAdapterConsumer(connection=conn3,
                                               topic=self.topic,
                                               proxy=self)

            self.timers.append(consumer_all.attach_to_eventlet())
            self.timers.append(consumer_node.attach_to_eventlet())
            self.timers.append(fanout.attach_to_eventlet())

            pulse = utils.LoopingCall(self.report_state)
            pulse.start(interval=self.report_interval, now=False)
            self.timers.append(pulse)

        if self.periodic_interval:
            periodic = utils.LoopingCall(self.periodic_tasks)
            periodic.start(interval=self.periodic_interval, now=False)
            self.timers.append(periodic)
コード例 #5
0
 def setUp(self):
     super(RpcTestCase, self).setUp()
     self.conn = rpc.Connection.instance(True)
     self.receiver = TestReceiver()
     self.consumer = rpc.TopicAdapterConsumer(connection=self.conn,
                                              topic='test',
                                              proxy=self.receiver)
     self.consumer.attach_to_eventlet()
     self.context = context.get_admin_context()
コード例 #6
0
 def test_rpc_consumer_isolation(self):
     connection = rpc.Connection.instance(new=True)
     consumer = rpc.TopicAdapterConsumer(connection, topic='compute')
     consumer.register_callback(
         lambda x, y: self.fail('I should never be called'))
     consumer.attach_to_eventlet()