Merge "Remove unused create_load_balancer_tree code"
This commit is contained in:
commit
0f9050ff61
|
@ -23,43 +23,6 @@ from octavia.common import validate
|
|||
CONF = cfg.CONF
|
||||
|
||||
|
||||
def create_load_balancer_tree(lb_dict):
|
||||
listeners = lb_dict.pop('listeners') or []
|
||||
prepped_lb = create_load_balancer(lb_dict)
|
||||
prepped_lb['listeners'] = []
|
||||
for listener_dict in listeners:
|
||||
pool = listener_dict.pop('default_pool') or None
|
||||
listener_dict['project_id'] = prepped_lb.get('project_id')
|
||||
prepped_listener = create_listener(listener_dict, prepped_lb.get('id'))
|
||||
if pool:
|
||||
hm = pool.pop('health_monitor') or None
|
||||
members = pool.pop('members') or []
|
||||
pool['project_id'] = prepped_lb.get('project_id')
|
||||
prepped_pool = create_pool(pool)
|
||||
pool_id = prepped_pool.get('id')
|
||||
prepped_pool['load_balancer_id'] = prepped_lb.get('id')
|
||||
if hm:
|
||||
hm['project_id'] = lb_dict.get('project_id')
|
||||
prepped_hm = create_health_monitor(hm, pool_id)
|
||||
prepped_pool['health_monitor'] = prepped_hm
|
||||
prepped_pool['members'] = []
|
||||
for member_dict in members:
|
||||
member_dict['project_id'] = prepped_lb.get('project_id')
|
||||
prepped_pool['members'].append(
|
||||
create_member(member_dict, pool_id))
|
||||
prepped_listener['default_pool'] = prepped_pool
|
||||
prepped_listener['default_pool_id'] = prepped_pool['id']
|
||||
if listener_dict.get('l7policies'):
|
||||
prepped_l7policies = []
|
||||
for l7policy in listener_dict.get('l7policies'):
|
||||
prepped_l7policy = create_l7policy(
|
||||
l7policy, prepped_lb.get('id'), listener_dict.get('id'))
|
||||
prepped_l7policies.append(prepped_l7policy)
|
||||
prepped_listener['l7policies'] = prepped_l7policies
|
||||
prepped_lb['listeners'].append(prepped_listener)
|
||||
return prepped_lb
|
||||
|
||||
|
||||
def create_load_balancer(lb_dict):
|
||||
if not lb_dict.get('id'):
|
||||
lb_dict['id'] = uuidutils.generate_uuid()
|
||||
|
|
|
@ -26,7 +26,6 @@ from oslo_db import api as oslo_db_api
|
|||
from oslo_db import exception as db_exception
|
||||
from oslo_log import log as logging
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import excutils
|
||||
from oslo_utils import uuidutils
|
||||
from sqlalchemy.orm import noload
|
||||
from sqlalchemy.orm import Session
|
||||
|
@ -667,154 +666,6 @@ class Repositories(object):
|
|||
{'proj': project_id})
|
||||
raise exceptions.ProjectBusyException() from e
|
||||
|
||||
def create_load_balancer_tree(self, session, lock_session, lb_dict):
|
||||
listener_dicts = lb_dict.pop('listeners', [])
|
||||
vip_dict = lb_dict.pop('vip')
|
||||
additional_vip_dicts = lb_dict.pop('additional_vips', [])
|
||||
try:
|
||||
if self.check_quota_met(session,
|
||||
lock_session,
|
||||
data_models.LoadBalancer,
|
||||
lb_dict['project_id']):
|
||||
raise exceptions.QuotaException(
|
||||
resource=data_models.LoadBalancer._name())
|
||||
lb_dm = self.create_load_balancer_and_vip(
|
||||
lock_session, lb_dict, vip_dict, additional_vip_dicts)
|
||||
for listener_dict in listener_dicts:
|
||||
# Add listener quota check
|
||||
if self.check_quota_met(session,
|
||||
lock_session,
|
||||
data_models.Listener,
|
||||
lb_dict['project_id']):
|
||||
raise exceptions.QuotaException(
|
||||
resource=data_models.Listener._name())
|
||||
pool_dict = listener_dict.pop('default_pool', None)
|
||||
l7policies_dict = listener_dict.pop('l7policies', None)
|
||||
sni_containers = listener_dict.pop('sni_containers', [])
|
||||
if pool_dict:
|
||||
# Add pool quota check
|
||||
if self.check_quota_met(session,
|
||||
lock_session,
|
||||
data_models.Pool,
|
||||
lb_dict['project_id']):
|
||||
raise exceptions.QuotaException(
|
||||
resource=data_models.Pool._name())
|
||||
hm_dict = pool_dict.pop('health_monitor', None)
|
||||
member_dicts = pool_dict.pop('members', [])
|
||||
sp_dict = pool_dict.pop('session_persistence', None)
|
||||
pool_dict['load_balancer_id'] = lb_dm.id
|
||||
del pool_dict['listener_id']
|
||||
pool_dm = self.pool.create(lock_session, **pool_dict)
|
||||
if sp_dict:
|
||||
sp_dict['pool_id'] = pool_dm.id
|
||||
self.session_persistence.create(lock_session,
|
||||
**sp_dict)
|
||||
if hm_dict:
|
||||
# Add hm quota check
|
||||
if self.check_quota_met(session,
|
||||
lock_session,
|
||||
data_models.HealthMonitor,
|
||||
lb_dict['project_id']):
|
||||
raise exceptions.QuotaException(
|
||||
resource=data_models.HealthMonitor._name())
|
||||
hm_dict['id'] = pool_dm.id
|
||||
hm_dict['pool_id'] = pool_dm.id
|
||||
self.health_monitor.create(lock_session, **hm_dict)
|
||||
for r_member_dict in member_dicts:
|
||||
# Add member quota check
|
||||
if self.check_quota_met(session,
|
||||
lock_session,
|
||||
data_models.Member,
|
||||
lb_dict['project_id']):
|
||||
raise exceptions.QuotaException(
|
||||
resource=data_models.Member._name())
|
||||
r_member_dict['pool_id'] = pool_dm.id
|
||||
self.member.create(lock_session, **r_member_dict)
|
||||
listener_dict['default_pool_id'] = pool_dm.id
|
||||
self.listener.create(lock_session, **listener_dict)
|
||||
for sni_container in sni_containers:
|
||||
self.sni.create(lock_session, **sni_container)
|
||||
if l7policies_dict:
|
||||
for policy_dict in l7policies_dict:
|
||||
# Add l7policy quota check
|
||||
if self.check_quota_met(session,
|
||||
lock_session,
|
||||
data_models.L7Policy,
|
||||
lb_dict['project_id']):
|
||||
raise exceptions.QuotaException(
|
||||
resource=data_models.L7Policy._name())
|
||||
l7rules_dict = policy_dict.pop('l7rules')
|
||||
if policy_dict.get('redirect_pool'):
|
||||
# Add pool quota check
|
||||
if self.check_quota_met(session,
|
||||
lock_session,
|
||||
data_models.Pool,
|
||||
lb_dict['project_id']):
|
||||
raise exceptions.QuotaException(
|
||||
resource=data_models.Pool._name())
|
||||
r_pool_dict = policy_dict.pop(
|
||||
'redirect_pool')
|
||||
r_hm_dict = r_pool_dict.pop('health_monitor',
|
||||
None)
|
||||
r_sp_dict = r_pool_dict.pop(
|
||||
'session_persistence', None)
|
||||
r_member_dicts = r_pool_dict.pop('members', [])
|
||||
if 'listener_id' in r_pool_dict.keys():
|
||||
del r_pool_dict['listener_id']
|
||||
r_pool_dm = self.pool.create(lock_session,
|
||||
**r_pool_dict)
|
||||
if r_sp_dict:
|
||||
r_sp_dict['pool_id'] = r_pool_dm.id
|
||||
self.session_persistence.create(lock_session,
|
||||
**r_sp_dict)
|
||||
if r_hm_dict:
|
||||
# Add hm quota check
|
||||
if self.check_quota_met(
|
||||
session,
|
||||
lock_session,
|
||||
data_models.HealthMonitor,
|
||||
lb_dict['project_id']):
|
||||
res = data_models.HealthMonitor
|
||||
raise exceptions.QuotaException(
|
||||
resource=res._name())
|
||||
r_hm_dict['id'] = r_pool_dm.id
|
||||
r_hm_dict['pool_id'] = r_pool_dm.id
|
||||
self.health_monitor.create(lock_session,
|
||||
**r_hm_dict)
|
||||
for r_member_dict in r_member_dicts:
|
||||
# Add member quota check
|
||||
if self.check_quota_met(
|
||||
session,
|
||||
lock_session,
|
||||
data_models.Member,
|
||||
lb_dict['project_id']):
|
||||
raise exceptions.QuotaException(
|
||||
resource=data_models.Member._name())
|
||||
r_member_dict['pool_id'] = r_pool_dm.id
|
||||
self.member.create(lock_session,
|
||||
**r_member_dict)
|
||||
policy_dict['redirect_pool_id'] = r_pool_dm.id
|
||||
policy_dm = self.l7policy.create(lock_session,
|
||||
**policy_dict)
|
||||
for rule_dict in l7rules_dict:
|
||||
# Add l7rule quota check
|
||||
if self.check_quota_met(
|
||||
session,
|
||||
lock_session,
|
||||
data_models.L7Rule,
|
||||
lb_dict['project_id']):
|
||||
raise exceptions.QuotaException(
|
||||
resource=data_models.L7Rule._name())
|
||||
rule_dict['l7policy_id'] = policy_dm.id
|
||||
self.l7rule.create(lock_session, **rule_dict)
|
||||
lock_session.commit()
|
||||
except Exception:
|
||||
with excutils.save_and_reraise_exception():
|
||||
lock_session.rollback()
|
||||
|
||||
session.expire_all()
|
||||
return self.load_balancer.get(session, id=lb_dm.id)
|
||||
|
||||
def get_amphora_stats(self, session, amp_id):
|
||||
"""Gets the statistics for all listeners on an amphora.
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import copy
|
||||
import datetime
|
||||
import random
|
||||
from unittest import mock
|
||||
|
@ -439,90 +438,6 @@ class AllRepositoriesTest(base.OctaviaDBTestBase):
|
|||
pool.update(update_pool)
|
||||
self.assertEqual(pool, pool_dm_dict)
|
||||
|
||||
def test_create_load_balancer_tree(self):
|
||||
self.skipTest("SLQAlchemy/PySqlite transaction handling is broken. "
|
||||
"Version 1.3.16 of sqlachemy changes how sqlite3 "
|
||||
"transactions are handled and this test fails as "
|
||||
"The LB created early in this process now disappears "
|
||||
"from the transaction context.")
|
||||
project_id = uuidutils.generate_uuid()
|
||||
member = {'project_id': project_id, 'ip_address': '11.0.0.1',
|
||||
'protocol_port': 80, 'enabled': True, 'backup': False,
|
||||
'operating_status': constants.ONLINE,
|
||||
'provisioning_status': constants.PENDING_CREATE,
|
||||
'id': uuidutils.generate_uuid()}
|
||||
health_monitor = {'type': constants.HEALTH_MONITOR_HTTP, 'delay': 1,
|
||||
'timeout': 1, 'fall_threshold': 1,
|
||||
'rise_threshold': 1, 'enabled': True,
|
||||
'operating_status': constants.OFFLINE,
|
||||
'provisioning_status': constants.PENDING_CREATE}
|
||||
sp = {'type': constants.SESSION_PERSISTENCE_APP_COOKIE,
|
||||
'cookie_name': 'cookie_name'}
|
||||
pool = {'protocol': constants.PROTOCOL_HTTP, 'name': 'pool1',
|
||||
'description': 'desc1', 'listener_id': None,
|
||||
'lb_algorithm': constants.LB_ALGORITHM_ROUND_ROBIN,
|
||||
'enabled': True, 'operating_status': constants.ONLINE,
|
||||
'provisioning_status': constants.PENDING_CREATE,
|
||||
'project_id': project_id, 'members': [member],
|
||||
'health_monitor': health_monitor, 'session_persistence': sp,
|
||||
'id': uuidutils.generate_uuid()}
|
||||
sp['pool_id'] = pool.get('id')
|
||||
member['pool_id'] = pool.get('id')
|
||||
health_monitor['pool_id'] = pool.get('id')
|
||||
l7rule = {'type': constants.L7RULE_TYPE_HOST_NAME,
|
||||
'compare_type': constants.L7RULE_COMPARE_TYPE_EQUAL_TO,
|
||||
'operating_status': constants.ONLINE,
|
||||
'provisioning_status': constants.PENDING_CREATE,
|
||||
'value': 'localhost',
|
||||
'enabled': True}
|
||||
r_health_monitor = {'type': constants.HEALTH_MONITOR_HTTP, 'delay': 1,
|
||||
'timeout': 1, 'fall_threshold': 1,
|
||||
'rise_threshold': 1, 'enabled': True,
|
||||
'operating_status': constants.OFFLINE,
|
||||
'provisioning_status': constants.PENDING_CREATE}
|
||||
redirect_pool = {'protocol': constants.PROTOCOL_HTTP, 'name': 'pool1',
|
||||
'description': 'desc1', 'project_id': project_id,
|
||||
'lb_algorithm': constants.LB_ALGORITHM_ROUND_ROBIN,
|
||||
'enabled': True, 'operating_status': constants.ONLINE,
|
||||
'provisioning_status': constants.PENDING_CREATE,
|
||||
'id': uuidutils.generate_uuid(),
|
||||
'health_monitor': r_health_monitor}
|
||||
l7policy = {'name': 'l7policy1', 'enabled': True,
|
||||
'description': 'l7policy_description', 'position': 1,
|
||||
'action': constants.L7POLICY_ACTION_REDIRECT_TO_POOL,
|
||||
'redirect_pool': redirect_pool, 'l7rules': [l7rule],
|
||||
'redirect_pool_id': redirect_pool.get('id'),
|
||||
'id': uuidutils.generate_uuid(),
|
||||
'provisioning_status': constants.PENDING_CREATE,
|
||||
'operating_status': constants.ONLINE}
|
||||
l7rule['l7policy_id'] = l7policy.get('id')
|
||||
listener = {'project_id': project_id, 'name': 'listener1',
|
||||
'description': 'listener_description',
|
||||
'protocol': constants.PROTOCOL_HTTP, 'protocol_port': 80,
|
||||
'connection_limit': 1, 'enabled': True,
|
||||
'default_pool': pool, 'l7policies': [l7policy],
|
||||
'provisioning_status': constants.PENDING_CREATE,
|
||||
'operating_status': constants.ONLINE,
|
||||
'id': uuidutils.generate_uuid()}
|
||||
l7policy['listener_id'] = listener.get('id')
|
||||
vip = {'ip_address': '192.0.2.1', 'port_id': uuidutils.generate_uuid(),
|
||||
'subnet_id': uuidutils.generate_uuid()}
|
||||
lb = {'name': 'lb1', 'description': 'desc1', 'enabled': True,
|
||||
'topology': constants.TOPOLOGY_ACTIVE_STANDBY,
|
||||
'vrrp_group': None, 'server_group_id': uuidutils.generate_uuid(),
|
||||
'project_id': project_id, 'vip': vip,
|
||||
'provisioning_status': constants.PENDING_CREATE,
|
||||
'operating_status': constants.ONLINE,
|
||||
'id': uuidutils.generate_uuid(), 'listeners': [listener]}
|
||||
listener['load_balancer_id'] = lb.get('id')
|
||||
pool['load_balancer_id'] = lb.get('id')
|
||||
redirect_pool['load_balancer_id'] = lb.get('id')
|
||||
lock_session = db_api.get_session(autocommit=False)
|
||||
db_lb = self.repos.create_load_balancer_tree(self.session,
|
||||
lock_session, lb)
|
||||
self.assertIsNotNone(db_lb)
|
||||
self.assertIsInstance(db_lb, data_models.LoadBalancer)
|
||||
|
||||
def test_sqlite_transactions_broken(self):
|
||||
self.skipTest("SLQAlchemy/PySqlite transaction handling is broken. "
|
||||
"Version 1.3.16 of sqlachemy changes how sqlite3 "
|
||||
|
@ -531,8 +446,7 @@ class AllRepositoriesTest(base.OctaviaDBTestBase):
|
|||
"from the transaction context.")
|
||||
"""This test is a canary for pysqlite fixing transaction handling.
|
||||
|
||||
When this test starts failing, we can fix and un-skip the deadlock
|
||||
test below: `test_create_load_balancer_tree_quotas`.
|
||||
When this test starts failing, we can fix and un-skip the deadlock.
|
||||
"""
|
||||
project_id = uuidutils.generate_uuid()
|
||||
vip = {'ip_address': '192.0.2.1', 'port_id': uuidutils.generate_uuid(),
|
||||
|
@ -578,509 +492,6 @@ class AllRepositoriesTest(base.OctaviaDBTestBase):
|
|||
project_id=project_id).all()
|
||||
self.assertEqual(1, len(lbs)) # After rollback: 1 (broken!)
|
||||
|
||||
def test_create_load_balancer_tree_quotas(self):
|
||||
self.skipTest("PySqlite transaction handling is broken. We can unskip"
|
||||
"this when `test_sqlite_transactions_broken` fails.")
|
||||
conf = self.useFixture(oslo_fixture.Config(cfg.CONF))
|
||||
conf.config(group='api_settings', auth_strategy=constants.TESTING)
|
||||
project_id = uuidutils.generate_uuid()
|
||||
member = {'project_id': project_id, 'ip_address': '11.0.0.1',
|
||||
'protocol_port': 80, 'enabled': True,
|
||||
'operating_status': constants.ONLINE,
|
||||
'id': uuidutils.generate_uuid()}
|
||||
member2 = {'project_id': project_id, 'ip_address': '11.0.0.2',
|
||||
'protocol_port': 81, 'enabled': True,
|
||||
'operating_status': constants.ONLINE,
|
||||
'id': uuidutils.generate_uuid()}
|
||||
member3 = {'project_id': project_id, 'ip_address': '11.0.0.3',
|
||||
'protocol_port': 81, 'enabled': True,
|
||||
'operating_status': constants.ONLINE,
|
||||
'id': uuidutils.generate_uuid()}
|
||||
health_monitor = {'type': constants.HEALTH_MONITOR_HTTP, 'delay': 1,
|
||||
'timeout': 1, 'fall_threshold': 1,
|
||||
'rise_threshold': 1, 'enabled': True}
|
||||
sp = {'type': constants.SESSION_PERSISTENCE_APP_COOKIE,
|
||||
'cookie_name': 'cookie_name'}
|
||||
pool = {'protocol': constants.PROTOCOL_HTTP, 'name': 'pool1',
|
||||
'description': 'desc1', 'listener_id': None,
|
||||
'lb_algorithm': constants.LB_ALGORITHM_ROUND_ROBIN,
|
||||
'enabled': True, 'operating_status': constants.ONLINE,
|
||||
'project_id': project_id, 'members': [member],
|
||||
'health_monitor': health_monitor, 'session_persistence': sp,
|
||||
'id': uuidutils.generate_uuid()}
|
||||
pool2 = {'protocol': constants.PROTOCOL_HTTP, 'name': 'pool2',
|
||||
'description': 'desc1', 'listener_id': None,
|
||||
'lb_algorithm': constants.LB_ALGORITHM_ROUND_ROBIN,
|
||||
'enabled': True, 'operating_status': constants.ONLINE,
|
||||
'project_id': project_id, 'members': [member2],
|
||||
'health_monitor': health_monitor,
|
||||
'id': uuidutils.generate_uuid()}
|
||||
sp['pool_id'] = pool.get('id')
|
||||
member['pool_id'] = pool.get('id')
|
||||
health_monitor['pool_id'] = pool.get('id')
|
||||
l7rule = {'type': constants.L7RULE_TYPE_HOST_NAME,
|
||||
'compare_type': constants.L7RULE_COMPARE_TYPE_EQUAL_TO,
|
||||
'value': 'localhost'}
|
||||
l7rule2 = {'type': constants.L7RULE_TYPE_PATH,
|
||||
'compare_type': constants.L7RULE_COMPARE_TYPE_CONTAINS,
|
||||
'value': 'abc'}
|
||||
r_health_monitor = {'type': constants.HEALTH_MONITOR_HTTP, 'delay': 1,
|
||||
'timeout': 1, 'fall_threshold': 1,
|
||||
'rise_threshold': 1, 'enabled': True}
|
||||
redirect_pool = {'protocol': constants.PROTOCOL_HTTP, 'name': 'pool1',
|
||||
'description': 'desc1', 'project_id': project_id,
|
||||
'lb_algorithm': constants.LB_ALGORITHM_ROUND_ROBIN,
|
||||
'enabled': True, 'operating_status': constants.ONLINE,
|
||||
'id': uuidutils.generate_uuid(),
|
||||
'health_monitor': r_health_monitor,
|
||||
'members': [member3]}
|
||||
l7policy = {'name': 'l7policy1', 'enabled': True,
|
||||
'description': 'l7policy_description', 'position': 1,
|
||||
'action': constants.L7POLICY_ACTION_REDIRECT_TO_POOL,
|
||||
'redirect_pool': redirect_pool, 'l7rules': [l7rule],
|
||||
'redirect_pool_id': redirect_pool.get('id'),
|
||||
'id': uuidutils.generate_uuid()}
|
||||
l7rule['l7policy_id'] = l7policy.get('id')
|
||||
l7policy2 = {'name': 'l7policy2', 'enabled': True,
|
||||
'description': 'l7policy_description', 'position': 2,
|
||||
'action': constants.L7POLICY_ACTION_REJECT,
|
||||
'id': uuidutils.generate_uuid()}
|
||||
l7rule2['l7policy_id'] = l7policy2.get('id')
|
||||
listener = {'project_id': project_id, 'name': 'listener1',
|
||||
'description': 'listener_description',
|
||||
'protocol': constants.PROTOCOL_HTTP, 'protocol_port': 80,
|
||||
'connection_limit': 1, 'enabled': True,
|
||||
'default_pool': pool, 'l7policies': [l7policy, l7policy2],
|
||||
'provisioning_status': constants.PENDING_CREATE,
|
||||
'operating_status': constants.ONLINE,
|
||||
'id': uuidutils.generate_uuid()}
|
||||
listener2 = {'project_id': project_id, 'name': 'listener2',
|
||||
'description': 'listener_description',
|
||||
'protocol': constants.PROTOCOL_HTTP, 'protocol_port': 83,
|
||||
'connection_limit': 1, 'enabled': True,
|
||||
'default_pool': pool2,
|
||||
'provisioning_status': constants.PENDING_CREATE,
|
||||
'operating_status': constants.ONLINE,
|
||||
'id': uuidutils.generate_uuid()}
|
||||
l7policy['listener_id'] = listener.get('id')
|
||||
l7policy2['listener_id'] = listener.get('id')
|
||||
vip = {'ip_address': '192.0.2.1', 'port_id': uuidutils.generate_uuid(),
|
||||
'subnet_id': uuidutils.generate_uuid()}
|
||||
lb = {'name': 'lb1', 'description': 'desc1', 'enabled': True,
|
||||
'topology': constants.TOPOLOGY_ACTIVE_STANDBY,
|
||||
'vrrp_group': None, 'server_group_id': uuidutils.generate_uuid(),
|
||||
'project_id': project_id, 'vip': vip,
|
||||
'provisioning_status': constants.PENDING_CREATE,
|
||||
'operating_status': constants.ONLINE,
|
||||
'id': uuidutils.generate_uuid(), 'listeners': [listener,
|
||||
listener2]}
|
||||
listener['load_balancer_id'] = lb.get('id')
|
||||
listener2['load_balancer_id'] = lb.get('id')
|
||||
pool['load_balancer_id'] = lb.get('id')
|
||||
redirect_pool['load_balancer_id'] = lb.get('id')
|
||||
|
||||
lb2_l7rule = {'type': constants.L7RULE_TYPE_HOST_NAME,
|
||||
'compare_type': constants.L7RULE_COMPARE_TYPE_EQUAL_TO,
|
||||
'value': 'localhost'}
|
||||
lb2_l7policy = {'name': 'l7policy1', 'enabled': True,
|
||||
'description': 'l7policy_description', 'position': 1,
|
||||
'action': constants.L7POLICY_ACTION_REDIRECT_TO_URL,
|
||||
'redirect_url': 'www.example.com',
|
||||
'l7rules': [lb2_l7rule],
|
||||
'id': uuidutils.generate_uuid()}
|
||||
lb2_l7rule['l7policy_id'] = lb2_l7policy.get('id')
|
||||
lb2_health_monitor = {'type': constants.HEALTH_MONITOR_HTTP,
|
||||
'delay': 1, 'timeout': 1, 'fall_threshold': 1,
|
||||
'rise_threshold': 1, 'enabled': True}
|
||||
lb2_member = {'project_id': project_id, 'ip_address': '11.0.0.3',
|
||||
'protocol_port': 80, 'enabled': True,
|
||||
'operating_status': constants.ONLINE,
|
||||
'id': uuidutils.generate_uuid()}
|
||||
lb2_pool = {'protocol': constants.PROTOCOL_HTTP, 'name': 'lb2_pool',
|
||||
'description': 'desc1', 'listener_id': None,
|
||||
'lb_algorithm': constants.LB_ALGORITHM_ROUND_ROBIN,
|
||||
'enabled': True, 'operating_status': constants.ONLINE,
|
||||
'project_id': project_id, 'members': [lb2_member],
|
||||
'health_monitor': lb2_health_monitor,
|
||||
'session_persistence': sp,
|
||||
'id': uuidutils.generate_uuid()}
|
||||
lb2_listener = {'project_id': project_id, 'name': 'lb2_listener',
|
||||
'description': 'listener_description',
|
||||
'protocol': constants.PROTOCOL_HTTP,
|
||||
'protocol_port': 83, 'connection_limit': 1,
|
||||
'enabled': True,
|
||||
'default_pool': lb2_pool, 'l7policies': [lb2_l7policy],
|
||||
'provisioning_status': constants.PENDING_CREATE,
|
||||
'operating_status': constants.ONLINE,
|
||||
'id': uuidutils.generate_uuid()}
|
||||
lb2_l7policy['listener_id'] = lb2_listener.get('id')
|
||||
lb2 = {'name': 'lb2', 'description': 'desc2', 'enabled': True,
|
||||
'topology': constants.TOPOLOGY_ACTIVE_STANDBY,
|
||||
'vrrp_group': None,
|
||||
'server_group_id': uuidutils.generate_uuid(),
|
||||
'project_id': project_id, 'vip': vip,
|
||||
'provisioning_status': constants.PENDING_CREATE,
|
||||
'operating_status': constants.ONLINE,
|
||||
'id': uuidutils.generate_uuid(), 'listeners': [lb2_listener]}
|
||||
lb2_listener['load_balancer_id'] = lb2.get('id')
|
||||
lb2_pool['load_balancer_id'] = lb2.get('id')
|
||||
|
||||
# Test zero quota
|
||||
quota = {'load_balancer': 0,
|
||||
'listener': 10,
|
||||
'pool': 10,
|
||||
'health_monitor': 10,
|
||||
'member': 10,
|
||||
'l7policy': 10,
|
||||
'l7rule': 10}
|
||||
self.repos.quotas.update(self.session, project_id, quota=quota)
|
||||
lock_session = db_api.get_session(autocommit=False)
|
||||
self.assertRaises(
|
||||
exceptions.QuotaException,
|
||||
self.repos.create_load_balancer_tree,
|
||||
self.session, lock_session, copy.deepcopy(lb))
|
||||
# Make sure we didn't create the load balancer anyway
|
||||
self.assertIsNone(self.repos.load_balancer.get(self.session,
|
||||
name='lb1'))
|
||||
|
||||
quota = {'load_balancer': 10,
|
||||
'listener': 0,
|
||||
'pool': 10,
|
||||
'health_monitor': 10,
|
||||
'member': 10,
|
||||
'l7policy': 10,
|
||||
'l7rule': 10}
|
||||
self.repos.quotas.update(self.session, project_id, quota=quota)
|
||||
lock_session = db_api.get_session(autocommit=False)
|
||||
self.assertRaises(
|
||||
exceptions.QuotaException,
|
||||
self.repos.create_load_balancer_tree,
|
||||
self.session, lock_session, copy.deepcopy(lb))
|
||||
# Make sure we didn't create the load balancer anyway
|
||||
self.assertIsNone(self.repos.load_balancer.get(self.session,
|
||||
name='lb1'))
|
||||
|
||||
quota = {'load_balancer': 10,
|
||||
'listener': 10,
|
||||
'pool': 0,
|
||||
'health_monitor': 10,
|
||||
'member': 10,
|
||||
'l7policy': 10,
|
||||
'l7rule': 10}
|
||||
self.repos.quotas.update(self.session, project_id, quota=quota)
|
||||
lock_session = db_api.get_session(autocommit=False)
|
||||
self.assertRaises(
|
||||
exceptions.QuotaException,
|
||||
self.repos.create_load_balancer_tree,
|
||||
self.session, lock_session, copy.deepcopy(lb))
|
||||
# Make sure we didn't create the load balancer anyway
|
||||
self.assertIsNone(self.repos.load_balancer.get(self.session,
|
||||
name='lb1'))
|
||||
|
||||
quota = {'load_balancer': 10,
|
||||
'listener': 10,
|
||||
'pool': 10,
|
||||
'health_monitor': 0,
|
||||
'member': 10,
|
||||
'l7policy': 10,
|
||||
'l7rule': 10}
|
||||
self.repos.quotas.update(self.session, project_id, quota=quota)
|
||||
lock_session = db_api.get_session(autocommit=False)
|
||||
self.assertRaises(
|
||||
exceptions.QuotaException,
|
||||
self.repos.create_load_balancer_tree,
|
||||
self.session, lock_session, copy.deepcopy(lb))
|
||||
# Make sure we didn't create the load balancer anyway
|
||||
self.assertIsNone(self.repos.load_balancer.get(self.session,
|
||||
name='lb1'))
|
||||
|
||||
quota = {'load_balancer': 10,
|
||||
'listener': 10,
|
||||
'pool': 10,
|
||||
'health_monitor': 10,
|
||||
'member': 0,
|
||||
'l7policy': 10,
|
||||
'l7rule': 10}
|
||||
self.repos.quotas.update(self.session, project_id, quota=quota)
|
||||
lock_session = db_api.get_session(autocommit=False)
|
||||
self.assertRaises(
|
||||
exceptions.QuotaException,
|
||||
self.repos.create_load_balancer_tree,
|
||||
self.session, lock_session, copy.deepcopy(lb))
|
||||
# Make sure we didn't create the load balancer anyway
|
||||
self.assertIsNone(self.repos.load_balancer.get(self.session,
|
||||
name='lb1'))
|
||||
|
||||
quota = {'load_balancer': 10,
|
||||
'listener': 10,
|
||||
'pool': 10,
|
||||
'health_monitor': 10,
|
||||
'member': 10,
|
||||
'l7policy': 0,
|
||||
'l7rule': 10}
|
||||
self.repos.quotas.update(self.session, project_id, quota=quota)
|
||||
lock_session = db_api.get_session(autocommit=False)
|
||||
self.assertRaises(
|
||||
exceptions.QuotaException,
|
||||
self.repos.create_load_balancer_tree,
|
||||
self.session, lock_session, copy.deepcopy(lb))
|
||||
# Make sure we didn't create the load balancer anyway
|
||||
self.assertIsNone(self.repos.load_balancer.get(self.session,
|
||||
name='lb1'))
|
||||
|
||||
quota = {'load_balancer': 10,
|
||||
'listener': 10,
|
||||
'pool': 10,
|
||||
'health_monitor': 10,
|
||||
'member': 10,
|
||||
'l7policy': 10,
|
||||
'l7rule': 0}
|
||||
self.repos.quotas.update(self.session, project_id, quota=quota)
|
||||
lock_session = db_api.get_session(autocommit=False)
|
||||
self.assertRaises(
|
||||
exceptions.QuotaException,
|
||||
self.repos.create_load_balancer_tree,
|
||||
self.session, lock_session, copy.deepcopy(lb))
|
||||
# Make sure we didn't create the load balancer anyway
|
||||
self.assertIsNone(self.repos.load_balancer.get(self.session,
|
||||
name='lb1'))
|
||||
|
||||
# Test l7policy quota for pools
|
||||
quota = {'load_balancer': 10,
|
||||
'listener': 10,
|
||||
'pool': 1,
|
||||
'health_monitor': 10,
|
||||
'member': 10,
|
||||
'l7policy': 10,
|
||||
'l7rule': 10}
|
||||
self.repos.quotas.update(self.session, project_id, quota=quota)
|
||||
lock_session = db_api.get_session(autocommit=False)
|
||||
self.assertRaises(
|
||||
exceptions.QuotaException,
|
||||
self.repos.create_load_balancer_tree,
|
||||
self.session, lock_session, copy.deepcopy(lb))
|
||||
# Make sure we didn't create the load balancer anyway
|
||||
self.assertIsNone(self.repos.load_balancer.get(self.session,
|
||||
name='lb1'))
|
||||
|
||||
# Test l7policy quota for health monitor
|
||||
quota = {'load_balancer': 10,
|
||||
'listener': 10,
|
||||
'pool': 10,
|
||||
'health_monitor': 1,
|
||||
'member': 10,
|
||||
'l7policy': 10,
|
||||
'l7rule': 10}
|
||||
self.repos.quotas.update(self.session, project_id, quota=quota)
|
||||
lock_session = db_api.get_session(autocommit=False)
|
||||
self.assertRaises(
|
||||
exceptions.QuotaException,
|
||||
self.repos.create_load_balancer_tree,
|
||||
self.session, lock_session, copy.deepcopy(lb))
|
||||
# Make sure we didn't create the load balancer anyway
|
||||
self.assertIsNone(self.repos.load_balancer.get(self.session,
|
||||
name='lb1'))
|
||||
|
||||
# Test l7policy quota for member
|
||||
quota = {'load_balancer': 10,
|
||||
'listener': 10,
|
||||
'pool': 10,
|
||||
'health_monitor': 10,
|
||||
'member': 1,
|
||||
'l7policy': 10,
|
||||
'l7rule': 10}
|
||||
self.repos.quotas.update(self.session, project_id, quota=quota)
|
||||
lock_session = db_api.get_session(autocommit=False)
|
||||
self.assertRaises(
|
||||
exceptions.QuotaException,
|
||||
self.repos.create_load_balancer_tree,
|
||||
self.session, lock_session, copy.deepcopy(lb))
|
||||
# Make sure we didn't create the load balancer anyway
|
||||
self.assertIsNone(self.repos.load_balancer.get(self.session,
|
||||
name='lb1'))
|
||||
|
||||
# Test quota for l7policy
|
||||
quota = {'load_balancer': 10,
|
||||
'listener': 10,
|
||||
'pool': 10,
|
||||
'health_monitor': 10,
|
||||
'member': 10,
|
||||
'l7policy': 1,
|
||||
'l7rule': 10}
|
||||
self.repos.quotas.update(self.session, project_id, quota=quota)
|
||||
lock_session = db_api.get_session(autocommit=False)
|
||||
self.assertRaises(
|
||||
exceptions.QuotaException,
|
||||
self.repos.create_load_balancer_tree,
|
||||
self.session, lock_session, copy.deepcopy(lb))
|
||||
# Make sure we didn't create the load balancer anyway
|
||||
self.assertIsNone(self.repos.load_balancer.get(self.session,
|
||||
name='lb1'))
|
||||
|
||||
# Test quota for l7rule
|
||||
quota = {'load_balancer': 10,
|
||||
'listener': 10,
|
||||
'pool': 10,
|
||||
'health_monitor': 10,
|
||||
'member': 10,
|
||||
'l7policy': 10,
|
||||
'l7rule': 1}
|
||||
self.repos.quotas.update(self.session, project_id, quota=quota)
|
||||
lock_session = db_api.get_session(autocommit=False)
|
||||
self.assertRaises(
|
||||
exceptions.QuotaException,
|
||||
self.repos.create_load_balancer_tree,
|
||||
self.session, lock_session, copy.deepcopy(lb))
|
||||
# Make sure we didn't create the load balancer anyway
|
||||
self.assertIsNone(self.repos.load_balancer.get(self.session,
|
||||
name='lb1'))
|
||||
|
||||
# ### Test load balancer quota
|
||||
# Test one quota, attempt to create another
|
||||
quota = {'load_balancer': 1,
|
||||
'listener': 10,
|
||||
'pool': 10,
|
||||
'health_monitor': 10,
|
||||
'member': 10,
|
||||
'l7policy': 10,
|
||||
'l7rule': 10}
|
||||
self.repos.quotas.update(self.session, project_id, quota=quota)
|
||||
lock_session = db_api.get_session(autocommit=False)
|
||||
self.repos.create_load_balancer_tree(self.session, lock_session,
|
||||
copy.deepcopy(lb))
|
||||
# Check if first LB build passed quota checks
|
||||
self.assertIsNotNone(self.repos.load_balancer.get(self.session,
|
||||
name='lb1'))
|
||||
# Try building another LB, it should fail
|
||||
lock_session = db_api.get_session(autocommit=False)
|
||||
self.assertRaises(
|
||||
exceptions.QuotaException,
|
||||
self.repos.create_load_balancer_tree,
|
||||
self.session, lock_session, copy.deepcopy(lb2))
|
||||
# Make sure we didn't create the load balancer anyway
|
||||
self.assertIsNone(self.repos.load_balancer.get(self.session,
|
||||
name='lb2'))
|
||||
|
||||
# ### Test listener quota
|
||||
# Create with custom quotas and limit to two listener (lb has two),
|
||||
# expect error of too many listeners/over quota
|
||||
quota = {'load_balancer': 10,
|
||||
'listener': 2,
|
||||
'pool': 10,
|
||||
'health_monitor': 10,
|
||||
'member': 10,
|
||||
'l7policy': 10,
|
||||
'l7rule': 10}
|
||||
self.repos.quotas.update(self.session, project_id, quota=quota)
|
||||
lock_session = db_api.get_session(autocommit=False)
|
||||
self.assertRaises(
|
||||
exceptions.QuotaException,
|
||||
self.repos.create_load_balancer_tree,
|
||||
self.session, lock_session, copy.deepcopy(lb2))
|
||||
# Make sure we didn't create the load balancer anyway
|
||||
self.assertIsNone(self.repos.load_balancer.get(self.session,
|
||||
name='lb2'))
|
||||
|
||||
# ### Test pool quota
|
||||
# Create with custom quotas and limit to two pools (lb has two),
|
||||
# expect error of too many pool/over quota
|
||||
quota = {'load_balancer': 10,
|
||||
'listener': 10,
|
||||
'pool': 2,
|
||||
'health_monitor': 10,
|
||||
'member': 10,
|
||||
'l7policy': 10,
|
||||
'l7rule': 10}
|
||||
self.repos.quotas.update(self.session, project_id, quota=quota)
|
||||
lock_session = db_api.get_session(autocommit=False)
|
||||
self.assertRaises(
|
||||
exceptions.QuotaException,
|
||||
self.repos.create_load_balancer_tree,
|
||||
self.session, lock_session, copy.deepcopy(lb2))
|
||||
# Make sure we didn't create the load balancer anyway
|
||||
self.assertIsNone(self.repos.load_balancer.get(self.session,
|
||||
name='lb2'))
|
||||
|
||||
# ### Test health monitor quota
|
||||
# Create with custom quotas and limit to one health monitor,
|
||||
# expect error of too many health monitor/over quota
|
||||
quota = {'load_balancer': 10,
|
||||
'listener': 10,
|
||||
'pool': 10,
|
||||
'health_monitor': 1,
|
||||
'member': 10,
|
||||
'l7policy': 10,
|
||||
'l7rule': 10}
|
||||
self.repos.quotas.update(self.session, project_id, quota=quota)
|
||||
lock_session = db_api.get_session(autocommit=False)
|
||||
self.assertRaises(
|
||||
exceptions.QuotaException,
|
||||
self.repos.create_load_balancer_tree,
|
||||
self.session, lock_session, copy.deepcopy(lb2))
|
||||
# Make sure we didn't create the load balancer anyway
|
||||
self.assertIsNone(self.repos.load_balancer.get(self.session,
|
||||
name='lb2'))
|
||||
|
||||
# ### Test member quota
|
||||
# Create with custom quotas and limit to two member (lb has two),
|
||||
# expect error of too many member/over quota
|
||||
quota = {'load_balancer': 10,
|
||||
'listener': 10,
|
||||
'pool': 10,
|
||||
'health_monitor': 10,
|
||||
'member': 2,
|
||||
'l7policy': 10,
|
||||
'l7rule': 10}
|
||||
self.repos.quotas.update(self.session, project_id, quota=quota)
|
||||
lock_session = db_api.get_session(autocommit=False)
|
||||
self.assertRaises(
|
||||
exceptions.QuotaException,
|
||||
self.repos.create_load_balancer_tree,
|
||||
self.session, lock_session, copy.deepcopy(lb2))
|
||||
# Make sure we didn't create the load balancer anyway
|
||||
self.assertIsNone(self.repos.load_balancer.get(self.session,
|
||||
name='lb2'))
|
||||
|
||||
# ### Test l7policy quota
|
||||
# Create with custom quotas and limit to two l7policy (lb has two),
|
||||
# expect error of too many l7policy/over quota
|
||||
quota = {'load_balancer': 10,
|
||||
'listener': 10,
|
||||
'pool': 10,
|
||||
'health_monitor': 10,
|
||||
'member': 10,
|
||||
'l7policy': 2,
|
||||
'l7rule': 10}
|
||||
self.repos.quotas.update(self.session, project_id, quota=quota)
|
||||
lock_session = db_api.get_session(autocommit=False)
|
||||
self.assertRaises(
|
||||
exceptions.QuotaException,
|
||||
self.repos.create_load_balancer_tree,
|
||||
self.session, lock_session, copy.deepcopy(lb2))
|
||||
# Make sure we didn't create the load balancer anyway
|
||||
self.assertIsNone(self.repos.load_balancer.get(self.session,
|
||||
name='lb2'))
|
||||
|
||||
# ### Test l7rule quota
|
||||
# Create with custom quotas and limit to two l7rule (lb has two),
|
||||
# expect error of too many l7rule/over quota
|
||||
quota = {'load_balancer': 10,
|
||||
'listener': 10,
|
||||
'pool': 10,
|
||||
'health_monitor': 10,
|
||||
'member': 10,
|
||||
'l7policy': 10,
|
||||
'l7rule': 2}
|
||||
self.repos.quotas.update(self.session, project_id, quota=quota)
|
||||
lock_session = db_api.get_session(autocommit=False)
|
||||
self.assertRaises(
|
||||
exceptions.QuotaException,
|
||||
self.repos.create_load_balancer_tree,
|
||||
self.session, lock_session, copy.deepcopy(lb2))
|
||||
# Make sure we didn't create the load balancer anyway
|
||||
self.assertIsNone(self.repos.load_balancer.get(self.session,
|
||||
name='lb2'))
|
||||
|
||||
def test_check_quota_met(self):
|
||||
|
||||
project_id = uuidutils.generate_uuid()
|
||||
|
|
Loading…
Reference in New Issue