summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrant Knudson <bknudson@us.ibm.com>2013-06-03 17:12:38 -0500
committerBrant Knudson <bknudson@us.ibm.com>2013-06-11 12:57:01 -0500
commitb0d766343bf618398df45cc1d5b4444255d986bc (patch)
tree7d224de2ee6de7348d404e4cc749aec6eb468da5
parentdc7fdb031a41f2c8e8f7479dc8e9d232a8da86de (diff)
Version response compatible with Folsom
This change adds <link> elements to the <version id="v2.0"> element in the version response to be compatible with the response given by the Keystone server in the Folsom release. Fixes bug 1187101 Change-Id: Ida71e2dbe3cf432d429fb739e68a83d7e009ca40
-rw-r--r--keystone/common/serializer.py12
-rw-r--r--tests/test_serializer.py45
-rw-r--r--tests/test_versions.py5
3 files changed, 62 insertions, 0 deletions
diff --git a/keystone/common/serializer.py b/keystone/common/serializer.py
index 6b12df3a..597fbfd8 100644
--- a/keystone/common/serializer.py
+++ b/keystone/common/serializer.py
@@ -300,6 +300,18 @@ class XmlSerializer(object):
self._populate_sequence(element, value)
elif isinstance(value, dict):
self._populate_tree(element, value)
+
+ # NOTE(blk-u): For compatibility with Folsom, when serializing the
+ # v2.0 version element also add the links to the base element.
+ if (value.get('id') == 'v2.0' and
+ value.get('status') == 'stable' and
+ value.get('updated') == '2013-03-06T00:00:00Z'):
+
+ for item in value['links']:
+ child = etree.Element('link')
+ self.populate_element(child, item)
+ element.append(child)
+
elif isinstance(value, basestring):
element.text = unicode(value)
diff --git a/tests/test_serializer.py b/tests/test_serializer.py
index ba162955..2024949b 100644
--- a/tests/test_serializer.py
+++ b/tests/test_serializer.py
@@ -250,3 +250,48 @@ class XmlSerializerTestCase(test.TestCase):
</object>
"""
self.assertSerializeDeserialize(d, xml)
+
+ def test_v2_links_special_case(self):
+ # There's special-case code (for backward compatibility) where if the
+ # data is the v2 version data, the link elements are also added to the
+ # main element.
+
+ d = {
+ "object": {
+ "id": "v2.0",
+ "status": "stable",
+ "updated": "2013-03-06T00:00:00Z",
+ "links": [{"href": "http://localhost:5000/v2.0/",
+ "rel": "self"},
+ {"href": "http://docs.openstack.org/api/openstack-"
+ "identity-service/2.0/content/",
+ "type": "text/html", "rel": "describedby"},
+ {"href": "http://docs.openstack.org/api/openstack-"
+ "identity-service/2.0/"
+ "identity-dev-guide-2.0.pdf",
+ "type": "application/pdf", "rel": "describedby"}]
+ }}
+
+ xml = """
+ <?xml version="1.0" encoding="UTF-8"?>
+ <object xmlns="http://docs.openstack.org/identity/api/v2.0"
+ id="v2.0" status="stable" updated="2013-03-06T00:00:00Z">
+ <links>
+ <link rel="self" href="http://localhost:5000/v2.0/"/>
+ <link rel="describedby"
+ href="http://docs.openstack.org/api/openstack-\
+identity-service/2.0/content/" type="text/html"/>
+ <link rel="describedby"
+ href="http://docs.openstack.org/api/openstack-\
+identity-service/2.0/identity-dev-guide-2.0.pdf" type="application/pdf"/>
+ </links>
+ <link rel="self" href="http://localhost:5000/v2.0/"/>
+ <link rel="describedby"
+ href="http://docs.openstack.org/api/openstack-\
+identity-service/2.0/content/" type="text/html"/>
+ <link rel="describedby"
+ href="http://docs.openstack.org/api/openstack-\
+identity-service/2.0/identity-dev-guide-2.0.pdf" type="application/pdf"/>
+ </object>
+ """
+ self.assertEqualXML(serializer.to_xml(d), xml)
diff --git a/tests/test_versions.py b/tests/test_versions.py
index 2a53952f..a6c7086b 100644
--- a/tests/test_versions.py
+++ b/tests/test_versions.py
@@ -281,6 +281,11 @@ vnd.openstack.identity-v2.0+xml"/>
<link href="http://docs.openstack.org/api/openstack-identity-service/\
2.0/identity-dev-guide-2.0.pdf" type="application/pdf" rel="describedby"/>
</links>
+ <link href="http://localhost:%%(port)s/v2.0/" rel="self"/>
+ <link href="http://docs.openstack.org/api/openstack-identity-service/\
+2.0/content/" type="text/html" rel="describedby"/>
+ <link href="http://docs.openstack.org/api/openstack-identity-service/\
+2.0/identity-dev-guide-2.0.pdf" type="application/pdf" rel="describedby"/>
</version>
"""