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

Looks good, +1
Note: the +x changes on symlinks are a little weird, but harmless.