From 6bb4321087a13d7554fb69a7fbca7215fc108721 Mon Sep 17 00:00:00 2001 From: Lingxian Kong Date: Tue, 15 Jan 2019 15:33:52 +1300 Subject: [PATCH] Fix the KeyError for getting the volume types Change-Id: I6e4499a32702f950710ab951aa90f305d9e3e9e1 --- distil/common/openstack.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/distil/common/openstack.py b/distil/common/openstack.py index 40a1c10..f72ca95 100644 --- a/distil/common/openstack.py +++ b/distil/common/openstack.py @@ -12,6 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. +from collections import defaultdict import re from ceilometerclient import client as ceilometerclient @@ -28,7 +29,7 @@ from distil.common import general CONF = cfg.CONF KS_SESSION = None -cache = {} +cache = defaultdict(list) ROOT_DEVICE_PATTERN = re.compile('^/dev/(x?v|s|h)da1?$') @@ -136,7 +137,7 @@ def get_root_volume(instance_id): @general.disable_ssl_warnings def get_volume_type(volume_type): - if not cache['volume_types']: + if not cache.get("volume_types"): cinder = get_cinder_client() for vtype in cinder.volume_types.list(): cache['volume_types'].append({'id': vtype.id, 'name': vtype.name})