From e2f2d10e1a59a6688c6f9763fff0fd45578da5eb Mon Sep 17 00:00:00 2001 From: Russell Bryant Date: Wed, 23 Jan 2013 17:34:13 -0500 Subject: Avoid db lookup in info_from_instance(). The method info_from_instance() in nova.notifications was doing a db lookup for the system_metadata for an instance. This patch updates that code to get that data from the instance that's passed in instead. The rest of the patch are related changes to make that happen. metadata_to_dict() was needed here. It lived in nova.compute.utils. nova.compute.utils already imported nova.notifications, so using it from there would have created a circular import. Move the method to nova.utils instead and update the tree to use it from its new location. I also noticed that the xen driver had a copy of metdata_to_dict(). This patch removes it and uses the common implementation in nova.utils. 'system_metadata' was added to _extra_keys of the Instance db model so that it would show up in a serialized instance. Tests failed without it as the result of getting instances via the conductor API did not include system_metadata. Now it's there. Part of bp no-db-compute. Change-Id: I451355fb26ae29f13b71438f7896c448b59f97b0 --- nova/compute/manager.py | 6 ++---- nova/compute/utils.py | 10 ++-------- 2 files changed, 4 insertions(+), 12 deletions(-) (limited to 'nova/compute') diff --git a/nova/compute/manager.py b/nova/compute/manager.py index d1cffea7d..275611cdf 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -1132,8 +1132,7 @@ class ComputeManager(manager.SchedulerDependentManager): vm_state=vm_states.DELETED, task_state=None, terminated_at=timeutils.utcnow()) - system_meta = compute_utils.metadata_to_dict( - instance['system_metadata']) + system_meta = utils.metadata_to_dict(instance['system_metadata']) self.conductor_api.instance_destroy(context, instance) # ensure block device mappings are not leaked @@ -1675,8 +1674,7 @@ class ComputeManager(manager.SchedulerDependentManager): def _get_rescue_image_ref(self, context, instance): """Determine what image should be used to boot the rescue VM.""" - system_meta = compute_utils.metadata_to_dict( - instance['system_metadata']) + system_meta = utils.metadata_to_dict(instance['system_metadata']) rescue_image_ref = system_meta.get('image_base_image_ref') diff --git a/nova/compute/utils.py b/nova/compute/utils.py index 2b1286e16..1874e886f 100644 --- a/nova/compute/utils.py +++ b/nova/compute/utils.py @@ -37,13 +37,6 @@ CONF.import_opt('host', 'nova.netconf') LOG = log.getLogger(__name__) -def metadata_to_dict(metadata): - result = {} - for item in metadata: - result[item['key']] = item['value'] - return result - - def add_instance_fault_from_exc(context, instance, fault, exc_info=None): """Adds the specified fault to the database.""" @@ -159,7 +152,8 @@ def notify_usage_exists(context, instance_ref, current_period=False, ignore_missing_network_data) if system_metadata is None: - system_metadata = metadata_to_dict(instance_ref['system_metadata']) + system_metadata = utils.metadata_to_dict( + instance_ref['system_metadata']) # add image metadata to the notification: image_meta = notifications.image_meta(system_metadata) -- cgit