Merge pull request #242 from gnuoy/add-debug-restart-on-change

Add a helper for testing restart on changed
This commit is contained in:
Alex Kavanagh
2020-04-21 10:10:28 +01:00
committed by GitHub
+38
View File
@@ -254,6 +254,44 @@ 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_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. config_file must be
an oslo config file and debug option must be set in the
`config_section` section.
: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.
: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 = {config_section: {'debug': [current_value]}}
alternate_entry = {config_section: {'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):