Merge lp:~junaidali/charms/trusty/plumgrid-edge/trunk into lp:~plumgrid-team/charms/trusty/plumgrid-edge/trunk

Proposed by Junaid Ali
Status: Merged
Merged at revision: 24
Proposed branch: lp:~junaidali/charms/trusty/plumgrid-edge/trunk
Merge into: lp:~plumgrid-team/charms/trusty/plumgrid-edge/trunk
Diff against target: 117 lines (+38/-28)
3 files modified
hooks/pg_edge_hooks.py (+26/-23)
hooks/pg_edge_utils.py (+12/-1)
unit_tests/test_pg_edge_hooks.py (+0/-4)
To merge this branch: bzr merge lp:~junaidali/charms/trusty/plumgrid-edge/trunk
Reviewer Review Type Date Requested Status
Bilal Baqar Approve
Hassaan Pasha Pending
Review via email: mp+289000@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Bilal Baqar (bbaqar) :
review: Approve
24. By Bilal Baqar

Improved config-changed hook to perform steps according to the config changed

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/pg_edge_hooks.py'
2--- hooks/pg_edge_hooks.py 2016-03-14 06:33:46 +0000
3+++ hooks/pg_edge_hooks.py 2016-03-24 12:36:47 +0000
4@@ -6,7 +6,7 @@
5 # in this file.
6
7 import sys
8-
9+from charmhelpers.core.host import service_running
10 from charmhelpers.core.hookenv import (
11 Hooks,
12 UnregisteredHookError,
13@@ -89,33 +89,36 @@
14 This hook is run when a config parameter is changed.
15 It also runs on node reboot.
16 '''
17- if add_lcm_key():
18- log("PLUMgrid LCM Key added")
19- return 1
20 charm_config = config()
21+ if charm_config.changed('lcm-ssh-key'):
22+ if add_lcm_key():
23+ log("PLUMgrid LCM Key added")
24 if charm_config.changed('fabric-interfaces'):
25 if not fabric_interface_changed():
26 log("Fabric interface already set")
27- return 1
28- if charm_config.changed('os-data-network'):
29- if charm_config['fabric-interfaces'] == 'MANAGEMENT':
30- log('Fabric running on managment network')
31- return 1
32- stop_pg()
33- configure_sources(update=True)
34- pkgs = determine_packages()
35- for pkg in pkgs:
36- apt_install(pkg, options=['--force-yes'], fatal=True)
37- remove_iovisor()
38- load_iovisor()
39- ensure_mtu()
40- for rid in relation_ids('neutron-plugin'):
41- neutron_plugin_joined(rid)
42- for rid in relation_ids('plumgrid-plugin'):
43- neutron_plugin_joined(rid)
44- ensure_files()
45+ else:
46+ stop_pg()
47+ if (charm_config.changed('install_sources') or
48+ charm_config.changed('plumgrid-build') or
49+ charm_config.changed('install_keys') or
50+ charm_config.changed('iovisor-build')):
51+ ensure_files()
52+ stop_pg()
53+ configure_sources(update=True)
54+ pkgs = determine_packages()
55+ for pkg in pkgs:
56+ apt_install(pkg, options=['--force-yes'], fatal=True)
57+ remove_iovisor()
58+ load_iovisor()
59+ if charm_config.changed('metadata-shared-key'):
60+ stop_pg()
61+ for rid in relation_ids('neutron-plugin'):
62+ neutron_plugin_joined(rid)
63+ for rid in relation_ids('plumgrid-plugin'):
64+ neutron_plugin_joined(rid)
65 CONFIGS.write_all()
66- restart_pg()
67+ if not service_running('plumgrid'):
68+ restart_pg()
69
70
71 @hooks.hook('upgrade-charm')
72
73=== modified file 'hooks/pg_edge_utils.py'
74--- hooks/pg_edge_utils.py 2016-03-12 21:32:55 +0000
75+++ hooks/pg_edge_utils.py 2016-03-24 12:36:47 +0000
76@@ -31,6 +31,7 @@
77 service_restart,
78 service_start,
79 service_stop,
80+ service_running,
81 )
82 from charmhelpers.fetch import (
83 apt_cache,
84@@ -156,7 +157,17 @@
85 '''
86 stop_pg()
87 service_start('plumgrid')
88- time.sleep(5)
89+ time.sleep(3)
90+ if not service_running('plumgrid'):
91+ if service_running('libvirt-bin'):
92+ raise ValueError("plumgrid service couldn't be started")
93+ else:
94+ if service_start('libvirt-bin'):
95+ time.sleep(3)
96+ if not service_running('plumgrid'):
97+ raise ValueError("plumgrid service couldn't be started")
98+ else:
99+ raise ValueError("libvirt-bin service couldn't be started")
100
101
102 def stop_pg():
103
104=== modified file 'unit_tests/test_pg_edge_hooks.py'
105--- unit_tests/test_pg_edge_hooks.py 2016-03-10 22:20:47 +0000
106+++ unit_tests/test_pg_edge_hooks.py 2016-03-24 12:36:47 +0000
107@@ -83,10 +83,6 @@
108 **rel_data
109 )
110
111- def test_config_changed_hook(self):
112- self.add_lcm_key.return_value = 1
113- self._call_hook('config-changed')
114-
115 def test_stop(self):
116 _pkgs = ['plumgrid-lxc', 'iovisor-dkms']
117 self._call_hook('stop')

Subscribers

People subscribed via source and target branches