From 3c609adde8dc6a0567a02c99d88690afdd9107d3 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 26 May 2022 19:00:17 +0000 Subject: [PATCH 1/4] Add new ceph-fs configuration test --- zaza/openstack/charm_tests/ceph/fs/tests.py | 66 ++++++++++++++++++++- 1 file changed, 64 insertions(+), 2 deletions(-) diff --git a/zaza/openstack/charm_tests/ceph/fs/tests.py b/zaza/openstack/charm_tests/ceph/fs/tests.py index 28ac259..434263d 100644 --- a/zaza/openstack/charm_tests/ceph/fs/tests.py +++ b/zaza/openstack/charm_tests/ceph/fs/tests.py @@ -15,14 +15,18 @@ """Encapsulate CephFS testing.""" import logging +import time +import asyncio from tenacity import Retrying, stop_after_attempt, wait_exponential - import zaza.model as model import zaza.openstack.charm_tests.neutron.tests as neutron_tests import zaza.openstack.charm_tests.nova.utils as nova_utils import zaza.openstack.charm_tests.test_utils as test_utils import zaza.openstack.configure.guest as guest -import zaza.openstack.utilities.openstack as openstack_utils + +from zaza.openstack.utilities import ( + openstack as openstack_utils, +) class CephFSTests(test_utils.OpenStackBaseTest): @@ -103,6 +107,64 @@ write_files: 'sudo cat /mnt/cephfs/test', password=password, privkey=privkey, verify=verify) + def test_conf(self): + """Test ceph to ensure juju config options are properly set.""" + self.TESTED_UNIT = 'ceph-fs/0' + + def _get_conf(): + """get/parse config file into dict for specified configs. + + :returns dict: conf options selected from configs + :rtype: dict + """ + conf = model.run_on_unit(self.TESTED_UNIT, "cat {}" + .format('/etc/ceph/ceph.conf')) + holder = [] + configs = ["mds cache memory limit", + "mds cache reservation", + "mds health cache threshold"] + for item in conf['Stdout'].split("\n"): + if any(ext in item for ext in configs): + holder.append(tuple(item.split('='))) + # strip the leading/trailing whitespace + return dict((k.strip(), v.strip()) + for k, v in dict(holder).items()) + + def _change_conf_check(mds_config): + """Change configs, then assert to ensure config was set. + + Doesn't return a value. + """ + loop = asyncio.get_event_loop() + crt = model.async_set_application_config('ceph-fs', mds_config) + loop.run_until_complete(crt) + results = _get_conf() + time.sleep(1) # needs time to release lock and update conf. + assert int(results['mds cache memory limit']) == \ + int(mds_config['mds-cache-memory-limit']) + assert float(results['mds cache reservation']) == \ + float(mds_config['mds-cache-reservation']) + assert float(results['mds health cache threshold']) == \ + float(mds_config['mds-health-cache-threshold']) + + # ensure defaults are set + mds_config = {'mds-cache-memory-limit': '4294967296', + 'mds-cache-reservation': '0.05', + 'mds-health-cache-threshold': '1.5'} + _change_conf_check(mds_config) + + # change defaults + mds_config = {'mds-cache-memory-limit': '8589934592', + 'mds-cache-reservation': '0.10', + 'mds-health-cache-threshold': '2'} + _change_conf_check(mds_config) + + # Restore config to keep tests idempotent + mds_config = {'mds-cache-memory-limit': '4294967296', + 'mds-cache-reservation': '0.05', + 'mds-health-cache-threshold': '1.5'} + _change_conf_check(mds_config) + def _indent(text, amount, ch=' '): padding = amount * ch From 37193497730e61822f09398c8f3699e7218f2f5b Mon Sep 17 00:00:00 2001 From: Ethan Myers Date: Fri, 27 May 2022 19:39:24 +0000 Subject: [PATCH 2/4] Using retry and better assert --- zaza/openstack/charm_tests/ceph/fs/tests.py | 28 ++++++++++++--------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/zaza/openstack/charm_tests/ceph/fs/tests.py b/zaza/openstack/charm_tests/ceph/fs/tests.py index 434263d..6d21669 100644 --- a/zaza/openstack/charm_tests/ceph/fs/tests.py +++ b/zaza/openstack/charm_tests/ceph/fs/tests.py @@ -15,9 +15,8 @@ """Encapsulate CephFS testing.""" import logging -import time import asyncio -from tenacity import Retrying, stop_after_attempt, wait_exponential +from tenacity import retry, Retrying, stop_after_attempt, wait_exponential import zaza.model as model import zaza.openstack.charm_tests.neutron.tests as neutron_tests import zaza.openstack.charm_tests.nova.utils as nova_utils @@ -130,6 +129,8 @@ write_files: return dict((k.strip(), v.strip()) for k, v in dict(holder).items()) + @retry(wait=wait_exponential(multiplier=1, min=4, max=10), + stop=stop_after_attempt(10)) def _change_conf_check(mds_config): """Change configs, then assert to ensure config was set. @@ -139,28 +140,31 @@ write_files: crt = model.async_set_application_config('ceph-fs', mds_config) loop.run_until_complete(crt) results = _get_conf() - time.sleep(1) # needs time to release lock and update conf. - assert int(results['mds cache memory limit']) == \ - int(mds_config['mds-cache-memory-limit']) - assert float(results['mds cache reservation']) == \ - float(mds_config['mds-cache-reservation']) - assert float(results['mds health cache threshold']) == \ - float(mds_config['mds-health-cache-threshold']) + + self.assertEquals( + results['mds cache memory limit'], + mds_config['mds-cache-memory-limit']) + self.assertAlmostEqual( + float(results['mds cache reservation']), + float(mds_config['mds-cache-reservation'])) + self.assertAlmostEqual( + float(results['mds health cache threshold']), + float(mds_config['mds-health-cache-threshold'])) # ensure defaults are set - mds_config = {'mds-cache-memory-limit': '4294967296', + mds_config = {'mds-cache-memory-limit': '4Gi', 'mds-cache-reservation': '0.05', 'mds-health-cache-threshold': '1.5'} _change_conf_check(mds_config) # change defaults - mds_config = {'mds-cache-memory-limit': '8589934592', + mds_config = {'mds-cache-memory-limit': '8Gi', 'mds-cache-reservation': '0.10', 'mds-health-cache-threshold': '2'} _change_conf_check(mds_config) # Restore config to keep tests idempotent - mds_config = {'mds-cache-memory-limit': '4294967296', + mds_config = {'mds-cache-memory-limit': '4Gi', 'mds-cache-reservation': '0.05', 'mds-health-cache-threshold': '1.5'} _change_conf_check(mds_config) From 197504a728f3ea5912f2183c92fae92fd5f14d59 Mon Sep 17 00:00:00 2001 From: Ethan Myers Date: Tue, 31 May 2022 22:03:31 +0000 Subject: [PATCH 3/4] switched to query ceph daemon vs checking config --- zaza/openstack/charm_tests/ceph/fs/tests.py | 44 +++++++++++---------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/zaza/openstack/charm_tests/ceph/fs/tests.py b/zaza/openstack/charm_tests/ceph/fs/tests.py index 6d21669..facafd7 100644 --- a/zaza/openstack/charm_tests/ceph/fs/tests.py +++ b/zaza/openstack/charm_tests/ceph/fs/tests.py @@ -111,23 +111,27 @@ write_files: self.TESTED_UNIT = 'ceph-fs/0' def _get_conf(): - """get/parse config file into dict for specified configs. + """get/parse ceph daemon response into dict for specified configs. :returns dict: conf options selected from configs :rtype: dict """ - conf = model.run_on_unit(self.TESTED_UNIT, "cat {}" - .format('/etc/ceph/ceph.conf')) - holder = [] - configs = ["mds cache memory limit", - "mds cache reservation", - "mds health cache threshold"] - for item in conf['Stdout'].split("\n"): - if any(ext in item for ext in configs): - holder.append(tuple(item.split('='))) - # strip the leading/trailing whitespace - return dict((k.strip(), v.strip()) - for k, v in dict(holder).items()) + configs = ["mds_cache_memory_limit", + "mds_cache_reservation", + "mds_health_cache_threshold"] + holder = {} + for config in configs: + cmd = "sudo ceph daemon mds." \ + "$HOSTNAME config show | grep {}".format(config) + conf = model.run_on_unit(self.TESTED_UNIT, cmd) + print(conf) + for i in (conf['Stdout'].replace('"', '') + .replace(',', '') + .strip() + .split("\n")): + key, val = i.split(":") + holder[key] = val.strip() + return holder @retry(wait=wait_exponential(multiplier=1, min=4, max=10), stop=stop_after_attempt(10)) @@ -140,31 +144,31 @@ write_files: crt = model.async_set_application_config('ceph-fs', mds_config) loop.run_until_complete(crt) results = _get_conf() - self.assertEquals( - results['mds cache memory limit'], + results['mds_cache_memory_limit'], mds_config['mds-cache-memory-limit']) self.assertAlmostEqual( - float(results['mds cache reservation']), + float(results['mds_cache_reservation']), float(mds_config['mds-cache-reservation'])) self.assertAlmostEqual( - float(results['mds health cache threshold']), + float(results['mds_health_cache_threshold']), float(mds_config['mds-health-cache-threshold'])) # ensure defaults are set - mds_config = {'mds-cache-memory-limit': '4Gi', + _get_conf() + mds_config = {'mds-cache-memory-limit': '4294967296', 'mds-cache-reservation': '0.05', 'mds-health-cache-threshold': '1.5'} _change_conf_check(mds_config) # change defaults - mds_config = {'mds-cache-memory-limit': '8Gi', + mds_config = {'mds-cache-memory-limit': '8589934592', 'mds-cache-reservation': '0.10', 'mds-health-cache-threshold': '2'} _change_conf_check(mds_config) # Restore config to keep tests idempotent - mds_config = {'mds-cache-memory-limit': '4Gi', + mds_config = {'mds-cache-memory-limit': '4294967296', 'mds-cache-reservation': '0.05', 'mds-health-cache-threshold': '1.5'} _change_conf_check(mds_config) From 9974c3849b3a8274abb174cec0ac7eaa965d927f Mon Sep 17 00:00:00 2001 From: Ethan Myers Date: Thu, 2 Jun 2022 14:12:05 +0000 Subject: [PATCH 4/4] no more print --- zaza/openstack/charm_tests/ceph/fs/tests.py | 1 - 1 file changed, 1 deletion(-) diff --git a/zaza/openstack/charm_tests/ceph/fs/tests.py b/zaza/openstack/charm_tests/ceph/fs/tests.py index facafd7..b713139 100644 --- a/zaza/openstack/charm_tests/ceph/fs/tests.py +++ b/zaza/openstack/charm_tests/ceph/fs/tests.py @@ -124,7 +124,6 @@ write_files: cmd = "sudo ceph daemon mds." \ "$HOSTNAME config show | grep {}".format(config) conf = model.run_on_unit(self.TESTED_UNIT, cmd) - print(conf) for i in (conf['Stdout'].replace('"', '') .replace(',', '') .strip()