From e2fc436d53f53d0993fc0b9dd29f402e6c7f8bc1 Mon Sep 17 00:00:00 2001 From: Nam Nguyen Hoai Date: Tue, 9 Aug 2016 14:31:34 +0700 Subject: [PATCH] Add --ha option to os router create command This patch added --ha option which the 'os router create' command was missed. Change-Id: I77635fb17af32beb0d8ed9aa080ef79285719fdc Closes-Bug: #1610161 --- doc/source/command-objects/router.rst | 6 ++++- openstackclient/network/v2/router.py | 10 ++++++-- .../tests/unit/network/v2/test_router.py | 25 +++++++++++++++++++ .../notes/bug-1610161-7c34c7b735701bd4.yaml | 5 ++++ 4 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 releasenotes/notes/bug-1610161-7c34c7b735701bd4.yaml diff --git a/doc/source/command-objects/router.rst b/doc/source/command-objects/router.rst index 13a75158f..335de1799 100644 --- a/doc/source/command-objects/router.rst +++ b/doc/source/command-objects/router.rst @@ -63,7 +63,7 @@ Create new router os router create [--project [--project-domain ]] [--enable | --disable] - [--distributed] + [--distributed] [--ha] [--description ] [--availability-zone-hint ] @@ -89,6 +89,10 @@ Create new router Create a distributed router +.. option:: --ha + + Create a highly available router + .. option:: --description Set router description diff --git a/openstackclient/network/v2/router.py b/openstackclient/network/v2/router.py index cb40d7741..48a3a92cd 100644 --- a/openstackclient/network/v2/router.py +++ b/openstackclient/network/v2/router.py @@ -94,7 +94,6 @@ def _get_attrs(client_manager, parsed_args): ).id attrs['tenant_id'] = project_id - # TODO(tangchen): Support getting 'ha' property. # TODO(tangchen): Support getting 'external_gateway_info' property. return attrs @@ -180,10 +179,15 @@ class CreateRouter(command.ShowOne): default=False, help=_("Create a distributed router") ) + parser.add_argument( + '--ha', + action='store_true', + help=_("Create a highly available router") + ) parser.add_argument( '--description', metavar='', - help=_('Set router description') + help=_("Set router description") ) parser.add_argument( '--project', @@ -207,6 +211,8 @@ class CreateRouter(command.ShowOne): client = self.app.client_manager.network attrs = _get_attrs(self.app.client_manager, parsed_args) + if parsed_args.ha: + attrs['ha'] = parsed_args.ha obj = client.create_router(**attrs) columns = _get_columns(obj) diff --git a/openstackclient/tests/unit/network/v2/test_router.py b/openstackclient/tests/unit/network/v2/test_router.py index d12289e15..6a4458622 100644 --- a/openstackclient/tests/unit/network/v2/test_router.py +++ b/openstackclient/tests/unit/network/v2/test_router.py @@ -166,6 +166,7 @@ class TestCreateRouter(TestRouter): ('name', self.new_router.name), ('enable', True), ('distributed', False), + ('ha', False), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -178,6 +179,29 @@ class TestCreateRouter(TestRouter): self.assertEqual(self.columns, columns) self.assertEqual(self.data, data) + def test_create_with_ha_option(self): + arglist = [ + '--ha', + self.new_router.name, + ] + verifylist = [ + ('name', self.new_router.name), + ('enable', True), + ('distributed', False), + ('ha', True), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + columns, data = (self.cmd.take_action(parsed_args)) + + self.network.create_router.assert_called_once_with(**{ + 'admin_state_up': True, + 'name': self.new_router.name, + 'ha': True, + }) + self.assertEqual(self.columns, columns) + self.assertEqual(self.data, data) + def test_create_with_AZ_hints(self): arglist = [ self.new_router.name, @@ -189,6 +213,7 @@ class TestCreateRouter(TestRouter): ('availability_zone_hints', ['fake-az', 'fake-az2']), ('enable', True), ('distributed', False), + ('ha', False) ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) diff --git a/releasenotes/notes/bug-1610161-7c34c7b735701bd4.yaml b/releasenotes/notes/bug-1610161-7c34c7b735701bd4.yaml new file mode 100644 index 000000000..9cdbba49f --- /dev/null +++ b/releasenotes/notes/bug-1610161-7c34c7b735701bd4.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Add ``--ha`` option to ``router create`` command. + [Bug `1610161 `_] \ No newline at end of file