]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Add missing attributes to xml deserializer for volume request
authorStephen Mulcahy <stephen.mulcahy@hp.com>
Fri, 7 Jun 2013 11:52:11 +0000 (11:52 +0000)
committerStephen Mulcahy <stephen.mulcahy@hp.com>
Tue, 11 Jun 2013 07:40:01 +0000 (07:40 +0000)
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

cinder/api/v1/volumes.py
cinder/api/v2/volumes.py
cinder/tests/api/v1/test_volumes.py
cinder/tests/api/v2/test_volumes.py

index fa395b402e2d616e21ece8424b99354b84c467d2..83ff4be07ebe569afd93d5168ba899b2ebf6f4df 100644 (file)
@@ -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']
 
index 6ef8997a2ad41cb4a475068e512ab20ca3a9ebe6..6824ebad6019d49b7f1311251c6439b1150be323 100644 (file)
@@ -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']
 
index b199ca40e84489036e69c71d426163119d5c14d1..e321c96949d8c3a21186620abedf8078c9c7d016 100644 (file)
@@ -732,6 +732,60 @@ class TestVolumeCreateRequestXMLDeserializer(test.TestCase):
         }
         self.assertEquals(request['body'], expected)
 
+    def test_imageref(self):
+        self_request = """
+<volume xmlns="http://docs.openstack.org/volume/api/v1"
+        size="1"
+        display_name="Volume-xml"
+        display_description="description"
+        imageRef="4a90189d-d702-4c7c-87fc-6608c554d737"></volume>"""
+        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 = """
+<volume xmlns="http://docs.openstack.org/volume/api/v1"
+        size="1"
+        display_name="Volume-xml"
+        display_description="description"
+        snapshot_id="4a90189d-d702-4c7c-87fc-6608c554d737"></volume>"""
+        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 = """
+<volume xmlns="http://docs.openstack.org/volume/api/v1"
+        size="1"
+        display_name="Volume-xml"
+        display_description="description"
+        source_volid="4a90189d-d702-4c7c-87fc-6608c554d737"></volume>"""
+        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):
 
index 7264c30a4977e62c537c2cf2036ad2beae825b00..ed55adccc71d3c377ada55e44df96587231c3575 100644 (file)
@@ -963,3 +963,57 @@ class TestVolumeCreateRequestXMLDeserializer(test.TestCase):
             },
         }
         self.assertEquals(request['body'], expected)
+
+    def test_imageref(self):
+        self_request = """
+<volume xmlns="http://docs.openstack.org/api/openstack-volume/2.0/content"
+        size="1"
+        name="Volume-xml"
+        description="description"
+        imageRef="4a90189d-d702-4c7c-87fc-6608c554d737"></volume>"""
+        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 = """
+<volume xmlns="http://docs.openstack.org/api/openstack-volume/2.0/content"
+        size="1"
+        name="Volume-xml"
+        description="description"
+        snapshot_id="4a90189d-d702-4c7c-87fc-6608c554d737"></volume>"""
+        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 = """
+<volume xmlns="http://docs.openstack.org/api/openstack-volume/2.0/content"
+        size="1"
+        name="Volume-xml"
+        description="description"
+        source_volid="4a90189d-d702-4c7c-87fc-6608c554d737"></volume>"""
+        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'])