]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
get volumes API does not handle limit=0
authorSteven Kaufer <kaufer@us.ibm.com>
Fri, 7 Mar 2014 04:54:50 +0000 (04:54 +0000)
committerSteven Kaufer <kaufer@us.ibm.com>
Sat, 8 Mar 2014 02:11:27 +0000 (02:11 +0000)
This bug fixes a regression from bug 1288429, where the "next"
link is added when the number of volumes returned is the
maximum limit (even if the "limit" param is not specified).

The regression is hit when a "limit" of 0 is specified; in this
case the logic to create the "next" link is still executed and an
exception is thrown. The fix is to add back in the "if" check that
implictly checks if the max_items is non-0.

Test code was also created to verify that a limit of 0 is handled
correctly.

Change-Id: I92f9afb9b0e2c627d2c77f67fa026b731903384f
Closes-bug: 1289124

cinder/api/common.py
cinder/tests/api/v2/test_volumes.py

index d38146243c7b4e0a940ae999b7ce6a2a30548f65..9ad0847f63e716a5d2802fde3da76b92c0926c45 100644 (file)
@@ -258,7 +258,7 @@ class ViewBuilder(object):
         max_items = min(
             int(request.params.get("limit", CONF.osapi_max_limit)),
             CONF.osapi_max_limit)
-        if max_items == len(items):
+        if max_items and max_items == len(items):
             last_item = items[-1]
             if id_key in last_item:
                 last_item_id = last_item[id_key]
index 9d7333cc8ab9d9108dc15765c7b57df24a0e5ce0..64cd6826247880f5812f2f034a334e7acc277398 100644 (file)
@@ -747,6 +747,16 @@ class VolumeApiTest(test.TestCase):
                           self.controller.index,
                           req)
 
+    def test_volume_with_limit_zero(self):
+        def stub_volume_get_all(context, marker, limit,
+                                sort_key, sort_dir):
+            return []
+        self.stubs.Set(db, 'volume_get_all', stub_volume_get_all)
+        req = fakes.HTTPRequest.blank('/v2/volumes?limit=0')
+        res_dict = self.controller.index(req)
+        expected = {'volumes': []}
+        self.assertEqual(res_dict, expected)
+
     def test_volume_default_limit(self):
         self.stubs.Set(volume_api.API, 'get', stubs.stub_volume_get)