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
This commit is contained in:
parent
436282fad2
commit
dc29ab91e4
@ -1,4 +1,2 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<server xmlns:atom="http://www.w3.org/2005/Atom" xmlns="http://docs.openstack.org/compute/api/v1.1" reservation_id="r-yk2p005y">
|
||||
<metadata/>
|
||||
</server>
|
||||
<server xmlns:atom="http://www.w3.org/2005/Atom" xmlns="http://docs.openstack.org/compute/api/v1.1" reservation_id="r-fq0lg4za"/>
|
@ -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])
|
||||
|
@ -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)
|
||||
|
@ -1,4 +1,2 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<server xmlns:atom="http://www.w3.org/2005/Atom" xmlns="http://docs.openstack.org/compute/api/v1.1" reservation_id="%(reservation_id)s">
|
||||
<metadata/>
|
||||
</server>
|
||||
<server xmlns:atom="http://www.w3.org/2005/Atom" xmlns="http://docs.openstack.org/compute/api/v1.1" reservation_id="%(reservation_id)s"/>
|
||||
|
Loading…
Reference in New Issue
Block a user