Improved config-changed hook to perform steps according to the config changed

This commit is contained in:
Bilal Baqar 2016-03-25 10:27:03 -07:00
commit 885d0337f2
2 changed files with 16 additions and 21 deletions

View File

@ -11,10 +11,12 @@ from charmhelpers.core.hookenv import (
Hooks,
UnregisteredHookError,
log,
config,
)
from charmhelpers.core.host import (
restart_on_change,
service_restart
)
from charmhelpers.fetch import (
@ -48,18 +50,25 @@ def install():
@hooks.hook('config-changed')
@restart_on_change(restart_map())
def config_changed():
'''
This hook is run when a config parameter is changed.
It also runs on node reboot.
'''
stop()
configure_sources()
apt_update()
pkgs = determine_packages()
for pkg in pkgs:
apt_install(pkg, options=['--force-yes'], fatal=True)
ensure_files()
charm_config = config()
if (charm_config.changed('install_sources') or
charm_config.changed('plumgrid-build') or
charm_config.changed('install_keys')):
configure_sources()
apt_update()
pkgs = determine_packages()
for pkg in pkgs:
apt_install(pkg, options=['--force-yes'], fatal=True)
service_restart('neutron-server')
if charm_config.changed('networking-plumgrid-version'):
ensure_files()
service_restart('neutron-server')
CONFIGS.write_all()

View File

@ -52,20 +52,6 @@ class NeutronPGHooksTests(CharmTestCase):
])
self.ensure_files.assert_called_with()
def test_config_changed_hook(self):
_pkgs = ['plumgrid-pythonlib']
self.determine_packages.return_value = [_pkgs]
self._call_hook('config-changed')
self.stop.assert_called_with()
self.configure_sources.assert_called_with()
self.apt_update.assert_called_with()
self.apt_install.assert_has_calls([
call(_pkgs, fatal=True,
options=['--force-yes']),
])
self.ensure_files.assert_called_with()
self.CONFIGS.write_all.assert_called_with()
def test_neutron_api_joined(self):
self._call_hook('neutron-plugin-api-relation-joined')
self.ensure_files.assert_called_with()