Add support of nova client microversion 2.60 84/13484/2
authorvegall <lvega@whitestack.com>
Thu, 1 Jun 2023 05:47:44 +0000 (00:47 -0500)
committervegall <lvega@whitestack.com>
Thu, 1 Jun 2023 22:20:41 +0000 (22:20 +0000)
Change-Id: I5ab566de7db67dc1e9665d7cb399be7af268ba6f
Signed-off-by: Gabriel Cuba <gcuba@whitestack.com>
Signed-off-by: vegall <lvega@whitestack.com>
RO-VIM-openstack/osm_rovim_openstack/tests/test_vimconn_openstack.py
RO-VIM-openstack/osm_rovim_openstack/vimconn_openstack.py
releasenotes/notes/support_nova_client_2.60-37f68440b154c9a6.yaml [new file with mode: 0644]

index 2e1ddc6..f022e7a 100644 (file)
@@ -117,6 +117,14 @@ class Volume:
         self.id = id
 
 
+class Server:
+    def __init__(self, name="", status="", flavor="", id=""):
+        self.id = id
+        self.name = name
+        self.status = status
+        self.flavor = flavor
+
+
 class CopyingMock(MagicMock):
     def __call__(self, *args, **kwargs):
         args = deepcopy(args)
@@ -5019,7 +5027,18 @@ class TestNewVmInstance(unittest.TestCase):
 
     @patch.object(vimconnector, "_reload_connection", new_callable=CopyingMock())
     def test_get_monitoring_data(self, mock_reload_conection):
-        servers = ["server1", "server2"]
+        flavors = [
+            {"original_name": "flavor1", "id": "367fc1eb-bd22-40f8-a519-ed2fb4e5976b"},
+            {"original_name": "flavor2", "id": "5dcf9732-d17d-40b3-910d-37fc4c5aacc0"},
+        ]
+        servers = [
+            Server(
+                "server1", "ACTIVE", flavors[0], "312200db-42e3-4772-9518-d5db85468392"
+            ),
+            Server(
+                "server2", "ACTIVE", flavors[1], "39a166cf-e4e6-479c-b88c-9ad558cf2cbf"
+            ),
+        ]
         ports = {"ports": ["port1", "port2"]}
         self.vimconn.nova.servers.list.return_value = servers
         self.vimconn.neutron.list_ports.return_value = ports
index bdee55d..7ce0ff7 100644 (file)
@@ -339,7 +339,7 @@ class vimconnector(vimconn.VimConnector):
             version = self.config.get("microversion")
 
             if not version:
-                version = "2.1"
+                version = "2.60"
 
             # addedd region_name to keystone, nova, neutron and cinder to support distributed cloud for Wind River
             # Titanium cloud and StarlingX
@@ -628,6 +628,31 @@ class vimconnector(vimconn.VimConnector):
                         "Not found security group {} for this tenant".format(sg)
                     )
 
+    def _find_nova_server(self, vm_id):
+        """
+        Returns the VM instance from Openstack and completes it with flavor ID
+        Do not call nova.servers.find directly, as it does not return flavor ID with microversion>=2.47
+        """
+        try:
+            self._reload_connection()
+            server = self.nova.servers.find(id=vm_id)
+            # TODO parse input and translate to VIM format (openmano_schemas.new_vminstance_response_schema)
+            server_dict = server.to_dict()
+            try:
+                server_dict["flavor"]["id"] = self.nova.flavors.find(
+                    name=server_dict["flavor"]["original_name"]
+                ).id
+            except nClient.exceptions.NotFound as e:
+                self.logger.warning(str(e.message))
+            return server_dict
+        except (
+            ksExceptions.ClientException,
+            nvExceptions.ClientException,
+            nvExceptions.NotFound,
+            ConnectionError,
+        ) as e:
+            self._format_exception(e)
+
     def check_vim_connectivity(self):
         # just get network list to check connectivity and credentials
         self.get_network_list(filter_dict={})
@@ -2857,20 +2882,7 @@ class vimconnector(vimconn.VimConnector):
 
     def get_vminstance(self, vm_id):
         """Returns the VM instance information from VIM"""
-        # self.logger.debug("Getting VM from VIM")
-        try:
-            self._reload_connection()
-            server = self.nova.servers.find(id=vm_id)
-            # TODO parse input and translate to VIM format (openmano_schemas.new_vminstance_response_schema)
-
-            return server.to_dict()
-        except (
-            ksExceptions.ClientException,
-            nvExceptions.ClientException,
-            nvExceptions.NotFound,
-            ConnectionError,
-        ) as e:
-            self._format_exception(e)
+        return self._find_nova_server(vm_id)
 
     def get_vminstance_console(self, vm_id, console_type="vnc"):
         """
@@ -3671,8 +3683,7 @@ class vimconnector(vimconn.VimConnector):
         self.logger.debug("Getting the status of VM")
         self.logger.debug("VIM VM ID %s", vm_id)
         self._reload_connection()
-        server = self.nova.servers.find(id=vm_id)
-        server_dict = server.to_dict()
+        server_dict = self._find_nova_server(vm_id)
         vdu_data = [
             server_dict["status"],
             server_dict["flavor"]["id"],
@@ -3885,6 +3896,13 @@ class vimconnector(vimconn.VimConnector):
             self.logger.debug("Getting servers and ports data from Openstack VIMs.")
             self._reload_connection()
             all_servers = self.nova.servers.list(detailed=True)
+            try:
+                for server in all_servers:
+                    server.flavor["id"] = self.nova.flavors.find(
+                        name=server.flavor["original_name"]
+                    ).id
+            except nClient.exceptions.NotFound as e:
+                self.logger.warning(str(e.message))
             all_ports = self.neutron.list_ports()
             return all_servers, all_ports
         except (
diff --git a/releasenotes/notes/support_nova_client_2.60-37f68440b154c9a6.yaml b/releasenotes/notes/support_nova_client_2.60-37f68440b154c9a6.yaml
new file mode 100644 (file)
index 0000000..86375e0
--- /dev/null
@@ -0,0 +1,22 @@
+#######################################################################################
+# 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.
+#######################################################################################
+---
+other:
+  - |
+    Add support of OpenStack Nova client microversion 2.60, by retrieving the flavor ID and 
+    adding it to the VM information.
+