oslo.messaging/oslo_messaging/tests/test_config_opts_proxy.py
Gevorg Davoian 282cbc222e Add query paramereters to TransportURL
This patch proposes to allow TransportURLs to have query parameters
with driver-specific options which may override corresponding
values from a static configuration. As an example, the patch
implements this possibility in the pika driver. If the idea is
approved, it will be possible to also implement it in the other
drivers.

Change-Id: Ibb7e13b4509fde035a3c334cde9bc4c498f92140
2016-06-09 16:05:36 +03:00

78 lines
3.4 KiB
Python

# Copyright 2016 Mirantis, 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
from oslo_config import types
from oslo_messaging._drivers import common as drv_cmn
from oslo_messaging.tests import utils as test_utils
from oslo_messaging import transport
class TestConfigOptsProxy(test_utils.BaseTestCase):
def test_rabbit(self):
group = 'oslo_messaging_rabbit'
self.config(rabbit_retry_interval=1,
rabbit_qos_prefetch_count=0,
rabbit_max_retries=3,
kombu_reconnect_delay=5.0,
group=group)
dummy_opts = [cfg.ListOpt('list_str', item_type=types.String(),
default=[]),
cfg.ListOpt('list_int', item_type=types.Integer(),
default=[]),
cfg.DictOpt('dict', default={}),
cfg.BoolOpt('bool', default=False),
cfg.StrOpt('str', default='default')]
self.conf.register_opts(dummy_opts, group=group)
url = transport.TransportURL.parse(
self.conf, "rabbit:///"
"?rabbit_qos_prefetch_count=2"
"&unknown_opt=4"
"&kombu_reconnect_delay=invalid_value"
"&list_str=1&list_str=2&list_str=3"
"&list_int=1&list_int=2&list_int=3"
"&dict=x:1&dict=y:2&dict=z:3"
"&bool=True"
)
conf = drv_cmn.ConfigOptsProxy(self.conf, url)
self.assertRaises(cfg.NoSuchOptError,
conf.__getattr__,
'unknown_group')
self.assertTrue(isinstance(getattr(conf, group),
conf.GroupAttrProxy))
self.assertEqual(conf.oslo_messaging_rabbit.rabbit_retry_interval,
1)
self.assertEqual(conf.oslo_messaging_rabbit.rabbit_qos_prefetch_count,
2)
self.assertEqual(conf.oslo_messaging_rabbit.rabbit_max_retries,
3)
self.assertRaises(cfg.NoSuchOptError,
conf.oslo_messaging_rabbit.__getattr__,
'unknown_opt')
self.assertRaises(ValueError,
conf.oslo_messaging_rabbit.__getattr__,
'kombu_reconnect_delay')
self.assertEqual(conf.oslo_messaging_rabbit.list_str,
['1', '2', '3'])
self.assertEqual(conf.oslo_messaging_rabbit.list_int,
[1, 2, 3])
self.assertEqual(conf.oslo_messaging_rabbit.dict,
{'x': '1', 'y': '2', 'z': '3'})
self.assertEqual(conf.oslo_messaging_rabbit.bool,
True)
self.assertEqual(conf.oslo_messaging_rabbit.str,
'default')