From 46363697d9a7ddc7880bf6071e5d035f3f9aa043 Mon Sep 17 00:00:00 2001 From: whoami-rajat Date: Thu, 7 Mar 2019 21:58:21 +0530 Subject: [PATCH] Handling filters in Generalized Filtering API This patch handles the following filters : 1) all_tenants : Restoring to previous functionality of ignoring invalid filters 2) is_public (volume_type): This filter has the 3 valid values, * True : show only public volume types (valid for non-admins) * False : show only private volume types (valid for admins) * None : show both private and public volume types Since this filter is valid for admins as well as non-admins, we can pass this through filtering API to lower level code where this is handled correctly. 3) name (group, group snapshot): 'name' is a valid parameter for non-admins while showing a group or group snapshot. Closes-Bug: #1753885 Change-Id: I1545c165087f80a9fdc9f576114a820ac95be5c5 (cherry picked from commit 80e94ac3dcc8a5ee9100899b43dcb2fae6320aee) --- cinder/api/common.py | 5 +++-- cinder/tests/unit/api/test_common.py | 4 ++-- etc/cinder/resource_filters.json | 6 +++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/cinder/api/common.py b/cinder/api/common.py index 3930a4da90a..d8751d4cba2 100644 --- a/cinder/api/common.py +++ b/cinder/api/common.py @@ -427,8 +427,9 @@ def reject_invalid_filters(context, filters, resource, "%s~" % key in configured_filters): invalid_filters.append(key) if invalid_filters: - if (resource == 'volume_type' and len(invalid_filters) == 1 - and invalid_filters[0] == 'is_public'): + if 'all_tenants' in invalid_filters: + invalid_filters.remove('all_tenants') + if len(invalid_filters) == 0: return raise webob.exc.HTTPBadRequest( explanation=_('Invalid filters %s are found in query ' diff --git a/cinder/tests/unit/api/test_common.py b/cinder/tests/unit/api/test_common.py index 3dfb4ebc086..14b733f7bf8 100644 --- a/cinder/tests/unit/api/test_common.py +++ b/cinder/tests/unit/api/test_common.py @@ -415,7 +415,7 @@ class GeneralFiltersTest(test.TestCase): 'resource': 'fake_resource'}, {'filters': {'is_public': True}, 'is_admin': False, - 'result': {'volume_type': []}, + 'result': {'volume_type': ["is_public"]}, 'expected': {'is_public': True}, 'resource': 'volume_type'}) @ddt.unpack @@ -485,7 +485,7 @@ class GeneralFiltersTest(test.TestCase): 'expected': ["name", "status", "volume_id", "metadata", "availability_zone"]}, {'resource': 'group_snapshot', - 'expected': ["status", "group_id"]}, + 'expected': ["name", "status", "group_id"]}, {'resource': 'attachment', 'expected': ["volume_id", "status", "instance_id", "attach_status"]}, diff --git a/etc/cinder/resource_filters.json b/etc/cinder/resource_filters.json index 11c191c2432..b0d1c0ad44b 100644 --- a/etc/cinder/resource_filters.json +++ b/etc/cinder/resource_filters.json @@ -5,11 +5,11 @@ "backup": ["name", "status", "volume_id"], "snapshot": ["name", "status", "volume_id", "metadata", "availability_zone"], - "group": [], - "group_snapshot": ["status", "group_id"], + "group": ["name"], + "group_snapshot": ["name", "status", "group_id"], "attachment": ["volume_id", "status", "instance_id", "attach_status"], "message": ["resource_uuid", "resource_type", "event_id", "request_id", "message_level"], "pool": ["name", "volume_type"], - "volume_type": [] + "volume_type": ["is_public"] }