Filter shares by share type "extra_specs"

This change fixes the query being used to filter share
types. We were using an "or" clause instead of an "and" clause,
and that was causing all the extra specs to be shown instead of
the ones that the user specified. With this fix, manila users will
be able to filter shares by share type extra_specs accurately.

Closes-Bug: #1929121

Change-Id: I5cf9788dcafebdf88426617d2824f4be42dbb412
(cherry picked from commit 4fbacf1df1)
(cherry picked from commit 59a0c147df)
This commit is contained in:
Kafilat Adeleke 2021-06-08 08:27:44 +00:00 committed by Goutham Pacha Ravi
parent 783c0777e8
commit 21d5b1b209
2 changed files with 8 additions and 2 deletions

View File

@ -40,6 +40,7 @@ from oslo_utils import excutils
from oslo_utils import timeutils
from oslo_utils import uuidutils
import six
from sqlalchemy import and_
from sqlalchemy import MetaData
from sqlalchemy import or_
from sqlalchemy.orm import joinedload
@ -2002,8 +2003,8 @@ def _process_share_filters(query, filters, project_id=None, is_public=False):
models.ShareTypeExtraSpecs.share_type_id ==
models.ShareInstance.share_type_id)
for k, v in filters['extra_specs'].items():
query = query.filter(or_(models.ShareTypeExtraSpecs.key == k,
models.ShareTypeExtraSpecs.value == v))
query = query.filter(and_(models.ShareTypeExtraSpecs.key == k,
models.ShareTypeExtraSpecs.value == v))
return query

View File

@ -0,0 +1,5 @@
---
fixes:
- |
Filtering shares by share-type "extra_specs" as
key=value now returns the expected output.