Remove oslo namespace package

Blueprint remove-namespace-packages

Depends-on: I77e50f2f14345321d1b5319343c5872a92977936
for openstack/murano-agent
Depends-on: If51059c31c82d5235e2ae21143911b5561783ca6
for openstack/os-collect-config
Depends-on: I324ca86a21c27ce43cebf255b3c075b8fe110820
for openstack/sahara-dashboard
Depends-on: Icfc882db41883410f7b40fc5a22bfaae1a65dedc
for openstack/tempest
Depends-on: I396a64aa7610b5fcc0bab05bff442ae6b43c6164
for openstack/congress
Depends-on: I749f43bd6dc15717154475cc1a776ffd6164b7fa
for openstack/octavia
Depends-on: I892c0b64ff6bab666f1f23f5e7aeb2da088ea087
for stackforge/python-solumclient
Depends-on: I09b3bec4c68c7fe9379b3d5fefbceaa86ffe994e
for openstack/congress

Related fixes for projects that can't build for other reasons:
I7d35c85926c8f098e2e47051ff44b714478df1b7 for stackforge/magnetodb

needed for the gate:
Depends-On: I0f07858e96ea3baf46f8a453e253b9ed29c7f7e2
Depends-On: I33bd2d9dff9cb7dc1a50177db7286b7317966784

Change-Id: Ibe16f8d7f73234845cab94c8e351f41954eecb0a
This commit is contained in:
Doug Hellmann 2015-04-27 20:27:21 +00:00
parent cbf6b30a7b
commit 59fd48b3f0
26 changed files with 18 additions and 5268 deletions

View File

@ -1,15 +0,0 @@
# Copyright 2012 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.
__import__('pkg_resources').declare_namespace(__name__)

View File

@ -1,28 +0,0 @@
# 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 warnings
from oslo_config import * # noqa
def deprecated():
new_name = __name__.replace('.', '_')
warnings.warn(
('The oslo namespace package is deprecated. Please use %s instead.' %
new_name),
DeprecationWarning,
stacklevel=3,
)
deprecated()

View File

@ -1,13 +0,0 @@
# 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.cfg import * # noqa

View File

@ -1,13 +0,0 @@
# 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.cfgfilter import * # noqa

View File

@ -1,13 +0,0 @@
# 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.fixture import * # noqa

View File

@ -1,13 +0,0 @@
# 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.generator import * # noqa

View File

@ -1,13 +0,0 @@
# 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.iniparser import * # noqa

View File

@ -1,13 +0,0 @@
# 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.types import * # noqa

View File

@ -2599,43 +2599,45 @@ class ImportOptTestCase(BaseTestCase):
def test_import_opt(self):
self.assertFalse(hasattr(cfg.CONF, 'blaa'))
cfg.CONF.import_opt('blaa', 'tests.testmods.blaa_opt')
cfg.CONF.import_opt('blaa', 'oslo_config.tests.testmods.blaa_opt')
self.assertTrue(hasattr(cfg.CONF, 'blaa'))
def test_import_opt_in_group(self):
self.assertFalse(hasattr(cfg.CONF, 'bar'))
cfg.CONF.import_opt('foo', 'tests.testmods.bar_foo_opt', group='bar')
cfg.CONF.import_opt('foo', 'oslo_config.tests.testmods.bar_foo_opt',
group='bar')
self.assertTrue(hasattr(cfg.CONF, 'bar'))
self.assertTrue(hasattr(cfg.CONF.bar, 'foo'))
def test_import_opt_import_errror(self):
self.assertRaises(ImportError, cfg.CONF.import_opt,
'blaa', 'tests.testmods.blaablaa_opt')
'blaa', 'oslo_config.tests.testmods.blaablaa_opt')
def test_import_opt_no_such_opt(self):
self.assertRaises(cfg.NoSuchOptError, cfg.CONF.import_opt,
'blaablaa', 'tests.testmods.blaa_opt')
'blaablaa', 'oslo_config.tests.testmods.blaa_opt')
def test_import_opt_no_such_group(self):
self.assertRaises(cfg.NoSuchGroupError, cfg.CONF.import_opt,
'blaa', 'tests.testmods.blaa_opt', group='blaa')
'blaa', 'oslo_config.tests.testmods.blaa_opt',
group='blaa')
class ImportGroupTestCase(BaseTestCase):
def test_import_group(self):
self.assertFalse(hasattr(cfg.CONF, 'qux'))
cfg.CONF.import_group('qux', 'tests.testmods.baz_qux_opt')
cfg.CONF.import_group('qux', 'oslo_config.tests.testmods.baz_qux_opt')
self.assertTrue(hasattr(cfg.CONF, 'qux'))
self.assertTrue(hasattr(cfg.CONF.qux, 'baz'))
def test_import_group_import_error(self):
self.assertRaises(ImportError, cfg.CONF.import_group,
'qux', 'tests.testmods.bazzz_quxxx_opt')
'qux', 'oslo_config.tests.testmods.bazzz_quxxx_opt')
def test_import_group_no_such_group(self):
self.assertRaises(cfg.NoSuchGroupError, cfg.CONF.import_group,
'quxxx', 'tests.testmods.baz_qux_opt')
'quxxx', 'oslo_config.tests.testmods.baz_qux_opt')
class RequiredOptsTestCase(BaseTestCase):

View File

@ -281,31 +281,33 @@ class ImportTestCase(BaseTestCase):
def test_import_opt(self):
self.assertFalse(hasattr(self.conf, 'fblaa'))
self.conf.import_opt('fblaa', 'tests.testmods.fblaa_opt')
self.conf.import_opt('fblaa', 'oslo_config.tests.testmods.fblaa_opt')
self.assertTrue(hasattr(self.conf, 'fblaa'))
self.assertFalse(hasattr(self.fconf, 'fblaa'))
self.fconf.import_opt('fblaa', 'tests.testmods.fblaa_opt')
self.fconf.import_opt('fblaa', 'oslo_config.tests.testmods.fblaa_opt')
self.assertTrue(hasattr(self.fconf, 'fblaa'))
def test_import_opt_in_group(self):
self.assertFalse(hasattr(self.conf, 'fbar'))
self.conf.import_opt('foo', 'tests.testmods.fbar_foo_opt',
self.conf.import_opt('foo', 'oslo_config.tests.testmods.fbar_foo_opt',
group='fbar')
self.assertTrue(hasattr(self.conf, 'fbar'))
self.assertTrue(hasattr(self.conf.fbar, 'foo'))
self.assertFalse(hasattr(self.fconf, 'fbar'))
self.fconf.import_opt('foo', 'tests.testmods.fbar_foo_opt',
self.fconf.import_opt('foo', 'oslo_config.tests.testmods.fbar_foo_opt',
group='fbar')
self.assertTrue(hasattr(self.fconf, 'fbar'))
self.assertTrue(hasattr(self.fconf.fbar, 'foo'))
def test_import_group(self):
self.assertFalse(hasattr(self.conf, 'fbaar'))
self.conf.import_group('fbaar', 'tests.testmods.fbaar_baa_opt')
self.conf.import_group('fbaar',
'oslo_config.tests.testmods.fbaar_baa_opt')
self.assertTrue(hasattr(self.conf, 'fbaar'))
self.assertTrue(hasattr(self.conf.fbaar, 'baa'))
self.assertFalse(hasattr(self.fconf, 'fbaar'))
self.fconf.import_group('fbaar', 'tests.testmods.fbaar_baa_opt')
self.fconf.import_group('fbaar',
'oslo_config.tests.testmods.fbaar_baa_opt')
self.assertTrue(hasattr(self.fconf, 'fbaar'))
self.assertTrue(hasattr(self.fconf.fbaar, 'baa'))

View File

@ -22,11 +22,7 @@ classifier =
[files]
packages =
oslo
oslo.config
oslo_config
namespace_packages =
oslo
[global]
setup-hooks =

File diff suppressed because it is too large Load Diff

View File

@ -1,249 +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 oslotest import base as test_base
from oslo.config import cfg
from oslo.config import cfgfilter
class BaseTestCase(test_base.BaseTestCase):
def setUp(self, conf=None):
super(BaseTestCase, self).setUp()
if conf is None:
self.conf = cfg.ConfigOpts()
else:
self.conf = conf
self.fconf = cfgfilter.ConfigFilter(self.conf)
class RegisterTestCase(BaseTestCase):
def test_register_opt_default(self):
self.fconf.register_opt(cfg.StrOpt('foo', default='bar'))
self.assertEqual('bar', self.fconf.foo)
self.assertEqual('bar', self.fconf['foo'])
self.assertIn('foo', self.fconf)
self.assertEqual(['foo'], list(self.fconf))
self.assertEqual(1, len(self.fconf))
self.assertNotIn('foo', self.conf)
self.assertEqual(0, len(self.conf))
self.assertRaises(cfg.NoSuchOptError, getattr, self.conf, 'foo')
def test_register_opt_none_default(self):
self.fconf.register_opt(cfg.StrOpt('foo'))
self.assertIsNone(self.fconf.foo)
self.assertIsNone(self.fconf['foo'])
self.assertIn('foo', self.fconf)
self.assertEqual(['foo'], list(self.fconf))
self.assertEqual(1, len(self.fconf))
self.assertNotIn('foo', self.conf)
self.assertEqual(0, len(self.conf))
self.assertRaises(cfg.NoSuchOptError, getattr, self.conf, 'foo')
def test_register_grouped_opt_default(self):
self.fconf.register_opt(cfg.StrOpt('foo', default='bar'),
group='blaa')
self.assertEqual('bar', self.fconf.blaa.foo)
self.assertEqual('bar', self.fconf['blaa']['foo'])
self.assertIn('blaa', self.fconf)
self.assertIn('foo', self.fconf.blaa)
self.assertEqual(['blaa'], list(self.fconf))
self.assertEqual(['foo'], list(self.fconf.blaa))
self.assertEqual(1, len(self.fconf))
self.assertEqual(1, len(self.fconf.blaa))
self.assertNotIn('blaa', self.conf)
self.assertEqual(0, len(self.conf))
self.assertRaises(cfg.NoSuchOptError, getattr, self.conf, 'blaa')
def test_register_grouped_opt_none_default(self):
self.fconf.register_opt(cfg.StrOpt('foo'), group='blaa')
self.assertIsNone(self.fconf.blaa.foo)
self.assertIsNone(self.fconf['blaa']['foo'])
self.assertIn('blaa', self.fconf)
self.assertIn('foo', self.fconf.blaa)
self.assertEqual(['blaa'], list(self.fconf))
self.assertEqual(['foo'], list(self.fconf.blaa))
self.assertEqual(1, len(self.fconf))
self.assertEqual(1, len(self.fconf.blaa))
self.assertNotIn('blaa', self.conf)
self.assertEqual(0, len(self.conf))
self.assertRaises(cfg.NoSuchOptError, getattr, self.conf, 'blaa')
def test_register_group(self):
group = cfg.OptGroup('blaa')
self.fconf.register_group(group)
self.fconf.register_opt(cfg.StrOpt('foo'), group=group)
self.assertIsNone(self.fconf.blaa.foo)
self.assertIsNone(self.fconf['blaa']['foo'])
self.assertIn('blaa', self.fconf)
self.assertIn('foo', self.fconf.blaa)
self.assertEqual(['blaa'], list(self.fconf))
self.assertEqual(['foo'], list(self.fconf.blaa))
self.assertEqual(1, len(self.fconf))
self.assertEqual(1, len(self.fconf.blaa))
self.assertNotIn('blaa', self.conf)
self.assertEqual(0, len(self.conf))
self.assertRaises(cfg.NoSuchOptError, getattr, self.conf, 'blaa')
def test_register_opts(self):
self.fconf.register_opts([cfg.StrOpt('foo'),
cfg.StrOpt('bar')])
self.assertIn('foo', self.fconf)
self.assertIn('bar', self.fconf)
self.assertNotIn('foo', self.conf)
self.assertNotIn('bar', self.conf)
def test_register_known_cli_opt(self):
self.conf.register_opt(cfg.StrOpt('foo'))
self.fconf.register_cli_opt(cfg.StrOpt('foo'))
self.assertIn('foo', self.fconf)
self.assertIn('foo', self.conf)
def test_register_known_cli_opts(self):
self.conf.register_cli_opts([cfg.StrOpt('foo'), cfg.StrOpt('bar')])
self.fconf.register_cli_opts([cfg.StrOpt('foo'), cfg.StrOpt('bar')])
self.assertIn('foo', self.fconf)
self.assertIn('bar', self.fconf)
self.assertIn('foo', self.conf)
self.assertIn('bar', self.conf)
def test_register_opts_grouped(self):
self.fconf.register_opts([cfg.StrOpt('foo'), cfg.StrOpt('bar')],
group='blaa')
self.assertIn('foo', self.fconf.blaa)
self.assertIn('bar', self.fconf.blaa)
self.assertNotIn('blaa', self.conf)
def test_register_known_cli_opt_grouped(self):
self.conf.register_cli_opt(cfg.StrOpt('foo'), group='blaa')
self.fconf.register_cli_opt(cfg.StrOpt('foo'), group='blaa')
self.assertIn('foo', self.fconf.blaa)
self.assertIn('blaa', self.fconf)
self.assertIn('blaa', self.conf)
def test_register_known_cli_opts_grouped(self):
self.conf.register_cli_opts([cfg.StrOpt('foo'), cfg.StrOpt('bar')],
group='blaa')
self.fconf.register_cli_opts([cfg.StrOpt('foo'), cfg.StrOpt('bar')],
group='blaa')
self.assertIn('foo', self.fconf.blaa)
self.assertIn('bar', self.fconf.blaa)
self.assertIn('blaa', self.fconf)
self.assertIn('blaa', self.conf)
def test_unknown_opt(self):
self.assertNotIn('foo', self.fconf)
self.assertEqual(0, len(self.fconf))
self.assertRaises(cfg.NoSuchOptError, getattr, self.fconf, 'foo')
self.assertNotIn('blaa', self.conf)
def test_blocked_opt(self):
self.conf.register_opt(cfg.StrOpt('foo'))
self.assertIn('foo', self.conf)
self.assertEqual(1, len(self.conf))
self.assertIsNone(self.conf.foo)
self.assertNotIn('foo', self.fconf)
self.assertEqual(0, len(self.fconf))
self.assertRaises(cfg.NoSuchOptError, getattr, self.fconf, 'foo')
def test_already_registered_opt(self):
self.conf.register_opt(cfg.StrOpt('foo'))
self.fconf.register_opt(cfg.StrOpt('foo'))
self.assertIn('foo', self.conf)
self.assertEqual(1, len(self.conf))
self.assertIsNone(self.conf.foo)
self.assertIn('foo', self.fconf)
self.assertEqual(1, len(self.fconf))
self.assertIsNone(self.fconf.foo)
self.conf.set_override('foo', 'bar')
self.assertEqual('bar', self.conf.foo)
self.assertEqual('bar', self.fconf.foo)
def test_already_registered_opts(self):
self.conf.register_opts([cfg.StrOpt('foo'),
cfg.StrOpt('fu')])
self.fconf.register_opts([cfg.StrOpt('foo'),
cfg.StrOpt('bu')])
self.assertIn('foo', self.conf)
self.assertIn('fu', self.conf)
self.assertNotIn('bu', self.conf)
self.assertEqual(2, len(self.conf))
self.assertIsNone(self.conf.foo)
self.assertIsNone(self.conf.fu)
self.assertIn('foo', self.fconf)
self.assertIn('bu', self.fconf)
self.assertNotIn('fu', self.fconf)
self.assertEqual(2, len(self.fconf))
self.assertIsNone(self.fconf.foo)
self.assertIsNone(self.fconf.bu)
self.conf.set_override('foo', 'bar')
self.assertEqual('bar', self.conf.foo)
self.assertEqual('bar', self.fconf.foo)
def test_already_registered_cli_opt(self):
self.conf.register_cli_opt(cfg.StrOpt('foo'))
self.fconf.register_cli_opt(cfg.StrOpt('foo'))
self.assertIn('foo', self.conf)
self.assertEqual(1, len(self.conf))
self.assertIsNone(self.conf.foo)
self.assertIn('foo', self.fconf)
self.assertEqual(1, len(self.fconf))
self.assertIsNone(self.fconf.foo)
self.conf.set_override('foo', 'bar')
self.assertEqual('bar', self.conf.foo)
self.assertEqual('bar', self.fconf.foo)
def test_already_registered_cli_opts(self):
self.conf.register_cli_opts([cfg.StrOpt('foo'),
cfg.StrOpt('fu')])
self.fconf.register_cli_opts([cfg.StrOpt('foo'),
cfg.StrOpt('fu')])
self.assertIn('foo', self.conf)
self.assertIn('fu', self.conf)
self.assertEqual(2, len(self.conf))
self.assertIsNone(self.conf.foo)
self.assertIsNone(self.conf.fu)
self.assertIn('foo', self.fconf)
self.assertIn('fu', self.fconf)
self.assertEqual(2, len(self.fconf))
self.assertIsNone(self.fconf.foo)
self.assertIsNone(self.fconf.fu)
self.conf.set_override('foo', 'bar')
self.assertEqual('bar', self.conf.foo)
self.assertEqual('bar', self.fconf.foo)

View File

@ -1,154 +0,0 @@
#
# 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 oslotest import base
from oslo.config import cfg
from oslo.config import fixture as config
class ConfigTestCase(base.BaseTestCase):
def _make_fixture(self):
conf = cfg.ConfigOpts()
config_fixture = config.Config(conf)
config_fixture.setUp()
config_fixture.register_opt(cfg.StrOpt(
'testing_option', default='initial_value'))
return (config_fixture, conf)
def test_overridden_value(self):
f, conf = self._make_fixture()
self.assertEqual(conf.get('testing_option'), 'initial_value')
f.config(testing_option='changed_value')
self.assertEqual(conf.get('testing_option'),
f.conf.get('testing_option'))
def test_cleanup(self):
f, conf = self._make_fixture()
f.config(testing_option='changed_value')
self.assertEqual(f.conf.get('testing_option'),
'changed_value')
f.conf.reset()
self.assertEqual(conf.get('testing_option'), 'initial_value')
def test_register_option(self):
f, conf = self._make_fixture()
opt = cfg.StrOpt('new_test_opt', default='initial_value')
f.register_opt(opt)
self.assertEqual(conf.get('new_test_opt'),
opt.default)
def test_register_options(self):
f, conf = self._make_fixture()
opt1 = cfg.StrOpt('first_test_opt', default='initial_value_1')
opt2 = cfg.StrOpt('second_test_opt', default='initial_value_2')
f.register_opts([opt1, opt2])
self.assertEqual(conf.get('first_test_opt'), opt1.default)
self.assertEqual(conf.get('second_test_opt'), opt2.default)
def test_cleanup_unregister_option(self):
f, conf = self._make_fixture()
opt = cfg.StrOpt('new_test_opt', default='initial_value')
f.register_opt(opt)
self.assertEqual(conf.get('new_test_opt'),
opt.default)
f.cleanUp()
self.assertRaises(cfg.NoSuchOptError, conf.get, 'new_test_opt')
def test_register_cli_option(self):
f, conf = self._make_fixture()
opt = cfg.StrOpt('new_test_opt', default='initial_value')
f.register_cli_opt(opt)
self.assertEqual(conf.get('new_test_opt'),
opt.default)
def test_register_cli_options(self):
f, conf = self._make_fixture()
opt1 = cfg.StrOpt('first_test_opt', default='initial_value_1')
opt2 = cfg.StrOpt('second_test_opt', default='initial_value_2')
f.register_cli_opts([opt1, opt2])
self.assertEqual(conf.get('first_test_opt'), opt1.default)
self.assertEqual(conf.get('second_test_opt'), opt2.default)
def test_cleanup_unregister_cli_option(self):
f, conf = self._make_fixture()
opt = cfg.StrOpt('new_test_opt', default='initial_value')
f.register_cli_opt(opt)
self.assertEqual(conf.get('new_test_opt'),
opt.default)
f.cleanUp()
self.assertRaises(cfg.NoSuchOptError, conf.get, 'new_test_opt')
def test_load_raw_values(self):
f, conf = self._make_fixture()
f.load_raw_values(first_test_opt='loaded_value_1',
second_test_opt='loaded_value_2')
# Must not be registered.
self.assertRaises(cfg.NoSuchOptError, conf.get, 'first_test_opt')
self.assertRaises(cfg.NoSuchOptError, conf.get, 'second_test_opt')
opt1 = cfg.StrOpt('first_test_opt', default='initial_value_1')
opt2 = cfg.StrOpt('second_test_opt', default='initial_value_2')
f.register_opt(opt1)
f.register_opt(opt2)
self.assertEqual(conf.first_test_opt, 'loaded_value_1')
self.assertEqual(conf.second_test_opt, 'loaded_value_2')
# Cleanup.
f.cleanUp()
# Must no longer be registered.
self.assertRaises(cfg.NoSuchOptError, conf.get, 'first_test_opt')
self.assertRaises(cfg.NoSuchOptError, conf.get, 'second_test_opt')
# Even when registered, must be default.
f.register_opt(opt1)
f.register_opt(opt2)
self.assertEqual(conf.first_test_opt, 'initial_value_1')
self.assertEqual(conf.second_test_opt, 'initial_value_2')
def test_assert_default_files_cleanup(self):
"""Assert that using the fixture forces a clean list."""
f, conf = self._make_fixture()
self.assertNotIn('default_config_files', conf)
config_files = ['./test_fixture.conf']
f.set_config_files(config_files)
self.assertEqual(conf.default_config_files, config_files)
f.cleanUp()
self.assertNotIn('default_config_files', conf)
def test_load_custom_files(self):
f, conf = self._make_fixture()
self.assertNotIn('default_config_files', conf)
config_files = ['./oslo_config/tests/test_fixture.conf']
f.set_config_files(config_files)
opt1 = cfg.StrOpt('first_test_opt', default='initial_value_1')
opt2 = cfg.StrOpt('second_test_opt', default='initial_value_2')
f.register_opt(opt1)
f.register_opt(opt2)
self.assertEqual('loaded_value_1', conf.get('first_test_opt'))
self.assertEqual('loaded_value_2', conf.get('second_test_opt'))

View File

@ -1,592 +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.
import sys
import fixtures
import mock
from oslotest import base
from six import moves
import testscenarios
from oslo.config import cfg
from oslo.config import fixture as config_fixture
from oslo.config import generator
from oslo_i18n import fixture as i18n_fixture
load_tests = testscenarios.load_tests_apply_scenarios
class GeneratorTestCase(base.BaseTestCase):
opts = {
'foo': cfg.StrOpt('foo', help='foo option'),
'foo_i18n_help': cfg.StrOpt('foo_i18n_help',
help=i18n_fixture.Translation().lazy(
'this is a lazy message')),
'bar': cfg.StrOpt('bar', help='bar option'),
'foo-bar': cfg.StrOpt('foo-bar', help='foobar'),
'no_help': cfg.StrOpt('no_help'),
'long_help': cfg.StrOpt('long_help',
help='Lorem ipsum dolor sit amet, consectetur '
'adipisicing elit, sed do eiusmod tempor '
'incididunt ut labore et dolore magna '
'aliqua. Ut enim ad minim veniam, quis '
'nostrud exercitation ullamco laboris '
'nisi ut aliquip ex ea commodo '
'consequat. Duis aute irure dolor in '
'reprehenderit in voluptate velit esse '
'cillum dolore eu fugiat nulla '
'pariatur. Excepteur sint occaecat '
'cupidatat non proident, sunt in culpa '
'qui officia deserunt mollit anim id est '
'laborum.'),
'choices_opt': cfg.StrOpt('choices_opt',
default='a',
choices=(None, '', 'a', 'b', 'c'),
help='a string with choices'),
'deprecated_opt': cfg.StrOpt('bar',
deprecated_name='foobar',
help='deprecated'),
'deprecated_group': cfg.StrOpt('bar',
deprecated_group='group1',
deprecated_name='foobar',
help='deprecated'),
# Unknown Opt default must be a string
'unknown_type': cfg.Opt('unknown_opt',
default='123',
help='unknown'),
'str_opt': cfg.StrOpt('str_opt',
default='foo bar',
help='a string'),
'str_opt_sample_default': cfg.StrOpt('str_opt',
default='fooishbar',
help='a string'),
'str_opt_with_space': cfg.StrOpt('str_opt',
default=' foo bar ',
help='a string with spaces'),
'bool_opt': cfg.BoolOpt('bool_opt',
default=False,
help='a boolean'),
'int_opt': cfg.IntOpt('int_opt',
default=10,
min=1,
max=20,
help='an integer'),
'float_opt': cfg.FloatOpt('float_opt',
default=0.1,
help='a float'),
'list_opt': cfg.ListOpt('list_opt',
default=['1', '2', '3'],
help='a list'),
'dict_opt': cfg.DictOpt('dict_opt',
default={'1': 'yes', '2': 'no'},
help='a dict'),
'multi_opt': cfg.MultiStrOpt('multi_opt',
default=['1', '2', '3'],
help='multiple strings'),
'multi_opt_none': cfg.MultiStrOpt('multi_opt_none',
help='multiple strings'),
'multi_opt_empty': cfg.MultiStrOpt('multi_opt_empty',
default=[],
help='multiple strings'),
'multi_opt_sample_default': cfg.MultiStrOpt('multi_opt',
default=['1', '2', '3'],
sample_default=['5', '6'],
help='multiple strings'),
'group_opt': cfg.OptGroup('group_opt', title='a group'),
}
content_scenarios = [
('empty',
dict(opts=[], expected='''[DEFAULT]
''')),
('single_namespace',
dict(opts=[('test', [(None, [opts['foo']])])],
expected='''[DEFAULT]
#
# From test
#
# foo option (string value)
#foo = <None>
''')),
('multiple_namespaces',
dict(opts=[('test', [(None, [opts['foo']])]),
('other', [(None, [opts['bar']])])],
expected='''[DEFAULT]
#
# From other
#
# bar option (string value)
#bar = <None>
#
# From test
#
# foo option (string value)
#foo = <None>
''')),
('group',
dict(opts=[('test', [('group1', [opts['foo']])])],
expected='''[DEFAULT]
[group1]
#
# From test
#
# foo option (string value)
#foo = <None>
''')),
('group_opt',
dict(opts=[('test', [(opts['group_opt'], [opts['foo']])])],
expected='''[DEFAULT]
[group_opt]
#
# From test
#
# foo option (string value)
#foo = <None>
''')),
('empty_group',
dict(opts=[('test', [('group1', [])])],
expected='''[DEFAULT]
''')),
('multiple_groups',
dict(opts=[('test', [('group1', [opts['foo']]),
('group2', [opts['bar']])])],
expected='''[DEFAULT]
[group1]
#
# From test
#
# foo option (string value)
#foo = <None>
[group2]
#
# From test
#
# bar option (string value)
#bar = <None>
''')),
('group_in_multiple_namespaces',
dict(opts=[('test', [('group1', [opts['foo']])]),
('other', [('group1', [opts['bar']])])],
expected='''[DEFAULT]
[group1]
#
# From other
#
# bar option (string value)
#bar = <None>
#
# From test
#
# foo option (string value)
#foo = <None>
''')),
('hyphenated_name',
dict(opts=[('test', [(None, [opts['foo-bar']])])],
expected='''[DEFAULT]
#
# From test
#
# foobar (string value)
#foo_bar = <None>
''')),
('i18n_help',
dict(opts=[('test', [(None, [opts['foo_i18n_help']])])],
expected='''[DEFAULT]
#
# From test
#
# this is a lazy message (string value)
#foo_i18n_help = <None>
''')),
('no_help',
dict(opts=[('test', [(None, [opts['no_help']])])],
log_warning=('"%s" is missing a help string', 'no_help'),
expected='''[DEFAULT]
#
# From test
#
# (string value)
#no_help = <None>
''')),
('long_help',
dict(opts=[('test', [(None, [opts['long_help']])])],
expected='''[DEFAULT]
#
# From test
#
# Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
# eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim
# ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
# aliquip ex ea commodo consequat. Duis aute irure dolor in
# reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
# pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
# culpa qui officia deserunt mollit anim id est laborum. (string
# value)
#long_help = <None>
''')),
('long_help_wrap_at_40',
dict(opts=[('test', [(None, [opts['long_help']])])],
wrap_width=40,
expected='''[DEFAULT]
#
# From test
#
# Lorem ipsum dolor sit amet,
# consectetur adipisicing elit, sed do
# eiusmod tempor incididunt ut labore et
# dolore magna aliqua. Ut enim ad minim
# veniam, quis nostrud exercitation
# ullamco laboris nisi ut aliquip ex ea
# commodo consequat. Duis aute irure
# dolor in reprehenderit in voluptate
# velit esse cillum dolore eu fugiat
# nulla pariatur. Excepteur sint
# occaecat cupidatat non proident, sunt
# in culpa qui officia deserunt mollit
# anim id est laborum. (string value)
#long_help = <None>
''')),
('long_help_no_wrapping',
dict(opts=[('test', [(None, [opts['long_help']])])],
wrap_width=0,
expected='''[DEFAULT]
#
# From test
#
''' # noqa
'# Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod '
'tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, '
'quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo '
'consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse '
'cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat '
'non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. '
'(string value)'
'''
#long_help = <None>
''')),
('choices_opt',
dict(opts=[('test', [(None, [opts['choices_opt']])])],
expected='''[DEFAULT]
#
# From test
#
# a string with choices (string value)
# Allowed values: <None>, '', a, b, c
#choices_opt = a
''')),
('deprecated',
dict(opts=[('test', [('foo', [opts['deprecated_opt']])])],
expected='''[DEFAULT]
[foo]
#
# From test
#
# deprecated (string value)
# Deprecated group/name - [DEFAULT]/foobar
#bar = <None>
''')),
('deprecated_group',
dict(opts=[('test', [('foo', [opts['deprecated_group']])])],
expected='''[DEFAULT]
[foo]
#
# From test
#
# deprecated (string value)
# Deprecated group/name - [group1]/foobar
#bar = <None>
''')),
('unknown_type',
dict(opts=[('test', [(None, [opts['unknown_type']])])],
log_warning=('Unknown option type: %s',
repr(opts['unknown_type'])),
expected='''[DEFAULT]
#
# From test
#
# unknown (unknown type)
#unknown_opt = 123
''')),
('str_opt',
dict(opts=[('test', [(None, [opts['str_opt']])])],
expected='''[DEFAULT]
#
# From test
#
# a string (string value)
#str_opt = foo bar
''')),
('str_opt_with_space',
dict(opts=[('test', [(None, [opts['str_opt_with_space']])])],
expected='''[DEFAULT]
#
# From test
#
# a string with spaces (string value)
#str_opt = " foo bar "
''')),
('bool_opt',
dict(opts=[('test', [(None, [opts['bool_opt']])])],
expected='''[DEFAULT]
#
# From test
#
# a boolean (boolean value)
#bool_opt = false
''')),
('int_opt',
dict(opts=[('test', [(None, [opts['int_opt']])])],
expected='''[DEFAULT]
#
# From test
#
# an integer (integer value)
# Minimum value: 1
# Maximum value: 20
#int_opt = 10
''')),
('float_opt',
dict(opts=[('test', [(None, [opts['float_opt']])])],
expected='''[DEFAULT]
#
# From test
#
# a float (floating point value)
#float_opt = 0.1
''')),
('list_opt',
dict(opts=[('test', [(None, [opts['list_opt']])])],
expected='''[DEFAULT]
#
# From test
#
# a list (list value)
#list_opt = 1,2,3
''')),
('dict_opt',
dict(opts=[('test', [(None, [opts['dict_opt']])])],
expected='''[DEFAULT]
#
# From test
#
# a dict (dict value)
#dict_opt = 1:yes,2:no
''')),
('multi_opt',
dict(opts=[('test', [(None, [opts['multi_opt']])])],
expected='''[DEFAULT]
#
# From test
#
# multiple strings (multi valued)
#multi_opt = 1
#multi_opt = 2
#multi_opt = 3
''')),
('multi_opt_none',
dict(opts=[('test', [(None, [opts['multi_opt_none']])])],
expected='''[DEFAULT]
#
# From test
#
# multiple strings (multi valued)
#multi_opt_none =
''')),
('multi_opt_empty',
dict(opts=[('test', [(None, [opts['multi_opt_empty']])])],
expected='''[DEFAULT]
#
# From test
#
# multiple strings (multi valued)
#multi_opt_empty =
''')),
('str_opt_sample_default',
dict(opts=[('test', [(None, [opts['str_opt_sample_default']])])],
expected='''[DEFAULT]
#
# From test
#
# a string (string value)
#str_opt = fooishbar
''')),
('multi_opt_sample_default',
dict(opts=[('test', [(None, [opts['multi_opt_sample_default']])])],
expected='''[DEFAULT]
#
# From test
#
# multiple strings (multi valued)
#multi_opt = 5
#multi_opt = 6
''')),
]
output_file_scenarios = [
('stdout',
dict(stdout=True, output_file=None)),
('output_file',
dict(output_file='sample.conf', stdout=False)),
]
@classmethod
def generate_scenarios(cls):
cls.scenarios = testscenarios.multiply_scenarios(
cls.content_scenarios,
cls.output_file_scenarios)
def setUp(self):
super(GeneratorTestCase, self).setUp()
self.conf = cfg.ConfigOpts()
self.config_fixture = config_fixture.Config(self.conf)
self.config = self.config_fixture.config
self.useFixture(self.config_fixture)
self.tempdir = self.useFixture(fixtures.TempDir())
def _capture_stream(self, stream_name):
self.useFixture(fixtures.MonkeyPatch("sys.%s" % stream_name,
moves.StringIO()))
return getattr(sys, stream_name)
def _capture_stdout(self):
return self._capture_stream('stdout')
@mock.patch('stevedore.named.NamedExtensionManager')
@mock.patch('oslo_config.generator.LOG')
def test_generate(self, mock_log, named_mgr):
generator.register_cli_opts(self.conf)
namespaces = [i[0] for i in self.opts]
self.config(namespace=namespaces)
wrap_width = getattr(self, 'wrap_width', None)
if wrap_width is not None:
self.config(wrap_width=wrap_width)
if self.stdout:
stdout = self._capture_stdout()
else:
output_file = self.tempdir.join(self.output_file)
self.config(output_file=output_file)
mock_eps = []
for name, opts in self.opts:
mock_ep = mock.Mock()
mock_ep.configure_mock(name=name, obj=opts)
mock_eps.append(mock_ep)
named_mgr.return_value = mock_eps
generator.generate(self.conf)
if self.stdout:
self.assertEqual(self.expected, stdout.getvalue())
else:
content = open(output_file).read()
self.assertEqual(self.expected, content)
named_mgr.assert_called_once_with(
'oslo.config.opts',
names=namespaces,
on_load_failure_callback=generator.on_load_failure_callback,
invoke_on_load=True)
log_warning = getattr(self, 'log_warning', None)
if log_warning is not None:
mock_log.warning.assert_called_once_with(*log_warning)
else:
self.assertFalse(mock_log.warning.called)
GeneratorTestCase.generate_scenarios()

View File

@ -1,124 +0,0 @@
# Copyright 2012 OpenStack Foundation
#
# 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 unittest
from oslo.config import iniparser
class TestParser(iniparser.BaseParser):
comment_called = False
values = None
section = ''
def __init__(self):
self.values = {}
def assignment(self, key, value):
self.values.setdefault(self.section, {})
self.values[self.section][key] = value
def new_section(self, section):
self.section = section
def comment(self, section):
self.comment_called = True
class BaseParserTestCase(unittest.TestCase):
def setUp(self):
self.parser = iniparser.BaseParser()
def _assertParseError(self, *lines):
self.assertRaises(iniparser.ParseError, self.parser.parse, lines)
def test_invalid_assignment(self):
self._assertParseError("foo - bar")
def test_empty_key(self):
self._assertParseError(": bar")
def test_unexpected_continuation(self):
self._assertParseError(" baz")
def test_invalid_section(self):
self._assertParseError("[section")
def test_no_section_name(self):
self._assertParseError("[]")
class ParserTestCase(unittest.TestCase):
def setUp(self):
self.parser = TestParser()
def test_blank_line(self):
lines = [""]
self.parser.parse(lines)
self.assertEqual(self.parser.values, {})
def test_assignment_equal(self):
lines = ["foo = bar"]
self.parser.parse(lines)
self.assertEqual(self.parser.values, {'': {'foo': ['bar']}})
def test_assignment_colon(self):
lines = ["foo: bar"]
self.parser.parse(lines)
self.assertEqual(self.parser.values, {'': {'foo': ['bar']}})
def test_assignment_multiline(self):
lines = ["foo = bar0", " bar1"]
self.parser.parse(lines)
self.assertEqual(self.parser.values, {'': {'foo': ['bar0', 'bar1']}})
def test_assignment_multline_empty(self):
lines = ["foo = bar0", "", " bar1"]
self.assertRaises(iniparser.ParseError, self.parser.parse, lines)
def test_section_assignment(self):
lines = ["[test]", "foo = bar"]
self.parser.parse(lines)
self.assertEqual(self.parser.values, {'test': {'foo': ['bar']}})
def test_new_section(self):
lines = ["[foo]"]
self.parser.parse(lines)
self.assertEqual(self.parser.section, 'foo')
def test_comment(self):
lines = ["# foobar"]
self.parser.parse(lines)
self.assertTrue(self.parser.comment_called)