From 9750c10f42aa3e058432f7c7d7352961fe7fe789 Mon Sep 17 00:00:00 2001 From: reedip Date: Wed, 2 Mar 2016 18:33:08 +0900 Subject: [PATCH] Simplify clearing session-persistence Currently Session Persistance for a pool can be cleared by "neutron lbaas-pool-update pool --session-persistence type=dict type=NONE" But this option seems to be a bit long and complicated, so therefore this patch tries to simplify it by adding a new option --no-session-persistence, which does the same job. Change-Id: Iacafe765a2f0f9537a4e4d01b9b8086a9e313b92 Depends-On: I654b172927e1d96677a7da9e0846231b0ac48aa9 --- neutronclient/neutron/v2_0/lb/v2/pool.py | 23 +++++++++++++------ .../tests/unit/lb/v2/test_cli20_pool.py | 11 +++++++++ ...session-clear-option-3c0b78ebc133a10c.yaml | 6 +++++ 3 files changed, 33 insertions(+), 7 deletions(-) create mode 100644 releasenotes/notes/add-new-session-clear-option-3c0b78ebc133a10c.yaml diff --git a/neutronclient/neutron/v2_0/lb/v2/pool.py b/neutronclient/neutron/v2_0/lb/v2/pool.py index b2bd326a9..5e76af228 100644 --- a/neutronclient/neutron/v2_0/lb/v2/pool.py +++ b/neutronclient/neutron/v2_0/lb/v2/pool.py @@ -39,7 +39,7 @@ def _get_listener_id(client, listener_id_or_name): client, 'listener', listener_id_or_name) -def _add_common_args(parser): +def _add_common_args(parser, is_create=True): parser.add_argument( '--description', help=_('Description of the pool.')) @@ -47,7 +47,7 @@ def _add_common_args(parser): '--name', help=_('The name of the pool.')) parser.add_argument( '--lb-algorithm', - required=True, + required=is_create, type=utils.convert_to_uppercase, choices=['ROUND_ROBIN', 'LEAST_CONNECTIONS', 'SOURCE_IP'], help=_('The algorithm used to distribute load between the members ' @@ -57,8 +57,7 @@ def _add_common_args(parser): def _parse_common_args(parsed_args): body = {} neutronV20.update_dict(parsed_args, - body, ['description', 'lb_algorithm', 'name', - 'session_persistence']) + body, ['description', 'lb_algorithm', 'name']) return body @@ -142,7 +141,8 @@ class CreatePool(neutronV20.CreateCommand): body['loadbalancer_id'] = loadbalancer_id body['admin_state_up'] = parsed_args.admin_state neutronV20.update_dict(parsed_args, body, - ['tenant_id', 'protocol']) + ['tenant_id', 'protocol', + 'session_persistence']) return {self.resource: body} @@ -157,17 +157,26 @@ class UpdatePool(neutronV20.UpdateCommand): parser, '--admin-state-up', help=_('Update the administrative state of ' 'the pool (True meaning "Up").')) - parser.add_argument( + session_group = parser.add_mutually_exclusive_group() + session_group.add_argument( '--session-persistence', metavar='type=TYPE[,cookie_name=COOKIE_NAME]', type=utils.str2dict_type(required_keys=['type'], optional_keys=['cookie_name']), help=_('The type of session persistence to use and associated ' 'cookie name.')) - _add_common_args(parser) + session_group.add_argument( + '--no-session-persistence', + action='store_true', + help=_('Clear session persistence for the pool.')) + _add_common_args(parser, False) def args2body(self, parsed_args): body = _parse_common_args(parsed_args) + if parsed_args.no_session_persistence: + body['session_persistence'] = None + elif parsed_args.session_persistence: + body['session_persistence'] = parsed_args.session_persistence neutronV20.update_dict(parsed_args, body, ['admin_state_up']) return {self.resource: body} diff --git a/neutronclient/tests/unit/lb/v2/test_cli20_pool.py b/neutronclient/tests/unit/lb/v2/test_cli20_pool.py index 7a4f7e7cb..8c1f428a3 100644 --- a/neutronclient/tests/unit/lb/v2/test_cli20_pool.py +++ b/neutronclient/tests/unit/lb/v2/test_cli20_pool.py @@ -179,6 +179,17 @@ class CLITestV20LbPoolJSON(test_cli20.CLITestV20Base): }, } self._test_update_resource(resource, cmd, 'myid', args, body, cmd_resource=cmd_resource) + # lbaas-pool-update myid --name Name + # --no-session-persistence + + resource = 'pool' + cmd_resource = 'lbaas_pool' + cmd = pool.UpdatePool(test_cli20.MyApp(sys.stdout), None) + args = ['myid', '--name', 'Name', '--no-session-persistence'] + body = {'name': "Name", + "session_persistence": None, } + self._test_update_resource(resource, cmd, 'myid', args, body, + cmd_resource=cmd_resource) def test_delete_pool(self): # lbaas-pool-delete my-id. diff --git a/releasenotes/notes/add-new-session-clear-option-3c0b78ebc133a10c.yaml b/releasenotes/notes/add-new-session-clear-option-3c0b78ebc133a10c.yaml new file mode 100644 index 000000000..2782efe4f --- /dev/null +++ b/releasenotes/notes/add-new-session-clear-option-3c0b78ebc133a10c.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + A new option ``--no-session-persistence`` has been added to + the ``neutron lbaas-pool-update`` CLI to clear the session persistence + with which the current pool is associated.