From 998a61a6a510ca26eb2d2e892b19657843253ea6 Mon Sep 17 00:00:00 2001 From: Frode Nordahl Date: Mon, 3 Feb 2020 10:03:49 +0100 Subject: [PATCH] octavia: Support testing multiple providers --- zaza/openstack/charm_tests/octavia/tests.py | 113 +++++++++++++------- 1 file changed, 75 insertions(+), 38 deletions(-) diff --git a/zaza/openstack/charm_tests/octavia/tests.py b/zaza/openstack/charm_tests/octavia/tests.py index c3786f4..bd23cc9 100644 --- a/zaza/openstack/charm_tests/octavia/tests.py +++ b/zaza/openstack/charm_tests/octavia/tests.py @@ -67,15 +67,43 @@ class LBAASv2Test(test_utils.OpenStackBaseTest): return resp + @staticmethod + def get_lb_providers(octavia_client): + """Retrieve loadbalancer providers. + + :param octavia_client: Octavia client object + :type octavia_client: OctaviaAPI + :returns: Dictionary with provider information, name as keys + :rtype: Dict[str,Dict[str,str]] + """ + providers = { + provider['name']: provider + for provider in octavia_client.provider_list().get('providers', []) + if provider['name'] != 'octavia' # alias for `amphora`, skip + } + return providers + def _create_lb_resources(self, octavia_client, provider, vip_subnet_id, member_subnet_id, payload_ips): + # The `amphora` provider is required for load balancing based on + # higher layer protocols + if provider == 'amphora': + protocol = 'HTTP' + algorithm = 'ROUND_ROBIN' + monitor = True + else: + protocol = 'TCP' + algorithm = 'SOURCE_IP_PORT' + monitor = False + result = octavia_client.load_balancer_create( json={ 'loadbalancer': { 'description': 'Created by Zaza', 'admin_state_up': True, 'vip_subnet_id': vip_subnet_id, - 'name': 'zaza-lb-0', + 'name': 'zaza-{}-0'.format(provider), + 'provider': provider, }}) lb = result['loadbalancer'] lb_id = lb['id'] @@ -91,7 +119,7 @@ class LBAASv2Test(test_utils.OpenStackBaseTest): 'listener': { 'loadbalancer_id': lb_id, 'name': 'listener1', - 'protocol': 'HTTP', + 'protocol': protocol, 'protocol_port': 80 }, }) @@ -107,8 +135,8 @@ class LBAASv2Test(test_utils.OpenStackBaseTest): 'pool': { 'listener_id': listener_id, 'name': 'pool1', - 'lb_algorithm': 'ROUND_ROBIN', - 'protocol': 'HTTP', + 'lb_algorithm': algorithm, + 'protocol': protocol, }, }) pool_id = result['pool']['id'] @@ -117,23 +145,25 @@ class LBAASv2Test(test_utils.OpenStackBaseTest): resp = self.wait_for_lb_resource(octavia_client.pool_show, pool_id) logging.info(resp) - result = octavia_client.health_monitor_create( - json={ - 'healthmonitor': { - 'pool_id': pool_id, - 'delay': 5, - 'max_retries': 4, - 'timeout': 10, - 'type': 'HTTP', - 'url_path': '/', - }, - }) - healthmonitor_id = result['healthmonitor']['id'] - logging.info('Awaiting healthmonitor to reach provisioning_status ' - '"ACTIVE"') - resp = self.wait_for_lb_resource(octavia_client.health_monitor_show, - healthmonitor_id) - logging.info(resp) + if monitor: + result = octavia_client.health_monitor_create( + json={ + 'healthmonitor': { + 'pool_id': pool_id, + 'delay': 5, + 'max_retries': 4, + 'timeout': 10, + 'type': 'HTTP', + 'url_path': '/', + }, + }) + healthmonitor_id = result['healthmonitor']['id'] + logging.info('Awaiting healthmonitor to reach provisioning_status ' + '"ACTIVE"') + resp = self.wait_for_lb_resource( + octavia_client.health_monitor_show, + healthmonitor_id) + logging.info(resp) for ip in payload_ips: result = octavia_client.member_create( @@ -152,10 +182,19 @@ class LBAASv2Test(test_utils.OpenStackBaseTest): lambda x: octavia_client.member_show( pool_id=pool_id, member_id=x), member_id, - operating_status='ONLINE') + operating_status='ONLINE' if monitor else '') logging.info(resp) return lb + @staticmethod + @tenacity.retry(wait=tenacity.wait_fixed(1), + reraise=True, stop=tenacity.stop_after_delay(900)) + def _get_payload(ip): + return subprocess.check_output( + ['wget', '-O', '-', + 'http://{}/'.format(ip)], + universal_newlines=True) + def test_create_loadbalancer(self): """Create load balancer.""" keystone_session = openstack_utils.get_overcloud_keystone_session() @@ -179,21 +218,19 @@ class LBAASv2Test(test_utils.OpenStackBaseTest): vip_subnet_id = subnet_id octavia_client = openstack_utils.get_octavia_session_client( keystone_session) - lb = self._create_lb_resources(octavia_client, 'amphora', - vip_subnet_id, subnet_id, payload_ips) + for provider in self.get_lb_providers(octavia_client).keys(): + logging.info('Creating loadbalancer with provider {}' + .format(provider)) + lb = self._create_lb_resources(octavia_client, provider, + vip_subnet_id, subnet_id, + payload_ips) - lb_fp = openstack_utils.create_floating_ip( - neutron_client, 'ext_net', port={'id': lb['vip_port_id']}) + lb_fp = openstack_utils.create_floating_ip( + neutron_client, 'ext_net', port={'id': lb['vip_port_id']}) - @tenacity.retry(wait=tenacity.wait_fixed(1), - reraise=True, stop=tenacity.stop_after_delay(900)) - def get_payload(): - return subprocess.check_output( - ['wget', '-O', '-', - 'http://{}/'.format(lb_fp['floating_ip_address'])], - universal_newlines=True) - snippet = 'This is the default welcome page' - assert snippet in get_payload() - logging.info('Found "{}" in page retrieved through load balancer at ' - '"http://{}/"' - .format(snippet, lb_fp['floating_ip_address'])) + snippet = 'This is the default welcome page' + assert snippet in self._get_payload(lb_fp['floating_ip_address']) + logging.info('Found "{}" in page retrieved through load balancer ' + ' (provider="{}") at "http://{}/"' + .format(snippet, provider, + lb_fp['floating_ip_address']))