From 8d43c3fba1a5e07703cae6f7b631d0787c4f41bb Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Tue, 18 Sep 2012 12:02:50 -0700 Subject: Makes scheduler hints and disk config xml correct The scheduler hints and disk config extensions were not using proper prefixes when deserializing xml. This patch modifes them to deserialize properly. It leaves the old deserialization in place as well so anyone using the broken implementation will continue to work. It also updates the api samples to use the new format. Note that the proper fix required changing the alias for the scheduler hints extension, since the alias is used for xml, so the samples had to be moved. Finally it fixes an issue with deserialization, allowing it to support multiple hints with the same name. Part of bug 1050997 Change-Id: I9969582d65d44de25388f07b6d2013fb7d093fb2 --- nova/tests/api/openstack/compute/test_servers.py | 47 +++++++++++++++++++++- .../OS-SCH-HNT/scheduler-hints-post-req.json.tpl | 11 +++++ .../OS-SCH-HNT/scheduler-hints-post-req.xml.tpl | 12 ++++++ .../OS-SCH-HNT/scheduler-hints-post-resp.json.tpl | 16 ++++++++ .../OS-SCH-HNT/scheduler-hints-post-resp.xml.tpl | 6 +++ .../all_extensions/extensions-get-resp.json.tpl | 16 ++++---- .../all_extensions/extensions-get-resp.xml.tpl | 6 +-- .../scheduler-hints-post-req.json.tpl | 11 ----- .../scheduler-hints-post-req.xml.tpl | 10 ----- .../scheduler-hints-post-resp.json.tpl | 16 -------- .../scheduler-hints-post-resp.xml.tpl | 6 --- 11 files changed, 102 insertions(+), 55 deletions(-) create mode 100644 nova/tests/integrated/api_samples/OS-SCH-HNT/scheduler-hints-post-req.json.tpl create mode 100644 nova/tests/integrated/api_samples/OS-SCH-HNT/scheduler-hints-post-req.xml.tpl create mode 100644 nova/tests/integrated/api_samples/OS-SCH-HNT/scheduler-hints-post-resp.json.tpl create mode 100644 nova/tests/integrated/api_samples/OS-SCH-HNT/scheduler-hints-post-resp.xml.tpl delete mode 100644 nova/tests/integrated/api_samples/os-scheduler-hints/scheduler-hints-post-req.json.tpl delete mode 100644 nova/tests/integrated/api_samples/os-scheduler-hints/scheduler-hints-post-req.xml.tpl delete mode 100644 nova/tests/integrated/api_samples/os-scheduler-hints/scheduler-hints-post-resp.json.tpl delete mode 100644 nova/tests/integrated/api_samples/os-scheduler-hints/scheduler-hints-post-resp.xml.tpl (limited to 'nova/tests') diff --git a/nova/tests/api/openstack/compute/test_servers.py b/nova/tests/api/openstack/compute/test_servers.py index 0aa628d96..bde59592b 100644 --- a/nova/tests/api/openstack/compute/test_servers.py +++ b/nova/tests/api/openstack/compute/test_servers.py @@ -1972,7 +1972,7 @@ class ServersControllerCreateTest(test.TestCase): self._test_create_extra(params) def test_create_instance_with_scheduler_hints_enabled(self): - self.ext_mgr.extensions = {'os-scheduler-hints': 'fake'} + self.ext_mgr.extensions = {'OS-SCH-HNT': 'fake'} hints = {'a': 'b'} params = {'scheduler_hints': hints} old_create = nova.compute.api.API.create @@ -3288,6 +3288,51 @@ class TestServerCreateRequestXMLDeserializer(test.TestCase): }} self.assertEquals(request['body'], expected) + def test_request_with_disk_config(self): + serial_request = """ + + """ + request = self.deserializer.deserialize(serial_request) + expected = {"server": { + "name": "new-server-test", + "imageRef": "1", + "flavorRef": "1", + "OS-DCF:diskConfig": True, + }} + self.assertEquals(request['body'], expected) + + def test_request_with_scheduler_hints(self): + serial_request = """ + + + + 7329b667-50c7-46a6-b913-cb2a09dfeee0 + + + f31efb24-34d2-43e1-8b44-316052956a39 + + + """ + request = self.deserializer.deserialize(serial_request) + expected = {"server": { + "name": "new-server-test", + "imageRef": "1", + "flavorRef": "1", + "OS-SCH-HNT:scheduler_hints": { + "different_host": [ + "7329b667-50c7-46a6-b913-cb2a09dfeee0", + "f31efb24-34d2-43e1-8b44-316052956a39", + ] + } + }} + self.assertEquals(request['body'], expected) + class TestAddressesXMLSerialization(test.TestCase): diff --git a/nova/tests/integrated/api_samples/OS-SCH-HNT/scheduler-hints-post-req.json.tpl b/nova/tests/integrated/api_samples/OS-SCH-HNT/scheduler-hints-post-req.json.tpl new file mode 100644 index 000000000..1a19960c2 --- /dev/null +++ b/nova/tests/integrated/api_samples/OS-SCH-HNT/scheduler-hints-post-req.json.tpl @@ -0,0 +1,11 @@ +{ + "server": { + "name": "new-server-test", + "imageRef": "%(image_id)s", + "flavorRef": "1" + }, + "os:scheduler_hints": { + "hypervisor": "xen", + "near": "%(image_near)s" + } +} diff --git a/nova/tests/integrated/api_samples/OS-SCH-HNT/scheduler-hints-post-req.xml.tpl b/nova/tests/integrated/api_samples/OS-SCH-HNT/scheduler-hints-post-req.xml.tpl new file mode 100644 index 000000000..a680e3476 --- /dev/null +++ b/nova/tests/integrated/api_samples/OS-SCH-HNT/scheduler-hints-post-req.xml.tpl @@ -0,0 +1,12 @@ + + + xen + %(image_near)s + + diff --git a/nova/tests/integrated/api_samples/OS-SCH-HNT/scheduler-hints-post-resp.json.tpl b/nova/tests/integrated/api_samples/OS-SCH-HNT/scheduler-hints-post-resp.json.tpl new file mode 100644 index 000000000..d5f030c87 --- /dev/null +++ b/nova/tests/integrated/api_samples/OS-SCH-HNT/scheduler-hints-post-resp.json.tpl @@ -0,0 +1,16 @@ +{ + "server": { + "adminPass": "%(password)s", + "id": "%(id)s", + "links": [ + { + "href": "%(host)s/v2/openstack/servers/%(uuid)s", + "rel": "self" + }, + { + "href": "%(host)s/openstack/servers/%(uuid)s", + "rel": "bookmark" + } + ] + } +} diff --git a/nova/tests/integrated/api_samples/OS-SCH-HNT/scheduler-hints-post-resp.xml.tpl b/nova/tests/integrated/api_samples/OS-SCH-HNT/scheduler-hints-post-resp.xml.tpl new file mode 100644 index 000000000..5a11c73c3 --- /dev/null +++ b/nova/tests/integrated/api_samples/OS-SCH-HNT/scheduler-hints-post-resp.xml.tpl @@ -0,0 +1,6 @@ + + + + + + diff --git a/nova/tests/integrated/api_samples/all_extensions/extensions-get-resp.json.tpl b/nova/tests/integrated/api_samples/all_extensions/extensions-get-resp.json.tpl index 62f6a8ece..f566a5020 100644 --- a/nova/tests/integrated/api_samples/all_extensions/extensions-get-resp.json.tpl +++ b/nova/tests/integrated/api_samples/all_extensions/extensions-get-resp.json.tpl @@ -48,6 +48,14 @@ "namespace": "http://docs.openstack.org/compute/ext/flavor_extra_data/api/v1.1", "updated": "%(timestamp)s" }, + { + "alias": "OS-SCH-HNT", + "description": "%(text)s", + "links": [], + "name": "SchedulerHints", + "namespace": "http://docs.openstack.org/compute/ext/scheduler-hints/api/v2", + "updated": "%(timestamp)s" + }, { "alias": "os-admin-actions", "description": "%(text)s", @@ -264,14 +272,6 @@ "namespace": "http://docs.openstack.org/compute/ext/rescue/api/v1.1", "updated": "%(timestamp)s" }, - { - "alias": "os-scheduler-hints", - "description": "%(text)s", - "links": [], - "name": "SchedulerHints", - "namespace": "http://docs.openstack.org/compute/ext/scheduler-hints/api/v2", - "updated": "%(timestamp)s" - }, { "alias": "os-security-groups", "description": "%(text)s", diff --git a/nova/tests/integrated/api_samples/all_extensions/extensions-get-resp.xml.tpl b/nova/tests/integrated/api_samples/all_extensions/extensions-get-resp.xml.tpl index cc79f8e84..20e650d7c 100644 --- a/nova/tests/integrated/api_samples/all_extensions/extensions-get-resp.xml.tpl +++ b/nova/tests/integrated/api_samples/all_extensions/extensions-get-resp.xml.tpl @@ -18,6 +18,9 @@ %(text)s + + %(text)s + %(text)s @@ -99,9 +102,6 @@ %(text)s - - %(text)s - %(text)s diff --git a/nova/tests/integrated/api_samples/os-scheduler-hints/scheduler-hints-post-req.json.tpl b/nova/tests/integrated/api_samples/os-scheduler-hints/scheduler-hints-post-req.json.tpl deleted file mode 100644 index 1a19960c2..000000000 --- a/nova/tests/integrated/api_samples/os-scheduler-hints/scheduler-hints-post-req.json.tpl +++ /dev/null @@ -1,11 +0,0 @@ -{ - "server": { - "name": "new-server-test", - "imageRef": "%(image_id)s", - "flavorRef": "1" - }, - "os:scheduler_hints": { - "hypervisor": "xen", - "near": "%(image_near)s" - } -} diff --git a/nova/tests/integrated/api_samples/os-scheduler-hints/scheduler-hints-post-req.xml.tpl b/nova/tests/integrated/api_samples/os-scheduler-hints/scheduler-hints-post-req.xml.tpl deleted file mode 100644 index 66327c534..000000000 --- a/nova/tests/integrated/api_samples/os-scheduler-hints/scheduler-hints-post-req.xml.tpl +++ /dev/null @@ -1,10 +0,0 @@ - - - xen - %(image_near)s - - diff --git a/nova/tests/integrated/api_samples/os-scheduler-hints/scheduler-hints-post-resp.json.tpl b/nova/tests/integrated/api_samples/os-scheduler-hints/scheduler-hints-post-resp.json.tpl deleted file mode 100644 index d5f030c87..000000000 --- a/nova/tests/integrated/api_samples/os-scheduler-hints/scheduler-hints-post-resp.json.tpl +++ /dev/null @@ -1,16 +0,0 @@ -{ - "server": { - "adminPass": "%(password)s", - "id": "%(id)s", - "links": [ - { - "href": "%(host)s/v2/openstack/servers/%(uuid)s", - "rel": "self" - }, - { - "href": "%(host)s/openstack/servers/%(uuid)s", - "rel": "bookmark" - } - ] - } -} diff --git a/nova/tests/integrated/api_samples/os-scheduler-hints/scheduler-hints-post-resp.xml.tpl b/nova/tests/integrated/api_samples/os-scheduler-hints/scheduler-hints-post-resp.xml.tpl deleted file mode 100644 index 5a11c73c3..000000000 --- a/nova/tests/integrated/api_samples/os-scheduler-hints/scheduler-hints-post-resp.xml.tpl +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - -- cgit