diff options
author | Andrea Rosa <andrea.rosa@hp.com> | 2013-02-20 11:52:10 +0000 |
---|---|---|
committer | Vishvananda Ishaya <vishvananda@gmail.com> | 2013-03-28 10:29:48 -0700 |
commit | 7f94300efc87662a94d645b8e592fae6817a05db (patch) | |
tree | 5ea1540776badc524fcfc78555b08512155dcd81 | |
parent | 2a47b329da09e858c6dfe3c5860e2ee088a8a307 (diff) | |
download | nova-7f94300efc87662a94d645b8e592fae6817a05db.tar.gz |
Fix typo in the XML serialization os-services API.
Partially implements blueprint nova-api-samples
fixes bug 1130609
The XML serializer for the update method in the os-services API extensions was
not serializing the "updated_at" field because of a typo in the code.
In this change we added api_samples for the XML output.
Change-Id: I9fff0677e9bad650b19e559b3ed6e9bc0ffe8c3c
(cherry picked from commit 48b41e0b880adf80e3be6d128cd392af57b8477e)
13 files changed, 51 insertions, 6 deletions
diff --git a/doc/api_samples/os-services/service-disable-put-req.xml b/doc/api_samples/os-services/service-disable-put-req.xml new file mode 100644 index 0000000000..598ffc0ca9 --- /dev/null +++ b/doc/api_samples/os-services/service-disable-put-req.xml @@ -0,0 +1,2 @@ +<?xml version='1.0' encoding='UTF-8'?> +<service host="host1" binary="nova-compute" /> diff --git a/doc/api_samples/os-services/service-disable-put-resp.xml b/doc/api_samples/os-services/service-disable-put-resp.xml new file mode 100644 index 0000000000..f7569159d9 --- /dev/null +++ b/doc/api_samples/os-services/service-disable-put-resp.xml @@ -0,0 +1,2 @@ +<?xml version='1.0' encoding='UTF-8'?> +<service host="host1" binary="nova-compute" status="disabled" /> diff --git a/doc/api_samples/os-services/service-enable-put-req.json b/doc/api_samples/os-services/service-enable-put-req.json index d11afaed9c..ffe896999d 100644 --- a/doc/api_samples/os-services/service-enable-put-req.json +++ b/doc/api_samples/os-services/service-enable-put-req.json @@ -1,4 +1,4 @@ { "host": "host1", "service": "nova-compute" -}
\ No newline at end of file +} diff --git a/doc/api_samples/os-services/service-enable-put-req.xml b/doc/api_samples/os-services/service-enable-put-req.xml new file mode 100644 index 0000000000..598ffc0ca9 --- /dev/null +++ b/doc/api_samples/os-services/service-enable-put-req.xml @@ -0,0 +1,2 @@ +<?xml version='1.0' encoding='UTF-8'?> +<service host="host1" binary="nova-compute" /> diff --git a/doc/api_samples/os-services/service-enable-put-resp.xml b/doc/api_samples/os-services/service-enable-put-resp.xml new file mode 100644 index 0000000000..04c29ffa03 --- /dev/null +++ b/doc/api_samples/os-services/service-enable-put-resp.xml @@ -0,0 +1,2 @@ +<?xml version='1.0' encoding='UTF-8'?> +<service host="host1" binary="nova-compute" status="enabled" /> diff --git a/doc/api_samples/os-services/services-list-get-resp.xml b/doc/api_samples/os-services/services-list-get-resp.xml new file mode 100644 index 0000000000..68809e9aaf --- /dev/null +++ b/doc/api_samples/os-services/services-list-get-resp.xml @@ -0,0 +1,6 @@ +<services> + <service status="disabled" binary="nova-scheduler" zone="internal" state="up" host="host1" updated_at="2012-10-29T13:42:02.000000"/> + <service status="disabled" binary="nova-compute" zone="nova" state="up" host="host1" updated_at="2012-10-29T13:42:05.000000" /> + <service status="enabled" binary="nova-scheduler" zone="internal" state="down" host="host2" updated_at="2012-09-19T06:55:34.000000"/> + <service status="disabled" binary="nova-compute" zone="nova" state="down" host="host2" updated_at="2012-09-18T08:03:38.000000"/> +</services> diff --git a/nova/api/openstack/compute/contrib/services.py b/nova/api/openstack/compute/contrib/services.py index 558c31586d..5b382f8929 100644 --- a/nova/api/openstack/compute/contrib/services.py +++ b/nova/api/openstack/compute/contrib/services.py @@ -42,14 +42,14 @@ class ServicesIndexTemplate(xmlutil.TemplateBuilder): elem.set('zone') elem.set('status') elem.set('state') - elem.set('update_at') + elem.set('updated_at') return xmlutil.MasterTemplate(root, 1) -class ServicesUpdateTemplate(xmlutil.TemplateBuilder): +class ServiceUpdateTemplate(xmlutil.TemplateBuilder): def construct(self): - root = xmlutil.TemplateElement('host') + root = xmlutil.TemplateElement('service', selector='service') root.set('host') root.set('binary') root.set('status') @@ -57,6 +57,19 @@ class ServicesUpdateTemplate(xmlutil.TemplateBuilder): return xmlutil.MasterTemplate(root, 1) +class ServiceUpdateDeserializer(wsgi.XMLDeserializer): + def default(self, string): + node = xmlutil.safe_minidom_parse_string(string) + service = {} + service_node = self.find_first_child_named(node, 'service') + if service_node is None: + return service + service['host'] = service_node.getAttribute('host') + service['binary'] = service_node.getAttribute('binary') + + return dict(body=service) + + class ServiceController(object): def __init__(self): @@ -98,7 +111,8 @@ class ServiceController(object): 'updated_at': svc['updated_at']}) return {'services': svcs} - @wsgi.serializers(xml=ServicesUpdateTemplate) + @wsgi.deserializers(xml=ServiceUpdateDeserializer) + @wsgi.serializers(xml=ServiceUpdateTemplate) def update(self, req, id, body): """Enable/Disable scheduling for a service.""" context = req.environ['nova.context'] @@ -110,7 +124,6 @@ class ServiceController(object): disabled = True else: raise webob.exc.HTTPNotFound("Unknown action") - try: host = body['host'] binary = body['binary'] diff --git a/nova/tests/integrated/api_samples/os-services/service-disable-put-req.xml.tpl b/nova/tests/integrated/api_samples/os-services/service-disable-put-req.xml.tpl new file mode 100644 index 0000000000..fc297bcd34 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-services/service-disable-put-req.xml.tpl @@ -0,0 +1,2 @@ +<?xml version='1.0' encoding='UTF-8'?> +<service host="%(host)s" binary="%(binary)s" /> diff --git a/nova/tests/integrated/api_samples/os-services/service-disable-put-resp.xml.tpl b/nova/tests/integrated/api_samples/os-services/service-disable-put-resp.xml.tpl new file mode 100644 index 0000000000..cc03298c53 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-services/service-disable-put-resp.xml.tpl @@ -0,0 +1,2 @@ +<?xml version='1.0' encoding='UTF-8'?> +<service host="%(host)s" binary="%(binary)s" status="disabled" /> diff --git a/nova/tests/integrated/api_samples/os-services/service-enable-put-req.xml.tpl b/nova/tests/integrated/api_samples/os-services/service-enable-put-req.xml.tpl new file mode 100644 index 0000000000..fc297bcd34 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-services/service-enable-put-req.xml.tpl @@ -0,0 +1,2 @@ +<?xml version='1.0' encoding='UTF-8'?> +<service host="%(host)s" binary="%(binary)s" /> diff --git a/nova/tests/integrated/api_samples/os-services/service-enable-put-resp.xml.tpl b/nova/tests/integrated/api_samples/os-services/service-enable-put-resp.xml.tpl new file mode 100644 index 0000000000..3cbf51b778 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-services/service-enable-put-resp.xml.tpl @@ -0,0 +1,2 @@ +<?xml version='1.0' encoding='UTF-8'?> +<service host="%(host)s" binary="%(binary)s" status="enabled" /> diff --git a/nova/tests/integrated/api_samples/os-services/services-list-get-resp.xml.tpl b/nova/tests/integrated/api_samples/os-services/services-list-get-resp.xml.tpl new file mode 100644 index 0000000000..e708aa78d2 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-services/services-list-get-resp.xml.tpl @@ -0,0 +1,6 @@ +<services> + <service status="disabled" binary="nova-scheduler" zone="internal" state="up" host="host1" updated_at="%(timestamp)s"/> + <service status="disabled" binary="nova-compute" zone="nova" state="up" host="host1" updated_at="%(timestamp)s" /> + <service status="enabled" binary="nova-scheduler" zone="internal" state="down" host="host2" updated_at="%(timestamp)s"/> + <service status="disabled" binary="nova-compute" zone="nova" state="down" host="host2" updated_at="%(timestamp)s"/> +</services> diff --git a/nova/tests/integrated/test_api_samples.py b/nova/tests/integrated/test_api_samples.py index c647e0292a..073f36f606 100644 --- a/nova/tests/integrated/test_api_samples.py +++ b/nova/tests/integrated/test_api_samples.py @@ -2012,6 +2012,10 @@ class ServicesJsonTest(ApiSampleTestBase): subs, response) +class ServicesXmlTest(ServicesJsonTest): + ctype = 'xml' + + class SimpleTenantUsageSampleJsonTest(ServersSampleBase): extension_name = ("nova.api.openstack.compute.contrib.simple_tenant_usage." "Simple_tenant_usage") |