From: Juan Manuel Olle Date: Tue, 29 Apr 2014 14:46:23 +0000 (-0300) Subject: fix atom link in XML Version API X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=a5a33a6833b29457d2ea7fc5b8c31f74a7aa4140;p=openstack-build%2Fcinder-build.git fix atom link in XML Version API 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 --- diff --git a/cinder/api/xmlutil.py b/cinder/api/xmlutil.py index 364ff3d6e..1ac3adb35 100644 --- a/cinder/api/xmlutil.py +++ b/cinder/api/xmlutil.py @@ -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 diff --git a/cinder/tests/api/test_xmlutil.py b/cinder/tests/api/test_xmlutil.py index 4c111e78f..b7ebf560b 100644 --- a/cinder/tests/api/test_xmlutil.py +++ b/cinder/tests/api/test_xmlutil.py @@ -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')