From: Stephen Mulcahy Date: Fri, 7 Jun 2013 11:52:11 +0000 (+0000) Subject: Add missing attributes to xml deserializer for volume request X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=0ec58418103f5097ba3bb0ce0e45fe890be12c2e;p=openstack-build%2Fcinder-build.git Add missing attributes to xml deserializer for volume request The v1 and v2 xml deserializers for volume requests are missing support for the imageRef, snapshot_id and source_volid attributes resulting in xml format create volume requests which specify any of those attributes being silently ignored. This fix adds support to v1 and v2 and extends the volumes unit tests to check for this. Also includes some minor debug logging enhancements to make this easier to find in future. Fixes bug #1188581 Change-Id: Ib661c4a961c57e682e0e4e6db98d863b3a99cf71 --- diff --git a/cinder/api/v1/volumes.py b/cinder/api/v1/volumes.py index fa395b402..83ff4be07 100644 --- a/cinder/api/v1/volumes.py +++ b/cinder/api/v1/volumes.py @@ -179,7 +179,8 @@ class CommonDeserializer(wsgi.MetadataXMLDeserializer): volume_node = self.find_first_child_named(node, 'volume') attributes = ['display_name', 'display_description', 'size', - 'volume_type', 'availability_zone'] + 'volume_type', 'availability_zone', 'imageRef', + 'snapshot_id', 'source_volid'] for attr in attributes: if volume_node.getAttribute(attr): volume[attr] = volume_node.getAttribute(attr) @@ -287,6 +288,7 @@ class VolumeController(wsgi.Controller): if not self.is_valid_body(body, 'volume'): raise exc.HTTPUnprocessableEntity() + LOG.debug('Create volume request body: %s', body) context = req.environ['cinder.context'] volume = body['volume'] diff --git a/cinder/api/v2/volumes.py b/cinder/api/v2/volumes.py index 6ef8997a2..6824ebad6 100644 --- a/cinder/api/v2/volumes.py +++ b/cinder/api/v2/volumes.py @@ -113,7 +113,8 @@ class CommonDeserializer(wsgi.MetadataXMLDeserializer): volume_node = self.find_first_child_named(node, 'volume') attributes = ['name', 'description', 'size', - 'volume_type', 'availability_zone'] + 'volume_type', 'availability_zone', 'imageRef', + 'snapshot_id', 'source_volid'] for attr in attributes: if volume_node.getAttribute(attr): volume[attr] = volume_node.getAttribute(attr) @@ -245,6 +246,7 @@ class VolumeController(wsgi.Controller): if not self.is_valid_body(body, 'volume'): raise exc.HTTPBadRequest() + LOG.debug('Create volume request body: %s', body) context = req.environ['cinder.context'] volume = body['volume'] diff --git a/cinder/tests/api/v1/test_volumes.py b/cinder/tests/api/v1/test_volumes.py index b199ca40e..e321c9694 100644 --- a/cinder/tests/api/v1/test_volumes.py +++ b/cinder/tests/api/v1/test_volumes.py @@ -732,6 +732,60 @@ class TestVolumeCreateRequestXMLDeserializer(test.TestCase): } self.assertEquals(request['body'], expected) + def test_imageref(self): + self_request = """ +""" + request = self.deserializer.deserialize(self_request) + expected = { + "volume": { + "size": "1", + "display_name": "Volume-xml", + "display_description": "description", + "imageRef": "4a90189d-d702-4c7c-87fc-6608c554d737", + }, + } + self.assertEquals(expected, request['body']) + + def test_snapshot_id(self): + self_request = """ +""" + request = self.deserializer.deserialize(self_request) + expected = { + "volume": { + "size": "1", + "display_name": "Volume-xml", + "display_description": "description", + "snapshot_id": "4a90189d-d702-4c7c-87fc-6608c554d737", + }, + } + self.assertEquals(expected, request['body']) + + def test_source_volid(self): + self_request = """ +""" + request = self.deserializer.deserialize(self_request) + expected = { + "volume": { + "size": "1", + "display_name": "Volume-xml", + "display_description": "description", + "source_volid": "4a90189d-d702-4c7c-87fc-6608c554d737", + }, + } + self.assertEquals(expected, request['body']) + class VolumesUnprocessableEntityTestCase(test.TestCase): diff --git a/cinder/tests/api/v2/test_volumes.py b/cinder/tests/api/v2/test_volumes.py index 7264c30a4..ed55adccc 100644 --- a/cinder/tests/api/v2/test_volumes.py +++ b/cinder/tests/api/v2/test_volumes.py @@ -963,3 +963,57 @@ class TestVolumeCreateRequestXMLDeserializer(test.TestCase): }, } self.assertEquals(request['body'], expected) + + def test_imageref(self): + self_request = """ +""" + request = self.deserializer.deserialize(self_request) + expected = { + "volume": { + "size": "1", + "name": "Volume-xml", + "description": "description", + "imageRef": "4a90189d-d702-4c7c-87fc-6608c554d737", + }, + } + self.assertEquals(expected, request['body']) + + def test_snapshot_id(self): + self_request = """ +""" + request = self.deserializer.deserialize(self_request) + expected = { + "volume": { + "size": "1", + "name": "Volume-xml", + "description": "description", + "snapshot_id": "4a90189d-d702-4c7c-87fc-6608c554d737", + }, + } + self.assertEquals(expected, request['body']) + + def test_source_volid(self): + self_request = """ +""" + request = self.deserializer.deserialize(self_request) + expected = { + "volume": { + "size": "1", + "name": "Volume-xml", + "description": "description", + "source_volid": "4a90189d-d702-4c7c-87fc-6608c554d737", + }, + } + self.assertEquals(expected, request['body'])