diff --git a/oslo/messaging/_drivers/protocols/amqp/__init__.py b/oslo/messaging/_drivers/protocols/amqp/__init__.py index bdd170f57..e69de29bb 100644 --- a/oslo/messaging/_drivers/protocols/amqp/__init__.py +++ b/oslo/messaging/_drivers/protocols/amqp/__init__.py @@ -1,14 +0,0 @@ -# Copyright 2014, Red Hat, Inc. -# -# 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 .driver import ProtonDriver diff --git a/oslo/messaging/_drivers/protocols/amqp/controller.py b/oslo/messaging/_drivers/protocols/amqp/controller.py index d3d14213b..12d4b29bf 100644 --- a/oslo/messaging/_drivers/protocols/amqp/controller.py +++ b/oslo/messaging/_drivers/protocols/amqp/controller.py @@ -35,55 +35,10 @@ from six import moves from oslo.config import cfg from oslo.messaging._drivers.protocols.amqp import eventloop +from oslo.messaging._drivers.protocols.amqp import opts LOG = logging.getLogger(__name__) -_amqp1_opts = [ - cfg.StrOpt('server_request_prefix', - default='exclusive', - help="address prefix used when sending to a specific server"), - - cfg.StrOpt('broadcast_prefix', - default='broadcast', - help="address prefix used when broadcasting to all servers"), - - cfg.StrOpt('group_request_prefix', - default='unicast', - help="address prefix when sending to any server in group"), - - cfg.StrOpt('container_name', - default=None, - help='Name for the AMQP container'), - - cfg.IntOpt('idle_timeout', - default=0, # disabled - help='Timeout for inactive connections (in seconds)'), - - cfg.BoolOpt('trace', - default=False, - help='Debug: dump AMQP frames to stdout'), - - cfg.StrOpt('ssl_ca_file', - default='', - help="CA certificate PEM file for verifing server certificate"), - - cfg.StrOpt('ssl_cert_file', - default='', - help='Identifying certificate PEM file to present to clients'), - - cfg.StrOpt('ssl_key_file', - default='', - help='Private key PEM file used to sign cert_file certificate'), - - cfg.StrOpt('ssl_key_password', - default=None, - help='Password for decrypting ssl_key_file (if encrypted)'), - - cfg.BoolOpt('allow_insecure_clients', - default=False, - help='Accept clients using either SSL or plain TCP') -] - class Task(object): """Perform a messaging operation via the Controller.""" @@ -287,24 +242,27 @@ class Controller(pyngus.ConnectionEventHandler): self._servers = {} self.hosts = Hosts(hosts) - opt_group = cfg.OptGroup(name='amqp1', - title='AMQP 1.0 options') + opt_group = cfg.OptGroup(name='oslo_messaging_amqp', + title='AMQP 1.0 driver options') config.register_group(opt_group) - config.register_opts(_amqp1_opts, group=opt_group) + config.register_opts(opts.amqp1_opts, group=opt_group) - self.server_request_prefix = config.amqp1.server_request_prefix - self.broadcast_prefix = config.amqp1.broadcast_prefix - self.group_request_prefix = config.amqp1.group_request_prefix - self._container_name = config.amqp1.container_name + self.server_request_prefix = \ + config.oslo_messaging_amqp.server_request_prefix + self.broadcast_prefix = config.oslo_messaging_amqp.broadcast_prefix + self.group_request_prefix = \ + config.oslo_messaging_amqp.group_request_prefix + self._container_name = config.oslo_messaging_amqp.container_name if not self._container_name: self._container_name = "container-%s" % uuid.uuid4().hex - self.idle_timeout = config.amqp1.idle_timeout - self.trace_protocol = config.amqp1.trace - self.ssl_ca_file = config.amqp1.ssl_ca_file - self.ssl_cert_file = config.amqp1.ssl_cert_file - self.ssl_key_file = config.amqp1.ssl_key_file - self.ssl_key_password = config.amqp1.ssl_key_password - self.ssl_allow_insecure = config.amqp1.allow_insecure_clients + self.idle_timeout = config.oslo_messaging_amqp.idle_timeout + self.trace_protocol = config.oslo_messaging_amqp.trace + self.ssl_ca_file = config.oslo_messaging_amqp.ssl_ca_file + self.ssl_cert_file = config.oslo_messaging_amqp.ssl_cert_file + self.ssl_key_file = config.oslo_messaging_amqp.ssl_key_file + self.ssl_key_password = config.oslo_messaging_amqp.ssl_key_password + self.ssl_allow_insecure = \ + config.oslo_messaging_amqp.allow_insecure_clients self.separator = "." self.fanout_qualifier = "all" self.default_exchange = default_exchange diff --git a/oslo/messaging/_drivers/protocols/amqp/driver.py b/oslo/messaging/_drivers/protocols/amqp/driver.py index b15c97298..e6b5c76c1 100644 --- a/oslo/messaging/_drivers/protocols/amqp/driver.py +++ b/oslo/messaging/_drivers/protocols/amqp/driver.py @@ -24,57 +24,16 @@ import logging import threading import time +import proton from six import moves from oslo import messaging from oslo.messaging._drivers import base from oslo.messaging._drivers import common -from oslo.messaging.openstack.common import importutils +from oslo.messaging._drivers.protocols.amqp import controller from oslo.messaging.openstack.common import jsonutils from oslo.messaging import target as messaging_target -# TODO(kgiusti): this module depends on platform specific libraries (proton) -# which are not available on all systems (yet). The unittest loader will -# attempt to directly import this driver even if the dependent libraries are -# not installed. Since the default set of unit tests do not exercise this -# driver, we shouldn't cause them to fail due to the missing -# dependencies. These hacks allow the import to succeed without raising an -# import error and causing all the tests to fail. [Note: to run the set of test -# for this driver, use the 'amqp1' test environment - e.g. 'tox -eamqp1'] -# -# Remove these hacks once the qpid-proton C libraries are available via Ubuntu -# base repos and can be added to the base test-requirements.txt [they are -# already available via EPEL]: - - -class _FakeController(object): - """A mocked Controller to use if the controller module fails to import - due to missing dependencies. Stubs out the _amqp1_opts option list and - provides a fake 'Task' superclass so the sub-classes SendTask, ListenTask, - and ReplyTask defined by this module will parse correctly on import. - - This allows the tests to import the driver.py module without failing even - if the proton libraries are not installed. Be aware that attempting to use - (instantiate) the PythonDriver will raise a NotImplementedError if the fake - controller is in use. This is by design since the driver really cannot - work without the real controller and its dependencies. - """ - fake_controller = True - Task = type('Task', (object,), {}) - _amqp1_opts = list() - - -proton = importutils.try_import("proton") -try: - from oslo.messaging._drivers.protocols.amqp import controller -except ImportError: - controller = _FakeController() - - -def get_opts(): - """Provide access to the controller's configuration options.""" - return controller._amqp1_opts -# TODO(kgiusti) End of hack LOG = logging.getLogger(__name__) diff --git a/oslo/messaging/_drivers/protocols/amqp/opts.py b/oslo/messaging/_drivers/protocols/amqp/opts.py new file mode 100644 index 000000000..22de2f4e6 --- /dev/null +++ b/oslo/messaging/_drivers/protocols/amqp/opts.py @@ -0,0 +1,62 @@ +# Copyright 2014, Red Hat, Inc. +# +# 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.config import cfg + + +amqp1_opts = [ + cfg.StrOpt('server_request_prefix', + default='exclusive', + help="address prefix used when sending to a specific server"), + + cfg.StrOpt('broadcast_prefix', + default='broadcast', + help="address prefix used when broadcasting to all servers"), + + cfg.StrOpt('group_request_prefix', + default='unicast', + help="address prefix when sending to any server in group"), + + cfg.StrOpt('container_name', + default=None, + help='Name for the AMQP container'), + + cfg.IntOpt('idle_timeout', + default=0, # disabled + help='Timeout for inactive connections (in seconds)'), + + cfg.BoolOpt('trace', + default=False, + help='Debug: dump AMQP frames to stdout'), + + cfg.StrOpt('ssl_ca_file', + default='', + help="CA certificate PEM file for verifing server certificate"), + + cfg.StrOpt('ssl_cert_file', + default='', + help='Identifying certificate PEM file to present to clients'), + + cfg.StrOpt('ssl_key_file', + default='', + help='Private key PEM file used to sign cert_file certificate'), + + cfg.StrOpt('ssl_key_password', + default=None, + help='Password for decrypting ssl_key_file (if encrypted)'), + + cfg.BoolOpt('allow_insecure_clients', + default=False, + help='Accept clients using either SSL or plain TCP') +] diff --git a/oslo/messaging/opts.py b/oslo/messaging/opts.py index 5ca0ab4aa..b101a5833 100644 --- a/oslo/messaging/opts.py +++ b/oslo/messaging/opts.py @@ -27,7 +27,7 @@ from oslo.messaging._drivers import impl_zmq from oslo.messaging._drivers import matchmaker from oslo.messaging._drivers import matchmaker_redis from oslo.messaging._drivers import matchmaker_ring -from oslo.messaging._drivers.protocols.amqp import driver as amqp1_driver +from oslo.messaging._drivers.protocols.amqp import opts as amqp_opts from oslo.messaging._executors import impl_eventlet from oslo.messaging.notify import notifier from oslo.messaging.rpc import client @@ -43,13 +43,13 @@ _global_opt_lists = [ notifier._notifier_opts, client._client_opts, transport._transport_opts, - amqp1_driver.get_opts() ] _opts = [ (None, list(itertools.chain(*_global_opt_lists))), ('matchmaker_redis', matchmaker_redis.matchmaker_redis_opts), ('matchmaker_ring', matchmaker_ring.matchmaker_opts), + ('oslo_messaging_amqp', amqp_opts.amqp1_opts), ] diff --git a/setup.cfg b/setup.cfg index 994d4ccbd..a716d98dd 100644 --- a/setup.cfg +++ b/setup.cfg @@ -31,7 +31,7 @@ oslo.messaging.drivers = rabbit = oslo.messaging._drivers.impl_rabbit:RabbitDriver qpid = oslo.messaging._drivers.impl_qpid:QpidDriver zmq = oslo.messaging._drivers.impl_zmq:ZmqDriver - amqp = oslo.messaging._drivers.protocols.amqp:ProtonDriver + amqp = oslo.messaging._drivers.protocols.amqp.driver:ProtonDriver # To avoid confusion kombu = oslo.messaging._drivers.impl_rabbit:RabbitDriver diff --git a/tests/test_amqp_driver.py b/tests/test_amqp_driver.py index 7df6eb11e..d48878526 100644 --- a/tests/test_amqp_driver.py +++ b/tests/test_amqp_driver.py @@ -24,7 +24,6 @@ from six import moves import testtools from oslo import messaging -from oslo.messaging._drivers.protocols.amqp import driver as amqp_driver from oslo.messaging.openstack.common import importutils from tests import utils as test_utils @@ -32,6 +31,9 @@ from tests import utils as test_utils # dependencies are installed. This should be removed once the proton libraries # are available in the base repos for all supported platforms. pyngus = importutils.try_import("pyngus") +if pyngus: + from oslo.messaging._drivers.protocols.amqp import driver as amqp_driver + LOG = logging.getLogger(__name__) diff --git a/tests/test_opts.py b/tests/test_opts.py index f8dec162a..920fa612d 100644 --- a/tests/test_opts.py +++ b/tests/test_opts.py @@ -29,12 +29,13 @@ class OptsTestCase(test_utils.BaseTestCase): super(OptsTestCase, self).setUp() def _test_list_opts(self, result): - self.assertEqual(3, len(result)) + self.assertEqual(4, len(result)) groups = [g for (g, l) in result] self.assertIn(None, groups) self.assertIn('matchmaker_ring', groups) self.assertIn('matchmaker_redis', groups) + self.assertIn('oslo_messaging_amqp', groups) opt_names = [o.name for (g, l) in result for o in l] self.assertIn('rpc_backend', opt_names)