Add "router remove port" to osc

This patch proposes the migration of port
deletion of Neutron's "router-interface-delete"
to OSC's "router remove port".

Change-Id: Ifceabce080aacac9f6410c809fcc097760e0c5ee
Partial-Bug: #1546849
Implements: blueprint neutron-client-advanced-router
This commit is contained in:
reedip 2016-03-19 12:04:00 +09:00 committed by Reedip
parent 2e94f2803f
commit 8ecdc57ea6
5 changed files with 96 additions and 2 deletions

View File

@ -6,6 +6,7 @@ Network v2
router add port
---------------
Add a port to a router
.. program:: router add port
@ -102,6 +103,29 @@ List routers
List additional fields in output
router remove port
------------------
Remove a port from a router
.. program:: router remove port
.. code:: bash
os router remove port
<router>
<port>
.. _router_remove_port:
.. describe:: <router>
Router from which port will be removed (name or ID)
.. describe:: <port>
Port to be removed (name or ID)
router set
----------
@ -167,4 +191,4 @@ Display router details
.. _router_show-router:
.. describe:: <router>
Router to display (name or ID)
Router to display (name or ID)

View File

@ -241,6 +241,30 @@ class ListRouter(command.Lister):
) for s in data))
class RemovePortFromRouter(command.Command):
"""Remove a port from a router"""
def get_parser(self, prog_name):
parser = super(RemovePortFromRouter, self).get_parser(prog_name)
parser.add_argument(
'router',
metavar='<router>',
help="Router from which port will be removed (name or ID)",
)
parser.add_argument(
'port',
metavar='<port>',
help="Port to be removed (name or ID).",
)
return parser
def take_action(self, parsed_args):
client = self.app.client_manager.network
port = client.find_port(parsed_args.port, ignore_missing=False)
client.router_remove_interface(client.find_router(
parsed_args.router, ignore_missing=False), port_id=port.id)
class SetRouter(command.Command):
"""Set router properties"""
@ -342,4 +366,4 @@ class ShowRouter(command.ShowOne):
obj = client.find_router(parsed_args.router, ignore_missing=False)
columns = _get_columns(obj)
data = utils.get_item_properties(obj, columns, formatters=_formatters)
return columns, data
return columns, data

View File

@ -269,6 +269,46 @@ class TestListRouter(TestRouter):
self.assertEqual(self.data_long, list(data))
class TestRemovePortFromRouter(TestRouter):
'''Remove port from a Router '''
_port = network_fakes.FakePort.create_one_port()
_router = network_fakes.FakeRouter.create_one_router(
attrs={'port': _port.id})
def setUp(self):
super(TestRemovePortFromRouter, self).setUp()
self.network.router_remove_interface = mock.Mock()
self.cmd = router.RemovePortFromRouter(self.app, self.namespace)
self.network.find_router = mock.Mock(return_value=self._router)
self.network.find_port = mock.Mock(return_value=self._port)
def test_remove_port_no_option(self):
arglist = []
verifylist = []
# Missing required args should bail here
self.assertRaises(tests_utils.ParserException, self.check_parser,
self.cmd, arglist, verifylist)
def test_remove_port_required_options(self):
arglist = [
self._router.id,
self._router.port,
]
verifylist = [
('router', self._router.id),
('port', self._router.port),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
self.network.router_remove_interface.assert_called_with(
self._router, **{'port_id': self._router.port})
self.assertIsNone(result)
class TestSetRouter(TestRouter):
# The router to set.

View File

@ -0,0 +1,5 @@
---
features:
- |
Add ``router remove port`` command
[Bug `1546849 <https://bugs.launchpad.net/bugs/1546849>`_]

View File

@ -342,6 +342,7 @@ openstack.network.v2 =
router_create = openstackclient.network.v2.router:CreateRouter
router_delete = openstackclient.network.v2.router:DeleteRouter
router_list = openstackclient.network.v2.router:ListRouter
router_remove_port = openstackclient.network.v2.router:RemovePortFromRouter
router_set = openstackclient.network.v2.router:SetRouter
router_show = openstackclient.network.v2.router:ShowRouter