From 72b420b56acb40622ea79f3be9555ccbbf876f59 Mon Sep 17 00:00:00 2001 From: Dmitrii Shcherbakov Date: Tue, 21 Apr 2020 16:50:02 +0300 Subject: [PATCH] Use the new svc restart checker where possible restart_on_changed_debug_oslo_config_file was added to avoid code duplication. --- zaza/openstack/charm_tests/aodh/tests.py | 10 +---- zaza/openstack/charm_tests/cinder/tests.py | 10 +---- zaza/openstack/charm_tests/designate/tests.py | 13 ++---- zaza/openstack/charm_tests/glance/tests.py | 26 ++---------- zaza/openstack/charm_tests/nova/tests.py | 41 ++----------------- 5 files changed, 12 insertions(+), 88 deletions(-) diff --git a/zaza/openstack/charm_tests/aodh/tests.py b/zaza/openstack/charm_tests/aodh/tests.py index a8c7ee8..c11e054 100644 --- a/zaza/openstack/charm_tests/aodh/tests.py +++ b/zaza/openstack/charm_tests/aodh/tests.py @@ -114,20 +114,12 @@ class AodhTest(test_utils.OpenStackBaseTest): Change debug mode and assert that change propagates to the correct file and that services are restarted as a result """ - # Expected default and alternate values - set_default = {'debug': 'False'} - set_alternate = {'debug': 'True'} - # Config file affected by juju set config change conf_file = '/etc/aodh/aodh.conf' # Make config change, check for service restarts - self.restart_on_changed( + self.restart_on_changed_debug_oslo_config_file( conf_file, - set_default, - set_alternate, - {'DEFAULT': {'debug': ['False']}}, - {'DEFAULT': {'debug': ['True']}}, self.services) self.query_aodh_api() diff --git a/zaza/openstack/charm_tests/cinder/tests.py b/zaza/openstack/charm_tests/cinder/tests.py index cdccce6..d645eed 100644 --- a/zaza/openstack/charm_tests/cinder/tests.py +++ b/zaza/openstack/charm_tests/cinder/tests.py @@ -168,21 +168,13 @@ class CinderTests(test_utils.OpenStackBaseTest): Change debug mode and assert that change propagates to the correct file and that services are restarted as a result """ - # Expected default and alternate values - set_default = {'debug': 'False'} - set_alternate = {'debug': 'True'} - # Config file affected by juju set config change conf_file = '/etc/cinder/cinder.conf' # Make config change, check for service restarts logging.debug('Setting debug mode...') - self.restart_on_changed( + self.restart_on_changed_debug_oslo_config_file( conf_file, - set_default, - set_alternate, - {'DEFAULT': {'debug': ['False']}}, - {'DEFAULT': {'debug': ['True']}}, self.services) def test_901_pause_resume(self): diff --git a/zaza/openstack/charm_tests/designate/tests.py b/zaza/openstack/charm_tests/designate/tests.py index 5066dd4..f8a32db 100644 --- a/zaza/openstack/charm_tests/designate/tests.py +++ b/zaza/openstack/charm_tests/designate/tests.py @@ -98,22 +98,15 @@ class DesignateTests(BaseDesignateTest): Change debug mode and assert that change propagates to the correct file and that services are restarted as a result """ - # Expected default and alternate values - set_default = {'debug': 'False'} - set_alternate = {'debug': 'True'} - # Services which are expected to restart upon config change, # and corresponding config files affected by the change conf_file = '/etc/designate/designate.conf' # Make config change, check for service restarts - self.restart_on_changed( + self.restart_on_changed_debug_oslo_config_file( conf_file, - set_default, - set_alternate, - {'DEFAULT': {'debug': ['False']}}, - {'DEFAULT': {'debug': ['True']}}, - self.designate_svcs) + self.designate_svcs, + ) def test_910_pause_and_resume(self): """Run pause and resume tests. diff --git a/zaza/openstack/charm_tests/glance/tests.py b/zaza/openstack/charm_tests/glance/tests.py index 033ec28..ba1051f 100644 --- a/zaza/openstack/charm_tests/glance/tests.py +++ b/zaza/openstack/charm_tests/glance/tests.py @@ -69,22 +69,6 @@ class GlanceTest(test_utils.OpenStackBaseTest): def test_900_restart_on_config_change(self): """Checking restart happens on config change.""" - # Expected default and alternate values - current_value = openstack_utils.get_application_config_option( - 'glance', 'debug') - # this is bool, not str - assert type(current_value) == bool - new_value = not current_value - - # convert bool to str - current_value = str(current_value) - new_value = str(new_value) - - set_default = {'debug': current_value} - set_alternate = {'debug': new_value} - default_entry = {'DEFAULT': {'debug': [current_value]}} - alternate_entry = {'DEFAULT': {'debug': [new_value]}} - # Config file affected by juju set config change conf_file = '/etc/glance/glance-api.conf' @@ -96,14 +80,10 @@ class GlanceTest(test_utils.OpenStackBaseTest): services.update({'glance-registry': conf_file}) # Make config change, check for service restarts - logging.info('changing config: {}'.format(set_alternate)) - self.restart_on_changed( + logging.info('changing debug config') + self.restart_on_changed_debug_oslo_config_file( conf_file, - set_default, - set_alternate, - default_entry, - alternate_entry, - services) + self.services) def test_901_pause_resume(self): """Run pause and resume tests. diff --git a/zaza/openstack/charm_tests/nova/tests.py b/zaza/openstack/charm_tests/nova/tests.py index 03faaae..eefdab5 100644 --- a/zaza/openstack/charm_tests/nova/tests.py +++ b/zaza/openstack/charm_tests/nova/tests.py @@ -80,29 +80,13 @@ class NovaCompute(test_utils.OpenStackBaseTest): Change debug mode and assert that change propagates to the correct file and that services are restarted as a result """ - # Expected default and alternate values - current_value = zaza.model.get_application_config( - 'nova-compute')['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]}} - # Config file affected by juju set config change conf_file = '/etc/nova/nova.conf' # Make config change, check for service restarts - logging.info( - 'Setting verbose on nova-compute {}'.format(set_alternate)) - self.restart_on_changed( + logging.info('Changing the debug config on nova-compute') + self.restart_on_changed_debug_oslo_config_file( conf_file, - set_default, - set_alternate, - default_entry, - alternate_entry, ['nova-compute']) def test_920_change_aa_profile(self): @@ -339,30 +323,13 @@ class NovaCloudController(test_utils.OpenStackBaseTest): Change debug mode and assert that change propagates to the correct file and that services are restarted as a result """ - # Expected default and alternate values - current_value = zaza.model.get_application_config( - 'nova-cloud-controller')['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]}} - # Config file affected by juju set config change conf_file = '/etc/nova/nova.conf' # Make config change, check for service restarts - logging.info( - 'Setting verbose on nova-cloud-controller {}'.format( - set_alternate)) - self.restart_on_changed( + logging.info('Changing debug config on nova-cloud-controller') + self.restart_on_changed_debug_oslo_config_file( conf_file, - set_default, - set_alternate, - default_entry, - alternate_entry, self.services) def test_901_pause_resume(self):