summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2015-04-22 15:20:13 +0000
committerGerrit Code Review <review@openstack.org>2015-04-22 15:20:13 +0000
commit11401209ae20fc3e4fd8dc237cec4074549e5078 (patch)
tree1d0827746108e4c5ba65691df440b51b19eb875f
parent9006cfa664254234cec67b78328ae9124029b9f3 (diff)
parent51bfd201e888caecf8dbdce8c8999bfa8ed05a26 (diff)
downloadcinder-11401209ae20fc3e4fd8dc237cec4074549e5078.tar.gz
Merge "Include boot properties from glance v2 images" into stable/kilo
-rw-r--r--cinder/image/glance.py11
-rw-r--r--cinder/tests/image/test_glance.py57
2 files changed, 68 insertions, 0 deletions
diff --git a/cinder/image/glance.py b/cinder/image/glance.py
index 5b9c85ed1..9bef05bf7 100644
--- a/cinder/image/glance.py
+++ b/cinder/image/glance.py
@@ -449,6 +449,17 @@ def _extract_attributes(image):
output['properties'] = getattr(image, 'properties', {})
+ # NOTE(jbernard): Update image properties for API version 2. For UEC
+ # images stored in glance, the necessary boot information is stored in the
+ # properties dict in version 1 so there is nothing more to do. However, in
+ # version 2 these are standalone fields in the GET response. This bit of
+ # code moves them back into the properties dict as the caller expects, thus
+ # producing a volume with correct metadata for booting.
+ for attr in ('kernel_id', 'ramdisk_id'):
+ value = getattr(image, attr, None)
+ if value:
+ output['properties'][attr] = value
+
return output
diff --git a/cinder/tests/image/test_glance.py b/cinder/tests/image/test_glance.py
index f4f9ee150..1fa518ff9 100644
--- a/cinder/tests/image/test_glance.py
+++ b/cinder/tests/image/test_glance.py
@@ -584,6 +584,63 @@ class TestGlanceImageService(test.TestCase):
}
self.assertEqual(actual, expected)
+ @mock.patch('cinder.image.glance.CONF')
+ def test_extracting_v2_boot_properties(self, config):
+
+ config.glance_api_version = 2
+
+ attributes = ['size', 'disk_format', 'owner', 'container_format',
+ 'checksum', 'id', 'name', 'created_at', 'updated_at',
+ 'deleted', 'status', 'min_disk', 'min_ram', 'is_public']
+
+ metadata = {
+ 'id': 1,
+ 'size': 2,
+ 'min_disk': 2,
+ 'min_ram': 2,
+ 'kernel_id': 'foo',
+ 'ramdisk_id': 'bar',
+ }
+
+ class FakeSchema(object):
+
+ def __init__(self, base):
+ self.base = base
+
+ def is_base_property(self, key):
+ if key in self.base:
+ return True
+ else:
+ return False
+
+ image = glance_stubs.FakeImage(metadata)
+ client = glance_stubs.StubGlanceClient()
+
+ service = self._create_image_service(client)
+ service._image_schema = FakeSchema(attributes)
+ actual = service._translate_from_glance(image)
+ expected = {
+ 'id': 1,
+ 'name': None,
+ 'is_public': None,
+ 'size': 2,
+ 'min_disk': 2,
+ 'min_ram': 2,
+ 'disk_format': None,
+ 'container_format': None,
+ 'checksum': None,
+ 'deleted': None,
+ 'deleted_at': None,
+ 'status': None,
+ 'properties': {'kernel_id': 'foo',
+ 'ramdisk_id': 'bar'},
+ 'owner': None,
+ 'created_at': None,
+ 'updated_at': None
+ }
+
+ self.assertEqual(expected, actual)
+
class TestGlanceClientVersion(test.TestCase):
"""Tests the version of the glance client generated."""