summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHideki Saito <saito@fgrep.org>2016-05-14 20:48:43 +0900
committerHideki Saito <saito@fgrep.org>2016-05-16 12:02:00 +0900
commitbc93ebfe5c0fa4d29b79fa3fd93ec603425997ea (patch)
treedcca43cba5bf88c6c9cd769c0aca07a96c26cbf3
parente1c53250bcf430517d254ada998e78b057a56a49 (diff)
downloadpython-openstackclient-bc93ebfe5c0fa4d29b79fa3fd93ec603425997ea.tar.gz
Added --no-route to the router set command
Deprecated --clear-routes Closes-Bug #1565034 Change-Id: I4a8975edc026aecd2a362fd1929c984cfab8ade6
-rw-r--r--doc/source/command-objects/router.rst4
-rw-r--r--openstackclient/network/v2/router.py20
-rw-r--r--openstackclient/tests/network/v2/test_router.py36
-rw-r--r--releasenotes/notes/bug-1565034-dd404bfb42d7778d.yaml5
4 files changed, 61 insertions, 4 deletions
diff --git a/doc/source/command-objects/router.rst b/doc/source/command-objects/router.rst
index 1bb9341e..9ca7661e 100644
--- a/doc/source/command-objects/router.rst
+++ b/doc/source/command-objects/router.rst
@@ -186,7 +186,7 @@ Set router properties
[--name <name>]
[--enable | --disable]
[--distributed | --centralized]
- [--route destination=<subnet>,gateway=<ip-address> | --clear-routes]
+ [--route destination=<subnet>,gateway=<ip-address> | --no-route]
<router>
.. option:: --name <name>
@@ -216,7 +216,7 @@ Set router properties
gateway: nexthop IP address
(repeat option to set multiple routes)
-.. option:: --clear-routes
+.. option:: --no-route
Clear routes associated with the router
diff --git a/openstackclient/network/v2/router.py b/openstackclient/network/v2/router.py
index a32ab5ea..e479eee3 100644
--- a/openstackclient/network/v2/router.py
+++ b/openstackclient/network/v2/router.py
@@ -13,7 +13,9 @@
"""Router action implementations"""
+import argparse
import json
+import logging
from openstackclient.common import command
from openstackclient.common import exceptions
@@ -23,6 +25,9 @@ from openstackclient.i18n import _
from openstackclient.identity import common as identity_common
+LOG = logging.getLogger(__name__)
+
+
def _format_admin_state(state):
return 'UP' if state else 'DOWN'
@@ -379,10 +384,15 @@ class SetRouter(command.Command):
"(repeat option to set multiple routes)")
)
routes_group.add_argument(
- '--clear-routes',
+ '--no-route',
action='store_true',
help=_("Clear routes associated with the router")
)
+ routes_group.add_argument(
+ '--clear-routes',
+ action='store_true',
+ help=argparse.SUPPRESS,
+ )
# TODO(tangchen): Support setting 'ha' property in 'router set'
# command. It appears that changing the ha state is supported by
@@ -401,8 +411,14 @@ class SetRouter(command.Command):
attrs = _get_attrs(self.app.client_manager, parsed_args)
# Get the route attributes.
- if parsed_args.clear_routes:
+ if parsed_args.no_route:
+ attrs['routes'] = []
+ elif parsed_args.clear_routes:
attrs['routes'] = []
+ LOG.warning(_(
+ 'The --clear-routes option is deprecated, '
+ 'please use --no-route instead.'
+ ))
elif parsed_args.routes is not None:
# Map the route keys and append to the current routes.
# The REST API will handle route validation and duplicates.
diff --git a/openstackclient/tests/network/v2/test_router.py b/openstackclient/tests/network/v2/test_router.py
index 655e86c9..99b41d2d 100644
--- a/openstackclient/tests/network/v2/test_router.py
+++ b/openstackclient/tests/network/v2/test_router.py
@@ -495,6 +495,42 @@ class TestSetRouter(TestRouter):
self._router, **attrs)
self.assertIsNone(result)
+ def test_set_no_route(self):
+ arglist = [
+ self._router.name,
+ '--no-route',
+ ]
+ verifylist = [
+ ('router', self._router.name),
+ ('no_route', True),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ result = self.cmd.take_action(parsed_args)
+
+ attrs = {
+ 'routes': [],
+ }
+ self.network.update_router.assert_called_once_with(
+ self._router, **attrs)
+ self.assertIsNone(result)
+
+ def test_set_route_no_route(self):
+ arglist = [
+ self._router.name,
+ '--route', 'destination=10.20.30.0/24,gateway=10.20.30.1',
+ '--no-route',
+ ]
+ verifylist = [
+ ('router', self._router.name),
+ ('routes', [{'destination': '10.20.30.0/24',
+ 'gateway': '10.20.30.1'}]),
+ ('no_route', True),
+ ]
+
+ self.assertRaises(tests_utils.ParserException, self.check_parser,
+ self.cmd, arglist, verifylist)
+
def test_set_clear_routes(self):
arglist = [
self._router.name,
diff --git a/releasenotes/notes/bug-1565034-dd404bfb42d7778d.yaml b/releasenotes/notes/bug-1565034-dd404bfb42d7778d.yaml
new file mode 100644
index 00000000..e5ff38e8
--- /dev/null
+++ b/releasenotes/notes/bug-1565034-dd404bfb42d7778d.yaml
@@ -0,0 +1,5 @@
+---
+fixes:
+ - Added ``--no-route`` to the ``router set`` command.
+ Deprecated ``--clear-routes``.
+ [Bug `1565034 <https://bugs.launchpad.net/bugs/1565034>`_]