Merge pull request #345 from openstack-charmers/octavia-use-common-launch-helper
Use common launch helper with retry handling for Octavia tests
This commit is contained in:
@@ -616,24 +616,6 @@ class NeutronNetworkingBase(test_utils.OpenStackBaseTest):
|
||||
super(NeutronNetworkingBase, cls).setUpClass()
|
||||
cls.neutron_client = (
|
||||
openstack_utils.get_neutron_session_client(cls.keystone_session))
|
||||
# NOTE(fnordahl): in the event of a test failure we do not want to run
|
||||
# tear down code as it will make debugging a problem virtually
|
||||
# impossible. To alleviate each test method will set the
|
||||
# `run_tearDown` instance variable at the end which will let us run
|
||||
# tear down only when there were no failure.
|
||||
cls.run_tearDown = False
|
||||
|
||||
@classmethod
|
||||
def tearDown(cls):
|
||||
"""Remove test resources."""
|
||||
if cls.run_tearDown:
|
||||
logging.info('Running teardown')
|
||||
for server in cls.nova_client.servers.list():
|
||||
if server.name.startswith(cls.RESOURCE_PREFIX):
|
||||
openstack_utils.delete_resource(
|
||||
cls.nova_client.servers,
|
||||
server.id,
|
||||
msg="server")
|
||||
|
||||
@tenacity.retry(wait=tenacity.wait_exponential(multiplier=1, max=60),
|
||||
reraise=True, stop=tenacity.stop_after_attempt(8))
|
||||
@@ -803,7 +785,7 @@ class NeutronNetworkingTest(NeutronNetworkingBase):
|
||||
self.launch_guests()
|
||||
instance_1, instance_2 = self.retrieve_guests()
|
||||
self.check_connectivity(instance_1, instance_2)
|
||||
self.run_tearDown = True
|
||||
self.run_resource_cleanup = True
|
||||
|
||||
|
||||
class NeutronNetworkingVRRPTests(NeutronNetworkingBase):
|
||||
|
||||
@@ -98,25 +98,6 @@ def configure_octavia():
|
||||
pass
|
||||
|
||||
|
||||
def prepare_payload_instance():
|
||||
"""Prepare a instance we can use as payload test."""
|
||||
session = openstack.get_overcloud_keystone_session()
|
||||
keystone = openstack.get_keystone_session_client(session)
|
||||
neutron = openstack.get_neutron_session_client(session)
|
||||
project_id = openstack.get_project_id(
|
||||
keystone, 'admin', domain_name='admin_domain')
|
||||
openstack.add_neutron_secgroup_rules(
|
||||
neutron,
|
||||
project_id,
|
||||
[{'protocol': 'tcp',
|
||||
'port_range_min': '80',
|
||||
'port_range_max': '80',
|
||||
'direction': 'ingress'}])
|
||||
zaza.openstack.configure.guest.launch_instance(
|
||||
glance_setup.LTS_IMAGE_NAME,
|
||||
userdata='#cloud-config\npackages:\n - apache2\n')
|
||||
|
||||
|
||||
def centralized_fip_network():
|
||||
"""Create network with centralized router for connecting lb and fips.
|
||||
|
||||
|
||||
@@ -38,7 +38,20 @@ class CharmOperationTest(test_utils.OpenStackBaseTest):
|
||||
Pause service and check services are stopped, then resume and check
|
||||
they are started.
|
||||
"""
|
||||
self.pause_resume(['apache2'])
|
||||
services = [
|
||||
'apache2',
|
||||
'octavia-health-manager',
|
||||
'octavia-housekeeping',
|
||||
'octavia-worker',
|
||||
]
|
||||
if openstack_utils.ovn_present():
|
||||
services.append('octavia-driver-agent')
|
||||
logging.info('Skipping pause resume test LP: #1886202...')
|
||||
return
|
||||
logging.info('Testing pause resume (services="{}")'
|
||||
.format(services))
|
||||
with self.pause_resume(services, pgrep_full=True):
|
||||
pass
|
||||
|
||||
|
||||
class LBAASv2Test(test_utils.OpenStackBaseTest):
|
||||
@@ -48,12 +61,13 @@ class LBAASv2Test(test_utils.OpenStackBaseTest):
|
||||
def setUpClass(cls):
|
||||
"""Run class setup for running LBaaSv2 service tests."""
|
||||
super(LBAASv2Test, cls).setUpClass()
|
||||
|
||||
cls.keystone_session = openstack_utils.get_overcloud_keystone_session()
|
||||
cls.keystone_client = openstack_utils.get_keystone_session_client(
|
||||
cls.keystone_session)
|
||||
cls.neutron_client = openstack_utils.get_neutron_session_client(
|
||||
cls.keystone_session)
|
||||
cls.octavia_client = openstack_utils.get_octavia_session_client(
|
||||
cls.keystone_session)
|
||||
cls.RESOURCE_PREFIX = 'zaza-octavia'
|
||||
|
||||
# NOTE(fnordahl): in the event of a test failure we do not want to run
|
||||
# tear down code as it will make debugging a problem virtually
|
||||
@@ -63,28 +77,24 @@ class LBAASv2Test(test_utils.OpenStackBaseTest):
|
||||
cls.run_tearDown = False
|
||||
# List of load balancers created by this test
|
||||
cls.loadbalancers = []
|
||||
# LIst of floating IPs created by this test
|
||||
# List of floating IPs created by this test
|
||||
cls.fips = []
|
||||
|
||||
@classmethod
|
||||
def tearDown(cls):
|
||||
"""Remove resources created during test execution.
|
||||
|
||||
Note that resources created in the configure step prior to executing
|
||||
the test should not be touched here.
|
||||
"""
|
||||
if not cls.run_tearDown:
|
||||
return
|
||||
for lb in cls.loadbalancers:
|
||||
cls.octavia_client.load_balancer_delete(lb['id'], cascade=True)
|
||||
def resource_cleanup(self):
|
||||
"""Remove resources created during test execution."""
|
||||
for lb in self.loadbalancers:
|
||||
self.octavia_client.load_balancer_delete(lb['id'], cascade=True)
|
||||
try:
|
||||
cls.wait_for_lb_resource(
|
||||
cls.octavia_client.load_balancer_show, lb['id'],
|
||||
self.wait_for_lb_resource(
|
||||
self.octavia_client.load_balancer_show, lb['id'],
|
||||
provisioning_status='DELETED')
|
||||
except osc_lib.exceptions.NotFound:
|
||||
pass
|
||||
for fip in cls.fips:
|
||||
cls.neutron_client.delete_floatingip(fip)
|
||||
for fip in self.fips:
|
||||
self.neutron_client.delete_floatingip(fip)
|
||||
# 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()
|
||||
|
||||
@staticmethod
|
||||
@tenacity.retry(retry=tenacity.retry_if_exception_type(AssertionError),
|
||||
@@ -238,12 +248,27 @@ class LBAASv2Test(test_utils.OpenStackBaseTest):
|
||||
|
||||
def test_create_loadbalancer(self):
|
||||
"""Create load balancer."""
|
||||
nova_client = openstack_utils.get_nova_session_client(
|
||||
self.keystone_session)
|
||||
# Prepare payload instances
|
||||
# First we allow communication to port 80 by adding a security group
|
||||
# rule
|
||||
project_id = openstack_utils.get_project_id(
|
||||
self.keystone_client, 'admin', domain_name='admin_domain')
|
||||
openstack_utils.add_neutron_secgroup_rules(
|
||||
self.neutron_client,
|
||||
project_id,
|
||||
[{'protocol': 'tcp',
|
||||
'port_range_min': '80',
|
||||
'port_range_max': '80',
|
||||
'direction': 'ingress'}])
|
||||
|
||||
# Then we request two Ubuntu instances with the Apache web server
|
||||
# installed
|
||||
instance_1, instance_2 = self.launch_guests(
|
||||
userdata='#cloud-config\npackages:\n - apache2\n')
|
||||
|
||||
# Get IP of the prepared payload instances
|
||||
payload_ips = []
|
||||
for server in nova_client.servers.list():
|
||||
for server in (instance_1, instance_2):
|
||||
payload_ips.append(server.networks['private'][0])
|
||||
self.assertTrue(len(payload_ips) > 0)
|
||||
|
||||
@@ -274,4 +299,4 @@ class LBAASv2Test(test_utils.OpenStackBaseTest):
|
||||
lb_fp['floating_ip_address']))
|
||||
|
||||
# If we get here, it means the tests passed
|
||||
self.run_tearDown = True
|
||||
self.run_resource_cleanup = True
|
||||
|
||||
@@ -100,8 +100,7 @@ class BaseCharmTest(unittest.TestCase):
|
||||
|
||||
run_resource_cleanup = False
|
||||
|
||||
@classmethod
|
||||
def resource_cleanup(cls):
|
||||
def resource_cleanup(self):
|
||||
"""Cleanup any resources created during the test run.
|
||||
|
||||
Override this method with a method which removes any resources
|
||||
@@ -111,12 +110,13 @@ class BaseCharmTest(unittest.TestCase):
|
||||
"""
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def tearDown(cls):
|
||||
# this must be a class instance method otherwise descentents will not be
|
||||
# able to influence if cleanup should be run.
|
||||
def tearDown(self):
|
||||
"""Run teardown for test class."""
|
||||
if cls.run_resource_cleanup:
|
||||
if self.run_resource_cleanup:
|
||||
logging.info('Running resource cleanup')
|
||||
cls.resource_cleanup()
|
||||
self.resource_cleanup()
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls, application_name=None, model_alias=None):
|
||||
@@ -440,6 +440,21 @@ class OpenStackBaseTest(BaseCharmTest):
|
||||
cls.nova_client = (
|
||||
openstack_utils.get_nova_session_client(cls.keystone_session))
|
||||
|
||||
def resource_cleanup(self):
|
||||
"""Remove test resources."""
|
||||
try:
|
||||
logging.info('Removing instances launched by test ({}*)'
|
||||
.format(self.RESOURCE_PREFIX))
|
||||
for server in self.nova_client.servers.list():
|
||||
if server.name.startswith(self.RESOURCE_PREFIX):
|
||||
openstack_utils.delete_resource(
|
||||
self.nova_client.servers,
|
||||
server.id,
|
||||
msg="server")
|
||||
except AttributeError:
|
||||
# Test did not define self.RESOURCE_PREFIX, ignore.
|
||||
pass
|
||||
|
||||
def launch_guest(self, guest_name, userdata=None):
|
||||
"""Launch two guests to use in tests.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user