Improved config-changed hook to perform steps according to the config changed
This commit is contained in:
commit
a8f68eae1e
|
@ -14,6 +14,8 @@ from charmhelpers.core.hookenv import (
|
|||
config,
|
||||
)
|
||||
|
||||
from charmhelpers.core.host import service_running
|
||||
|
||||
from charmhelpers.fetch import (
|
||||
apt_install,
|
||||
apt_purge,
|
||||
|
@ -74,30 +76,32 @@ def config_changed():
|
|||
This hook is run when a config parameter is changed.
|
||||
It also runs on node reboot.
|
||||
'''
|
||||
if add_lcm_key():
|
||||
log("PLUMgrid LCM Key added")
|
||||
return 1
|
||||
charm_config = config()
|
||||
if charm_config.changed('lcm-ssh-key'):
|
||||
if add_lcm_key():
|
||||
log("PLUMgrid LCM Key added")
|
||||
if charm_config.changed('fabric-interfaces'):
|
||||
if not fabric_interface_changed():
|
||||
log("Fabric interface already set")
|
||||
return 1
|
||||
if charm_config.changed('os-data-network'):
|
||||
if charm_config['fabric-interfaces'] == 'MANAGEMENT':
|
||||
log('Fabric running on managment network')
|
||||
return 1
|
||||
stop_pg()
|
||||
configure_sources(update=True)
|
||||
pkgs = determine_packages()
|
||||
for pkg in pkgs:
|
||||
apt_install(pkg, options=['--force-yes'], fatal=True)
|
||||
remove_iovisor()
|
||||
load_iovisor()
|
||||
else:
|
||||
stop_pg()
|
||||
if charm_config.changed('external-interfaces'):
|
||||
stop_pg()
|
||||
if (charm_config.changed('install_sources') or
|
||||
charm_config.changed('plumgrid-build') or
|
||||
charm_config.changed('install_keys') or
|
||||
charm_config.changed('iovisor-build')):
|
||||
stop_pg()
|
||||
configure_sources(update=True)
|
||||
pkgs = determine_packages()
|
||||
for pkg in pkgs:
|
||||
apt_install(pkg, options=['--force-yes'], fatal=True)
|
||||
remove_iovisor()
|
||||
load_iovisor()
|
||||
ensure_mtu()
|
||||
ensure_files()
|
||||
add_lcm_key()
|
||||
CONFIGS.write_all()
|
||||
restart_pg()
|
||||
if not service_running('plumgrid'):
|
||||
restart_pg()
|
||||
|
||||
|
||||
@hooks.hook('upgrade-charm')
|
||||
|
|
|
@ -30,6 +30,7 @@ from charmhelpers.core.host import (
|
|||
write_file,
|
||||
service_start,
|
||||
service_stop,
|
||||
service_running
|
||||
)
|
||||
from charmhelpers.fetch import (
|
||||
apt_cache,
|
||||
|
@ -142,7 +143,17 @@ def restart_pg():
|
|||
'''
|
||||
stop_pg()
|
||||
service_start('plumgrid')
|
||||
time.sleep(30)
|
||||
time.sleep(3)
|
||||
if not service_running('plumgrid'):
|
||||
if service_running('libvirt-bin'):
|
||||
raise ValueError("plumgrid service couldn't be started")
|
||||
else:
|
||||
if service_start('libvirt-bin'):
|
||||
time.sleep(3)
|
||||
if not service_running('plumgrid'):
|
||||
raise ValueError("plumgrid service couldn't be started")
|
||||
else:
|
||||
raise ValueError("libvirt-bin service couldn't be started")
|
||||
|
||||
|
||||
def stop_pg():
|
||||
|
|
|
@ -70,10 +70,6 @@ class PGGwHooksTests(CharmTestCase):
|
|||
self.CONFIGS.write_all.assert_called_with()
|
||||
self.restart_pg.assert_called_with()
|
||||
|
||||
def test_config_changed_hook(self):
|
||||
self.add_lcm_key.return_value = 1
|
||||
self._call_hook('config-changed')
|
||||
|
||||
def test_stop(self):
|
||||
_pkgs = ['plumgrid-lxc', 'iovisor-dkms']
|
||||
self._call_hook('stop')
|
||||
|
|
Loading…
Reference in New Issue