diff --git a/shade/tests/unit/base.py b/shade/tests/unit/base.py index d9d6012c4..8768ebb7a 100644 --- a/shade/tests/unit/base.py +++ b/shade/tests/unit/base.py @@ -20,7 +20,6 @@ import time import fixtures import os_client_config as occ import tempfile -import yaml import shade.openstackcloud from shade.tests import base @@ -28,26 +27,7 @@ from shade.tests import base class TestCase(base.TestCase): - """Test case base class for all unit tests.""" - - CLOUD_CONFIG = { - 'clouds': - { - '_test_cloud_': - { - 'auth': - { - 'auth_url': 'http://198.51.100.1:35357/v2.0', - 'username': '_test_user_', - 'password': '_test_pass_', - 'project_name': '_test_project_', - }, - 'region_name': '_test_region_', - }, - }, - } - - def setUp(self): + def setUp(self, cloud_config_fixture='clouds.yaml'): """Run before each test method to initialize test environment.""" super(TestCase, self).setUp() @@ -61,11 +41,17 @@ class TestCase(base.TestCase): self.sleep_fixture = self.useFixture(fixtures.MonkeyPatch( 'time.sleep', _nosleep)) + self.fixtures_directory = 'shade/tests/unit/fixtures' # Isolate os-client-config from test environment config = tempfile.NamedTemporaryFile(delete=False) - config.write(bytes(yaml.dump(self.CLOUD_CONFIG).encode('utf-8'))) + cloud_path = '%s/clouds/%s' % (self.fixtures_directory, + cloud_config_fixture) + with open(cloud_path, 'rb') as f: + content = f.read() + config.write(content) config.close() + vendor = tempfile.NamedTemporaryFile(delete=False) vendor.write(b'{}') vendor.close() diff --git a/shade/tests/unit/fixtures/clouds/clouds.yaml b/shade/tests/unit/fixtures/clouds/clouds.yaml new file mode 100644 index 000000000..6be237471 --- /dev/null +++ b/shade/tests/unit/fixtures/clouds/clouds.yaml @@ -0,0 +1,17 @@ +clouds: + _test_cloud_: + auth: + auth_url: http://192.168.0.19:35357 + password: password + project_name: admin + username: admin + identity_api_version: '2.0' + region_name: RegionOne + _bogus_test_: + auth_type: bogus + auth: + auth_url: http://198.51.100.1:35357/v2.0 + username: _test_user_ + password: _test_pass_ + project_name: _test_project_ + region_name: _test_region_ diff --git a/shade/tests/unit/fixtures/clouds/clouds_cache.yaml b/shade/tests/unit/fixtures/clouds/clouds_cache.yaml new file mode 100644 index 000000000..bc39142e9 --- /dev/null +++ b/shade/tests/unit/fixtures/clouds/clouds_cache.yaml @@ -0,0 +1,22 @@ +cache: + max_age: 90 + class: dogpile.cache.memory + expiration: + server: 1 +clouds: + _test_cloud_: + auth: + auth_url: http://192.168.0.19:35357 + password: password + project_name: admin + username: admin + identity_api_version: '2.0' + region_name: RegionOne + _bogus_test_: + auth_type: bogus + auth: + auth_url: http://198.51.100.1:35357/v2.0 + username: _test_user_ + password: _test_pass_ + project_name: _test_project_ + region_name: _test_region_ diff --git a/shade/tests/unit/test_caching.py b/shade/tests/unit/test_caching.py index 8626bd9fa..477cd9906 100644 --- a/shade/tests/unit/test_caching.py +++ b/shade/tests/unit/test_caching.py @@ -97,30 +97,9 @@ _TASK_SCHEMA = dict( class TestMemoryCache(base.TestCase): - CLOUD_CONFIG = { - 'cache': - { - 'max_age': 90, - 'class': 'dogpile.cache.memory', - 'expiration': { - 'server': 1, - }, - }, - 'clouds': - { - '_test_cloud_': - { - 'auth': - { - 'auth_url': 'http://198.51.100.1:35357/v2.0', - 'username': '_test_user_', - 'password': '_test_pass_', - 'project_name': '_test_project_', - }, - 'region_name': '_test_region_', - }, - }, - } + def setUp(self): + super(TestMemoryCache, self).setUp( + cloud_config_fixture='clouds_cache.yaml') def test_openstack_cloud(self): self.assertIsInstance(self.cloud, shade.OpenStackCloud) @@ -522,37 +501,10 @@ class TestMemoryCache(base.TestCase): class TestBogusAuth(base.TestCase): - CLOUD_CONFIG = { - 'clouds': - { - '_test_cloud_': - { - 'auth': - { - 'auth_url': 'http://198.51.100.1:35357/v2.0', - 'username': '_test_user_', - 'password': '_test_pass_', - 'project_name': '_test_project_', - }, - 'region_name': '_test_region_', - }, - '_bogus_test_': - { - 'auth_type': 'bogus', - 'auth': - { - 'auth_url': 'http://198.51.100.1:35357/v2.0', - 'username': '_test_user_', - 'password': '_test_pass_', - 'project_name': '_test_project_', - }, - 'region_name': '_test_region_', - }, - }, - } def setUp(self): - super(TestBogusAuth, self).setUp() + super(TestBogusAuth, self).setUp( + cloud_config_fixture='clouds_cache.yaml') def test_get_auth_bogus(self): with testtools.ExpectedException(exc.OpenStackCloudException):