Fix username is not defined warning

The tool tries to find the credentials in auth section first
and if it gets None, it tries identity section then. Because
of this a unnecessary warning message is logged out.
The patch changes the way, how the credentials are retrieved
from conf, so that there are no warnings.

Change-Id: I841241bddeb12cac9207c15e9dc4e1de8860791b
Story: 2002539
Task: 22085
Martin Kopec 2018-06-13 19:08:02 +00:00
parent b8f5b25728
commit 6d7968bb16
2 changed files with 7 additions and 29 deletions

View File

@ -53,24 +53,14 @@ class Credentials(object):
:returns: credential
:rtype: string
admin_prefix = 'admin_' if self.admin else ""
return self.get_identity_credential(admin_prefix + key)
def get_identity_credential(self, key):
"""Get credential requested by its name.
The function is providing the backwards compatibility for looking up
the credentials, because admin credentials were moved from identity
to auth section.
:param key: name of the credential e.g. username, passsword ...
:type key: string
:returns: credential
:rtype: string
value = self._conf.get_defaulted('auth', key)
if value is None:
if self.admin:
# admin credentials are stored in auth section
# and are prefixed by 'admin_'
return self._conf.get_defaulted('auth', 'admin_' + key)
# Tempest doesn't have non admin credentials, but the
# tool keeps them in identity section for further usage
return self._conf.get_defaulted('identity', key)
return value
def _get_identity_version(self):
"""Looks for identity version in TempestConf object.

View File

@ -38,18 +38,6 @@ class TestCredentials(BaseConfigTempestTest):
resp = self.creds.get_credential("username")
self.assertEqual(resp, "admin")
def test_get_identity_credential(self):
for i in range(0, 2):
resp = self.creds.get_identity_credential("username")
self.assertEqual(resp, "demo")
# set admin credentials
self.creds.admin = True
resp = self.creds.get_identity_credential("admin_username")
self.assertEqual(resp, "admin")
# use conf which contains the newer values - (admin creds
# in auth section)
self.creds._conf = self._get_alt_conf("v2.0", "v3")
def test_get_identity_version_v2(self):
resp = self.creds._get_identity_version()
self.assertEqual(resp, 'v2')