Add guard state around configure_domain_name()

This change adds a guard state around the configure_domain_name()
function so that it only gets called ONCE when the relation connects.

This is to prevent restarting keystone everytime the update-status
hook runs on this charm.

Change-Id: I85d14ddb97e78be966f0cc8dbbcea312599d7327
This commit is contained in:
Alex Kavanagh 2017-05-15 17:38:19 +00:00
parent 92f0fb511d
commit 2ba3850521
4 changed files with 26 additions and 1 deletions

View File

@ -3,3 +3,4 @@ options:
basic:
use_venv: True
include_system_packages: True
repo: https://github.com/openstack/charm-keystone-ldap.git

View File

@ -26,11 +26,19 @@ charm.use_defaults(
@reactive.when('domain-backend.connected')
@reactive.when_not('domain-name-configured')
@reactive.when('config.complete')
def configure_domain_name(domain):
keystone_ldap.render_config(domain.trigger_restart)
domain.domain_name(hookenv.config('domain-name') or
hookenv.service_name())
reactive.set_state('domain-name-configured')
@reactive.when_not('domain-backend.connected')
@reactive.when('domain-name-configured')
def clear_domain_name_configured(domain):
reactive.remove_state('domain-name-configured')
@reactive.when_not('always.run')

View File

@ -14,6 +14,9 @@ from __future__ import print_function
import mock
from charms_openstack.test_mocks import charmhelpers as ch
ch.contrib.openstack.utils.OPENSTACK_RELEASES = ('mitaka', )
import reactive.keystone_ldap_handlers as handlers
import charms_openstack.test_utils as test_utils
@ -29,9 +32,12 @@ class TestRegisteredHooks(test_utils.TestRegisteredHooks):
'when': {
'configure_domain_name': ('domain-backend.connected',
'config.complete'),
'clear_domain_name_configured': ('domain-name-configured', ),
},
'when_not': {
'check_configuration': ('always.run',),
'check_configuration': ('always.run', ),
'configure_domain_name': ('domain-name-configured', ),
'clear_domain_name_configured': ('domain-backend.connected', ),
}
}
# test that the hooks were registered via the
@ -54,6 +60,7 @@ class TestKeystoneLDAPCharmHandlers(test_utils.PatchHelper):
self.patch(handlers.keystone_ldap, 'render_config')
self.patch(handlers.hookenv, 'config')
self.patch(handlers.hookenv, 'service_name')
self.patch(handlers.reactive, 'set_state')
self.config.return_value = None
self.service_name.return_value = 'keystone-ldap'
domain = mock.MagicMock()
@ -64,6 +71,13 @@ class TestKeystoneLDAPCharmHandlers(test_utils.PatchHelper):
domain.domain_name.assert_called_with(
'keystone-ldap'
)
self.set_state.assert_called_once_with('domain-name-configured')
def test_clear_domain_name_configured(self):
self.patch(handlers.reactive, 'remove_state')
domain = mock.MagicMock()
handlers.clear_domain_name_configured(domain)
self.remove_state.assert_called_once_with('domain-name-configured')
def test_configure_domain_name_config(self):
self.patch(handlers.keystone_ldap, 'render_config')

View File

@ -16,6 +16,8 @@ import unittest
import mock
from charms_openstack.test_mocks import charmhelpers as ch
ch.contrib.openstack.utils.OPENSTACK_RELEASES = ('mitaka', )
import charm.openstack.keystone_ldap as keystone_ldap