From f8987ff8ca1cea34b386bdf01ebddf3bd73ddb7c Mon Sep 17 00:00:00 2001 From: Junaid Ali Date: Mon, 14 Mar 2016 20:13:15 +0500 Subject: [PATCH 1/5] Ensuring plumgrid services to restart on certain hooks, Updated restart_pg() --- hooks/pg_gw_hooks.py | 33 +++++++++++++++++---------------- hooks/pg_gw_utils.py | 9 ++++++++- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/hooks/pg_gw_hooks.py b/hooks/pg_gw_hooks.py index 97ea9c6..7df9ba1 100755 --- a/hooks/pg_gw_hooks.py +++ b/hooks/pg_gw_hooks.py @@ -74,30 +74,31 @@ 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 + else: + restart_pg() 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() - ensure_mtu() - ensure_files() - add_lcm_key() + 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('upgrade-charm') diff --git a/hooks/pg_gw_utils.py b/hooks/pg_gw_utils.py index 186870f..3786485 100644 --- a/hooks/pg_gw_utils.py +++ b/hooks/pg_gw_utils.py @@ -141,7 +141,14 @@ def restart_pg(): Stops and Starts PLUMgrid service after flushing iptables. ''' stop_pg() - 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(30) From 2e99af93876bcc669b15ee1f20a3118a3948705f Mon Sep 17 00:00:00 2001 From: Junaid Ali Date: Wed, 16 Mar 2016 07:13:44 +0500 Subject: [PATCH 2/5] Updated config-changed hook and restart_pg() --- hooks/pg_gw_hooks.py | 10 +++++++--- hooks/pg_gw_utils.py | 3 ++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/hooks/pg_gw_hooks.py b/hooks/pg_gw_hooks.py index 7df9ba1..5e3b1cc 100755 --- a/hooks/pg_gw_hooks.py +++ b/hooks/pg_gw_hooks.py @@ -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, @@ -82,13 +84,12 @@ def config_changed(): if not fabric_interface_changed(): log("Fabric interface already set") else: - restart_pg() + stop_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) @@ -97,8 +98,11 @@ def config_changed(): apt_install(pkg, options=['--force-yes'], fatal=True) remove_iovisor() load_iovisor() - restart_pg() CONFIGS.write_all() + # Restarting the plumgrid service only if it is + # already stopped by any config-parameters or node reboot + 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 3786485..9ca5bdb 100644 --- a/hooks/pg_gw_utils.py +++ b/hooks/pg_gw_utils.py @@ -148,7 +148,8 @@ def restart_pg(): # wait for 3 secs so that libvirt-bin can be completely up and # start the plumgrid service time.sleep(3) - service_start('plumgrid') + if not service_start('plumgrid'): + raise ValueError("plumgrid service couldn't be started") time.sleep(30) From c21e4554ce563a9254577ea579e521a3b61ab1a4 Mon Sep 17 00:00:00 2001 From: Junaid Ali Date: Mon, 21 Mar 2016 23:46:01 +0500 Subject: [PATCH 3/5] Updated restart_pg() --- hooks/pg_gw_hooks.py | 6 +----- hooks/pg_gw_utils.py | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/hooks/pg_gw_hooks.py b/hooks/pg_gw_hooks.py index 5e3b1cc..4ff5abc 100755 --- a/hooks/pg_gw_hooks.py +++ b/hooks/pg_gw_hooks.py @@ -85,11 +85,9 @@ def config_changed(): log("Fabric interface already set") else: stop_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('install_keys') or charm_config.changed('iovisor-build')): stop_pg() configure_sources(update=True) @@ -99,8 +97,6 @@ def config_changed(): remove_iovisor() load_iovisor() CONFIGS.write_all() - # Restarting the plumgrid service only if it is - # already stopped by any config-parameters or node reboot if not service_running('plumgrid'): restart_pg() diff --git a/hooks/pg_gw_utils.py b/hooks/pg_gw_utils.py index 9ca5bdb..1830f12 100644 --- a/hooks/pg_gw_utils.py +++ b/hooks/pg_gw_utils.py @@ -30,6 +30,7 @@ from charmhelpers.core.host import ( write_file, service_start, service_stop, + service_running ) from charmhelpers.fetch import ( apt_cache, @@ -141,16 +142,18 @@ def restart_pg(): Stops and Starts PLUMgrid service after flushing iptables. ''' stop_pg() - if not service_start('plumgrid'): - if not service_start('libvirt-bin'): - raise ValueError("libvirt-bin service couldn't be started") + service_start('plumgrid') + time.sleep(3) + if not service_running('plumgrid'): + if service_running('libvirt-bin'): + raise ValueError("plumgrid 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) - if not service_start('plumgrid'): - raise ValueError("plumgrid service couldn't be started") - time.sleep(30) + 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(): From 13b2c42048fc54fcaf8965c063a6cce8c5c913b1 Mon Sep 17 00:00:00 2001 From: Junaid Ali Date: Thu, 24 Mar 2016 18:12:00 +0500 Subject: [PATCH 4/5] unit_test fix --- unit_tests/test_pg_gw_hooks.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/unit_tests/test_pg_gw_hooks.py b/unit_tests/test_pg_gw_hooks.py index a1b5779..c132dd3 100644 --- a/unit_tests/test_pg_gw_hooks.py +++ b/unit_tests/test_pg_gw_hooks.py @@ -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') From 8d618fed2abbaa4f85face4e8a7be3874247eefe Mon Sep 17 00:00:00 2001 From: Junaid Ali Date: Fri, 25 Mar 2016 21:50:46 +0500 Subject: [PATCH 5/5] Updated config-changed hook --- hooks/pg_gw_hooks.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hooks/pg_gw_hooks.py b/hooks/pg_gw_hooks.py index 4ff5abc..639e9a5 100755 --- a/hooks/pg_gw_hooks.py +++ b/hooks/pg_gw_hooks.py @@ -85,6 +85,8 @@ def config_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