Browse Source

get volumes API does not handle limit=0

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
tags/2014.1.rc1
Steven Kaufer 5 years ago
parent
commit
5cee4f4107
2 changed files with 11 additions and 1 deletions
  1. 1
    1
      cinder/api/common.py
  2. 10
    0
      cinder/tests/api/v2/test_volumes.py

+ 1
- 1
cinder/api/common.py View File

@@ -258,7 +258,7 @@ class ViewBuilder(object):
258 258
         max_items = min(
259 259
             int(request.params.get("limit", CONF.osapi_max_limit)),
260 260
             CONF.osapi_max_limit)
261
-        if max_items == len(items):
261
+        if max_items and max_items == len(items):
262 262
             last_item = items[-1]
263 263
             if id_key in last_item:
264 264
                 last_item_id = last_item[id_key]

+ 10
- 0
cinder/tests/api/v2/test_volumes.py View File

@@ -747,6 +747,16 @@ class VolumeApiTest(test.TestCase):
747 747
                           self.controller.index,
748 748
                           req)
749 749
 
750
+    def test_volume_with_limit_zero(self):
751
+        def stub_volume_get_all(context, marker, limit,
752
+                                sort_key, sort_dir):
753
+            return []
754
+        self.stubs.Set(db, 'volume_get_all', stub_volume_get_all)
755
+        req = fakes.HTTPRequest.blank('/v2/volumes?limit=0')
756
+        res_dict = self.controller.index(req)
757
+        expected = {'volumes': []}
758
+        self.assertEqual(res_dict, expected)
759
+
750 760
     def test_volume_default_limit(self):
751 761
         self.stubs.Set(volume_api.API, 'get', stubs.stub_volume_get)
752 762
 

Loading…
Cancel
Save