Skip to content

Commit

Permalink
Add missing attributes to xml deserializer for volume request
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Stephen Mulcahy committed Jun 11, 2013
1 parent f34aef3 commit 0ec5841
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 2 deletions.
4 changes: 3 additions & 1 deletion cinder/api/v1/volumes.py
Expand Up @@ -179,7 +179,8 @@ def _extract_volume(self, node):
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)
Expand Down Expand Up @@ -287,6 +288,7 @@ def create(self, req, body):
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']

Expand Down
4 changes: 3 additions & 1 deletion cinder/api/v2/volumes.py
Expand Up @@ -113,7 +113,8 @@ def _extract_volume(self, node):
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)
Expand Down Expand Up @@ -245,6 +246,7 @@ def create(self, req, body):
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']

Expand Down
54 changes: 54 additions & 0 deletions cinder/tests/api/v1/test_volumes.py
Expand Up @@ -732,6 +732,60 @@ def test_full_volume(self):
}
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):

Expand Down
54 changes: 54 additions & 0 deletions cinder/tests/api/v2/test_volumes.py
Expand Up @@ -963,3 +963,57 @@ def test_full_volume(self):
},
}
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'])

0 comments on commit 0ec5841

Please sign in to comment.