diff --git a/neutronclient/neutron/v2_0/lb/v2/healthmonitor.py b/neutronclient/neutron/v2_0/lb/v2/healthmonitor.py index a11b57806..34e72c842 100644 --- a/neutronclient/neutron/v2_0/lb/v2/healthmonitor.py +++ b/neutronclient/neutron/v2_0/lb/v2/healthmonitor.py @@ -14,11 +14,56 @@ # License for the specific language governing permissions and limitations # under the License. # - from neutronclient._i18n import _ +from neutronclient.common import utils from neutronclient.neutron import v2_0 as neutronV20 +def _add_common_args(parser, is_create=True): + parser.add_argument( + '--delay', + required=is_create, + help=_('The time in seconds between sending probes to members.')) + parser.add_argument( + '--name', + help=_('Name of the health monitor.')) + parser.add_argument( + '--timeout', + required=is_create, + help=_('Maximum number of seconds for a monitor to wait for a ' + 'connection to be established before it times out. The ' + 'value must be less than the delay value.')) + parser.add_argument( + '--http-method', + type=utils.convert_to_uppercase, + help=_('The HTTP method used for requests by the monitor of type ' + 'HTTP.')) + parser.add_argument( + '--url-path', + help=_('The HTTP path used in the HTTP request used by the monitor ' + 'to test a member health. This must be a string ' + 'beginning with a / (forward slash).')) + parser.add_argument( + '--max-retries', + required=is_create, + help=_('Number of permissible connection failures before changing ' + 'the member status to INACTIVE. [1..10].')) + parser.add_argument( + '--expected-codes', + help=_('The list of HTTP status codes expected in ' + 'response from the member to declare it healthy. This ' + 'attribute can contain one value, ' + 'or a list of values separated by comma, ' + 'or a range of values (e.g. "200-299"). If this attribute ' + 'is not specified, it defaults to "200".')) + + +def _parse_common_args(body, parsed_args): + neutronV20.update_dict(parsed_args, body, + ['expected_codes', 'http_method', 'url_path', + 'timeout', 'name', 'delay', 'max_retries']) + + class ListHealthMonitor(neutronV20.ListCommand): """LBaaS v2 List healthmonitors that belong to a given tenant.""" @@ -43,45 +88,11 @@ class CreateHealthMonitor(neutronV20.CreateCommand): shadow_resource = 'lbaas_healthmonitor' def add_known_arguments(self, parser): - parser.add_argument( - '--name', - help=_('Name of the health monitor to be created.')) + _add_common_args(parser) parser.add_argument( '--admin-state-down', dest='admin_state', action='store_false', help=_('Set admin state up to false.')) - parser.add_argument( - '--expected-codes', - help=_('The list of HTTP status codes expected in ' - 'response from the member to declare it healthy. This ' - 'attribute can contain one value, ' - 'or a list of values separated by comma, ' - 'or a range of values (e.g. "200-299"). If this attribute ' - 'is not specified, it defaults to "200".')) - parser.add_argument( - '--http-method', - help=_('The HTTP method used for requests by the monitor of type ' - 'HTTP.')) - parser.add_argument( - '--url-path', - help=_('The HTTP path used in the HTTP request used by the monitor' - ' to test a member health. This must be a string ' - 'beginning with a / (forward slash).')) - parser.add_argument( - '--delay', - required=True, - help=_('The time in seconds between sending probes to members.')) - parser.add_argument( - '--max-retries', - required=True, - help=_('Number of permissible connection failures before changing ' - 'the member status to INACTIVE. [1..10].')) - parser.add_argument( - '--timeout', - required=True, - help=_('Maximum number of seconds for a monitor to wait for a ' - 'connection to be established before it times out. The ' - 'value must be less than the delay value.')) parser.add_argument( '--type', required=True, choices=['PING', 'TCP', 'HTTP', 'HTTPS'], @@ -96,14 +107,11 @@ class CreateHealthMonitor(neutronV20.CreateCommand): self.get_client(), 'pool', parsed_args.pool, cmd_resource='lbaas_pool') body = {'admin_state_up': parsed_args.admin_state, - 'delay': parsed_args.delay, - 'max_retries': parsed_args.max_retries, - 'timeout': parsed_args.timeout, 'type': parsed_args.type, 'pool_id': pool_id} neutronV20.update_dict(parsed_args, body, - ['expected_codes', 'http_method', 'url_path', - 'tenant_id', 'name']) + ['tenant_id']) + _parse_common_args(body, parsed_args) return {self.resource: body} @@ -114,13 +122,17 @@ class UpdateHealthMonitor(neutronV20.UpdateCommand): shadow_resource = 'lbaas_healthmonitor' def add_known_arguments(self, parser): - parser.add_argument( - '--name', - help=_('Updated name of the health monitor.')) + _add_common_args(parser, is_create=False) + utils.add_boolean_argument( + parser, '--admin-state-up', + help=_('Update the administrative state of ' + 'the health monitor (True meaning "Up").')) def args2body(self, parsed_args): body = {} - neutronV20.update_dict(parsed_args, body, ['name']) + _parse_common_args(body, parsed_args) + neutronV20.update_dict(parsed_args, body, + ['admin_state_up']) return {self.resource: body} diff --git a/neutronclient/neutron/v2_0/lb/v2/listener.py b/neutronclient/neutron/v2_0/lb/v2/listener.py index b63e2c28f..1adac9789 100644 --- a/neutronclient/neutron/v2_0/lb/v2/listener.py +++ b/neutronclient/neutron/v2_0/lb/v2/listener.py @@ -37,6 +37,29 @@ def _get_pool_id(client, pool_id_or_name): client, 'pool', pool_id_or_name, cmd_resource='lbaas_pool') +def _add_common_args(parser): + parser.add_argument( + '--description', + help=_('Description of the listener.')) + parser.add_argument( + '--connection-limit', + type=int, + help=_('The maximum number of connections per second allowed for ' + 'the vip. Positive integer or -1 for unlimited (default).')) + parser.add_argument( + '--default-pool', + help=_('Default pool for the listener.')) + + +def _parse_common_args(body, parsed_args, client): + neutronV20.update_dict(parsed_args, body, + ['name', 'description', 'connection_limit']) + if parsed_args.default_pool: + default_pool_id = _get_pool_id( + client, parsed_args.default_pool) + body['default_pool_id'] = default_pool_id + + class ListListener(neutronV20.ListCommand): """LBaaS v2 List listeners that belong to a given tenant.""" @@ -59,18 +82,11 @@ class CreateListener(neutronV20.CreateCommand): resource = 'listener' def add_known_arguments(self, parser): + _add_common_args(parser) parser.add_argument( '--admin-state-down', dest='admin_state', action='store_false', help=_('Set admin state up to false.')) - parser.add_argument( - '--connection-limit', - help=_('The maximum number of connections per second allowed for ' - 'the vip. Positive integer or -1 for unlimited (default).'), - type=int) - parser.add_argument( - '--description', - help=_('Description of the listener.')) parser.add_argument( '--name', help=_('The name of the listener. At least one of --default-pool ' @@ -85,9 +101,6 @@ class CreateListener(neutronV20.CreateCommand): dest='sni_container_refs', nargs='+', help=_('List of TLS container references for SNI.')) - parser.add_argument( - '--default-pool', - help=_('Default pool for the listener.')) parser.add_argument( '--loadbalancer', metavar='LOADBALANCER', @@ -105,36 +118,48 @@ class CreateListener(neutronV20.CreateCommand): help=_('Protocol port for the listener.')) def args2body(self, parsed_args): - resource = { - 'protocol': parsed_args.protocol, - 'protocol_port': parsed_args.protocol_port, - 'admin_state_up': parsed_args.admin_state - } if not parsed_args.loadbalancer and not parsed_args.default_pool: message = _('Either --default-pool or --loadbalancer must be ' 'specified.') raise exceptions.CommandError(message) + body = { + 'protocol': parsed_args.protocol, + 'protocol_port': parsed_args.protocol_port, + 'admin_state_up': parsed_args.admin_state + } if parsed_args.loadbalancer: loadbalancer_id = _get_loadbalancer_id( self.get_client(), parsed_args.loadbalancer) - resource['loadbalancer_id'] = loadbalancer_id - if parsed_args.default_pool: - default_pool_id = _get_pool_id( - self.get_client(), parsed_args.default_pool) - resource['default_pool_id'] = default_pool_id + body['loadbalancer_id'] = loadbalancer_id - neutronV20.update_dict(parsed_args, resource, - ['connection_limit', 'description', - 'name', 'default_tls_container_ref', + neutronV20.update_dict(parsed_args, body, + ['default_tls_container_ref', 'sni_container_refs', 'tenant_id']) - return {self.resource: resource} + _parse_common_args(body, parsed_args, self.get_client()) + return {self.resource: body} class UpdateListener(neutronV20.UpdateCommand): """LBaaS v2 Update a given listener.""" resource = 'listener' - allow_names = False + + def add_known_arguments(self, parser): + _add_common_args(parser) + parser.add_argument( + '--name', + help=_('Name of the listener.')) + utils.add_boolean_argument( + parser, '--admin-state-up', dest='admin_state_up', + help=_('Specify the administrative state of the listener. ' + '(True meaning "Up")')) + + def args2body(self, parsed_args): + body = {} + neutronV20.update_dict(parsed_args, body, + ['admin_state_up']) + _parse_common_args(body, parsed_args, self.get_client()) + return {self.resource: body} class DeleteListener(neutronV20.DeleteCommand): diff --git a/neutronclient/neutron/v2_0/lb/v2/loadbalancer.py b/neutronclient/neutron/v2_0/lb/v2/loadbalancer.py index ceba4990d..76f37fc50 100644 --- a/neutronclient/neutron/v2_0/lb/v2/loadbalancer.py +++ b/neutronclient/neutron/v2_0/lb/v2/loadbalancer.py @@ -17,9 +17,24 @@ from oslo_serialization import jsonutils from neutronclient._i18n import _ +from neutronclient.common import utils from neutronclient.neutron import v2_0 as neutronV20 +def _add_common_args(parser): + parser.add_argument( + '--description', + help=_('Description of the load balancer.')) + parser.add_argument( + '--name', metavar='NAME', + help=_('Name of the load balancer.')) + + +def _parse_common_args(body, parsed_args): + neutronV20.update_dict(parsed_args, body, + ['name', 'description']) + + class ListLoadBalancer(neutronV20.ListCommand): """LBaaS v2 List loadbalancers that belong to a given tenant.""" @@ -40,19 +55,13 @@ class CreateLoadBalancer(neutronV20.CreateCommand): """LBaaS v2 Create a loadbalancer.""" resource = 'loadbalancer' - allow_names = True def add_known_arguments(self, parser): - parser.add_argument( - '--description', - help=_('Description of the load balancer.')) + _add_common_args(parser) parser.add_argument( '--admin-state-down', dest='admin_state', action='store_false', help=_('Set admin state up to false.')) - parser.add_argument( - '--name', metavar='NAME', - help=_('Name of the load balancer.')) parser.add_argument( '--provider', help=_('Provider name of load balancer service.')) @@ -77,8 +86,8 @@ class CreateLoadBalancer(neutronV20.CreateCommand): body['flavor_id'] = _flavor_id neutronV20.update_dict(parsed_args, body, - ['description', 'provider', 'vip_address', - 'tenant_id', 'name']) + ['provider', 'vip_address', 'tenant_id']) + _parse_common_args(body, parsed_args) return {self.resource: body} @@ -86,14 +95,26 @@ class UpdateLoadBalancer(neutronV20.UpdateCommand): """LBaaS v2 Update a given loadbalancer.""" resource = 'loadbalancer' - allow_names = True + + def add_known_arguments(self, parser): + utils.add_boolean_argument( + parser, '--admin-state-up', + help=_('Update the administrative state of ' + 'the load balancer (True meaning "Up").')) + _add_common_args(parser) + + def args2body(self, parsed_args): + body = {} + _parse_common_args(body, parsed_args) + neutronV20.update_dict(parsed_args, body, + ['admin_state_up']) + return {self.resource: body} class DeleteLoadBalancer(neutronV20.DeleteCommand): """LBaaS v2 Delete a given loadbalancer.""" resource = 'loadbalancer' - allow_names = True class RetrieveLoadBalancerStats(neutronV20.ShowCommand): diff --git a/neutronclient/neutron/v2_0/lb/v2/member.py b/neutronclient/neutron/v2_0/lb/v2/member.py index 28109c12b..4a94a7a8d 100644 --- a/neutronclient/neutron/v2_0/lb/v2/member.py +++ b/neutronclient/neutron/v2_0/lb/v2/member.py @@ -15,8 +15,10 @@ # License for the specific language governing permissions and limitations # under the License. # +import argparse from neutronclient._i18n import _ +from neutronclient.common import utils from neutronclient.neutron import v2_0 as neutronV20 @@ -37,6 +39,20 @@ class LbaasMemberMixin(object): help=_('ID or name of the pool that this member belongs to.')) +def _add_common_args(parser): + parser.add_argument( + '--name', + help=_('Name of the member.')) + parser.add_argument( + '--weight', + help=_('Weight of member in the pool (default:1, [0..256]).')) + + +def _parse_common_args(body, parsed_args): + neutronV20.update_dict(parsed_args, body, + ['weight', 'name']) + + class ListMember(LbaasMemberMixin, neutronV20.ListCommand): """LBaaS v2 List members that belong to a given pool.""" @@ -69,16 +85,11 @@ class CreateMember(neutronV20.CreateCommand): shadow_resource = 'lbaas_member' def add_known_arguments(self, parser): + _add_common_args(parser) parser.add_argument( '--admin-state-down', dest='admin_state', action='store_false', - help=_('Set admin state up to false')) - parser.add_argument( - '--weight', - help=_('Weight of member in the pool (default:1, [0..256]).')) - parser.add_argument( - '--name', - help=_('Name of the member to be created.')) + help=_('Set admin state up to false.')) parser.add_argument( '--subnet', required=True, @@ -105,7 +116,8 @@ class CreateMember(neutronV20.CreateCommand): 'protocol_port': parsed_args.protocol_port, 'address': parsed_args.address} neutronV20.update_dict(parsed_args, body, - ['weight', 'subnet_id', 'tenant_id', 'name']) + ['subnet_id', 'tenant_id']) + _parse_common_args(body, parsed_args) return {self.resource: body} @@ -119,22 +131,25 @@ class UpdateMember(neutronV20.UpdateCommand): parser.add_argument( '--admin-state-down', dest='admin_state', action='store_false', - help=_('Set admin state up to false')) - parser.add_argument( - '--weight', - help=_('Weight of member in the pool (default:1, [0..256])')) + default=argparse.SUPPRESS, + help=_('[DEPRECATED in Mitaka] Set admin state up to false.')) parser.add_argument( 'pool', metavar='POOL', - help=_('ID or name of the pool that this member belongs to')) - parser.add_argument( - '--name', - help=_('Updated name of the member.')) + help=_('ID or name of the pool that this member belongs to.')) + utils.add_boolean_argument( + parser, '--admin-state-up', + dest='admin_state', + help=_('Update the administrative state of ' + 'the member (True meaning "Up").')) + # ToDo(reedip): After Mitaka, remove admin-state-down + _add_common_args(parser) def args2body(self, parsed_args): self.parent_id = _get_pool_id(self.get_client(), parsed_args.pool) body = {} - neutronV20.update_dict(parsed_args, body, - ['admin_state_up', 'weight', 'name']) + if hasattr(parsed_args, 'admin_state'): + body['admin_state_up'] = parsed_args.admin_state + _parse_common_args(body, parsed_args) return {self.resource: body} diff --git a/neutronclient/neutron/v2_0/lb/v2/pool.py b/neutronclient/neutron/v2_0/lb/v2/pool.py index 6cd0b8be5..b2bd326a9 100644 --- a/neutronclient/neutron/v2_0/lb/v2/pool.py +++ b/neutronclient/neutron/v2_0/lb/v2/pool.py @@ -39,6 +39,29 @@ def _get_listener_id(client, listener_id_or_name): client, 'listener', listener_id_or_name) +def _add_common_args(parser): + parser.add_argument( + '--description', + help=_('Description of the pool.')) + parser.add_argument( + '--name', help=_('The name of the pool.')) + parser.add_argument( + '--lb-algorithm', + required=True, + type=utils.convert_to_uppercase, + choices=['ROUND_ROBIN', 'LEAST_CONNECTIONS', 'SOURCE_IP'], + help=_('The algorithm used to distribute load between the members ' + 'of the pool.')) + + +def _parse_common_args(parsed_args): + body = {} + neutronV20.update_dict(parsed_args, + body, ['description', 'lb_algorithm', 'name', + 'session_persistence']) + return body + + class ListPool(neutronV20.ListCommand): """LBaaS v2 List pools that belong to a given tenant.""" @@ -72,22 +95,11 @@ class CreatePool(neutronV20.CreateCommand): shadow_resource = 'lbaas_pool' def add_known_arguments(self, parser): + _add_common_args(parser) parser.add_argument( '--admin-state-down', dest='admin_state', action='store_false', help=_('Set admin state up to false.')) - parser.add_argument( - '--description', - help=_('Description of the pool.')) - parser.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')) - parser.add_argument( - '--name', help=_('The name of the pool.')) parser.add_argument( '--listener', help=_('Listener whose default-pool should be set to this pool. ' @@ -98,43 +110,40 @@ class CreatePool(neutronV20.CreateCommand): help=_('Loadbalancer with which this pool should be associated. ' 'At least one of --listener or --loadbalancer must be ' 'specified.')) - parser.add_argument( - '--lb-algorithm', - required=True, - choices=['ROUND_ROBIN', 'LEAST_CONNECTIONS', 'SOURCE_IP'], - help=_('The algorithm used to distribute load between the members ' - 'of the pool.')) parser.add_argument( '--protocol', + type=utils.convert_to_uppercase, required=True, choices=['HTTP', 'HTTPS', 'TCP'], - type=utils.convert_to_uppercase, help=_('Protocol for balancing.')) + parser.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.')) def args2body(self, parsed_args): - resource = { - 'admin_state_up': parsed_args.admin_state, - 'protocol': parsed_args.protocol, - 'lb_algorithm': parsed_args.lb_algorithm - } if not parsed_args.listener and not parsed_args.loadbalancer: message = _('At least one of --listener or --loadbalancer must be ' 'specified.') raise exceptions.CommandError(message) + body = _parse_common_args(parsed_args) if parsed_args.listener: listener_id = _get_listener_id( self.get_client(), parsed_args.listener) - resource['listener_id'] = listener_id + body['listener_id'] = listener_id if parsed_args.loadbalancer: loadbalancer_id = _get_loadbalancer_id( self.get_client(), parsed_args.loadbalancer) - resource['loadbalancer_id'] = loadbalancer_id - neutronV20.update_dict(parsed_args, resource, - ['description', 'name', - 'session_persistence', 'tenant_id']) - return {self.resource: resource} + body['loadbalancer_id'] = loadbalancer_id + body['admin_state_up'] = parsed_args.admin_state + neutronV20.update_dict(parsed_args, body, + ['tenant_id', 'protocol']) + return {self.resource: body} class UpdatePool(neutronV20.UpdateCommand): @@ -143,6 +152,26 @@ class UpdatePool(neutronV20.UpdateCommand): resource = 'pool' shadow_resource = 'lbaas_pool' + def add_known_arguments(self, parser): + utils.add_boolean_argument( + parser, '--admin-state-up', + help=_('Update the administrative state of ' + 'the pool (True meaning "Up").')) + parser.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) + + def args2body(self, parsed_args): + body = _parse_common_args(parsed_args) + neutronV20.update_dict(parsed_args, body, + ['admin_state_up']) + return {self.resource: body} + class DeletePool(neutronV20.DeleteCommand): """LBaaS v2 Delete a given pool.""" diff --git a/neutronclient/tests/unit/lb/v2/test_cli20_healthmonitor.py b/neutronclient/tests/unit/lb/v2/test_cli20_healthmonitor.py index b585ec3a2..945ac18e3 100644 --- a/neutronclient/tests/unit/lb/v2/test_cli20_healthmonitor.py +++ b/neutronclient/tests/unit/lb/v2/test_cli20_healthmonitor.py @@ -129,17 +129,40 @@ class CLITestV20LbHealthMonitorJSON(test_cli20.CLITestV20Base): args, ['id', 'name'], cmd_resource=cmd_resource) - def test_update_healthmonitor(self): - # lbaas-healthmonitor-update myid --name newname. + def _test_update_hm(self, args, expected_values): resource = 'healthmonitor' cmd_resource = 'lbaas_healthmonitor' + my_id = 'myid' cmd = healthmonitor.UpdateHealthMonitor(test_cli20.MyApp(sys.stdout), None) - self._test_update_resource(resource, cmd, 'myid', - ['myid', '--name', 'newname'], - {'name': 'newname', }, + args.insert(0, my_id) + self._test_update_resource(resource, cmd, my_id, + args, + expected_values, cmd_resource=cmd_resource) + def test_update_healthmonitor(self): + # lbaas-healthmonitor-update myid --name newname. + self._test_update_hm(['--name', 'newname'], {'name': 'newname', }) + # lbaas-healthmonitor-update myid --delay 10. + self._test_update_hm(['--delay', '10'], {'delay': '10'}) + # lbaas-healthmonitor-update myid --timeout 5. + self._test_update_hm(['--timeout', '5'], {'timeout': '5', }) + # lbaas-healthmonitor-update myid --delay 10. + self._test_update_hm(['--http-method', 'OPTIONS'], + {'http_method': 'OPTIONS'}) + # lbaas-healthmonitor-update myid --url-path /test/string . + self._test_update_hm(['--url-path', '/test/string'], + {'url_path': '/test/string', }) + # lbaas-healthmonitor-update myid --max-retries 5 + self._test_update_hm(['--max-retries', '5'], {'max_retries': '5'}) + # lbaas-healthmonitor-update myid --expected-codes 201 + self._test_update_hm(['--expected-codes', '201'], + {'expected_codes': '201'}) + # lbaas-healthmonitor-update myid --admin-state-up False + self._test_update_hm(['--admin-state-up', 'False'], + {'admin_state_up': 'False'}) + def test_delete_healthmonitor(self): # lbaas-healthmonitor-delete my-id. resource = 'healthmonitor' diff --git a/neutronclient/tests/unit/lb/v2/test_cli20_listener.py b/neutronclient/tests/unit/lb/v2/test_cli20_listener.py index 581e511ea..3993ea7f7 100644 --- a/neutronclient/tests/unit/lb/v2/test_cli20_listener.py +++ b/neutronclient/tests/unit/lb/v2/test_cli20_listener.py @@ -159,16 +159,30 @@ class CLITestV20LbListenerJSON(test_cli20.CLITestV20Base): args, ['id', 'name'], cmd_resource=cmd_resource) - def test_update_listener(self): - # lbaas-listener-update myid --name newname. + def _test_update_listener(self, args, expected_values): resource = 'listener' cmd_resource = 'lbaas_listener' + my_id = 'myid' + args.insert(0, my_id) cmd = listener.UpdateListener(test_cli20.MyApp(sys.stdout), None) - self._test_update_resource(resource, cmd, 'myid', - ['myid', '--name', 'newname'], - {'name': 'newname', }, + self._test_update_resource(resource, cmd, my_id, + args, expected_values, cmd_resource=cmd_resource) + def test_update_listener(self): + # lbaas-listener-update myid --name newname. + self._test_update_listener(['--name', 'newname'], + {'name': 'newname', }) + # lbaas-listener-update myid --description check. + self._test_update_listener(['--description', 'check'], + {'description': 'check', }) + # lbaas-listener-update myid --connection-limit -1 + self._test_update_listener(['--connection-limit', '-1'], + {'connection_limit': -1, }) + # lbaas-listener-update myid --admin-state-up False. + self._test_update_listener(['--admin-state-up', 'False'], + {'admin_state_up': 'False', }) + def test_delete_listener(self): # lbaas-listener-delete my-id. resource = 'listener' diff --git a/neutronclient/tests/unit/lb/v2/test_cli20_loadbalancer.py b/neutronclient/tests/unit/lb/v2/test_cli20_loadbalancer.py index 205e6816b..b62ce3435 100644 --- a/neutronclient/tests/unit/lb/v2/test_cli20_loadbalancer.py +++ b/neutronclient/tests/unit/lb/v2/test_cli20_loadbalancer.py @@ -112,16 +112,26 @@ class CLITestV20LbLoadBalancerJSON(test_cli20.CLITestV20Base): args, ['id', 'name'], cmd_resource=cmd_resource) - def test_update_loadbalancer(self): - # lbaas-loadbalancer-loadbalancer-update myid --name newname. + def _test_update_lb(self, args, expected_values): resource = 'loadbalancer' cmd_resource = 'lbaas_loadbalancer' + my_id = 'myid' + args.insert(0, my_id) cmd = lb.UpdateLoadBalancer(test_cli20.MyApp(sys.stdout), None) - self._test_update_resource(resource, cmd, 'myid', - ['myid', '--name', 'newname'], - {'name': 'newname', }, + self._test_update_resource(resource, cmd, my_id, + args, expected_values, cmd_resource=cmd_resource) + def test_update_loadbalancer(self): + # lbaas-loadbalancer-update myid --name newname. + self._test_update_lb(['--name', 'newname'], {'name': 'newname', }) + # lbaas-loadbalancer-update myid --description check. + self._test_update_lb(['--description', 'check'], + {'description': 'check', }) + # lbaas-loadbalancer-update myid --admin-state-up False. + self._test_update_lb(['--admin-state-up', 'False'], + {'admin_state_up': 'False', }) + def test_delete_loadbalancer(self): # lbaas-loadbalancer-loadbalancer-delete my-id. resource = 'loadbalancer' diff --git a/neutronclient/tests/unit/lb/v2/test_cli20_member.py b/neutronclient/tests/unit/lb/v2/test_cli20_member.py index acc663ac5..057da4254 100644 --- a/neutronclient/tests/unit/lb/v2/test_cli20_member.py +++ b/neutronclient/tests/unit/lb/v2/test_cli20_member.py @@ -61,7 +61,7 @@ class CLITestV20LbMemberJSON(test_cli20.CLITestV20Base): 'subnet_id', 'weight', 'name'] position_values = [False, address, protocol_port, subnet_id, weight, name] - self._test_create_resource(resource, cmd, '', my_id, args, + self._test_create_resource(resource, cmd, name, my_id, args, position_names, position_values, cmd_resource=cmd_resource, parent_id=pool_id) @@ -145,6 +145,18 @@ class CLITestV20LbMemberJSON(test_cli20.CLITestV20Base): {'name': 'newname', }, cmd_resource=cmd_resource, parent_id=pool_id) + # lbaas-member-update myid --weight 100. + args = [my_id, pool_id, '--weight', '100'] + self._test_update_resource(resource, cmd, my_id, args, + {'weight': '100', }, + cmd_resource=cmd_resource, + parent_id=pool_id) + # lbaas-member-update myid --admin-state-up False + args = [my_id, pool_id, '--admin-state-up', 'False'] + self._test_update_resource(resource, cmd, my_id, args, + {'admin_state_up': 'False', }, + cmd_resource=cmd_resource, + parent_id=pool_id) def test_delete_member(self): # lbaas-member-delete my-id. diff --git a/neutronclient/tests/unit/lb/v2/test_cli20_pool.py b/neutronclient/tests/unit/lb/v2/test_cli20_pool.py index 2e5787b0e..7a4f7e7cb 100644 --- a/neutronclient/tests/unit/lb/v2/test_cli20_pool.py +++ b/neutronclient/tests/unit/lb/v2/test_cli20_pool.py @@ -157,13 +157,27 @@ class CLITestV20LbPoolJSON(test_cli20.CLITestV20Base): cmd_resource=cmd_resource) def test_update_pool(self): - # lbaas-pool-update myid --name newname. + # lbaas-pool-update myid --name newname --description SuperPool + # --lb-algorithm SOURCE_IP --admin-state-up + # --session-persistence type=dict,type=HTTP_COOKIE,cookie_name=pie + resource = 'pool' cmd_resource = 'lbaas_pool' cmd = pool.UpdatePool(test_cli20.MyApp(sys.stdout), None) - self._test_update_resource(resource, cmd, 'myid', - ['myid', '--name', 'newname'], - {'name': 'newname', }, + args = ['myid', '--name', 'newname', + '--description', 'SuperPool', '--lb-algorithm', "SOURCE_IP", + '--admin-state-up', 'True', + '--session-persistence', 'type=dict,' + 'type=HTTP_COOKIE,cookie_name=pie'] + body = {'name': 'newname', + "description": "SuperPool", + "lb_algorithm": "SOURCE_IP", + "admin_state_up": 'True', + 'session_persistence': { + 'type': 'HTTP_COOKIE', + 'cookie_name': 'pie', + }, } + self._test_update_resource(resource, cmd, 'myid', args, body, cmd_resource=cmd_resource) def test_delete_pool(self):