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

Proposed by Junaid Ali on 2016-03-14
Status: Merged
Merged at revision: 23
Proposed branch: lp:~junaidali/charms/trusty/plumgrid-gateway/trunk
Merge into: lp:~plumgrid-team/charms/trusty/plumgrid-gateway/trunk
Diff against target: 109 lines (+34/-24)
3 files modified
hooks/pg_gw_hooks.py (+22/-19)
hooks/pg_gw_utils.py (+12/-1)
unit_tests/test_pg_gw_hooks.py (+0/-4)
To merge this branch: bzr merge lp:~junaidali/charms/trusty/plumgrid-gateway/trunk
Reviewer Review Type Date Requested Status
Bilal Baqar 2016-03-14 Approve on 2016-03-25
Hassaan Pasha 2016-03-21 Pending
Review via email: mp+288939@code.launchpad.net
To post a comment you must log in.
Bilal Baqar (bbaqar) :
review: Approve
23. By Bilal Baqar on 2016-03-25

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_gw_hooks.py'
2--- hooks/pg_gw_hooks.py 2016-03-14 04:18:03 +0000
3+++ hooks/pg_gw_hooks.py 2016-03-25 16:51:08 +0000
4@@ -14,6 +14,8 @@
5 config,
6 )
7
8+from charmhelpers.core.host import service_running
9+
10 from charmhelpers.fetch import (
11 apt_install,
12 apt_purge,
13@@ -74,30 +76,31 @@
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- ensure_files()
41- add_lcm_key()
42+ else:
43+ stop_pg()
44+ if charm_config.changed('external-interfaces'):
45+ stop_pg()
46+ if (charm_config.changed('install_sources') or
47+ charm_config.changed('plumgrid-build') or
48+ charm_config.changed('install_keys') or
49+ charm_config.changed('iovisor-build')):
50+ stop_pg()
51+ configure_sources(update=True)
52+ pkgs = determine_packages()
53+ for pkg in pkgs:
54+ apt_install(pkg, options=['--force-yes'], fatal=True)
55+ remove_iovisor()
56+ load_iovisor()
57 CONFIGS.write_all()
58- restart_pg()
59+ if not service_running('plumgrid'):
60+ restart_pg()
61
62
63 @hooks.hook('upgrade-charm')
64
65=== modified file 'hooks/pg_gw_utils.py'
66--- hooks/pg_gw_utils.py 2016-03-13 02:08:48 +0000
67+++ hooks/pg_gw_utils.py 2016-03-25 16:51:08 +0000
68@@ -30,6 +30,7 @@
69 write_file,
70 service_start,
71 service_stop,
72+ service_running
73 )
74 from charmhelpers.fetch import (
75 apt_cache,
76@@ -142,7 +143,17 @@
77 '''
78 stop_pg()
79 service_start('plumgrid')
80- time.sleep(30)
81+ time.sleep(3)
82+ if not service_running('plumgrid'):
83+ if service_running('libvirt-bin'):
84+ raise ValueError("plumgrid service couldn't be started")
85+ else:
86+ if service_start('libvirt-bin'):
87+ time.sleep(3)
88+ if not service_running('plumgrid'):
89+ raise ValueError("plumgrid service couldn't be started")
90+ else:
91+ raise ValueError("libvirt-bin service couldn't be started")
92
93
94 def stop_pg():
95
96=== modified file 'unit_tests/test_pg_gw_hooks.py'
97--- unit_tests/test_pg_gw_hooks.py 2016-03-10 22:39:19 +0000
98+++ unit_tests/test_pg_gw_hooks.py 2016-03-25 16:51:08 +0000
99@@ -70,10 +70,6 @@
100 self.CONFIGS.write_all.assert_called_with()
101 self.restart_pg.assert_called_with()
102
103- def test_config_changed_hook(self):
104- self.add_lcm_key.return_value = 1
105- self._call_hook('config-changed')
106-
107 def test_stop(self):
108 _pkgs = ['plumgrid-lxc', 'iovisor-dkms']
109 self._call_hook('stop')

Subscribers

People subscribed via source and target branches