Add deserialization for multiple create and az

We were not deserializing xml values causing the multiple create
extension and the availability zone extension to fail with xml.

This adds deserialization for these attributes and adds tests

Part of bug 1050997

Change-Id: Ic40ce58b0854717dd99dba8ed39c861e31e6bba4
This commit is contained in:
Vishvananda Ishaya 2012-09-18 11:56:54 -07:00
parent afefc88389
commit 71c9677d80
2 changed files with 38 additions and 1 deletions

View File

@ -159,11 +159,16 @@ class CommonDeserializer(wsgi.MetadataXMLDeserializer):
server_node = self.find_first_child_named(node, 'server')
attributes = ["name", "imageRef", "flavorRef", "adminPass",
"accessIPv4", "accessIPv6", "key_name"]
"accessIPv4", "accessIPv6", "key_name",
"availability_zone", "min_count", "max_count"]
for attr in attributes:
if server_node.getAttribute(attr):
server[attr] = server_node.getAttribute(attr)
res_id = server_node.getAttribute('return_reservation_id')
if res_id:
server['return_reservation_id'] = utils.bool_from_str(res_id)
scheduler_hints = self._extract_scheduler_hints(server_node)
if scheduler_hints:
server['os:scheduler_hints'] = scheduler_hints

View File

@ -3256,6 +3256,38 @@ class TestServerCreateRequestXMLDeserializer(test.TestCase):
}}
self.assertEquals(request['body'], expected)
def test_request_with_availability_zone(self):
serial_request = """
<server xmlns="http://docs.openstack.org/compute/api/v2"
name="new-server-test" imageRef="1" flavorRef="1"
availability_zone="some_zone:some_host">
</server>"""
request = self.deserializer.deserialize(serial_request)
expected = {"server": {
"name": "new-server-test",
"imageRef": "1",
"flavorRef": "1",
"availability_zone": "some_zone:some_host",
}}
self.assertEquals(request['body'], expected)
def test_request_with_multiple_create_args(self):
serial_request = """
<server xmlns="http://docs.openstack.org/compute/api/v2"
name="new-server-test" imageRef="1" flavorRef="1"
min_count="1" max_count="3" return_reservation_id="True">
</server>"""
request = self.deserializer.deserialize(serial_request)
expected = {"server": {
"name": "new-server-test",
"imageRef": "1",
"flavorRef": "1",
"min_count": "1",
"max_count": "3",
"return_reservation_id": True,
}}
self.assertEquals(request['body'], expected)
class TestAddressesXMLSerialization(test.TestCase):