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
This commit is contained in:
Kafilat Adeleke 2021-06-08 08:27:44 +00:00
parent 4bfea794d7
commit 4fbacf1df1
2 changed files with 8 additions and 2 deletions

View File

@ -42,6 +42,7 @@ from oslo_utils import importutils
from oslo_utils import timeutils
from oslo_utils import uuidutils
import sqlalchemy
from sqlalchemy import and_
from sqlalchemy import MetaData
from sqlalchemy import or_
from sqlalchemy.orm import joinedload
@ -2016,8 +2017,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.