summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--nova/compute/manager.py8
-rw-r--r--nova/compute/utils.py13
-rw-r--r--nova/tests/compute/test_compute_utils.py12
3 files changed, 24 insertions, 9 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
index 564b2aa02..633c51843 100644
--- a/nova/compute/manager.py
+++ b/nova/compute/manager.py
@@ -1053,9 +1053,9 @@ 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'])
self.db.instance_destroy(context, instance_uuid)
- system_meta = self.db.instance_system_metadata_get(context,
- instance_uuid)
# ensure block device mappings are not leaked
self.conductor_api.block_device_mapping_destroy(context, bdms)
@@ -1542,8 +1542,8 @@ 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 = self.db.instance_system_metadata_get(
- context, instance['uuid'])
+ system_meta = compute_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 a0dfbea8d..8852cb820 100644
--- a/nova/compute/utils.py
+++ b/nova/compute/utils.py
@@ -37,6 +37,13 @@ CONF.import_opt('host', 'nova.config')
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_uuid, fault, exc_info=None):
"""Adds the specified fault to the database."""
@@ -153,11 +160,7 @@ def notify_usage_exists(context, instance_ref, current_period=False,
ignore_missing_network_data)
if system_metadata is None:
- try:
- system_metadata = db.instance_system_metadata_get(
- context, instance_ref['uuid'])
- except exception.NotFound:
- system_metadata = {}
+ system_metadata = metadata_to_dict(instance_ref['system_metadata'])
# add image metadata to the notification:
image_meta = notifications.image_meta(system_metadata)
diff --git a/nova/tests/compute/test_compute_utils.py b/nova/tests/compute/test_compute_utils.py
index b3f7ea3df..5acc1cc53 100644
--- a/nova/tests/compute/test_compute_utils.py
+++ b/nova/tests/compute/test_compute_utils.py
@@ -260,6 +260,7 @@ class UsageInfoTestCase(test.TestCase):
'other_data': 'meow'}
db.instance_system_metadata_update(self.context, instance['uuid'],
sys_metadata, False)
+ instance = db.instance_get(self.context, instance_id)
compute_utils.notify_usage_exists(self.context, instance)
self.assertEquals(len(test_notifier.NOTIFICATIONS), 1)
msg = test_notifier.NOTIFICATIONS[0]
@@ -378,3 +379,14 @@ class UsageInfoTestCase(test.TestCase):
image_ref_url = "%s/images/1" % utils.generate_glance_url()
self.assertEquals(payload['image_ref_url'], image_ref_url)
self.compute.terminate_instance(self.context, instance)
+
+
+class MetadataToDictTestCase(test.TestCase):
+ def test_metadata_to_dict(self):
+ self.assertEqual(compute_utils.metadata_to_dict(
+ [{'key': 'foo1', 'value': 'bar'},
+ {'key': 'foo2', 'value': 'baz'}]),
+ {'foo1': 'bar', 'foo2': 'baz'})
+
+ def test_metadata_to_dict_empty(self):
+ self.assertEqual(compute_utils.metadata_to_dict([]), {})