Add support for ~name and ~description filtering when listing shares.
This fix addresses a TODO item for the "openstack share list" command. It adds support for ~name and ~description filtering when listing shares. Closes-Bug: #1949091 Change-Id: If6bb9e7d379672116d88012682069686f5aedb52
This commit is contained in:
parent
0f9ba9a7d3
commit
b5a4f9c396
|
@ -461,6 +461,20 @@ class ListShare(command.Lister):
|
||||||
metavar="<share>",
|
metavar="<share>",
|
||||||
help=_('The last share ID of the previous page'),
|
help=_('The last share ID of the previous page'),
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--name~",
|
||||||
|
metavar="<name~>",
|
||||||
|
default=None,
|
||||||
|
help=_("Filter results matching a share name pattern. "
|
||||||
|
"Available only for microversion >= 2.36.")
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--description~',
|
||||||
|
metavar="<description~>",
|
||||||
|
default=None,
|
||||||
|
help=_("Filter results matching a share description pattern."
|
||||||
|
"Available only for microversion >= 2.36.")
|
||||||
|
)
|
||||||
|
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
@ -468,8 +482,7 @@ class ListShare(command.Lister):
|
||||||
share_client = self.app.client_manager.share
|
share_client = self.app.client_manager.share
|
||||||
identity_client = self.app.client_manager.identity
|
identity_client = self.app.client_manager.identity
|
||||||
|
|
||||||
# TODO(gouthamr): Add support for ~name, ~description
|
# TODO(gouthamr): Add support for export_location filtering
|
||||||
# export_location filtering
|
|
||||||
if parsed_args.long:
|
if parsed_args.long:
|
||||||
columns = SHARE_ATTRIBUTES
|
columns = SHARE_ATTRIBUTES
|
||||||
column_headers = SHARE_ATTRIBUTES_HEADERS
|
column_headers = SHARE_ATTRIBUTES_HEADERS
|
||||||
|
@ -563,6 +576,15 @@ class ListShare(command.Lister):
|
||||||
|
|
||||||
# NOTE(vkmc) We implemented sorting and filtering in manilaclient
|
# NOTE(vkmc) We implemented sorting and filtering in manilaclient
|
||||||
# but we will use the one provided by osc
|
# but we will use the one provided by osc
|
||||||
|
if share_client.api_version >= api_versions.APIVersion("2.36"):
|
||||||
|
search_opts['name~'] = getattr(parsed_args, 'name~')
|
||||||
|
search_opts['description~'] = getattr(parsed_args, 'description~')
|
||||||
|
elif (getattr(parsed_args, 'name~') or
|
||||||
|
getattr(parsed_args, 'description~')):
|
||||||
|
raise exceptions.CommandError(
|
||||||
|
"Pattern based filtering (name~ and description~)"
|
||||||
|
" is only available with manila API version >= 2.36")
|
||||||
|
|
||||||
data = share_client.shares.list(search_opts=search_opts)
|
data = share_client.shares.list(search_opts=search_opts)
|
||||||
data = oscutils.sort_items(data, parsed_args.sort, str)
|
data = oscutils.sort_items(data, parsed_args.sort, str)
|
||||||
|
|
||||||
|
|
|
@ -535,6 +535,8 @@ class TestShareList(TestShare):
|
||||||
'project_id': None,
|
'project_id': None,
|
||||||
'user_id': None,
|
'user_id': None,
|
||||||
'offset': None,
|
'offset': None,
|
||||||
|
'name~': None,
|
||||||
|
'description~': None,
|
||||||
}
|
}
|
||||||
return search_opts
|
return search_opts
|
||||||
|
|
||||||
|
@ -550,24 +552,7 @@ class TestShareList(TestShare):
|
||||||
|
|
||||||
cmd_columns, cmd_data = self.cmd.take_action(parsed_args)
|
cmd_columns, cmd_data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
search_opts = {
|
search_opts = self._get_search_opts()
|
||||||
'all_tenants': False,
|
|
||||||
'is_public': False,
|
|
||||||
'metadata': {},
|
|
||||||
'extra_specs': {},
|
|
||||||
'limit': None,
|
|
||||||
'name': None,
|
|
||||||
'status': None,
|
|
||||||
'host': None,
|
|
||||||
'share_server_id': None,
|
|
||||||
'share_network_id': None,
|
|
||||||
'share_type_id': None,
|
|
||||||
'snapshot_id': None,
|
|
||||||
'share_group_id': None,
|
|
||||||
'project_id': None,
|
|
||||||
'user_id': None,
|
|
||||||
'offset': None,
|
|
||||||
}
|
|
||||||
|
|
||||||
self.shares_mock.list.assert_called_once_with(
|
self.shares_mock.list.assert_called_once_with(
|
||||||
search_opts=search_opts,
|
search_opts=search_opts,
|
||||||
|
@ -593,24 +578,7 @@ class TestShareList(TestShare):
|
||||||
|
|
||||||
cmd_columns, cmd_data = self.cmd.take_action(parsed_args)
|
cmd_columns, cmd_data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
search_opts = {
|
search_opts = self._get_search_opts()
|
||||||
'all_tenants': False,
|
|
||||||
'is_public': False,
|
|
||||||
'metadata': {},
|
|
||||||
'extra_specs': {},
|
|
||||||
'limit': None,
|
|
||||||
'name': None,
|
|
||||||
'status': None,
|
|
||||||
'host': None,
|
|
||||||
'share_server_id': None,
|
|
||||||
'share_network_id': None,
|
|
||||||
'share_type_id': None,
|
|
||||||
'snapshot_id': None,
|
|
||||||
'share_group_id': None,
|
|
||||||
'project_id': None,
|
|
||||||
'user_id': None,
|
|
||||||
'offset': None,
|
|
||||||
}
|
|
||||||
|
|
||||||
search_opts['project_id'] = self.project.id
|
search_opts['project_id'] = self.project.id
|
||||||
search_opts['all_tenants'] = True
|
search_opts['all_tenants'] = True
|
||||||
|
@ -641,24 +609,7 @@ class TestShareList(TestShare):
|
||||||
|
|
||||||
cmd_columns, cmd_data = self.cmd.take_action(parsed_args)
|
cmd_columns, cmd_data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
search_opts = {
|
search_opts = self._get_search_opts()
|
||||||
'all_tenants': False,
|
|
||||||
'is_public': False,
|
|
||||||
'metadata': {},
|
|
||||||
'extra_specs': {},
|
|
||||||
'limit': None,
|
|
||||||
'name': None,
|
|
||||||
'status': None,
|
|
||||||
'host': None,
|
|
||||||
'share_server_id': None,
|
|
||||||
'share_network_id': None,
|
|
||||||
'share_type_id': None,
|
|
||||||
'snapshot_id': None,
|
|
||||||
'share_group_id': None,
|
|
||||||
'project_id': None,
|
|
||||||
'user_id': None,
|
|
||||||
'offset': None,
|
|
||||||
}
|
|
||||||
|
|
||||||
search_opts['project_id'] = self.project.id
|
search_opts['project_id'] = self.project.id
|
||||||
search_opts['all_tenants'] = True
|
search_opts['all_tenants'] = True
|
||||||
|
@ -687,24 +638,7 @@ class TestShareList(TestShare):
|
||||||
|
|
||||||
cmd_columns, cmd_data = self.cmd.take_action(parsed_args)
|
cmd_columns, cmd_data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
search_opts = {
|
search_opts = self._get_search_opts()
|
||||||
'all_tenants': False,
|
|
||||||
'is_public': False,
|
|
||||||
'metadata': {},
|
|
||||||
'extra_specs': {},
|
|
||||||
'limit': None,
|
|
||||||
'name': None,
|
|
||||||
'status': None,
|
|
||||||
'host': None,
|
|
||||||
'share_server_id': None,
|
|
||||||
'share_network_id': None,
|
|
||||||
'share_type_id': None,
|
|
||||||
'snapshot_id': None,
|
|
||||||
'share_group_id': None,
|
|
||||||
'project_id': None,
|
|
||||||
'user_id': None,
|
|
||||||
'offset': None,
|
|
||||||
}
|
|
||||||
|
|
||||||
search_opts['user_id'] = self.user.id
|
search_opts['user_id'] = self.user.id
|
||||||
|
|
||||||
|
@ -733,24 +667,7 @@ class TestShareList(TestShare):
|
||||||
|
|
||||||
cmd_columns, cmd_data = self.cmd.take_action(parsed_args)
|
cmd_columns, cmd_data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
search_opts = {
|
search_opts = self._get_search_opts()
|
||||||
'all_tenants': False,
|
|
||||||
'is_public': False,
|
|
||||||
'metadata': {},
|
|
||||||
'extra_specs': {},
|
|
||||||
'limit': None,
|
|
||||||
'name': None,
|
|
||||||
'status': None,
|
|
||||||
'host': None,
|
|
||||||
'share_server_id': None,
|
|
||||||
'share_network_id': None,
|
|
||||||
'share_type_id': None,
|
|
||||||
'snapshot_id': None,
|
|
||||||
'share_group_id': None,
|
|
||||||
'project_id': None,
|
|
||||||
'user_id': None,
|
|
||||||
'offset': None,
|
|
||||||
}
|
|
||||||
|
|
||||||
search_opts['user_id'] = self.user.id
|
search_opts['user_id'] = self.user.id
|
||||||
|
|
||||||
|
@ -778,24 +695,7 @@ class TestShareList(TestShare):
|
||||||
|
|
||||||
cmd_columns, cmd_data = self.cmd.take_action(parsed_args)
|
cmd_columns, cmd_data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
search_opts = {
|
search_opts = self._get_search_opts()
|
||||||
'all_tenants': False,
|
|
||||||
'is_public': False,
|
|
||||||
'metadata': {},
|
|
||||||
'extra_specs': {},
|
|
||||||
'limit': None,
|
|
||||||
'name': None,
|
|
||||||
'status': None,
|
|
||||||
'host': None,
|
|
||||||
'share_server_id': None,
|
|
||||||
'share_network_id': None,
|
|
||||||
'share_type_id': None,
|
|
||||||
'snapshot_id': None,
|
|
||||||
'share_group_id': None,
|
|
||||||
'project_id': None,
|
|
||||||
'user_id': None,
|
|
||||||
'offset': None,
|
|
||||||
}
|
|
||||||
|
|
||||||
search_opts['name'] = self.new_share.name
|
search_opts['name'] = self.new_share.name
|
||||||
|
|
||||||
|
@ -823,24 +723,7 @@ class TestShareList(TestShare):
|
||||||
|
|
||||||
cmd_columns, cmd_data = self.cmd.take_action(parsed_args)
|
cmd_columns, cmd_data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
search_opts = {
|
search_opts = self._get_search_opts()
|
||||||
'all_tenants': False,
|
|
||||||
'is_public': False,
|
|
||||||
'metadata': {},
|
|
||||||
'extra_specs': {},
|
|
||||||
'limit': None,
|
|
||||||
'name': None,
|
|
||||||
'status': None,
|
|
||||||
'host': None,
|
|
||||||
'share_server_id': None,
|
|
||||||
'share_network_id': None,
|
|
||||||
'share_type_id': None,
|
|
||||||
'snapshot_id': None,
|
|
||||||
'share_group_id': None,
|
|
||||||
'project_id': None,
|
|
||||||
'user_id': None,
|
|
||||||
'offset': None,
|
|
||||||
}
|
|
||||||
|
|
||||||
search_opts['status'] = self.new_share.status
|
search_opts['status'] = self.new_share.status
|
||||||
|
|
||||||
|
@ -868,24 +751,7 @@ class TestShareList(TestShare):
|
||||||
|
|
||||||
cmd_columns, cmd_data = self.cmd.take_action(parsed_args)
|
cmd_columns, cmd_data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
search_opts = {
|
search_opts = self._get_search_opts()
|
||||||
'all_tenants': False,
|
|
||||||
'is_public': False,
|
|
||||||
'metadata': {},
|
|
||||||
'extra_specs': {},
|
|
||||||
'limit': None,
|
|
||||||
'name': None,
|
|
||||||
'status': None,
|
|
||||||
'host': None,
|
|
||||||
'share_server_id': None,
|
|
||||||
'share_network_id': None,
|
|
||||||
'share_type_id': None,
|
|
||||||
'snapshot_id': None,
|
|
||||||
'share_group_id': None,
|
|
||||||
'project_id': None,
|
|
||||||
'user_id': None,
|
|
||||||
'offset': None,
|
|
||||||
}
|
|
||||||
|
|
||||||
search_opts['all_tenants'] = True
|
search_opts['all_tenants'] = True
|
||||||
|
|
||||||
|
@ -912,24 +778,7 @@ class TestShareList(TestShare):
|
||||||
|
|
||||||
cmd_columns, cmd_data = self.cmd.take_action(parsed_args)
|
cmd_columns, cmd_data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
search_opts = {
|
search_opts = self._get_search_opts()
|
||||||
'all_tenants': False,
|
|
||||||
'is_public': False,
|
|
||||||
'metadata': {},
|
|
||||||
'extra_specs': {},
|
|
||||||
'limit': None,
|
|
||||||
'name': None,
|
|
||||||
'status': None,
|
|
||||||
'host': None,
|
|
||||||
'share_server_id': None,
|
|
||||||
'share_network_id': None,
|
|
||||||
'share_type_id': None,
|
|
||||||
'snapshot_id': None,
|
|
||||||
'share_group_id': None,
|
|
||||||
'project_id': None,
|
|
||||||
'user_id': None,
|
|
||||||
'offset': None,
|
|
||||||
}
|
|
||||||
|
|
||||||
self.shares_mock.list.assert_called_once_with(
|
self.shares_mock.list.assert_called_once_with(
|
||||||
search_opts=search_opts,
|
search_opts=search_opts,
|
||||||
|
@ -1019,24 +868,10 @@ class TestShareList(TestShare):
|
||||||
|
|
||||||
self.assertEqual(self.columns, cmd_columns)
|
self.assertEqual(self.columns, cmd_columns)
|
||||||
|
|
||||||
search_opts = {
|
search_opts = self._get_search_opts()
|
||||||
'all_tenants': False,
|
|
||||||
'is_public': False,
|
search_opts['limit'] = 2
|
||||||
'metadata': {},
|
search_opts['offset'] = self.new_share.id
|
||||||
'extra_specs': {},
|
|
||||||
'limit': 2,
|
|
||||||
'name': None,
|
|
||||||
'status': None,
|
|
||||||
'host': None,
|
|
||||||
'share_server_id': None,
|
|
||||||
'share_network_id': None,
|
|
||||||
'share_type_id': None,
|
|
||||||
'snapshot_id': None,
|
|
||||||
'share_group_id': None,
|
|
||||||
'project_id': None,
|
|
||||||
'user_id': None,
|
|
||||||
'offset': self.new_share.id
|
|
||||||
}
|
|
||||||
|
|
||||||
data = self._get_data()
|
data = self._get_data()
|
||||||
|
|
||||||
|
@ -1055,6 +890,55 @@ class TestShareList(TestShare):
|
||||||
self.assertRaises(argparse.ArgumentTypeError, self.check_parser,
|
self.assertRaises(argparse.ArgumentTypeError, self.check_parser,
|
||||||
self.cmd, arglist, verifylist)
|
self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
def test_share_list_name_description_filter(self):
|
||||||
|
arglist = [
|
||||||
|
'--name~', self.new_share.name,
|
||||||
|
'--description~', self.new_share.description,
|
||||||
|
]
|
||||||
|
|
||||||
|
verifylist = [
|
||||||
|
('name~', self.new_share.name),
|
||||||
|
('description~', self.new_share.description),
|
||||||
|
]
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
cmd_columns, cmd_data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
search_opts = self._get_search_opts()
|
||||||
|
|
||||||
|
search_opts['name~'] = self.new_share.name
|
||||||
|
search_opts['description~'] = self.new_share.description
|
||||||
|
|
||||||
|
self.shares_mock.list.assert_called_once_with(
|
||||||
|
search_opts=search_opts,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(self.columns, cmd_columns)
|
||||||
|
|
||||||
|
data = self._get_data()
|
||||||
|
|
||||||
|
self.assertEqual(data, tuple(cmd_data))
|
||||||
|
|
||||||
|
def test_list_share_api_version_exception(self):
|
||||||
|
self.app.client_manager.share.api_version = api_versions.APIVersion(
|
||||||
|
"2.35")
|
||||||
|
|
||||||
|
arglist = [
|
||||||
|
'--name~', 'Name',
|
||||||
|
'--description~', 'Description',
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('name~', 'Name'),
|
||||||
|
('description~', 'Description'),
|
||||||
|
]
|
||||||
|
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
self.assertRaises(
|
||||||
|
osc_exceptions.CommandError,
|
||||||
|
self.cmd.take_action,
|
||||||
|
parsed_args)
|
||||||
|
|
||||||
|
|
||||||
class TestShareShow(TestShare):
|
class TestShareShow(TestShare):
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue