Merge lp:~lazypower/charms/trusty/elasticsearch/amulet-test-bump into lp:charms/trusty/elasticsearch

Proposed by Charles Butler
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
Reviewer Review Type Date Requested Status
Chris Glass (community) Approve
Review via email: mp+293703@code.launchpad.net

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-single-to-scale-test.py PASS

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.

To post a comment you must log in.
Revision history for this message
Chris Glass (tribaal) wrote :

Looks good, +1

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

review: Approve

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

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified symlink 'hooks/client-relation-departed' (properties changed: -x to +x)
=== target was u'hooks.py'
--- hooks/client-relation-departed 1970-01-01 00:00:00 +0000
+++ hooks/client-relation-departed 2016-05-04 03:14:14 +0000
@@ -0,0 +1,100 @@
1#!/usr/bin/env python
2"""Setup hooks for the elasticsearch charm."""
3
4import sys
5import charmhelpers.contrib.ansible
6import charmhelpers.payload.execd
7import charmhelpers.core.host
8from charmhelpers.core import hookenv
9import os
10import shutil
11
12mountpoint = '/srv/elasticsearch'
13
14hooks = charmhelpers.contrib.ansible.AnsibleHooks(
15 playbook_path='playbook.yaml',
16 default_hooks=[
17 'config-changed',
18 'cluster-relation-joined',
19 'logs-relation-joined',
20 'data-relation-joined',
21 'data-relation-changed',
22 'data-relation-departed',
23 'data-relation-broken',
24 'peer-relation-joined',
25 'peer-relation-changed',
26 'peer-relation-departed',
27 'nrpe-external-master-relation-changed',
28 'rest-relation-joined',
29 'start',
30 'stop',
31 'upgrade-charm',
32 'client-relation-joined',
33 'client-relation-departed',
34 ])
35
36
37@hooks.hook('install', 'upgrade-charm')
38def install():
39 """Install ansible before running the tasks tagged with 'install'."""
40 # Allow charm users to run preinstall setup.
41 charmhelpers.payload.execd.execd_preinstall()
42 charmhelpers.contrib.ansible.install_ansible_support(
43 from_ppa=False)
44
45 # We copy the backported ansible modules here because they need to be
46 # in place by the time ansible runs any hook.
47 charmhelpers.core.host.rsync(
48 'ansible_module_backports',
49 '/usr/share/ansible')
50
51
52@hooks.hook('data-relation-joined', 'data-relation-changed')
53def data_relation():
54 if hookenv.relation_get('mountpoint') == mountpoint:
55 # Other side of relation is ready
56 migrate_to_mount(mountpoint)
57 else:
58 # Other side not ready yet, provide mountpoint
59 hookenv.log('Requesting storage for {}'.format(mountpoint))
60 hookenv.relation_set(mountpoint=mountpoint)
61
62
63@hooks.hook('data-relation-departed', 'data-relation-broken')
64def data_relation_gone():
65 hookenv.log('Data relation no longer present, stopping elasticsearch.')
66 charmhelpers.core.host.service_stop('elasticsearch')
67
68
69def migrate_to_mount(new_path):
70 """Invoked when new mountpoint appears. This function safely migrates
71 elasticsearch data from local disk to persistent storage (only if needed)
72 """
73 old_path = '/var/lib/elasticsearch'
74 if os.path.islink(old_path):
75 hookenv.log('{} is already a symlink, skipping migration'.format(
76 old_path))
77 return True
78 # Ensure our new mountpoint is empty. Otherwise error and allow
79 # users to investigate and migrate manually
80 files = os.listdir(new_path)
81 try:
82 files.remove('lost+found')
83 except ValueError:
84 pass
85 if files:
86 raise RuntimeError('Persistent storage contains old data. '
87 'Please investigate and migrate data manually '
88 'to: {}'.format(new_path))
89 os.chmod(new_path, 0700)
90 charmhelpers.core.host.service_stop('elasticsearch')
91 charmhelpers.core.host.rsync(os.path.join(old_path, ''), # Ensure we have trailing slashes
92 os.path.join(new_path, ''),
93 options=['--archive'])
94 shutil.rmtree(old_path)
95 os.symlink(new_path, old_path)
96 charmhelpers.core.host.service_start('elasticsearch')
97
98
99if __name__ == "__main__":
100 hooks.execute(sys.argv)
0101
=== modified symlink 'hooks/client-relation-joined' (properties changed: -x to +x)
=== target was u'hooks.py'
--- hooks/client-relation-joined 1970-01-01 00:00:00 +0000
+++ hooks/client-relation-joined 2016-05-04 03:14:14 +0000
@@ -0,0 +1,100 @@
1#!/usr/bin/env python
2"""Setup hooks for the elasticsearch charm."""
3
4import sys
5import charmhelpers.contrib.ansible
6import charmhelpers.payload.execd
7import charmhelpers.core.host
8from charmhelpers.core import hookenv
9import os
10import shutil
11
12mountpoint = '/srv/elasticsearch'
13
14hooks = charmhelpers.contrib.ansible.AnsibleHooks(
15 playbook_path='playbook.yaml',
16 default_hooks=[
17 'config-changed',
18 'cluster-relation-joined',
19 'logs-relation-joined',
20 'data-relation-joined',
21 'data-relation-changed',
22 'data-relation-departed',
23 'data-relation-broken',
24 'peer-relation-joined',
25 'peer-relation-changed',
26 'peer-relation-departed',
27 'nrpe-external-master-relation-changed',
28 'rest-relation-joined',
29 'start',
30 'stop',
31 'upgrade-charm',
32 'client-relation-joined',
33 'client-relation-departed',
34 ])
35
36
37@hooks.hook('install', 'upgrade-charm')
38def install():
39 """Install ansible before running the tasks tagged with 'install'."""
40 # Allow charm users to run preinstall setup.
41 charmhelpers.payload.execd.execd_preinstall()
42 charmhelpers.contrib.ansible.install_ansible_support(
43 from_ppa=False)
44
45 # We copy the backported ansible modules here because they need to be
46 # in place by the time ansible runs any hook.
47 charmhelpers.core.host.rsync(
48 'ansible_module_backports',
49 '/usr/share/ansible')
50
51
52@hooks.hook('data-relation-joined', 'data-relation-changed')
53def data_relation():
54 if hookenv.relation_get('mountpoint') == mountpoint:
55 # Other side of relation is ready
56 migrate_to_mount(mountpoint)
57 else:
58 # Other side not ready yet, provide mountpoint
59 hookenv.log('Requesting storage for {}'.format(mountpoint))
60 hookenv.relation_set(mountpoint=mountpoint)
61
62
63@hooks.hook('data-relation-departed', 'data-relation-broken')
64def data_relation_gone():
65 hookenv.log('Data relation no longer present, stopping elasticsearch.')
66 charmhelpers.core.host.service_stop('elasticsearch')
67
68
69def migrate_to_mount(new_path):
70 """Invoked when new mountpoint appears. This function safely migrates
71 elasticsearch data from local disk to persistent storage (only if needed)
72 """
73 old_path = '/var/lib/elasticsearch'
74 if os.path.islink(old_path):
75 hookenv.log('{} is already a symlink, skipping migration'.format(
76 old_path))
77 return True
78 # Ensure our new mountpoint is empty. Otherwise error and allow
79 # users to investigate and migrate manually
80 files = os.listdir(new_path)
81 try:
82 files.remove('lost+found')
83 except ValueError:
84 pass
85 if files:
86 raise RuntimeError('Persistent storage contains old data. '
87 'Please investigate and migrate data manually '
88 'to: {}'.format(new_path))
89 os.chmod(new_path, 0700)
90 charmhelpers.core.host.service_stop('elasticsearch')
91 charmhelpers.core.host.rsync(os.path.join(old_path, ''), # Ensure we have trailing slashes
92 os.path.join(new_path, ''),
93 options=['--archive'])
94 shutil.rmtree(old_path)
95 os.symlink(new_path, old_path)
96 charmhelpers.core.host.service_start('elasticsearch')
97
98
99if __name__ == "__main__":
100 hooks.execute(sys.argv)
0101
=== modified symlink 'hooks/config-changed' (properties changed: -x to +x)
=== target was u'hooks.py'
--- hooks/config-changed 1970-01-01 00:00:00 +0000
+++ hooks/config-changed 2016-05-04 03:14:14 +0000
@@ -0,0 +1,100 @@
1#!/usr/bin/env python
2"""Setup hooks for the elasticsearch charm."""
3
4import sys
5import charmhelpers.contrib.ansible
6import charmhelpers.payload.execd
7import charmhelpers.core.host
8from charmhelpers.core import hookenv
9import os
10import shutil
11
12mountpoint = '/srv/elasticsearch'
13
14hooks = charmhelpers.contrib.ansible.AnsibleHooks(
15 playbook_path='playbook.yaml',
16 default_hooks=[
17 'config-changed',
18 'cluster-relation-joined',
19 'logs-relation-joined',
20 'data-relation-joined',
21 'data-relation-changed',
22 'data-relation-departed',
23 'data-relation-broken',
24 'peer-relation-joined',
25 'peer-relation-changed',
26 'peer-relation-departed',
27 'nrpe-external-master-relation-changed',
28 'rest-relation-joined',
29 'start',
30 'stop',
31 'upgrade-charm',
32 'client-relation-joined',
33 'client-relation-departed',
34 ])
35
36
37@hooks.hook('install', 'upgrade-charm')
38def install():
39 """Install ansible before running the tasks tagged with 'install'."""
40 # Allow charm users to run preinstall setup.
41 charmhelpers.payload.execd.execd_preinstall()
42 charmhelpers.contrib.ansible.install_ansible_support(
43 from_ppa=False)
44
45 # We copy the backported ansible modules here because they need to be
46 # in place by the time ansible runs any hook.
47 charmhelpers.core.host.rsync(
48 'ansible_module_backports',
49 '/usr/share/ansible')
50
51
52@hooks.hook('data-relation-joined', 'data-relation-changed')
53def data_relation():
54 if hookenv.relation_get('mountpoint') == mountpoint:
55 # Other side of relation is ready
56 migrate_to_mount(mountpoint)
57 else:
58 # Other side not ready yet, provide mountpoint
59 hookenv.log('Requesting storage for {}'.format(mountpoint))
60 hookenv.relation_set(mountpoint=mountpoint)
61
62
63@hooks.hook('data-relation-departed', 'data-relation-broken')
64def data_relation_gone():
65 hookenv.log('Data relation no longer present, stopping elasticsearch.')
66 charmhelpers.core.host.service_stop('elasticsearch')
67
68
69def migrate_to_mount(new_path):
70 """Invoked when new mountpoint appears. This function safely migrates
71 elasticsearch data from local disk to persistent storage (only if needed)
72 """
73 old_path = '/var/lib/elasticsearch'
74 if os.path.islink(old_path):
75 hookenv.log('{} is already a symlink, skipping migration'.format(
76 old_path))
77 return True
78 # Ensure our new mountpoint is empty. Otherwise error and allow
79 # users to investigate and migrate manually
80 files = os.listdir(new_path)
81 try:
82 files.remove('lost+found')
83 except ValueError:
84 pass
85 if files:
86 raise RuntimeError('Persistent storage contains old data. '
87 'Please investigate and migrate data manually '
88 'to: {}'.format(new_path))
89 os.chmod(new_path, 0700)
90 charmhelpers.core.host.service_stop('elasticsearch')
91 charmhelpers.core.host.rsync(os.path.join(old_path, ''), # Ensure we have trailing slashes
92 os.path.join(new_path, ''),
93 options=['--archive'])
94 shutil.rmtree(old_path)
95 os.symlink(new_path, old_path)
96 charmhelpers.core.host.service_start('elasticsearch')
97
98
99if __name__ == "__main__":
100 hooks.execute(sys.argv)
0101
=== modified symlink 'hooks/data-relation-changed' (properties changed: -x to +x)
=== target was u'hooks.py'
--- hooks/data-relation-changed 1970-01-01 00:00:00 +0000
+++ hooks/data-relation-changed 2016-05-04 03:14:14 +0000
@@ -0,0 +1,100 @@
1#!/usr/bin/env python
2"""Setup hooks for the elasticsearch charm."""
3
4import sys
5import charmhelpers.contrib.ansible
6import charmhelpers.payload.execd
7import charmhelpers.core.host
8from charmhelpers.core import hookenv
9import os
10import shutil
11
12mountpoint = '/srv/elasticsearch'
13
14hooks = charmhelpers.contrib.ansible.AnsibleHooks(
15 playbook_path='playbook.yaml',
16 default_hooks=[
17 'config-changed',
18 'cluster-relation-joined',
19 'logs-relation-joined',
20 'data-relation-joined',
21 'data-relation-changed',
22 'data-relation-departed',
23 'data-relation-broken',
24 'peer-relation-joined',
25 'peer-relation-changed',
26 'peer-relation-departed',
27 'nrpe-external-master-relation-changed',
28 'rest-relation-joined',
29 'start',
30 'stop',
31 'upgrade-charm',
32 'client-relation-joined',
33 'client-relation-departed',
34 ])
35
36
37@hooks.hook('install', 'upgrade-charm')
38def install():
39 """Install ansible before running the tasks tagged with 'install'."""
40 # Allow charm users to run preinstall setup.
41 charmhelpers.payload.execd.execd_preinstall()
42 charmhelpers.contrib.ansible.install_ansible_support(
43 from_ppa=False)
44
45 # We copy the backported ansible modules here because they need to be
46 # in place by the time ansible runs any hook.
47 charmhelpers.core.host.rsync(
48 'ansible_module_backports',
49 '/usr/share/ansible')
50
51
52@hooks.hook('data-relation-joined', 'data-relation-changed')
53def data_relation():
54 if hookenv.relation_get('mountpoint') == mountpoint:
55 # Other side of relation is ready
56 migrate_to_mount(mountpoint)
57 else:
58 # Other side not ready yet, provide mountpoint
59 hookenv.log('Requesting storage for {}'.format(mountpoint))
60 hookenv.relation_set(mountpoint=mountpoint)
61
62
63@hooks.hook('data-relation-departed', 'data-relation-broken')
64def data_relation_gone():
65 hookenv.log('Data relation no longer present, stopping elasticsearch.')
66 charmhelpers.core.host.service_stop('elasticsearch')
67
68
69def migrate_to_mount(new_path):
70 """Invoked when new mountpoint appears. This function safely migrates
71 elasticsearch data from local disk to persistent storage (only if needed)
72 """
73 old_path = '/var/lib/elasticsearch'
74 if os.path.islink(old_path):
75 hookenv.log('{} is already a symlink, skipping migration'.format(
76 old_path))
77 return True
78 # Ensure our new mountpoint is empty. Otherwise error and allow
79 # users to investigate and migrate manually
80 files = os.listdir(new_path)
81 try:
82 files.remove('lost+found')
83 except ValueError:
84 pass
85 if files:
86 raise RuntimeError('Persistent storage contains old data. '
87 'Please investigate and migrate data manually '
88 'to: {}'.format(new_path))
89 os.chmod(new_path, 0700)
90 charmhelpers.core.host.service_stop('elasticsearch')
91 charmhelpers.core.host.rsync(os.path.join(old_path, ''), # Ensure we have trailing slashes
92 os.path.join(new_path, ''),
93 options=['--archive'])
94 shutil.rmtree(old_path)
95 os.symlink(new_path, old_path)
96 charmhelpers.core.host.service_start('elasticsearch')
97
98
99if __name__ == "__main__":
100 hooks.execute(sys.argv)
0101
=== modified symlink 'hooks/data-relation-departed' (properties changed: -x to +x)
=== target was u'hooks.py'
--- hooks/data-relation-departed 1970-01-01 00:00:00 +0000
+++ hooks/data-relation-departed 2016-05-04 03:14:14 +0000
@@ -0,0 +1,100 @@
1#!/usr/bin/env python
2"""Setup hooks for the elasticsearch charm."""
3
4import sys
5import charmhelpers.contrib.ansible
6import charmhelpers.payload.execd
7import charmhelpers.core.host
8from charmhelpers.core import hookenv
9import os
10import shutil
11
12mountpoint = '/srv/elasticsearch'
13
14hooks = charmhelpers.contrib.ansible.AnsibleHooks(
15 playbook_path='playbook.yaml',
16 default_hooks=[
17 'config-changed',
18 'cluster-relation-joined',
19 'logs-relation-joined',
20 'data-relation-joined',
21 'data-relation-changed',
22 'data-relation-departed',
23 'data-relation-broken',
24 'peer-relation-joined',
25 'peer-relation-changed',
26 'peer-relation-departed',
27 'nrpe-external-master-relation-changed',
28 'rest-relation-joined',
29 'start',
30 'stop',
31 'upgrade-charm',
32 'client-relation-joined',
33 'client-relation-departed',
34 ])
35
36
37@hooks.hook('install', 'upgrade-charm')
38def install():
39 """Install ansible before running the tasks tagged with 'install'."""
40 # Allow charm users to run preinstall setup.
41 charmhelpers.payload.execd.execd_preinstall()
42 charmhelpers.contrib.ansible.install_ansible_support(
43 from_ppa=False)
44
45 # We copy the backported ansible modules here because they need to be
46 # in place by the time ansible runs any hook.
47 charmhelpers.core.host.rsync(
48 'ansible_module_backports',
49 '/usr/share/ansible')
50
51
52@hooks.hook('data-relation-joined', 'data-relation-changed')
53def data_relation():
54 if hookenv.relation_get('mountpoint') == mountpoint:
55 # Other side of relation is ready
56 migrate_to_mount(mountpoint)
57 else:
58 # Other side not ready yet, provide mountpoint
59 hookenv.log('Requesting storage for {}'.format(mountpoint))
60 hookenv.relation_set(mountpoint=mountpoint)
61
62
63@hooks.hook('data-relation-departed', 'data-relation-broken')
64def data_relation_gone():
65 hookenv.log('Data relation no longer present, stopping elasticsearch.')
66 charmhelpers.core.host.service_stop('elasticsearch')
67
68
69def migrate_to_mount(new_path):
70 """Invoked when new mountpoint appears. This function safely migrates
71 elasticsearch data from local disk to persistent storage (only if needed)
72 """
73 old_path = '/var/lib/elasticsearch'
74 if os.path.islink(old_path):
75 hookenv.log('{} is already a symlink, skipping migration'.format(
76 old_path))
77 return True
78 # Ensure our new mountpoint is empty. Otherwise error and allow
79 # users to investigate and migrate manually
80 files = os.listdir(new_path)
81 try:
82 files.remove('lost+found')
83 except ValueError:
84 pass
85 if files:
86 raise RuntimeError('Persistent storage contains old data. '
87 'Please investigate and migrate data manually '
88 'to: {}'.format(new_path))
89 os.chmod(new_path, 0700)
90 charmhelpers.core.host.service_stop('elasticsearch')
91 charmhelpers.core.host.rsync(os.path.join(old_path, ''), # Ensure we have trailing slashes
92 os.path.join(new_path, ''),
93 options=['--archive'])
94 shutil.rmtree(old_path)
95 os.symlink(new_path, old_path)
96 charmhelpers.core.host.service_start('elasticsearch')
97
98
99if __name__ == "__main__":
100 hooks.execute(sys.argv)
0101
=== modified symlink 'hooks/data-relation-joined' (properties changed: -x to +x)
=== target was u'hooks.py'
--- hooks/data-relation-joined 1970-01-01 00:00:00 +0000
+++ hooks/data-relation-joined 2016-05-04 03:14:14 +0000
@@ -0,0 +1,100 @@
1#!/usr/bin/env python
2"""Setup hooks for the elasticsearch charm."""
3
4import sys
5import charmhelpers.contrib.ansible
6import charmhelpers.payload.execd
7import charmhelpers.core.host
8from charmhelpers.core import hookenv
9import os
10import shutil
11
12mountpoint = '/srv/elasticsearch'
13
14hooks = charmhelpers.contrib.ansible.AnsibleHooks(
15 playbook_path='playbook.yaml',
16 default_hooks=[
17 'config-changed',
18 'cluster-relation-joined',
19 'logs-relation-joined',
20 'data-relation-joined',
21 'data-relation-changed',
22 'data-relation-departed',
23 'data-relation-broken',
24 'peer-relation-joined',
25 'peer-relation-changed',
26 'peer-relation-departed',
27 'nrpe-external-master-relation-changed',
28 'rest-relation-joined',
29 'start',
30 'stop',
31 'upgrade-charm',
32 'client-relation-joined',
33 'client-relation-departed',
34 ])
35
36
37@hooks.hook('install', 'upgrade-charm')
38def install():
39 """Install ansible before running the tasks tagged with 'install'."""
40 # Allow charm users to run preinstall setup.
41 charmhelpers.payload.execd.execd_preinstall()
42 charmhelpers.contrib.ansible.install_ansible_support(
43 from_ppa=False)
44
45 # We copy the backported ansible modules here because they need to be
46 # in place by the time ansible runs any hook.
47 charmhelpers.core.host.rsync(
48 'ansible_module_backports',
49 '/usr/share/ansible')
50
51
52@hooks.hook('data-relation-joined', 'data-relation-changed')
53def data_relation():
54 if hookenv.relation_get('mountpoint') == mountpoint:
55 # Other side of relation is ready
56 migrate_to_mount(mountpoint)
57 else:
58 # Other side not ready yet, provide mountpoint
59 hookenv.log('Requesting storage for {}'.format(mountpoint))
60 hookenv.relation_set(mountpoint=mountpoint)
61
62
63@hooks.hook('data-relation-departed', 'data-relation-broken')
64def data_relation_gone():
65 hookenv.log('Data relation no longer present, stopping elasticsearch.')
66 charmhelpers.core.host.service_stop('elasticsearch')
67
68
69def migrate_to_mount(new_path):
70 """Invoked when new mountpoint appears. This function safely migrates
71 elasticsearch data from local disk to persistent storage (only if needed)
72 """
73 old_path = '/var/lib/elasticsearch'
74 if os.path.islink(old_path):
75 hookenv.log('{} is already a symlink, skipping migration'.format(
76 old_path))
77 return True
78 # Ensure our new mountpoint is empty. Otherwise error and allow
79 # users to investigate and migrate manually
80 files = os.listdir(new_path)
81 try:
82 files.remove('lost+found')
83 except ValueError:
84 pass
85 if files:
86 raise RuntimeError('Persistent storage contains old data. '
87 'Please investigate and migrate data manually '
88 'to: {}'.format(new_path))
89 os.chmod(new_path, 0700)
90 charmhelpers.core.host.service_stop('elasticsearch')
91 charmhelpers.core.host.rsync(os.path.join(old_path, ''), # Ensure we have trailing slashes
92 os.path.join(new_path, ''),
93 options=['--archive'])
94 shutil.rmtree(old_path)
95 os.symlink(new_path, old_path)
96 charmhelpers.core.host.service_start('elasticsearch')
97
98
99if __name__ == "__main__":
100 hooks.execute(sys.argv)
0101
=== modified file 'hooks/hooks.py'
--- hooks/hooks.py 2015-10-27 22:30:30 +0000
+++ hooks/hooks.py 2016-05-04 03:14:14 +0000
@@ -88,9 +88,10 @@
88 'to: {}'.format(new_path))88 'to: {}'.format(new_path))
89 os.chmod(new_path, 0700)89 os.chmod(new_path, 0700)
90 charmhelpers.core.host.service_stop('elasticsearch')90 charmhelpers.core.host.service_stop('elasticsearch')
91 charmhelpers.core.host.rsync(os.path.join(old_path, ''), # Ensure we have trailing slashes91 # Ensure we have trailing slashes
92 os.path.join(new_path, ''),92 charmhelpers.core.host.rsync(os.path.join(old_path, ''),
93 options=['--archive'])93 os.path.join(new_path, ''),
94 options=['--archive'])
94 shutil.rmtree(old_path)95 shutil.rmtree(old_path)
95 os.symlink(new_path, old_path)96 os.symlink(new_path, old_path)
96 charmhelpers.core.host.service_start('elasticsearch')97 charmhelpers.core.host.service_start('elasticsearch')
9798
=== modified symlink 'hooks/install' (properties changed: -x to +x)
=== target was u'hooks.py'
--- hooks/install 1970-01-01 00:00:00 +0000
+++ hooks/install 2016-05-04 03:14:14 +0000
@@ -0,0 +1,100 @@
1#!/usr/bin/env python
2"""Setup hooks for the elasticsearch charm."""
3
4import sys
5import charmhelpers.contrib.ansible
6import charmhelpers.payload.execd
7import charmhelpers.core.host
8from charmhelpers.core import hookenv
9import os
10import shutil
11
12mountpoint = '/srv/elasticsearch'
13
14hooks = charmhelpers.contrib.ansible.AnsibleHooks(
15 playbook_path='playbook.yaml',
16 default_hooks=[
17 'config-changed',
18 'cluster-relation-joined',
19 'logs-relation-joined',
20 'data-relation-joined',
21 'data-relation-changed',
22 'data-relation-departed',
23 'data-relation-broken',
24 'peer-relation-joined',
25 'peer-relation-changed',
26 'peer-relation-departed',
27 'nrpe-external-master-relation-changed',
28 'rest-relation-joined',
29 'start',
30 'stop',
31 'upgrade-charm',
32 'client-relation-joined',
33 'client-relation-departed',
34 ])
35
36
37@hooks.hook('install', 'upgrade-charm')
38def install():
39 """Install ansible before running the tasks tagged with 'install'."""
40 # Allow charm users to run preinstall setup.
41 charmhelpers.payload.execd.execd_preinstall()
42 charmhelpers.contrib.ansible.install_ansible_support(
43 from_ppa=False)
44
45 # We copy the backported ansible modules here because they need to be
46 # in place by the time ansible runs any hook.
47 charmhelpers.core.host.rsync(
48 'ansible_module_backports',
49 '/usr/share/ansible')
50
51
52@hooks.hook('data-relation-joined', 'data-relation-changed')
53def data_relation():
54 if hookenv.relation_get('mountpoint') == mountpoint:
55 # Other side of relation is ready
56 migrate_to_mount(mountpoint)
57 else:
58 # Other side not ready yet, provide mountpoint
59 hookenv.log('Requesting storage for {}'.format(mountpoint))
60 hookenv.relation_set(mountpoint=mountpoint)
61
62
63@hooks.hook('data-relation-departed', 'data-relation-broken')
64def data_relation_gone():
65 hookenv.log('Data relation no longer present, stopping elasticsearch.')
66 charmhelpers.core.host.service_stop('elasticsearch')
67
68
69def migrate_to_mount(new_path):
70 """Invoked when new mountpoint appears. This function safely migrates
71 elasticsearch data from local disk to persistent storage (only if needed)
72 """
73 old_path = '/var/lib/elasticsearch'
74 if os.path.islink(old_path):
75 hookenv.log('{} is already a symlink, skipping migration'.format(
76 old_path))
77 return True
78 # Ensure our new mountpoint is empty. Otherwise error and allow
79 # users to investigate and migrate manually
80 files = os.listdir(new_path)
81 try:
82 files.remove('lost+found')
83 except ValueError:
84 pass
85 if files:
86 raise RuntimeError('Persistent storage contains old data. '
87 'Please investigate and migrate data manually '
88 'to: {}'.format(new_path))
89 os.chmod(new_path, 0700)
90 charmhelpers.core.host.service_stop('elasticsearch')
91 charmhelpers.core.host.rsync(os.path.join(old_path, ''), # Ensure we have trailing slashes
92 os.path.join(new_path, ''),
93 options=['--archive'])
94 shutil.rmtree(old_path)
95 os.symlink(new_path, old_path)
96 charmhelpers.core.host.service_start('elasticsearch')
97
98
99if __name__ == "__main__":
100 hooks.execute(sys.argv)
0101
=== modified symlink 'hooks/logs-relation-joined' (properties changed: -x to +x)
=== target was u'hooks.py'
--- hooks/logs-relation-joined 1970-01-01 00:00:00 +0000
+++ hooks/logs-relation-joined 2016-05-04 03:14:14 +0000
@@ -0,0 +1,100 @@
1#!/usr/bin/env python
2"""Setup hooks for the elasticsearch charm."""
3
4import sys
5import charmhelpers.contrib.ansible
6import charmhelpers.payload.execd
7import charmhelpers.core.host
8from charmhelpers.core import hookenv
9import os
10import shutil
11
12mountpoint = '/srv/elasticsearch'
13
14hooks = charmhelpers.contrib.ansible.AnsibleHooks(
15 playbook_path='playbook.yaml',
16 default_hooks=[
17 'config-changed',
18 'cluster-relation-joined',
19 'logs-relation-joined',
20 'data-relation-joined',
21 'data-relation-changed',
22 'data-relation-departed',
23 'data-relation-broken',
24 'peer-relation-joined',
25 'peer-relation-changed',
26 'peer-relation-departed',
27 'nrpe-external-master-relation-changed',
28 'rest-relation-joined',
29 'start',
30 'stop',
31 'upgrade-charm',
32 'client-relation-joined',
33 'client-relation-departed',
34 ])
35
36
37@hooks.hook('install', 'upgrade-charm')
38def install():
39 """Install ansible before running the tasks tagged with 'install'."""
40 # Allow charm users to run preinstall setup.
41 charmhelpers.payload.execd.execd_preinstall()
42 charmhelpers.contrib.ansible.install_ansible_support(
43 from_ppa=False)
44
45 # We copy the backported ansible modules here because they need to be
46 # in place by the time ansible runs any hook.
47 charmhelpers.core.host.rsync(
48 'ansible_module_backports',
49 '/usr/share/ansible')
50
51
52@hooks.hook('data-relation-joined', 'data-relation-changed')
53def data_relation():
54 if hookenv.relation_get('mountpoint') == mountpoint:
55 # Other side of relation is ready
56 migrate_to_mount(mountpoint)
57 else:
58 # Other side not ready yet, provide mountpoint
59 hookenv.log('Requesting storage for {}'.format(mountpoint))
60 hookenv.relation_set(mountpoint=mountpoint)
61
62
63@hooks.hook('data-relation-departed', 'data-relation-broken')
64def data_relation_gone():
65 hookenv.log('Data relation no longer present, stopping elasticsearch.')
66 charmhelpers.core.host.service_stop('elasticsearch')
67
68
69def migrate_to_mount(new_path):
70 """Invoked when new mountpoint appears. This function safely migrates
71 elasticsearch data from local disk to persistent storage (only if needed)
72 """
73 old_path = '/var/lib/elasticsearch'
74 if os.path.islink(old_path):
75 hookenv.log('{} is already a symlink, skipping migration'.format(
76 old_path))
77 return True
78 # Ensure our new mountpoint is empty. Otherwise error and allow
79 # users to investigate and migrate manually
80 files = os.listdir(new_path)
81 try:
82 files.remove('lost+found')
83 except ValueError:
84 pass
85 if files:
86 raise RuntimeError('Persistent storage contains old data. '
87 'Please investigate and migrate data manually '
88 'to: {}'.format(new_path))
89 os.chmod(new_path, 0700)
90 charmhelpers.core.host.service_stop('elasticsearch')
91 charmhelpers.core.host.rsync(os.path.join(old_path, ''), # Ensure we have trailing slashes
92 os.path.join(new_path, ''),
93 options=['--archive'])
94 shutil.rmtree(old_path)
95 os.symlink(new_path, old_path)
96 charmhelpers.core.host.service_start('elasticsearch')
97
98
99if __name__ == "__main__":
100 hooks.execute(sys.argv)
0101
=== modified symlink 'hooks/nrpe-external-master-relation-changed' (properties changed: -x to +x)
=== target was u'hooks.py'
--- hooks/nrpe-external-master-relation-changed 1970-01-01 00:00:00 +0000
+++ hooks/nrpe-external-master-relation-changed 2016-05-04 03:14:14 +0000
@@ -0,0 +1,100 @@
1#!/usr/bin/env python
2"""Setup hooks for the elasticsearch charm."""
3
4import sys
5import charmhelpers.contrib.ansible
6import charmhelpers.payload.execd
7import charmhelpers.core.host
8from charmhelpers.core import hookenv
9import os
10import shutil
11
12mountpoint = '/srv/elasticsearch'
13
14hooks = charmhelpers.contrib.ansible.AnsibleHooks(
15 playbook_path='playbook.yaml',
16 default_hooks=[
17 'config-changed',
18 'cluster-relation-joined',
19 'logs-relation-joined',
20 'data-relation-joined',
21 'data-relation-changed',
22 'data-relation-departed',
23 'data-relation-broken',
24 'peer-relation-joined',
25 'peer-relation-changed',
26 'peer-relation-departed',
27 'nrpe-external-master-relation-changed',
28 'rest-relation-joined',
29 'start',
30 'stop',
31 'upgrade-charm',
32 'client-relation-joined',
33 'client-relation-departed',
34 ])
35
36
37@hooks.hook('install', 'upgrade-charm')
38def install():
39 """Install ansible before running the tasks tagged with 'install'."""
40 # Allow charm users to run preinstall setup.
41 charmhelpers.payload.execd.execd_preinstall()
42 charmhelpers.contrib.ansible.install_ansible_support(
43 from_ppa=False)
44
45 # We copy the backported ansible modules here because they need to be
46 # in place by the time ansible runs any hook.
47 charmhelpers.core.host.rsync(
48 'ansible_module_backports',
49 '/usr/share/ansible')
50
51
52@hooks.hook('data-relation-joined', 'data-relation-changed')
53def data_relation():
54 if hookenv.relation_get('mountpoint') == mountpoint:
55 # Other side of relation is ready
56 migrate_to_mount(mountpoint)
57 else:
58 # Other side not ready yet, provide mountpoint
59 hookenv.log('Requesting storage for {}'.format(mountpoint))
60 hookenv.relation_set(mountpoint=mountpoint)
61
62
63@hooks.hook('data-relation-departed', 'data-relation-broken')
64def data_relation_gone():
65 hookenv.log('Data relation no longer present, stopping elasticsearch.')
66 charmhelpers.core.host.service_stop('elasticsearch')
67
68
69def migrate_to_mount(new_path):
70 """Invoked when new mountpoint appears. This function safely migrates
71 elasticsearch data from local disk to persistent storage (only if needed)
72 """
73 old_path = '/var/lib/elasticsearch'
74 if os.path.islink(old_path):
75 hookenv.log('{} is already a symlink, skipping migration'.format(
76 old_path))
77 return True
78 # Ensure our new mountpoint is empty. Otherwise error and allow
79 # users to investigate and migrate manually
80 files = os.listdir(new_path)
81 try:
82 files.remove('lost+found')
83 except ValueError:
84 pass
85 if files:
86 raise RuntimeError('Persistent storage contains old data. '
87 'Please investigate and migrate data manually '
88 'to: {}'.format(new_path))
89 os.chmod(new_path, 0700)
90 charmhelpers.core.host.service_stop('elasticsearch')
91 charmhelpers.core.host.rsync(os.path.join(old_path, ''), # Ensure we have trailing slashes
92 os.path.join(new_path, ''),
93 options=['--archive'])
94 shutil.rmtree(old_path)
95 os.symlink(new_path, old_path)
96 charmhelpers.core.host.service_start('elasticsearch')
97
98
99if __name__ == "__main__":
100 hooks.execute(sys.argv)
0101
=== modified symlink 'hooks/peer-relation-changed' (properties changed: -x to +x)
=== target was u'hooks.py'
--- hooks/peer-relation-changed 1970-01-01 00:00:00 +0000
+++ hooks/peer-relation-changed 2016-05-04 03:14:14 +0000
@@ -0,0 +1,100 @@
1#!/usr/bin/env python
2"""Setup hooks for the elasticsearch charm."""
3
4import sys
5import charmhelpers.contrib.ansible
6import charmhelpers.payload.execd
7import charmhelpers.core.host
8from charmhelpers.core import hookenv
9import os
10import shutil
11
12mountpoint = '/srv/elasticsearch'
13
14hooks = charmhelpers.contrib.ansible.AnsibleHooks(
15 playbook_path='playbook.yaml',
16 default_hooks=[
17 'config-changed',
18 'cluster-relation-joined',
19 'logs-relation-joined',
20 'data-relation-joined',
21 'data-relation-changed',
22 'data-relation-departed',
23 'data-relation-broken',
24 'peer-relation-joined',
25 'peer-relation-changed',
26 'peer-relation-departed',
27 'nrpe-external-master-relation-changed',
28 'rest-relation-joined',
29 'start',
30 'stop',
31 'upgrade-charm',
32 'client-relation-joined',
33 'client-relation-departed',
34 ])
35
36
37@hooks.hook('install', 'upgrade-charm')
38def install():
39 """Install ansible before running the tasks tagged with 'install'."""
40 # Allow charm users to run preinstall setup.
41 charmhelpers.payload.execd.execd_preinstall()
42 charmhelpers.contrib.ansible.install_ansible_support(
43 from_ppa=False)
44
45 # We copy the backported ansible modules here because they need to be
46 # in place by the time ansible runs any hook.
47 charmhelpers.core.host.rsync(
48 'ansible_module_backports',
49 '/usr/share/ansible')
50
51
52@hooks.hook('data-relation-joined', 'data-relation-changed')
53def data_relation():
54 if hookenv.relation_get('mountpoint') == mountpoint:
55 # Other side of relation is ready
56 migrate_to_mount(mountpoint)
57 else:
58 # Other side not ready yet, provide mountpoint
59 hookenv.log('Requesting storage for {}'.format(mountpoint))
60 hookenv.relation_set(mountpoint=mountpoint)
61
62
63@hooks.hook('data-relation-departed', 'data-relation-broken')
64def data_relation_gone():
65 hookenv.log('Data relation no longer present, stopping elasticsearch.')
66 charmhelpers.core.host.service_stop('elasticsearch')
67
68
69def migrate_to_mount(new_path):
70 """Invoked when new mountpoint appears. This function safely migrates
71 elasticsearch data from local disk to persistent storage (only if needed)
72 """
73 old_path = '/var/lib/elasticsearch'
74 if os.path.islink(old_path):
75 hookenv.log('{} is already a symlink, skipping migration'.format(
76 old_path))
77 return True
78 # Ensure our new mountpoint is empty. Otherwise error and allow
79 # users to investigate and migrate manually
80 files = os.listdir(new_path)
81 try:
82 files.remove('lost+found')
83 except ValueError:
84 pass
85 if files:
86 raise RuntimeError('Persistent storage contains old data. '
87 'Please investigate and migrate data manually '
88 'to: {}'.format(new_path))
89 os.chmod(new_path, 0700)
90 charmhelpers.core.host.service_stop('elasticsearch')
91 charmhelpers.core.host.rsync(os.path.join(old_path, ''), # Ensure we have trailing slashes
92 os.path.join(new_path, ''),
93 options=['--archive'])
94 shutil.rmtree(old_path)
95 os.symlink(new_path, old_path)
96 charmhelpers.core.host.service_start('elasticsearch')
97
98
99if __name__ == "__main__":
100 hooks.execute(sys.argv)
0101
=== modified symlink 'hooks/peer-relation-departed' (properties changed: -x to +x)
=== target was u'hooks.py'
--- hooks/peer-relation-departed 1970-01-01 00:00:00 +0000
+++ hooks/peer-relation-departed 2016-05-04 03:14:14 +0000
@@ -0,0 +1,100 @@
1#!/usr/bin/env python
2"""Setup hooks for the elasticsearch charm."""
3
4import sys
5import charmhelpers.contrib.ansible
6import charmhelpers.payload.execd
7import charmhelpers.core.host
8from charmhelpers.core import hookenv
9import os
10import shutil
11
12mountpoint = '/srv/elasticsearch'
13
14hooks = charmhelpers.contrib.ansible.AnsibleHooks(
15 playbook_path='playbook.yaml',
16 default_hooks=[
17 'config-changed',
18 'cluster-relation-joined',
19 'logs-relation-joined',
20 'data-relation-joined',
21 'data-relation-changed',
22 'data-relation-departed',
23 'data-relation-broken',
24 'peer-relation-joined',
25 'peer-relation-changed',
26 'peer-relation-departed',
27 'nrpe-external-master-relation-changed',
28 'rest-relation-joined',
29 'start',
30 'stop',
31 'upgrade-charm',
32 'client-relation-joined',
33 'client-relation-departed',
34 ])
35
36
37@hooks.hook('install', 'upgrade-charm')
38def install():
39 """Install ansible before running the tasks tagged with 'install'."""
40 # Allow charm users to run preinstall setup.
41 charmhelpers.payload.execd.execd_preinstall()
42 charmhelpers.contrib.ansible.install_ansible_support(
43 from_ppa=False)
44
45 # We copy the backported ansible modules here because they need to be
46 # in place by the time ansible runs any hook.
47 charmhelpers.core.host.rsync(
48 'ansible_module_backports',
49 '/usr/share/ansible')
50
51
52@hooks.hook('data-relation-joined', 'data-relation-changed')
53def data_relation():
54 if hookenv.relation_get('mountpoint') == mountpoint:
55 # Other side of relation is ready
56 migrate_to_mount(mountpoint)
57 else:
58 # Other side not ready yet, provide mountpoint
59 hookenv.log('Requesting storage for {}'.format(mountpoint))
60 hookenv.relation_set(mountpoint=mountpoint)
61
62
63@hooks.hook('data-relation-departed', 'data-relation-broken')
64def data_relation_gone():
65 hookenv.log('Data relation no longer present, stopping elasticsearch.')
66 charmhelpers.core.host.service_stop('elasticsearch')
67
68
69def migrate_to_mount(new_path):
70 """Invoked when new mountpoint appears. This function safely migrates
71 elasticsearch data from local disk to persistent storage (only if needed)
72 """
73 old_path = '/var/lib/elasticsearch'
74 if os.path.islink(old_path):
75 hookenv.log('{} is already a symlink, skipping migration'.format(
76 old_path))
77 return True
78 # Ensure our new mountpoint is empty. Otherwise error and allow
79 # users to investigate and migrate manually
80 files = os.listdir(new_path)
81 try:
82 files.remove('lost+found')
83 except ValueError:
84 pass
85 if files:
86 raise RuntimeError('Persistent storage contains old data. '
87 'Please investigate and migrate data manually '
88 'to: {}'.format(new_path))
89 os.chmod(new_path, 0700)
90 charmhelpers.core.host.service_stop('elasticsearch')
91 charmhelpers.core.host.rsync(os.path.join(old_path, ''), # Ensure we have trailing slashes
92 os.path.join(new_path, ''),
93 options=['--archive'])
94 shutil.rmtree(old_path)
95 os.symlink(new_path, old_path)
96 charmhelpers.core.host.service_start('elasticsearch')
97
98
99if __name__ == "__main__":
100 hooks.execute(sys.argv)
0101
=== modified symlink 'hooks/peer-relation-joined' (properties changed: -x to +x)
=== target was u'hooks.py'
--- hooks/peer-relation-joined 1970-01-01 00:00:00 +0000
+++ hooks/peer-relation-joined 2016-05-04 03:14:14 +0000
@@ -0,0 +1,100 @@
1#!/usr/bin/env python
2"""Setup hooks for the elasticsearch charm."""
3
4import sys
5import charmhelpers.contrib.ansible
6import charmhelpers.payload.execd
7import charmhelpers.core.host
8from charmhelpers.core import hookenv
9import os
10import shutil
11
12mountpoint = '/srv/elasticsearch'
13
14hooks = charmhelpers.contrib.ansible.AnsibleHooks(
15 playbook_path='playbook.yaml',
16 default_hooks=[
17 'config-changed',
18 'cluster-relation-joined',
19 'logs-relation-joined',
20 'data-relation-joined',
21 'data-relation-changed',
22 'data-relation-departed',
23 'data-relation-broken',
24 'peer-relation-joined',
25 'peer-relation-changed',
26 'peer-relation-departed',
27 'nrpe-external-master-relation-changed',
28 'rest-relation-joined',
29 'start',
30 'stop',
31 'upgrade-charm',
32 'client-relation-joined',
33 'client-relation-departed',
34 ])
35
36
37@hooks.hook('install', 'upgrade-charm')
38def install():
39 """Install ansible before running the tasks tagged with 'install'."""
40 # Allow charm users to run preinstall setup.
41 charmhelpers.payload.execd.execd_preinstall()
42 charmhelpers.contrib.ansible.install_ansible_support(
43 from_ppa=False)
44
45 # We copy the backported ansible modules here because they need to be
46 # in place by the time ansible runs any hook.
47 charmhelpers.core.host.rsync(
48 'ansible_module_backports',
49 '/usr/share/ansible')
50
51
52@hooks.hook('data-relation-joined', 'data-relation-changed')
53def data_relation():
54 if hookenv.relation_get('mountpoint') == mountpoint:
55 # Other side of relation is ready
56 migrate_to_mount(mountpoint)
57 else:
58 # Other side not ready yet, provide mountpoint
59 hookenv.log('Requesting storage for {}'.format(mountpoint))
60 hookenv.relation_set(mountpoint=mountpoint)
61
62
63@hooks.hook('data-relation-departed', 'data-relation-broken')
64def data_relation_gone():
65 hookenv.log('Data relation no longer present, stopping elasticsearch.')
66 charmhelpers.core.host.service_stop('elasticsearch')
67
68
69def migrate_to_mount(new_path):
70 """Invoked when new mountpoint appears. This function safely migrates
71 elasticsearch data from local disk to persistent storage (only if needed)
72 """
73 old_path = '/var/lib/elasticsearch'
74 if os.path.islink(old_path):
75 hookenv.log('{} is already a symlink, skipping migration'.format(
76 old_path))
77 return True
78 # Ensure our new mountpoint is empty. Otherwise error and allow
79 # users to investigate and migrate manually
80 files = os.listdir(new_path)
81 try:
82 files.remove('lost+found')
83 except ValueError:
84 pass
85 if files:
86 raise RuntimeError('Persistent storage contains old data. '
87 'Please investigate and migrate data manually '
88 'to: {}'.format(new_path))
89 os.chmod(new_path, 0700)
90 charmhelpers.core.host.service_stop('elasticsearch')
91 charmhelpers.core.host.rsync(os.path.join(old_path, ''), # Ensure we have trailing slashes
92 os.path.join(new_path, ''),
93 options=['--archive'])
94 shutil.rmtree(old_path)
95 os.symlink(new_path, old_path)
96 charmhelpers.core.host.service_start('elasticsearch')
97
98
99if __name__ == "__main__":
100 hooks.execute(sys.argv)
0101
=== modified symlink 'hooks/start' (properties changed: -x to +x)
=== target was u'hooks.py'
--- hooks/start 1970-01-01 00:00:00 +0000
+++ hooks/start 2016-05-04 03:14:14 +0000
@@ -0,0 +1,100 @@
1#!/usr/bin/env python
2"""Setup hooks for the elasticsearch charm."""
3
4import sys
5import charmhelpers.contrib.ansible
6import charmhelpers.payload.execd
7import charmhelpers.core.host
8from charmhelpers.core import hookenv
9import os
10import shutil
11
12mountpoint = '/srv/elasticsearch'
13
14hooks = charmhelpers.contrib.ansible.AnsibleHooks(
15 playbook_path='playbook.yaml',
16 default_hooks=[
17 'config-changed',
18 'cluster-relation-joined',
19 'logs-relation-joined',
20 'data-relation-joined',
21 'data-relation-changed',
22 'data-relation-departed',
23 'data-relation-broken',
24 'peer-relation-joined',
25 'peer-relation-changed',
26 'peer-relation-departed',
27 'nrpe-external-master-relation-changed',
28 'rest-relation-joined',
29 'start',
30 'stop',
31 'upgrade-charm',
32 'client-relation-joined',
33 'client-relation-departed',
34 ])
35
36
37@hooks.hook('install', 'upgrade-charm')
38def install():
39 """Install ansible before running the tasks tagged with 'install'."""
40 # Allow charm users to run preinstall setup.
41 charmhelpers.payload.execd.execd_preinstall()
42 charmhelpers.contrib.ansible.install_ansible_support(
43 from_ppa=False)
44
45 # We copy the backported ansible modules here because they need to be
46 # in place by the time ansible runs any hook.
47 charmhelpers.core.host.rsync(
48 'ansible_module_backports',
49 '/usr/share/ansible')
50
51
52@hooks.hook('data-relation-joined', 'data-relation-changed')
53def data_relation():
54 if hookenv.relation_get('mountpoint') == mountpoint:
55 # Other side of relation is ready
56 migrate_to_mount(mountpoint)
57 else:
58 # Other side not ready yet, provide mountpoint
59 hookenv.log('Requesting storage for {}'.format(mountpoint))
60 hookenv.relation_set(mountpoint=mountpoint)
61
62
63@hooks.hook('data-relation-departed', 'data-relation-broken')
64def data_relation_gone():
65 hookenv.log('Data relation no longer present, stopping elasticsearch.')
66 charmhelpers.core.host.service_stop('elasticsearch')
67
68
69def migrate_to_mount(new_path):
70 """Invoked when new mountpoint appears. This function safely migrates
71 elasticsearch data from local disk to persistent storage (only if needed)
72 """
73 old_path = '/var/lib/elasticsearch'
74 if os.path.islink(old_path):
75 hookenv.log('{} is already a symlink, skipping migration'.format(
76 old_path))
77 return True
78 # Ensure our new mountpoint is empty. Otherwise error and allow
79 # users to investigate and migrate manually
80 files = os.listdir(new_path)
81 try:
82 files.remove('lost+found')
83 except ValueError:
84 pass
85 if files:
86 raise RuntimeError('Persistent storage contains old data. '
87 'Please investigate and migrate data manually '
88 'to: {}'.format(new_path))
89 os.chmod(new_path, 0700)
90 charmhelpers.core.host.service_stop('elasticsearch')
91 charmhelpers.core.host.rsync(os.path.join(old_path, ''), # Ensure we have trailing slashes
92 os.path.join(new_path, ''),
93 options=['--archive'])
94 shutil.rmtree(old_path)
95 os.symlink(new_path, old_path)
96 charmhelpers.core.host.service_start('elasticsearch')
97
98
99if __name__ == "__main__":
100 hooks.execute(sys.argv)
0101
=== modified symlink 'hooks/stop' (properties changed: -x to +x)
=== target was u'hooks.py'
--- hooks/stop 1970-01-01 00:00:00 +0000
+++ hooks/stop 2016-05-04 03:14:14 +0000
@@ -0,0 +1,100 @@
1#!/usr/bin/env python
2"""Setup hooks for the elasticsearch charm."""
3
4import sys
5import charmhelpers.contrib.ansible
6import charmhelpers.payload.execd
7import charmhelpers.core.host
8from charmhelpers.core import hookenv
9import os
10import shutil
11
12mountpoint = '/srv/elasticsearch'
13
14hooks = charmhelpers.contrib.ansible.AnsibleHooks(
15 playbook_path='playbook.yaml',
16 default_hooks=[
17 'config-changed',
18 'cluster-relation-joined',
19 'logs-relation-joined',
20 'data-relation-joined',
21 'data-relation-changed',
22 'data-relation-departed',
23 'data-relation-broken',
24 'peer-relation-joined',
25 'peer-relation-changed',
26 'peer-relation-departed',
27 'nrpe-external-master-relation-changed',
28 'rest-relation-joined',
29 'start',
30 'stop',
31 'upgrade-charm',
32 'client-relation-joined',
33 'client-relation-departed',
34 ])
35
36
37@hooks.hook('install', 'upgrade-charm')
38def install():
39 """Install ansible before running the tasks tagged with 'install'."""
40 # Allow charm users to run preinstall setup.
41 charmhelpers.payload.execd.execd_preinstall()
42 charmhelpers.contrib.ansible.install_ansible_support(
43 from_ppa=False)
44
45 # We copy the backported ansible modules here because they need to be
46 # in place by the time ansible runs any hook.
47 charmhelpers.core.host.rsync(
48 'ansible_module_backports',
49 '/usr/share/ansible')
50
51
52@hooks.hook('data-relation-joined', 'data-relation-changed')
53def data_relation():
54 if hookenv.relation_get('mountpoint') == mountpoint:
55 # Other side of relation is ready
56 migrate_to_mount(mountpoint)
57 else:
58 # Other side not ready yet, provide mountpoint
59 hookenv.log('Requesting storage for {}'.format(mountpoint))
60 hookenv.relation_set(mountpoint=mountpoint)
61
62
63@hooks.hook('data-relation-departed', 'data-relation-broken')
64def data_relation_gone():
65 hookenv.log('Data relation no longer present, stopping elasticsearch.')
66 charmhelpers.core.host.service_stop('elasticsearch')
67
68
69def migrate_to_mount(new_path):
70 """Invoked when new mountpoint appears. This function safely migrates
71 elasticsearch data from local disk to persistent storage (only if needed)
72 """
73 old_path = '/var/lib/elasticsearch'
74 if os.path.islink(old_path):
75 hookenv.log('{} is already a symlink, skipping migration'.format(
76 old_path))
77 return True
78 # Ensure our new mountpoint is empty. Otherwise error and allow
79 # users to investigate and migrate manually
80 files = os.listdir(new_path)
81 try:
82 files.remove('lost+found')
83 except ValueError:
84 pass
85 if files:
86 raise RuntimeError('Persistent storage contains old data. '
87 'Please investigate and migrate data manually '
88 'to: {}'.format(new_path))
89 os.chmod(new_path, 0700)
90 charmhelpers.core.host.service_stop('elasticsearch')
91 charmhelpers.core.host.rsync(os.path.join(old_path, ''), # Ensure we have trailing slashes
92 os.path.join(new_path, ''),
93 options=['--archive'])
94 shutil.rmtree(old_path)
95 os.symlink(new_path, old_path)
96 charmhelpers.core.host.service_start('elasticsearch')
97
98
99if __name__ == "__main__":
100 hooks.execute(sys.argv)
0101
=== modified symlink 'hooks/upgrade-charm' (properties changed: -x to +x)
=== target was u'hooks.py'
--- hooks/upgrade-charm 1970-01-01 00:00:00 +0000
+++ hooks/upgrade-charm 2016-05-04 03:14:14 +0000
@@ -0,0 +1,100 @@
1#!/usr/bin/env python
2"""Setup hooks for the elasticsearch charm."""
3
4import sys
5import charmhelpers.contrib.ansible
6import charmhelpers.payload.execd
7import charmhelpers.core.host
8from charmhelpers.core import hookenv
9import os
10import shutil
11
12mountpoint = '/srv/elasticsearch'
13
14hooks = charmhelpers.contrib.ansible.AnsibleHooks(
15 playbook_path='playbook.yaml',
16 default_hooks=[
17 'config-changed',
18 'cluster-relation-joined',
19 'logs-relation-joined',
20 'data-relation-joined',
21 'data-relation-changed',
22 'data-relation-departed',
23 'data-relation-broken',
24 'peer-relation-joined',
25 'peer-relation-changed',
26 'peer-relation-departed',
27 'nrpe-external-master-relation-changed',
28 'rest-relation-joined',
29 'start',
30 'stop',
31 'upgrade-charm',
32 'client-relation-joined',
33 'client-relation-departed',
34 ])
35
36
37@hooks.hook('install', 'upgrade-charm')
38def install():
39 """Install ansible before running the tasks tagged with 'install'."""
40 # Allow charm users to run preinstall setup.
41 charmhelpers.payload.execd.execd_preinstall()
42 charmhelpers.contrib.ansible.install_ansible_support(
43 from_ppa=False)
44
45 # We copy the backported ansible modules here because they need to be
46 # in place by the time ansible runs any hook.
47 charmhelpers.core.host.rsync(
48 'ansible_module_backports',
49 '/usr/share/ansible')
50
51
52@hooks.hook('data-relation-joined', 'data-relation-changed')
53def data_relation():
54 if hookenv.relation_get('mountpoint') == mountpoint:
55 # Other side of relation is ready
56 migrate_to_mount(mountpoint)
57 else:
58 # Other side not ready yet, provide mountpoint
59 hookenv.log('Requesting storage for {}'.format(mountpoint))
60 hookenv.relation_set(mountpoint=mountpoint)
61
62
63@hooks.hook('data-relation-departed', 'data-relation-broken')
64def data_relation_gone():
65 hookenv.log('Data relation no longer present, stopping elasticsearch.')
66 charmhelpers.core.host.service_stop('elasticsearch')
67
68
69def migrate_to_mount(new_path):
70 """Invoked when new mountpoint appears. This function safely migrates
71 elasticsearch data from local disk to persistent storage (only if needed)
72 """
73 old_path = '/var/lib/elasticsearch'
74 if os.path.islink(old_path):
75 hookenv.log('{} is already a symlink, skipping migration'.format(
76 old_path))
77 return True
78 # Ensure our new mountpoint is empty. Otherwise error and allow
79 # users to investigate and migrate manually
80 files = os.listdir(new_path)
81 try:
82 files.remove('lost+found')
83 except ValueError:
84 pass
85 if files:
86 raise RuntimeError('Persistent storage contains old data. '
87 'Please investigate and migrate data manually '
88 'to: {}'.format(new_path))
89 os.chmod(new_path, 0700)
90 charmhelpers.core.host.service_stop('elasticsearch')
91 charmhelpers.core.host.rsync(os.path.join(old_path, ''), # Ensure we have trailing slashes
92 os.path.join(new_path, ''),
93 options=['--archive'])
94 shutil.rmtree(old_path)
95 os.symlink(new_path, old_path)
96 charmhelpers.core.host.service_start('elasticsearch')
97
98
99if __name__ == "__main__":
100 hooks.execute(sys.argv)
0101
=== removed file 'tests/00-create-index'
--- tests/00-create-index 2014-10-30 01:02:33 +0000
+++ tests/00-create-index 1970-01-01 00:00:00 +0000
@@ -1,32 +0,0 @@
1#!/usr/bin/python3
2import amulet
3import helpers
4
5
6d = amulet.Deployment(series='trusty')
7
8d.add('elasticsearch')
9
10helpers.setup_deployment(d)
11
12health = helpers.get_cluster_health(d)
13
14if health['status'] not in ('green', 'yellow'):
15 msg = "Elastic Search status is %s" % health['status']
16 amulet.raise_status(amulet.FAIL, msg=msg)
17
18# Create a test index.
19curl_command = """
20curl -XPUT 'http://localhost:9200/test/tweet/1' -d '{
21 "user" : "me",
22 "message" : "testing"
23}'
24"""
25response = helpers.curl_on_unit(curl_command, d)
26
27health = helpers.get_index_health(d, 'test')
28if health['status'] not in ('green', 'yellow'):
29 msg = "Elastic Search test index status is %s." % health['status']
30 amulet.raise_status(amulet.FAIL, msg=msg)
31
32print("Successfully created test index.")
330
=== added file 'tests/00-single-to-scale-test.py'
--- tests/00-single-to-scale-test.py 1970-01-01 00:00:00 +0000
+++ tests/00-single-to-scale-test.py 2016-05-04 03:14:14 +0000
@@ -0,0 +1,112 @@
1#!/usr/bin/python3
2
3import amulet
4import unittest
5import requests
6import json
7
8class TestElasticsearch(unittest.TestCase):
9
10 @classmethod
11 def setUpClass(self):
12 self.deployment = amulet.Deployment(series='trusty')
13 self.deployment.add('elasticsearch')
14 self.deployment.configure('elasticsearch',
15 {'cluster-name': 'unique-name'})
16
17 try:
18 self.deployment.setup(timeout=1200)
19 self.deployment.sentry.wait()
20 except amulet.helpers.TimeoutError:
21 amulet.raise_status(
22 amulet.SKIP, msg="Environment wasn't setup in time")
23
24
25 def test_health(self):
26 ''' Test the health of the node upon first deployment
27 by getting the cluster health, then inserting data and
28 validating cluster health'''
29 health = self.get_cluster_health()
30 assert health['status'] in ('green', 'yellow')
31
32 # Create a test index.
33 curl_command = """
34 curl -XPUT 'http://localhost:9200/test/tweet/1' -d '{
35 "user" : "me",
36 "message" : "testing"
37 }'
38 """
39 response = self.curl_on_unit(curl_command)
40 health = self.get_index_health('test')
41 assert health['status'] in ('green', 'yellow')
42
43 def test_config(self):
44 ''' Validate our configuration of the cluster name made it to the
45 application configuration'''
46 health = self.get_cluster_health()
47 cluster_name = health['cluster_name']
48 assert cluster_name == 'unique-name'
49
50 def test_scale(self):
51 ''' Validate scaling the elasticsearch cluster yields a healthy
52 response from the API, and all units are participating '''
53 self.deployment.add_unit('elasticsearch', units=2)
54 self.deployment.setup(timeout=1200)
55 self.deployment.sentry.wait()
56 health = self.get_cluster_health(wait_for_nodes=3)
57 index_health = self.get_index_health('test')
58 print(health['number_of_nodes'])
59 assert health['number_of_nodes'] == 3
60 assert index_health['status'] in ('green', 'yellow')
61
62 def curl_on_unit(self, curl_command, unit_number=0):
63 unit = "elasticsearch"
64 response = self.deployment.sentry[unit][unit_number].run(curl_command)
65 if response[1] != 0:
66 msg = (
67 "Elastic search didn't respond to the command \n"
68 "'{curl_command}' as expected.\n"
69 "Return code: {return_code}\n"
70 "Result: {result}".format(
71 curl_command=curl_command,
72 return_code=response[1],
73 result=response[0])
74 )
75 amulet.raise_status(amulet.FAIL, msg=msg)
76
77 return json.loads(response[0])
78
79 def get_cluster_health(self, unit_number=0, wait_for_nodes=0,
80 timeout=180):
81 curl_command = "curl http://localhost:9200"
82 curl_command = curl_command + "/_cluster/health?timeout={}s".format(
83 timeout)
84 if wait_for_nodes > 0:
85 curl_command = curl_command + "&wait_for_nodes={}".format(
86 wait_for_nodes)
87
88 return self.curl_on_unit(curl_command, unit_number=unit_number)
89
90 def get_index_health(self, index_name, unit_number=0):
91 curl_command = "curl http://localhost:9200"
92 curl_command = curl_command + "/_cluster/health/" + index_name
93
94 return self.curl_on_unit(curl_command)
95
96
97def check_response(response, expected_code=200):
98 if response.status_code != expected_code:
99 msg = (
100 "Elastic search did not respond as expected. \n"
101 "Expected status code: %{expected_code} \n"
102 "Status code: %{status_code} \n"
103 "Response text: %{response_text}".format(
104 expected_code=expected_code,
105 status_code=response.status_code,
106 response_text=response.text))
107
108 amulet.raise_status(amulet.FAIL, msg=msg)
109
110
111if __name__ == "__main__":
112 unittest.main()
0113
=== removed file 'tests/01-config-changes'
--- tests/01-config-changes 2014-10-30 01:02:33 +0000
+++ tests/01-config-changes 1970-01-01 00:00:00 +0000
@@ -1,22 +0,0 @@
1#!/usr/bin/python3
2import amulet
3import helpers
4
5d = amulet.Deployment(series='trusty')
6
7d.add('elasticsearch')
8config = {'cluster-name': 'unique-name'}
9d.configure('elasticsearch', config)
10
11helpers.setup_deployment(d)
12
13health = helpers.get_cluster_health(d)
14
15cluster_name = health['cluster_name']
16
17if cluster_name != 'unique-name':
18 msg = ("Expected cluster name to be 'unique-name' "
19 "but was '{}'.".format(cluster_name))
20 amulet.raise_status(amulet.FAIL, msg=msg)
21
22print("Successfully created cluster with non-default cluster-name.")
230
=== removed file 'tests/02-deploy-three-units'
--- tests/02-deploy-three-units 2014-10-30 01:02:33 +0000
+++ tests/02-deploy-three-units 1970-01-01 00:00:00 +0000
@@ -1,18 +0,0 @@
1#!/usr/bin/python3
2import amulet
3import helpers
4
5d = amulet.Deployment(series='trusty')
6
7d.add('elasticsearch', units=3)
8
9helpers.setup_deployment(d)
10
11health = helpers.get_cluster_health(d, wait_for_nodes=3)
12
13if health['number_of_nodes'] != 3:
14 amulet.raise_status(amulet.FAIL, msg=msg)
15 msg = ("Expected at least 3 nodes in cluster with 3 units deployed, "
16 "got {}".format(health['number_of_nodes']))
17
18print("Successfully deployed cluster of 3 units.")
190
=== removed file 'tests/__init__.py'
=== removed directory 'tests/helpers'
=== removed file 'tests/helpers/__init__.py'
--- tests/helpers/__init__.py 2014-10-30 01:02:33 +0000
+++ tests/helpers/__init__.py 1970-01-01 00:00:00 +0000
@@ -1,64 +0,0 @@
1import amulet
2import json
3
4
5def check_response(response, expected_code=200):
6 if response.status_code != expected_code:
7 msg = (
8 "Elastic search did not respond as expected. \n"
9 "Expected status code: %{expected_code} \n"
10 "Status code: %{status_code} \n"
11 "Response text: %{response_text}".format(
12 expected_code=expected_code,
13 status_code=response.status_code,
14 response_text=response.text))
15
16 amulet.raise_status(amulet.FAIL, msg=msg)
17
18
19def curl_on_unit(curl_command, deployment, unit_number=0):
20 unit = "elasticsearch/{}".format(unit_number)
21
22 response = deployment.sentry.unit[unit].run(curl_command)
23 if response[1] != 0:
24 msg = (
25 "Elastic search didn't respond to the command \n"
26 "'{curl_command}' as expected.\n"
27 "Return code: {return_code}\n"
28 "Result: {result}".format(
29 curl_command=curl_command,
30 return_code=response[1],
31 result=response[0])
32 )
33 amulet.raise_status(amulet.FAIL, msg=msg)
34
35 return json.loads(response[0])
36
37
38def setup_deployment(deployment, timeout=900):
39 """Setup the deployment and wait until installed."""
40 try:
41 deployment.setup(timeout=timeout)
42 deployment.sentry.wait()
43 except amulet.helpers.TimeoutError:
44 amulet.raise_status(
45 amulet.SKIP, msg="Environment wasn't setup in time")
46
47
48def get_cluster_health(deployment, unit_number=0, wait_for_nodes=0,
49 timeout=180):
50 curl_command = "curl http://localhost:9200"
51 curl_command = curl_command + "/_cluster/health?timeout={}s".format(
52 timeout)
53 if wait_for_nodes > 0:
54 curl_command = curl_command + "&wait_for_nodes={}".format(
55 wait_for_nodes)
56
57 return curl_on_unit(curl_command, deployment, unit_number=unit_number)
58
59
60def get_index_health(deployment, index_name, unit_number=0):
61 curl_command = "curl http://localhost:9200"
62 curl_command = curl_command + "/_cluster/health/" + index_name
63
64 return curl_on_unit(curl_command, deployment)
650
=== added file 'tests/tests.yaml'
--- tests/tests.yaml 1970-01-01 00:00:00 +0000
+++ tests/tests.yaml 2016-05-04 03:14:14 +0000
@@ -0,0 +1,2 @@
1packages:
2 - python3-amulet

Subscribers

People subscribed via source and target branches