Ensure the amqp options are present in config file

This change ensures that the amqp1 will be present into the
configfile even the required python module are not present and
also put them into the correct section, [oslo_messaging_amqp1].

Change-Id: I1005405d7ed51090495688eadbe400dbff7c3cc9
This commit is contained in:
Mehdi Abaakouk 2014-09-05 15:24:50 +02:00
parent 37ed443727
commit d753b030c6
8 changed files with 90 additions and 122 deletions

View File

@ -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

View File

@ -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

View File

@ -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__)

View File

@ -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')
]

View File

@ -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),
]

View File

@ -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

View File

@ -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__)

View File

@ -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)