Merge "Validate connection limit for LBaaS"

This commit is contained in:
Jenkins 2015-12-04 17:52:53 +00:00 committed by Gerrit Code Review
commit 67cddb2bae
4 changed files with 86 additions and 2 deletions

View File

@ -26,6 +26,8 @@ from neutron.common import exceptions as nexception
from neutron import manager
from neutron.plugins.common import constants
from neutron.services import service_base
from neutron_lbaas.extensions import loadbalancerv2
from neutron_lbaas.services.loadbalancer import constants as lb_const
LOADBALANCER_PREFIX = "/lb"
@ -96,6 +98,10 @@ class MemberExists(nexception.NeutronException):
"already present in pool %(pool)s")
attr.validators['type:connection_limit'] = (
loadbalancerv2._validate_connection_limit)
RESOURCE_ATTRIBUTE_MAP = {
'vips': {
'id': {'allow_post': False, 'allow_put': False,
@ -146,7 +152,9 @@ RESOURCE_ATTRIBUTE_MAP = {
'required': False}}},
'is_visible': True},
'connection_limit': {'allow_post': True, 'allow_put': True,
'default': -1,
'validate': {'type:connection_limit':
lb_const.MIN_CONNECT_VALUE},
'default': lb_const.MIN_CONNECT_VALUE,
'convert_to': attr.convert_to_int,
'is_visible': True},
'admin_state_up': {'allow_post': True, 'allow_put': True,

View File

@ -17,6 +17,7 @@
import abc
from oslo_config import cfg
from oslo_log import log as logging
import six
from neutron.api import extensions
@ -32,6 +33,8 @@ from neutron_lbaas.services.loadbalancer import constants as lb_const
LOADBALANCERV2_PREFIX = "/lbaas"
LOG = logging.getLogger(__name__)
# Loadbalancer Exceptions
# This exception is only for a workaround when having v1 and v2 lbaas extension
@ -132,6 +135,17 @@ class FlavorsPluginNotLoaded(nexception.NotFound):
message = _("Flavors plugin not found")
def _validate_connection_limit(data, min_value=lb_const.MIN_CONNECT_VALUE):
if int(data) < min_value:
msg = (_("'%(data)s' is not a valid value, "
"because it cannot be less than %(min_value)s") %
{'data': data, 'min_value': min_value})
LOG.debug(msg)
return msg
attr.validators['type:connection_limit'] = _validate_connection_limit
RESOURCE_ATTRIBUTE_MAP = {
'loadbalancers': {
'id': {'allow_post': False, 'allow_put': False,
@ -210,7 +224,9 @@ RESOURCE_ATTRIBUTE_MAP = {
'convert_to': attr.convert_to_list,
'is_visible': True},
'connection_limit': {'allow_post': True, 'allow_put': True,
'default': -1,
'validate': {'type:connection_limit':
lb_const.MIN_CONNECT_VALUE},
'default': lb_const.MIN_CONNECT_VALUE,
'convert_to': attr.convert_to_int,
'is_visible': True},
'protocol': {'allow_post': True, 'allow_put': False,

View File

@ -113,3 +113,8 @@ LOADBALANCER_AGENT = 'n-lbaas_agent'
LOADBALANCER = "LOADBALANCER"
LOADBALANCERV2 = "LOADBALANCERV2"
# Used to check number of connections per second allowed
# for the LBaaS V1 vip and LBaaS V2 listeners. -1 indicates
# no limit, the value cannot be less than -1.
MIN_CONNECT_VALUE = -1

View File

@ -69,6 +69,24 @@ class LoadBalancerExtensionTestCase(base.ExtensionTestCase):
self.assertIn('vip', res)
self.assertEqual(return_value, res['vip'])
def test_vip_create_with_connection_limit_smaller_than_min_value(self):
data = {'vip': {'name': 'vip1',
'description': 'descr_vip1',
'subnet_id': _uuid(),
'address': '127.0.0.1',
'protocol_port': 80,
'protocol': 'HTTP',
'pool_id': _uuid(),
'session_persistence': {'type': 'HTTP_COOKIE'},
'connection_limit': -4,
'admin_state_up': True,
'tenant_id': _uuid()}}
res = self.api.post(_get_path('lb/vips', fmt=self.fmt),
self.serialize(data),
content_type='application/%s' % self.fmt,
expect_errors=True)
self.assertEqual(exc.HTTPBadRequest.code, res.status_int)
def test_vip_list(self):
vip_id = _uuid()
return_value = [{'name': 'vip1',
@ -107,6 +125,15 @@ class LoadBalancerExtensionTestCase(base.ExtensionTestCase):
self.assertIn('vip', res)
self.assertEqual(return_value, res['vip'])
def test_vip_update_with_connection_limit_smaller_than_min_value(self):
vip_id = _uuid()
data = {'vip': {'connection_limit': -4}}
res = self.api.put(_get_path('lb/vips', id=vip_id, fmt=self.fmt),
self.serialize(data),
content_type='application/%s' % self.fmt,
expect_errors=True)
self.assertEqual(exc.HTTPBadRequest.code, res.status_int)
def test_vip_get(self):
vip_id = _uuid()
return_value = {'name': 'vip1',
@ -651,6 +678,24 @@ class LoadBalancerExtensionV2TestCase(base.ExtensionTestCase):
self.assertIn('listener', res)
self.assertEqual(res['listener'], return_value)
def test_listener_create_with_connection_limit_less_than_min_value(self):
data = {'listener': {'tenant_id': _uuid(),
'name': 'listen-name-1',
'description': 'listen-1-desc',
'protocol': 'HTTP',
'protocol_port': 80,
'default_tls_container_ref': None,
'sni_container_refs': [],
'connection_limit': -4,
'admin_state_up': True,
'loadbalancer_id': _uuid()}}
res = self.api.post(_get_path('lbaas/listeners', fmt=self.fmt),
self.serialize(data),
content_type='application/{0}'.format(self.fmt),
expect_errors=True)
self.assertEqual(exc.HTTPBadRequest.code, res.status_int)
def test_listener_list(self):
listener_id = _uuid()
return_value = [{'admin_state_up': True,
@ -718,6 +763,16 @@ class LoadBalancerExtensionV2TestCase(base.ExtensionTestCase):
self.assertIn('listener', res)
self.assertEqual(res['listener'], return_value)
def test_listener_update_with_connection_limit_less_than_min_value(self):
listener_id = _uuid()
update_data = {'listener': {'connection_limit': -4}}
res = self.api.put(_get_path('lbaas/listeners',
id=listener_id,
fmt=self.fmt),
self.serialize(update_data),
expect_errors=True)
self.assertEqual(exc.HTTPBadRequest.code, res.status_int)
def test_listener_get(self):
listener_id = _uuid()
return_value = {'name': 'listener1',