diff --git a/oslo_messaging/conffixture.py b/oslo_messaging/conffixture.py index 2f53d3f9e..42e9d51b0 100644 --- a/oslo_messaging/conffixture.py +++ b/oslo_messaging/conffixture.py @@ -18,6 +18,7 @@ __all__ = ['ConfFixture'] import sys import fixtures +from functools import wraps def _import_opts(conf, module, opts, group=None): @@ -70,6 +71,24 @@ class ConfFixture(fixtures.Fixture): '_notifier_opts', 'oslo_messaging_notifications') + # Support older test cases that still use the set_override + # with the old config key names + def decorator_for_set_override(wrapped_function): + @wraps(wrapped_function) + def _wrapper(*args, **kwargs): + group = 'oslo_messaging_notifications' + if args[0] == 'notification_driver': + args = ('driver', args[1], group) + elif args[0] == 'notification_transport_url': + args = ('transport_url', args[1], group) + elif args[0] == 'notification_topics': + args = ('topics', args[1], group) + return wrapped_function(*args, **kwargs) + return _wrapper + + self.conf.set_override = decorator_for_set_override( + self.conf.set_override) + def setUp(self): super(ConfFixture, self).setUp() self.addCleanup(self.conf.reset) diff --git a/oslo_messaging/tests/test_fixture.py b/oslo_messaging/tests/test_fixture.py new file mode 100644 index 000000000..dfa78b63d --- /dev/null +++ b/oslo_messaging/tests/test_fixture.py @@ -0,0 +1,33 @@ +# Copyright 2015 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_messaging.tests import utils as test_utils + + +class TestConfFixture(test_utils.BaseTestCase): + def test_old_notifications_config_override(self): + conf = self.messaging_conf.conf + conf.set_override( + "notification_driver", "messaging") + conf.set_override( + "notification_transport_url", "http://xyz") + conf.set_override( + "notification_topics", ['topic1']) + + self.assertEqual("messaging", + conf.oslo_messaging_notifications.driver) + self.assertEqual("http://xyz", + conf.oslo_messaging_notifications.transport_url) + self.assertEqual(['topic1'], + conf.oslo_messaging_notifications.topics)