From 3bf0ec72b99053277e5fe4e86877f5fc84c8d6a9 Mon Sep 17 00:00:00 2001 From: Luciano Lo Giudice Date: Wed, 24 Apr 2024 11:29:33 -0300 Subject: [PATCH 1/7] Implement ceph-fs key rotation tests This PR implements tests for key rotation in ceph-fs units. It works similarly to how RGW tests do. --- zaza/openstack/charm_tests/ceph/tests.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/zaza/openstack/charm_tests/ceph/tests.py b/zaza/openstack/charm_tests/ceph/tests.py index 85de53dcf..9e18ca872 100644 --- a/zaza/openstack/charm_tests/ceph/tests.py +++ b/zaza/openstack/charm_tests/ceph/tests.py @@ -1812,3 +1812,13 @@ def test_key_rotate(self): logging.info('ceph-radosgw units present, but no RGW service') except KeyError: pass + + try: + zaza_model.get_application('ceph-fs') + fs_entity = self._get_all_keys(unit, lambda x: x.startswith('mds.')) + if fs_entity is not None: + self._check_key_rotation(next(iter(fs_entity))[0], unit) + else: + logging.info('ceph-fs units present, but no MDS service') + except KeyError: + pass From 42966304799465bf13e8cfe5c80dfe2647862a54 Mon Sep 17 00:00:00 2001 From: Luciano Lo Giudice Date: Wed, 24 Apr 2024 11:38:12 -0300 Subject: [PATCH 2/7] PEP8 change --- zaza/openstack/charm_tests/ceph/tests.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/zaza/openstack/charm_tests/ceph/tests.py b/zaza/openstack/charm_tests/ceph/tests.py index 9e18ca872..86fcf33c9 100644 --- a/zaza/openstack/charm_tests/ceph/tests.py +++ b/zaza/openstack/charm_tests/ceph/tests.py @@ -1815,9 +1815,9 @@ def test_key_rotate(self): try: zaza_model.get_application('ceph-fs') - fs_entity = self._get_all_keys(unit, lambda x: x.startswith('mds.')) - if fs_entity is not None: - self._check_key_rotation(next(iter(fs_entity))[0], unit) + fs_svc = self._get_all_keys(unit, lambda x: x.startswith('mds.')) + if fs_svc is not None: + self._check_key_rotation(next(iter(fs_svc))[0], unit) else: logging.info('ceph-fs units present, but no MDS service') except KeyError: From 1ecd7cc9c6ebcf8f425de767c33c145efd23046c Mon Sep 17 00:00:00 2001 From: Luciano Lo Giudice Date: Wed, 24 Apr 2024 14:04:29 -0300 Subject: [PATCH 3/7] Use specific workload messages for the Ubuntu units --- zaza/openstack/charm_tests/ceph/tests.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/zaza/openstack/charm_tests/ceph/tests.py b/zaza/openstack/charm_tests/ceph/tests.py index 86fcf33c9..1bca97355 100644 --- a/zaza/openstack/charm_tests/ceph/tests.py +++ b/zaza/openstack/charm_tests/ceph/tests.py @@ -1770,7 +1770,7 @@ def _get_all_keys(self, unit, entity_filter): ret.add((data[ix - 1], data[ix + 1])) return ret - def _check_key_rotation(self, entity, unit): + def _check_key_rotation(self, entity, unit, states=None): def entity_filter(name): return name.startswith(entity) @@ -1781,7 +1781,7 @@ def entity_filter(name): action_params={'entity': entity} ) zaza_utils.assertActionRanOK(action_obj) - zaza_model.wait_for_application_states() + zaza_model.wait_for_application_states(states=states) new_keys = self._get_all_keys(unit, entity_filter) self.assertNotEqual(old_keys, new_keys) diff = new_keys - old_keys @@ -1817,7 +1817,14 @@ def test_key_rotate(self): zaza_model.get_application('ceph-fs') fs_svc = self._get_all_keys(unit, lambda x: x.startswith('mds.')) if fs_svc is not None: - self._check_key_rotation(next(iter(fs_svc))[0], unit) + ubuntu_states = { + 'ubuntu': { + 'workload-status': 'active', + 'workload-status-message': '' + } + } + self._check_key_rotation(next(iter(fs_svc))[0], unit, + ubuntu_states) else: logging.info('ceph-fs units present, but no MDS service') except KeyError: From f8136a6c1579c5ef27b9fa4af10cc2716796dcec Mon Sep 17 00:00:00 2001 From: Luciano Lo Giudice Date: Thu, 25 Apr 2024 11:30:08 -0300 Subject: [PATCH 4/7] Use a different waiting strategy for ceph-fs tests --- zaza/openstack/charm_tests/ceph/tests.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/zaza/openstack/charm_tests/ceph/tests.py b/zaza/openstack/charm_tests/ceph/tests.py index 1bca97355..638a31fe8 100644 --- a/zaza/openstack/charm_tests/ceph/tests.py +++ b/zaza/openstack/charm_tests/ceph/tests.py @@ -1770,7 +1770,7 @@ def _get_all_keys(self, unit, entity_filter): ret.add((data[ix - 1], data[ix + 1])) return ret - def _check_key_rotation(self, entity, unit, states=None): + def _check_key_rotation(self, entity, unit, wait_for_unit=None): def entity_filter(name): return name.startswith(entity) @@ -1781,7 +1781,11 @@ def entity_filter(name): action_params={'entity': entity} ) zaza_utils.assertActionRanOK(action_obj) - zaza_model.wait_for_application_states(states=states) + if wait_for_unit is None: + # Wait for all applications + zaza_model.wait_for_application_states() + else: + zaza_model.wait_for_unit_idle(wait_for_unit) new_keys = self._get_all_keys(unit, entity_filter) self.assertNotEqual(old_keys, new_keys) diff = new_keys - old_keys @@ -1817,14 +1821,11 @@ def test_key_rotate(self): zaza_model.get_application('ceph-fs') fs_svc = self._get_all_keys(unit, lambda x: x.startswith('mds.')) if fs_svc is not None: - ubuntu_states = { - 'ubuntu': { - 'workload-status': 'active', - 'workload-status-message': '' - } - } + # Only wait for ceph-fs, as this model includes 'ubuntu' + # units, and those don't play nice with zaza (they don't + # set the workload-status-message correctly). self._check_key_rotation(next(iter(fs_svc))[0], unit, - ubuntu_states) + 'ceph-fs/0') else: logging.info('ceph-fs units present, but no MDS service') except KeyError: From 08b1e4902fb133cf5b132d572986a7d309bef744 Mon Sep 17 00:00:00 2001 From: Luciano Lo Giudice Date: Thu, 25 Apr 2024 16:13:03 -0300 Subject: [PATCH 5/7] Use a more thorough stategy --- zaza/openstack/charm_tests/ceph/tests.py | 25 ++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/zaza/openstack/charm_tests/ceph/tests.py b/zaza/openstack/charm_tests/ceph/tests.py index 638a31fe8..9b5e99598 100644 --- a/zaza/openstack/charm_tests/ceph/tests.py +++ b/zaza/openstack/charm_tests/ceph/tests.py @@ -1753,6 +1753,20 @@ def test_persistent_config(self): class CephMonKeyRotationTests(test_utils.BaseCharmTest): """Tests for the rotate-key action.""" + def setUp(self): + """Initialize key rotation test class.""" + super(CephMonKeyRotationTests, self).setUp() + try: + # Workaround for ubuntu units that don't play nicely with zaza. + zaza_model.get_application('ubuntu') + self.app_states = { + 'ubuntu': { + 'workload-status-message': '' + } + } + except KeyError: + self.app_states = None + def _get_all_keys(self, unit, entity_filter): cmd = 'sudo ceph auth ls' result = zaza_model.run_on_unit(unit, cmd) @@ -1770,7 +1784,7 @@ def _get_all_keys(self, unit, entity_filter): ret.add((data[ix - 1], data[ix + 1])) return ret - def _check_key_rotation(self, entity, unit, wait_for_unit=None): + def _check_key_rotation(self, entity, unit): def entity_filter(name): return name.startswith(entity) @@ -1781,11 +1795,7 @@ def entity_filter(name): action_params={'entity': entity} ) zaza_utils.assertActionRanOK(action_obj) - if wait_for_unit is None: - # Wait for all applications - zaza_model.wait_for_application_states() - else: - zaza_model.wait_for_unit_idle(wait_for_unit) + zaza_model.wait_for_application_states(states=self.app_states) new_keys = self._get_all_keys(unit, entity_filter) self.assertNotEqual(old_keys, new_keys) diff = new_keys - old_keys @@ -1824,8 +1834,7 @@ def test_key_rotate(self): # Only wait for ceph-fs, as this model includes 'ubuntu' # units, and those don't play nice with zaza (they don't # set the workload-status-message correctly). - self._check_key_rotation(next(iter(fs_svc))[0], unit, - 'ceph-fs/0') + self._check_key_rotation(next(iter(fs_svc))[0], unit) else: logging.info('ceph-fs units present, but no MDS service') except KeyError: From 6f87be2b5f8515d95cd4d9dfdc9460aa02dec43d Mon Sep 17 00:00:00 2001 From: Luciano Lo Giudice Date: Thu, 25 Apr 2024 18:18:51 -0300 Subject: [PATCH 6/7] Filter master MDS client --- zaza/openstack/charm_tests/ceph/tests.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/zaza/openstack/charm_tests/ceph/tests.py b/zaza/openstack/charm_tests/ceph/tests.py index 9b5e99598..27ad29738 100644 --- a/zaza/openstack/charm_tests/ceph/tests.py +++ b/zaza/openstack/charm_tests/ceph/tests.py @@ -1812,6 +1812,13 @@ def _get_rgw_client(self, unit): return None return next(iter(ret))[0] + def _get_fs_client(self, unit): + ret = self._get_all_keys(unit, lambda x: (x.startswith('mds.') and + x != 'mds.ceph-fs')) + if not ret: + return None + return next(iter(ret))[0] + def test_key_rotate(self): """Test that rotating the keys actually changes them.""" unit = 'ceph-mon/0' @@ -1829,7 +1836,7 @@ def test_key_rotate(self): try: zaza_model.get_application('ceph-fs') - fs_svc = self._get_all_keys(unit, lambda x: x.startswith('mds.')) + fs_svc = self._get_fs_client(unit) if fs_svc is not None: # Only wait for ceph-fs, as this model includes 'ubuntu' # units, and those don't play nice with zaza (they don't From 987e048c11e314481f37ee8fddb6f128756d3dd1 Mon Sep 17 00:00:00 2001 From: Luciano Lo Giudice Date: Thu, 25 Apr 2024 19:39:52 -0300 Subject: [PATCH 7/7] Fix fetching of FS service --- zaza/openstack/charm_tests/ceph/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zaza/openstack/charm_tests/ceph/tests.py b/zaza/openstack/charm_tests/ceph/tests.py index 27ad29738..b8be90d52 100644 --- a/zaza/openstack/charm_tests/ceph/tests.py +++ b/zaza/openstack/charm_tests/ceph/tests.py @@ -1841,7 +1841,7 @@ def test_key_rotate(self): # Only wait for ceph-fs, as this model includes 'ubuntu' # units, and those don't play nice with zaza (they don't # set the workload-status-message correctly). - self._check_key_rotation(next(iter(fs_svc))[0], unit) + self._check_key_rotation(fs_svc, unit) else: logging.info('ceph-fs units present, but no MDS service') except KeyError: