summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBilal Baqar <bbaqar@plumgrid.com>2016-03-25 10:33:22 -0700
committerBilal Baqar <bbaqar@plumgrid.com>2016-03-25 10:33:22 -0700
commita8f68eae1ebfa9bf0d5e6fb29355094acb566ca7 (patch)
tree281d1e9d4ae7e313a244d20201422dcf199af063
parentc4868ea75125efa2fd65fe4e840fe8a902d19a6d (diff)
parent8d618fed2abbaa4f85face4e8a7be3874247eefe (diff)
Improved config-changed hook to perform steps according to the config changed
-rwxr-xr-xhooks/pg_gw_hooks.py40
-rw-r--r--hooks/pg_gw_utils.py13
-rw-r--r--unit_tests/test_pg_gw_hooks.py4
3 files changed, 34 insertions, 23 deletions
diff --git a/hooks/pg_gw_hooks.py b/hooks/pg_gw_hooks.py
index 97ea9c6..b302e4a 100755
--- a/hooks/pg_gw_hooks.py
+++ b/hooks/pg_gw_hooks.py
@@ -14,6 +14,8 @@ from charmhelpers.core.hookenv import (
14 config, 14 config,
15) 15)
16 16
17from charmhelpers.core.host import service_running
18
17from charmhelpers.fetch import ( 19from charmhelpers.fetch import (
18 apt_install, 20 apt_install,
19 apt_purge, 21 apt_purge,
@@ -74,30 +76,32 @@ def config_changed():
74 This hook is run when a config parameter is changed. 76 This hook is run when a config parameter is changed.
75 It also runs on node reboot. 77 It also runs on node reboot.
76 ''' 78 '''
77 if add_lcm_key():
78 log("PLUMgrid LCM Key added")
79 return 1
80 charm_config = config() 79 charm_config = config()
80 if charm_config.changed('lcm-ssh-key'):
81 if add_lcm_key():
82 log("PLUMgrid LCM Key added")
81 if charm_config.changed('fabric-interfaces'): 83 if charm_config.changed('fabric-interfaces'):
82 if not fabric_interface_changed(): 84 if not fabric_interface_changed():
83 log("Fabric interface already set") 85 log("Fabric interface already set")
84 return 1 86 else:
85 if charm_config.changed('os-data-network'): 87 stop_pg()
86 if charm_config['fabric-interfaces'] == 'MANAGEMENT': 88 if charm_config.changed('external-interfaces'):
87 log('Fabric running on managment network') 89 stop_pg()
88 return 1 90 if (charm_config.changed('install_sources') or
89 stop_pg() 91 charm_config.changed('plumgrid-build') or
90 configure_sources(update=True) 92 charm_config.changed('install_keys') or
91 pkgs = determine_packages() 93 charm_config.changed('iovisor-build')):
92 for pkg in pkgs: 94 stop_pg()
93 apt_install(pkg, options=['--force-yes'], fatal=True) 95 configure_sources(update=True)
94 remove_iovisor() 96 pkgs = determine_packages()
95 load_iovisor() 97 for pkg in pkgs:
98 apt_install(pkg, options=['--force-yes'], fatal=True)
99 remove_iovisor()
100 load_iovisor()
96 ensure_mtu() 101 ensure_mtu()
97 ensure_files()
98 add_lcm_key()
99 CONFIGS.write_all() 102 CONFIGS.write_all()
100 restart_pg() 103 if not service_running('plumgrid'):
104 restart_pg()
101 105
102 106
103@hooks.hook('upgrade-charm') 107@hooks.hook('upgrade-charm')
diff --git a/hooks/pg_gw_utils.py b/hooks/pg_gw_utils.py
index 186870f..1830f12 100644
--- a/hooks/pg_gw_utils.py
+++ b/hooks/pg_gw_utils.py
@@ -30,6 +30,7 @@ from charmhelpers.core.host import (
30 write_file, 30 write_file,
31 service_start, 31 service_start,
32 service_stop, 32 service_stop,
33 service_running
33) 34)
34from charmhelpers.fetch import ( 35from charmhelpers.fetch import (
35 apt_cache, 36 apt_cache,
@@ -142,7 +143,17 @@ def restart_pg():
142 ''' 143 '''
143 stop_pg() 144 stop_pg()
144 service_start('plumgrid') 145 service_start('plumgrid')
145 time.sleep(30) 146 time.sleep(3)
147 if not service_running('plumgrid'):
148 if service_running('libvirt-bin'):
149 raise ValueError("plumgrid service couldn't be started")
150 else:
151 if service_start('libvirt-bin'):
152 time.sleep(3)
153 if not service_running('plumgrid'):
154 raise ValueError("plumgrid service couldn't be started")
155 else:
156 raise ValueError("libvirt-bin service couldn't be started")
146 157
147 158
148def stop_pg(): 159def stop_pg():
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):
70 self.CONFIGS.write_all.assert_called_with() 70 self.CONFIGS.write_all.assert_called_with()
71 self.restart_pg.assert_called_with() 71 self.restart_pg.assert_called_with()
72 72
73 def test_config_changed_hook(self):
74 self.add_lcm_key.return_value = 1
75 self._call_hook('config-changed')
76
77 def test_stop(self): 73 def test_stop(self):
78 _pkgs = ['plumgrid-lxc', 'iovisor-dkms'] 74 _pkgs = ['plumgrid-lxc', 'iovisor-dkms']
79 self._call_hook('stop') 75 self._call_hook('stop')