From 08b8a46e8eee069b975e7a98ced823c4f5d923e3 Mon Sep 17 00:00:00 2001
From: garciadeblas <gerardo.garciadeblas@telefonica.com>
Date: Thu, 28 Nov 2024 17:46:13 +0100
Subject: [PATCH] Fix cinder client initialization vimconn_openstack

This commit changes the setup of cinder client version, trying first
version v3 if the service exists, instead of the default client which
was v2.

Change-Id: I9c63a0d3a5fa44597d633cc5db79ae0a783c66ff
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
---
 .../osm_rovim_openstack/vimconn_openstack.py  | 20 ++++++++++++++--
 ...lient_initialization-802020147bc03b26.yaml | 23 +++++++++++++++++++
 2 files changed, 41 insertions(+), 2 deletions(-)
 create mode 100644 releasenotes/notes/fix_cinder_client_initialization-802020147bc03b26.yaml

diff --git a/RO-VIM-openstack/osm_rovim_openstack/vimconn_openstack.py b/RO-VIM-openstack/osm_rovim_openstack/vimconn_openstack.py
index 2017d563..9f7499c6 100644
--- a/RO-VIM-openstack/osm_rovim_openstack/vimconn_openstack.py
+++ b/RO-VIM-openstack/osm_rovim_openstack/vimconn_openstack.py
@@ -314,17 +314,19 @@ class vimconnector(vimconn.VimConnector):
                 )
 
             sess = session.Session(auth=auth, verify=self.verify)
-            # addedd region_name to keystone, nova, neutron and cinder to support distributed cloud for Wind River
+            # added region_name to keystone, nova, neutron and cinder to support distributed cloud for Wind River
             # Titanium cloud and StarlingX
             region_name = self.config.get("region_name")
 
             if self.api_version3:
+                self.logger.debug(f"Using Keystone client v3 for VIM {self.id}")
                 self.keystone = ksClient_v3.Client(
                     session=sess,
                     endpoint_type=self.endpoint_type,
                     region_name=region_name,
                 )
             else:
+                self.logger.debug(f"Using Keystone client v2 for VIM {self.id}")
                 self.keystone = ksClient_v2.Client(
                     session=sess, endpoint_type=self.endpoint_type
                 )
@@ -356,7 +358,18 @@ class vimconnector(vimconn.VimConnector):
                 region_name=region_name,
             )
 
-            if sess.get_all_version_data(service_type="volumev2"):
+            if sess.get_all_version_data(service_type="volumev3"):
+                self.logger.debug(f"Using Cinder client v3 for VIM {self.id}")
+                self.cinder = self.session["cinder"] = cClient.Client(
+                    3,
+                    session=sess,
+                    endpoint_type=self.endpoint_type,
+                    region_name=region_name,
+                )
+            elif sess.get_all_version_data(service_type="volumev2"):
+                self.logger.debug(
+                    f"Service type volumev3 not found. Using Cinder client v2 for VIM {self.id}"
+                )
                 self.cinder = self.session["cinder"] = cClient.Client(
                     2,
                     session=sess,
@@ -364,6 +377,9 @@ class vimconnector(vimconn.VimConnector):
                     region_name=region_name,
                 )
             else:
+                self.logger.debug(
+                    f"Service type not found. Using Cinder client v3 for VIM {self.id}"
+                )
                 self.cinder = self.session["cinder"] = cClient.Client(
                     3,
                     session=sess,
diff --git a/releasenotes/notes/fix_cinder_client_initialization-802020147bc03b26.yaml b/releasenotes/notes/fix_cinder_client_initialization-802020147bc03b26.yaml
new file mode 100644
index 00000000..3111b959
--- /dev/null
+++ b/releasenotes/notes/fix_cinder_client_initialization-802020147bc03b26.yaml
@@ -0,0 +1,23 @@
+#######################################################################################
+# Copyright ETSI Contributors and Others.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#######################################################################################
+---
+fixes:
+  - |
+    This commit changes the setup of cinder client version, trying first version
+    v3 if the service exists in Openstack, instead of the default client which
+    was v2. In that way, the highest available cinder client version will be used.
+
-- 
GitLab