]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Don't truncate osapi_volume_link prefixes
authorDeliang Fan <fandeliang@letv.com>
Fri, 24 Apr 2015 03:16:46 +0000 (11:16 +0800)
committerDeliang Fan <fandeliang@letv.com>
Fri, 24 Apr 2015 03:24:17 +0000 (11:24 +0800)
When osapi_volume_link_prefix is defined and used to update the
links return in API responses, do not drop the path component of
the overriding link prefix.

Change-Id: Ic84e16cdfa989d4af7f076a4c244808be2ca4dce
Closes-Bug: #1304099

cinder/api/common.py
cinder/tests/unit/api/test_common.py

index ceffef5b099f38bd4b4cf5736499b07b57ed7fc8..758df61bd364a2acdb77905ef569314624582b57 100644 (file)
@@ -353,7 +353,9 @@ class ViewBuilder(object):
         url_parts = list(urlparse.urlsplit(orig_url))
         prefix_parts = list(urlparse.urlsplit(prefix))
         url_parts[0:2] = prefix_parts[0:2]
-        return urlparse.urlunsplit(url_parts)
+        url_parts[2] = prefix_parts[2] + url_parts[2]
+
+        return urlparse.urlunsplit(url_parts).rstrip('/')
 
 
 class MetadataDeserializer(wsgi.MetadataXMLDeserializer):
index 75ef32894a800a3279596249d6cd58e1eef5fd47..71d0a32d7bd2d8a57dd840f1dc080ee72cb102d8 100644 (file)
@@ -547,3 +547,21 @@ class TestCollectionLinks(test.TestCase):
         self._validate_next_link(href_link_mock, item_count,
                                  osapi_max_limit,
                                  limit, should_link_exist)
+
+
+class LinkPrefixTest(test.TestCase):
+    def test_update_link_prefix(self):
+        vb = common.ViewBuilder()
+        result = vb._update_link_prefix("http://192.168.0.243:24/",
+                                        "http://127.0.0.1/volume")
+        self.assertEqual("http://127.0.0.1/volume", result)
+
+        result = vb._update_link_prefix("http://foo.x.com/v1",
+                                        "http://new.prefix.com")
+        self.assertEqual("http://new.prefix.com/v1", result)
+
+        result = vb._update_link_prefix(
+            "http://foo.x.com/v1",
+            "http://new.prefix.com:20455/new_extra_prefix")
+        self.assertEqual("http://new.prefix.com:20455/new_extra_prefix/v1",
+                         result)