def test_call_fanout(self): transport = _FakeTransport(self.conf) client = oslo_messaging.RPCClient(transport, oslo_messaging.Target(**self.target)) if self.prepare is not _notset: client = client.prepare(**self.prepare) self.assertRaises(exceptions.InvalidTarget, client.call, {}, 'foo')
def conductor_client(self): if self._conductor_client is None: target = om.Target( topic=self.conductor_topic, version=self.API_VERSION, ) self._conductor_client = om.RPCClient(self.transport, target, serializer=self.serializer) return self._conductor_client
def __init__(self): super(A10ProviderDriver, self).__init__() self._args = {} self.transport = messaging.get_rpc_transport(cfg.CONF) self._args['fanout'] = False self._args['namespace'] = constants.RPC_NAMESPACE_CONTROLLER_AGENT self._args['topic'] = "a10_octavia" self._args['version'] = '1.0' self.target = messaging.Target(**self._args) self.client = messaging.RPCClient(self.transport, target=self.target)
def test_invalid_version_type(self): target = oslo_messaging.Target(topic='sometopic') transport = _FakeTransport(self.conf) client = oslo_messaging.RPCClient(transport, target) self.assertRaises(exceptions.MessagingException, client.prepare, version='5') self.assertRaises(exceptions.MessagingException, client.prepare, version='5.a') self.assertRaises(exceptions.MessagingException, client.prepare, version='5.5.a')
def client(self, context): transport = context.mq_connection if transport: cmt = self.default_client.call_monitor_timeout return messaging.RPCClient(transport, self.target, version_cap=self.version_cap, serializer=self.serializer, call_monitor_timeout=cmt) else: return self.default_client
def invoke_service_rpc(self, service_id, method, kwargs=None, timeout=None, local=False, retry=None): """Invoke RPC method on a DSE Service. :param: service_id: The ID of the data service on which to invoke the call. :param: method: The method name to call. :param: kwargs: A dict of method arguments. :returns: The result of the method invocation. :raises: MessagingTimeout, RemoteError, MessageDeliveryFailure, NotFound """ target = self.service_rpc_target( service_id, server=(self.node_id if local else None)) LOG.trace("<%s> Preparing to invoking RPC '%s' on %s", self.node_id, method, target) client = messaging.RPCClient(self.transport, target, timeout=timeout, retry=retry) if not self.is_valid_service(service_id): try: # First ping the destination to fail fast if unresponsive LOG.trace( "<%s> Checking responsiveness before invoking RPC " "'%s' on %s", self.node_id, method, target) client.prepare(timeout=cfg.CONF.dse.ping_timeout).call( self.context, 'ping') except (messaging_exceptions.MessagingTimeout, messaging_exceptions.MessageDeliveryFailure): msg = "service '%s' could not be found" raise exception.RpcTargetNotFound(msg % service_id) if kwargs is None: kwargs = {} try: LOG.trace("<%s> Invoking RPC '%s' on %s", self.node_id, method, target) result = client.call(self.context, method, **kwargs) except dispatcher.NoSuchMethod: msg = "Method %s not supported for datasource %s" LOG.exception(msg, method, service_id) raise exception.BadRequest(msg % (method, service_id)) except (messaging_exceptions.MessagingTimeout, messaging_exceptions.MessageDeliveryFailure): msg = "Request to service '%s' timed out" raise exception.Unavailable(msg % service_id) LOG.trace("<%s> RPC call returned: %s", self.node_id, result) return result
def call(self, topic, server, api_name, timeout=2, retry=0, **api_kwargs): target = oslo_messaging.Target( topic=topic, server=server, version=self.broker_endpoint.Version, namespace=self.broker_endpoint.Namespace) queryclient = oslo_messaging.RPCClient(self.transport, target, timeout=timeout, retry=retry) return queryclient.call({}, api_name, **api_kwargs)
def get_client(target, version_cap=None, serializer=None, timeout=None): assert TRANSPORT is not None if profiler: serializer = ProfilerRequestContextSerializer(serializer) else: serializer = RequestContextSerializer(serializer) return messaging.RPCClient(TRANSPORT, target, version_cap=version_cap, serializer=serializer, timeout=timeout)
def get_client(transport, target, version_cap=None, serializer=None): assert transport is not None if profiler: LOG.info('profiler enabled for RPC client') serializer = ProfilerContextSerializer(serializer=serializer) return messaging.RPCClient(transport, target, version_cap=version_cap, serializer=serializer)
def cast(self, topic, api_name, timeout=None, retry=None, **api_kwargs): target = oslo_messaging.Target( topic=topic, fanout=True, version=self.broker_endpoint.Version, namespace=self.broker_endpoint.Namespace) queryclient = oslo_messaging.RPCClient(self.transport, target, timeout=timeout, retry=retry) queryclient.cast({}, api_name, **api_kwargs)
def __init__(self, conf): super(OsloRPCClient, self).__init__(conf) self.topic = conf.topic serializer = auth_ctx.RpcContextSerializer() self._client = messaging.RPCClient( rpc.get_transport(), messaging.Target(topic=self.topic), serializer=serializer )
def __init__(self, transport): super(YarmaPublisherService, self).__init__() self.publisher_target = messaging.Target( topic=cfg.CONF.default.publisher_queue, ) self.transport = transport self.server = messaging.RPCClient( self.transport, self.publisher_target, serializer=messaging.JsonPayloadSerializer() )
def __init__(self, transport=None, context=None, topic=None): serializer = RequestContextSerializer(JsonPayloadSerializer()) if transport is None: transport = messaging.get_transport(cfg.CONF) self._context = context if topic is None: topic = '' target = messaging.Target(topic=topic) self._client = messaging.RPCClient(transport, target, serializer=serializer)
def __init__(self): super(AmphoraProviderDriver, self).__init__() topic = cfg.CONF.oslo_messaging.topic self.transport = messaging.get_rpc_transport(cfg.CONF) self.target = messaging.Target( namespace=consts.RPC_NAMESPACE_CONTROLLER_AGENT, topic=topic, version="1.0", fanout=False) self.client = messaging.RPCClient(self.transport, target=self.target) self.repositories = repositories.Repositories()
def __init__(self, amp_id): super(FailoverController, self).__init__() topic = cfg.CONF.oslo_messaging.topic self.transport = messaging.get_rpc_transport(cfg.CONF) self.target = messaging.Target( namespace=constants.RPC_NAMESPACE_CONTROLLER_AGENT, topic=topic, version="1.0", fanout=False) self.client = messaging.RPCClient(self.transport, target=self.target) self.amp_id = amp_id
def get_client(target, version_cap=None, serializer=None): if TRANSPORT is None: raise AssertionError("'TRANSPORT' must not be None") if serializer is None: serializer = DesignateObjectSerializer() serializer = RequestContextSerializer(serializer) return messaging.RPCClient( TRANSPORT, target, version_cap=version_cap, serializer=serializer )
def get_cell_client(context, default_client): """Get a RPCClient object based on a RequestContext. :param context: The RequestContext that can contain a Transport :param default_client: The default RPCClient """ if context.mq_connection: return messaging.RPCClient(context.mq_connection, default_client.target, version_cap=default_client.version_cap, serializer=default_client.serializer) return default_client
def __init__(self, transport): """Constructs an RPC client for engine. :param transport: Messaging transport. """ serializer = auth_ctx.RpcContextSerializer( auth_ctx.JsonPayloadSerializer()) self._client = messaging.RPCClient( transport, messaging.Target(topic=cfg.CONF.engine.topic), serializer=serializer)
def __init__(self, transport_url, fake_server=False): if not fake_server: transport = messaging.get_transport( cfg.CONF, transport_url, allowed_remote_exmods=ALLOWED_EXMODS) else: from . import rpc fake_rpc_server = rpc.start_fake_server() transport = fake_rpc_server.transport target = messaging.Target(topic=self.topic, namespace=self.namespace, version=self.version) self.client = messaging.RPCClient(transport, target, serializer=RPCSerializer())
def __init__(self): """Initialize the driver plugin RPC client.""" self.environment_prefix = 'Project' self.topic = '%s_%s' % (f5_const.TOPIC_PROCESS_ON_HOST_V2, self.environment_prefix) messaging.set_transport_defaults('neutron') self.transport = messaging.get_transport( CONF, url=CONF.f5_lbaasv2_driver.transport_url) self.target = messaging.Target(topic=self.topic) self.client = messaging.RPCClient(self.transport, self.target) self.context = context.get_admin_context().to_dict()
def test_call_serializer(self): self.config(rpc_response_timeout=None) transport = oslo_messaging.get_rpc_transport(self.conf, url='fake:') serializer = msg_serializer.NoOpSerializer() client = oslo_messaging.RPCClient(transport, oslo_messaging.Target(), serializer=serializer) transport._send = mock.Mock() kwargs = dict(wait_for_reply=True, timeout=None) if self.call else {} kwargs['retry'] = None if self.call: kwargs['call_monitor_timeout'] = None transport._send.return_value = self.retval serializer.serialize_entity = mock.Mock() serializer.deserialize_entity = mock.Mock() serializer.serialize_context = mock.Mock() def _stub(ctxt, arg): return 's' + arg msg = dict(method='foo', args=dict()) for k, v in self.args.items(): msg['args'][k] = 's' + v serializer.serialize_entity.side_effect = _stub if self.call: serializer.deserialize_entity.return_value = 'd' + self.retval serializer.serialize_context.return_value = dict(user='******') method = client.call if self.call else client.cast retval = method(self.ctxt, 'foo', **self.args) if self.retval is not None: self.assertEqual('d' + self.retval, retval) transport._send.assert_called_once_with(oslo_messaging.Target(), dict(user='******'), msg, transport_options=None, **kwargs) expected_calls = [mock.call(self.ctxt, arg) for arg in self.args] self.assertEqual(expected_calls, serializer.serialize_entity.mock_calls) if self.call: serializer.deserialize_entity.assert_called_once_with( self.ctxt, self.retval) serializer.serialize_context.assert_called_once_with(self.ctxt)
def __init__(self): target = messaging.Target(topic=self.TOPIC, version=self.RPC_API_VERSION) #obj_version_cap = self._determine_obj_version_cap() #serializer = base.WaterfallObjectSerializer(obj_version_cap) #rpc_version_cap = self._determine_rpc_version_cap() #self.client = get_client(target, version_cap=rpc_version_cap, # serializer=serializer) #serializer = RequestContextSerializer(serializer) self.client = messaging.RPCClient(TRANSPORT, target, version_cap='2.0')
def setUp(self): super(RpcServerFixture, self).setUp() endpoints = [self.endpoint, self] transport = self.useFixture(TransportFixture(self.conf, self.url)) self.server = oslo_messaging.get_rpc_server( transport=transport.transport, target=self.target, endpoints=endpoints, executor=self.executor) self._ctrl = oslo_messaging.RPCClient(transport.transport, self.ctrl_target) self._start() transport.wait()
def __init__(self, transport=None, context=None, topic=None, server=None, timeout=None): serializer = _init_serializer() if transport is None: exmods = rpc.get_allowed_exmods() transport = messaging.get_rpc_transport( CONF, allowed_remote_exmods=exmods) self._context = context if topic is None: topic = '' target = messaging.Target(topic=topic, server=server) self._client = messaging.RPCClient(transport, target, serializer=serializer, timeout=timeout)
def __init__(self): topic = cfg.CONF.oslo_messaging.event_stream_topic if cfg.CONF.oslo_messaging.event_stream_transport_url: # Use custom URL self.transport = oslo_messaging.get_rpc_transport( cfg.CONF, cfg.CONF.oslo_messaging.event_stream_transport_url) else: self.transport = oslo_messaging.get_rpc_transport(cfg.CONF) self.target = oslo_messaging.Target(topic=topic, exchange="common", namespace='control', fanout=False, version='1.0') self.client = oslo_messaging.RPCClient(self.transport, self.target)
def create_client(component_name): topic = topics.CASCADING_SERVICE target = oslo_messaging.Target( exchange="tricircle", topic=topic, namespace=component_name, version='1.0', ) return oslo_messaging.RPCClient( TRANSPORT, target, serializer=Serializer(), )
def __init__(self): """ RPC mode has two function for sending message 1.cast(ctxt, method, **kwargs): Do not have return value 2.call(ctxt, method, **kwargs): Have return value :param ctxt: (dict) A request context dict :param method: (str) The remote method :param **kwargs: (dict) The params of the remote method """ super(RPCClient, self).__init__() self.transport = oslo_messaging.get_transport(cfg.CONF) self.target = oslo_messaging.Target(topic=self.topic, exchange='common', namespace='control', fanout=False, version='1.0') self.client = oslo_messaging.RPCClient(self.transport, self.target)
def __init__(self, transport, target, cast=False, name=None, transport_options=None, **kwargs): self.name = name or "functional-tests" self.cast = cast self.client = oslo_messaging.RPCClient( transport=transport, target=target, transport_options=transport_options, **kwargs)
def get_client(topic=None): """Get a RPC client instance. :param topic: The topic of the message will be delivered to. This argument is ignored if CONF.standalone is True. """ assert TRANSPORT is not None if CONF.standalone: target = messaging.Target(topic=manager.MANAGER_TOPIC, server=CONF.host, version='1.3') else: target = messaging.Target(topic=topic, version='1.3') return messaging.RPCClient(TRANSPORT, target)
def saygood(): try: transport_url = 'rabbit://*****:*****@10.0.0.108:5672/' #transport_url = 'rabbit://*****:*****@10.1.101.36:5672/' transport = oslo_messaging.get_transport(cfg.CONF,transport_url) #mac = request.args.get("mac") mac = request.json.get("mac") #mac = request.form["mac"] target = oslo_messaging.Target(topic='test', server=getCid(mac)) client = oslo_messaging.RPCClient(transport, target) r = client.prepare(timeout=2).call({}, 'sayGood') except: return ("error", 400) else: return 'success'