Merge "port: add --host to list command"

This commit is contained in:
Zuul 2020-06-26 01:13:35 +00:00 committed by Gerrit Code Review
commit abfca138d9
2 changed files with 22 additions and 0 deletions

View File

@ -514,6 +514,10 @@ class ListPort(command.Lister):
"This is the entity that uses the port (for example, "
"network:dhcp).")
)
parser.add_argument(
'--host',
metavar='<host-id>',
help=_("List only ports bound to this host ID"))
parser.add_argument(
'--network',
metavar='<network>',
@ -602,6 +606,8 @@ class ListPort(command.Lister):
server = utils.find_resource(compute_client.servers,
parsed_args.server)
filters['device_id'] = server.id
if parsed_args.host:
filters['binding:host_id'] = parsed_args.host
if parsed_args.network:
network = network_client.find_network(parsed_args.network,
ignore_missing=False)

View File

@ -1054,6 +1054,22 @@ class TestListPort(TestPort):
self.assertEqual(self.columns_long, columns)
self.assertListItemEqual(self.data_long, list(data))
def test_port_list_host(self):
arglist = [
'--host', 'foobar',
]
verifylist = [
('host', 'foobar'),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
filters = {'binding:host_id': 'foobar'}
self.network.ports.assert_called_once_with(**filters)
self.assertEqual(self.columns, columns)
self.assertListItemEqual(self.data, list(data))
def test_port_list_project(self):
project = identity_fakes.FakeProject.create_one_project()
self.projects_mock.get.return_value = project