Skip to content

Commit 11be59d

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Added --no-route to the router set command"
2 parents 22e738c + bc93ebf commit 11be59d

4 files changed

Lines changed: 61 additions & 4 deletions

File tree

doc/source/command-objects/router.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ Set router properties
186186
[--name <name>]
187187
[--enable | --disable]
188188
[--distributed | --centralized]
189-
[--route destination=<subnet>,gateway=<ip-address> | --clear-routes]
189+
[--route destination=<subnet>,gateway=<ip-address> | --no-route]
190190
<router>
191191
192192
.. option:: --name <name>
@@ -216,7 +216,7 @@ Set router properties
216216
gateway: nexthop IP address
217217
(repeat option to set multiple routes)
218218
219-
.. option:: --clear-routes
219+
.. option:: --no-route
220220
221221
Clear routes associated with the router
222222

openstackclient/network/v2/router.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313

1414
"""Router action implementations"""
1515

16+
import argparse
1617
import json
18+
import logging
1719

1820
from openstackclient.common import command
1921
from openstackclient.common import exceptions
@@ -23,6 +25,9 @@
2325
from openstackclient.identity import common as identity_common
2426

2527

28+
LOG = logging.getLogger(__name__)
29+
30+
2631
def _format_admin_state(state):
2732
return 'UP' if state else 'DOWN'
2833

@@ -379,10 +384,15 @@ def get_parser(self, prog_name):
379384
"(repeat option to set multiple routes)")
380385
)
381386
routes_group.add_argument(
382-
'--clear-routes',
387+
'--no-route',
383388
action='store_true',
384389
help=_("Clear routes associated with the router")
385390
)
391+
routes_group.add_argument(
392+
'--clear-routes',
393+
action='store_true',
394+
help=argparse.SUPPRESS,
395+
)
386396

387397
# TODO(tangchen): Support setting 'ha' property in 'router set'
388398
# command. It appears that changing the ha state is supported by
@@ -401,8 +411,14 @@ def take_action(self, parsed_args):
401411
attrs = _get_attrs(self.app.client_manager, parsed_args)
402412

403413
# Get the route attributes.
404-
if parsed_args.clear_routes:
414+
if parsed_args.no_route:
415+
attrs['routes'] = []
416+
elif parsed_args.clear_routes:
405417
attrs['routes'] = []
418+
LOG.warning(_(
419+
'The --clear-routes option is deprecated, '
420+
'please use --no-route instead.'
421+
))
406422
elif parsed_args.routes is not None:
407423
# Map the route keys and append to the current routes.
408424
# The REST API will handle route validation and duplicates.

openstackclient/tests/network/v2/test_router.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,42 @@ def test_set_route(self):
495495
self._router, **attrs)
496496
self.assertIsNone(result)
497497

498+
def test_set_no_route(self):
499+
arglist = [
500+
self._router.name,
501+
'--no-route',
502+
]
503+
verifylist = [
504+
('router', self._router.name),
505+
('no_route', True),
506+
]
507+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
508+
509+
result = self.cmd.take_action(parsed_args)
510+
511+
attrs = {
512+
'routes': [],
513+
}
514+
self.network.update_router.assert_called_once_with(
515+
self._router, **attrs)
516+
self.assertIsNone(result)
517+
518+
def test_set_route_no_route(self):
519+
arglist = [
520+
self._router.name,
521+
'--route', 'destination=10.20.30.0/24,gateway=10.20.30.1',
522+
'--no-route',
523+
]
524+
verifylist = [
525+
('router', self._router.name),
526+
('routes', [{'destination': '10.20.30.0/24',
527+
'gateway': '10.20.30.1'}]),
528+
('no_route', True),
529+
]
530+
531+
self.assertRaises(tests_utils.ParserException, self.check_parser,
532+
self.cmd, arglist, verifylist)
533+
498534
def test_set_clear_routes(self):
499535
arglist = [
500536
self._router.name,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
fixes:
3+
- Added ``--no-route`` to the ``router set`` command.
4+
Deprecated ``--clear-routes``.
5+
[Bug `1565034 <https://bugs.launchpad.net/bugs/1565034>`_]

0 commit comments

Comments
 (0)