]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
fix atom link in XML Version API
authorJuan Manuel Olle <juan.m.olle@intel.com>
Tue, 29 Apr 2014 14:46:23 +0000 (11:46 -0300)
committerJuan Manuel Olle <juan.m.olle@intel.com>
Tue, 29 Jul 2014 17:53:08 +0000 (17:53 +0000)
This patch fixes tag names where the tag name has ':'
for links templates.
Some examples are
'{http://www.w3.org/2005/Atom}link'
should be
['{http://www.w3.org/2005/Atom}link']

and

'test1:test2'
should be
['test1', 'test2']

Closes-Bug: #1311243
Change-Id: I6e7c068e41eb6b069c24ef9d6c46b726ea722074

cinder/api/xmlutil.py
cinder/tests/api/test_xmlutil.py

index 364ff3d6ef370264e89d02d7163fe9c7e432bde9..1ac3adb357c8b3514147bec43716586c8249a29f 100644 (file)
@@ -14,6 +14,7 @@
 #    under the License.
 
 import os.path
+import re
 
 from lxml import etree
 
@@ -29,6 +30,8 @@ XMLNS_VOLUME_V1 = 'http://docs.openstack.org/volume/api/v1'
 XMLNS_VOLUME_V2 = ('http://docs.openstack.org/api/openstack-volume/2.0/'
                    'content')
 
+_split_pattern = re.compile(r'([^:{]*{[^}]*}[^:]*|[^:]+)')
+
 
 def validate_schema(xml, schema_name):
     if isinstance(xml, str):
@@ -356,6 +359,10 @@ class TemplateElement(object):
                 pass
         return tmpattrib
 
+    @staticmethod
+    def _splitTagName(name):
+        return _split_pattern.findall(name)
+
     def _render(self, parent, datum, patches, nsmap):
         """Internal rendering.
 
@@ -382,7 +389,7 @@ class TemplateElement(object):
         else:
             tmpattrib = {}
 
-        tagnameList = tagname.split(':')
+        tagnameList = self._splitTagName(tagname)
         insertIndex = 0
 
         #If parent is not none and has same tagname
index 4c111e78fdbb969007cf28baf78e6e1124e8fc89..b7ebf560b3949c8972057149be04134f1624d550 100644 (file)
@@ -472,6 +472,18 @@ class TemplateTest(test.TestCase):
         self.assertEqual(len(siblings), 1)
         self.assertEqual(siblings[0], elem)
 
+    def test__splitTagName(self):
+        test_cases = [
+            ('a', ['a']),
+            ('a:b', ['a', 'b']),
+            ('{http://test.com}a:b', ['{http://test.com}a', 'b']),
+            ('a:b{http://test.com}:c', ['a', 'b{http://test.com}', 'c']),
+        ]
+
+        for test_case, expected in test_cases:
+            result = xmlutil.TemplateElement._splitTagName(test_case)
+            self.assertEqual(expected, result)
+
     def test__nsmap(self):
         # Set up a basic template
         elem = xmlutil.TemplateElement('test')