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) self.conn = rpc.create_connection(new=True) logging.debug("Creating Consumer connection for Service %s" % self.topic) # Share this same connection for these Consumers consumer_all = rpc.create_consumer(self.conn, self.topic, self, fanout=False) node_topic = '%s.%s' % (self.topic, self.host) consumer_node = rpc.create_consumer(self.conn, node_topic, self, fanout=False) fanout = rpc.create_consumer(self.conn, self.topic, self, fanout=True) consumers = [consumer_all, consumer_node, fanout] consumer_set = rpc.create_consumer_set(self.conn, consumers) # Wait forever, processing these consumers def _wait(): try: consumer_set.wait() finally: consumer_set.close() self.consumer_set_thread = eventlet.spawn(_wait) if self.report_interval: 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)
def setUp(self): super(RpcAMQPTestCase, self).setUp() self.conn = rpc.create_connection(True) self.receiver = TestReceiver() self.consumer = rpc.create_consumer(self.conn, "test", self.receiver, False) self.consumer.attach_to_eventlet() self.context = context.get_admin_context()
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()) # TODO: so, it will replay the context and use the same REQID? # that's bizarre. ret = rpc.call(context, queue, {"method": "echo", "args": {"value": value}}) LOG.debug(_("Nested return %s"), ret) return value nested = Nested() conn = rpc.create_connection(True) consumer = rpc.create_consumer(conn, 'nested', nested, False) consumer.attach_to_eventlet() value = 42 result = rpc.call(self.context, 'nested', {"method": "echo", "args": {"queue": "test", "value": value}}) self.assertEqual(value, result)
def test_rpc_consumer_isolation(self): class NeverCalled(object): def __getattribute__(*args): assert False, "I should never get called." connection = rpc.create_connection(new=True) proxy = NeverCalled() consumer = rpc.create_consumer(connection, 'compute', proxy, fanout=False) consumer.attach_to_eventlet()