Merge lp:~lazypower/charms/trusty/elasticsearch/amulet-test-bump into lp:charms/trusty/elasticsearch
- Trusty Tahr (14.04)
- amulet-test-bump
- Merge into trunk
Status: | Needs review |
---|---|
Proposed branch: | lp:~lazypower/charms/trusty/elasticsearch/amulet-test-bump |
Merge into: | lp:charms/trusty/elasticsearch |
Diff against target: |
1889 lines (+1618/-139) 22 files modified
hooks/client-relation-departed (+100/-0) hooks/client-relation-joined (+100/-0) hooks/config-changed (+100/-0) hooks/data-relation-changed (+100/-0) hooks/data-relation-departed (+100/-0) hooks/data-relation-joined (+100/-0) hooks/hooks.py (+4/-3) hooks/install (+100/-0) hooks/logs-relation-joined (+100/-0) hooks/nrpe-external-master-relation-changed (+100/-0) hooks/peer-relation-changed (+100/-0) hooks/peer-relation-departed (+100/-0) hooks/peer-relation-joined (+100/-0) hooks/start (+100/-0) hooks/stop (+100/-0) hooks/upgrade-charm (+100/-0) tests/00-create-index (+0/-32) tests/00-single-to-scale-test.py (+112/-0) tests/01-config-changes (+0/-22) tests/02-deploy-three-units (+0/-18) tests/helpers/__init__.py (+0/-64) tests/tests.yaml (+2/-0) |
To merge this branch: | bzr merge lp:~lazypower/charms/trusty/elasticsearch/amulet-test-bump |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Chris Glass (community) | Approve | ||
Review via email: mp+293703@code.launchpad.net |
Commit message
Description of the change
Refactors the tests into a single amulet class
Slight refactoring of the test helper modules inline
elasticsearch
charm-proof PASS
make lint PASS
make test PASS
00-
Bundletester seems to like this branch, it passes cleanly on AWS and OpenStack. I have not tested if this has changed the results on GCE failures.
This branch also properly marks hooks as chmod +x instead of relying on Juju to do this for us.
Unmerged revisions
- 43. By Charles Butler
-
- Merged tests into a single amulet TestClass
- Refactored the tests due to consistent failures when testing on GCE
- minor lint cleanups
Preview Diff
1 | === modified symlink 'hooks/client-relation-departed' (properties changed: -x to +x) | |||
2 | === target was u'hooks.py' | |||
3 | --- hooks/client-relation-departed 1970-01-01 00:00:00 +0000 | |||
4 | +++ hooks/client-relation-departed 2016-05-04 03:14:14 +0000 | |||
5 | @@ -0,0 +1,100 @@ | |||
6 | 1 | #!/usr/bin/env python | ||
7 | 2 | """Setup hooks for the elasticsearch charm.""" | ||
8 | 3 | |||
9 | 4 | import sys | ||
10 | 5 | import charmhelpers.contrib.ansible | ||
11 | 6 | import charmhelpers.payload.execd | ||
12 | 7 | import charmhelpers.core.host | ||
13 | 8 | from charmhelpers.core import hookenv | ||
14 | 9 | import os | ||
15 | 10 | import shutil | ||
16 | 11 | |||
17 | 12 | mountpoint = '/srv/elasticsearch' | ||
18 | 13 | |||
19 | 14 | hooks = charmhelpers.contrib.ansible.AnsibleHooks( | ||
20 | 15 | playbook_path='playbook.yaml', | ||
21 | 16 | default_hooks=[ | ||
22 | 17 | 'config-changed', | ||
23 | 18 | 'cluster-relation-joined', | ||
24 | 19 | 'logs-relation-joined', | ||
25 | 20 | 'data-relation-joined', | ||
26 | 21 | 'data-relation-changed', | ||
27 | 22 | 'data-relation-departed', | ||
28 | 23 | 'data-relation-broken', | ||
29 | 24 | 'peer-relation-joined', | ||
30 | 25 | 'peer-relation-changed', | ||
31 | 26 | 'peer-relation-departed', | ||
32 | 27 | 'nrpe-external-master-relation-changed', | ||
33 | 28 | 'rest-relation-joined', | ||
34 | 29 | 'start', | ||
35 | 30 | 'stop', | ||
36 | 31 | 'upgrade-charm', | ||
37 | 32 | 'client-relation-joined', | ||
38 | 33 | 'client-relation-departed', | ||
39 | 34 | ]) | ||
40 | 35 | |||
41 | 36 | |||
42 | 37 | @hooks.hook('install', 'upgrade-charm') | ||
43 | 38 | def install(): | ||
44 | 39 | """Install ansible before running the tasks tagged with 'install'.""" | ||
45 | 40 | # Allow charm users to run preinstall setup. | ||
46 | 41 | charmhelpers.payload.execd.execd_preinstall() | ||
47 | 42 | charmhelpers.contrib.ansible.install_ansible_support( | ||
48 | 43 | from_ppa=False) | ||
49 | 44 | |||
50 | 45 | # We copy the backported ansible modules here because they need to be | ||
51 | 46 | # in place by the time ansible runs any hook. | ||
52 | 47 | charmhelpers.core.host.rsync( | ||
53 | 48 | 'ansible_module_backports', | ||
54 | 49 | '/usr/share/ansible') | ||
55 | 50 | |||
56 | 51 | |||
57 | 52 | @hooks.hook('data-relation-joined', 'data-relation-changed') | ||
58 | 53 | def data_relation(): | ||
59 | 54 | if hookenv.relation_get('mountpoint') == mountpoint: | ||
60 | 55 | # Other side of relation is ready | ||
61 | 56 | migrate_to_mount(mountpoint) | ||
62 | 57 | else: | ||
63 | 58 | # Other side not ready yet, provide mountpoint | ||
64 | 59 | hookenv.log('Requesting storage for {}'.format(mountpoint)) | ||
65 | 60 | hookenv.relation_set(mountpoint=mountpoint) | ||
66 | 61 | |||
67 | 62 | |||
68 | 63 | @hooks.hook('data-relation-departed', 'data-relation-broken') | ||
69 | 64 | def data_relation_gone(): | ||
70 | 65 | hookenv.log('Data relation no longer present, stopping elasticsearch.') | ||
71 | 66 | charmhelpers.core.host.service_stop('elasticsearch') | ||
72 | 67 | |||
73 | 68 | |||
74 | 69 | def migrate_to_mount(new_path): | ||
75 | 70 | """Invoked when new mountpoint appears. This function safely migrates | ||
76 | 71 | elasticsearch data from local disk to persistent storage (only if needed) | ||
77 | 72 | """ | ||
78 | 73 | old_path = '/var/lib/elasticsearch' | ||
79 | 74 | if os.path.islink(old_path): | ||
80 | 75 | hookenv.log('{} is already a symlink, skipping migration'.format( | ||
81 | 76 | old_path)) | ||
82 | 77 | return True | ||
83 | 78 | # Ensure our new mountpoint is empty. Otherwise error and allow | ||
84 | 79 | # users to investigate and migrate manually | ||
85 | 80 | files = os.listdir(new_path) | ||
86 | 81 | try: | ||
87 | 82 | files.remove('lost+found') | ||
88 | 83 | except ValueError: | ||
89 | 84 | pass | ||
90 | 85 | if files: | ||
91 | 86 | raise RuntimeError('Persistent storage contains old data. ' | ||
92 | 87 | 'Please investigate and migrate data manually ' | ||
93 | 88 | 'to: {}'.format(new_path)) | ||
94 | 89 | os.chmod(new_path, 0700) | ||
95 | 90 | charmhelpers.core.host.service_stop('elasticsearch') | ||
96 | 91 | charmhelpers.core.host.rsync(os.path.join(old_path, ''), # Ensure we have trailing slashes | ||
97 | 92 | os.path.join(new_path, ''), | ||
98 | 93 | options=['--archive']) | ||
99 | 94 | shutil.rmtree(old_path) | ||
100 | 95 | os.symlink(new_path, old_path) | ||
101 | 96 | charmhelpers.core.host.service_start('elasticsearch') | ||
102 | 97 | |||
103 | 98 | |||
104 | 99 | if __name__ == "__main__": | ||
105 | 100 | hooks.execute(sys.argv) | ||
106 | 0 | 101 | ||
107 | === modified symlink 'hooks/client-relation-joined' (properties changed: -x to +x) | |||
108 | === target was u'hooks.py' | |||
109 | --- hooks/client-relation-joined 1970-01-01 00:00:00 +0000 | |||
110 | +++ hooks/client-relation-joined 2016-05-04 03:14:14 +0000 | |||
111 | @@ -0,0 +1,100 @@ | |||
112 | 1 | #!/usr/bin/env python | ||
113 | 2 | """Setup hooks for the elasticsearch charm.""" | ||
114 | 3 | |||
115 | 4 | import sys | ||
116 | 5 | import charmhelpers.contrib.ansible | ||
117 | 6 | import charmhelpers.payload.execd | ||
118 | 7 | import charmhelpers.core.host | ||
119 | 8 | from charmhelpers.core import hookenv | ||
120 | 9 | import os | ||
121 | 10 | import shutil | ||
122 | 11 | |||
123 | 12 | mountpoint = '/srv/elasticsearch' | ||
124 | 13 | |||
125 | 14 | hooks = charmhelpers.contrib.ansible.AnsibleHooks( | ||
126 | 15 | playbook_path='playbook.yaml', | ||
127 | 16 | default_hooks=[ | ||
128 | 17 | 'config-changed', | ||
129 | 18 | 'cluster-relation-joined', | ||
130 | 19 | 'logs-relation-joined', | ||
131 | 20 | 'data-relation-joined', | ||
132 | 21 | 'data-relation-changed', | ||
133 | 22 | 'data-relation-departed', | ||
134 | 23 | 'data-relation-broken', | ||
135 | 24 | 'peer-relation-joined', | ||
136 | 25 | 'peer-relation-changed', | ||
137 | 26 | 'peer-relation-departed', | ||
138 | 27 | 'nrpe-external-master-relation-changed', | ||
139 | 28 | 'rest-relation-joined', | ||
140 | 29 | 'start', | ||
141 | 30 | 'stop', | ||
142 | 31 | 'upgrade-charm', | ||
143 | 32 | 'client-relation-joined', | ||
144 | 33 | 'client-relation-departed', | ||
145 | 34 | ]) | ||
146 | 35 | |||
147 | 36 | |||
148 | 37 | @hooks.hook('install', 'upgrade-charm') | ||
149 | 38 | def install(): | ||
150 | 39 | """Install ansible before running the tasks tagged with 'install'.""" | ||
151 | 40 | # Allow charm users to run preinstall setup. | ||
152 | 41 | charmhelpers.payload.execd.execd_preinstall() | ||
153 | 42 | charmhelpers.contrib.ansible.install_ansible_support( | ||
154 | 43 | from_ppa=False) | ||
155 | 44 | |||
156 | 45 | # We copy the backported ansible modules here because they need to be | ||
157 | 46 | # in place by the time ansible runs any hook. | ||
158 | 47 | charmhelpers.core.host.rsync( | ||
159 | 48 | 'ansible_module_backports', | ||
160 | 49 | '/usr/share/ansible') | ||
161 | 50 | |||
162 | 51 | |||
163 | 52 | @hooks.hook('data-relation-joined', 'data-relation-changed') | ||
164 | 53 | def data_relation(): | ||
165 | 54 | if hookenv.relation_get('mountpoint') == mountpoint: | ||
166 | 55 | # Other side of relation is ready | ||
167 | 56 | migrate_to_mount(mountpoint) | ||
168 | 57 | else: | ||
169 | 58 | # Other side not ready yet, provide mountpoint | ||
170 | 59 | hookenv.log('Requesting storage for {}'.format(mountpoint)) | ||
171 | 60 | hookenv.relation_set(mountpoint=mountpoint) | ||
172 | 61 | |||
173 | 62 | |||
174 | 63 | @hooks.hook('data-relation-departed', 'data-relation-broken') | ||
175 | 64 | def data_relation_gone(): | ||
176 | 65 | hookenv.log('Data relation no longer present, stopping elasticsearch.') | ||
177 | 66 | charmhelpers.core.host.service_stop('elasticsearch') | ||
178 | 67 | |||
179 | 68 | |||
180 | 69 | def migrate_to_mount(new_path): | ||
181 | 70 | """Invoked when new mountpoint appears. This function safely migrates | ||
182 | 71 | elasticsearch data from local disk to persistent storage (only if needed) | ||
183 | 72 | """ | ||
184 | 73 | old_path = '/var/lib/elasticsearch' | ||
185 | 74 | if os.path.islink(old_path): | ||
186 | 75 | hookenv.log('{} is already a symlink, skipping migration'.format( | ||
187 | 76 | old_path)) | ||
188 | 77 | return True | ||
189 | 78 | # Ensure our new mountpoint is empty. Otherwise error and allow | ||
190 | 79 | # users to investigate and migrate manually | ||
191 | 80 | files = os.listdir(new_path) | ||
192 | 81 | try: | ||
193 | 82 | files.remove('lost+found') | ||
194 | 83 | except ValueError: | ||
195 | 84 | pass | ||
196 | 85 | if files: | ||
197 | 86 | raise RuntimeError('Persistent storage contains old data. ' | ||
198 | 87 | 'Please investigate and migrate data manually ' | ||
199 | 88 | 'to: {}'.format(new_path)) | ||
200 | 89 | os.chmod(new_path, 0700) | ||
201 | 90 | charmhelpers.core.host.service_stop('elasticsearch') | ||
202 | 91 | charmhelpers.core.host.rsync(os.path.join(old_path, ''), # Ensure we have trailing slashes | ||
203 | 92 | os.path.join(new_path, ''), | ||
204 | 93 | options=['--archive']) | ||
205 | 94 | shutil.rmtree(old_path) | ||
206 | 95 | os.symlink(new_path, old_path) | ||
207 | 96 | charmhelpers.core.host.service_start('elasticsearch') | ||
208 | 97 | |||
209 | 98 | |||
210 | 99 | if __name__ == "__main__": | ||
211 | 100 | hooks.execute(sys.argv) | ||
212 | 0 | 101 | ||
213 | === modified symlink 'hooks/config-changed' (properties changed: -x to +x) | |||
214 | === target was u'hooks.py' | |||
215 | --- hooks/config-changed 1970-01-01 00:00:00 +0000 | |||
216 | +++ hooks/config-changed 2016-05-04 03:14:14 +0000 | |||
217 | @@ -0,0 +1,100 @@ | |||
218 | 1 | #!/usr/bin/env python | ||
219 | 2 | """Setup hooks for the elasticsearch charm.""" | ||
220 | 3 | |||
221 | 4 | import sys | ||
222 | 5 | import charmhelpers.contrib.ansible | ||
223 | 6 | import charmhelpers.payload.execd | ||
224 | 7 | import charmhelpers.core.host | ||
225 | 8 | from charmhelpers.core import hookenv | ||
226 | 9 | import os | ||
227 | 10 | import shutil | ||
228 | 11 | |||
229 | 12 | mountpoint = '/srv/elasticsearch' | ||
230 | 13 | |||
231 | 14 | hooks = charmhelpers.contrib.ansible.AnsibleHooks( | ||
232 | 15 | playbook_path='playbook.yaml', | ||
233 | 16 | default_hooks=[ | ||
234 | 17 | 'config-changed', | ||
235 | 18 | 'cluster-relation-joined', | ||
236 | 19 | 'logs-relation-joined', | ||
237 | 20 | 'data-relation-joined', | ||
238 | 21 | 'data-relation-changed', | ||
239 | 22 | 'data-relation-departed', | ||
240 | 23 | 'data-relation-broken', | ||
241 | 24 | 'peer-relation-joined', | ||
242 | 25 | 'peer-relation-changed', | ||
243 | 26 | 'peer-relation-departed', | ||
244 | 27 | 'nrpe-external-master-relation-changed', | ||
245 | 28 | 'rest-relation-joined', | ||
246 | 29 | 'start', | ||
247 | 30 | 'stop', | ||
248 | 31 | 'upgrade-charm', | ||
249 | 32 | 'client-relation-joined', | ||
250 | 33 | 'client-relation-departed', | ||
251 | 34 | ]) | ||
252 | 35 | |||
253 | 36 | |||
254 | 37 | @hooks.hook('install', 'upgrade-charm') | ||
255 | 38 | def install(): | ||
256 | 39 | """Install ansible before running the tasks tagged with 'install'.""" | ||
257 | 40 | # Allow charm users to run preinstall setup. | ||
258 | 41 | charmhelpers.payload.execd.execd_preinstall() | ||
259 | 42 | charmhelpers.contrib.ansible.install_ansible_support( | ||
260 | 43 | from_ppa=False) | ||
261 | 44 | |||
262 | 45 | # We copy the backported ansible modules here because they need to be | ||
263 | 46 | # in place by the time ansible runs any hook. | ||
264 | 47 | charmhelpers.core.host.rsync( | ||
265 | 48 | 'ansible_module_backports', | ||
266 | 49 | '/usr/share/ansible') | ||
267 | 50 | |||
268 | 51 | |||
269 | 52 | @hooks.hook('data-relation-joined', 'data-relation-changed') | ||
270 | 53 | def data_relation(): | ||
271 | 54 | if hookenv.relation_get('mountpoint') == mountpoint: | ||
272 | 55 | # Other side of relation is ready | ||
273 | 56 | migrate_to_mount(mountpoint) | ||
274 | 57 | else: | ||
275 | 58 | # Other side not ready yet, provide mountpoint | ||
276 | 59 | hookenv.log('Requesting storage for {}'.format(mountpoint)) | ||
277 | 60 | hookenv.relation_set(mountpoint=mountpoint) | ||
278 | 61 | |||
279 | 62 | |||
280 | 63 | @hooks.hook('data-relation-departed', 'data-relation-broken') | ||
281 | 64 | def data_relation_gone(): | ||
282 | 65 | hookenv.log('Data relation no longer present, stopping elasticsearch.') | ||
283 | 66 | charmhelpers.core.host.service_stop('elasticsearch') | ||
284 | 67 | |||
285 | 68 | |||
286 | 69 | def migrate_to_mount(new_path): | ||
287 | 70 | """Invoked when new mountpoint appears. This function safely migrates | ||
288 | 71 | elasticsearch data from local disk to persistent storage (only if needed) | ||
289 | 72 | """ | ||
290 | 73 | old_path = '/var/lib/elasticsearch' | ||
291 | 74 | if os.path.islink(old_path): | ||
292 | 75 | hookenv.log('{} is already a symlink, skipping migration'.format( | ||
293 | 76 | old_path)) | ||
294 | 77 | return True | ||
295 | 78 | # Ensure our new mountpoint is empty. Otherwise error and allow | ||
296 | 79 | # users to investigate and migrate manually | ||
297 | 80 | files = os.listdir(new_path) | ||
298 | 81 | try: | ||
299 | 82 | files.remove('lost+found') | ||
300 | 83 | except ValueError: | ||
301 | 84 | pass | ||
302 | 85 | if files: | ||
303 | 86 | raise RuntimeError('Persistent storage contains old data. ' | ||
304 | 87 | 'Please investigate and migrate data manually ' | ||
305 | 88 | 'to: {}'.format(new_path)) | ||
306 | 89 | os.chmod(new_path, 0700) | ||
307 | 90 | charmhelpers.core.host.service_stop('elasticsearch') | ||
308 | 91 | charmhelpers.core.host.rsync(os.path.join(old_path, ''), # Ensure we have trailing slashes | ||
309 | 92 | os.path.join(new_path, ''), | ||
310 | 93 | options=['--archive']) | ||
311 | 94 | shutil.rmtree(old_path) | ||
312 | 95 | os.symlink(new_path, old_path) | ||
313 | 96 | charmhelpers.core.host.service_start('elasticsearch') | ||
314 | 97 | |||
315 | 98 | |||
316 | 99 | if __name__ == "__main__": | ||
317 | 100 | hooks.execute(sys.argv) | ||
318 | 0 | 101 | ||
319 | === modified symlink 'hooks/data-relation-changed' (properties changed: -x to +x) | |||
320 | === target was u'hooks.py' | |||
321 | --- hooks/data-relation-changed 1970-01-01 00:00:00 +0000 | |||
322 | +++ hooks/data-relation-changed 2016-05-04 03:14:14 +0000 | |||
323 | @@ -0,0 +1,100 @@ | |||
324 | 1 | #!/usr/bin/env python | ||
325 | 2 | """Setup hooks for the elasticsearch charm.""" | ||
326 | 3 | |||
327 | 4 | import sys | ||
328 | 5 | import charmhelpers.contrib.ansible | ||
329 | 6 | import charmhelpers.payload.execd | ||
330 | 7 | import charmhelpers.core.host | ||
331 | 8 | from charmhelpers.core import hookenv | ||
332 | 9 | import os | ||
333 | 10 | import shutil | ||
334 | 11 | |||
335 | 12 | mountpoint = '/srv/elasticsearch' | ||
336 | 13 | |||
337 | 14 | hooks = charmhelpers.contrib.ansible.AnsibleHooks( | ||
338 | 15 | playbook_path='playbook.yaml', | ||
339 | 16 | default_hooks=[ | ||
340 | 17 | 'config-changed', | ||
341 | 18 | 'cluster-relation-joined', | ||
342 | 19 | 'logs-relation-joined', | ||
343 | 20 | 'data-relation-joined', | ||
344 | 21 | 'data-relation-changed', | ||
345 | 22 | 'data-relation-departed', | ||
346 | 23 | 'data-relation-broken', | ||
347 | 24 | 'peer-relation-joined', | ||
348 | 25 | 'peer-relation-changed', | ||
349 | 26 | 'peer-relation-departed', | ||
350 | 27 | 'nrpe-external-master-relation-changed', | ||
351 | 28 | 'rest-relation-joined', | ||
352 | 29 | 'start', | ||
353 | 30 | 'stop', | ||
354 | 31 | 'upgrade-charm', | ||
355 | 32 | 'client-relation-joined', | ||
356 | 33 | 'client-relation-departed', | ||
357 | 34 | ]) | ||
358 | 35 | |||
359 | 36 | |||
360 | 37 | @hooks.hook('install', 'upgrade-charm') | ||
361 | 38 | def install(): | ||
362 | 39 | """Install ansible before running the tasks tagged with 'install'.""" | ||
363 | 40 | # Allow charm users to run preinstall setup. | ||
364 | 41 | charmhelpers.payload.execd.execd_preinstall() | ||
365 | 42 | charmhelpers.contrib.ansible.install_ansible_support( | ||
366 | 43 | from_ppa=False) | ||
367 | 44 | |||
368 | 45 | # We copy the backported ansible modules here because they need to be | ||
369 | 46 | # in place by the time ansible runs any hook. | ||
370 | 47 | charmhelpers.core.host.rsync( | ||
371 | 48 | 'ansible_module_backports', | ||
372 | 49 | '/usr/share/ansible') | ||
373 | 50 | |||
374 | 51 | |||
375 | 52 | @hooks.hook('data-relation-joined', 'data-relation-changed') | ||
376 | 53 | def data_relation(): | ||
377 | 54 | if hookenv.relation_get('mountpoint') == mountpoint: | ||
378 | 55 | # Other side of relation is ready | ||
379 | 56 | migrate_to_mount(mountpoint) | ||
380 | 57 | else: | ||
381 | 58 | # Other side not ready yet, provide mountpoint | ||
382 | 59 | hookenv.log('Requesting storage for {}'.format(mountpoint)) | ||
383 | 60 | hookenv.relation_set(mountpoint=mountpoint) | ||
384 | 61 | |||
385 | 62 | |||
386 | 63 | @hooks.hook('data-relation-departed', 'data-relation-broken') | ||
387 | 64 | def data_relation_gone(): | ||
388 | 65 | hookenv.log('Data relation no longer present, stopping elasticsearch.') | ||
389 | 66 | charmhelpers.core.host.service_stop('elasticsearch') | ||
390 | 67 | |||
391 | 68 | |||
392 | 69 | def migrate_to_mount(new_path): | ||
393 | 70 | """Invoked when new mountpoint appears. This function safely migrates | ||
394 | 71 | elasticsearch data from local disk to persistent storage (only if needed) | ||
395 | 72 | """ | ||
396 | 73 | old_path = '/var/lib/elasticsearch' | ||
397 | 74 | if os.path.islink(old_path): | ||
398 | 75 | hookenv.log('{} is already a symlink, skipping migration'.format( | ||
399 | 76 | old_path)) | ||
400 | 77 | return True | ||
401 | 78 | # Ensure our new mountpoint is empty. Otherwise error and allow | ||
402 | 79 | # users to investigate and migrate manually | ||
403 | 80 | files = os.listdir(new_path) | ||
404 | 81 | try: | ||
405 | 82 | files.remove('lost+found') | ||
406 | 83 | except ValueError: | ||
407 | 84 | pass | ||
408 | 85 | if files: | ||
409 | 86 | raise RuntimeError('Persistent storage contains old data. ' | ||
410 | 87 | 'Please investigate and migrate data manually ' | ||
411 | 88 | 'to: {}'.format(new_path)) | ||
412 | 89 | os.chmod(new_path, 0700) | ||
413 | 90 | charmhelpers.core.host.service_stop('elasticsearch') | ||
414 | 91 | charmhelpers.core.host.rsync(os.path.join(old_path, ''), # Ensure we have trailing slashes | ||
415 | 92 | os.path.join(new_path, ''), | ||
416 | 93 | options=['--archive']) | ||
417 | 94 | shutil.rmtree(old_path) | ||
418 | 95 | os.symlink(new_path, old_path) | ||
419 | 96 | charmhelpers.core.host.service_start('elasticsearch') | ||
420 | 97 | |||
421 | 98 | |||
422 | 99 | if __name__ == "__main__": | ||
423 | 100 | hooks.execute(sys.argv) | ||
424 | 0 | 101 | ||
425 | === modified symlink 'hooks/data-relation-departed' (properties changed: -x to +x) | |||
426 | === target was u'hooks.py' | |||
427 | --- hooks/data-relation-departed 1970-01-01 00:00:00 +0000 | |||
428 | +++ hooks/data-relation-departed 2016-05-04 03:14:14 +0000 | |||
429 | @@ -0,0 +1,100 @@ | |||
430 | 1 | #!/usr/bin/env python | ||
431 | 2 | """Setup hooks for the elasticsearch charm.""" | ||
432 | 3 | |||
433 | 4 | import sys | ||
434 | 5 | import charmhelpers.contrib.ansible | ||
435 | 6 | import charmhelpers.payload.execd | ||
436 | 7 | import charmhelpers.core.host | ||
437 | 8 | from charmhelpers.core import hookenv | ||
438 | 9 | import os | ||
439 | 10 | import shutil | ||
440 | 11 | |||
441 | 12 | mountpoint = '/srv/elasticsearch' | ||
442 | 13 | |||
443 | 14 | hooks = charmhelpers.contrib.ansible.AnsibleHooks( | ||
444 | 15 | playbook_path='playbook.yaml', | ||
445 | 16 | default_hooks=[ | ||
446 | 17 | 'config-changed', | ||
447 | 18 | 'cluster-relation-joined', | ||
448 | 19 | 'logs-relation-joined', | ||
449 | 20 | 'data-relation-joined', | ||
450 | 21 | 'data-relation-changed', | ||
451 | 22 | 'data-relation-departed', | ||
452 | 23 | 'data-relation-broken', | ||
453 | 24 | 'peer-relation-joined', | ||
454 | 25 | 'peer-relation-changed', | ||
455 | 26 | 'peer-relation-departed', | ||
456 | 27 | 'nrpe-external-master-relation-changed', | ||
457 | 28 | 'rest-relation-joined', | ||
458 | 29 | 'start', | ||
459 | 30 | 'stop', | ||
460 | 31 | 'upgrade-charm', | ||
461 | 32 | 'client-relation-joined', | ||
462 | 33 | 'client-relation-departed', | ||
463 | 34 | ]) | ||
464 | 35 | |||
465 | 36 | |||
466 | 37 | @hooks.hook('install', 'upgrade-charm') | ||
467 | 38 | def install(): | ||
468 | 39 | """Install ansible before running the tasks tagged with 'install'.""" | ||
469 | 40 | # Allow charm users to run preinstall setup. | ||
470 | 41 | charmhelpers.payload.execd.execd_preinstall() | ||
471 | 42 | charmhelpers.contrib.ansible.install_ansible_support( | ||
472 | 43 | from_ppa=False) | ||
473 | 44 | |||
474 | 45 | # We copy the backported ansible modules here because they need to be | ||
475 | 46 | # in place by the time ansible runs any hook. | ||
476 | 47 | charmhelpers.core.host.rsync( | ||
477 | 48 | 'ansible_module_backports', | ||
478 | 49 | '/usr/share/ansible') | ||
479 | 50 | |||
480 | 51 | |||
481 | 52 | @hooks.hook('data-relation-joined', 'data-relation-changed') | ||
482 | 53 | def data_relation(): | ||
483 | 54 | if hookenv.relation_get('mountpoint') == mountpoint: | ||
484 | 55 | # Other side of relation is ready | ||
485 | 56 | migrate_to_mount(mountpoint) | ||
486 | 57 | else: | ||
487 | 58 | # Other side not ready yet, provide mountpoint | ||
488 | 59 | hookenv.log('Requesting storage for {}'.format(mountpoint)) | ||
489 | 60 | hookenv.relation_set(mountpoint=mountpoint) | ||
490 | 61 | |||
491 | 62 | |||
492 | 63 | @hooks.hook('data-relation-departed', 'data-relation-broken') | ||
493 | 64 | def data_relation_gone(): | ||
494 | 65 | hookenv.log('Data relation no longer present, stopping elasticsearch.') | ||
495 | 66 | charmhelpers.core.host.service_stop('elasticsearch') | ||
496 | 67 | |||
497 | 68 | |||
498 | 69 | def migrate_to_mount(new_path): | ||
499 | 70 | """Invoked when new mountpoint appears. This function safely migrates | ||
500 | 71 | elasticsearch data from local disk to persistent storage (only if needed) | ||
501 | 72 | """ | ||
502 | 73 | old_path = '/var/lib/elasticsearch' | ||
503 | 74 | if os.path.islink(old_path): | ||
504 | 75 | hookenv.log('{} is already a symlink, skipping migration'.format( | ||
505 | 76 | old_path)) | ||
506 | 77 | return True | ||
507 | 78 | # Ensure our new mountpoint is empty. Otherwise error and allow | ||
508 | 79 | # users to investigate and migrate manually | ||
509 | 80 | files = os.listdir(new_path) | ||
510 | 81 | try: | ||
511 | 82 | files.remove('lost+found') | ||
512 | 83 | except ValueError: | ||
513 | 84 | pass | ||
514 | 85 | if files: | ||
515 | 86 | raise RuntimeError('Persistent storage contains old data. ' | ||
516 | 87 | 'Please investigate and migrate data manually ' | ||
517 | 88 | 'to: {}'.format(new_path)) | ||
518 | 89 | os.chmod(new_path, 0700) | ||
519 | 90 | charmhelpers.core.host.service_stop('elasticsearch') | ||
520 | 91 | charmhelpers.core.host.rsync(os.path.join(old_path, ''), # Ensure we have trailing slashes | ||
521 | 92 | os.path.join(new_path, ''), | ||
522 | 93 | options=['--archive']) | ||
523 | 94 | shutil.rmtree(old_path) | ||
524 | 95 | os.symlink(new_path, old_path) | ||
525 | 96 | charmhelpers.core.host.service_start('elasticsearch') | ||
526 | 97 | |||
527 | 98 | |||
528 | 99 | if __name__ == "__main__": | ||
529 | 100 | hooks.execute(sys.argv) | ||
530 | 0 | 101 | ||
531 | === modified symlink 'hooks/data-relation-joined' (properties changed: -x to +x) | |||
532 | === target was u'hooks.py' | |||
533 | --- hooks/data-relation-joined 1970-01-01 00:00:00 +0000 | |||
534 | +++ hooks/data-relation-joined 2016-05-04 03:14:14 +0000 | |||
535 | @@ -0,0 +1,100 @@ | |||
536 | 1 | #!/usr/bin/env python | ||
537 | 2 | """Setup hooks for the elasticsearch charm.""" | ||
538 | 3 | |||
539 | 4 | import sys | ||
540 | 5 | import charmhelpers.contrib.ansible | ||
541 | 6 | import charmhelpers.payload.execd | ||
542 | 7 | import charmhelpers.core.host | ||
543 | 8 | from charmhelpers.core import hookenv | ||
544 | 9 | import os | ||
545 | 10 | import shutil | ||
546 | 11 | |||
547 | 12 | mountpoint = '/srv/elasticsearch' | ||
548 | 13 | |||
549 | 14 | hooks = charmhelpers.contrib.ansible.AnsibleHooks( | ||
550 | 15 | playbook_path='playbook.yaml', | ||
551 | 16 | default_hooks=[ | ||
552 | 17 | 'config-changed', | ||
553 | 18 | 'cluster-relation-joined', | ||
554 | 19 | 'logs-relation-joined', | ||
555 | 20 | 'data-relation-joined', | ||
556 | 21 | 'data-relation-changed', | ||
557 | 22 | 'data-relation-departed', | ||
558 | 23 | 'data-relation-broken', | ||
559 | 24 | 'peer-relation-joined', | ||
560 | 25 | 'peer-relation-changed', | ||
561 | 26 | 'peer-relation-departed', | ||
562 | 27 | 'nrpe-external-master-relation-changed', | ||
563 | 28 | 'rest-relation-joined', | ||
564 | 29 | 'start', | ||
565 | 30 | 'stop', | ||
566 | 31 | 'upgrade-charm', | ||
567 | 32 | 'client-relation-joined', | ||
568 | 33 | 'client-relation-departed', | ||
569 | 34 | ]) | ||
570 | 35 | |||
571 | 36 | |||
572 | 37 | @hooks.hook('install', 'upgrade-charm') | ||
573 | 38 | def install(): | ||
574 | 39 | """Install ansible before running the tasks tagged with 'install'.""" | ||
575 | 40 | # Allow charm users to run preinstall setup. | ||
576 | 41 | charmhelpers.payload.execd.execd_preinstall() | ||
577 | 42 | charmhelpers.contrib.ansible.install_ansible_support( | ||
578 | 43 | from_ppa=False) | ||
579 | 44 | |||
580 | 45 | # We copy the backported ansible modules here because they need to be | ||
581 | 46 | # in place by the time ansible runs any hook. | ||
582 | 47 | charmhelpers.core.host.rsync( | ||
583 | 48 | 'ansible_module_backports', | ||
584 | 49 | '/usr/share/ansible') | ||
585 | 50 | |||
586 | 51 | |||
587 | 52 | @hooks.hook('data-relation-joined', 'data-relation-changed') | ||
588 | 53 | def data_relation(): | ||
589 | 54 | if hookenv.relation_get('mountpoint') == mountpoint: | ||
590 | 55 | # Other side of relation is ready | ||
591 | 56 | migrate_to_mount(mountpoint) | ||
592 | 57 | else: | ||
593 | 58 | # Other side not ready yet, provide mountpoint | ||
594 | 59 | hookenv.log('Requesting storage for {}'.format(mountpoint)) | ||
595 | 60 | hookenv.relation_set(mountpoint=mountpoint) | ||
596 | 61 | |||
597 | 62 | |||
598 | 63 | @hooks.hook('data-relation-departed', 'data-relation-broken') | ||
599 | 64 | def data_relation_gone(): | ||
600 | 65 | hookenv.log('Data relation no longer present, stopping elasticsearch.') | ||
601 | 66 | charmhelpers.core.host.service_stop('elasticsearch') | ||
602 | 67 | |||
603 | 68 | |||
604 | 69 | def migrate_to_mount(new_path): | ||
605 | 70 | """Invoked when new mountpoint appears. This function safely migrates | ||
606 | 71 | elasticsearch data from local disk to persistent storage (only if needed) | ||
607 | 72 | """ | ||
608 | 73 | old_path = '/var/lib/elasticsearch' | ||
609 | 74 | if os.path.islink(old_path): | ||
610 | 75 | hookenv.log('{} is already a symlink, skipping migration'.format( | ||
611 | 76 | old_path)) | ||
612 | 77 | return True | ||
613 | 78 | # Ensure our new mountpoint is empty. Otherwise error and allow | ||
614 | 79 | # users to investigate and migrate manually | ||
615 | 80 | files = os.listdir(new_path) | ||
616 | 81 | try: | ||
617 | 82 | files.remove('lost+found') | ||
618 | 83 | except ValueError: | ||
619 | 84 | pass | ||
620 | 85 | if files: | ||
621 | 86 | raise RuntimeError('Persistent storage contains old data. ' | ||
622 | 87 | 'Please investigate and migrate data manually ' | ||
623 | 88 | 'to: {}'.format(new_path)) | ||
624 | 89 | os.chmod(new_path, 0700) | ||
625 | 90 | charmhelpers.core.host.service_stop('elasticsearch') | ||
626 | 91 | charmhelpers.core.host.rsync(os.path.join(old_path, ''), # Ensure we have trailing slashes | ||
627 | 92 | os.path.join(new_path, ''), | ||
628 | 93 | options=['--archive']) | ||
629 | 94 | shutil.rmtree(old_path) | ||
630 | 95 | os.symlink(new_path, old_path) | ||
631 | 96 | charmhelpers.core.host.service_start('elasticsearch') | ||
632 | 97 | |||
633 | 98 | |||
634 | 99 | if __name__ == "__main__": | ||
635 | 100 | hooks.execute(sys.argv) | ||
636 | 0 | 101 | ||
637 | === modified file 'hooks/hooks.py' | |||
638 | --- hooks/hooks.py 2015-10-27 22:30:30 +0000 | |||
639 | +++ hooks/hooks.py 2016-05-04 03:14:14 +0000 | |||
640 | @@ -88,9 +88,10 @@ | |||
641 | 88 | 'to: {}'.format(new_path)) | 88 | 'to: {}'.format(new_path)) |
642 | 89 | os.chmod(new_path, 0700) | 89 | os.chmod(new_path, 0700) |
643 | 90 | charmhelpers.core.host.service_stop('elasticsearch') | 90 | charmhelpers.core.host.service_stop('elasticsearch') |
647 | 91 | charmhelpers.core.host.rsync(os.path.join(old_path, ''), # Ensure we have trailing slashes | 91 | # Ensure we have trailing slashes |
648 | 92 | os.path.join(new_path, ''), | 92 | charmhelpers.core.host.rsync(os.path.join(old_path, ''), |
649 | 93 | options=['--archive']) | 93 | os.path.join(new_path, ''), |
650 | 94 | options=['--archive']) | ||
651 | 94 | shutil.rmtree(old_path) | 95 | shutil.rmtree(old_path) |
652 | 95 | os.symlink(new_path, old_path) | 96 | os.symlink(new_path, old_path) |
653 | 96 | charmhelpers.core.host.service_start('elasticsearch') | 97 | charmhelpers.core.host.service_start('elasticsearch') |
654 | 97 | 98 | ||
655 | === modified symlink 'hooks/install' (properties changed: -x to +x) | |||
656 | === target was u'hooks.py' | |||
657 | --- hooks/install 1970-01-01 00:00:00 +0000 | |||
658 | +++ hooks/install 2016-05-04 03:14:14 +0000 | |||
659 | @@ -0,0 +1,100 @@ | |||
660 | 1 | #!/usr/bin/env python | ||
661 | 2 | """Setup hooks for the elasticsearch charm.""" | ||
662 | 3 | |||
663 | 4 | import sys | ||
664 | 5 | import charmhelpers.contrib.ansible | ||
665 | 6 | import charmhelpers.payload.execd | ||
666 | 7 | import charmhelpers.core.host | ||
667 | 8 | from charmhelpers.core import hookenv | ||
668 | 9 | import os | ||
669 | 10 | import shutil | ||
670 | 11 | |||
671 | 12 | mountpoint = '/srv/elasticsearch' | ||
672 | 13 | |||
673 | 14 | hooks = charmhelpers.contrib.ansible.AnsibleHooks( | ||
674 | 15 | playbook_path='playbook.yaml', | ||
675 | 16 | default_hooks=[ | ||
676 | 17 | 'config-changed', | ||
677 | 18 | 'cluster-relation-joined', | ||
678 | 19 | 'logs-relation-joined', | ||
679 | 20 | 'data-relation-joined', | ||
680 | 21 | 'data-relation-changed', | ||
681 | 22 | 'data-relation-departed', | ||
682 | 23 | 'data-relation-broken', | ||
683 | 24 | 'peer-relation-joined', | ||
684 | 25 | 'peer-relation-changed', | ||
685 | 26 | 'peer-relation-departed', | ||
686 | 27 | 'nrpe-external-master-relation-changed', | ||
687 | 28 | 'rest-relation-joined', | ||
688 | 29 | 'start', | ||
689 | 30 | 'stop', | ||
690 | 31 | 'upgrade-charm', | ||
691 | 32 | 'client-relation-joined', | ||
692 | 33 | 'client-relation-departed', | ||
693 | 34 | ]) | ||
694 | 35 | |||
695 | 36 | |||
696 | 37 | @hooks.hook('install', 'upgrade-charm') | ||
697 | 38 | def install(): | ||
698 | 39 | """Install ansible before running the tasks tagged with 'install'.""" | ||
699 | 40 | # Allow charm users to run preinstall setup. | ||
700 | 41 | charmhelpers.payload.execd.execd_preinstall() | ||
701 | 42 | charmhelpers.contrib.ansible.install_ansible_support( | ||
702 | 43 | from_ppa=False) | ||
703 | 44 | |||
704 | 45 | # We copy the backported ansible modules here because they need to be | ||
705 | 46 | # in place by the time ansible runs any hook. | ||
706 | 47 | charmhelpers.core.host.rsync( | ||
707 | 48 | 'ansible_module_backports', | ||
708 | 49 | '/usr/share/ansible') | ||
709 | 50 | |||
710 | 51 | |||
711 | 52 | @hooks.hook('data-relation-joined', 'data-relation-changed') | ||
712 | 53 | def data_relation(): | ||
713 | 54 | if hookenv.relation_get('mountpoint') == mountpoint: | ||
714 | 55 | # Other side of relation is ready | ||
715 | 56 | migrate_to_mount(mountpoint) | ||
716 | 57 | else: | ||
717 | 58 | # Other side not ready yet, provide mountpoint | ||
718 | 59 | hookenv.log('Requesting storage for {}'.format(mountpoint)) | ||
719 | 60 | hookenv.relation_set(mountpoint=mountpoint) | ||
720 | 61 | |||
721 | 62 | |||
722 | 63 | @hooks.hook('data-relation-departed', 'data-relation-broken') | ||
723 | 64 | def data_relation_gone(): | ||
724 | 65 | hookenv.log('Data relation no longer present, stopping elasticsearch.') | ||
725 | 66 | charmhelpers.core.host.service_stop('elasticsearch') | ||
726 | 67 | |||
727 | 68 | |||
728 | 69 | def migrate_to_mount(new_path): | ||
729 | 70 | """Invoked when new mountpoint appears. This function safely migrates | ||
730 | 71 | elasticsearch data from local disk to persistent storage (only if needed) | ||
731 | 72 | """ | ||
732 | 73 | old_path = '/var/lib/elasticsearch' | ||
733 | 74 | if os.path.islink(old_path): | ||
734 | 75 | hookenv.log('{} is already a symlink, skipping migration'.format( | ||
735 | 76 | old_path)) | ||
736 | 77 | return True | ||
737 | 78 | # Ensure our new mountpoint is empty. Otherwise error and allow | ||
738 | 79 | # users to investigate and migrate manually | ||
739 | 80 | files = os.listdir(new_path) | ||
740 | 81 | try: | ||
741 | 82 | files.remove('lost+found') | ||
742 | 83 | except ValueError: | ||
743 | 84 | pass | ||
744 | 85 | if files: | ||
745 | 86 | raise RuntimeError('Persistent storage contains old data. ' | ||
746 | 87 | 'Please investigate and migrate data manually ' | ||
747 | 88 | 'to: {}'.format(new_path)) | ||
748 | 89 | os.chmod(new_path, 0700) | ||
749 | 90 | charmhelpers.core.host.service_stop('elasticsearch') | ||
750 | 91 | charmhelpers.core.host.rsync(os.path.join(old_path, ''), # Ensure we have trailing slashes | ||
751 | 92 | os.path.join(new_path, ''), | ||
752 | 93 | options=['--archive']) | ||
753 | 94 | shutil.rmtree(old_path) | ||
754 | 95 | os.symlink(new_path, old_path) | ||
755 | 96 | charmhelpers.core.host.service_start('elasticsearch') | ||
756 | 97 | |||
757 | 98 | |||
758 | 99 | if __name__ == "__main__": | ||
759 | 100 | hooks.execute(sys.argv) | ||
760 | 0 | 101 | ||
761 | === modified symlink 'hooks/logs-relation-joined' (properties changed: -x to +x) | |||
762 | === target was u'hooks.py' | |||
763 | --- hooks/logs-relation-joined 1970-01-01 00:00:00 +0000 | |||
764 | +++ hooks/logs-relation-joined 2016-05-04 03:14:14 +0000 | |||
765 | @@ -0,0 +1,100 @@ | |||
766 | 1 | #!/usr/bin/env python | ||
767 | 2 | """Setup hooks for the elasticsearch charm.""" | ||
768 | 3 | |||
769 | 4 | import sys | ||
770 | 5 | import charmhelpers.contrib.ansible | ||
771 | 6 | import charmhelpers.payload.execd | ||
772 | 7 | import charmhelpers.core.host | ||
773 | 8 | from charmhelpers.core import hookenv | ||
774 | 9 | import os | ||
775 | 10 | import shutil | ||
776 | 11 | |||
777 | 12 | mountpoint = '/srv/elasticsearch' | ||
778 | 13 | |||
779 | 14 | hooks = charmhelpers.contrib.ansible.AnsibleHooks( | ||
780 | 15 | playbook_path='playbook.yaml', | ||
781 | 16 | default_hooks=[ | ||
782 | 17 | 'config-changed', | ||
783 | 18 | 'cluster-relation-joined', | ||
784 | 19 | 'logs-relation-joined', | ||
785 | 20 | 'data-relation-joined', | ||
786 | 21 | 'data-relation-changed', | ||
787 | 22 | 'data-relation-departed', | ||
788 | 23 | 'data-relation-broken', | ||
789 | 24 | 'peer-relation-joined', | ||
790 | 25 | 'peer-relation-changed', | ||
791 | 26 | 'peer-relation-departed', | ||
792 | 27 | 'nrpe-external-master-relation-changed', | ||
793 | 28 | 'rest-relation-joined', | ||
794 | 29 | 'start', | ||
795 | 30 | 'stop', | ||
796 | 31 | 'upgrade-charm', | ||
797 | 32 | 'client-relation-joined', | ||
798 | 33 | 'client-relation-departed', | ||
799 | 34 | ]) | ||
800 | 35 | |||
801 | 36 | |||
802 | 37 | @hooks.hook('install', 'upgrade-charm') | ||
803 | 38 | def install(): | ||
804 | 39 | """Install ansible before running the tasks tagged with 'install'.""" | ||
805 | 40 | # Allow charm users to run preinstall setup. | ||
806 | 41 | charmhelpers.payload.execd.execd_preinstall() | ||
807 | 42 | charmhelpers.contrib.ansible.install_ansible_support( | ||
808 | 43 | from_ppa=False) | ||
809 | 44 | |||
810 | 45 | # We copy the backported ansible modules here because they need to be | ||
811 | 46 | # in place by the time ansible runs any hook. | ||
812 | 47 | charmhelpers.core.host.rsync( | ||
813 | 48 | 'ansible_module_backports', | ||
814 | 49 | '/usr/share/ansible') | ||
815 | 50 | |||
816 | 51 | |||
817 | 52 | @hooks.hook('data-relation-joined', 'data-relation-changed') | ||
818 | 53 | def data_relation(): | ||
819 | 54 | if hookenv.relation_get('mountpoint') == mountpoint: | ||
820 | 55 | # Other side of relation is ready | ||
821 | 56 | migrate_to_mount(mountpoint) | ||
822 | 57 | else: | ||
823 | 58 | # Other side not ready yet, provide mountpoint | ||
824 | 59 | hookenv.log('Requesting storage for {}'.format(mountpoint)) | ||
825 | 60 | hookenv.relation_set(mountpoint=mountpoint) | ||
826 | 61 | |||
827 | 62 | |||
828 | 63 | @hooks.hook('data-relation-departed', 'data-relation-broken') | ||
829 | 64 | def data_relation_gone(): | ||
830 | 65 | hookenv.log('Data relation no longer present, stopping elasticsearch.') | ||
831 | 66 | charmhelpers.core.host.service_stop('elasticsearch') | ||
832 | 67 | |||
833 | 68 | |||
834 | 69 | def migrate_to_mount(new_path): | ||
835 | 70 | """Invoked when new mountpoint appears. This function safely migrates | ||
836 | 71 | elasticsearch data from local disk to persistent storage (only if needed) | ||
837 | 72 | """ | ||
838 | 73 | old_path = '/var/lib/elasticsearch' | ||
839 | 74 | if os.path.islink(old_path): | ||
840 | 75 | hookenv.log('{} is already a symlink, skipping migration'.format( | ||
841 | 76 | old_path)) | ||
842 | 77 | return True | ||
843 | 78 | # Ensure our new mountpoint is empty. Otherwise error and allow | ||
844 | 79 | # users to investigate and migrate manually | ||
845 | 80 | files = os.listdir(new_path) | ||
846 | 81 | try: | ||
847 | 82 | files.remove('lost+found') | ||
848 | 83 | except ValueError: | ||
849 | 84 | pass | ||
850 | 85 | if files: | ||
851 | 86 | raise RuntimeError('Persistent storage contains old data. ' | ||
852 | 87 | 'Please investigate and migrate data manually ' | ||
853 | 88 | 'to: {}'.format(new_path)) | ||
854 | 89 | os.chmod(new_path, 0700) | ||
855 | 90 | charmhelpers.core.host.service_stop('elasticsearch') | ||
856 | 91 | charmhelpers.core.host.rsync(os.path.join(old_path, ''), # Ensure we have trailing slashes | ||
857 | 92 | os.path.join(new_path, ''), | ||
858 | 93 | options=['--archive']) | ||
859 | 94 | shutil.rmtree(old_path) | ||
860 | 95 | os.symlink(new_path, old_path) | ||
861 | 96 | charmhelpers.core.host.service_start('elasticsearch') | ||
862 | 97 | |||
863 | 98 | |||
864 | 99 | if __name__ == "__main__": | ||
865 | 100 | hooks.execute(sys.argv) | ||
866 | 0 | 101 | ||
867 | === modified symlink 'hooks/nrpe-external-master-relation-changed' (properties changed: -x to +x) | |||
868 | === target was u'hooks.py' | |||
869 | --- hooks/nrpe-external-master-relation-changed 1970-01-01 00:00:00 +0000 | |||
870 | +++ hooks/nrpe-external-master-relation-changed 2016-05-04 03:14:14 +0000 | |||
871 | @@ -0,0 +1,100 @@ | |||
872 | 1 | #!/usr/bin/env python | ||
873 | 2 | """Setup hooks for the elasticsearch charm.""" | ||
874 | 3 | |||
875 | 4 | import sys | ||
876 | 5 | import charmhelpers.contrib.ansible | ||
877 | 6 | import charmhelpers.payload.execd | ||
878 | 7 | import charmhelpers.core.host | ||
879 | 8 | from charmhelpers.core import hookenv | ||
880 | 9 | import os | ||
881 | 10 | import shutil | ||
882 | 11 | |||
883 | 12 | mountpoint = '/srv/elasticsearch' | ||
884 | 13 | |||
885 | 14 | hooks = charmhelpers.contrib.ansible.AnsibleHooks( | ||
886 | 15 | playbook_path='playbook.yaml', | ||
887 | 16 | default_hooks=[ | ||
888 | 17 | 'config-changed', | ||
889 | 18 | 'cluster-relation-joined', | ||
890 | 19 | 'logs-relation-joined', | ||
891 | 20 | 'data-relation-joined', | ||
892 | 21 | 'data-relation-changed', | ||
893 | 22 | 'data-relation-departed', | ||
894 | 23 | 'data-relation-broken', | ||
895 | 24 | 'peer-relation-joined', | ||
896 | 25 | 'peer-relation-changed', | ||
897 | 26 | 'peer-relation-departed', | ||
898 | 27 | 'nrpe-external-master-relation-changed', | ||
899 | 28 | 'rest-relation-joined', | ||
900 | 29 | 'start', | ||
901 | 30 | 'stop', | ||
902 | 31 | 'upgrade-charm', | ||
903 | 32 | 'client-relation-joined', | ||
904 | 33 | 'client-relation-departed', | ||
905 | 34 | ]) | ||
906 | 35 | |||
907 | 36 | |||
908 | 37 | @hooks.hook('install', 'upgrade-charm') | ||
909 | 38 | def install(): | ||
910 | 39 | """Install ansible before running the tasks tagged with 'install'.""" | ||
911 | 40 | # Allow charm users to run preinstall setup. | ||
912 | 41 | charmhelpers.payload.execd.execd_preinstall() | ||
913 | 42 | charmhelpers.contrib.ansible.install_ansible_support( | ||
914 | 43 | from_ppa=False) | ||
915 | 44 | |||
916 | 45 | # We copy the backported ansible modules here because they need to be | ||
917 | 46 | # in place by the time ansible runs any hook. | ||
918 | 47 | charmhelpers.core.host.rsync( | ||
919 | 48 | 'ansible_module_backports', | ||
920 | 49 | '/usr/share/ansible') | ||
921 | 50 | |||
922 | 51 | |||
923 | 52 | @hooks.hook('data-relation-joined', 'data-relation-changed') | ||
924 | 53 | def data_relation(): | ||
925 | 54 | if hookenv.relation_get('mountpoint') == mountpoint: | ||
926 | 55 | # Other side of relation is ready | ||
927 | 56 | migrate_to_mount(mountpoint) | ||
928 | 57 | else: | ||
929 | 58 | # Other side not ready yet, provide mountpoint | ||
930 | 59 | hookenv.log('Requesting storage for {}'.format(mountpoint)) | ||
931 | 60 | hookenv.relation_set(mountpoint=mountpoint) | ||
932 | 61 | |||
933 | 62 | |||
934 | 63 | @hooks.hook('data-relation-departed', 'data-relation-broken') | ||
935 | 64 | def data_relation_gone(): | ||
936 | 65 | hookenv.log('Data relation no longer present, stopping elasticsearch.') | ||
937 | 66 | charmhelpers.core.host.service_stop('elasticsearch') | ||
938 | 67 | |||
939 | 68 | |||
940 | 69 | def migrate_to_mount(new_path): | ||
941 | 70 | """Invoked when new mountpoint appears. This function safely migrates | ||
942 | 71 | elasticsearch data from local disk to persistent storage (only if needed) | ||
943 | 72 | """ | ||
944 | 73 | old_path = '/var/lib/elasticsearch' | ||
945 | 74 | if os.path.islink(old_path): | ||
946 | 75 | hookenv.log('{} is already a symlink, skipping migration'.format( | ||
947 | 76 | old_path)) | ||
948 | 77 | return True | ||
949 | 78 | # Ensure our new mountpoint is empty. Otherwise error and allow | ||
950 | 79 | # users to investigate and migrate manually | ||
951 | 80 | files = os.listdir(new_path) | ||
952 | 81 | try: | ||
953 | 82 | files.remove('lost+found') | ||
954 | 83 | except ValueError: | ||
955 | 84 | pass | ||
956 | 85 | if files: | ||
957 | 86 | raise RuntimeError('Persistent storage contains old data. ' | ||
958 | 87 | 'Please investigate and migrate data manually ' | ||
959 | 88 | 'to: {}'.format(new_path)) | ||
960 | 89 | os.chmod(new_path, 0700) | ||
961 | 90 | charmhelpers.core.host.service_stop('elasticsearch') | ||
962 | 91 | charmhelpers.core.host.rsync(os.path.join(old_path, ''), # Ensure we have trailing slashes | ||
963 | 92 | os.path.join(new_path, ''), | ||
964 | 93 | options=['--archive']) | ||
965 | 94 | shutil.rmtree(old_path) | ||
966 | 95 | os.symlink(new_path, old_path) | ||
967 | 96 | charmhelpers.core.host.service_start('elasticsearch') | ||
968 | 97 | |||
969 | 98 | |||
970 | 99 | if __name__ == "__main__": | ||
971 | 100 | hooks.execute(sys.argv) | ||
972 | 0 | 101 | ||
973 | === modified symlink 'hooks/peer-relation-changed' (properties changed: -x to +x) | |||
974 | === target was u'hooks.py' | |||
975 | --- hooks/peer-relation-changed 1970-01-01 00:00:00 +0000 | |||
976 | +++ hooks/peer-relation-changed 2016-05-04 03:14:14 +0000 | |||
977 | @@ -0,0 +1,100 @@ | |||
978 | 1 | #!/usr/bin/env python | ||
979 | 2 | """Setup hooks for the elasticsearch charm.""" | ||
980 | 3 | |||
981 | 4 | import sys | ||
982 | 5 | import charmhelpers.contrib.ansible | ||
983 | 6 | import charmhelpers.payload.execd | ||
984 | 7 | import charmhelpers.core.host | ||
985 | 8 | from charmhelpers.core import hookenv | ||
986 | 9 | import os | ||
987 | 10 | import shutil | ||
988 | 11 | |||
989 | 12 | mountpoint = '/srv/elasticsearch' | ||
990 | 13 | |||
991 | 14 | hooks = charmhelpers.contrib.ansible.AnsibleHooks( | ||
992 | 15 | playbook_path='playbook.yaml', | ||
993 | 16 | default_hooks=[ | ||
994 | 17 | 'config-changed', | ||
995 | 18 | 'cluster-relation-joined', | ||
996 | 19 | 'logs-relation-joined', | ||
997 | 20 | 'data-relation-joined', | ||
998 | 21 | 'data-relation-changed', | ||
999 | 22 | 'data-relation-departed', | ||
1000 | 23 | 'data-relation-broken', | ||
1001 | 24 | 'peer-relation-joined', | ||
1002 | 25 | 'peer-relation-changed', | ||
1003 | 26 | 'peer-relation-departed', | ||
1004 | 27 | 'nrpe-external-master-relation-changed', | ||
1005 | 28 | 'rest-relation-joined', | ||
1006 | 29 | 'start', | ||
1007 | 30 | 'stop', | ||
1008 | 31 | 'upgrade-charm', | ||
1009 | 32 | 'client-relation-joined', | ||
1010 | 33 | 'client-relation-departed', | ||
1011 | 34 | ]) | ||
1012 | 35 | |||
1013 | 36 | |||
1014 | 37 | @hooks.hook('install', 'upgrade-charm') | ||
1015 | 38 | def install(): | ||
1016 | 39 | """Install ansible before running the tasks tagged with 'install'.""" | ||
1017 | 40 | # Allow charm users to run preinstall setup. | ||
1018 | 41 | charmhelpers.payload.execd.execd_preinstall() | ||
1019 | 42 | charmhelpers.contrib.ansible.install_ansible_support( | ||
1020 | 43 | from_ppa=False) | ||
1021 | 44 | |||
1022 | 45 | # We copy the backported ansible modules here because they need to be | ||
1023 | 46 | # in place by the time ansible runs any hook. | ||
1024 | 47 | charmhelpers.core.host.rsync( | ||
1025 | 48 | 'ansible_module_backports', | ||
1026 | 49 | '/usr/share/ansible') | ||
1027 | 50 | |||
1028 | 51 | |||
1029 | 52 | @hooks.hook('data-relation-joined', 'data-relation-changed') | ||
1030 | 53 | def data_relation(): | ||
1031 | 54 | if hookenv.relation_get('mountpoint') == mountpoint: | ||
1032 | 55 | # Other side of relation is ready | ||
1033 | 56 | migrate_to_mount(mountpoint) | ||
1034 | 57 | else: | ||
1035 | 58 | # Other side not ready yet, provide mountpoint | ||
1036 | 59 | hookenv.log('Requesting storage for {}'.format(mountpoint)) | ||
1037 | 60 | hookenv.relation_set(mountpoint=mountpoint) | ||
1038 | 61 | |||
1039 | 62 | |||
1040 | 63 | @hooks.hook('data-relation-departed', 'data-relation-broken') | ||
1041 | 64 | def data_relation_gone(): | ||
1042 | 65 | hookenv.log('Data relation no longer present, stopping elasticsearch.') | ||
1043 | 66 | charmhelpers.core.host.service_stop('elasticsearch') | ||
1044 | 67 | |||
1045 | 68 | |||
1046 | 69 | def migrate_to_mount(new_path): | ||
1047 | 70 | """Invoked when new mountpoint appears. This function safely migrates | ||
1048 | 71 | elasticsearch data from local disk to persistent storage (only if needed) | ||
1049 | 72 | """ | ||
1050 | 73 | old_path = '/var/lib/elasticsearch' | ||
1051 | 74 | if os.path.islink(old_path): | ||
1052 | 75 | hookenv.log('{} is already a symlink, skipping migration'.format( | ||
1053 | 76 | old_path)) | ||
1054 | 77 | return True | ||
1055 | 78 | # Ensure our new mountpoint is empty. Otherwise error and allow | ||
1056 | 79 | # users to investigate and migrate manually | ||
1057 | 80 | files = os.listdir(new_path) | ||
1058 | 81 | try: | ||
1059 | 82 | files.remove('lost+found') | ||
1060 | 83 | except ValueError: | ||
1061 | 84 | pass | ||
1062 | 85 | if files: | ||
1063 | 86 | raise RuntimeError('Persistent storage contains old data. ' | ||
1064 | 87 | 'Please investigate and migrate data manually ' | ||
1065 | 88 | 'to: {}'.format(new_path)) | ||
1066 | 89 | os.chmod(new_path, 0700) | ||
1067 | 90 | charmhelpers.core.host.service_stop('elasticsearch') | ||
1068 | 91 | charmhelpers.core.host.rsync(os.path.join(old_path, ''), # Ensure we have trailing slashes | ||
1069 | 92 | os.path.join(new_path, ''), | ||
1070 | 93 | options=['--archive']) | ||
1071 | 94 | shutil.rmtree(old_path) | ||
1072 | 95 | os.symlink(new_path, old_path) | ||
1073 | 96 | charmhelpers.core.host.service_start('elasticsearch') | ||
1074 | 97 | |||
1075 | 98 | |||
1076 | 99 | if __name__ == "__main__": | ||
1077 | 100 | hooks.execute(sys.argv) | ||
1078 | 0 | 101 | ||
1079 | === modified symlink 'hooks/peer-relation-departed' (properties changed: -x to +x) | |||
1080 | === target was u'hooks.py' | |||
1081 | --- hooks/peer-relation-departed 1970-01-01 00:00:00 +0000 | |||
1082 | +++ hooks/peer-relation-departed 2016-05-04 03:14:14 +0000 | |||
1083 | @@ -0,0 +1,100 @@ | |||
1084 | 1 | #!/usr/bin/env python | ||
1085 | 2 | """Setup hooks for the elasticsearch charm.""" | ||
1086 | 3 | |||
1087 | 4 | import sys | ||
1088 | 5 | import charmhelpers.contrib.ansible | ||
1089 | 6 | import charmhelpers.payload.execd | ||
1090 | 7 | import charmhelpers.core.host | ||
1091 | 8 | from charmhelpers.core import hookenv | ||
1092 | 9 | import os | ||
1093 | 10 | import shutil | ||
1094 | 11 | |||
1095 | 12 | mountpoint = '/srv/elasticsearch' | ||
1096 | 13 | |||
1097 | 14 | hooks = charmhelpers.contrib.ansible.AnsibleHooks( | ||
1098 | 15 | playbook_path='playbook.yaml', | ||
1099 | 16 | default_hooks=[ | ||
1100 | 17 | 'config-changed', | ||
1101 | 18 | 'cluster-relation-joined', | ||
1102 | 19 | 'logs-relation-joined', | ||
1103 | 20 | 'data-relation-joined', | ||
1104 | 21 | 'data-relation-changed', | ||
1105 | 22 | 'data-relation-departed', | ||
1106 | 23 | 'data-relation-broken', | ||
1107 | 24 | 'peer-relation-joined', | ||
1108 | 25 | 'peer-relation-changed', | ||
1109 | 26 | 'peer-relation-departed', | ||
1110 | 27 | 'nrpe-external-master-relation-changed', | ||
1111 | 28 | 'rest-relation-joined', | ||
1112 | 29 | 'start', | ||
1113 | 30 | 'stop', | ||
1114 | 31 | 'upgrade-charm', | ||
1115 | 32 | 'client-relation-joined', | ||
1116 | 33 | 'client-relation-departed', | ||
1117 | 34 | ]) | ||
1118 | 35 | |||
1119 | 36 | |||
1120 | 37 | @hooks.hook('install', 'upgrade-charm') | ||
1121 | 38 | def install(): | ||
1122 | 39 | """Install ansible before running the tasks tagged with 'install'.""" | ||
1123 | 40 | # Allow charm users to run preinstall setup. | ||
1124 | 41 | charmhelpers.payload.execd.execd_preinstall() | ||
1125 | 42 | charmhelpers.contrib.ansible.install_ansible_support( | ||
1126 | 43 | from_ppa=False) | ||
1127 | 44 | |||
1128 | 45 | # We copy the backported ansible modules here because they need to be | ||
1129 | 46 | # in place by the time ansible runs any hook. | ||
1130 | 47 | charmhelpers.core.host.rsync( | ||
1131 | 48 | 'ansible_module_backports', | ||
1132 | 49 | '/usr/share/ansible') | ||
1133 | 50 | |||
1134 | 51 | |||
1135 | 52 | @hooks.hook('data-relation-joined', 'data-relation-changed') | ||
1136 | 53 | def data_relation(): | ||
1137 | 54 | if hookenv.relation_get('mountpoint') == mountpoint: | ||
1138 | 55 | # Other side of relation is ready | ||
1139 | 56 | migrate_to_mount(mountpoint) | ||
1140 | 57 | else: | ||
1141 | 58 | # Other side not ready yet, provide mountpoint | ||
1142 | 59 | hookenv.log('Requesting storage for {}'.format(mountpoint)) | ||
1143 | 60 | hookenv.relation_set(mountpoint=mountpoint) | ||
1144 | 61 | |||
1145 | 62 | |||
1146 | 63 | @hooks.hook('data-relation-departed', 'data-relation-broken') | ||
1147 | 64 | def data_relation_gone(): | ||
1148 | 65 | hookenv.log('Data relation no longer present, stopping elasticsearch.') | ||
1149 | 66 | charmhelpers.core.host.service_stop('elasticsearch') | ||
1150 | 67 | |||
1151 | 68 | |||
1152 | 69 | def migrate_to_mount(new_path): | ||
1153 | 70 | """Invoked when new mountpoint appears. This function safely migrates | ||
1154 | 71 | elasticsearch data from local disk to persistent storage (only if needed) | ||
1155 | 72 | """ | ||
1156 | 73 | old_path = '/var/lib/elasticsearch' | ||
1157 | 74 | if os.path.islink(old_path): | ||
1158 | 75 | hookenv.log('{} is already a symlink, skipping migration'.format( | ||
1159 | 76 | old_path)) | ||
1160 | 77 | return True | ||
1161 | 78 | # Ensure our new mountpoint is empty. Otherwise error and allow | ||
1162 | 79 | # users to investigate and migrate manually | ||
1163 | 80 | files = os.listdir(new_path) | ||
1164 | 81 | try: | ||
1165 | 82 | files.remove('lost+found') | ||
1166 | 83 | except ValueError: | ||
1167 | 84 | pass | ||
1168 | 85 | if files: | ||
1169 | 86 | raise RuntimeError('Persistent storage contains old data. ' | ||
1170 | 87 | 'Please investigate and migrate data manually ' | ||
1171 | 88 | 'to: {}'.format(new_path)) | ||
1172 | 89 | os.chmod(new_path, 0700) | ||
1173 | 90 | charmhelpers.core.host.service_stop('elasticsearch') | ||
1174 | 91 | charmhelpers.core.host.rsync(os.path.join(old_path, ''), # Ensure we have trailing slashes | ||
1175 | 92 | os.path.join(new_path, ''), | ||
1176 | 93 | options=['--archive']) | ||
1177 | 94 | shutil.rmtree(old_path) | ||
1178 | 95 | os.symlink(new_path, old_path) | ||
1179 | 96 | charmhelpers.core.host.service_start('elasticsearch') | ||
1180 | 97 | |||
1181 | 98 | |||
1182 | 99 | if __name__ == "__main__": | ||
1183 | 100 | hooks.execute(sys.argv) | ||
1184 | 0 | 101 | ||
1185 | === modified symlink 'hooks/peer-relation-joined' (properties changed: -x to +x) | |||
1186 | === target was u'hooks.py' | |||
1187 | --- hooks/peer-relation-joined 1970-01-01 00:00:00 +0000 | |||
1188 | +++ hooks/peer-relation-joined 2016-05-04 03:14:14 +0000 | |||
1189 | @@ -0,0 +1,100 @@ | |||
1190 | 1 | #!/usr/bin/env python | ||
1191 | 2 | """Setup hooks for the elasticsearch charm.""" | ||
1192 | 3 | |||
1193 | 4 | import sys | ||
1194 | 5 | import charmhelpers.contrib.ansible | ||
1195 | 6 | import charmhelpers.payload.execd | ||
1196 | 7 | import charmhelpers.core.host | ||
1197 | 8 | from charmhelpers.core import hookenv | ||
1198 | 9 | import os | ||
1199 | 10 | import shutil | ||
1200 | 11 | |||
1201 | 12 | mountpoint = '/srv/elasticsearch' | ||
1202 | 13 | |||
1203 | 14 | hooks = charmhelpers.contrib.ansible.AnsibleHooks( | ||
1204 | 15 | playbook_path='playbook.yaml', | ||
1205 | 16 | default_hooks=[ | ||
1206 | 17 | 'config-changed', | ||
1207 | 18 | 'cluster-relation-joined', | ||
1208 | 19 | 'logs-relation-joined', | ||
1209 | 20 | 'data-relation-joined', | ||
1210 | 21 | 'data-relation-changed', | ||
1211 | 22 | 'data-relation-departed', | ||
1212 | 23 | 'data-relation-broken', | ||
1213 | 24 | 'peer-relation-joined', | ||
1214 | 25 | 'peer-relation-changed', | ||
1215 | 26 | 'peer-relation-departed', | ||
1216 | 27 | 'nrpe-external-master-relation-changed', | ||
1217 | 28 | 'rest-relation-joined', | ||
1218 | 29 | 'start', | ||
1219 | 30 | 'stop', | ||
1220 | 31 | 'upgrade-charm', | ||
1221 | 32 | 'client-relation-joined', | ||
1222 | 33 | 'client-relation-departed', | ||
1223 | 34 | ]) | ||
1224 | 35 | |||
1225 | 36 | |||
1226 | 37 | @hooks.hook('install', 'upgrade-charm') | ||
1227 | 38 | def install(): | ||
1228 | 39 | """Install ansible before running the tasks tagged with 'install'.""" | ||
1229 | 40 | # Allow charm users to run preinstall setup. | ||
1230 | 41 | charmhelpers.payload.execd.execd_preinstall() | ||
1231 | 42 | charmhelpers.contrib.ansible.install_ansible_support( | ||
1232 | 43 | from_ppa=False) | ||
1233 | 44 | |||
1234 | 45 | # We copy the backported ansible modules here because they need to be | ||
1235 | 46 | # in place by the time ansible runs any hook. | ||
1236 | 47 | charmhelpers.core.host.rsync( | ||
1237 | 48 | 'ansible_module_backports', | ||
1238 | 49 | '/usr/share/ansible') | ||
1239 | 50 | |||
1240 | 51 | |||
1241 | 52 | @hooks.hook('data-relation-joined', 'data-relation-changed') | ||
1242 | 53 | def data_relation(): | ||
1243 | 54 | if hookenv.relation_get('mountpoint') == mountpoint: | ||
1244 | 55 | # Other side of relation is ready | ||
1245 | 56 | migrate_to_mount(mountpoint) | ||
1246 | 57 | else: | ||
1247 | 58 | # Other side not ready yet, provide mountpoint | ||
1248 | 59 | hookenv.log('Requesting storage for {}'.format(mountpoint)) | ||
1249 | 60 | hookenv.relation_set(mountpoint=mountpoint) | ||
1250 | 61 | |||
1251 | 62 | |||
1252 | 63 | @hooks.hook('data-relation-departed', 'data-relation-broken') | ||
1253 | 64 | def data_relation_gone(): | ||
1254 | 65 | hookenv.log('Data relation no longer present, stopping elasticsearch.') | ||
1255 | 66 | charmhelpers.core.host.service_stop('elasticsearch') | ||
1256 | 67 | |||
1257 | 68 | |||
1258 | 69 | def migrate_to_mount(new_path): | ||
1259 | 70 | """Invoked when new mountpoint appears. This function safely migrates | ||
1260 | 71 | elasticsearch data from local disk to persistent storage (only if needed) | ||
1261 | 72 | """ | ||
1262 | 73 | old_path = '/var/lib/elasticsearch' | ||
1263 | 74 | if os.path.islink(old_path): | ||
1264 | 75 | hookenv.log('{} is already a symlink, skipping migration'.format( | ||
1265 | 76 | old_path)) | ||
1266 | 77 | return True | ||
1267 | 78 | # Ensure our new mountpoint is empty. Otherwise error and allow | ||
1268 | 79 | # users to investigate and migrate manually | ||
1269 | 80 | files = os.listdir(new_path) | ||
1270 | 81 | try: | ||
1271 | 82 | files.remove('lost+found') | ||
1272 | 83 | except ValueError: | ||
1273 | 84 | pass | ||
1274 | 85 | if files: | ||
1275 | 86 | raise RuntimeError('Persistent storage contains old data. ' | ||
1276 | 87 | 'Please investigate and migrate data manually ' | ||
1277 | 88 | 'to: {}'.format(new_path)) | ||
1278 | 89 | os.chmod(new_path, 0700) | ||
1279 | 90 | charmhelpers.core.host.service_stop('elasticsearch') | ||
1280 | 91 | charmhelpers.core.host.rsync(os.path.join(old_path, ''), # Ensure we have trailing slashes | ||
1281 | 92 | os.path.join(new_path, ''), | ||
1282 | 93 | options=['--archive']) | ||
1283 | 94 | shutil.rmtree(old_path) | ||
1284 | 95 | os.symlink(new_path, old_path) | ||
1285 | 96 | charmhelpers.core.host.service_start('elasticsearch') | ||
1286 | 97 | |||
1287 | 98 | |||
1288 | 99 | if __name__ == "__main__": | ||
1289 | 100 | hooks.execute(sys.argv) | ||
1290 | 0 | 101 | ||
1291 | === modified symlink 'hooks/start' (properties changed: -x to +x) | |||
1292 | === target was u'hooks.py' | |||
1293 | --- hooks/start 1970-01-01 00:00:00 +0000 | |||
1294 | +++ hooks/start 2016-05-04 03:14:14 +0000 | |||
1295 | @@ -0,0 +1,100 @@ | |||
1296 | 1 | #!/usr/bin/env python | ||
1297 | 2 | """Setup hooks for the elasticsearch charm.""" | ||
1298 | 3 | |||
1299 | 4 | import sys | ||
1300 | 5 | import charmhelpers.contrib.ansible | ||
1301 | 6 | import charmhelpers.payload.execd | ||
1302 | 7 | import charmhelpers.core.host | ||
1303 | 8 | from charmhelpers.core import hookenv | ||
1304 | 9 | import os | ||
1305 | 10 | import shutil | ||
1306 | 11 | |||
1307 | 12 | mountpoint = '/srv/elasticsearch' | ||
1308 | 13 | |||
1309 | 14 | hooks = charmhelpers.contrib.ansible.AnsibleHooks( | ||
1310 | 15 | playbook_path='playbook.yaml', | ||
1311 | 16 | default_hooks=[ | ||
1312 | 17 | 'config-changed', | ||
1313 | 18 | 'cluster-relation-joined', | ||
1314 | 19 | 'logs-relation-joined', | ||
1315 | 20 | 'data-relation-joined', | ||
1316 | 21 | 'data-relation-changed', | ||
1317 | 22 | 'data-relation-departed', | ||
1318 | 23 | 'data-relation-broken', | ||
1319 | 24 | 'peer-relation-joined', | ||
1320 | 25 | 'peer-relation-changed', | ||
1321 | 26 | 'peer-relation-departed', | ||
1322 | 27 | 'nrpe-external-master-relation-changed', | ||
1323 | 28 | 'rest-relation-joined', | ||
1324 | 29 | 'start', | ||
1325 | 30 | 'stop', | ||
1326 | 31 | 'upgrade-charm', | ||
1327 | 32 | 'client-relation-joined', | ||
1328 | 33 | 'client-relation-departed', | ||
1329 | 34 | ]) | ||
1330 | 35 | |||
1331 | 36 | |||
1332 | 37 | @hooks.hook('install', 'upgrade-charm') | ||
1333 | 38 | def install(): | ||
1334 | 39 | """Install ansible before running the tasks tagged with 'install'.""" | ||
1335 | 40 | # Allow charm users to run preinstall setup. | ||
1336 | 41 | charmhelpers.payload.execd.execd_preinstall() | ||
1337 | 42 | charmhelpers.contrib.ansible.install_ansible_support( | ||
1338 | 43 | from_ppa=False) | ||
1339 | 44 | |||
1340 | 45 | # We copy the backported ansible modules here because they need to be | ||
1341 | 46 | # in place by the time ansible runs any hook. | ||
1342 | 47 | charmhelpers.core.host.rsync( | ||
1343 | 48 | 'ansible_module_backports', | ||
1344 | 49 | '/usr/share/ansible') | ||
1345 | 50 | |||
1346 | 51 | |||
1347 | 52 | @hooks.hook('data-relation-joined', 'data-relation-changed') | ||
1348 | 53 | def data_relation(): | ||
1349 | 54 | if hookenv.relation_get('mountpoint') == mountpoint: | ||
1350 | 55 | # Other side of relation is ready | ||
1351 | 56 | migrate_to_mount(mountpoint) | ||
1352 | 57 | else: | ||
1353 | 58 | # Other side not ready yet, provide mountpoint | ||
1354 | 59 | hookenv.log('Requesting storage for {}'.format(mountpoint)) | ||
1355 | 60 | hookenv.relation_set(mountpoint=mountpoint) | ||
1356 | 61 | |||
1357 | 62 | |||
1358 | 63 | @hooks.hook('data-relation-departed', 'data-relation-broken') | ||
1359 | 64 | def data_relation_gone(): | ||
1360 | 65 | hookenv.log('Data relation no longer present, stopping elasticsearch.') | ||
1361 | 66 | charmhelpers.core.host.service_stop('elasticsearch') | ||
1362 | 67 | |||
1363 | 68 | |||
1364 | 69 | def migrate_to_mount(new_path): | ||
1365 | 70 | """Invoked when new mountpoint appears. This function safely migrates | ||
1366 | 71 | elasticsearch data from local disk to persistent storage (only if needed) | ||
1367 | 72 | """ | ||
1368 | 73 | old_path = '/var/lib/elasticsearch' | ||
1369 | 74 | if os.path.islink(old_path): | ||
1370 | 75 | hookenv.log('{} is already a symlink, skipping migration'.format( | ||
1371 | 76 | old_path)) | ||
1372 | 77 | return True | ||
1373 | 78 | # Ensure our new mountpoint is empty. Otherwise error and allow | ||
1374 | 79 | # users to investigate and migrate manually | ||
1375 | 80 | files = os.listdir(new_path) | ||
1376 | 81 | try: | ||
1377 | 82 | files.remove('lost+found') | ||
1378 | 83 | except ValueError: | ||
1379 | 84 | pass | ||
1380 | 85 | if files: | ||
1381 | 86 | raise RuntimeError('Persistent storage contains old data. ' | ||
1382 | 87 | 'Please investigate and migrate data manually ' | ||
1383 | 88 | 'to: {}'.format(new_path)) | ||
1384 | 89 | os.chmod(new_path, 0700) | ||
1385 | 90 | charmhelpers.core.host.service_stop('elasticsearch') | ||
1386 | 91 | charmhelpers.core.host.rsync(os.path.join(old_path, ''), # Ensure we have trailing slashes | ||
1387 | 92 | os.path.join(new_path, ''), | ||
1388 | 93 | options=['--archive']) | ||
1389 | 94 | shutil.rmtree(old_path) | ||
1390 | 95 | os.symlink(new_path, old_path) | ||
1391 | 96 | charmhelpers.core.host.service_start('elasticsearch') | ||
1392 | 97 | |||
1393 | 98 | |||
1394 | 99 | if __name__ == "__main__": | ||
1395 | 100 | hooks.execute(sys.argv) | ||
1396 | 0 | 101 | ||
1397 | === modified symlink 'hooks/stop' (properties changed: -x to +x) | |||
1398 | === target was u'hooks.py' | |||
1399 | --- hooks/stop 1970-01-01 00:00:00 +0000 | |||
1400 | +++ hooks/stop 2016-05-04 03:14:14 +0000 | |||
1401 | @@ -0,0 +1,100 @@ | |||
1402 | 1 | #!/usr/bin/env python | ||
1403 | 2 | """Setup hooks for the elasticsearch charm.""" | ||
1404 | 3 | |||
1405 | 4 | import sys | ||
1406 | 5 | import charmhelpers.contrib.ansible | ||
1407 | 6 | import charmhelpers.payload.execd | ||
1408 | 7 | import charmhelpers.core.host | ||
1409 | 8 | from charmhelpers.core import hookenv | ||
1410 | 9 | import os | ||
1411 | 10 | import shutil | ||
1412 | 11 | |||
1413 | 12 | mountpoint = '/srv/elasticsearch' | ||
1414 | 13 | |||
1415 | 14 | hooks = charmhelpers.contrib.ansible.AnsibleHooks( | ||
1416 | 15 | playbook_path='playbook.yaml', | ||
1417 | 16 | default_hooks=[ | ||
1418 | 17 | 'config-changed', | ||
1419 | 18 | 'cluster-relation-joined', | ||
1420 | 19 | 'logs-relation-joined', | ||
1421 | 20 | 'data-relation-joined', | ||
1422 | 21 | 'data-relation-changed', | ||
1423 | 22 | 'data-relation-departed', | ||
1424 | 23 | 'data-relation-broken', | ||
1425 | 24 | 'peer-relation-joined', | ||
1426 | 25 | 'peer-relation-changed', | ||
1427 | 26 | 'peer-relation-departed', | ||
1428 | 27 | 'nrpe-external-master-relation-changed', | ||
1429 | 28 | 'rest-relation-joined', | ||
1430 | 29 | 'start', | ||
1431 | 30 | 'stop', | ||
1432 | 31 | 'upgrade-charm', | ||
1433 | 32 | 'client-relation-joined', | ||
1434 | 33 | 'client-relation-departed', | ||
1435 | 34 | ]) | ||
1436 | 35 | |||
1437 | 36 | |||
1438 | 37 | @hooks.hook('install', 'upgrade-charm') | ||
1439 | 38 | def install(): | ||
1440 | 39 | """Install ansible before running the tasks tagged with 'install'.""" | ||
1441 | 40 | # Allow charm users to run preinstall setup. | ||
1442 | 41 | charmhelpers.payload.execd.execd_preinstall() | ||
1443 | 42 | charmhelpers.contrib.ansible.install_ansible_support( | ||
1444 | 43 | from_ppa=False) | ||
1445 | 44 | |||
1446 | 45 | # We copy the backported ansible modules here because they need to be | ||
1447 | 46 | # in place by the time ansible runs any hook. | ||
1448 | 47 | charmhelpers.core.host.rsync( | ||
1449 | 48 | 'ansible_module_backports', | ||
1450 | 49 | '/usr/share/ansible') | ||
1451 | 50 | |||
1452 | 51 | |||
1453 | 52 | @hooks.hook('data-relation-joined', 'data-relation-changed') | ||
1454 | 53 | def data_relation(): | ||
1455 | 54 | if hookenv.relation_get('mountpoint') == mountpoint: | ||
1456 | 55 | # Other side of relation is ready | ||
1457 | 56 | migrate_to_mount(mountpoint) | ||
1458 | 57 | else: | ||
1459 | 58 | # Other side not ready yet, provide mountpoint | ||
1460 | 59 | hookenv.log('Requesting storage for {}'.format(mountpoint)) | ||
1461 | 60 | hookenv.relation_set(mountpoint=mountpoint) | ||
1462 | 61 | |||
1463 | 62 | |||
1464 | 63 | @hooks.hook('data-relation-departed', 'data-relation-broken') | ||
1465 | 64 | def data_relation_gone(): | ||
1466 | 65 | hookenv.log('Data relation no longer present, stopping elasticsearch.') | ||
1467 | 66 | charmhelpers.core.host.service_stop('elasticsearch') | ||
1468 | 67 | |||
1469 | 68 | |||
1470 | 69 | def migrate_to_mount(new_path): | ||
1471 | 70 | """Invoked when new mountpoint appears. This function safely migrates | ||
1472 | 71 | elasticsearch data from local disk to persistent storage (only if needed) | ||
1473 | 72 | """ | ||
1474 | 73 | old_path = '/var/lib/elasticsearch' | ||
1475 | 74 | if os.path.islink(old_path): | ||
1476 | 75 | hookenv.log('{} is already a symlink, skipping migration'.format( | ||
1477 | 76 | old_path)) | ||
1478 | 77 | return True | ||
1479 | 78 | # Ensure our new mountpoint is empty. Otherwise error and allow | ||
1480 | 79 | # users to investigate and migrate manually | ||
1481 | 80 | files = os.listdir(new_path) | ||
1482 | 81 | try: | ||
1483 | 82 | files.remove('lost+found') | ||
1484 | 83 | except ValueError: | ||
1485 | 84 | pass | ||
1486 | 85 | if files: | ||
1487 | 86 | raise RuntimeError('Persistent storage contains old data. ' | ||
1488 | 87 | 'Please investigate and migrate data manually ' | ||
1489 | 88 | 'to: {}'.format(new_path)) | ||
1490 | 89 | os.chmod(new_path, 0700) | ||
1491 | 90 | charmhelpers.core.host.service_stop('elasticsearch') | ||
1492 | 91 | charmhelpers.core.host.rsync(os.path.join(old_path, ''), # Ensure we have trailing slashes | ||
1493 | 92 | os.path.join(new_path, ''), | ||
1494 | 93 | options=['--archive']) | ||
1495 | 94 | shutil.rmtree(old_path) | ||
1496 | 95 | os.symlink(new_path, old_path) | ||
1497 | 96 | charmhelpers.core.host.service_start('elasticsearch') | ||
1498 | 97 | |||
1499 | 98 | |||
1500 | 99 | if __name__ == "__main__": | ||
1501 | 100 | hooks.execute(sys.argv) | ||
1502 | 0 | 101 | ||
1503 | === modified symlink 'hooks/upgrade-charm' (properties changed: -x to +x) | |||
1504 | === target was u'hooks.py' | |||
1505 | --- hooks/upgrade-charm 1970-01-01 00:00:00 +0000 | |||
1506 | +++ hooks/upgrade-charm 2016-05-04 03:14:14 +0000 | |||
1507 | @@ -0,0 +1,100 @@ | |||
1508 | 1 | #!/usr/bin/env python | ||
1509 | 2 | """Setup hooks for the elasticsearch charm.""" | ||
1510 | 3 | |||
1511 | 4 | import sys | ||
1512 | 5 | import charmhelpers.contrib.ansible | ||
1513 | 6 | import charmhelpers.payload.execd | ||
1514 | 7 | import charmhelpers.core.host | ||
1515 | 8 | from charmhelpers.core import hookenv | ||
1516 | 9 | import os | ||
1517 | 10 | import shutil | ||
1518 | 11 | |||
1519 | 12 | mountpoint = '/srv/elasticsearch' | ||
1520 | 13 | |||
1521 | 14 | hooks = charmhelpers.contrib.ansible.AnsibleHooks( | ||
1522 | 15 | playbook_path='playbook.yaml', | ||
1523 | 16 | default_hooks=[ | ||
1524 | 17 | 'config-changed', | ||
1525 | 18 | 'cluster-relation-joined', | ||
1526 | 19 | 'logs-relation-joined', | ||
1527 | 20 | 'data-relation-joined', | ||
1528 | 21 | 'data-relation-changed', | ||
1529 | 22 | 'data-relation-departed', | ||
1530 | 23 | 'data-relation-broken', | ||
1531 | 24 | 'peer-relation-joined', | ||
1532 | 25 | 'peer-relation-changed', | ||
1533 | 26 | 'peer-relation-departed', | ||
1534 | 27 | 'nrpe-external-master-relation-changed', | ||
1535 | 28 | 'rest-relation-joined', | ||
1536 | 29 | 'start', | ||
1537 | 30 | 'stop', | ||
1538 | 31 | 'upgrade-charm', | ||
1539 | 32 | 'client-relation-joined', | ||
1540 | 33 | 'client-relation-departed', | ||
1541 | 34 | ]) | ||
1542 | 35 | |||
1543 | 36 | |||
1544 | 37 | @hooks.hook('install', 'upgrade-charm') | ||
1545 | 38 | def install(): | ||
1546 | 39 | """Install ansible before running the tasks tagged with 'install'.""" | ||
1547 | 40 | # Allow charm users to run preinstall setup. | ||
1548 | 41 | charmhelpers.payload.execd.execd_preinstall() | ||
1549 | 42 | charmhelpers.contrib.ansible.install_ansible_support( | ||
1550 | 43 | from_ppa=False) | ||
1551 | 44 | |||
1552 | 45 | # We copy the backported ansible modules here because they need to be | ||
1553 | 46 | # in place by the time ansible runs any hook. | ||
1554 | 47 | charmhelpers.core.host.rsync( | ||
1555 | 48 | 'ansible_module_backports', | ||
1556 | 49 | '/usr/share/ansible') | ||
1557 | 50 | |||
1558 | 51 | |||
1559 | 52 | @hooks.hook('data-relation-joined', 'data-relation-changed') | ||
1560 | 53 | def data_relation(): | ||
1561 | 54 | if hookenv.relation_get('mountpoint') == mountpoint: | ||
1562 | 55 | # Other side of relation is ready | ||
1563 | 56 | migrate_to_mount(mountpoint) | ||
1564 | 57 | else: | ||
1565 | 58 | # Other side not ready yet, provide mountpoint | ||
1566 | 59 | hookenv.log('Requesting storage for {}'.format(mountpoint)) | ||
1567 | 60 | hookenv.relation_set(mountpoint=mountpoint) | ||
1568 | 61 | |||
1569 | 62 | |||
1570 | 63 | @hooks.hook('data-relation-departed', 'data-relation-broken') | ||
1571 | 64 | def data_relation_gone(): | ||
1572 | 65 | hookenv.log('Data relation no longer present, stopping elasticsearch.') | ||
1573 | 66 | charmhelpers.core.host.service_stop('elasticsearch') | ||
1574 | 67 | |||
1575 | 68 | |||
1576 | 69 | def migrate_to_mount(new_path): | ||
1577 | 70 | """Invoked when new mountpoint appears. This function safely migrates | ||
1578 | 71 | elasticsearch data from local disk to persistent storage (only if needed) | ||
1579 | 72 | """ | ||
1580 | 73 | old_path = '/var/lib/elasticsearch' | ||
1581 | 74 | if os.path.islink(old_path): | ||
1582 | 75 | hookenv.log('{} is already a symlink, skipping migration'.format( | ||
1583 | 76 | old_path)) | ||
1584 | 77 | return True | ||
1585 | 78 | # Ensure our new mountpoint is empty. Otherwise error and allow | ||
1586 | 79 | # users to investigate and migrate manually | ||
1587 | 80 | files = os.listdir(new_path) | ||
1588 | 81 | try: | ||
1589 | 82 | files.remove('lost+found') | ||
1590 | 83 | except ValueError: | ||
1591 | 84 | pass | ||
1592 | 85 | if files: | ||
1593 | 86 | raise RuntimeError('Persistent storage contains old data. ' | ||
1594 | 87 | 'Please investigate and migrate data manually ' | ||
1595 | 88 | 'to: {}'.format(new_path)) | ||
1596 | 89 | os.chmod(new_path, 0700) | ||
1597 | 90 | charmhelpers.core.host.service_stop('elasticsearch') | ||
1598 | 91 | charmhelpers.core.host.rsync(os.path.join(old_path, ''), # Ensure we have trailing slashes | ||
1599 | 92 | os.path.join(new_path, ''), | ||
1600 | 93 | options=['--archive']) | ||
1601 | 94 | shutil.rmtree(old_path) | ||
1602 | 95 | os.symlink(new_path, old_path) | ||
1603 | 96 | charmhelpers.core.host.service_start('elasticsearch') | ||
1604 | 97 | |||
1605 | 98 | |||
1606 | 99 | if __name__ == "__main__": | ||
1607 | 100 | hooks.execute(sys.argv) | ||
1608 | 0 | 101 | ||
1609 | === removed file 'tests/00-create-index' | |||
1610 | --- tests/00-create-index 2014-10-30 01:02:33 +0000 | |||
1611 | +++ tests/00-create-index 1970-01-01 00:00:00 +0000 | |||
1612 | @@ -1,32 +0,0 @@ | |||
1613 | 1 | #!/usr/bin/python3 | ||
1614 | 2 | import amulet | ||
1615 | 3 | import helpers | ||
1616 | 4 | |||
1617 | 5 | |||
1618 | 6 | d = amulet.Deployment(series='trusty') | ||
1619 | 7 | |||
1620 | 8 | d.add('elasticsearch') | ||
1621 | 9 | |||
1622 | 10 | helpers.setup_deployment(d) | ||
1623 | 11 | |||
1624 | 12 | health = helpers.get_cluster_health(d) | ||
1625 | 13 | |||
1626 | 14 | if health['status'] not in ('green', 'yellow'): | ||
1627 | 15 | msg = "Elastic Search status is %s" % health['status'] | ||
1628 | 16 | amulet.raise_status(amulet.FAIL, msg=msg) | ||
1629 | 17 | |||
1630 | 18 | # Create a test index. | ||
1631 | 19 | curl_command = """ | ||
1632 | 20 | curl -XPUT 'http://localhost:9200/test/tweet/1' -d '{ | ||
1633 | 21 | "user" : "me", | ||
1634 | 22 | "message" : "testing" | ||
1635 | 23 | }' | ||
1636 | 24 | """ | ||
1637 | 25 | response = helpers.curl_on_unit(curl_command, d) | ||
1638 | 26 | |||
1639 | 27 | health = helpers.get_index_health(d, 'test') | ||
1640 | 28 | if health['status'] not in ('green', 'yellow'): | ||
1641 | 29 | msg = "Elastic Search test index status is %s." % health['status'] | ||
1642 | 30 | amulet.raise_status(amulet.FAIL, msg=msg) | ||
1643 | 31 | |||
1644 | 32 | print("Successfully created test index.") | ||
1645 | 33 | 0 | ||
1646 | === added file 'tests/00-single-to-scale-test.py' | |||
1647 | --- tests/00-single-to-scale-test.py 1970-01-01 00:00:00 +0000 | |||
1648 | +++ tests/00-single-to-scale-test.py 2016-05-04 03:14:14 +0000 | |||
1649 | @@ -0,0 +1,112 @@ | |||
1650 | 1 | #!/usr/bin/python3 | ||
1651 | 2 | |||
1652 | 3 | import amulet | ||
1653 | 4 | import unittest | ||
1654 | 5 | import requests | ||
1655 | 6 | import json | ||
1656 | 7 | |||
1657 | 8 | class TestElasticsearch(unittest.TestCase): | ||
1658 | 9 | |||
1659 | 10 | @classmethod | ||
1660 | 11 | def setUpClass(self): | ||
1661 | 12 | self.deployment = amulet.Deployment(series='trusty') | ||
1662 | 13 | self.deployment.add('elasticsearch') | ||
1663 | 14 | self.deployment.configure('elasticsearch', | ||
1664 | 15 | {'cluster-name': 'unique-name'}) | ||
1665 | 16 | |||
1666 | 17 | try: | ||
1667 | 18 | self.deployment.setup(timeout=1200) | ||
1668 | 19 | self.deployment.sentry.wait() | ||
1669 | 20 | except amulet.helpers.TimeoutError: | ||
1670 | 21 | amulet.raise_status( | ||
1671 | 22 | amulet.SKIP, msg="Environment wasn't setup in time") | ||
1672 | 23 | |||
1673 | 24 | |||
1674 | 25 | def test_health(self): | ||
1675 | 26 | ''' Test the health of the node upon first deployment | ||
1676 | 27 | by getting the cluster health, then inserting data and | ||
1677 | 28 | validating cluster health''' | ||
1678 | 29 | health = self.get_cluster_health() | ||
1679 | 30 | assert health['status'] in ('green', 'yellow') | ||
1680 | 31 | |||
1681 | 32 | # Create a test index. | ||
1682 | 33 | curl_command = """ | ||
1683 | 34 | curl -XPUT 'http://localhost:9200/test/tweet/1' -d '{ | ||
1684 | 35 | "user" : "me", | ||
1685 | 36 | "message" : "testing" | ||
1686 | 37 | }' | ||
1687 | 38 | """ | ||
1688 | 39 | response = self.curl_on_unit(curl_command) | ||
1689 | 40 | health = self.get_index_health('test') | ||
1690 | 41 | assert health['status'] in ('green', 'yellow') | ||
1691 | 42 | |||
1692 | 43 | def test_config(self): | ||
1693 | 44 | ''' Validate our configuration of the cluster name made it to the | ||
1694 | 45 | application configuration''' | ||
1695 | 46 | health = self.get_cluster_health() | ||
1696 | 47 | cluster_name = health['cluster_name'] | ||
1697 | 48 | assert cluster_name == 'unique-name' | ||
1698 | 49 | |||
1699 | 50 | def test_scale(self): | ||
1700 | 51 | ''' Validate scaling the elasticsearch cluster yields a healthy | ||
1701 | 52 | response from the API, and all units are participating ''' | ||
1702 | 53 | self.deployment.add_unit('elasticsearch', units=2) | ||
1703 | 54 | self.deployment.setup(timeout=1200) | ||
1704 | 55 | self.deployment.sentry.wait() | ||
1705 | 56 | health = self.get_cluster_health(wait_for_nodes=3) | ||
1706 | 57 | index_health = self.get_index_health('test') | ||
1707 | 58 | print(health['number_of_nodes']) | ||
1708 | 59 | assert health['number_of_nodes'] == 3 | ||
1709 | 60 | assert index_health['status'] in ('green', 'yellow') | ||
1710 | 61 | |||
1711 | 62 | def curl_on_unit(self, curl_command, unit_number=0): | ||
1712 | 63 | unit = "elasticsearch" | ||
1713 | 64 | response = self.deployment.sentry[unit][unit_number].run(curl_command) | ||
1714 | 65 | if response[1] != 0: | ||
1715 | 66 | msg = ( | ||
1716 | 67 | "Elastic search didn't respond to the command \n" | ||
1717 | 68 | "'{curl_command}' as expected.\n" | ||
1718 | 69 | "Return code: {return_code}\n" | ||
1719 | 70 | "Result: {result}".format( | ||
1720 | 71 | curl_command=curl_command, | ||
1721 | 72 | return_code=response[1], | ||
1722 | 73 | result=response[0]) | ||
1723 | 74 | ) | ||
1724 | 75 | amulet.raise_status(amulet.FAIL, msg=msg) | ||
1725 | 76 | |||
1726 | 77 | return json.loads(response[0]) | ||
1727 | 78 | |||
1728 | 79 | def get_cluster_health(self, unit_number=0, wait_for_nodes=0, | ||
1729 | 80 | timeout=180): | ||
1730 | 81 | curl_command = "curl http://localhost:9200" | ||
1731 | 82 | curl_command = curl_command + "/_cluster/health?timeout={}s".format( | ||
1732 | 83 | timeout) | ||
1733 | 84 | if wait_for_nodes > 0: | ||
1734 | 85 | curl_command = curl_command + "&wait_for_nodes={}".format( | ||
1735 | 86 | wait_for_nodes) | ||
1736 | 87 | |||
1737 | 88 | return self.curl_on_unit(curl_command, unit_number=unit_number) | ||
1738 | 89 | |||
1739 | 90 | def get_index_health(self, index_name, unit_number=0): | ||
1740 | 91 | curl_command = "curl http://localhost:9200" | ||
1741 | 92 | curl_command = curl_command + "/_cluster/health/" + index_name | ||
1742 | 93 | |||
1743 | 94 | return self.curl_on_unit(curl_command) | ||
1744 | 95 | |||
1745 | 96 | |||
1746 | 97 | def check_response(response, expected_code=200): | ||
1747 | 98 | if response.status_code != expected_code: | ||
1748 | 99 | msg = ( | ||
1749 | 100 | "Elastic search did not respond as expected. \n" | ||
1750 | 101 | "Expected status code: %{expected_code} \n" | ||
1751 | 102 | "Status code: %{status_code} \n" | ||
1752 | 103 | "Response text: %{response_text}".format( | ||
1753 | 104 | expected_code=expected_code, | ||
1754 | 105 | status_code=response.status_code, | ||
1755 | 106 | response_text=response.text)) | ||
1756 | 107 | |||
1757 | 108 | amulet.raise_status(amulet.FAIL, msg=msg) | ||
1758 | 109 | |||
1759 | 110 | |||
1760 | 111 | if __name__ == "__main__": | ||
1761 | 112 | unittest.main() | ||
1762 | 0 | 113 | ||
1763 | === removed file 'tests/01-config-changes' | |||
1764 | --- tests/01-config-changes 2014-10-30 01:02:33 +0000 | |||
1765 | +++ tests/01-config-changes 1970-01-01 00:00:00 +0000 | |||
1766 | @@ -1,22 +0,0 @@ | |||
1767 | 1 | #!/usr/bin/python3 | ||
1768 | 2 | import amulet | ||
1769 | 3 | import helpers | ||
1770 | 4 | |||
1771 | 5 | d = amulet.Deployment(series='trusty') | ||
1772 | 6 | |||
1773 | 7 | d.add('elasticsearch') | ||
1774 | 8 | config = {'cluster-name': 'unique-name'} | ||
1775 | 9 | d.configure('elasticsearch', config) | ||
1776 | 10 | |||
1777 | 11 | helpers.setup_deployment(d) | ||
1778 | 12 | |||
1779 | 13 | health = helpers.get_cluster_health(d) | ||
1780 | 14 | |||
1781 | 15 | cluster_name = health['cluster_name'] | ||
1782 | 16 | |||
1783 | 17 | if cluster_name != 'unique-name': | ||
1784 | 18 | msg = ("Expected cluster name to be 'unique-name' " | ||
1785 | 19 | "but was '{}'.".format(cluster_name)) | ||
1786 | 20 | amulet.raise_status(amulet.FAIL, msg=msg) | ||
1787 | 21 | |||
1788 | 22 | print("Successfully created cluster with non-default cluster-name.") | ||
1789 | 23 | 0 | ||
1790 | === removed file 'tests/02-deploy-three-units' | |||
1791 | --- tests/02-deploy-three-units 2014-10-30 01:02:33 +0000 | |||
1792 | +++ tests/02-deploy-three-units 1970-01-01 00:00:00 +0000 | |||
1793 | @@ -1,18 +0,0 @@ | |||
1794 | 1 | #!/usr/bin/python3 | ||
1795 | 2 | import amulet | ||
1796 | 3 | import helpers | ||
1797 | 4 | |||
1798 | 5 | d = amulet.Deployment(series='trusty') | ||
1799 | 6 | |||
1800 | 7 | d.add('elasticsearch', units=3) | ||
1801 | 8 | |||
1802 | 9 | helpers.setup_deployment(d) | ||
1803 | 10 | |||
1804 | 11 | health = helpers.get_cluster_health(d, wait_for_nodes=3) | ||
1805 | 12 | |||
1806 | 13 | if health['number_of_nodes'] != 3: | ||
1807 | 14 | amulet.raise_status(amulet.FAIL, msg=msg) | ||
1808 | 15 | msg = ("Expected at least 3 nodes in cluster with 3 units deployed, " | ||
1809 | 16 | "got {}".format(health['number_of_nodes'])) | ||
1810 | 17 | |||
1811 | 18 | print("Successfully deployed cluster of 3 units.") | ||
1812 | 19 | 0 | ||
1813 | === removed file 'tests/__init__.py' | |||
1814 | === removed directory 'tests/helpers' | |||
1815 | === removed file 'tests/helpers/__init__.py' | |||
1816 | --- tests/helpers/__init__.py 2014-10-30 01:02:33 +0000 | |||
1817 | +++ tests/helpers/__init__.py 1970-01-01 00:00:00 +0000 | |||
1818 | @@ -1,64 +0,0 @@ | |||
1819 | 1 | import amulet | ||
1820 | 2 | import json | ||
1821 | 3 | |||
1822 | 4 | |||
1823 | 5 | def check_response(response, expected_code=200): | ||
1824 | 6 | if response.status_code != expected_code: | ||
1825 | 7 | msg = ( | ||
1826 | 8 | "Elastic search did not respond as expected. \n" | ||
1827 | 9 | "Expected status code: %{expected_code} \n" | ||
1828 | 10 | "Status code: %{status_code} \n" | ||
1829 | 11 | "Response text: %{response_text}".format( | ||
1830 | 12 | expected_code=expected_code, | ||
1831 | 13 | status_code=response.status_code, | ||
1832 | 14 | response_text=response.text)) | ||
1833 | 15 | |||
1834 | 16 | amulet.raise_status(amulet.FAIL, msg=msg) | ||
1835 | 17 | |||
1836 | 18 | |||
1837 | 19 | def curl_on_unit(curl_command, deployment, unit_number=0): | ||
1838 | 20 | unit = "elasticsearch/{}".format(unit_number) | ||
1839 | 21 | |||
1840 | 22 | response = deployment.sentry.unit[unit].run(curl_command) | ||
1841 | 23 | if response[1] != 0: | ||
1842 | 24 | msg = ( | ||
1843 | 25 | "Elastic search didn't respond to the command \n" | ||
1844 | 26 | "'{curl_command}' as expected.\n" | ||
1845 | 27 | "Return code: {return_code}\n" | ||
1846 | 28 | "Result: {result}".format( | ||
1847 | 29 | curl_command=curl_command, | ||
1848 | 30 | return_code=response[1], | ||
1849 | 31 | result=response[0]) | ||
1850 | 32 | ) | ||
1851 | 33 | amulet.raise_status(amulet.FAIL, msg=msg) | ||
1852 | 34 | |||
1853 | 35 | return json.loads(response[0]) | ||
1854 | 36 | |||
1855 | 37 | |||
1856 | 38 | def setup_deployment(deployment, timeout=900): | ||
1857 | 39 | """Setup the deployment and wait until installed.""" | ||
1858 | 40 | try: | ||
1859 | 41 | deployment.setup(timeout=timeout) | ||
1860 | 42 | deployment.sentry.wait() | ||
1861 | 43 | except amulet.helpers.TimeoutError: | ||
1862 | 44 | amulet.raise_status( | ||
1863 | 45 | amulet.SKIP, msg="Environment wasn't setup in time") | ||
1864 | 46 | |||
1865 | 47 | |||
1866 | 48 | def get_cluster_health(deployment, unit_number=0, wait_for_nodes=0, | ||
1867 | 49 | timeout=180): | ||
1868 | 50 | curl_command = "curl http://localhost:9200" | ||
1869 | 51 | curl_command = curl_command + "/_cluster/health?timeout={}s".format( | ||
1870 | 52 | timeout) | ||
1871 | 53 | if wait_for_nodes > 0: | ||
1872 | 54 | curl_command = curl_command + "&wait_for_nodes={}".format( | ||
1873 | 55 | wait_for_nodes) | ||
1874 | 56 | |||
1875 | 57 | return curl_on_unit(curl_command, deployment, unit_number=unit_number) | ||
1876 | 58 | |||
1877 | 59 | |||
1878 | 60 | def get_index_health(deployment, index_name, unit_number=0): | ||
1879 | 61 | curl_command = "curl http://localhost:9200" | ||
1880 | 62 | curl_command = curl_command + "/_cluster/health/" + index_name | ||
1881 | 63 | |||
1882 | 64 | return curl_on_unit(curl_command, deployment) | ||
1883 | 65 | 0 | ||
1884 | === added file 'tests/tests.yaml' | |||
1885 | --- tests/tests.yaml 1970-01-01 00:00:00 +0000 | |||
1886 | +++ tests/tests.yaml 2016-05-04 03:14:14 +0000 | |||
1887 | @@ -0,0 +1,2 @@ | |||
1888 | 1 | packages: | ||
1889 | 2 | - python3-amulet |
Looks good, +1
Note: the +x changes on symlinks are a little weird, but harmless.