From 95763cdb0557aefd165487847d2f82f7fcf978f9 Mon Sep 17 00:00:00 2001 From: Kiran Pawar Date: Tue, 21 Feb 2023 11:03:51 +0000 Subject: [PATCH] Use suitable api version for OSC. In manilaclient i.e. manila commands, if user supplied version is above the max version supported by server, manilaclient adjust to max version. This was missing in openstack commands which results in failure that version is not supported. Fix by discovering most suitable version and use it for client creation. Closes-bug: #1960490 Change-Id: I734f6953e8b0266b38f0cb6e1581c4201f2bd676 --- manilaclient/osc/plugin.py | 48 +++++++++++-------- ...able-version-for-osc-b375a32273b56522.yaml | 7 +++ 2 files changed, 35 insertions(+), 20 deletions(-) create mode 100644 releasenotes/notes/bug-1960490-use-suitable-version-for-osc-b375a32273b56522.yaml diff --git a/manilaclient/osc/plugin.py b/manilaclient/osc/plugin.py index 5f088fe2c..568b2f3fd 100644 --- a/manilaclient/osc/plugin.py +++ b/manilaclient/osc/plugin.py @@ -20,6 +20,7 @@ import logging from osc_lib import utils from manilaclient import api_versions +from manilaclient import client from manilaclient.common import constants from manilaclient import exceptions @@ -60,35 +61,42 @@ def make_client(instance): """Returns a shared file system service client.""" requested_api_version = instance._api_version[API_NAME] - shared_file_system_client = utils.get_client_class( - API_NAME, requested_api_version, API_VERSIONS) + service_type, manila_endpoint_url = _get_manila_url_from_service_catalog( + instance) + instance.setup_auth() + debugging_enabled = instance._cli_options.debug + + client_args = dict(session=instance.session, + service_catalog_url=manila_endpoint_url, + endpoint_type=instance.interface, + region_name=instance.region_name, + service_type=service_type, + auth=instance.auth, + http_log_debug=debugging_enabled, + cacert=instance.cacert, + cert=instance.cert, + insecure=not instance.verify) # Cast the API version into an object for further processing requested_api_version = api_versions.APIVersion( version_str=requested_api_version) + max_version = api_versions.APIVersion(api_versions.MAX_VERSION) + client_args.update(dict(api_version=max_version)) + temp_client = client.Client(max_version, **client_args) + discovered_version = api_versions.discover_version(temp_client, + requested_api_version) + + shared_file_system_client = utils.get_client_class( + API_NAME, discovered_version.get_string(), API_VERSIONS) + LOG.debug('Instantiating Shared File System (share) client: %s', shared_file_system_client) LOG.debug('Shared File System API version: %s', - requested_api_version) + discovered_version) - service_type, manila_endpoint_url = _get_manila_url_from_service_catalog( - instance) - - instance.setup_auth() - debugging_enabled = instance._cli_options.debug - client = shared_file_system_client(session=instance.session, - service_catalog_url=manila_endpoint_url, - endpoint_type=instance.interface, - region_name=instance.region_name, - service_type=service_type, - auth=instance.auth, - http_log_debug=debugging_enabled, - api_version=requested_api_version, - cacert=instance.cacert, - cert=instance.cert, - insecure=not instance.verify) - return client + client_args.update(dict(api_version=discovered_version)) + return shared_file_system_client(**client_args) def build_option_parser(parser): diff --git a/releasenotes/notes/bug-1960490-use-suitable-version-for-osc-b375a32273b56522.yaml b/releasenotes/notes/bug-1960490-use-suitable-version-for-osc-b375a32273b56522.yaml new file mode 100644 index 000000000..6975e7f3e --- /dev/null +++ b/releasenotes/notes/bug-1960490-use-suitable-version-for-osc-b375a32273b56522.yaml @@ -0,0 +1,7 @@ +--- +fixes: + - | + The OpenStackClient plugin will now use most suitable version for + openstack commmands client generation if user supplied version is above + max version supported by server. For more details, please refer `Launchpad + bug #1960490 `_