From 329d4fb8c568b2dca89c0a79f64b682b7d898fae Mon Sep 17 00:00:00 2001 From: Alex Kavanagh Date: Mon, 20 Apr 2020 12:51:27 +0100 Subject: [PATCH 1/3] Fix hacluster tests for focal with mysql8 The hacluster tests assume that all the subordinates are hacluster. However, with mysql8 there is a mysql-router subordinate as well, and it doesn't support the clean-up action. This change ensures that the tests checks that the subordinate IS hacluter prior to applying the action/test. --- zaza/openstack/charm_tests/hacluster/tests.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/zaza/openstack/charm_tests/hacluster/tests.py b/zaza/openstack/charm_tests/hacluster/tests.py index fb9d8e2..ebffb84 100644 --- a/zaza/openstack/charm_tests/hacluster/tests.py +++ b/zaza/openstack/charm_tests/hacluster/tests.py @@ -49,6 +49,10 @@ class HaclusterTest(test_utils.OpenStackBaseTest): if primary_status["units"][leader].get("subordinates"): for subordinate in primary_status["units"][leader]["subordinates"]: + # mysql-router is a subordinate from focal onwards + _app = subordinate.split('/')[0] + if _app != 'hacluster': + continue logging.info("Cleaning {}".format(subordinate)) _action = "cleanup" action_id = zaza.model.run_action(subordinate, "cleanup") @@ -84,6 +88,10 @@ class HaclusterTest(test_utils.OpenStackBaseTest): if primary_status["units"][leader].get("subordinates"): for subordinate in primary_status["units"][leader]["subordinates"]: + # mysql-router is a subordinate from focal onwards + _app = subordinate.split('/')[0] + if _app != 'hacluster': + continue logging.info("Pausing {}".format(subordinate)) zaza.model.run_action(subordinate, "pause") zaza.model.block_until_unit_wl_status( From d652eff6d9666f0a73ad66c9ebe46f71b2745fa3 Mon Sep 17 00:00:00 2001 From: Liam Young Date: Tue, 21 Apr 2020 07:16:58 +0000 Subject: [PATCH 2/3] Add a helper for testing restart on changed Most api charms test restart on changed by flipping the value of debug. This has led to the same test being copied around. To reduce the boiler plate code this change adds a new test helper which can be used instead. --- zaza/openstack/charm_tests/test_utils.py | 35 ++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/zaza/openstack/charm_tests/test_utils.py b/zaza/openstack/charm_tests/test_utils.py index 137f096..78a2023 100644 --- a/zaza/openstack/charm_tests/test_utils.py +++ b/zaza/openstack/charm_tests/test_utils.py @@ -254,6 +254,41 @@ class BaseCharmTest(unittest.TestCase): # TODO: Optimize with a block on a specific application until idle. model.block_until_all_units_idle() + def restart_on_changed_use_debug(self, config_file, services): + """Check restart happens on config change by flipping debug mode. + + Change debug mode and assert that change propagates to the correct + file and that services are restarted as a result + + :param config_file: Config file to check for settings + :type config_file: str + :param services: Services expected to be restarted when config_file is + changed. + :type services: list + """ + # Expected default and alternate values + current_value = model.get_application_config( + self.application_name)['debug']['value'] + new_value = str(not bool(current_value)).title() + current_value = str(current_value).title() + + set_default = {'debug': current_value} + set_alternate = {'debug': new_value} + default_entry = {'DEFAULT': {'debug': [current_value]}} + alternate_entry = {'DEFAULT': {'debug': [new_value]}} + + # Make config change, check for service restarts + logging.info( + 'Changing settings on {} to {}'.format( + self.application_name, set_alternate)) + self.restart_on_changed( + config_file, + set_default, + set_alternate, + default_entry, + alternate_entry, + services) + def restart_on_changed(self, config_file, default_config, alternate_config, default_entry, alternate_entry, services, pgrep_full=False): From 6694caf281baa2ba47d54a1847cf3962cdb7a404 Mon Sep 17 00:00:00 2001 From: Liam Young Date: Tue, 21 Apr 2020 07:45:42 +0000 Subject: [PATCH 3/3] Improve docstring and allo section override --- zaza/openstack/charm_tests/test_utils.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/zaza/openstack/charm_tests/test_utils.py b/zaza/openstack/charm_tests/test_utils.py index 78a2023..ae431c1 100644 --- a/zaza/openstack/charm_tests/test_utils.py +++ b/zaza/openstack/charm_tests/test_utils.py @@ -254,13 +254,16 @@ class BaseCharmTest(unittest.TestCase): # TODO: Optimize with a block on a specific application until idle. model.block_until_all_units_idle() - def restart_on_changed_use_debug(self, config_file, services): + def restart_on_changed_debug_oslo_config_file(self, config_file, services, + config_section='DEFAULT'): """Check restart happens on config change by flipping debug mode. Change debug mode and assert that change propagates to the correct - file and that services are restarted as a result + file and that services are restarted as a result. config_file must be + an oslo config file and debug option must be set in the + `config_section` section. - :param config_file: Config file to check for settings + :param config_file: OSLO Config file to check for settings :type config_file: str :param services: Services expected to be restarted when config_file is changed. @@ -274,8 +277,8 @@ class BaseCharmTest(unittest.TestCase): set_default = {'debug': current_value} set_alternate = {'debug': new_value} - default_entry = {'DEFAULT': {'debug': [current_value]}} - alternate_entry = {'DEFAULT': {'debug': [new_value]}} + default_entry = {config_section: {'debug': [current_value]}} + alternate_entry = {config_section: {'debug': [new_value]}} # Make config change, check for service restarts logging.info(