Fix HostDeserializer to enable multiple line xml
Fixes bug: 1082132 The current HostDeserializer wasn't able to deal with multiple line xml inputs. Since the HostDeserializer is used only on the update operation this patch renames it to HostUpdateDeserializer, and parses only the valid options (status and maintenance_mode). Change-Id: I9ec3b296a07e0fc903da1c005cf7bd5dcb08fd1b
This commit is contained in:
parent
e6ba5845cd
commit
f58f2b48a1
@ -70,7 +70,7 @@ class HostShowTemplate(xmlutil.TemplateBuilder):
|
||||
return xmlutil.MasterTemplate(root, 1)
|
||||
|
||||
|
||||
class HostDeserializer(wsgi.XMLDeserializer):
|
||||
class HostUpdateDeserializer(wsgi.XMLDeserializer):
|
||||
def default(self, string):
|
||||
try:
|
||||
node = minidom.parseString(string)
|
||||
@ -79,8 +79,16 @@ class HostDeserializer(wsgi.XMLDeserializer):
|
||||
raise exception.MalformedRequestBody(reason=msg)
|
||||
|
||||
updates = {}
|
||||
for child in node.childNodes[0].childNodes:
|
||||
updates[child.tagName] = self.extract_text(child)
|
||||
updates_node = self.find_first_child_named(node, 'updates')
|
||||
if updates_node is not None:
|
||||
maintenance = self.find_first_child_named(updates_node,
|
||||
'maintenance_mode')
|
||||
if maintenance is not None:
|
||||
updates[maintenance.tagName] = self.extract_text(maintenance)
|
||||
|
||||
status = self.find_first_child_named(updates_node, 'status')
|
||||
if status is not None:
|
||||
updates[status.tagName] = self.extract_text(status)
|
||||
|
||||
return dict(body=updates)
|
||||
|
||||
@ -131,7 +139,7 @@ class HostController(object):
|
||||
return {'hosts': _list_hosts(req)}
|
||||
|
||||
@wsgi.serializers(xml=HostUpdateTemplate)
|
||||
@wsgi.deserializers(xml=HostDeserializer)
|
||||
@wsgi.deserializers(xml=HostUpdateDeserializer)
|
||||
@check_host
|
||||
def update(self, req, id, body):
|
||||
authorize(req.environ['nova.context'])
|
||||
|
@ -272,7 +272,7 @@ class HostTestCase(test.TestCase):
|
||||
class HostSerializerTest(test.TestCase):
|
||||
def setUp(self):
|
||||
super(HostSerializerTest, self).setUp()
|
||||
self.deserializer = os_hosts.HostDeserializer()
|
||||
self.deserializer = os_hosts.HostUpdateDeserializer()
|
||||
|
||||
def test_index_serializer(self):
|
||||
serializer = os_hosts.HostIndexTemplate()
|
||||
@ -336,9 +336,12 @@ class HostSerializerTest(test.TestCase):
|
||||
self.assertEqual(value, tree.get(key))
|
||||
|
||||
def test_update_deserializer(self):
|
||||
exemplar = dict(status='enabled', foo='bar')
|
||||
intext = ("<?xml version='1.0' encoding='UTF-8'?>\n"
|
||||
'<updates><status>enabled</status><foo>bar</foo></updates>')
|
||||
exemplar = dict(status='enabled', maintenance_mode='disable')
|
||||
intext = """<?xml version='1.0' encoding='UTF-8'?>
|
||||
<updates>
|
||||
<status>enabled</status>
|
||||
<maintenance_mode>disable</maintenance_mode>
|
||||
</updates>"""
|
||||
result = self.deserializer.deserialize(intext)
|
||||
|
||||
self.assertEqual(dict(body=exemplar), result)
|
||||
|
Loading…
Reference in New Issue
Block a user