Merge "Add --name to port list"

This commit is contained in:
Zuul 2021-03-03 17:03:02 +00:00 committed by Gerrit Code Review
commit 1c84b44ac2
2 changed files with 27 additions and 0 deletions

View File

@ -600,6 +600,11 @@ class ListPort(command.Lister):
metavar='<project>',
help=_("List ports according to their project (name or ID)")
)
parser.add_argument(
'--name',
metavar='<name>',
help=_("List ports according to their name")
)
identity_common.add_project_domain_option_to_parser(parser)
parser.add_argument(
'--fixed-ip',
@ -667,6 +672,8 @@ class ListPort(command.Lister):
).id
filters['tenant_id'] = project_id
filters['project_id'] = project_id
if parsed_args.name:
filters['name'] = parsed_args.name
if parsed_args.fixed_ip:
filters['fixed_ips'] = _prepare_filter_fixed_ips(
self.app.client_manager, parsed_args)

View File

@ -1250,6 +1250,26 @@ class TestListPort(TestPort):
self.assertEqual(self.columns, columns)
self.assertItemsEqual(self.data, list(data))
def test_port_list_name(self):
test_name = "fakename"
arglist = [
'--name', test_name,
]
verifylist = [
('name', test_name),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
filters = {
'name': test_name,
'fields': LIST_FIELDS_TO_RETRIEVE,
}
self.network.ports.assert_called_once_with(**filters)
self.assertEqual(self.columns, columns)
self.assertItemsEqual(self.data, list(data))
def test_list_with_tag_options(self):
arglist = [
'--tags', 'red,blue',