From 1c83ae3a993229bfa2a7daaaf2dd3599977267dd Mon Sep 17 00:00:00 2001 From: Lukas Piwowarski Date: Mon, 5 Aug 2019 15:05:16 +0000 Subject: [PATCH] Replace os-client-config module by openstacksdk Because openstacksdk superseded os-client-config module, it is recommended to use this module instead. Story: 2002021 Task: 19662 Change-Id: I6f225416ff4791a00b04655614eb8f24bed8ae7b --- config_tempest/main.py | 25 +++++++++++-------- config_tempest/tests/test_config_tempest.py | 17 ++----------- doc/source/user/import.rst | 2 +- doc/source/user/usage.rst | 8 +++--- ...dule-by-openstacksdk-4a52d8c953d92a41.yaml | 5 ++++ requirements.txt | 2 +- 6 files changed, 28 insertions(+), 31 deletions(-) create mode 100644 releasenotes/notes/Replace-os_client_config-module-by-openstacksdk-4a52d8c953d92a41.yaml diff --git a/config_tempest/main.py b/config_tempest/main.py index e9b21d6d..b0a9ee5d 100755 --- a/config_tempest/main.py +++ b/config_tempest/main.py @@ -25,8 +25,8 @@ be discovered by the user. The file used here could be created by an installer, or manually if necessary. 3. Values provided in client's cloud config file or as an environment -variables, see documentation of os-client-config -https://docs.openstack.org/developer/os-client-config/ +variables, see documentation of openstacksdk +https://docs.openstack.org/openstacksdk/latest/ 4. Values provided on the command line. These override all other values. @@ -40,7 +40,7 @@ import os import six import sys -import os_client_config +import openstack from oslo_config import cfg from six.moves import configparser @@ -153,7 +153,7 @@ def set_options(conf, deployer_input, non_admin, image_path, overrides=[], 2. read a file provided by --deployer-input argument 3. read default DEPLOYER_INPUT if --no-deployer-input is False and no deployer_input was passed - 4. set values from client's config (os-client-config support) if provided + 4. set values from client's config (openstacksdk support) if provided 5. set overrides - may override values which were set in the steps above :param conf: TempestConf object @@ -216,7 +216,7 @@ def set_options(conf, deployer_input, non_admin, image_path, overrides=[], def get_arg_parser(): parser = argparse.ArgumentParser(__doc__) - cloud_config = os_client_config.OpenStackConfig() + cloud_config = openstack.config.OpenStackConfig() cloud_config.register_argparse_arguments(parser, sys.argv) parser.add_argument('--create', action='store_true', default=False, help="""Create Tempest resources @@ -444,7 +444,7 @@ def set_cloud_config_values(non_admin, cloud_creds, conf): Note: the values may be later overridden by values specified in CLI. :type non_admin: Boolean - :param cloud_creds: auth data from os-client-config + :param cloud_creds: auth data from openstacksdk :type cloud_creds: dict :param conf: TempestConf object """ @@ -488,12 +488,17 @@ def get_cloud_creds(args_namespace): 'auth_url': 'http://172.16.52.8:5000/v3', 'password': 'f0921edc3c2b4fc8', 'project_domain_name': 'Default'} """ - cloud = os_client_config.OpenStackConfig() - cloud = cloud.get_one_cloud(argparse=args_namespace) - cloud_creds = cloud.config.get('auth') - region_name = cloud.config.get('region_name') + if args_namespace.os_cloud: + cloud = openstack.connect(cloud=args_namespace.os_cloud) + else: + cloud = openstack.connect(argparse=args_namespace) + + cloud_creds = cloud.config.get_auth_args() + region_name = cloud.config.config['region_name'] + if region_name: cloud_creds['region_name'] = region_name + return cloud_creds diff --git a/config_tempest/tests/test_config_tempest.py b/config_tempest/tests/test_config_tempest.py index fa26f460..efbe3f81 100644 --- a/config_tempest/tests/test_config_tempest.py +++ b/config_tempest/tests/test_config_tempest.py @@ -39,16 +39,7 @@ class TestOsClientConfigSupport(BaseConfigTempestTest): self.assertEqual(exp_pass, password) self.assertEqual(exp_project, project_name) - @mock.patch('os_client_config.cloud_config.CloudConfig') - def _override_setup(self, mock_args): - cloud_args = { - 'username': 'cloud_user', - 'password': 'cloud_pass', - 'project_name': 'cloud_project' - } - mock_function = mock.Mock(return_value=cloud_args) - func2mock = 'os_client_config.cloud_config.CloudConfig.config.get' - self.useFixture(MonkeyPatch(func2mock, mock_function)) + def _override_setup(self): mock_function = mock.Mock(return_value={"id": "my_fake_id"}) func2mock = ('config_tempest.clients.ProjectsClient.' 'get_project_by_name') @@ -95,11 +86,7 @@ class TestOsClientConfigSupport(BaseConfigTempestTest): def test_init_manager_client_config_region_name(self): self._obtain_client_config_data(region_name='regionOne') - @mock.patch('os_client_config.cloud_config.CloudConfig') - def test_init_manager_client_config_get_default(self, mock_args): - mock_function = mock.Mock(return_value={}) - func2mock = 'os_client_config.cloud_config.CloudConfig.config.get' - self.useFixture(MonkeyPatch(func2mock, mock_function)) + def test_init_manager_client_config_get_default(self): manager = ClientManager(self.conf, self._get_creds(self.conf)) # cloud_args is empty => check if default credentials were used self._check_credentials(manager, diff --git a/doc/source/user/import.rst b/doc/source/user/import.rst index 4a3293b6..516d949f 100644 --- a/doc/source/user/import.rst +++ b/doc/source/user/import.rst @@ -28,7 +28,7 @@ Import ``python-tempestconf`` in your project as follows: ``python-tempestconf`` needs cloud credentials in order to create a tempest configuration file. There is a helper method for obtaining cloud credentials which uses -`os-client-config `_ +`openstacksdk `_ for parsing the cloud for credentials. The following example shows how to get cloud credentials and how to pass it to diff --git a/doc/source/user/usage.rst b/doc/source/user/usage.rst index 1aa7c8d9..4805de73 100644 --- a/doc/source/user/usage.rst +++ b/doc/source/user/usage.rst @@ -11,7 +11,7 @@ of the following: * source OpenStack RC file before running :command:`discover-tempest-config` command, see `Examples of usage with sourced credentials`_ - * use ``clouds.yaml`` file and take advantage of ``os-client-config`` support + * use ``clouds.yaml`` file and take advantage of ``openstacksdk`` support and use a named cloud, see `Examples of usage with a named cloud`_ If a user doesn't use ``--create``, no resources, which require admin @@ -48,7 +48,7 @@ step **as a prerequisite**: .. note:: Thanks to - `os-client-config `_ + `openstacksdk `_ support, ``python-tempestconf`` is able to read cloud credentials from the shell environment, which means, they **don't need** to be explicitly passed via CLI. @@ -249,11 +249,11 @@ Examples of usage with a named cloud ------------------------------------ ``python-tempestconf`` supports -`os-client-config `__ +`openstacksdk `__ so instead of sourcing an OpenStack RC file a user can use clouds.yml file. Location where this file should be stored and syntax which is used to define it can be found -`here `__ +`here `__ Let's say there is a ``clouds.yaml`` file located in ``/etc/openstack/`` with the following content: diff --git a/releasenotes/notes/Replace-os_client_config-module-by-openstacksdk-4a52d8c953d92a41.yaml b/releasenotes/notes/Replace-os_client_config-module-by-openstacksdk-4a52d8c953d92a41.yaml new file mode 100644 index 00000000..4ca8e6cf --- /dev/null +++ b/releasenotes/notes/Replace-os_client_config-module-by-openstacksdk-4a52d8c953d92a41.yaml @@ -0,0 +1,5 @@ +features: + - | + Openstacksdk module superseded os-client-config + module, therefore it is now used for parsing cloud + credentials instead of os-client-config module. diff --git a/requirements.txt b/requirements.txt index a46c41ee..7ca7002f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,6 +6,6 @@ pbr>=1.8 # Apache-2.0 six>=1.10.0 # MIT tempest>=14.0.0 # Apache-2.0 requests>=2.10.0,!=2.12.2 # Apache-2.0 -os-client-config>=1.26.0 # Apache-2.0 +openstacksdk>=0.11.3 # Apache-2.0 oslo.config>=3.23.0 # Apache-2.0 PyYAML>=3.12 # MIT