Switch to restart_on_change as context manager

The restart_on_change function is now both a decorator and a context
manager. Using it as a context manager is preferred.

func-test-pr: https://github.com/openstack-charmers/zaza-openstack-tests/pull/527

Depends On: https://github.com/juju/charm-helpers/pull/589

Closes-Bug: #1917792

Change-Id: Ifcabf6b233f467a66982957211b40b83cfccd7ef
This commit is contained in:
David Ames 2021-03-16 14:15:41 -07:00
parent 584bf4b14e
commit 477e22553f
3 changed files with 17 additions and 17 deletions

View File

@ -29,7 +29,6 @@ import charmhelpers.contrib.network.ip as ch_net_ip
import charmhelpers.contrib.database.mysql as mysql
import charmhelpers.contrib.openstack.templating as os_templating
import charmhelpers.contrib.openstack.utils as os_utils
# Flag Strings
@ -643,15 +642,10 @@ class MySQLRouterCharm(charms_openstack.charm.OpenStackCharm):
ch_core.hookenv.log("TLS mode PREFERRED", "DEBUG")
_parameters["DEFAULT"] = {"client_ssl_mode": "PREFERRED"}
# NOTE: LP Bug #1917792
# Switch to context manager when work there is completed
@os_utils.pausable_restart_on_change(
self.restart_map, restart_functions=self.restart_functions)
def _config_changed(self, parameters):
with ch_core.host.restart_on_change(
self.restart_map, restart_functions=self.restart_functions):
ch_core.hookenv.log("Updating configuration parameters", "DEBUG")
self.update_config_parameters(parameters)
_config_changed(self, _parameters)
self.update_config_parameters(_parameters)
@tenacity.retry(wait=tenacity.wait_fixed(10),
retry=tenacity.retry_if_exception_type(

View File

@ -10,8 +10,10 @@ configure:
- zaza.openstack.charm_tests.nova.setup.manage_ssh_key
- zaza.openstack.charm_tests.keystone.setup.add_demo_user
tests:
- zaza.openstack.charm_tests.mysql.tests.MySQLRouterTests
- zaza.openstack.charm_tests.keystone.tests.AuthenticationAuthorizationTest
- full_model_ha:
- zaza.openstack.charm_tests.mysql.tests.MySQLRouterTests
- zaza.openstack.charm_tests.keystone.tests.AuthenticationAuthorizationTest
- zaza.openstack.charm_tests.hacluster.tests.HaclusterScalebackTest
gate_bundles:

View File

@ -625,20 +625,15 @@ class TestMySQLRouterCharm(test_utils.PatchHelper):
"auth_cache_ttl": '10',
"auth_cache_refresh_interval": '7',
}
_mock_decorator = mock.MagicMock()
_mock_decorated = mock.MagicMock()
_mock_decorator.return_value = _mock_decorated
def _fake_config(key=None):
return _config_data[key] if key else _config_data
self.patch_object(mysql_router.ch_core.hookenv, "config")
self.patch_object(mysql_router.os.path, "exists")
self.patch_object(mysql_router.os_utils, "pausable_restart_on_change")
self.patch_object(mysql_router.ch_core.host, "restart_on_change")
self.config.side_effect = _fake_config
self.pausable_restart_on_change.return_value = _mock_decorator
self.endpoint_from_flag.return_value = self.db_router
self.db_router.ssl_ca.return_value = '"CACERT"'
_mock_update_config_parameters = mock.MagicMock()
mrc = mysql_router.MySQLRouterCharm()
@ -654,10 +649,19 @@ class TestMySQLRouterCharm(test_utils.PatchHelper):
mrc.config_changed()
_mock_update_config_parameters.assert_not_called()
# Bootstrapped
# With TLS PASSTHROUGH
self.db_router.ssl_ca.return_value = '"CACERT"'
self.exists.return_value = True
mrc.config_changed()
_mock_decorated.assert_has_calls([mock.call(mrc, _params)])
_mock_update_config_parameters.assert_called_once_with(_params)
# With TLS PREFERRED
self.db_router.ssl_ca.return_value = None
_params["DEFAULT"]["client_ssl_mode"] = "PREFERRED"
self.exists.return_value = True
_mock_update_config_parameters.reset_mock()
mrc.config_changed()
_mock_update_config_parameters.assert_called_once_with(_params)
def test_custom_restart_function(self):
self.patch_object(mysql_router.ch_core.host, "service_stop")