1414
1515"""Encapsulate octavia testing."""
1616
17+ import json
1718import logging
1819import subprocess
1920import tenacity
2627import zaza .openstack .utilities .openstack as openstack_utils
2728
2829from zaza .openstack .utilities import ObjectRetrierWraps
30+ from zaza .openstack .utilities .os_versions import CompareOpenStack
2931
3032LBAAS_ADMIN_ROLE = 'load-balancer_admin'
3133
@@ -136,12 +138,6 @@ def setUpClass(cls):
136138 cls .keystone_client = ObjectRetrierWraps (
137139 openstack_utils .get_keystone_session_client (cls .keystone_session ))
138140
139- if (openstack_utils .get_os_release () >=
140- openstack_utils .get_os_release ('focal_wallaby' )):
141- # add role to admin user for the duration of the test
142- grant_role_current_user (cls .keystone_client , cls .keystone_session ,
143- LBAAS_ADMIN_ROLE )
144-
145141 cls .neutron_client = ObjectRetrierWraps (
146142 openstack_utils .get_neutron_session_client (cls .keystone_session ))
147143 cls .octavia_client = ObjectRetrierWraps (
@@ -159,6 +155,16 @@ def setUpClass(cls):
159155 # List of floating IPs created by this test
160156 cls .fips = []
161157
158+ def setUp (self ):
159+ """Configure the octavia test environment."""
160+ super (LBAASv2Test , self ).setUp ()
161+ if (openstack_utils .get_os_release () >=
162+ openstack_utils .get_os_release ('focal_wallaby' )):
163+ # add role to admin user for the duration of the test
164+ grant_role_current_user (self .keystone_client ,
165+ self .keystone_session ,
166+ LBAAS_ADMIN_ROLE )
167+
162168 def _remove_amphorae_instances (self ):
163169 """Remove amphorae instances forcefully.
164170
@@ -189,6 +195,7 @@ def resource_cleanup(self, only_local=False):
189195 :param only_local: When set to true do not call parent method
190196 :type only_local: bool
191197 """
198+ logging .info ("deleting loadbalancer(s): {}" .format (self .loadbalancers ))
192199 for lb in self .loadbalancers :
193200 try :
194201 self .octavia_client .load_balancer_delete (
@@ -384,7 +391,7 @@ def _get_payload(ip):
384391 'http://{}/' .format (ip )],
385392 universal_newlines = True )
386393
387- def test_create_loadbalancer (self ):
394+ def create_loadbalancer (self , ensure_volume_backed = False ):
388395 """Create load balancer."""
389396 # Prepare payload instances
390397 # First we allow communication to port 80 by adding a security group
@@ -451,5 +458,47 @@ def test_create_loadbalancer(self):
451458 .format (snippet , provider ,
452459 lb_fp ['floating_ip_address' ]))
453460
461+ if ensure_volume_backed :
462+ amphora_list = self .octavia_client .amphora_list ()
463+ self .assertTrue (len (amphora_list ) > 0 )
464+ attached_volumes = []
465+ for amphora in amphora_list .get ('amphorae' , []):
466+ server_id = amphora ['compute_id' ]
467+ logging .info ("Checking amphora {} server {} for attached "
468+ "volumes" .format (amphora ['id' ], server_id ))
469+ volumes = self .nova_client .volumes .get_server_volumes (
470+ server_id )
471+ logging .info ('amphora {} server {} has volumes={}' .
472+ format (amphora ['id' ],
473+ server_id , volumes ))
474+ attached_volumes .append (json .dumps (vars (volumes )))
475+
476+ self .assertTrue (len (attached_volumes ) > 0 )
477+ logging .info ("Amphora volumes creation successful: {}" .format (
478+ attached_volumes ))
479+
454480 # If we get here, it means the tests passed
455481 self .run_resource_cleanup = True
482+
483+ def test_create_loadbalancer (self ):
484+ """Test creating a load balancer."""
485+ self .create_loadbalancer ()
486+
487+
488+ class OctaviaVolumeBackedAmphoraTest (LBAASv2Test ):
489+ """Octavia service tests."""
490+
491+ def test_volume_backed_amphora (self ):
492+ """Test volume-backed amphora load balancer."""
493+ os_versions = openstack_utils .get_current_os_versions (['octavia' ])
494+ if CompareOpenStack (os_versions ['octavia' ]) < 'ussuri' :
495+ self .skipTest ('Run only for Openstack Ussuri and newer releases.' )
496+ return
497+
498+ """Test creating a load balancer that uses volume-based amphora."""
499+ default_charm_config = {'enable-volume-based-amphora' : False }
500+ alternate_charm_config = {'enable-volume-based-amphora' : True }
501+ with self .config_change (default_charm_config ,
502+ alternate_charm_config , reset_to_charm_default = True ):
503+ logging .info ("Testing create volume-backed amphora loadbalancer" )
504+ self .create_loadbalancer (ensure_volume_backed = True )
0 commit comments