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
diff --git a/tempest/common/accounts.py b/tempest/common/accounts.py
index c491169..7423c17 100644
--- a/tempest/common/accounts.py
+++ b/tempest/common/accounts.py
@@ -38,7 +38,12 @@
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 @@
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 @@
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
diff --git a/tempest/tests/common/test_accounts.py b/tempest/tests/common/test_accounts.py
index a0b3496..cf7ce65 100644
--- a/tempest/tests/common/test_accounts.py
+++ b/tempest/tests/common/test_accounts.py
@@ -57,6 +57,7 @@
'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 @@
'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 @@
self.assertIsNotNone(creds, msg)
self.assertRaises(exceptions.InvalidConfiguration,
test_accounts_class.get_creds,
- id=len(self.test_accounts))
\ No newline at end of file
+ id=len(self.test_accounts))