Log the names of the other isolated_creds on starvation
When exhaust all of the valid hashes for a give creds request the
error message just says insufficient creds, which isn't useful in
debugging the case when there are sufficient creds but some other
interaction is going on. This commit adds the name passed into the
isolated_creds constructor for all of the hashes which were tried
before the list was exhausted to the exception message so we have
a starting place for debugging these issues.
Change-Id: Ie97dd6ae2c375b385ae4ea30e347af28493025cb
diff --git a/tempest/common/accounts.py b/tempest/common/accounts.py
index 9ecf596..e21a85e 100644
--- a/tempest/common/accounts.py
+++ b/tempest/common/accounts.py
@@ -37,6 +37,7 @@
def __init__(self, name):
super(Accounts, self).__init__(name)
+ self.name = name
if os.path.isfile(CONF.auth.test_accounts_file):
accounts = read_accounts_yaml(CONF.auth.test_accounts_file)
self.use_default_creds = False
@@ -70,7 +71,8 @@
def _create_hash_file(self, hash_string):
path = os.path.join(os.path.join(self.accounts_dir, hash_string))
if not os.path.isfile(path):
- open(path, 'w').close()
+ with open(path, 'w') as fd:
+ fd.write(self.name)
return True
return False
@@ -81,11 +83,18 @@
# Create File from first hash (since none are in use)
self._create_hash_file(hashes[0])
return hashes[0]
+ names = []
for _hash in hashes:
res = self._create_hash_file(_hash)
if res:
return _hash
- msg = 'Insufficient number of users provided'
+ else:
+ path = os.path.join(os.path.join(self.accounts_dir,
+ _hash))
+ with open(path, 'r') as fd:
+ names.append(fd.read())
+ msg = ('Insufficient number of users provided. %s have allocated all '
+ 'the credentials for this allocation request' % ','.join(names))
raise exceptions.InvalidConfiguration(msg)
def _get_creds(self):
diff --git a/tempest/tests/common/test_accounts.py b/tempest/tests/common/test_accounts.py
index a836a20..5726e69 100644
--- a/tempest/tests/common/test_accounts.py
+++ b/tempest/tests/common/test_accounts.py
@@ -129,8 +129,9 @@
# Emulate all lcoks in list are in use
self.useFixture(mockpatch.Patch('os.path.isfile', return_value=True))
test_account_class = accounts.Accounts('test_name')
- self.assertRaises(exceptions.InvalidConfiguration,
- test_account_class._get_free_hash, hash_list)
+ with mock.patch('__builtin__.open', mock.mock_open(), create=True):
+ self.assertRaises(exceptions.InvalidConfiguration,
+ test_account_class._get_free_hash, hash_list)
@mock.patch('tempest.openstack.common.lockutils.lock')
def test_get_free_hash_some_in_use_accounts(self, lock_mock):
@@ -152,7 +153,7 @@
test_account_class._get_free_hash(hash_list)
lock_path = os.path.join(accounts.CONF.lock_path, 'test_accounts',
hash_list[3])
- open_mock.assert_called_once_with(lock_path, 'w')
+ open_mock.assert_has_calls([mock.call(lock_path, 'w')])
@mock.patch('tempest.openstack.common.lockutils.lock')
def test_remove_hash_last_account(self, lock_mock):