Browse Source

Merge "Fix: listing volumes with filters"

tags/17.0.0.0rc1
Zuul 2 weeks ago
committed by Gerrit Code Review
parent
commit
e410315074
3 changed files with 29 additions and 2 deletions
  1. +17
    -0
      cinder/tests/unit/api/v3/test_volumes.py
  2. +7
    -2
      cinder/volume/api.py
  3. +5
    -0
      releasenotes/notes/fix-list-volume-filtering-3f2bf93ab9b98974.yaml

+ 17
- 0
cinder/tests/unit/api/v3/test_volumes.py View File

@@ -291,6 +291,23 @@ class VolumeApiTest(test.TestCase):
else:
self.assertNotIn('count', res_dict)

def test_list_volume_with_multiple_filters(self):
metadata = {'key_X': 'value_X'}
self._create_multiple_volumes_with_different_project()
test_utils.create_volume(self.ctxt, metadata=metadata)

self.mock_object(ViewBuilder, '_get_volume_type',
v2_fakes.fake_volume_type_name_get)
# Request with 'all_tenants' and 'metadata'
req = fakes.HTTPRequest.blank(
"/v3/volumes/detail?all_tenants=1"
"&metadata=%7B%27key_X%27%3A+%27value_X%27%7D")
ctxt = context.RequestContext(fake.USER_ID, fake.PROJECT_ID, False)
req.environ['cinder.context'] = ctxt
res_dict = self.controller._get_volumes(req, is_detail=True)
self.assertEqual(1, len(res_dict['volumes']))
self.assertEqual(metadata, res_dict['volumes'][0]['metadata'])

def test_volume_index_filter_by_group_id_in_unsupport_version(self):
self._create_volume_with_group()
req = fakes.HTTPRequest.blank(("/v3/volumes?group_id=%s") %


+ 7
- 2
cinder/volume/api.py View File

@@ -2034,8 +2034,8 @@ class API(base.Base):

# To translate any true/false equivalent to True/False
# which is only acceptable format in database queries.
for key, val in filters.items():
temp_dict = filters.copy()
for key, val in temp_dict.items():
try:
if key in booleans:
filters[key] = self._check_boolean_filter_value(
@@ -2048,6 +2048,11 @@ class API(base.Base):
# the filter becomes different from the user input.
continue
else:
# this is required as ast.literal_eval(<int>/<float>)
# raises exception. Eg: ast.literal_eval(5) generates
# ValueError: malformed node or string: 5
if not isinstance(val, str):
val = str(val)
filters[key] = ast.literal_eval(val)
except (ValueError, SyntaxError):
LOG.debug('Could not evaluate value %s, assuming string', val)


+ 5
- 0
releasenotes/notes/fix-list-volume-filtering-3f2bf93ab9b98974.yaml View File

@@ -0,0 +1,5 @@
---
fixes:
- |
`Bug #1883490 <https://bugs.launchpad.net/cinder/+bug/1883490>`_:
Fixed incorrect response of listing volumes with filters.

Loading…
Cancel
Save