diff --git a/hooks/pg_gw_hooks.py b/hooks/pg_gw_hooks.py index ad020ed..1d3f87d 100755 --- a/hooks/pg_gw_hooks.py +++ b/hooks/pg_gw_hooks.py @@ -14,8 +14,6 @@ from charmhelpers.core.hookenv import ( config, ) -from charmhelpers.core.host import service_running - from charmhelpers.fetch import ( apt_install, configure_sources, @@ -24,7 +22,6 @@ from charmhelpers.fetch import ( from pg_gw_utils import ( register_configs, ensure_files, - restart_pg, restart_map, stop_pg, determine_packages, @@ -35,6 +32,7 @@ from pg_gw_utils import ( fabric_interface_changed, load_iptables, restart_on_change, + restart_on_stop, director_cluster_ready ) @@ -71,6 +69,8 @@ def plumgrid_changed(): @hooks.hook('config-changed') +@restart_on_stop() +@restart_on_change(restart_map()) def config_changed(): ''' This hook is run when a config parameter is changed. @@ -83,10 +83,6 @@ def config_changed(): if charm_config.changed('fabric-interfaces'): if not fabric_interface_changed(): log("Fabric interface already set") - 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 @@ -100,8 +96,6 @@ def config_changed(): load_iovisor() ensure_mtu() CONFIGS.write_all() - if not service_running('plumgrid'): - restart_pg() @hooks.hook('upgrade-charm') diff --git a/hooks/pg_gw_utils.py b/hooks/pg_gw_utils.py index 5bf695c..b4e2f98 100644 --- a/hooks/pg_gw_utils.py +++ b/hooks/pg_gw_utils.py @@ -393,6 +393,19 @@ def director_cluster_ready(): return True if dirs_count == 1 or dirs_count == 3 else False +def restart_on_stop(): + """ + Starts plumgrid service if it is stopped + """ + def wrap(f): + def wrapped_f(*args, **kwargs): + f(*args, **kwargs) + if not service_running('plumgrid'): + restart_pg() + return wrapped_f + return wrap + + def restart_on_change(restart_map): """ Restart services based on configuration files changing @@ -403,6 +416,8 @@ def restart_on_change(restart_map): f(*args, **kwargs) for path in restart_map: if path_hash(path) != checksums[path]: + if path == PG_IFCS_CONF: + ensure_files() restart_pg() break return wrapped_f diff --git a/unit_tests/test_pg_gw_hooks.py b/unit_tests/test_pg_gw_hooks.py index b218be3..eb879c6 100644 --- a/unit_tests/test_pg_gw_hooks.py +++ b/unit_tests/test_pg_gw_hooks.py @@ -24,7 +24,6 @@ TO_PATCH = [ 'configure_sources', 'ensure_files', 'stop_pg', - 'restart_pg', 'load_iovisor', 'ensure_mtu', 'add_lcm_key',