Skip to content

Commit

Permalink
Extract image metadata from Cinder
Browse files Browse the repository at this point in the history
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
  • Loading branch information
djipko committed Dec 19, 2012
1 parent 420e051 commit fb32f1e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
18 changes: 18 additions & 0 deletions nova/tests/test_cinder.py
Expand Up @@ -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):

Expand Down Expand Up @@ -82,6 +87,13 @@ def get_volumes_1234(self, **kw):
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):

Expand Down Expand Up @@ -155,3 +167,9 @@ def test_cinder_endpoint_template(self):
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)
4 changes: 4 additions & 0 deletions nova/volume/cinder.py
Expand Up @@ -20,6 +20,7 @@
Handles all requests relating to volumes + cinder.
"""

from copy import deepcopy
import sys

from cinderclient import exceptions as cinder_exception
Expand Down Expand Up @@ -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


Expand Down

0 comments on commit fb32f1e

Please sign in to comment.