From 71c9677d803a722f5c9eb5b2d0719f1e713d1b7b Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Tue, 18 Sep 2012 11:56:54 -0700 Subject: [PATCH] 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 --- nova/api/openstack/compute/servers.py | 7 +++- .../api/openstack/compute/test_servers.py | 32 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py index c949ad661428..5cb7369c0093 100644 --- a/nova/api/openstack/compute/servers.py +++ b/nova/api/openstack/compute/servers.py @@ -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 diff --git a/nova/tests/api/openstack/compute/test_servers.py b/nova/tests/api/openstack/compute/test_servers.py index aa8f6132bd9e..0aa628d96013 100644 --- a/nova/tests/api/openstack/compute/test_servers.py +++ b/nova/tests/api/openstack/compute/test_servers.py @@ -3256,6 +3256,38 @@ class TestServerCreateRequestXMLDeserializer(test.TestCase): }} self.assertEquals(request['body'], expected) + def test_request_with_availability_zone(self): + serial_request = """ + + """ + 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 = """ + + """ + 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):