From c53829da297cc23e651d4ac97e1b847db67099bb Mon Sep 17 00:00:00 2001 From: vegall Date: Thu, 1 Jun 2023 00:47:44 -0500 Subject: [PATCH] Add support of nova client microversion 2.60 Change-Id: I5ab566de7db67dc1e9665d7cb399be7af268ba6f Signed-off-by: Gabriel Cuba Signed-off-by: vegall --- .../tests/test_vimconn_openstack.py | 21 +++++++- .../osm_rovim_openstack/vimconn_openstack.py | 52 +++++++++++++------ ...ort_nova_client_2.60-37f68440b154c9a6.yaml | 22 ++++++++ 3 files changed, 77 insertions(+), 18 deletions(-) create mode 100644 releasenotes/notes/support_nova_client_2.60-37f68440b154c9a6.yaml diff --git a/RO-VIM-openstack/osm_rovim_openstack/tests/test_vimconn_openstack.py b/RO-VIM-openstack/osm_rovim_openstack/tests/test_vimconn_openstack.py index 2e1ddc6a..f022e7a5 100644 --- a/RO-VIM-openstack/osm_rovim_openstack/tests/test_vimconn_openstack.py +++ b/RO-VIM-openstack/osm_rovim_openstack/tests/test_vimconn_openstack.py @@ -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 diff --git a/RO-VIM-openstack/osm_rovim_openstack/vimconn_openstack.py b/RO-VIM-openstack/osm_rovim_openstack/vimconn_openstack.py index bdee55d7..7ce0ff78 100644 --- a/RO-VIM-openstack/osm_rovim_openstack/vimconn_openstack.py +++ b/RO-VIM-openstack/osm_rovim_openstack/vimconn_openstack.py @@ -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 index 00000000..86375e0e --- /dev/null +++ b/releasenotes/notes/support_nova_client_2.60-37f68440b154c9a6.yaml @@ -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. + -- 2.25.1