From 60e3a015722b313e7e736d3378befdabb5ee3ef5 Mon Sep 17 00:00:00 2001 From: Tetsuro Nakamura Date: Sun, 1 Jul 2018 20:46:56 +0900 Subject: [PATCH] Support nova compute-api microversion '2.53' Nova has changed the '/os-hypervisors' API to return compute host UUIDs instead of internal ids since version 2.53 [1]. However, if version 2.53 is set for the nova_client_version option in blazar.conf, an internal server error is caused when creating a host because the nova client exception has been changed from NotFound to BadRequest since that version. This patch solves the problem by handling both exceptions. [1] https://developer.openstack.org/api-ref/compute/#list-hypervisors Change-Id: I67718490a07ee2edf05d043755dcc02fda3516a9 Closes-Bug: #1780738 --- blazar/utils/openstack/nova.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/blazar/utils/openstack/nova.py b/blazar/utils/openstack/nova.py index 5c66bc64..91fd6a00 100644 --- a/blazar/utils/openstack/nova.py +++ b/blazar/utils/openstack/nova.py @@ -441,12 +441,18 @@ class NovaInventory(NovaClientWrapper): def get_host_details(self, host): """Get Nova capabilities of a single host - :param host: UUID or name of nova-compute host + :param host: UUID, ID or name of nova-compute host :return: Dict of capabilities or raise HostNotFound """ try: + # NOTE(tetsuro): Only id (microversion < 2.53) or uuid + # (microversion >= 2.53) is acceptable for the + # `novaclient.hypervisors.get` argument. The invalid arguments + # result in NotFound exception for microversion < 2.53 and + # BadRequest exception for microversion >= 2.53 hypervisor = self.nova.hypervisors.get(host) - except nova_exception.NotFound: + except (nova_exception.NotFound, nova_exception.BadRequest): + # Name (not id or uuid) is given for the `host` parameter. try: hypervisors_list = self.nova.hypervisors.search(host) except nova_exception.NotFound: @@ -468,12 +474,15 @@ class NovaInventory(NovaClientWrapper): az_name = zone.zoneName try: + # NOTE(tetsuro): compute API microversion 2.28 changes cpu_info + # from string to object + cpu_info = str(hypervisor.cpu_info) return {'id': hypervisor.id, 'availability_zone': az_name, 'hypervisor_hostname': hypervisor.hypervisor_hostname, 'service_name': hypervisor.service['host'], 'vcpus': hypervisor.vcpus, - 'cpu_info': hypervisor.cpu_info, + 'cpu_info': cpu_info, 'hypervisor_type': hypervisor.hypervisor_type, 'hypervisor_version': hypervisor.hypervisor_version, 'memory_mb': hypervisor.memory_mb,