From 825813ed317bf979213a6fdfeaa751e289dcc9d8 Mon Sep 17 00:00:00 2001 From: Nicholas Njihia Date: Wed, 22 Sep 2021 17:15:48 +0300 Subject: [PATCH] Add Octavia volume-based Amphora test Enable Amphora to run instances booted from volume by flipping the config option `enable-volume-based-amphora` to True and checking volumes attached to the amphora instances. Depends-On: https://review.opendev.org/c/openstack/charm-octavia/+/810567 Related-Bug: https://launchpad.net/bugs/1901732 --- zaza/openstack/charm_tests/octavia/setup.py | 1 + zaza/openstack/charm_tests/octavia/tests.py | 52 ++++++++++++++++++--- 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/zaza/openstack/charm_tests/octavia/setup.py b/zaza/openstack/charm_tests/octavia/setup.py index 49c60d51a..c284d2878 100644 --- a/zaza/openstack/charm_tests/octavia/setup.py +++ b/zaza/openstack/charm_tests/octavia/setup.py @@ -35,6 +35,7 @@ def ensure_lts_images(): glance_setup.add_lts_image(image_name='bionic', release='bionic') glance_setup.add_lts_image(image_name='focal', release='focal') glance_setup.add_lts_image(image_name='jammy', release='jammy') + glance_setup.add_lts_image(image_name='noble', release='noble') def add_amphora_image(image_url=None): diff --git a/zaza/openstack/charm_tests/octavia/tests.py b/zaza/openstack/charm_tests/octavia/tests.py index 3899d75c6..06e530309 100644 --- a/zaza/openstack/charm_tests/octavia/tests.py +++ b/zaza/openstack/charm_tests/octavia/tests.py @@ -14,6 +14,7 @@ """Encapsulate octavia testing.""" +import json import logging import subprocess import tenacity @@ -34,6 +35,7 @@ LoadBalancerUnexpectedState, LoadBalancerUnrecoverableError, ) +from zaza.openstack.utilities.os_versions import CompareOpenStack LBAAS_ADMIN_ROLE = 'load-balancer_admin' @@ -182,13 +184,13 @@ def test_pause_resume(self): pass -class LBAASv2Test(test_utils.OpenStackBaseTest): - """LBaaSv2 service tests.""" +class OctaviaTest(test_utils.OpenStackBaseTest): + """Octavia service tests.""" @classmethod def setUpClass(cls): - """Run class setup for running LBaaSv2 service tests.""" - super(LBAASv2Test, cls).setUpClass() + """Run class setup for running Octavia service tests.""" + super(OctaviaTest, cls).setUpClass() cls.keystone_client = ObjectRetrierWraps( openstack_utils.get_keystone_session_client(cls.keystone_session)) @@ -281,7 +283,7 @@ def resource_cleanup(self, only_local=False): # we run the parent resource_cleanup last as it will remove instances # referenced as members in the above cleaned up load balancers - super(LBAASv2Test, self).resource_cleanup() + super(OctaviaTest, self).resource_cleanup() @staticmethod @tenacity.retry( @@ -456,7 +458,7 @@ def _get_payload(ip): 'http://{}/'.format(ip)], universal_newlines=True) - def test_create_loadbalancer(self): + def create_loadbalancer(self, ensure_volume_backed=False): """Create load balancer.""" # Prepare payload instances # First we allow communication to port 80 by adding a security group @@ -526,9 +528,47 @@ def test_create_loadbalancer(self): .format(snippet, provider, lb_fp['floating_ip_address'])) + if ensure_volume_backed: + amphora_list = self.octavia_client.amphora_list() + self.assertTrue(len(amphora_list) > 0) + attached_volumes = [] + for amphora in amphora_list.get('amphorae', []): + server_id = amphora['compute_id'] + logging.info("Checking amphora {} server {} for attached " + "volumes".format(amphora['id'], server_id)) + volumes = self.nova_client.volumes.get_server_volumes( + server_id) + logging.info('amphora {} server {} has volumes={}'. + format(amphora['id'], + server_id, volumes)) + attached_volumes.append(json.dumps(vars(volumes))) + + self.assertTrue(len(attached_volumes) > 0) + logging.info("Amphora volumes creation successful: {}".format( + attached_volumes)) + # If we get here, it means the tests passed self.run_resource_cleanup = True + def test_create_loadbalancer(self): + """Test creating a load balancer.""" + self.create_loadbalancer() + + def test_volume_backed_amphora(self): + """Test volume-backed amphora load balancer.""" + os_versions = openstack_utils.get_current_os_versions(['octavia']) + if CompareOpenStack(os_versions['octavia']) < 'ussuri': + self.skipTest('Run only for Openstack Ussuri and newer releases.') + return + + """Test creating a load balancer that uses volume-based amphora.""" + default_charm_config = {'enable-volume-based-amphora': False} + alternate_charm_config = {'enable-volume-based-amphora': True} + with self.config_change(default_charm_config, + alternate_charm_config, reset_to_charm_default=True): + logging.info("Testing create volume-backed amphora loadbalancer") + self.create_loadbalancer(ensure_volume_backed=True) + class OctaviaTempestTestK8S(tempest_tests.TempestTestScaleK8SBase): """Test octavia k8s scale out and scale back."""