From ac3dc8d9fe6fde971c8a4442a4bf6272392c4464 Mon Sep 17 00:00:00 2001 From: "Dr. Jens Harbott" Date: Thu, 17 Mar 2022 12:05:24 +0100 Subject: [PATCH] Fix flavor handling for openstacksdk 1.0 The newest openstacksdk release returns an object of type Flavor instead of a dict, which does have an id field, but that might not correspond to an existing flavor, so we cannot find it in our cache. Check for the presence of the attributes that we really need and as a last resort skip quota calculation instead of failing. Signed-off-by: Dr. Jens Harbott Change-Id: I09b03916598ff147d4be210a27a59799c23a2041 --- nodepool/driver/openstack/provider.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/nodepool/driver/openstack/provider.py b/nodepool/driver/openstack/provider.py index a4c8cedb6..ed7360c2d 100755 --- a/nodepool/driver/openstack/provider.py +++ b/nodepool/driver/openstack/provider.py @@ -135,14 +135,18 @@ class OpenStackProvider(Provider, QuotaSupport): # It has not leaked. continue - # In earlier versions of nova, flavor is an id. In later versions - # it returns the information we're looking for. If we get the - # information, we do not have to attempt to look up the ram or - # vcpus. - if hasattr(server.flavor, 'id'): - flavor = flavors.get(server.flavor.id) - else: + # In earlier versions of nova or the sdk, flavor has just an id. + # In later versions it returns the information we're looking for. + # If we get the information we want, we do not need to try to + # lookup the flavor in our list. + if hasattr(server.flavor, 'vcpus'): flavor = server.flavor + else: + flavor = flavors.get(server.flavor.id) + # If we still haven't found the flavor, skip handling this + # server instead of failing completely + if not flavor: + continue used_quota.add(QuotaInformation.construct_from_flavor(flavor)) return used_quota