Add option to allow filtering by mac-address on port list

Added support to allow filtering ports via --mac-address
option to the port list command.

Change-Id: I903e443f2f9057571d46520c4cafb88d1972c0cb
Partial-bug: #1634333
Partially-Implements: blueprint network-commands-options
This commit is contained in:
Yan Xing'an 2016-10-17 22:33:35 -07:00
parent 5e3ec1b42f
commit a1e3056414
4 changed files with 42 additions and 2 deletions

View File

@ -127,6 +127,7 @@ List ports
[--device-owner <device-owner>]
[--router <router> | --server <server>]
[--network <network>]
[--mac-address <mac-address>]
[--long]
.. option:: --device-owner <device-owner>
@ -146,6 +147,10 @@ List ports
List only ports attached to this network (name or ID)
.. option:: --mac-address <mac-address>
List only ports with this MAC address
.. option:: --long
List additional fields in output

View File

@ -384,6 +384,11 @@ class ListPort(command.Lister):
metavar='<server>',
help=_("List only ports attached to this server (name or ID)"),
)
parser.add_argument(
'--mac-address',
metavar='<mac-address>',
help=_("List only ports with this MAC address")
)
parser.add_argument(
'--long',
action='store_true',
@ -429,6 +434,8 @@ class ListPort(command.Lister):
network = network_client.find_network(parsed_args.network,
ignore_missing=False)
filters['network_id'] = network.id
if parsed_args.mac_address:
filters['mac_address'] = parsed_args.mac_address
data = network_client.ports(**filters)

View File

@ -530,12 +530,14 @@ class TestListPort(TestPort):
'--device-owner', self._ports[0].device_owner,
'--router', 'fake-router-name',
'--network', 'fake-network-name',
'--mac-address', self._ports[0].mac_address,
]
verifylist = [
('device_owner', self._ports[0].device_owner),
('router', 'fake-router-name'),
('network', 'fake-network-name')
('network', 'fake-network-name'),
('mac_address', self._ports[0].mac_address)
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -545,7 +547,27 @@ class TestListPort(TestPort):
self.network.ports.assert_called_once_with(**{
'device_owner': self._ports[0].device_owner,
'device_id': 'fake-router-id',
'network_id': 'fake-network-id'
'network_id': 'fake-network-id',
'mac_address': self._ports[0].mac_address
})
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, list(data))
def test_port_list_mac_address_opt(self):
arglist = [
'--mac-address', self._ports[0].mac_address,
]
verifylist = [
('mac_address', self._ports[0].mac_address)
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
self.network.ports.assert_called_once_with(**{
'mac_address': self._ports[0].mac_address
})
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, list(data))

View File

@ -0,0 +1,6 @@
---
features:
- |
Add support to allow filtering ports via ``--mac-address``
option to the ``port list`` command.
[Bug `1634333 <https://bugs.launchpad.net/bugs/1634333>`_]