Convert fake_config class to use config fixture
This commit changes the fake_config object used in the unit tests to
use the config fixture and use the real config defaults by registering
the config options and using the oslo config set_default method to
override the defaults when needed for testing. This will enable reusing
the tempest defaults in most places which should save effort duplicating
defaults in the fake object.
Partially Implements bp unit-tests
Change-Id: Ib9ee8e68f7000bfbcd3cd1c94cca103a3286ec77
diff --git a/tempest/tests/fake_config.py b/tempest/tests/fake_config.py
index e941606..8a8ebb0 100644
--- a/tempest/tests/fake_config.py
+++ b/tempest/tests/fake_config.py
@@ -12,49 +12,33 @@
# License for the specific language governing permissions and limitations
# under the License.
+from oslo.config import cfg
-class FakeConfig(object):
+from tempest import config
+from tempest.openstack.common.fixture import config as conf_fixture
- class fake_compute(object):
- build_interval = 10
- build_timeout = 10
- class fake_identity(object):
- disable_ssl_certificate_validation = True
- catalog_type = 'identity'
- uri = 'http://fake_uri.com/auth'
- uri_v3 = 'http://fake_uri_v3.com/auth'
+class ConfigFixture(conf_fixture.Config):
- class fake_default_feature_enabled(object):
- api_extensions = ['all']
+ def __init__(self):
+ config.register_opts()
+ super(ConfigFixture, self).__init__()
- class fake_compute_feature_enabled(fake_default_feature_enabled):
- api_v3_extensions = ['all']
+ def setUp(self):
+ super(ConfigFixture, self).setUp()
+ self.conf.set_default('build_interval', 10, group='compute')
+ self.conf.set_default('build_timeout', 10, group='compute')
+ self.conf.set_default('disable_ssl_certificate_validation', True,
+ group='identity')
+ self.conf.set_default('uri', 'http://fake_uri.com/auth',
+ group='identity')
+ self.conf.set_default('uri_v3', 'http://fake_uri_v3.com/auth',
+ group='identity')
+ self.conf.set_default('neutron', True, group='service_available')
+ self.conf.set_default('heat', True, group='service_available')
- class fake_object_storage_discoverable_apis(object):
- discoverable_apis = ['all']
- class fake_service_available(object):
- nova = True
- glance = True
- cinder = True
- heat = True
- neutron = True
- swift = True
- horizon = True
-
- class fake_negative(object):
- test_generator = 'tempest.common.' \
- 'generator.negative_generator.NegativeTestGenerator'
-
- compute_feature_enabled = fake_compute_feature_enabled()
- volume_feature_enabled = fake_default_feature_enabled()
- network_feature_enabled = fake_default_feature_enabled()
- object_storage_feature_enabled = fake_object_storage_discoverable_apis()
-
- service_available = fake_service_available()
-
- compute = fake_compute()
- identity = fake_identity()
-
- negative = fake_negative()
+class FakePrivate(config.TempestConfigPrivate):
+ def __init__(self):
+ cfg.CONF([], default_config_files=[])
+ self._set_attrs()
diff --git a/tempest/tests/negative/test_negative_auto_test.py b/tempest/tests/negative/test_negative_auto_test.py
index 27ddc95..7a1909a 100644
--- a/tempest/tests/negative/test_negative_auto_test.py
+++ b/tempest/tests/negative/test_negative_auto_test.py
@@ -15,6 +15,7 @@
import mock
+from tempest import config
import tempest.test as test
from tempest.tests import base
from tempest.tests import fake_config
@@ -38,7 +39,8 @@
def setUp(self):
super(TestNegativeAutoTest, self).setUp()
- self.stubs.Set(test, 'CONF', fake_config.FakeConfig)
+ self.useFixture(fake_config.ConfigFixture())
+ self.stubs.Set(config, 'TempestConfigPrivate', fake_config.FakePrivate)
def _check_prop_entries(self, result, entry):
entries = [a for a in result if entry in a[0]]
diff --git a/tempest/tests/test_auth.py b/tempest/tests/test_auth.py
index df04d65..b6e15bd 100644
--- a/tempest/tests/test_auth.py
+++ b/tempest/tests/test_auth.py
@@ -42,7 +42,8 @@
def setUp(self):
super(BaseAuthTestsSetUp, self).setUp()
- self.stubs.Set(config, 'TempestConfigPrivate', fake_config.FakeConfig)
+ self.useFixture(fake_config.ConfigFixture())
+ self.stubs.Set(config, 'TempestConfigPrivate', fake_config.FakePrivate)
self.fake_http = fake_http.fake_httplib2(return_type=200)
self.stubs.Set(http.ClosingHttp, 'request', self.fake_http.request)
self.auth_provider = self._auth(self.credentials)
diff --git a/tempest/tests/test_decorators.py b/tempest/tests/test_decorators.py
index aa3c8fc..ebf0ca0 100644
--- a/tempest/tests/test_decorators.py
+++ b/tempest/tests/test_decorators.py
@@ -15,6 +15,9 @@
import testtools
+from oslo.config import cfg
+
+from tempest import config
from tempest import exceptions
from tempest.openstack.common.fixture import mockpatch
from tempest import test
@@ -25,7 +28,8 @@
class BaseDecoratorsTest(base.TestCase):
def setUp(self):
super(BaseDecoratorsTest, self).setUp()
- self.stubs.Set(test, 'CONF', fake_config.FakeConfig)
+ self.config_fixture = self.useFixture(fake_config.ConfigFixture())
+ self.stubs.Set(config, 'TempestConfigPrivate', fake_config.FakePrivate)
class TestAttrDecorator(BaseDecoratorsTest):
@@ -191,10 +195,8 @@
class TestRequiresExtDecorator(BaseDecoratorsTest):
def setUp(self):
super(TestRequiresExtDecorator, self).setUp()
- self.fixture = self.useFixture(mockpatch.PatchObject(
- test.CONF.compute_feature_enabled,
- 'api_extensions',
- new=['enabled_ext', 'another_ext']))
+ cfg.CONF.set_default('api_extensions', ['enabled_ext', 'another_ext'],
+ 'compute-feature-enabled')
def _test_requires_ext_helper(self, expected_to_skip=True,
**decorator_args):
@@ -220,7 +222,7 @@
def test_requires_ext_decorator_with_all_ext_enabled(self):
# disable fixture so the default (all) is used.
- self.fixture.cleanUp()
+ self.config_fixture.cleanUp()
self._test_requires_ext_helper(expected_to_skip=False,
extension='random_ext',
service='compute')
diff --git a/tempest/tests/test_rest_client.py b/tempest/tests/test_rest_client.py
index 827b5c9..4c23fbd 100644
--- a/tempest/tests/test_rest_client.py
+++ b/tempest/tests/test_rest_client.py
@@ -35,7 +35,8 @@
def setUp(self):
super(BaseRestClientTestClass, self).setUp()
- self.stubs.Set(config, 'TempestConfigPrivate', fake_config.FakeConfig)
+ self.useFixture(fake_config.ConfigFixture())
+ self.stubs.Set(config, 'TempestConfigPrivate', fake_config.FakePrivate)
self.rest_client = rest_client.RestClient(
fake_auth_provider.FakeAuthProvider())
self.stubs.Set(httplib2.Http, 'request', self.fake_http.request)
@@ -254,7 +255,8 @@
def setUp(self):
super(TestRestClientErrorCheckerJSON, self).setUp()
- self.stubs.Set(config, 'TempestConfigPrivate', fake_config.FakeConfig)
+ self.useFixture(fake_config.ConfigFixture())
+ self.stubs.Set(config, 'TempestConfigPrivate', fake_config.FakePrivate)
self.rest_client = rest_client.RestClient(
fake_auth_provider.FakeAuthProvider())