From dc29ab91e434335f4468427475baea23d2c68b7b Mon Sep 17 00:00:00 2001 From: "Mauro S. M. Rodrigues" Date: Thu, 7 Mar 2013 13:25:09 -0500 Subject: Add MultipleCreate template and fix conflict with other templates This patch creates a dedicated xml template to the os-multiple-create extension when using return_reservation_id=True in the request. The previous code, with all extensions loaded, conflicted with security_groups extension. There is also a change in the response due to the new Template, but the only information removed is an empty metadata field (which made the previous xml output even more inconsisten with json). The consistency between json and xml will be treated in the next api version. DocImpact Fixes bug 1149526 Change-Id: I3ca0129086ff1df3a8faa2b3b8bd959c9b74103c --- .../os-multiple-create/multiple-create-post-resp.xml | 4 +--- nova/api/openstack/compute/servers.py | 18 ++++++++++-------- nova/tests/api/openstack/compute/test_servers.py | 2 +- .../multiple-create-post-resp.xml.tpl | 4 +--- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/doc/api_samples/os-multiple-create/multiple-create-post-resp.xml b/doc/api_samples/os-multiple-create/multiple-create-post-resp.xml index 84a400061..8db4ac2eb 100644 --- a/doc/api_samples/os-multiple-create/multiple-create-post-resp.xml +++ b/doc/api_samples/os-multiple-create/multiple-create-post-resp.xml @@ -1,4 +1,2 @@ - - - \ No newline at end of file + \ No newline at end of file diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py index 3464cfdbd..c21599300 100644 --- a/nova/api/openstack/compute/servers.py +++ b/nova/api/openstack/compute/servers.py @@ -134,6 +134,13 @@ class ServerAdminPassTemplate(xmlutil.TemplateBuilder): return xmlutil.SlaveTemplate(root, 1, nsmap=server_nsmap) +class ServerMultipleCreateTemplate(xmlutil.TemplateBuilder): + def construct(self): + root = xmlutil.TemplateElement('server') + root.set('reservation_id') + return xmlutil.MasterTemplate(root, 1, nsmap=server_nsmap) + + def FullServerTemplate(): master = ServerTemplate() master.attach(ServerAdminPassTemplate()) @@ -917,14 +924,9 @@ class Controller(wsgi.Controller): # Let the caller deal with unhandled exceptions. # If the caller wanted a reservation_id, return it - - # NOTE(treinish): XML serialization will not work without a root - # selector of 'server' however JSON return is not expecting a server - # field/object - if ret_resv_id and (req.get_content_type() == 'application/xml'): - return {'server': {'reservation_id': resv_id}} - elif ret_resv_id: - return {'reservation_id': resv_id} + if ret_resv_id: + return wsgi.ResponseObject({'reservation_id': resv_id}, + xml=ServerMultipleCreateTemplate) req.cache_db_instances(instances) server = self._view_builder.create(req, instances[0]) diff --git a/nova/tests/api/openstack/compute/test_servers.py b/nova/tests/api/openstack/compute/test_servers.py index 638ef79b0..e1c88b6f8 100644 --- a/nova/tests/api/openstack/compute/test_servers.py +++ b/nova/tests/api/openstack/compute/test_servers.py @@ -1988,7 +1988,7 @@ class ServersControllerCreateTest(test.TestCase): req.headers["content-type"] = "application/json" res = self.controller.create(req, body) - reservation_id = res.get('reservation_id') + reservation_id = res.obj.get('reservation_id') self.assertNotEqual(reservation_id, "") self.assertNotEqual(reservation_id, None) self.assertTrue(len(reservation_id) > 1) diff --git a/nova/tests/integrated/api_samples/os-multiple-create/multiple-create-post-resp.xml.tpl b/nova/tests/integrated/api_samples/os-multiple-create/multiple-create-post-resp.xml.tpl index a361612b2..e5ba2cc56 100644 --- a/nova/tests/integrated/api_samples/os-multiple-create/multiple-create-post-resp.xml.tpl +++ b/nova/tests/integrated/api_samples/os-multiple-create/multiple-create-post-resp.xml.tpl @@ -1,4 +1,2 @@ - - - + -- cgit