Improved config-changed hook to perform steps according to the config changed
This commit is contained in:
commit
563af6aebf
@ -6,7 +6,6 @@
|
||||
import re
|
||||
from charmhelpers.contrib.openstack import context
|
||||
from charmhelpers.contrib.openstack.utils import get_host_ip
|
||||
from charmhelpers.contrib.network.ip import get_address_in_network
|
||||
from charmhelpers.core.hookenv import (
|
||||
config,
|
||||
unit_get,
|
||||
@ -16,6 +15,11 @@ from charmhelpers.core.hookenv import (
|
||||
related_units,
|
||||
relation_get,
|
||||
)
|
||||
from charmhelpers.contrib.network.ip import (
|
||||
is_ip,
|
||||
get_address_in_network,
|
||||
)
|
||||
|
||||
from socket import (
|
||||
gethostname,
|
||||
getfqdn
|
||||
@ -84,7 +88,11 @@ class PGDirContext(context.NeutronContext):
|
||||
else:
|
||||
pg_dir_ips_string = pg_dir_ips_string + ',' + str(ip)
|
||||
pg_ctxt['director_ips_string'] = pg_dir_ips_string
|
||||
pg_ctxt['virtual_ip'] = conf['plumgrid-virtual-ip']
|
||||
PG_VIP = config('plumgrid-virtual-ip')
|
||||
if is_ip(PG_VIP):
|
||||
pg_ctxt['virtual_ip'] = conf['plumgrid-virtual-ip']
|
||||
else:
|
||||
raise ValueError('Invalid PLUMgrid Virtual IP Provided')
|
||||
unit_hostname = gethostname()
|
||||
pg_ctxt['pg_hostname'] = unit_hostname
|
||||
pg_ctxt['pg_fqdn'] = getfqdn()
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
import sys
|
||||
import time
|
||||
from charmhelpers.core.host import service_running
|
||||
|
||||
from charmhelpers.core.hookenv import (
|
||||
Hooks,
|
||||
@ -69,33 +70,36 @@ 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('plumgrid-license-key'):
|
||||
if post_pg_license():
|
||||
log("PLUMgrid License Posted")
|
||||
return 1
|
||||
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('plumgrid-virtual-ip'):
|
||||
CONFIGS.write_all()
|
||||
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()
|
||||
add_lcm_key()
|
||||
CONFIGS.write_all()
|
||||
restart_pg()
|
||||
if not service_running('plumgrid'):
|
||||
restart_pg()
|
||||
|
||||
|
||||
@hooks.hook('start')
|
||||
|
@ -30,6 +30,7 @@ from charmhelpers.contrib.network.ip import (
|
||||
from charmhelpers.core.host import (
|
||||
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(5)
|
||||
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():
|
||||
|
@ -62,10 +62,6 @@ class PGDirHooksTests(CharmTestCase):
|
||||
self.load_iovisor.assert_called_with()
|
||||
self.ensure_mtu.assert_called_with()
|
||||
|
||||
def test_config_changed_hook(self):
|
||||
self.add_lcm_key.return_value = 1
|
||||
self._call_hook('config-changed')
|
||||
|
||||
def test_start(self):
|
||||
self._call_hook('start')
|
||||
self.test_config.set('plumgrid-license-key', None)
|
||||
|
Loading…
x
Reference in New Issue
Block a user