Move cloud fixtures to independent yaml files

Instead of hardcoding the cloud data inside the code,
move them to independent fixtures, so they are easily
reusable, and we have freedom to add more cloud fixtures
in the future.

Change-Id: I57e460684ccc203b2eb5c70019e64b81ed5f2396
This commit is contained in:
Yolanda Robla 2016-05-04 16:50:42 +02:00
parent 31ac451e12
commit a53db2c680
4 changed files with 52 additions and 75 deletions

View File

@ -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()

View File

@ -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_

View File

@ -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_

View File

@ -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):