From acf30b3a8a8d8d82e0c9452afb1e58206d880c99 Mon Sep 17 00:00:00 2001 From: Luciano Lo Giudice Date: Fri, 9 Sep 2022 08:24:10 -0300 Subject: [PATCH] Add functional tests for ceph-mon actions. (#866) * Add functional tests for ceph-mon actions. This PR adds functional validation for 2 actions of the ceph-mon charm that are currently being rewritten. Cleanup after the tests run. Co-authored-by: Luciano Lo Giudice --- zaza/openstack/charm_tests/ceph/tests.py | 80 ++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/zaza/openstack/charm_tests/ceph/tests.py b/zaza/openstack/charm_tests/ceph/tests.py index b147fd26a..6a33aa930 100644 --- a/zaza/openstack/charm_tests/ceph/tests.py +++ b/zaza/openstack/charm_tests/ceph/tests.py @@ -1427,3 +1427,83 @@ def test_ceph_auth(self): delete_results = action_obj.data['results']['message'] self.assertEqual(delete_results, "entity client.sandbox does not exist\n") + + +class CephMonActionsTest(test_utils.OpenStackBaseTest): + """Test miscellaneous actions of the ceph-mon charm.""" + + @classmethod + def setUpClass(cls): + """Run class setup for running ceph-mon actions.""" + super(CephMonActionsTest, cls).setUpClass() + # Allow mons to delete pools. + zaza_model.run_on_unit( + 'ceph-mon/0', + "ceph tell mon.\\* injectargs '--mon-allow-pool-delete=true'" + ) + + def _get_osd_weight(self, osd, unit): + """Fetch the CRUSH weight of an OSD.""" + cmd = 'sudo ceph osd crush tree --format=json' + result = zaza_model.run_on_unit(unit, cmd) + self.assertEqual(int(result.get('Code')), 0) + + tree = json.loads(result.get('Stdout')) + for node in tree['nodes']: + if node.get('name') == osd: + return node['crush_weight'] + + def test_reweight_osd(self): + """Test the change-osd-weight action.""" + unit = 'ceph-mon/0' + osd = 0 + osd_str = 'osd.' + str(osd) + weight = 700 + prev_weight = self._get_osd_weight(osd_str, unit) + try: + action_obj = zaza_model.run_action( + unit_name=unit, + action_name='change-osd-weight', + action_params={'osd': osd, 'weight': 700} + ) + zaza_utils.assertActionRanOK(action_obj) + self.assertEqual(weight, self._get_osd_weight(osd_str, unit)) + finally: + # Reset the weight. + zaza_model.run_action( + unit_name=unit, + action_name='change-osd-weight', + action_params={'osd': osd, 'weight': prev_weight} + ) + + def test_copy_pool(self): + """Test the copy-pool (and list-pool) action.""" + unit = 'ceph-mon/0' + logging.debug('Creating secondary test pool') + cmd = 'sudo ceph osd pool create test2 32' + try: + result = zaza_model.run_on_unit(unit, cmd) + self.assertEqual(int(result.get('Code')), 0) + + action_obj = zaza_model.run_action( + unit_name=unit, + action_name='list-pools', + action_params={} + ) + zaza_utils.assertActionRanOK(action_obj) + self.assertIn('test2', action_obj.data['results']['message']) + + logging.debug('Copying test pool') + action_obj = zaza_model.run_action( + unit_name=unit, + action_name='copy-pool', + action_params={'source': 'nova', 'target': 'test2'} + ) + zaza_utils.assertActionRanOK(action_obj) + finally: + # Clean up our mess. + zaza_model.run_on_unit( + unit, + ('sudo ceph osd pool delete test2 test2 ' + '--yes-i-really-really-mean-it') + )