[LBaaS v2] Validate name, description and tenant_id attributes length

* Unskip related API tests
* Fixed a number of negative pool tests which didn't pass
  listener_id with create_pool requests thus didn't actually
  test anything.
* Fixed admin api v2 tests that expected create operations with
  an empty 'tenant_id' field to succeed.

Conflicts:
	neutron_lbaas/extensions/loadbalancerv2.py

Change-Id: If50c664086e1b2bffa2899775de010c0a424f505
Related-Bug: #1408230
(cherry picked from commit b54dc219c1)
This commit is contained in:
Elena Ezhova 2015-09-23 15:08:10 +03:00
parent ab8c9925e5
commit af19f54319
9 changed files with 78 additions and 80 deletions

View File

@ -145,15 +145,16 @@ RESOURCE_ATTRIBUTE_MAP = {
'is_visible': True,
'primary_key': True},
'name': {'allow_post': True, 'allow_put': True,
'validate': {'type:string': None},
'validate': {'type:string': attr.NAME_MAX_LEN},
'default': '',
'is_visible': True},
'tenant_id': {'allow_post': True, 'allow_put': False,
'validate': {'type:string': None},
'validate': {'type:not_empty_string':
attr.TENANT_ID_MAX_LEN},
'required_by_policy': True,
'is_visible': True},
'description': {'allow_post': True, 'allow_put': True,
'validate': {'type:string': None},
'validate': {'type:string': attr.DESCRIPTION_MAX_LEN},
'is_visible': True, 'default': ''},
'vip_subnet_id': {'allow_post': True, 'allow_put': False,
'validate': {'type:uuid': None},
@ -184,15 +185,16 @@ RESOURCE_ATTRIBUTE_MAP = {
'is_visible': True,
'primary_key': True},
'tenant_id': {'allow_post': True, 'allow_put': False,
'validate': {'type:string': None},
'validate': {'type:not_empty_string':
attr.TENANT_ID_MAX_LEN},
'required_by_policy': True,
'is_visible': True},
'name': {'allow_post': True, 'allow_put': True,
'validate': {'type:string': None},
'validate': {'type:string': attr.NAME_MAX_LEN},
'default': '',
'is_visible': True},
'description': {'allow_post': True, 'allow_put': True,
'validate': {'type:string': None},
'validate': {'type:string': attr.DESCRIPTION_MAX_LEN},
'is_visible': True, 'default': ''},
'loadbalancer_id': {'allow_post': True, 'allow_put': False,
'validate': {'type:uuid': None},
@ -236,14 +238,15 @@ RESOURCE_ATTRIBUTE_MAP = {
'is_visible': True,
'primary_key': True},
'tenant_id': {'allow_post': True, 'allow_put': False,
'validate': {'type:string': None},
'validate': {'type:not_empty_string':
attr.TENANT_ID_MAX_LEN},
'required_by_policy': True,
'is_visible': True},
'name': {'allow_post': True, 'allow_put': True,
'validate': {'type:string': None},
'validate': {'type:string': attr.NAME_MAX_LEN},
'is_visible': True, 'default': ''},
'description': {'allow_post': True, 'allow_put': True,
'validate': {'type:string': None},
'validate': {'type:string': attr.DESCRIPTION_MAX_LEN},
'is_visible': True, 'default': ''},
'listener_id': {'allow_post': True, 'allow_put': False,
'validate': {'type:uuid': None},
@ -286,7 +289,8 @@ RESOURCE_ATTRIBUTE_MAP = {
'is_visible': True,
'primary_key': True},
'tenant_id': {'allow_post': True, 'allow_put': False,
'validate': {'type:string': None},
'validate': {'type:not_empty_string':
attr.TENANT_ID_MAX_LEN},
'required_by_policy': True,
'is_visible': True},
'pool_id': {'allow_post': True, 'allow_put': False,
@ -346,7 +350,8 @@ SUB_RESOURCE_ATTRIBUTE_MAP = {
'is_visible': True,
'primary_key': True},
'tenant_id': {'allow_post': True, 'allow_put': False,
'validate': {'type:string': None},
'validate': {'type:not_empty_string':
attr.TENANT_ID_MAX_LEN},
'required_by_policy': True,
'is_visible': True},
'address': {'allow_post': True, 'allow_put': False,

View File

@ -14,6 +14,7 @@
from oslo_log import log as logging
from oslo_utils import uuidutils
from tempest_lib import exceptions as ex
from neutron_lbaas.tests.tempest.lib.common.utils import data_utils
from neutron_lbaas.tests.tempest.lib import config
@ -81,17 +82,13 @@ class TestHealthMonitors(base.BaseAdminTestCase):
def test_create_health_monitor_empty_tenant_id_field(self):
"""
Test with admin user create health monitor with an empty tenant id
field.
should fail.
"""
hm = self._create_health_monitor(type='HTTP', delay=3, max_retries=10,
timeout=5,
pool_id=self.pool.get('id'),
tenant_id="")
self.assertEqual(hm.get('tenant_id'), "")
# cleanup test
self._delete_health_monitor(hm.get('id'))
self.assertRaises(ex.BadRequest, self._create_health_monitor,
type='HTTP', delay=3, max_retries=10,
timeout=5,
pool_id=self.pool.get('id'),
tenant_id="")
@test.attr(type='smoke')
def test_create_health_monitor_for_another_tenant_id_field(self):

View File

@ -15,6 +15,7 @@
from oslo_log import log as logging
from tempest_lib.common.utils import data_utils
from tempest_lib import exceptions as ex
from neutron_lbaas.tests.tempest.lib import config
from neutron_lbaas.tests.tempest.lib import test
@ -62,20 +63,16 @@ class ListenersTestJSON(base.BaseAdminTestCase):
@test.attr(type='smoke')
def test_create_listener_empty_tenant_id(self):
"""Test create listener with an empty tenant id"""
"""Test create listener with an empty tenant id should fail"""
create_new_listener_kwargs = self.create_listener_kwargs
create_new_listener_kwargs['protocol_port'] = 8081
create_new_listener_kwargs['tenant_id'] = ""
new_listener = self._create_listener(
**create_new_listener_kwargs)
new_listener_id = new_listener['id']
self.assertRaises(ex.BadRequest,
self._create_listener,
**create_new_listener_kwargs)
self._check_status_tree(
load_balancer_id=self.load_balancer_id,
listener_ids=[self.listener_id, new_listener_id])
listener = self.listeners_client.get_listener(
new_listener_id)
self.assertEqual(new_listener, listener)
self._delete_listener(new_listener_id)
listener_ids=[self.listener_id])
@test.attr(type='smoke')
def test_create_listener_invalid_tenant_id(self):

View File

@ -15,7 +15,6 @@
from oslo_log import log as logging
from tempest_lib.common.utils import data_utils
from tempest_lib import decorators
from tempest_lib import exceptions
from neutron_lbaas.tests.tempest.lib import config
@ -219,7 +218,6 @@ class ListenersTestJSON(base.BaseTestCase):
self._check_status_tree(load_balancer_id=self.load_balancer_id,
listener_ids=[self.listener_id])
@decorators.skip_because(bug="1434717")
@test.attr(type='negative')
def test_create_listener_invalid_name(self):
"""Test create listener with an invalid name"""
@ -232,7 +230,6 @@ class ListenersTestJSON(base.BaseTestCase):
self._check_status_tree(load_balancer_id=self.load_balancer_id,
listener_ids=[self.listener_id])
@decorators.skip_because(bug="1434717")
@test.attr(type='negative')
def test_create_listener_invalid_description(self):
"""Test create listener with an invalid description"""
@ -404,7 +401,6 @@ class ListenersTestJSON(base.BaseTestCase):
self._check_status_tree(load_balancer_id=self.load_balancer_id,
listener_ids=[self.listener_id])
@decorators.skip_because(bug="1434717")
@test.attr(type='negative')
def test_update_listener_invalid_name(self):
"""Test update a listener with an invalid name"""
@ -415,7 +411,6 @@ class ListenersTestJSON(base.BaseTestCase):
self._check_status_tree(load_balancer_id=self.load_balancer_id,
listener_ids=[self.listener_id])
@decorators.skip_because(bug="1434717")
@test.attr(type='negative')
def test_update_listener_invalid_description(self):
"""Test update a listener with an invalid description"""

View File

@ -14,6 +14,7 @@
from oslo_log import log as logging
from tempest_lib.common.utils import data_utils
from tempest_lib import exceptions as ex
from neutron_lbaas.tests.tempest.lib import config
from neutron_lbaas.tests.tempest.lib import test
@ -84,13 +85,12 @@ class LoadBalancersTestJSON(base.BaseAdminTestCase):
@test.attr(type='smoke')
def test_create_load_balancer_empty_tenant_id_field(self):
"""Test create load balancer with empty tenant_id field"""
load_balancer = self.load_balancers_client.create_load_balancer(
vip_subnet_id=self.subnet['id'],
tenant_id="")
self.assertEqual(load_balancer.get('tenant_id'), "")
self._wait_for_load_balancer_status(load_balancer['id'])
self._delete_load_balancer(load_balancer['id'])
"""Test create load balancer with empty tenant_id field should fail"""
self.assertRaises(ex.BadRequest,
self.load_balancers_client.create_load_balancer,
vip_subnet_id=self.subnet['id'],
wait=False,
tenant_id="")
@test.attr(type='smoke')
def test_create_load_balancer_for_another_tenant(self):

View File

@ -17,7 +17,6 @@ from netaddr import IPAddress
from oslo_log import log as logging
from tempest_lib.common.utils import data_utils
from tempest_lib import decorators
from tempest_lib import exceptions
from neutron_lbaas.tests.tempest.lib import config
@ -229,7 +228,6 @@ class LoadBalancersTestJSON(base.BaseTestCase):
wait=False,
tenant_id="&^%123")
@decorators.skip_because(bug="1434717")
@test.attr(type='negative')
def test_create_load_balancer_invalid_name(self):
"""Test create load balancer with an invalid name"""
@ -240,7 +238,6 @@ class LoadBalancersTestJSON(base.BaseTestCase):
vip_subnet_id=self.subnet['id'],
name='n' * 256)
@decorators.skip_because(bug="1434717")
@test.attr(type='negative')
def test_create_load_balancer_invalid_description(self):
"""Test create load balancer with an invalid description"""
@ -308,7 +305,6 @@ class LoadBalancersTestJSON(base.BaseTestCase):
self.load_balancer_id)
self.assertEqual(load_balancer.get('name'), "")
@decorators.skip_because(bug="1434717")
@test.attr(type='negative')
def test_update_load_balancer_invalid_name(self):
"""Test update load balancer with invalid name"""
@ -330,7 +326,6 @@ class LoadBalancersTestJSON(base.BaseTestCase):
load_balancer_new = load_balancer['name']
self.assertEqual(load_balancer_initial, load_balancer_new)
@decorators.skip_because(bug="1434717")
@test.attr(type='negative')
def test_update_load_balancer_invalid_description(self):
"""Test update load balancer with invalid description"""

View File

@ -15,6 +15,7 @@
from oslo_log import log as logging
from tempest_lib.common.utils import data_utils
from tempest_lib import exceptions as ex
from neutron_lbaas.tests.tempest.lib import config
from neutron_lbaas.tests.tempest.lib import test
@ -77,14 +78,11 @@ class MemberTestJSON(base.BaseAdminTestCase):
@test.attr(type='smoke')
def test_create_member_empty_tenant_id(self):
"""Test create member with an empty tenant_id"""
"""Test create member with an empty tenant_id should fail"""
member_opts = {}
member_opts['address'] = "127.0.0.1"
member_opts['protocol_port'] = 80
member_opts['subnet_id'] = self.subnet_id
member_opts['tenant_id'] = ""
member = self._create_member(self.pool_id, **member_opts)
self.assertEqual(member['subnet_id'], self.subnet_id)
self.assertEqual(member['tenant_id'], "")
self._delete_member(self.pool_id, member['id'])
self.assertEmpty(self.members_client.list_members(self.pool_id))
self.assertRaises(ex.BadRequest, self._create_member,
self.pool_id, **member_opts)

View File

@ -14,6 +14,7 @@
from tempest_lib.common.utils import data_utils
from tempest_lib import decorators
from tempest_lib import exceptions as ex
from neutron_lbaas.tests.tempest.lib import test
from neutron_lbaas.tests.tempest.v2.api import base
@ -70,16 +71,13 @@ class TestPools(base.BaseAdminTestCase):
**kwargs)
return response
@decorators.skip_because(bug="1468457")
@test.attr(type='smoke')
def test_create_pool_using_empty_tenant_field(self):
"""Test create pool with empty tenant field"""
new_pool = self._prepare_and_create_pool(
tenant_id="")
pool = self.pools_client.get_pool(new_pool.get('id'))
pool_tenant = pool.get('tenant_id')
self.assertEqual(pool_tenant, '')
self._delete_pool(new_pool.get('id'))
"""Test create pool with empty tenant field should fail"""
self.assertRaises(ex.BadRequest, self._create_pool,
protocol='HTTP',
tenant_id="",
lb_algorithm='ROUND_ROBIN')
@decorators.skip_because(bug="1468457")
@test.attr(type='smoke')

View File

@ -13,7 +13,6 @@
# under the License.
from tempest_lib.common.utils import data_utils
from tempest_lib import decorators
from tempest_lib import exceptions as ex
from neutron_lbaas.tests.tempest.lib import test
@ -48,6 +47,9 @@ class TestPools(base.BaseTestCase):
tenant_id=cls.subnet.get('tenant_id'),
vip_subnet_id=cls.subnet.get('id'),
wait=True)
cls.listener = cls._create_listener(
loadbalancer_id=cls.load_balancer.get('id'),
protocol='HTTP', protocol_port=80)
def increment_protocol_port(self):
global PROTOCOL_PORT
@ -220,7 +222,8 @@ class TestPools(base.BaseTestCase):
"""Test create pool with an invalid protocol"""
self.assertRaises(ex.BadRequest, self._create_pool,
protocol='UDP',
lb_algorithm='ROUND_ROBIN')
lb_algorithm='ROUND_ROBIN',
listener_id=self.listener['id'])
@test.attr(type='negative')
def test_create_pool_invalid_session_persistence_field(self):
@ -228,14 +231,16 @@ class TestPools(base.BaseTestCase):
self.assertRaises(ex.BadRequest, self._create_pool,
protocol='HTTP',
session_persistence={'type': 'HTTP'},
lb_algorithm='ROUND_ROBIN')
lb_algorithm='ROUND_ROBIN',
listener_id=self.listener['id'])
@test.attr(type='negative')
def test_create_pool_invalid_algorithm(self):
"""Test create pool with an invalid algorithm"""
self.assertRaises(ex.BadRequest, self._create_pool,
protocol='HTTP',
lb_algorithm='LEAST_CON')
lb_algorithm='LEAST_CON',
listener_id=self.listener['id'])
@test.attr(type='negative')
def test_create_pool_invalid_admin_state_up(self):
@ -243,7 +248,8 @@ class TestPools(base.BaseTestCase):
self.assertRaises(ex.BadRequest, self._create_pool,
protocol='HTTP',
admin_state_up="$!1%9823",
lb_algorithm='ROUND_ROBIN')
lb_algorithm='ROUND_ROBIN',
listener_id=self.listener['id'])
@test.attr(type='negative')
def test_create_pool_invalid_listener_field(self):
@ -276,7 +282,8 @@ class TestPools(base.BaseTestCase):
self.assertRaises(ex.BadRequest, self._create_pool,
protocol='HTTP',
lb_algorithm='ROUND_ROBIN',
protocol_port=80)
protocol_port=80,
listener_id=self.listener['id'])
@test.attr(type='negative')
def test_create_pool_empty_listener_field(self):
@ -311,7 +318,8 @@ class TestPools(base.BaseTestCase):
"""Test create pool with an empty protocol"""
self.assertRaises(ex.BadRequest, self._create_pool,
protocol="",
lb_algorithm='ROUND_ROBIN')
lb_algorithm='ROUND_ROBIN',
listener_id=self.listener['id'])
@test.attr(type='negative')
def test_create_pool_empty_session_persistence_field(self):
@ -319,14 +327,16 @@ class TestPools(base.BaseTestCase):
self.assertRaises(ex.BadRequest, self._create_pool,
session_persistence="",
protocol='HTTP',
lb_algorithm='ROUND_ROBIN')
lb_algorithm='ROUND_ROBIN',
listener_id=self.listener['id'])
@test.attr(type='negative')
def test_create_pool_empty_algorithm(self):
"""Test create pool with an empty algorithm"""
self.assertRaises(ex.BadRequest, self._create_pool,
protocol='HTTP',
lb_algorithm="")
lb_algorithm="",
listener_id=self.listener['id'])
@test.attr(type='negative')
def test_create_pool_empty_admin_state_up(self):
@ -342,7 +352,8 @@ class TestPools(base.BaseTestCase):
self.assertRaises(ex.BadRequest, self._create_pool,
protocol='HTTP',
tenant_id="",
lb_algorithm='ROUND_ROBIN')
lb_algorithm='ROUND_ROBIN',
listener_id=self.listener['id'])
@test.attr(type='negative')
def test_create_pool_for_other_tenant_field(self):
@ -351,9 +362,9 @@ class TestPools(base.BaseTestCase):
self.assertRaises(ex.BadRequest, self._create_pool,
protocol='HTTP',
tenant_id=tenant,
lb_algorithm='ROUND_ROBIN')
lb_algorithm='ROUND_ROBIN',
listener_id=self.listener['id'])
@decorators.skip_because(bug="1434717")
@test.attr(type='negative')
def test_create_pool_invalid_name_field(self):
"""
@ -363,18 +374,19 @@ class TestPools(base.BaseTestCase):
self.assertRaises(ex.BadRequest, self._create_pool,
protocol='HTTP',
lb_algorithm='ROUND_ROBIN',
listener_id=self.listener['id'],
name='n' * 256)
@decorators.skip_because(bug="1434717")
@test.attr(type='negative')
def test_create_pool_invalid_desc_field(self):
"""
known bug with input more than 255 chars
Test create pool with invalid desc field
"""
self.assertRaises(ex.BadRequest, self._create_pool,
self.assertRaises(ex.BadRequest, self._prepare_and_create_pool,
protocol='HTTP',
lb_algorithm='ROUND_ROBIN',
listener_id=self.listener['id'],
description='d' * 256)
@test.attr(type='negative')
@ -385,7 +397,8 @@ class TestPools(base.BaseTestCase):
self.assertRaises(ex.BadRequest, self._create_pool,
session_persistence={'type': 'UNSUPPORTED'},
protocol='HTTP',
lb_algorithm='ROUND_ROBIN')
lb_algorithm='ROUND_ROBIN',
listener_id=self.listener['id'])
@test.attr(type='smoke')
def test_create_pool_with_session_persistence_http_cookie(self):
@ -415,7 +428,8 @@ class TestPools(base.BaseTestCase):
session_persistence={'type': 'HTTP_COOKIE',
'cookie_name': 'sessionId'},
protocol='HTTP',
lb_algorithm='ROUND_ROBIN')
lb_algorithm='ROUND_ROBIN',
listener_id=self.listener['id'])
@test.attr(type='negative')
def test_create_pool_with_session_persistence_without_cookie_name(self):
@ -425,7 +439,8 @@ class TestPools(base.BaseTestCase):
self.assertRaises(ex.BadRequest, self._create_pool,
session_persistence={'type': 'APP_COOKIE'},
protocol='HTTP',
lb_algorithm='ROUND_ROBIN')
lb_algorithm='ROUND_ROBIN',
listener_id=self.listener['id'])
@test.attr(type='smoke')
def test_update_pool(self):
@ -482,7 +497,6 @@ class TestPools(base.BaseTestCase):
self._wait_for_load_balancer_status(self.load_balancer.get('id'))
self._delete_pool(new_pool.get('id'))
@decorators.skip_because(bug="1434717")
@test.attr(type='negative')
def test_update_pool_invalid_name(self):
"""Test update pool with invalid name"""
@ -491,7 +505,6 @@ class TestPools(base.BaseTestCase):
new_pool.get('id'), name='n' * 256)
self._delete_pool(new_pool.get('id'))
@decorators.skip_because(bug="1434717")
@test.attr(type='negative')
def test_update_pool_invalid_desc(self):
"""Test update pool with invalid desc"""