Merge "Support filter search for share type API"
This commit is contained in:
commit
fdd6f34599
@ -193,15 +193,16 @@ export_location_path_query:
|
||||
required: false
|
||||
type: string
|
||||
min_version: 2.35
|
||||
extra_specs_1:
|
||||
extra_specs_query:
|
||||
description: |
|
||||
The extra specifications as a set of one or more
|
||||
key-value pairs. In each pair, the key is the name of the extra
|
||||
specification and the value is the share type that was used to
|
||||
create the share.
|
||||
filter search share type list.
|
||||
in: query
|
||||
required: false
|
||||
type: string
|
||||
min_version: 2.43
|
||||
group_snapshot_description_query:
|
||||
description: |
|
||||
The share group snapshot description that can be used to filter
|
||||
|
@ -105,6 +105,7 @@ Request
|
||||
.. rest_parameters:: parameters.yaml
|
||||
|
||||
- tenant_id: tenant_id_path
|
||||
- extra_specs: extra_specs_query
|
||||
|
||||
Response parameters
|
||||
-------------------
|
||||
|
@ -113,13 +113,14 @@ REST_API_VERSION_HISTORY = """
|
||||
* 2.40 - Added share group and share group snapshot quotas.
|
||||
* 2.41 - Added 'description' in share type create/list APIs.
|
||||
* 2.42 - Added ``with_count`` in share list API to get total count info.
|
||||
* 2.43 - Added filter search by extra spec for share type list.
|
||||
"""
|
||||
|
||||
# The minimum and maximum versions of the API supported
|
||||
# The default api version request is defined to be the
|
||||
# minimum version of the API supported.
|
||||
_MIN_API_VERSION = "2.0"
|
||||
_MAX_API_VERSION = "2.42"
|
||||
_MAX_API_VERSION = "2.43"
|
||||
DEFAULT_API_VERSION = _MIN_API_VERSION
|
||||
|
||||
|
||||
|
@ -234,3 +234,7 @@ user documentation.
|
||||
2.42
|
||||
----
|
||||
Added ``with_count`` in share list API to get total count info.
|
||||
|
||||
2.43
|
||||
----
|
||||
Added filter search by extra spec for share type list.
|
||||
|
@ -15,6 +15,8 @@
|
||||
|
||||
"""The share type API controller module.."""
|
||||
|
||||
import ast
|
||||
|
||||
from oslo_log import log
|
||||
from oslo_utils import strutils
|
||||
from oslo_utils import uuidutils
|
||||
@ -123,6 +125,19 @@ class ShareTypesController(wsgi.Controller):
|
||||
req.params.get('is_public'))
|
||||
else:
|
||||
filters['is_public'] = True
|
||||
|
||||
if (req.api_version_request < api_version.APIVersionRequest("2.43")):
|
||||
extra_specs = req.params.get('extra_specs')
|
||||
if extra_specs:
|
||||
msg = _("Filter by 'extra_specs' is not supported by this "
|
||||
"microversion. Use 2.43 or greater microversion to "
|
||||
"be able to use filter search by 'extra_specs.")
|
||||
raise webob.exc.HTTPBadRequest(explanation=msg)
|
||||
else:
|
||||
extra_specs = req.params.get('extra_specs')
|
||||
if extra_specs:
|
||||
filters['extra_specs'] = ast.literal_eval(extra_specs)
|
||||
|
||||
limited_types = share_types.get_all_types(
|
||||
context, search_opts=filters).values()
|
||||
return list(limited_types)
|
||||
|
@ -91,8 +91,15 @@ def get_all_types(context, inactive=0, search_opts=None):
|
||||
|
||||
type_args['required_extra_specs'] = required_extra_specs
|
||||
|
||||
search_vars = {}
|
||||
if 'extra_specs' in search_opts:
|
||||
search_vars['extra_specs'] = search_opts.pop('extra_specs')
|
||||
search_vars = search_opts.get('extra_specs')
|
||||
|
||||
if search_opts:
|
||||
LOG.debug("Searching by: %s", search_opts)
|
||||
return {}
|
||||
elif search_vars:
|
||||
LOG.debug("Searching by: %s", search_vars)
|
||||
|
||||
def _check_extra_specs_match(share_type, searchdict):
|
||||
for k, v in searchdict.items():
|
||||
@ -107,7 +114,7 @@ def get_all_types(context, inactive=0, search_opts=None):
|
||||
result = {}
|
||||
for type_name, type_args in share_types.items():
|
||||
# go over all filters in the list
|
||||
for opt, values in search_opts.items():
|
||||
for opt, values in search_vars.items():
|
||||
try:
|
||||
filter_func = filter_mapping[opt]
|
||||
except KeyError:
|
||||
|
@ -71,6 +71,28 @@ class ShareTypesTestCase(test.TestCase):
|
||||
}
|
||||
}
|
||||
|
||||
fake_r_extra_specs = {
|
||||
u'gold': u'True',
|
||||
u'driver_handles_share_servers': u'True'
|
||||
}
|
||||
|
||||
fake_r_required_extra_specs = {
|
||||
u'driver_handles_share_servers': u'True'
|
||||
}
|
||||
|
||||
fake_r_type_extra = {
|
||||
'test_with_extra': {
|
||||
'created_at': datetime.datetime(2015, 1, 22, 11, 45, 31),
|
||||
'deleted': '0',
|
||||
'deleted_at': None,
|
||||
'extra_specs': fake_r_extra_specs,
|
||||
'required_extra_specs': fake_r_required_extra_specs,
|
||||
'id': fake_share_type_id,
|
||||
'name': u'test_with_extra',
|
||||
'updated_at': None
|
||||
}
|
||||
}
|
||||
|
||||
fake_required_extra_specs = {
|
||||
constants.ExtraSpecs.DRIVER_HANDLES_SHARE_SERVERS: 'true',
|
||||
}
|
||||
@ -114,7 +136,7 @@ class ShareTypesTestCase(test.TestCase):
|
||||
|
||||
def test_get_all_types_search(self):
|
||||
share_type = self.fake_type_w_extra
|
||||
search_filter = {"extra_specs": {"gold": "True"}, 'is_public': True}
|
||||
search_filter = {'extra_specs': {'gold': 'True'}, 'is_public': True}
|
||||
self.mock_object(db,
|
||||
'share_type_get_all',
|
||||
mock.Mock(return_value=share_type))
|
||||
@ -122,11 +144,18 @@ class ShareTypesTestCase(test.TestCase):
|
||||
search_opts=search_filter)
|
||||
db.share_type_get_all.assert_called_once_with(
|
||||
mock.ANY, 0, filters={'is_public': True})
|
||||
|
||||
self.assertItemsEqual(share_type, returned_type)
|
||||
search_filter = {"extra_specs": {"gold": "False"}}
|
||||
search_filter = {'extra_specs': {'gold': 'False'}}
|
||||
returned_type = share_types.get_all_types(self.context,
|
||||
search_opts=search_filter)
|
||||
self.assertEqual({}, returned_type)
|
||||
self.assertEqual(share_type, returned_type)
|
||||
|
||||
share_type = self.fake_r_type_extra
|
||||
search_filter = {'extra_specs': {'gold': 'True'}}
|
||||
returned_type = share_types.get_all_types(self.context,
|
||||
search_opts=search_filter)
|
||||
self.assertItemsEqual(share_type, returned_type)
|
||||
|
||||
def test_get_share_type_extra_specs(self):
|
||||
share_type = self.fake_type_w_extra['test_with_extra']
|
||||
|
@ -0,0 +1,3 @@
|
||||
---
|
||||
features:
|
||||
- Share types can now be filtered with its extra_specs.
|
Loading…
Reference in New Issue
Block a user