Run tests with algorithm supported by provider driver

This patch adds map of supported algorithms by
provider drivers. For a first iteration lets select
the first from supported algorithms to be used as
a default and run the tests with it.

In addition this patch splits check_members_balanced()
into subfunctions related to the algorithm
that is validated.

Story: 2006264
Task: 35972

Change-Id: Id055763f35b487da539eddfe802c543a11246503
This commit is contained in:
Maciej Józefczyk 2019-12-10 10:12:30 +00:00
parent 70c90ff66f
commit b6df5f8143
17 changed files with 106 additions and 52 deletions

View File

@ -58,6 +58,17 @@ LB_ALGORITHM = 'lb_algorithm'
LB_ALGORITHM_ROUND_ROBIN = 'ROUND_ROBIN'
LB_ALGORITHM_LEAST_CONNECTIONS = 'LEAST_CONNECTIONS'
LB_ALGORITHM_SOURCE_IP = 'SOURCE_IP'
LB_ALGORITHM_SOURCE_IP_PORT = 'SOURCE_IP_PORT'
SUPPORTED_LB_ALGORITHMS_AMPHORA = [
LB_ALGORITHM_ROUND_ROBIN,
LB_ALGORITHM_LEAST_CONNECTIONS,
LB_ALGORITHM_SOURCE_IP]
SUPPORTED_LB_ALGORITHMS = {
'default': SUPPORTED_LB_ALGORITHMS_AMPHORA,
'octavia': SUPPORTED_LB_ALGORITHMS_AMPHORA,
'amphorav2': SUPPORTED_LB_ALGORITHMS_AMPHORA,
'amphora': SUPPORTED_LB_ALGORITHMS_AMPHORA,
'ovn': [LB_ALGORITHM_SOURCE_IP_PORT]}
SESSION_PERSISTENCE = 'session_persistence'
LISTENER_ID = 'listener_id'
LOADBALANCERS = 'loadbalancers'

View File

@ -116,7 +116,7 @@ class ActiveStandbyIptablesScenarioTest(
pool_kwargs = {
const.NAME: pool_name,
const.PROTOCOL: const.HTTP,
const.LB_ALGORITHM: const.LB_ALGORITHM_ROUND_ROBIN,
const.LB_ALGORITHM: cls.lb_algorithm,
const.LISTENER_ID: cls.listener_id,
}
pool = cls.mem_pool_client.create_pool(**pool_kwargs)

View File

@ -77,7 +77,7 @@ class HealthMonitorAPITest(test_base.LoadBalancerBaseTest):
pool_kwargs = {
const.NAME: pool_name,
const.PROTOCOL: const.HTTP,
const.LB_ALGORITHM: const.LB_ALGORITHM_ROUND_ROBIN,
const.LB_ALGORITHM: self.lb_algorithm,
const.LOADBALANCER_ID: self.lb_id,
}
@ -180,7 +180,7 @@ class HealthMonitorAPITest(test_base.LoadBalancerBaseTest):
pool1_kwargs = {
const.NAME: pool1_name,
const.PROTOCOL: const.HTTP,
const.LB_ALGORITHM: const.LB_ALGORITHM_ROUND_ROBIN,
const.LB_ALGORITHM: self.lb_algorithm,
const.LOADBALANCER_ID: self.lb_id,
}
@ -200,7 +200,7 @@ class HealthMonitorAPITest(test_base.LoadBalancerBaseTest):
pool2_kwargs = {
const.NAME: pool2_name,
const.PROTOCOL: const.HTTP,
const.LB_ALGORITHM: const.LB_ALGORITHM_ROUND_ROBIN,
const.LB_ALGORITHM: self.lb_algorithm,
const.LOADBALANCER_ID: self.lb_id,
}
@ -220,7 +220,7 @@ class HealthMonitorAPITest(test_base.LoadBalancerBaseTest):
pool3_kwargs = {
const.NAME: pool3_name,
const.PROTOCOL: const.HTTP,
const.LB_ALGORITHM: const.LB_ALGORITHM_ROUND_ROBIN,
const.LB_ALGORITHM: self.lb_algorithm,
const.LOADBALANCER_ID: self.lb_id,
}
@ -469,7 +469,7 @@ class HealthMonitorAPITest(test_base.LoadBalancerBaseTest):
pool_kwargs = {
const.NAME: pool_name,
const.PROTOCOL: const.HTTP,
const.LB_ALGORITHM: const.LB_ALGORITHM_ROUND_ROBIN,
const.LB_ALGORITHM: self.lb_algorithm,
const.LOADBALANCER_ID: self.lb_id,
}
@ -577,7 +577,7 @@ class HealthMonitorAPITest(test_base.LoadBalancerBaseTest):
pool_kwargs = {
const.NAME: pool_name,
const.PROTOCOL: const.HTTP,
const.LB_ALGORITHM: const.LB_ALGORITHM_ROUND_ROBIN,
const.LB_ALGORITHM: self.lb_algorithm,
const.LOADBALANCER_ID: self.lb_id,
}
@ -734,7 +734,7 @@ class HealthMonitorAPITest(test_base.LoadBalancerBaseTest):
pool_kwargs = {
const.NAME: pool_name,
const.PROTOCOL: const.HTTP,
const.LB_ALGORITHM: const.LB_ALGORITHM_ROUND_ROBIN,
const.LB_ALGORITHM: self.lb_algorithm,
const.LOADBALANCER_ID: self.lb_id,
}

View File

@ -87,7 +87,7 @@ class L7PolicyAPITest(test_base.LoadBalancerBaseTest):
pool_kwargs = {
const.NAME: pool_name,
const.PROTOCOL: const.HTTP,
const.LB_ALGORITHM: const.LB_ALGORITHM_ROUND_ROBIN,
const.LB_ALGORITHM: cls.lb_algorithm,
const.LOADBALANCER_ID: cls.lb_id,
}

View File

@ -86,7 +86,7 @@ class L7RuleAPITest(test_base.LoadBalancerBaseTest):
pool_kwargs = {
const.NAME: pool_name,
const.PROTOCOL: const.HTTP,
const.LB_ALGORITHM: const.LB_ALGORITHM_ROUND_ROBIN,
const.LB_ALGORITHM: cls.lb_algorithm,
const.LISTENER_ID: cls.listener_id,
}

View File

@ -82,7 +82,7 @@ class MemberAPITest(test_base.LoadBalancerBaseTest):
pool_kwargs = {
const.NAME: pool_name,
const.PROTOCOL: cls.protocol,
const.LB_ALGORITHM: const.LB_ALGORITHM_ROUND_ROBIN,
const.LB_ALGORITHM: cls.lb_algorithm,
const.LISTENER_ID: cls.listener_id,
}
@ -226,7 +226,7 @@ class MemberAPITest(test_base.LoadBalancerBaseTest):
pool = self.mem_pool_client.create_pool(
name=pool_name, loadbalancer_id=self.lb_id,
protocol=self.protocol,
lb_algorithm=const.LB_ALGORITHM_ROUND_ROBIN)
lb_algorithm=self.lb_algorithm)
pool_id = pool[const.ID]
self.addCleanup(
self.mem_pool_client.cleanup_pool, pool_id,
@ -736,7 +736,7 @@ class MemberAPITest(test_base.LoadBalancerBaseTest):
pool = self.mem_pool_client.create_pool(
name=pool_name, loadbalancer_id=self.lb_id,
protocol=self.protocol,
lb_algorithm=const.LB_ALGORITHM_ROUND_ROBIN)
lb_algorithm=self.lb_algorithm)
pool_id = pool[const.ID]
self.addClassResourceCleanup(
self.mem_pool_client.cleanup_pool, pool_id,

View File

@ -102,7 +102,7 @@ class PoolAPITest(test_base.LoadBalancerBaseTest):
const.DESCRIPTION: pool_description,
const.ADMIN_STATE_UP: True,
const.PROTOCOL: self.protocol,
const.LB_ALGORITHM: const.LB_ALGORITHM_ROUND_ROBIN,
const.LB_ALGORITHM: self.lb_algorithm,
}
if self.lb_feature_enabled.session_persistence_enabled:
pool_kwargs[const.SESSION_PERSISTENCE] = {
@ -170,7 +170,7 @@ class PoolAPITest(test_base.LoadBalancerBaseTest):
pool[const.LISTENERS][0][const.ID])
else:
self.assertEmpty(pool[const.LISTENERS])
self.assertEqual(const.LB_ALGORITHM_ROUND_ROBIN,
self.assertEqual(self.lb_algorithm,
pool[const.LB_ALGORITHM])
if self.lb_feature_enabled.session_persistence_enabled:
self.assertIsNotNone(pool.get(const.SESSION_PERSISTENCE))
@ -219,7 +219,7 @@ class PoolAPITest(test_base.LoadBalancerBaseTest):
const.DESCRIPTION: pool1_desc,
const.ADMIN_STATE_UP: True,
const.PROTOCOL: self.protocol,
const.LB_ALGORITHM: const.LB_ALGORITHM_ROUND_ROBIN,
const.LB_ALGORITHM: self.lb_algorithm,
const.LOADBALANCER_ID: lb_id,
}
if self.lb_feature_enabled.session_persistence_enabled:
@ -257,7 +257,7 @@ class PoolAPITest(test_base.LoadBalancerBaseTest):
const.DESCRIPTION: pool2_desc,
const.ADMIN_STATE_UP: True,
const.PROTOCOL: self.protocol,
const.LB_ALGORITHM: const.LB_ALGORITHM_ROUND_ROBIN,
const.LB_ALGORITHM: self.lb_algorithm,
const.LOADBALANCER_ID: lb_id,
}
if self.lb_feature_enabled.session_persistence_enabled:
@ -294,7 +294,7 @@ class PoolAPITest(test_base.LoadBalancerBaseTest):
const.DESCRIPTION: pool3_desc,
const.ADMIN_STATE_UP: False,
const.PROTOCOL: self.protocol,
const.LB_ALGORITHM: const.LB_ALGORITHM_ROUND_ROBIN,
const.LB_ALGORITHM: self.lb_algorithm,
# No session persistence, just so there's one test for that
const.LOADBALANCER_ID: lb_id,
}
@ -435,7 +435,7 @@ class PoolAPITest(test_base.LoadBalancerBaseTest):
const.DESCRIPTION: pool_description,
const.ADMIN_STATE_UP: True,
const.PROTOCOL: self.protocol,
const.LB_ALGORITHM: const.LB_ALGORITHM_ROUND_ROBIN,
const.LB_ALGORITHM: self.lb_algorithm,
const.LOADBALANCER_ID: self.lb_id,
}
if self.lb_feature_enabled.session_persistence_enabled:
@ -474,7 +474,7 @@ class PoolAPITest(test_base.LoadBalancerBaseTest):
self.assertEqual(1, len(pool[const.LOADBALANCERS]))
self.assertEqual(self.lb_id, pool[const.LOADBALANCERS][0][const.ID])
self.assertEmpty(pool[const.LISTENERS])
self.assertEqual(const.LB_ALGORITHM_ROUND_ROBIN,
self.assertEqual(self.lb_algorithm,
pool[const.LB_ALGORITHM])
if self.lb_feature_enabled.session_persistence_enabled:
self.assertIsNotNone(pool.get(const.SESSION_PERSISTENCE))
@ -532,7 +532,7 @@ class PoolAPITest(test_base.LoadBalancerBaseTest):
const.DESCRIPTION: pool_description,
const.ADMIN_STATE_UP: False,
const.PROTOCOL: self.protocol,
const.LB_ALGORITHM: const.LB_ALGORITHM_ROUND_ROBIN,
const.LB_ALGORITHM: self.lb_algorithm,
const.LOADBALANCER_ID: self.lb_id,
}
if self.lb_feature_enabled.session_persistence_enabled:
@ -570,7 +570,7 @@ class PoolAPITest(test_base.LoadBalancerBaseTest):
self.assertEqual(1, len(pool[const.LOADBALANCERS]))
self.assertEqual(self.lb_id, pool[const.LOADBALANCERS][0][const.ID])
self.assertEmpty(pool[const.LISTENERS])
self.assertEqual(const.LB_ALGORITHM_ROUND_ROBIN,
self.assertEqual(self.lb_algorithm,
pool[const.LB_ALGORITHM])
if self.lb_feature_enabled.session_persistence_enabled:
self.assertIsNotNone(pool.get(const.SESSION_PERSISTENCE))
@ -617,7 +617,7 @@ class PoolAPITest(test_base.LoadBalancerBaseTest):
const.NAME: new_name,
const.DESCRIPTION: new_description,
const.ADMIN_STATE_UP: True,
const.LB_ALGORITHM: const.LB_ALGORITHM_ROUND_ROBIN,
const.LB_ALGORITHM: self.lb_algorithm,
}
if self.lb_feature_enabled.session_persistence_enabled:
pool_update_kwargs[const.SESSION_PERSISTENCE] = {
@ -641,7 +641,7 @@ class PoolAPITest(test_base.LoadBalancerBaseTest):
self.assertEqual(new_name, pool[const.NAME])
self.assertEqual(new_description, pool[const.DESCRIPTION])
self.assertTrue(pool[const.ADMIN_STATE_UP])
self.assertEqual(const.LB_ALGORITHM_ROUND_ROBIN,
self.assertEqual(self.lb_algorithm,
pool[const.LB_ALGORITHM])
if self.lb_feature_enabled.session_persistence_enabled:
self.assertIsNotNone(pool.get(const.SESSION_PERSISTENCE))
@ -686,7 +686,7 @@ class PoolAPITest(test_base.LoadBalancerBaseTest):
pool_kwargs = {
const.NAME: pool_name,
const.PROTOCOL: self.protocol,
const.LB_ALGORITHM: const.LB_ALGORITHM_ROUND_ROBIN,
const.LB_ALGORITHM: self.lb_algorithm,
const.LOADBALANCER_ID: self.lb_id,
}
if self.lb_feature_enabled.session_persistence_enabled:

View File

@ -176,7 +176,7 @@ class TLSWithBarbicanTest(test_base.LoadBalancerBaseTestWithCompute):
pool_kwargs = {
const.NAME: pool_name,
const.PROTOCOL: const.HTTP,
const.LB_ALGORITHM: const.LB_ALGORITHM_ROUND_ROBIN,
const.LB_ALGORITHM: cls.lb_algorithm,
const.LOADBALANCER_ID: cls.lb_id,
}
pool = cls.mem_pool_client.create_pool(**pool_kwargs)

View File

@ -61,7 +61,7 @@ class HealthMonitorScenarioTest(test_base.LoadBalancerBaseTest):
pool_kwargs = {
const.NAME: pool_name,
const.PROTOCOL: const.HTTP,
const.LB_ALGORITHM: const.LB_ALGORITHM_ROUND_ROBIN,
const.LB_ALGORITHM: cls.lb_algorithm,
const.LOADBALANCER_ID: cls.lb_id,
}
pool = cls.mem_pool_client.create_pool(**pool_kwargs)

View File

@ -93,7 +93,7 @@ class IPv6TrafficOperationsScenarioTest(
pool_kwargs = {
const.NAME: pool_name,
const.PROTOCOL: const.HTTP,
const.LB_ALGORITHM: const.LB_ALGORITHM_ROUND_ROBIN,
const.LB_ALGORITHM: cls.lb_algorithm,
const.LISTENER_ID: cls.listener_id,
}
pool = cls.mem_pool_client.create_pool(**pool_kwargs)

View File

@ -84,7 +84,7 @@ class L7PolicyScenarioTest(test_base.LoadBalancerBaseTest):
pool_kwargs = {
const.NAME: pool_name,
const.PROTOCOL: const.HTTP,
const.LB_ALGORITHM: const.LB_ALGORITHM_ROUND_ROBIN,
const.LB_ALGORITHM: cls.lb_algorithm,
const.LOADBALANCER_ID: cls.lb_id,
}
pool = cls.mem_pool_client.create_pool(**pool_kwargs)

View File

@ -60,7 +60,7 @@ class ListenerScenarioTest(test_base.LoadBalancerBaseTest):
pool1_kwargs = {
const.NAME: pool1_name,
const.PROTOCOL: cls.protocol,
const.LB_ALGORITHM: const.LB_ALGORITHM_ROUND_ROBIN,
const.LB_ALGORITHM: cls.lb_algorithm,
const.LOADBALANCER_ID: cls.lb_id,
}
pool1 = cls.mem_pool_client.create_pool(**pool1_kwargs)
@ -80,7 +80,7 @@ class ListenerScenarioTest(test_base.LoadBalancerBaseTest):
pool2_kwargs = {
const.NAME: pool2_name,
const.PROTOCOL: cls.protocol,
const.LB_ALGORITHM: const.LB_ALGORITHM_ROUND_ROBIN,
const.LB_ALGORITHM: cls.lb_algorithm,
const.LOADBALANCER_ID: cls.lb_id,
}
pool2 = cls.mem_pool_client.create_pool(**pool2_kwargs)

View File

@ -79,7 +79,7 @@ class MemberScenarioTest(test_base.LoadBalancerBaseTest):
pool_kwargs = {
const.NAME: pool_name,
const.PROTOCOL: protocol,
const.LB_ALGORITHM: const.LB_ALGORITHM_ROUND_ROBIN,
const.LB_ALGORITHM: cls.lb_algorithm,
const.LISTENER_ID: cls.listener_id,
}
pool = cls.mem_pool_client.create_pool(**pool_kwargs)

View File

@ -100,7 +100,7 @@ class PoolScenarioTest(test_base.LoadBalancerBaseTest):
const.DESCRIPTION: pool_description,
const.ADMIN_STATE_UP: False,
const.PROTOCOL: self.protocol,
const.LB_ALGORITHM: const.LB_ALGORITHM_ROUND_ROBIN,
const.LB_ALGORITHM: self.lb_algorithm,
}
if self.lb_feature_enabled.session_persistence_enabled:
pool_kwargs[const.SESSION_PERSISTENCE] = {
@ -146,7 +146,7 @@ class PoolScenarioTest(test_base.LoadBalancerBaseTest):
pool[const.LISTENERS][0][const.ID])
else:
self.assertEmpty(pool[const.LISTENERS])
self.assertEqual(const.LB_ALGORITHM_ROUND_ROBIN,
self.assertEqual(self.lb_algorithm,
pool[const.LB_ALGORITHM])
if self.lb_feature_enabled.session_persistence_enabled:
self.assertIsNotNone(pool.get(const.SESSION_PERSISTENCE))

View File

@ -102,7 +102,7 @@ class TrafficOperationsScenarioTest(test_base.LoadBalancerBaseTestWithCompute):
pool_kwargs = {
const.NAME: pool_name,
const.PROTOCOL: protocol,
const.LB_ALGORITHM: const.LB_ALGORITHM_ROUND_ROBIN,
const.LB_ALGORITHM: cls.lb_algorithm,
const.LISTENER_ID: cls.listener_id,
}
pool = cls.mem_pool_client.create_pool(**pool_kwargs)
@ -413,7 +413,7 @@ class TrafficOperationsScenarioTest(test_base.LoadBalancerBaseTestWithCompute):
pool_kwargs = {
const.NAME: pool_name,
const.PROTOCOL: const.HTTP,
const.LB_ALGORITHM: const.LB_ALGORITHM_ROUND_ROBIN,
const.LB_ALGORITHM: self.lb_algorithm,
const.LOADBALANCER_ID: self.lb_id,
}
pool = self.mem_pool_client.create_pool(**pool_kwargs)

View File

@ -129,7 +129,7 @@ class SparePoolTest(test_base.LoadBalancerBaseTestWithCompute):
pool_kwargs = {
const.NAME: pool_name,
const.PROTOCOL: const.HTTP,
const.LB_ALGORITHM: const.LB_ALGORITHM_ROUND_ROBIN,
const.LB_ALGORITHM: self.lb_algorithm,
const.LISTENER_ID: self.listener_id,
}
pool = self.mem_pool_client.create_pool(**pool_kwargs)

View File

@ -145,6 +145,15 @@ class LoadBalancerBaseTest(test.BaseTestCase):
"Configuration value test_network_override must be "
"specified if test_subnet_override is used.")
# Get loadbalancing algorithms supported by provider driver.
try:
algorithms = const.SUPPORTED_LB_ALGORITHMS[
CONF.load_balancer.provider]
except KeyError:
algorithms = const.SUPPORTED_LB_ALGORITHMS['default']
# Set default algorithm as first from the list.
cls.lb_algorithm = algorithms[0]
show_subnet = cls.lb_mem_subnet_client.show_subnet
if CONF.load_balancer.test_with_noop:
cls.lb_member_vip_net = {'id': uuidutils.generate_uuid()}
@ -860,41 +869,75 @@ class LoadBalancerBaseTestWithCompute(LoadBalancerBaseTest):
'period. Failing test.')
raise Exception()
def check_members_balanced(self, vip_address, traffic_member_count=2,
protocol='http', verify=True, protocol_port=80):
handler = requests
if CONF.load_balancer.test_reuse_connection:
handler = requests.Session()
def _send_lb_request(self, handler, protocol, vip_address,
verify, protocol_port, num=20):
response_counts = {}
if ipaddress.ip_address(vip_address).version == 6:
vip_address = '[{}]'.format(vip_address)
self._wait_for_lb_functional(vip_address, protocol, verify)
# Send a number requests to lb vip
for i in range(20):
for i in range(num):
try:
r = handler.get('{0}://{1}:{2}'.format(protocol, vip_address,
protocol_port),
timeout=2, verify=verify)
if r.content in response_counts:
response_counts[r.content] += 1
else:
response_counts[r.content] = 1
except Exception:
LOG.exception('Failed to send request to loadbalancer vip')
raise Exception('Failed to connect to lb')
LOG.debug('Loadbalancer response totals: %s', response_counts)
return response_counts
def _check_members_balanced_round_robin(
self, vip_address, traffic_member_count=2, protocol='http',
verify=True, protocol_port=80):
handler = requests.Session()
response_counts = self._send_lb_request(
handler, protocol, vip_address,
verify, protocol_port)
# Ensure the correct number of members
self.assertEqual(traffic_member_count, len(response_counts))
# Ensure both members got the same number of responses
self.assertEqual(1, len(set(response_counts.values())))
def _check_members_balanced_source_ip_port(
self, vip_address, traffic_member_count=2, protocol='http',
verify=True, protocol_port=80):
handler = requests
response_counts = self._send_lb_request(
handler, protocol, vip_address,
verify, protocol_port)
# Ensure the correct number of members
self.assertEqual(traffic_member_count, len(response_counts))
if CONF.load_balancer.test_reuse_connection:
handler = requests.Session()
response_counts = self._send_lb_request(
handler, protocol, vip_address,
verify, protocol_port)
# Ensure only one member answered
self.assertEqual(1, len(response_counts))
def check_members_balanced(self, vip_address, traffic_member_count=2,
protocol='http', verify=True, protocol_port=80):
if ipaddress.ip_address(vip_address).version == 6:
vip_address = '[{}]'.format(vip_address)
self._wait_for_lb_functional(vip_address, protocol, verify)
validate_func = '_check_members_balanced_%s' % self.lb_algorithm
validate_func = getattr(self, validate_func.lower())
validate_func(
vip_address=vip_address,
traffic_member_count=traffic_member_count,
protocol=protocol,
verify=verify,
protocol_port=protocol_port)
def assertConsistentResponse(self, response, url, method='GET', repeat=10,
redirect=False, timeout=2, **kwargs):
"""Assert that a request to URL gets the expected response.