Backward compatibility to credentials in conf

Before switching to the YAML based configuration as the default for
credentials, we need to introduce backward compatibility to allow
credentials to be configured in tempest.conf.

Partially implements bp:test-accounts

Change-Id: I29c66c87d02f442b1d5b0b2d7c82ff2a140c111f
This commit is contained in:
Matthew Treinish 2014-09-04 09:57:46 -04:00 committed by Andrea Frittoli
parent 905d3c9f67
commit b19eeb84e9
2 changed files with 22 additions and 6 deletions

View File

@ -38,7 +38,12 @@ class Accounts(cred_provider.CredentialProvider):
def __init__(self, name):
super(Accounts, self).__init__(name)
accounts = read_accounts_yaml(CONF.auth.test_accounts_file)
if os.path.isfile(CONF.auth.test_accounts_file):
accounts = read_accounts_yaml(CONF.auth.test_accounts_file)
self.use_default_creds = False
else:
accounts = {}
self.use_default_creds = True
self.hash_dict = self.get_hash_dict(accounts)
self.accounts_dir = os.path.join(CONF.lock_path, 'test_accounts')
self.isolated_creds = {}
@ -77,6 +82,9 @@ class Accounts(cred_provider.CredentialProvider):
raise exceptions.InvalidConfiguration(msg)
def _get_creds(self):
if self.use_default_creds:
raise exceptions.InvalidConfiguration(
"Account file %s doesn't exist" % CONF.auth.test_accounts_file)
free_hash = self._get_free_hash(self.hash_dict.keys())
return self.hash_dict[free_hash]
@ -150,16 +158,22 @@ class NotLockingAccounts(Accounts):
def get_primary_creds(self):
if self.isolated_creds.get('primary'):
return self.isolated_creds.get('primary')
creds = self.get_creds(0)
primary_credential = auth.get_credentials(**creds)
if not self.use_default_creds:
creds = self.get_creds(0)
primary_credential = auth.get_credentials(**creds)
else:
primary_credential = auth.get_default_credentials('user')
self.isolated_creds['primary'] = primary_credential
return primary_credential
def get_alt_creds(self):
if self.isolated_creds.get('alt'):
return self.isolated_creds.get('alt')
creds = self.get_creds(1)
alt_credential = auth.get_credentials(**creds)
if not self.use_default_creds:
creds = self.get_creds(1)
alt_credential = auth.get_credentials(**creds)
else:
alt_credential = auth.get_default_credentials('alt_user')
self.isolated_creds['alt'] = alt_credential
return alt_credential

View File

@ -57,6 +57,7 @@ class TestAccount(base.TestCase):
'tempest.common.accounts.read_accounts_yaml',
return_value=self.test_accounts))
cfg.CONF.set_default('test_accounts_file', '', group='auth')
self.useFixture(mockpatch.Patch('os.path.isfile', return_value=True))
def _get_hash_list(self, accounts_list):
hash_list = []
@ -220,6 +221,7 @@ class TestNotLockingAccount(base.TestCase):
'tempest.common.accounts.read_accounts_yaml',
return_value=self.test_accounts))
cfg.CONF.set_default('test_accounts_file', '', group='auth')
self.useFixture(mockpatch.Patch('os.path.isfile', return_value=True))
def test_get_creds(self):
test_accounts_class = accounts.NotLockingAccounts('test_name')
@ -229,4 +231,4 @@ class TestNotLockingAccount(base.TestCase):
self.assertIsNotNone(creds, msg)
self.assertRaises(exceptions.InvalidConfiguration,
test_accounts_class.get_creds,
id=len(self.test_accounts))
id=len(self.test_accounts))