From 340344526bff3dc2b298eb55f99ce5eb7bff1579 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Piwowarski?= Date: Wed, 12 Oct 2022 12:11:41 +0200 Subject: [PATCH] Fix parsing of tenant/project_name values The parsing of tenant_name value from tempest.conf ends with an error as the ConfigParser.get() function fails if a requested value is missing in a config file. This patch fixes the issue by using the fallback option of the ConfigParser.get() function. Also, the unittest that checks the reading of [identity] section from tempest.conf is fixed. Change-Id: I9b3224f4ab8900a4954814844ef8c13e099ccae9 --- refstack_client/refstack_client.py | 3 ++- refstack_client/tests/unit/refstack-client.test.conf | 3 ++- refstack_client/tests/unit/test_client.py | 12 +++++++----- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/refstack_client/refstack_client.py b/refstack_client/refstack_client.py index 08a9251..959fc41 100755 --- a/refstack_client/refstack_client.py +++ b/refstack_client/refstack_client.py @@ -228,7 +228,8 @@ class RefstackClient: project_id = conf_file.get('identity', 'project_id') else: project_id = None - project_name = (conf_file.get('identity', 'tenant_name') or + project_name = (conf_file.get('identity', 'tenant_name', + fallback=False) or conf_file.get('identity', 'project_name')) return {'auth_version': auth_version, 'auth_url': auth_url, diff --git a/refstack_client/tests/unit/refstack-client.test.conf b/refstack_client/tests/unit/refstack-client.test.conf index 432c107..05e0ae5 100644 --- a/refstack_client/tests/unit/refstack-client.test.conf +++ b/refstack_client/tests/unit/refstack-client.test.conf @@ -4,7 +4,8 @@ uri = http://0.0.0.0:35357/v2.0 uri_v3 = http://0.0.0.0:35357/v3 username = admin password = test -tenant_id = admin_tenant_id +tenant_id = admin_project_id +project_name = project_name [identity-feature-enabled] api_v2 = true diff --git a/refstack_client/tests/unit/test_client.py b/refstack_client/tests/unit/test_client.py index 7ab4510..fcadc82 100755 --- a/refstack_client/tests/unit/test_client.py +++ b/refstack_client/tests/unit/test_client.py @@ -189,17 +189,19 @@ class TestRefstackClient(unittest.TestCase): def test_get_keystone_config_no_accounts_file(self): """ - Test that the client will exit if accounts file - is not specified. + Test that the client will read account info from + tempest.conf when the 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) + + actual_result = client._get_keystone_config(client.conf) + + expected_result = self.v2_config + self.assertEqual(expected_result, actual_result) def test_get_keystone_config(self): """