From 48b41e0b880adf80e3be6d128cd392af57b8477e Mon Sep 17 00:00:00 2001 From: Andrea Rosa Date: Wed, 20 Feb 2013 11:52:10 +0000 Subject: 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 --- nova/api/openstack/compute/contrib/services.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/compute/contrib/services.py b/nova/api/openstack/compute/contrib/services.py index 558c31586..5b382f892 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'] -- cgit