summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGiampaolo Lauria <lauria@us.ibm.com>2013-01-25 10:44:23 -0500
committerGiampaolo Lauria <lauria@us.ibm.com>2013-01-29 12:55:14 -0500
commit2b602148be8ffa9aec377fc2c220464d9c43c885 (patch)
tree1f688cc0f15cae72a979063620ccfdc511f8ffb3
parent7a01888b3f663c2292dc4ed9ff36436fdffa9b3e (diff)
downloadnova-2b602148be8ffa9aec377fc2c220464d9c43c885.tar.gz
nova-2b602148be8ffa9aec377fc2c220464d9c43c885.tar.xz
nova-2b602148be8ffa9aec377fc2c220464d9c43c885.zip
Fix get and update in FlavorExtraSpecs
Fixes bug 1105170 Added serializer test Change-Id: I365a81e17319fa96d53b53eafb6326fff8bde288
-rw-r--r--nova/api/openstack/compute/contrib/flavorextraspecs.py14
-rw-r--r--nova/tests/api/openstack/compute/contrib/test_flavors_extra_specs.py7
2 files changed, 18 insertions, 3 deletions
diff --git a/nova/api/openstack/compute/contrib/flavorextraspecs.py b/nova/api/openstack/compute/contrib/flavorextraspecs.py
index c8deb7b4c..84f157b6a 100644
--- a/nova/api/openstack/compute/contrib/flavorextraspecs.py
+++ b/nova/api/openstack/compute/contrib/flavorextraspecs.py
@@ -34,6 +34,15 @@ class ExtraSpecsTemplate(xmlutil.TemplateBuilder):
return xmlutil.MasterTemplate(xmlutil.make_flat_dict('extra_specs'), 1)
+class ExtraSpecTemplate(xmlutil.TemplateBuilder):
+ def construct(self):
+ sel = xmlutil.Selector(xmlutil.get_items, 0)
+ root = xmlutil.TemplateElement('extra_spec', selector=sel)
+ root.set('key', 0)
+ root.text = 1
+ return xmlutil.MasterTemplate(root, 1)
+
+
class FlavorExtraSpecsController(object):
"""The flavor extra specs API controller for the OpenStack API."""
@@ -70,7 +79,7 @@ class FlavorExtraSpecsController(object):
raise exc.HTTPBadRequest(explanation=unicode(error))
return body
- @wsgi.serializers(xml=ExtraSpecsTemplate)
+ @wsgi.serializers(xml=ExtraSpecTemplate)
def update(self, req, flavor_id, id, body):
context = req.environ['nova.context']
authorize(context)
@@ -87,10 +96,9 @@ class FlavorExtraSpecsController(object):
body)
except exception.MetadataLimitExceeded as error:
raise exc.HTTPBadRequest(explanation=unicode(error))
-
return body
- @wsgi.serializers(xml=ExtraSpecsTemplate)
+ @wsgi.serializers(xml=ExtraSpecTemplate)
def show(self, req, flavor_id, id):
"""Return a single extra spec item."""
context = req.environ['nova.context']
diff --git a/nova/tests/api/openstack/compute/contrib/test_flavors_extra_specs.py b/nova/tests/api/openstack/compute/contrib/test_flavors_extra_specs.py
index bc9f66eb2..03f6a8f48 100644
--- a/nova/tests/api/openstack/compute/contrib/test_flavors_extra_specs.py
+++ b/nova/tests/api/openstack/compute/contrib/test_flavors_extra_specs.py
@@ -182,3 +182,10 @@ class FlavorsExtraSpecsXMLSerializerTest(test.TestCase):
'<extra_specs><key1>value1</key1></extra_specs>')
result = deserializer.deserialize(intext)['body']
self.assertEqual(result, expected)
+
+ def test_show_update_serializer(self):
+ serializer = flavorextraspecs.ExtraSpecTemplate()
+ expected = ("<?xml version='1.0' encoding='UTF-8'?>\n"
+ '<extra_spec key="key1">value1</extra_spec>')
+ text = serializer.serialize(dict({"key1": "value1"}))
+ self.assertEqual(text, expected)