diff options
| author | Dan Smith <danms@us.ibm.com> | 2012-09-27 13:59:29 -0700 |
|---|---|---|
| committer | Mauro S. M. Rodrigues <maurosr@linux.vnet.ibm.com> | 2012-09-28 10:00:51 -0400 |
| commit | 2ba27f66cf14e1cb111ebc93d094c6e77c55245f (patch) | |
| tree | 1f1564de2bcad83ae74ffe3437b64370ffa0e959 | |
| parent | 0d565de78b5cc8ecdd18e10444ec731db46b48eb (diff) | |
| download | nova-2ba27f66cf14e1cb111ebc93d094c6e77c55245f.tar.gz nova-2ba27f66cf14e1cb111ebc93d094c6e77c55245f.tar.xz nova-2ba27f66cf14e1cb111ebc93d094c6e77c55245f.zip | |
Fix CloudPipe extension XML serialization
It is completely broken right now and this fixes it to properly
traverse a list of cloudpipe instance dictionaries, resulting
in XML output that matches the API spec.
Fixes bug: 1056242
Change-Id: Ic768afeaa76d776fd55a4f618d14fa41ed4c8a63
| -rw-r--r-- | nova/api/openstack/compute/contrib/cloudpipe.py | 14 | ||||
| -rw-r--r-- | nova/tests/api/openstack/compute/contrib/test_cloudpipe.py | 11 |
2 files changed, 15 insertions, 10 deletions
diff --git a/nova/api/openstack/compute/contrib/cloudpipe.py b/nova/api/openstack/compute/contrib/cloudpipe.py index f38a1b12a..48b641348 100644 --- a/nova/api/openstack/compute/contrib/cloudpipe.py +++ b/nova/api/openstack/compute/contrib/cloudpipe.py @@ -37,15 +37,21 @@ authorize = extensions.extension_authorizer('compute', 'cloudpipe') class CloudpipeTemplate(xmlutil.TemplateBuilder): def construct(self): - return xmlutil.MasterTemplate(xmlutil.make_flat_dict('cloudpipe'), 1) + root = xmlutil.TemplateElement('cloudpipe') + elem = xmlutil.SubTemplateElement(root, 'instance_id', + selector='instance_id') + elem.text = str + return xmlutil.MasterTemplate(root, 1) class CloudpipesTemplate(xmlutil.TemplateBuilder): def construct(self): root = xmlutil.TemplateElement('cloudpipes') - elem = xmlutil.make_flat_dict('cloudpipe', selector='cloudpipes', - subselector='cloudpipe') - root.append(elem) + elem1 = xmlutil.SubTemplateElement(root, 'cloudpipe', + selector='cloudpipes') + elem2 = xmlutil.SubTemplateElement(elem1, xmlutil.Selector(0), + selector=xmlutil.get_items) + elem2.text = 1 return xmlutil.MasterTemplate(root, 1) diff --git a/nova/tests/api/openstack/compute/contrib/test_cloudpipe.py b/nova/tests/api/openstack/compute/contrib/test_cloudpipe.py index bb0eafe66..97b78f81e 100644 --- a/nova/tests/api/openstack/compute/contrib/test_cloudpipe.py +++ b/nova/tests/api/openstack/compute/contrib/test_cloudpipe.py @@ -152,25 +152,24 @@ class CloudpipesXMLSerializerTest(test.TestCase): def test_index_serializer(self): serializer = cloudpipe.CloudpipesTemplate() exemplar = dict(cloudpipes=[ - dict(cloudpipe=dict( + dict( project_id='1234', public_ip='1.2.3.4', public_port='321', instance_id='1234-1234-1234-1234', created_at=timeutils.isotime(), - state='running')), - dict(cloudpipe=dict( + state='running'), + dict( project_id='4321', public_ip='4.3.2.1', public_port='123', - state='pending'))]) + state='pending')]) text = serializer.serialize(exemplar) tree = etree.fromstring(text) self.assertEqual('cloudpipes', tree.tag) self.assertEqual(len(exemplar['cloudpipes']), len(tree)) for idx, cl_pipe in enumerate(tree): - self.assertEqual('cloudpipe', cl_pipe.tag) - kp_data = exemplar['cloudpipes'][idx]['cloudpipe'] + kp_data = exemplar['cloudpipes'][idx] for child in cl_pipe: self.assertTrue(child.tag in kp_data) self.assertEqual(child.text, kp_data[child.tag]) |
