def test_when_no_args_then_default_zmq_module_is_loaded(self): mock_try_import = mock.Mock() zmq_async.importutils.try_import = mock_try_import zmq_async.import_zmq() mock_try_import.assert_called_with('eventlet.green.zmq', default=None)
def test_when_evetlet_is_unavailable_then_load_zmq(self): zmq_async.eventletutils.is_monkey_patched = lambda _: False mock_try_import = mock.Mock() zmq_async.importutils.try_import = mock_try_import zmq_async.import_zmq() mock_try_import.assert_called_with('zmq', default=None)
def test_config_short_names_are_converted_to_correct_module_names(self): mock_try_import = mock.Mock() zmq_async.importutils.try_import = mock_try_import zmq_async.importutils.try_import.return_value = 'mock zmq module' self.assertEqual('mock zmq module', zmq_async.import_zmq('native')) mock_try_import.assert_called_with('zmq', default=None) zmq_async.importutils.try_import.return_value = 'mock eventlet module' self.assertEqual('mock eventlet module', zmq_async.import_zmq('eventlet')) mock_try_import.assert_called_with('eventlet.green.zmq', default=None)
def __init__(self, conf, url, default_exchange=None, allowed_remote_exmods=None): """Construct ZeroMQ driver. Initialize driver options. Construct matchmaker - pluggable interface to targets management Name Service Construct client and server controllers :param conf: oslo messaging configuration object :type conf: oslo_config.CONF :param url: transport URL :type url: TransportUrl :param default_exchange: Not used in zmq implementation :type default_exchange: None :param allowed_remote_exmods: remote exception passing options :type allowed_remote_exmods: list """ zmq = zmq_async.import_zmq() if zmq is None: raise ImportError(_LE("ZeroMQ is not available!")) conf.register_opts(zmq_opts) conf.register_opts(impl_pooledexecutor._pool_opts) conf.register_opts(base.base_opts) self.conf = conf self.allowed_remote_exmods = allowed_remote_exmods self.matchmaker = driver.DriverManager( 'oslo.messaging.zmq.matchmaker', self.conf.rpc_zmq_matchmaker, ).driver(self.conf) self.server = LazyDriverItem( zmq_server.ZmqServer, self, self.conf, self.matchmaker) self.notify_server = LazyDriverItem( zmq_server.ZmqServer, self, self.conf, self.matchmaker) client_cls = zmq_client_light.ZmqClientLight \ if conf.zmq_use_broker else zmq_client.ZmqClient self.client = LazyDriverItem( client_cls, self.conf, self.matchmaker, self.allowed_remote_exmods) self.notifier = LazyDriverItem( client_cls, self.conf, self.matchmaker, self.allowed_remote_exmods) super(ZmqDriver, self).__init__(conf, url, default_exchange, allowed_remote_exmods)
def __init__(self, conf, url, default_exchange=None, allowed_remote_exmods=None): """Construct ZeroMQ driver. Initialize driver options. Construct matchmaker - pluggable interface to targets management Name Service Construct client and server controllers :param conf: oslo messaging configuration object :type conf: oslo_config.CONF :param url: transport URL :type url: TransportUrl :param default_exchange: Not used in zmq implementation :type default_exchange: None :param allowed_remote_exmods: remote exception passing options :type allowed_remote_exmods: list """ zmq = zmq_async.import_zmq() if zmq is None: raise ImportError(_LE("ZeroMQ is not available!")) conf = zmq_options.register_opts(conf, url) self.conf = conf self.allowed_remote_exmods = allowed_remote_exmods self.matchmaker = driver.DriverManager( 'oslo.messaging.zmq.matchmaker', self.get_matchmaker_backend(self.conf, url), ).driver(self.conf, url=url) client_cls = zmq_client.ZmqClientProxy if conf.oslo_messaging_zmq.use_pub_sub and not \ conf.oslo_messaging_zmq.use_router_proxy: client_cls = zmq_client.ZmqClientMixDirectPubSub elif not conf.oslo_messaging_zmq.use_pub_sub and not \ conf.oslo_messaging_zmq.use_router_proxy: client_cls = zmq_client.ZmqClientDirect self.client = LazyDriverItem( client_cls, self.conf, self.matchmaker, self.allowed_remote_exmods) self.notifier = LazyDriverItem( client_cls, self.conf, self.matchmaker, self.allowed_remote_exmods) super(ZmqDriver, self).__init__(conf, url, default_exchange, allowed_remote_exmods)
# # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from oslo_messaging._drivers.zmq_driver import zmq_async zmq = zmq_async.import_zmq() FIELD_TYPE = "type" FIELD_FAILURE = "failure" FIELD_REPLY = "reply" FIELD_LOG_FAILURE = "log_failure" FIELD_ID = "id" FIELD_MSG_ID = "message_id" FIELD_MSG_TYPE = "msg_type" FIELD_REPLY_ID = "reply_id" FIELD_TARGET = "target" IDX_REPLY_TYPE = 1 IDX_REPLY_BODY = 2
def test_invalid_config_value_raise_ValueError(self): invalid_opt = 'x' errmsg = 'Invalid zmq_concurrency value: x' with self.assertRaisesRegexp(ValueError, errmsg): zmq_async.import_zmq(invalid_opt)
# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import logging import threading from oslo_utils import eventletutils from oslo_messaging._drivers.zmq_driver import zmq_async from oslo_messaging._drivers.zmq_driver import zmq_poller zmq = zmq_async.import_zmq(zmq_concurrency='native') LOG = logging.getLogger(__name__) _threading = threading if eventletutils.EVENTLET_AVAILABLE: import eventlet _threading = eventlet.patcher.original('threading') class ThreadingPoller(zmq_poller.ZmqPoller): def __init__(self): self.poller = zmq.Poller() self.recv_methods = {}
def test_when_import_fails_then_raise_ImportError(self): zmq_async.importutils.try_import = mock.Mock() zmq_async.importutils.try_import.return_value = None with self.assertRaisesRegexp(ImportError, "ZeroMQ not found!"): zmq_async.import_zmq('native')
import uuid import six from oslo_messaging._drivers import common as rpc_common from oslo_messaging._drivers.zmq_driver import zmq_address from oslo_messaging._drivers.zmq_driver import zmq_async from oslo_messaging._drivers.zmq_driver import zmq_names from oslo_messaging._i18n import _LE, _LI from oslo_messaging import exceptions from oslo_serialization.serializer import json_serializer from oslo_serialization.serializer import msgpack_serializer LOG = logging.getLogger(__name__) zmq = zmq_async.import_zmq() class ZmqSocket(object): SERIALIZERS = { 'json': json_serializer.JSONSerializer(), 'msgpack': msgpack_serializer.MessagePackSerializer() } def __init__(self, conf, context, socket_type, immediate, high_watermark=0,
def test_invalid_config_value_raise_ValueError(self): invalid_opt = 'x' errmsg = 'Invalid zmq_concurrency value: x' with self.assertRaisesRegexp(ValueError, errmsg): zmq_async.import_zmq(invalid_opt)
def test_when_import_fails_then_raise_ImportError(self): zmq_async.importutils.try_import = mock.Mock() zmq_async.importutils.try_import.return_value = None with self.assertRaisesRegexp(ImportError, "ZeroMQ not found!"): zmq_async.import_zmq('native')
# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import logging import threading from oslo_utils import eventletutils from oslo_messaging._drivers.zmq_driver import zmq_async from oslo_messaging._drivers.zmq_driver import zmq_poller zmq = zmq_async.import_zmq(zmq_concurrency='native') LOG = logging.getLogger(__name__) _threading = threading if eventletutils.EVENTLET_AVAILABLE: import eventlet _threading = eventlet.patcher.original('threading') class ThreadingPoller(zmq_poller.ZmqPoller): def __init__(self): self.poller = zmq.Poller() self.recv_methods = {}
# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import logging import threading from oslo_utils import eventletutils from oslo_messaging._drivers.zmq_driver import zmq_async from oslo_messaging._drivers.zmq_driver import zmq_poller zmq = zmq_async.import_zmq(zmq_concurrency="native") LOG = logging.getLogger(__name__) _threading = threading if eventletutils.EVENTLET_AVAILABLE: import eventlet _threading = eventlet.patcher.original("threading") class ThreadingPoller(zmq_poller.ZmqPoller): def __init__(self): self.poller = zmq.Poller() self.recv_methods = {}