Skip to content

Commit fccf457

Browse files
Nicholas Njihiadosaboy
authored andcommitted
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/+/931587 Related-Bug: https://launchpad.net/bugs/1901732 (cherry picked from commit d096096) (cherry picked from commit f0f60a5) (cherry picked from commit 3968c10)
1 parent 448e722 commit fccf457

File tree

3 files changed

+70
-16
lines changed

3 files changed

+70
-16
lines changed

unit_tests/utilities/test_zaza_utilities_os_versions.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@
2020
class TestOpenStackUtils(ut_utils.BaseTestCase):
2121

2222
def test_compare_openstack(self):
23-
yoga = os_versions.CompareOpenStack('yoga')
24-
xena = os_versions.CompareOpenStack('xena')
2523
wallaby = os_versions.CompareOpenStack('wallaby')
26-
self.assertGreater(yoga, xena)
27-
self.assertLess(xena, yoga)
28-
self.assertGreaterEqual(xena, xena)
29-
self.assertGreaterEqual(yoga, yoga)
30-
self.assertGreaterEqual(yoga, wallaby)
24+
victoria = os_versions.CompareOpenStack('victoria')
25+
self.assertGreater(wallaby, victoria)
26+
self.assertLess(victoria, wallaby)
27+
self.assertGreaterEqual(wallaby, wallaby)
28+
self.assertGreaterEqual(victoria, victoria)
29+
self.assertGreaterEqual(wallaby, victoria)
3130

32-
self.assertEqual("CompareOpenStack<xena>", repr(xena))
31+
self.assertEqual("CompareOpenStack<wallaby>", repr(wallaby))

zaza/openstack/charm_tests/octavia/tests.py

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
"""Encapsulate octavia testing."""
1616

17+
import json
1718
import logging
1819
import subprocess
1920
import tenacity
@@ -26,6 +27,7 @@
2627
import zaza.openstack.utilities.openstack as openstack_utils
2728

2829
from zaza.openstack.utilities import ObjectRetrierWraps
30+
from zaza.openstack.utilities.os_versions import CompareOpenStack
2931

3032
LBAAS_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)

zaza/openstack/utilities/os_versions.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161
('2019.2', 'train'),
6262
('2020.1', 'ussuri'),
6363
('2020.2', 'victoria'),
64+
('2021.1', 'wallaby'),
65+
('2021.2', 'xena'),
6466
])
6567

6668
OPENSTACK_RELEASES_PAIRS = [
@@ -274,6 +276,11 @@
274276
('3', 'ussuri'),
275277
('4', 'victoria'),
276278
]),
279+
'octavia-common': OrderedDict([
280+
('5', 'train'),
281+
('6', 'ussuri'),
282+
('7', 'victoria'),
283+
]),
277284
}
278285

279286

@@ -394,4 +401,3 @@ class CompareOpenStack(BasicStringComparator):
394401
"""
395402

396403
_list = list(OPENSTACK_CODENAMES.values())
397-

0 commit comments

Comments
 (0)