summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikola Dipanov <ndipanov@redhat.com>2012-12-19 16:23:30 +0100
committerNikola Dipanov <ndipanov@redhat.com>2012-12-19 18:25:52 +0100
commitfb32f1ed9be3e4f2f46d5aea405c62ef21397640 (patch)
treeee807eaaec45e10000696a1a48a0b4b32bf2d6c1
parent420e0518c37a4eafb54509e5b4abd692b1caa055 (diff)
downloadnova-fb32f1ed9be3e4f2f46d5aea405c62ef21397640.tar.gz
nova-fb32f1ed9be3e4f2f46d5aea405c62ef21397640.tar.xz
nova-fb32f1ed9be3e4f2f46d5aea405c62ef21397640.zip
Extract image metadata from Cinder
This patch makes nova extract image metadata if it is present in the volume dict received from Cinder API. The volume image metadata is received from Cinder when the volume_image_metadata Cinder extension is loaded. This patch is part of the work done on blueprint improve-boot-from-volume as this metadata will be used when booting instances from volumes without the need to supply an image just for the metadata. Subsequent patches will make Nova consider this metadata when booting instances without and image id. Change-Id: I9e5925ea4147a41c41f9019933a47c5ccf756747
-rw-r--r--nova/tests/test_cinder.py18
-rw-r--r--nova/volume/cinder.py4
2 files changed, 22 insertions, 0 deletions
diff --git a/nova/tests/test_cinder.py b/nova/tests/test_cinder.py
index 11d29a3ff..dfdd4f3d7 100644
--- a/nova/tests/test_cinder.py
+++ b/nova/tests/test_cinder.py
@@ -42,6 +42,11 @@ def _stub_volume(**kwargs):
volume.update(kwargs)
return volume
+_image_metadata = {
+ 'kernel_id': 'fake',
+ 'ramdisk_id': 'fake'
+}
+
class FakeHTTPClient(cinder.cinder_client.client.HTTPClient):
@@ -82,6 +87,13 @@ class FakeHTTPClient(cinder.cinder_client.client.HTTPClient):
def get_volumes_nonexisting(self, **kw):
raise cinder_exception.NotFound(code=404, message='Resource not found')
+ def get_volumes_5678(self, **kw):
+ """Volume with image metadata"""
+ volume = {'volume': _stub_volume(id='1234',
+ volume_image_metadata=_image_metadata)
+ }
+ return (200, volume)
+
class FakeCinderClient(cinder.cinder_client.Client):
@@ -155,3 +167,9 @@ class CinderTestCase(test.TestCase):
def test_get_non_existing_volume(self):
self.assertRaises(exception.VolumeNotFound, self.api.get, self.context,
'nonexisting')
+
+ def test_volume_with_image_metadata(self):
+ volume = self.api.get(self.context, '5678')
+ self.assert_called('GET', '/volumes/5678')
+ self.assertTrue('volume_image_metadata' in volume)
+ self.assertEqual(volume['volume_image_metadata'], _image_metadata)
diff --git a/nova/volume/cinder.py b/nova/volume/cinder.py
index 1b8305505..04c151d1e 100644
--- a/nova/volume/cinder.py
+++ b/nova/volume/cinder.py
@@ -20,6 +20,7 @@
Handles all requests relating to volumes + cinder.
"""
+from copy import deepcopy
import sys
from cinderclient import exceptions as cinder_exception
@@ -117,6 +118,9 @@ def _untranslate_volume_summary_view(context, vol):
item['value'] = value
d['volume_metadata'].append(item)
+ if hasattr(vol, 'volume_image_metadata'):
+ d['volume_image_metadata'] = deepcopy(vol.volume_image_metadata)
+
return d