Improve exception handling, comments and naming

This commit is contained in:
Luciano Lo Giudice
2024-01-03 16:50:02 -03:00
parent 9a8b7650a0
commit ad246b1a14
@@ -184,14 +184,14 @@ class CephRBDMirrorBase(test_utils.BaseCharmTest):
# get ready for multi-model Zaza
cls.site_a_model = cls.site_b_model = zaza.model.get_juju_model()
cls.site_b_app_suffix = '-b'
# Test if we have the needed Openstack applications.
# Test if we have the cinder-ceph application.
try:
zaza.model.get_application(cls.cinder_ceph_app_name)
cls.with_cinder = True
except Exception:
except KeyError:
cls.with_cinder = False
def check_cinder_present(self, caller):
def skip_test_if_cinder_not_present(self, caller):
"""Skip a test if Cinder isn't present."""
if not self.with_cinder:
raise unittest.SkipTest('Skipping %s due to lack of Cinder'
@@ -425,7 +425,7 @@ class CephRBDMirrorTest(CephRBDMirrorBase):
site B and subsequently comparing the contents we get a full end to end
test.
"""
self.check_cinder_present('test_cinder_volume_mirrored')
self.skip_test_if_cinder_not_present('test_cinder_volume_mirrored')
volume = self.setup_test_cinder_volume()
site_a_hash = zaza.openstack.utilities.ceph.get_rbd_hash(
zaza.model.get_lead_unit_name('ceph-mon',
@@ -567,7 +567,7 @@ class CephRBDMirrorControlledFailoverTest(CephRBDMirrorBase):
This test only makes sense if Cinder RBD mirroring mode is 'image'.
It will return early, if this is not the case.
"""
self.check_cinder_present('test_100_cinder_failover')
self.skip_test_if_cinder_not_present('test_100_cinder_failover')
cinder_rbd_mirroring_mode = get_cinder_rbd_mirroring_mode(
self.cinder_ceph_app_name)
if cinder_rbd_mirroring_mode != 'image':
@@ -617,7 +617,7 @@ class CephRBDMirrorControlledFailoverTest(CephRBDMirrorBase):
The test needs to be executed when the Cinder volume host is already
failed-over with the test volume on it.
"""
self.check_cinder_present('test_101_cinder_failback')
self.skip_test_if_cinder_not_present('test_101_cinder_failback')
cinder_rbd_mirroring_mode = get_cinder_rbd_mirroring_mode(
self.cinder_ceph_app_name)
if cinder_rbd_mirroring_mode != 'image':
@@ -827,7 +827,7 @@ class CephRBDMirrorDisasterFailoverTest(CephRBDMirrorBase):
This assumes that the primary site is already killed.
"""
self.check_cinder_present('test_200_forced_cinder_failover')
self.skip_test_if_cinder_not_present('test_200_forced_cinder_failover')
cinder_rbd_mirroring_mode = get_cinder_rbd_mirroring_mode(
self.cinder_ceph_app_name)
if cinder_rbd_mirroring_mode != 'image':