From 96164cecc6b7bf447d06896f723dab416e63ee06 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Fri, 10 May 2013 15:34:00 -0700 Subject: [PATCH] Make a few places tolerant of sys_meta being a dict This will be necessary as we start to introduce objects with real dicts in system_metadata. These are the common spots that need to be ready ahead of time. The rest are at the actual use sites and can/will be replaced when individual uses are converted to objects. Related to bp/unified-internal-objects Change-Id: I8314e0d52ec2ae800765f60ce58ce9b309d7d513 --- nova/compute/flavors.py | 2 +- nova/notifications.py | 3 +-- nova/utils.py | 7 +++++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/nova/compute/flavors.py b/nova/compute/flavors.py index 58dcd3fa5af..7177f26bdf2 100644 --- a/nova/compute/flavors.py +++ b/nova/compute/flavors.py @@ -238,7 +238,7 @@ def extract_instance_type(instance, prefix=''): information.""" instance_type = {} - sys_meta = utils.metadata_to_dict(instance['system_metadata']) + sys_meta = utils.instance_sys_meta(instance) for key, type_fn in system_metadata_instance_type_props.items(): type_key = '%sinstance_type_%s' % (prefix, key) instance_type[key] = type_fn(sys_meta[type_key]) diff --git a/nova/notifications.py b/nova/notifications.py index 4442d99045b..2e5e7660db0 100644 --- a/nova/notifications.py +++ b/nova/notifications.py @@ -288,8 +288,7 @@ def null_safe_str(s): instance_type_name = instance_type.get('name', '') if system_metadata is None: - system_metadata = utils.metadata_to_dict( - instance_ref['system_metadata']) + system_metadata = utils.instance_sys_meta(instance_ref) instance_info = dict( # Owner properties diff --git a/nova/utils.py b/nova/utils.py index 3e9d8c597ed..97551e8eb9a 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -1032,6 +1032,13 @@ def dict_to_metadata(metadata): return result +def instance_sys_meta(instance): + if isinstance(instance['system_metadata'], dict): + return instance['system_metadata'] + else: + return metadata_to_dict(instance['system_metadata']) + + def get_wrapped_function(function): """Get the method at the bottom of a stack of decorators.""" if not hasattr(function, 'func_closure') or not function.func_closure: