Add new filter options for share server list

After share server migration and manage/unmanage of share servers
were implemented, share servers can be filtered by their source
share server ID field, as well as the back end identifier. So we
add these fields to the share servers list to be used as a search
option.

Change-Id: I8071f7218101f9fcee059d943494b5914a89ba1a
Closes-Bug: #2068631
This commit is contained in:
Carlos da Silva 2024-07-19 19:50:54 +00:00 committed by Carlos Eduardo
parent 0e74a7bcf2
commit c8b1665d63
4 changed files with 96 additions and 0 deletions

View File

@ -146,6 +146,23 @@ class ListShareServer(command.Lister):
"Available for microversion >= 2.51 (Optional, "
"Default=None)")
)
parser.add_argument(
'--source-share-server-id',
metavar='<source-share-server-id>',
type=str,
default=None,
help=_("Share server ID to be used as a filter. Available for "
"microversion >= 2.57 (Optional, Default=None)")
)
parser.add_argument(
'--identifier',
metavar='<identifier>',
type=str,
default=None,
help=_("Identifier of the share server in the share back end. "
"Available for microversion >= 2.49 "
"(Optional, Default=None)")
)
identity_common.add_project_domain_option_to_parser(parser)
return parser
@ -160,12 +177,24 @@ class ListShareServer(command.Lister):
parsed_args.project,
parsed_args.project_domain).id
if (parsed_args.identifier and
share_client.api_version < api_versions.APIVersion("2.49")):
raise exceptions.CommandError(
"Filtering by identifier is only allowed with manila API "
"version >= 2.49."
)
if (parsed_args.share_network_subnet and
share_client.api_version < api_versions.APIVersion("2.51")):
raise exceptions.CommandError(
"Share network subnet can be specified only with manila API "
"version >= 2.51"
)
if (parsed_args.source_share_server_id and
share_client.api_version < api_versions.APIVersion("2.57")):
raise exceptions.CommandError(
"Filtering by source_share_server_id is only allowed with "
"manila API version >= 2.57."
)
columns = [
'ID',
@ -187,6 +216,16 @@ class ListShareServer(command.Lister):
parsed_args.share_network).id
search_opts['share_network'] = share_network_id
if parsed_args.source_share_server_id:
search_opts['source_share_server_id'] = (
parsed_args.source_share_server_id
)
if parsed_args.identifier:
search_opts['identifier'] = (
parsed_args.identifier
)
if parsed_args.share_network_subnet:
search_opts['share_network_subnet_id'] = (
parsed_args.share_network_subnet)

View File

@ -1495,6 +1495,7 @@ class FakeShareServer(object):
'share_network_name': None,
'share_network_id': str(uuid.uuid4()),
'share_network_subnet_id': str(uuid.uuid4()),
'source_share_server_id': str(uuid.uuid4()),
'created_at': datetime.datetime.now().isoformat(),
'is_auto_deletable': False,
'identifier': str(uuid.uuid4())

View File

@ -219,6 +219,56 @@ class TestListShareServer(TestShareServer):
self.assertEqual(self.columns, columns)
self.assertEqual(list(self.values), list(data))
def test_share_server_list_by_source_share_server(self):
expected_source_share_server_id = (
self.servers_list[0].source_share_server_id
)
arglist = [
'--source-share-server-id', expected_source_share_server_id,
]
verifylist = [
('source_share_server_id', expected_source_share_server_id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
search_opts = {
'status': None,
'host': None,
'project_id': None,
'source_share_server_id': expected_source_share_server_id,
}
self.servers_mock.list.assert_called_once_with(
search_opts=search_opts,
)
self.assertEqual(self.columns, columns)
self.assertEqual(list(self.values), list(data))
def test_share_server_list_by_identifier(self):
expected_identifier = self.servers_list[0].identifier
arglist = ['--identifier', expected_identifier,]
verifylist = [('identifier', expected_identifier),]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
search_opts = {
'status': None,
'host': None,
'project_id': None,
'identifier': expected_identifier,
}
self.servers_mock.list.assert_called_once_with(
search_opts=search_opts,
)
self.assertEqual(self.columns, columns)
self.assertEqual(list(self.values), list(data))
class TestAdoptShareServer(TestShareServer):

View File

@ -0,0 +1,6 @@
---
fixes:
- |
Share server list command now support filtering share servers by source
share server IDs and identifiers. For more details, please refer to
`Launchpad bug #1896949 <https://bugs.launchpad.net/python-manilaclient/+bug/2068631>`_.