Fix unit tests for migration

Prepare credential providers unit tests for migration:
- move dynamic_creds tests to the right folder
- rename tenant_isolation variable to dynamic_creds in admin_available
- create missing tests for alt_available

Change-Id: Ib8dcdd1671b3d107a6358b8b0b5a1639485161c5
This commit is contained in:
Andrea Frittoli (andreaf) 2015-10-09 13:38:20 +01:00 committed by Andrea Frittoli
parent c2e6a88831
commit 9c79845e58
3 changed files with 145 additions and 22 deletions

View File

@ -30,10 +30,10 @@ class TestAdminAvailable(base.TestCase):
self.useFixture(fake_config.ConfigFixture())
self.stubs.Set(config, 'TempestConfigPrivate', fake_config.FakePrivate)
def run_test(self, tenant_isolation, use_accounts_file, admin_creds):
def run_test(self, dynamic_creds, use_accounts_file, admin_creds):
cfg.CONF.set_default('use_dynamic_credentials',
tenant_isolation, group='auth')
dynamic_creds, group='auth')
if use_accounts_file:
accounts = [{'username': 'u1',
'tenant_name': 't1',
@ -62,48 +62,54 @@ class TestAdminAvailable(base.TestCase):
self.useFixture(mockpatch.Patch('os.path.isfile',
return_value=False))
if admin_creds:
(u, t, p, d) = ('u', 't', 'p', 'd')
username = 'u'
tenant = 't'
password = 'p'
domain = 'd'
else:
(u, t, p, d) = (None, None, None, None)
username = None
tenant = None
password = None
domain = None
cfg.CONF.set_default('admin_username', u, group='auth')
cfg.CONF.set_default('admin_tenant_name', t, group='auth')
cfg.CONF.set_default('admin_password', p, group='auth')
cfg.CONF.set_default('admin_domain_name', d, group='auth')
cfg.CONF.set_default('admin_username', username, group='auth')
cfg.CONF.set_default('admin_tenant_name', tenant, group='auth')
cfg.CONF.set_default('admin_password', password, group='auth')
cfg.CONF.set_default('admin_domain_name', domain, group='auth')
expected = admin_creds is not None or tenant_isolation
expected = admin_creds is not None or dynamic_creds
observed = credentials.is_admin_available(
identity_version=self.identity_version)
self.assertEqual(expected, observed)
# Tenant isolation implies admin so only one test case for True
def test__tenant_isolation__accounts_file__no_admin(self):
self.run_test(tenant_isolation=True,
# Dynamic credentials implies admin so only one test case for True
def test__dynamic_creds__accounts_file__no_admin(self):
self.run_test(dynamic_creds=True,
use_accounts_file=True,
admin_creds=None)
def test__no_tenant_isolation__accounts_file__no_admin(self):
self.run_test(tenant_isolation=False,
def test__no_dynamic_creds__accounts_file__no_admin(self):
self.run_test(dynamic_creds=False,
use_accounts_file=True,
admin_creds=None)
def test__no_tenant_isolation__accounts_file__admin_role(self):
self.run_test(tenant_isolation=False,
def test__no_dynamic_creds__accounts_file__admin_role(self):
self.run_test(dynamic_creds=False,
use_accounts_file=True,
admin_creds='role')
def test__no_tenant_isolation__accounts_file__admin_type(self):
self.run_test(tenant_isolation=False,
def test__no_dynamic_creds__accounts_file__admin_type(self):
self.run_test(dynamic_creds=False,
use_accounts_file=True,
admin_creds='type')
def test__no_tenant_isolation__no_accounts_file__no_admin(self):
self.run_test(tenant_isolation=False,
def test__no_dynamic_creds__no_accounts_file__no_admin(self):
self.run_test(dynamic_creds=False,
use_accounts_file=False,
admin_creds=None)
def test__no_tenant_isolation__no_accounts_file__admin(self):
self.run_test(tenant_isolation=False,
def test__no_dynamic_creds__no_accounts_file__admin(self):
self.run_test(dynamic_creds=False,
use_accounts_file=False,
admin_creds='role')

View File

@ -0,0 +1,117 @@
# Copyright 2015 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 oslo_config import cfg
from oslotest import mockpatch
from tempest.common import credentials
from tempest import config
from tempest.tests import base
from tempest.tests import fake_config
class TestAltAvailable(base.TestCase):
identity_version = 'v2'
def setUp(self):
super(TestAltAvailable, self).setUp()
self.useFixture(fake_config.ConfigFixture())
self.stubs.Set(config, 'TempestConfigPrivate', fake_config.FakePrivate)
def run_test(self, dynamic_creds, use_accounts_file, creds):
cfg.CONF.set_default('use_dynamic_credentials',
dynamic_creds, group='auth')
if use_accounts_file:
accounts = [dict(username="u%s" % ii,
tenant_name="t%s" % ii,
password="p") for ii in creds]
self.useFixture(mockpatch.Patch(
'tempest.common.preprov_creds.read_accounts_yaml',
return_value=accounts))
cfg.CONF.set_default('test_accounts_file',
use_accounts_file, group='auth')
self.useFixture(mockpatch.Patch('os.path.isfile',
return_value=True))
else:
self.useFixture(mockpatch.Patch('os.path.isfile',
return_value=False))
cred_prefix = ['', 'alt_']
for ii in range(0, 2):
if len(creds) > ii:
username = 'u%s' % creds[ii]
tenant = 't%s' % creds[ii]
password = 'p'
domain = 'd'
else:
username = None
tenant = None
password = None
domain = None
cfg.CONF.set_default('%susername' % cred_prefix[ii], username,
group='identity')
cfg.CONF.set_default('%stenant_name' % cred_prefix[ii], tenant,
group='identity')
cfg.CONF.set_default('%spassword' % cred_prefix[ii], password,
group='identity')
cfg.CONF.set_default('%sdomain_name' % cred_prefix[ii], domain,
group='identity')
expected = len(set(creds)) > 1 or dynamic_creds
observed = credentials.is_alt_available(
identity_version=self.identity_version)
self.assertEqual(expected, observed)
# Dynamic credentials implies alt so only one test case for True
def test__dynamic_creds__accounts_file__one_user(self):
self.run_test(dynamic_creds=True,
use_accounts_file=False,
creds=['1', '2'])
def test__no_dynamic_creds__accounts_file__one_user(self):
self.run_test(dynamic_creds=False,
use_accounts_file=True,
creds=['1'])
def test__no_dynamic_creds__accounts_file__two_users(self):
self.run_test(dynamic_creds=False,
use_accounts_file=True,
creds=['1', '2'])
def test__no_dynamic_creds__accounts_file__two_users_identical(self):
self.run_test(dynamic_creds=False,
use_accounts_file=True,
creds=['1', '1'])
def test__no_dynamic_creds__no_accounts_file__one_user(self):
self.run_test(dynamic_creds=False,
use_accounts_file=False,
creds=['1'])
def test__no_dynamic_creds__no_accounts_file__two_users(self):
self.run_test(dynamic_creds=False,
use_accounts_file=False,
creds=['1', '2'])
def test__no_dynamic_creds__no_accounts_file__two_users_identical(self):
self.run_test(dynamic_creds=False,
use_accounts_file=False,
creds=['1', '1'])
class TestAltAvailableV3(TestAltAvailable):
identity_version = 'v3'