summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--openstack/common/fixture/config.py45
-rw-r--r--openstack/common/rpc/securemessage.py10
-rw-r--r--tests/unit/fixture/__init__.py0
-rw-r--r--tests/unit/fixture/test_config.py45
-rw-r--r--tools/install_venv_common.py19
5 files changed, 106 insertions, 13 deletions
diff --git a/openstack/common/fixture/config.py b/openstack/common/fixture/config.py
new file mode 100644
index 0000000..cf52a66
--- /dev/null
+++ b/openstack/common/fixture/config.py
@@ -0,0 +1,45 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+#
+# Copyright 2013 Mirantis, Inc.
+# Copyright 2013 OpenStack Foundation
+# All Rights Reserved.
+#
+# 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.
+import fixtures
+from oslo.config import cfg
+
+
+class Config(fixtures.Fixture):
+ """Override some configuration values.
+
+ The keyword arguments are the names of configuration options to
+ override and their values.
+
+ If a group argument is supplied, the overrides are applied to
+ the specified configuration option group.
+
+ All overrides are automatically cleared at the end of the current
+ test by the reset() method, which is registred by addCleanup().
+ """
+
+ def __init__(self, conf=cfg.CONF):
+ self.conf = conf
+
+ def setUp(self):
+ super(Config, self).setUp()
+ self.addCleanup(self.conf.reset)
+
+ def config(self, **kw):
+ group = kw.pop('group', None)
+ for k, v in kw.iteritems():
+ self.conf.set_override(k, v, group)
diff --git a/openstack/common/rpc/securemessage.py b/openstack/common/rpc/securemessage.py
index 9dc2eca..c5530a6 100644
--- a/openstack/common/rpc/securemessage.py
+++ b/openstack/common/rpc/securemessage.py
@@ -47,10 +47,9 @@ secure_message_opts = [
cfg.StrOpt('kds_endpoint',
help='KDS endpoint (ex: http://kds.example.com:35357/v3)'),
]
-CONF = cfg.CONF
-CONF.register_group(cfg.OptGroup('secure_messages',
- title='Secure Messaging options'))
-CONF.register_opts(secure_message_opts, group='secure_messages')
+secure_message_group = cfg.OptGroup('secure_messages',
+ title='Secure Messaging options')
+
LOG = logging.getLogger(__name__)
@@ -349,6 +348,9 @@ class SecureMessage(object):
def __init__(self, topic, host, conf, key=None, key_store=None,
encrypt=None, enctype='AES', hashtype='SHA256'):
+ conf.register_group(secure_message_group)
+ conf.register_opts(secure_message_opts, group='secure_messages')
+
self._name = '%s.%s' % (topic, host)
self._key = key
self._conf = conf.secure_messages
diff --git a/tests/unit/fixture/__init__.py b/tests/unit/fixture/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/unit/fixture/__init__.py
diff --git a/tests/unit/fixture/test_config.py b/tests/unit/fixture/test_config.py
new file mode 100644
index 0000000..89582cc
--- /dev/null
+++ b/tests/unit/fixture/test_config.py
@@ -0,0 +1,45 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+#
+# Copyright 2013 Mirantis, Inc.
+# Copyright 2013 OpenStack Foundation
+# All Rights Reserved.
+#
+# 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 openstack.common.fixture import config
+from tests.utils import BaseTestCase
+
+conf = cfg.CONF
+
+
+class ConfigTestCase(BaseTestCase):
+ def setUp(self):
+ super(ConfigTestCase, self).setUp()
+ self.config = self.useFixture(config.Config(conf)).config
+ self.config_fixture = config.Config(conf)
+ conf.register_opt(cfg.StrOpt(
+ 'testing_option', default='initial_value'))
+
+ def test_overriden_value(self):
+ self.assertEquals(conf.get('testing_option'), 'initial_value')
+ self.config(testing_option='changed_value')
+ self.assertEquals(conf.get('testing_option'),
+ self.config_fixture.conf.get('testing_option'))
+
+ def test_cleanup(self):
+ self.config(testing_option='changed_value')
+ self.assertEquals(self.config_fixture.conf.get('testing_option'),
+ 'changed_value')
+ self.config_fixture.conf.reset()
+ self.assertEquals(conf.get('testing_option'), 'initial_value')
diff --git a/tools/install_venv_common.py b/tools/install_venv_common.py
index 6ce5d00..0999e2c 100644
--- a/tools/install_venv_common.py
+++ b/tools/install_venv_common.py
@@ -202,12 +202,13 @@ class Fedora(Distro):
RHEL: https://bugzilla.redhat.com/958868
"""
- # Install "patch" program if it's not there
- if not self.check_pkg('patch'):
- self.die("Please install 'patch'.")
-
- # Apply the eventlet patch
- self.apply_patch(os.path.join(self.venv, 'lib', self.py_version,
- 'site-packages',
- 'eventlet/green/subprocess.py'),
- 'contrib/redhat-eventlet.patch')
+ if os.path.exists('contrib/redhat-eventlet.patch'):
+ # Install "patch" program if it's not there
+ if not self.check_pkg('patch'):
+ self.die("Please install 'patch'.")
+
+ # Apply the eventlet patch
+ self.apply_patch(os.path.join(self.venv, 'lib', self.py_version,
+ 'site-packages',
+ 'eventlet/green/subprocess.py'),
+ 'contrib/redhat-eventlet.patch')