Identity section should not be used to specify credentials

Credentials should be specified in the accounts file
as described in the Tempest configuration guide
(http://docs.openstack.org/developer/tempest/configuration.html).
Specifying credentials in the identity section of the tempest
config file is deprecated.

If the user provides credentials in the identity section of tempest
config file and does not provide accounts file, show a warning
that this is deprecated and will be not supported in the future.

If the user does not provide credentials at all, show an error and
exit.

Show information to the user how to configure the credentials.

Update the refstack-client unit tests that still use the identity
section to use accounts file instead.

Change-Id: I6eab3b587292a35404c93da35914ad1f53ef49c7
Closes-Bug: #1552377
This commit is contained in:
Simeon Monov 2016-03-03 02:12:57 +01:00
parent 1b7f413b60
commit b066bd68a8
2 changed files with 85 additions and 6 deletions

View File

@ -183,7 +183,15 @@ class RefstackClient:
'username': username, 'password': password,
'tenant_id': tenant_id, 'tenant_name': tenant_name
}
else:
elif conf_file.has_option('identity', 'username'):
self.logger.warn('Using identity section of tempest config '
'file to specify user credentials is '
'deprecated and won\'t be supported soon. '
'User credentials should be defined in the '
'accounts file as described in the Tempest '
'configuration guide (http://docs.openstack.'
'org/developer/tempest/configuration.html).')
username = conf_file.get('identity', 'username')
password = conf_file.get('identity', 'password')
@ -197,6 +205,13 @@ class RefstackClient:
'domain_name': domain_name,
'username': username, 'password': password,
'tenant_id': tenant_id, 'tenant_name': tenant_name}
else:
self.logger.error('User credentials cannot be found. '
'User credentials should be defined in the '
'accounts file as described in the Tempest '
'configuration guide (http://docs.openstack.'
'org/developer/tempest/configuration.html).')
exit(1)
except ConfigParser.Error as e:
# Most likely a missing section or option in the config file.
self.logger.error("Invalid Config File: %s" % e)

View File

@ -193,6 +193,20 @@ class TestRefstackClient(unittest.TestCase):
with self.assertRaises(SystemExit):
client._get_keystone_config(client.conf)
def test_get_keystone_config_no_accounts_file(self):
"""
Test that the client will exit if accounts file
is not specified.
"""
args = rc.parse_cli_args(self.mock_argv())
client = rc.RefstackClient(args)
client.tempest_dir = self.test_path
client._prep_test()
self.mock_data()
with self.assertRaises(SystemExit):
client._get_keystone_config(client.conf)
def test_get_keystone_config(self):
"""
Test that keystone configs properly parsed.
@ -201,8 +215,22 @@ class TestRefstackClient(unittest.TestCase):
client = rc.RefstackClient(args)
client.tempest_dir = self.test_path
client._prep_test()
client.conf.set('identity', 'tenant_name', 'tenant_name')
client.conf.add_section('auth')
client.conf.set('auth',
'test_accounts_file',
'%s/test-accounts.yaml' % self.test_path)
self.mock_data()
accounts = [
{
'username': 'admin',
'tenant_name': 'tenant_name',
'tenant_id': 'admin_tenant_id',
'password': 'test'
}
]
self.patch(
'refstack_client.refstack_client.read_accounts_yaml',
return_value=accounts)
actual_result = client._get_keystone_config(client.conf)
expected_result = self.v2_config
self.assertEqual(expected_result, actual_result)
@ -243,8 +271,21 @@ class TestRefstackClient(unittest.TestCase):
client = rc.RefstackClient(args)
client.tempest_dir = self.test_path
client._prep_test()
client.conf.set('identity', 'tenant_name', 'tenant_name')
client.conf.add_section('auth')
client.conf.set('auth',
'test_accounts_file',
'%s/test-accounts.yaml' % self.test_path)
self.mock_data()
accounts = [
{
'username': 'admin',
'tenant_id': 'admin_tenant_id',
'password': 'test'
}
]
self.patch(
'refstack_client.refstack_client.read_accounts_yaml',
return_value=accounts)
configs = client._get_keystone_config(client.conf)
actual_results = client._generate_keystone_data(configs)
expected_results = ('v2', 'http://0.0.0.0:35357/v2.0/tokens',
@ -264,10 +305,20 @@ class TestRefstackClient(unittest.TestCase):
client = rc.RefstackClient(args)
client.tempest_dir = self.test_path
client._prep_test()
client.conf.remove_option('identity', 'tenant_id')
client.conf.set('identity', 'tenant_name', 'tenant_name')
client.conf.set('identity-feature-enabled', 'api_v3', 'true')
client.conf.add_section('auth')
client.conf.set('auth',
'test_accounts_file',
'%s/test-accounts.yaml' % self.test_path)
self.mock_data()
accounts = [
{
'tenant_name': 'tenant_name'
}
]
self.patch(
'refstack_client.refstack_client.read_accounts_yaml',
return_value=accounts)
configs = client._get_keystone_config(client.conf)
auth_version, auth_url, content = \
client._generate_keystone_data(configs)
@ -329,10 +380,23 @@ class TestRefstackClient(unittest.TestCase):
client = rc.RefstackClient(args)
client.tempest_dir = self.test_path
client._prep_test()
client.conf.set('identity', 'tenant_name', 'tenant_name')
client.logger.warning = MagicMock()
client._generate_cpid_from_endpoint = MagicMock()
client.conf.add_section('auth')
client.conf.set('auth',
'test_accounts_file',
'%s/test-accounts.yaml' % self.test_path)
self.mock_data()
accounts = [
{
'tenant_name': 'tenant_name',
'tenant_id': 'admin_tenant_id',
'password': 'test'
}
]
self.patch(
'refstack_client.refstack_client.read_accounts_yaml',
return_value=accounts)
configs = client._get_keystone_config(client.conf)
auth_version, url, content = client._generate_keystone_data(configs)