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
This commit is contained in:
Andrea Rosa 2013-02-20 11:52:10 +00:00
parent 7bf541cc90
commit 48b41e0b88
13 changed files with 51 additions and 6 deletions

View File

@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<service host="host1" binary="nova-compute" />

View File

@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<service host="host1" binary="nova-compute" status="disabled" />

View File

@ -1,4 +1,4 @@
{
"host": "host1",
"service": "nova-compute"
}
}

View File

@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<service host="host1" binary="nova-compute" />

View File

@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<service host="host1" binary="nova-compute" status="enabled" />

View File

@ -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>

View File

@ -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']

View File

@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<service host="%(host)s" binary="%(binary)s" />

View File

@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<service host="%(host)s" binary="%(binary)s" status="disabled" />

View File

@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<service host="%(host)s" binary="%(binary)s" />

View File

@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<service host="%(host)s" binary="%(binary)s" status="enabled" />

View File

@ -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>

View File

@ -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")