Merge lp:~adam-collard/charms/trusty/swift-proxy/guard-paused-unit-service-restarts into lp:~openstack-charmers-archive/charms/trusty/swift-proxy/next

Proposed by Adam Collard
Status: Merged
Merged at revision: 110
Proposed branch: lp:~adam-collard/charms/trusty/swift-proxy/guard-paused-unit-service-restarts
Merge into: lp:~openstack-charmers-archive/charms/trusty/swift-proxy/next
Prerequisite: lp:~adam-collard/charms/trusty/swift-proxy/add-pause-resume-actions
Diff against target: 214 lines (+83/-15)
4 files modified
hooks/swift_hooks.py (+19/-14)
lib/swift_utils.py (+19/-1)
tests/basic_deployment.py (+33/-0)
unit_tests/test_swift_utils.py (+12/-0)
To merge this branch: bzr merge lp:~adam-collard/charms/trusty/swift-proxy/guard-paused-unit-service-restarts
Reviewer Review Type Date Requested Status
Chris Glass (community) Approve
Geoff Teale (community) Approve
Review via email: mp+270641@code.launchpad.net

Description of the change

This is a follow up branch to https://code.launchpad.net/~adam-collard/charms/trusty/swift-proxy/add-pause-resume-actions/+merge/270407 to prevent config-changed and other hooks from blindly (re)starting services when the unit is paused.

Normal flow is pause(), (optionally) change config -> changes should be persisted on disk, but nothing started. resume() -> services started.

It's a mirror of https://code.launchpad.net/~adam-collard/charms/trusty/swift-storage/guard-paused-unit-service-restarts/+merge/269860

To post a comment you must log in.
114. By Adam Collard

Back out accidental commit of pointer to tealeg's charm-helpers branch

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

charm_lint_check #9702 swift-proxy-next for adam-collard mp270641
    LINT FAIL: lint-test failed
    LINT FAIL: charm-proof failed

LINT Results (max last 2 lines):
make: *** [lint] Error 100
ERROR:root:Make target returned non-zero.

Full lint test output: http://paste.ubuntu.com/12328231/
Build: http://10.245.162.77:8080/job/charm_lint_check/9702/

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

charm_unit_test #8938 swift-proxy-next for adam-collard mp270641
    UNIT OK: passed

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

115. By Adam Collard

Merge from ../add-pause-resume-actions/

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

charm_lint_check #9716 swift-proxy-next for adam-collard mp270641
    LINT OK: passed

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

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

charm_unit_test #8947 swift-proxy-next for adam-collard mp270641
    UNIT OK: passed

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

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

charm_amulet_test #6342 swift-proxy-next for adam-collard mp270641
    AMULET OK: passed

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

Revision history for this message
Geoff Teale (tealeg) wrote :

+1

review: Approve
Revision history for this message
Chris Glass (tribaal) wrote :

+1, Merged.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/swift_hooks.py'
2--- hooks/swift_hooks.py 2015-09-07 13:44:04 +0000
3+++ hooks/swift_hooks.py 2015-09-10 14:15:17 +0000
4@@ -32,6 +32,8 @@
5 get_first_available_value,
6 all_responses_equal,
7 ensure_www_dir_permissions,
8+ is_paused,
9+ pause_aware_restart_on_change
10 )
11
12 import charmhelpers.contrib.openstack.utils as openstack
13@@ -60,7 +62,6 @@
14 service_restart,
15 service_stop,
16 service_start,
17- restart_on_change,
18 )
19 from charmhelpers.fetch import (
20 apt_install,
21@@ -121,7 +122,7 @@
22
23
24 @hooks.hook('config-changed')
25-@restart_on_change(restart_map())
26+@pause_aware_restart_on_change(restart_map())
27 def config_changed():
28 if config('prefer-ipv6'):
29 setup_ipv6()
30@@ -161,7 +162,7 @@
31
32
33 @hooks.hook('identity-service-relation-changed')
34-@restart_on_change(restart_map())
35+@pause_aware_restart_on_change(restart_map())
36 def keystone_changed():
37 configure_https()
38
39@@ -181,7 +182,7 @@
40
41
42 @hooks.hook('swift-storage-relation-changed')
43-@restart_on_change(restart_map())
44+@pause_aware_restart_on_change(restart_map())
45 def storage_changed():
46 """Storage relation.
47
48@@ -231,13 +232,14 @@
49 node_settings['devices'] = devs.split(':')
50
51 update_rings(node_settings)
52- # Restart proxy here in case no config changes made (so
53- # restart_on_change() ineffective).
54- service_restart('swift-proxy')
55+ if not is_paused():
56+ # Restart proxy here in case no config changes made (so
57+ # pause_aware_restart_on_change() ineffective).
58+ service_restart('swift-proxy')
59
60
61 @hooks.hook('swift-storage-relation-broken')
62-@restart_on_change(restart_map())
63+@pause_aware_restart_on_change(restart_map())
64 def storage_broken():
65 CONFIGS.write_all()
66
67@@ -358,7 +360,8 @@
68 broker = settings.get('builder-broker', None)
69 if not broker:
70 log("No update available", level=DEBUG)
71- service_start('swift-proxy')
72+ if not is_paused():
73+ service_start('swift-proxy')
74 return
75
76 builders_only = int(settings.get('sync-only-builders', 0))
77@@ -375,14 +378,15 @@
78 if fully_synced():
79 log("Ring builders synced - starting proxy", level=INFO)
80 CONFIGS.write_all()
81- service_start('swift-proxy')
82+ if not is_paused():
83+ service_start('swift-proxy')
84 else:
85 log("Not all builders and rings synced yet - waiting for peer sync "
86 "before starting proxy", level=INFO)
87
88
89 @hooks.hook('cluster-relation-changed')
90-@restart_on_change(restart_map())
91+@pause_aware_restart_on_change(restart_map())
92 def cluster_changed():
93 key = SwiftProxyClusterRPC.KEY_NOTIFY_LEADER_CHANGED
94 leader_changed = relation_get(attribute=key)
95@@ -481,9 +485,10 @@
96 if os.path.exists('/usr/sbin/a2enconf'):
97 check_call(['a2enconf', 'swift-rings'])
98
99- # TODO: improve this by checking if local CN certs are available
100- # first then checking reload status (see LP #1433114).
101- service_reload('apache2', restart_on_failure=True)
102+ if not is_paused():
103+ # TODO: improve this by checking if local CN certs are available
104+ # first then checking reload status (see LP #1433114).
105+ service_reload('apache2', restart_on_failure=True)
106
107 for rid in relation_ids('identity-service'):
108 keystone_joined(relid=rid)
109
110=== modified file 'lib/swift_utils.py'
111--- lib/swift_utils.py 2015-09-07 13:44:04 +0000
112+++ lib/swift_utils.py 2015-09-10 14:15:17 +0000
113@@ -42,6 +42,7 @@
114 relation_set,
115 relation_ids,
116 related_units,
117+ status_get
118 )
119 from charmhelpers.fetch import (
120 apt_update,
121@@ -50,7 +51,8 @@
122 add_source
123 )
124 from charmhelpers.core.host import (
125- lsb_release
126+ lsb_release,
127+ restart_on_change,
128 )
129 from charmhelpers.contrib.network.ip import (
130 format_ipv6_addr,
131@@ -994,3 +996,19 @@
132 return get_ipv6_addr(exc_list=[config('vip')])[0]
133
134 return unit_get('private-address')
135+
136+
137+def is_paused(status_get=status_get):
138+ """Is the unit paused?"""
139+ status, message = status_get()
140+ return status == "maintenance" and message.startswith("Paused")
141+
142+
143+def pause_aware_restart_on_change(restart_map):
144+ """Avoids restarting services if config changes when unit is paused."""
145+ def wrapper(f):
146+ if is_paused():
147+ return f
148+ else:
149+ return restart_on_change(restart_map)(f)
150+ return wrapper
151
152=== modified file 'tests/basic_deployment.py'
153--- tests/basic_deployment.py 2015-09-10 14:15:17 +0000
154+++ tests/basic_deployment.py 2015-09-10 14:15:17 +0000
155@@ -333,6 +333,39 @@
156
157 self.d.configure('swift-proxy', {'node-timeout': '60'})
158
159+ def test_z_no_restart_on_config_change_when_paused(self):
160+ """Verify that the specified services are not restarted when the config
161+ is changed and the unit is paused."""
162+ u.log.info('Checking that system services do not get restarted '
163+ 'when charm config changes but unit is paused...')
164+ sentry = self.swift_proxy_sentry
165+ juju_service = 'swift-proxy'
166+
167+ # Expected default and alternate values
168+ set_default = {'node-timeout': '60'}
169+ set_alternate = {'node-timeout': '90'}
170+
171+ services = ['swift-proxy', 'haproxy', 'apache2', 'memcached']
172+
173+ # Pause the unit
174+ u.log.debug('Pausing the unit...')
175+ pause_action_id = u.run_action(sentry, "pause")
176+ assert u.wait_on_action(pause_action_id), "Resume action failed."
177+ # Make config change, check for service restarts
178+ u.log.debug('Making config change on {}...'.format(juju_service))
179+ self.d.configure(juju_service, set_alternate)
180+
181+ for service in services:
182+ u.log.debug("Checking that service didn't start while "
183+ "paused: {}".format(service))
184+ # No explicit assert because get_process_id_list will do it for us
185+ u.get_process_id_list(
186+ sentry, service, expect_success=False)
187+
188+ self.d.configure(juju_service, set_default)
189+ resume_action_id = u.run_action(sentry, "resume")
190+ assert u.wait_on_action(resume_action_id), "Resume action failed."
191+
192 def _assert_services(self, should_run):
193 swift_proxy_services = ['swift-proxy-server',
194 'haproxy',
195
196=== modified file 'unit_tests/test_swift_utils.py'
197--- unit_tests/test_swift_utils.py 2015-09-07 13:44:04 +0000
198+++ unit_tests/test_swift_utils.py 2015-09-10 14:15:17 +0000
199@@ -222,3 +222,15 @@
200
201 rsps = []
202 self.assertIsNone(swift_utils.get_first_available_value(rsps, 'key3'))
203+
204+ def test_is_paused_unknown(self):
205+ fake_status_get = lambda: ("unknown", "")
206+ self.assertFalse(swift_utils.is_paused(status_get=fake_status_get))
207+
208+ def test_is_paused_paused(self):
209+ fake_status_get = lambda: ("maintenance", "Paused")
210+ self.assertTrue(swift_utils.is_paused(status_get=fake_status_get))
211+
212+ def test_is_paused_other_maintenance(self):
213+ fake_status_get = lambda: ("maintenance", "Hook")
214+ self.assertFalse(swift_utils.is_paused(status_get=fake_status_get))

Subscribers

People subscribed via source and target branches