Updated config-changed hook and restart_pg()

This commit is contained in:
Junaid Ali 2016-03-14 19:58:46 +05:00
parent 8db3c9f7e2
commit 8260d9e4d7
2 changed files with 13 additions and 29 deletions

View File

@ -14,8 +14,6 @@ from charmhelpers.core.hookenv import (
config,
)
from charmhelpers.contrib.network.ip import is_ip
from charmhelpers.fetch import (
apt_install,
apt_purge,
@ -69,46 +67,35 @@ def config_changed():
It also runs on node reboot.
'''
charm_config = config()
count = 0
for key in charm_config:
if charm_config.changed(key):
count += 1
if charm_config.changed('lcm-ssh-key'):
if add_lcm_key():
count -= 1
log("PLUMgrid LCM Key added")
if charm_config.changed('plumgrid-license-key'):
if post_pg_license():
count -= 1
log("PLUMgrid License Posted")
if charm_config.changed('network-device-mtu'):
count -= 1
ensure_mtu()
if count > 0:
stop_pg()
else:
CONFIGS.write_all()
return 1
if charm_config.changed('plumgrid-virtual-ip'):
if not is_ip(charm_config['plumgrid-virtual-ip']):
raise ValueError('Invalid IP Provided')
if charm_config.changed('fabric-interfaces'):
if not fabric_interface_changed():
log("Fabric interface already set")
else:
restart_pg()
if charm_config.changed('os-data-network'):
if charm_config['fabric-interfaces'] == 'MANAGEMENT':
log('Fabric running on managment network')
if (charm_config.changed('install_sources') or
charm_config.changed('plumgrid-build') or
charm_config.changed('plumgrid-virtual-ip') 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()
restart_pg()
CONFIGS.write_all()
restart_pg()
@hooks.hook('start')

View File

@ -30,7 +30,6 @@ from charmhelpers.contrib.openstack.utils import (
from charmhelpers.core.host import (
service_start,
service_stop,
service_available,
)
from socket import gethostname as get_unit_hostname
import pg_dir_context
@ -142,19 +141,17 @@ def restart_pg():
'''
Stops and Starts PLUMgrid service after flushing iptables.
'''
if not service_available('plumgrid'):
if service_available('libvirt-bin'):
if not service_start('libvirt-bin'):
raise ValueError("libvirt-bin service couldn't be started")
else:
time.sleep(5)
else:
log("libvirt-bin not installed")
return 0
service_stop('plumgrid')
time.sleep(2)
_exec_cmd(cmd=['iptables', '-F'])
service_start('plumgrid')
if not service_start('plumgrid'):
if not service_start('libvirt-bin'):
raise ValueError("libvirt-bin service couldn't be started")
else:
# wait for 3 secs so that libvirt-bin can be completely up and
# start the plumgrid service
time.sleep(3)
service_start('plumgrid')
time.sleep(5)