Merge lp:~thedac/charms/trusty/ceph-radosgw/stop-start into lp:~openstack-charmers-archive/charms/trusty/ceph-radosgw/next

Proposed by David Ames
Status: Needs review
Proposed branch: lp:~thedac/charms/trusty/ceph-radosgw/stop-start
Merge into: lp:~openstack-charmers-archive/charms/trusty/ceph-radosgw/next
Diff against target: 198 lines (+72/-11)
4 files modified
hooks/charmhelpers/contrib/openstack/utils.py (+3/-1)
hooks/hooks.py (+13/-7)
hooks/utils.py (+51/-1)
unit_tests/test_hooks.py (+5/-2)
To merge this branch: bzr merge lp:~thedac/charms/trusty/ceph-radosgw/stop-start
Reviewer Review Type Date Requested Status
Liam Young (community) Needs Fixing
Ryan Beisner (community) Needs Information
Review via email: mp+275225@code.launchpad.net

Description of the change

Fixes Bug #1508551
Check radosgw is running for status
stop/start rather than restart
Remove superfluous restart() call

To post a comment you must log in.
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_lint_check #12291 ceph-radosgw-next for thedac mp275225
    LINT OK: passed

Build: http://10.245.162.77:8080/job/charm_lint_check/12291/

Revision history for this message
Ryan Beisner (1chb1n) wrote :

FYI, it's safe to ignore any amulet tests on this MP.

I've pulled these fixes into my WIP MP for updated tests @:
https://code.launchpad.net/~1chb1n/charms/trusty/ceph-radosgw/next-amulet-15.10/+merge/275107

51. By David Ames

Allow time between start and stop

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_lint_check #12327 ceph-radosgw-next for thedac mp275225
    LINT OK: passed

Build: http://10.245.162.77:8080/job/charm_lint_check/12327/

52. By David Ames

Sleep on restart() also

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_lint_check #12332 ceph-radosgw-next for thedac mp275225
    LINT OK: passed

Build: http://10.245.162.77:8080/job/charm_lint_check/12332/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_unit_test #11438 ceph-radosgw-next for thedac mp275225
    UNIT OK: passed

Build: http://10.245.162.77:8080/job/charm_unit_test/11438/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_amulet_test #7498 ceph-radosgw-next for thedac mp275225
    AMULET OK: passed

Build: http://10.245.162.77:8080/job/charm_amulet_test/7498/

Revision history for this message
Ryan Beisner (1chb1n) wrote :

I'd recommend that we wait for the underlying init script bug fix to make its way into the releases by way of the updated ceph package, then re-visit this.

https://bugs.launchpad.net/charms/+source/ceph-radosgw/+bug/1477225

https://launchpad.net/ubuntu/+source/ceph/0.94.3-0ubuntu0.15.04.1

review: Needs Information
Revision history for this message
Ryan Beisner (1chb1n) wrote :

Perhaps we should go forward with radosgw process check and corresponding status message, though. That is helpful, and creates a more accurate readiness indicator in the charm.

Revision history for this message
Liam Young (gnuoy) wrote :

I agree with Ryan that it would be useful to have the status info but the init script fix in the package should negate the need for the restart changes

review: Needs Fixing

Unmerged revisions

52. By David Ames

Sleep on restart() also

51. By David Ames

Allow time between start and stop

50. By David Ames

Pull in CH message fix

49. By David Ames

Check radosgw is running for status. stop/start rather than restart. Remove superfluous restart() call

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/charmhelpers/contrib/openstack/utils.py'
2--- hooks/charmhelpers/contrib/openstack/utils.py 2015-10-01 20:02:04 +0000
3+++ hooks/charmhelpers/contrib/openstack/utils.py 2015-10-22 04:50:31 +0000
4@@ -858,7 +858,9 @@
5 if charm_state != 'active' and charm_state != 'unknown':
6 state = workload_state_compare(state, charm_state)
7 if message:
8- message = "{} {}".format(message, charm_message)
9+ charm_message = charm_message.replace("Incomplete relations: ",
10+ "")
11+ message = "{}, {}".format(message, charm_message)
12 else:
13 message = charm_message
14
15
16=== modified file 'hooks/hooks.py'
17--- hooks/hooks.py 2015-10-08 12:13:08 +0000
18+++ hooks/hooks.py 2015-10-22 04:50:31 +0000
19@@ -13,6 +13,7 @@
20 import glob
21 import os
22 import ceph
23+import time
24 from charmhelpers.core.hookenv import (
25 relation_get,
26 relation_ids,
27@@ -32,7 +33,6 @@
28 )
29 from charmhelpers.core.host import (
30 lsb_release,
31- restart_on_change,
32 )
33 from utils import (
34 render_template,
35@@ -42,6 +42,7 @@
36 register_configs,
37 REQUIRED_INTERFACES,
38 check_optional_relations,
39+ restart_on_change,
40 )
41
42 from charmhelpers.payload.execd import execd_preinstall
43@@ -158,7 +159,8 @@
44 @hooks.hook('upgrade-charm',
45 'config-changed')
46 @restart_on_change({'/etc/ceph/ceph.conf': ['radosgw'],
47- '/etc/haproxy/haproxy.cfg': ['haproxy']})
48+ '/etc/haproxy/haproxy.cfg': ['haproxy']},
49+ stopstart=True)
50 def config_changed():
51 install_packages()
52 CONFIGS.write_all()
53@@ -176,7 +178,8 @@
54
55 @hooks.hook('mon-relation-departed',
56 'mon-relation-changed')
57-@restart_on_change({'/etc/ceph/ceph.conf': ['radosgw']})
58+@restart_on_change({'/etc/ceph/ceph.conf': ['radosgw']},
59+ stopstart=True)
60 def mon_relation():
61 CONFIGS.write_all()
62 key = relation_get('radosgw_key')
63@@ -202,7 +205,9 @@
64
65
66 def restart():
67- subprocess.call(['service', 'radosgw', 'restart'])
68+ stop()
69+ time.sleep(5)
70+ start()
71 open_port(port=80)
72
73
74@@ -227,15 +232,16 @@
75
76
77 @hooks.hook('identity-service-relation-changed')
78-@restart_on_change({'/etc/ceph/ceph.conf': ['radosgw']})
79+@restart_on_change({'/etc/ceph/ceph.conf': ['radosgw']},
80+ stopstart=True)
81 def identity_changed():
82 CONFIGS.write_all()
83- restart()
84
85
86 @hooks.hook('cluster-relation-changed',
87 'cluster-relation-joined')
88-@restart_on_change({'/etc/haproxy/haproxy.cfg': ['haproxy']})
89+@restart_on_change({'/etc/haproxy/haproxy.cfg': ['haproxy']},
90+ stopstart=True)
91 def cluster_changed():
92 CONFIGS.write_all()
93 for r_id in relation_ids('identity-service'):
94
95=== modified file 'hooks/utils.py'
96--- hooks/utils.py 2015-10-12 10:56:01 +0000
97+++ hooks/utils.py 2015-10-22 04:50:31 +0000
98@@ -11,13 +11,15 @@
99 import os
100 import dns.resolver
101 import jinja2
102+import time
103 from copy import deepcopy
104 from collections import OrderedDict
105 from charmhelpers.core.hookenv import unit_get, relation_ids, status_get
106 from charmhelpers.contrib.openstack import context, templating
107 from charmhelpers.contrib.openstack.utils import set_os_workload_status
108 from charmhelpers.contrib.hahelpers.cluster import get_hacluster_config
109-from charmhelpers.core.host import cmp_pkgrevno
110+from charmhelpers.core.hookenv import status_set
111+from charmhelpers.core.host import cmp_pkgrevno, path_hash, service
112 from charmhelpers.fetch import filter_installed_packages
113
114 import ceph_radosgw_context
115@@ -45,6 +47,8 @@
116 }),
117 ])
118
119+SOCKET_PATH = '/var/run/ceph/ceph-client.radosgw.gateway.asok'
120+
121
122 def resource_map():
123 '''
124@@ -115,6 +119,10 @@
125
126
127 def check_optional_relations(configs):
128+ # Check if radosgw is running by verifying its socket file
129+ if not os.path.exists(SOCKET_PATH):
130+ return ("blocked",
131+ "radosgw is not running")
132 required_interfaces = {}
133 if relation_ids('ha'):
134 required_interfaces['ha'] = ['cluster']
135@@ -132,3 +140,45 @@
136 return status_get()
137 else:
138 return 'unknown', 'No optional relations'
139+
140+
141+def restart_on_change(restart_map, stopstart=False):
142+ """Restart services based on configuration files changing
143+
144+ This function is used a decorator, for example::
145+
146+ @restart_on_change({
147+ '/etc/ceph/ceph.conf': [ 'cinder-api', 'cinder-volume' ]
148+ '/etc/apache/sites-enabled/*': [ 'apache2' ]
149+ })
150+ def config_changed():
151+ pass # your code here
152+
153+ In this example, the cinder-api and cinder-volume services
154+ would be restarted if /etc/ceph/ceph.conf is changed by the
155+ ceph_client_changed function. The apache2 service would be
156+ restarted if any file matching the pattern got changed, created
157+ or removed. Standard wildcards are supported, see documentation
158+ for the 'glob' module for more information.
159+ """
160+ def wrap(f):
161+ def wrapped_f(*args, **kwargs):
162+ checksums = {path: path_hash(path) for path in restart_map}
163+ f(*args, **kwargs)
164+ restarts = []
165+ for path in restart_map:
166+ if path_hash(path) != checksums[path]:
167+ restarts += restart_map[path]
168+ services_list = list(OrderedDict.fromkeys(restarts))
169+ if not stopstart:
170+ for service_name in services_list:
171+ service('restart', service_name)
172+ else:
173+ for action in ['stop', 'start']:
174+ for service_name in services_list:
175+ status_set("maintenance", "{}ing {}"
176+ "".format(action, service_name))
177+ service(action, service_name)
178+ time.sleep(5)
179+ return wrapped_f
180+ return wrap
181
182=== modified file 'unit_tests/test_hooks.py'
183--- unit_tests/test_hooks.py 2015-10-08 13:17:51 +0000
184+++ unit_tests/test_hooks.py 2015-10-22 04:50:31 +0000
185@@ -218,8 +218,11 @@
186
187 def test_restart(self):
188 ceph_hooks.restart()
189- cmd = ['service', 'radosgw', 'restart']
190- self.subprocess.call.assert_called_with(cmd)
191+ start = ['service', 'radosgw', 'stop']
192+ stop = ['service', 'radosgw', 'start']
193+ self.subprocess.call.assert_any_call(start)
194+ self.subprocess.call.assert_any_call(stop)
195+ assert 2 == self.subprocess.call.call_count
196
197 @patch('charmhelpers.contrib.openstack.ip.service_name',
198 lambda *args: 'ceph-radosgw')

Subscribers

People subscribed via source and target branches