Merge lp:~jamesbeedy/charm-elasticsearch/fixes_for_xenial_5_x into lp:charm-elasticsearch

Proposed by james beedy
Status: Merged
Merged at revision: 60
Proposed branch: lp:~jamesbeedy/charm-elasticsearch/fixes_for_xenial_5_x
Merge into: lp:charm-elasticsearch
Diff against target: 246 lines (+56/-39)
7 files modified
hooks/hooks.py (+2/-17)
hooks/install (+18/-0)
playbook.yaml (+1/-2)
tasks/install-elasticsearch.yml (+18/-10)
tasks/setup-ufw.yml (+4/-4)
templates/elasticsearch.yml (+8/-1)
unit_tests/test_hooks.py (+5/-5)
To merge this branch: bzr merge lp:~jamesbeedy/charm-elasticsearch/fixes_for_xenial_5_x
Reviewer Review Type Date Requested Status
Thomas Cuthbert (community) Approve
Review via email: mp+330793@code.launchpad.net

Description of the change

Updates for 5.x + xenial

To post a comment you must log in.
Revision history for this message
Thomas Cuthbert (tcuthbert) wrote :

+1 LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'hooks/hooks.py'
--- hooks/hooks.py 2017-03-29 09:59:19 +0000
+++ hooks/hooks.py 2017-09-15 00:48:54 +0000
@@ -8,10 +8,8 @@
8from charmhelpers.core import hookenv8from charmhelpers.core import hookenv
9import os9import os
10import shutil10import shutil
11import subprocess as sp
1211
13mountpoint = '/srv/elasticsearch'12mountpoint = '/srv/elasticsearch'
14config = hookenv.config()
1513
16hooks = charmhelpers.contrib.ansible.AnsibleHooks(14hooks = charmhelpers.contrib.ansible.AnsibleHooks(
17 playbook_path='playbook.yaml',15 playbook_path='playbook.yaml',
@@ -36,14 +34,10 @@
36 ])34 ])
3735
3836
39@hooks.hook('install', 'upgrade-charm')37@hooks.hook('install.real', 'upgrade-charm')
40def install():38def install_real():
41 """Install ansible before running the tasks tagged with 'install'."""39 """Install ansible before running the tasks tagged with 'install'."""
42 # Allow charm users to run preinstall setup.40 # Allow charm users to run preinstall setup.
43 if is_container:
44 config["env-vars"] = {"ES_SKIP_SET_KERNEL_PARAMETERS": "true"}
45 else:
46 config["env-vars"] = {}
47 charmhelpers.payload.execd.execd_preinstall()41 charmhelpers.payload.execd.execd_preinstall()
48 charmhelpers.contrib.ansible.install_ansible_support(42 charmhelpers.contrib.ansible.install_ansible_support(
49 from_ppa=False)43 from_ppa=False)
@@ -103,14 +97,5 @@
103 charmhelpers.core.host.service_start('elasticsearch')97 charmhelpers.core.host.service_start('elasticsearch')
10498
10599
106def is_container():
107 """Return True if system is running inside a container"""
108 virt_type = sp.check_output('systemd-detect-virt').decode().strip()
109 if virt_type == 'lxc':
110 return True
111 else:
112 return False
113
114
115if __name__ == "__main__":100if __name__ == "__main__":
116 hooks.execute(sys.argv)101 hooks.execute(sys.argv)
117102
=== 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 2017-09-15 00:48:54 +0000
@@ -0,0 +1,18 @@
1#!/bin/bash
2# Wrapper to deal with older Ubuntu versions that don't have py3 installed
3# by default.
4
5declare -a DEPS=('python3' 'python3-dnspython' 'python3-netifaces' 'python-dnspython')
6
7check_and_install() {
8 pkg="${1}"
9 if ! dpkg -s ${pkg} 2>&1 > /dev/null; then
10 apt-get -y install ${pkg}
11 fi
12}
13
14for dep in ${DEPS[@]}; do
15 check_and_install ${dep}
16done
17
18exec ./hooks/install.real
019
=== added symlink 'hooks/install.real'
=== target is u'hooks.py'
=== modified file 'playbook.yaml'
--- playbook.yaml 2016-09-02 18:52:15 +0000
+++ playbook.yaml 2017-09-15 00:48:54 +0000
@@ -19,7 +19,7 @@
19 - include: tasks/peer-relations.yml19 - include: tasks/peer-relations.yml
20 - include: tasks/setup-ufw.yml20 - include: tasks/setup-ufw.yml
21 tags:21 tags:
22 - install22 - install.real
23 - upgrade-charm23 - upgrade-charm
24 - config-changed24 - config-changed
25 - client-relation-joined25 - client-relation-joined
@@ -92,4 +92,3 @@
92 - peer-relation-joined92 - peer-relation-joined
93 - peer-relation-departed93 - peer-relation-departed
94 - start94 - start
95
9695
=== modified file 'tasks/install-elasticsearch.yml'
--- tasks/install-elasticsearch.yml 2017-03-29 09:59:19 +0000
+++ tasks/install-elasticsearch.yml 2017-09-15 00:48:54 +0000
@@ -1,14 +1,14 @@
1- name: Add apt key.1- name: Add apt key.
2 tags:2 tags:
3 - install3 - install.real
4 - upgrade-charm4 - upgrade-charm
5 - config-changed5 - config-changed
6 apt_key: url={{ apt_key_url }} state=present id={{gpg_key_id}}6 apt_key: url={{ apt_key_url }} state=present id={{gpg_key_id}} validate_certs=no
7 when: apt_key_url != ""7 when: apt_key_url != ""
88
9- name: Add apt archive.9- name: Add apt archive.
10 tags:10 tags:
11 - install11 - install.real
12 - upgrade-charm12 - upgrade-charm
13 - config-changed13 - config-changed
14 apt_repository:14 apt_repository:
@@ -16,34 +16,42 @@
16 state: present16 state: present
17 when: apt_repository != ""17 when: apt_repository != ""
1818
19- name: Add java apt archive for trusty only.
20 tags:
21 - install.real
22 - upgrade-charm
23 - config-changed
24 apt_repository:
25 repo: "ppa:openjdk-r/ppa"
26 state: present
27 when: ansible_distribution_release == 'trusty'
28
19- name: Install dependent packages.29- name: Install dependent packages.
20 apt: pkg={{ item }} state=latest update_cache=yes30 apt: pkg={{ item }} state=latest update_cache=yes
21 tags:31 tags:
22 - install32 - install.real
23 - upgrade-charm33 - upgrade-charm
24 with_items:34 with_items:
25 - default-jre-headless35 - openjdk-8-jre-headless
26 - ufw36 - ufw
2737
28- name: Check for local elasticsearch.deb in payload.38- name: Check for local elasticsearch.deb in payload.
29 stat: path=files/elasticsearch.deb39 stat: path=files/elasticsearch.deb
30 register: stat_elasticsearch_deb40 register: stat_elasticsearch_deb
31 tags:41 tags:
32 - install42 - install.real
33 - upgrade-charm43 - upgrade-charm
3444
35- name: Install elasticsearch from repository45- name: Install elasticsearch from repository
36 apt: pkg=elasticsearch state=latest update_cache=yes46 apt: pkg=elasticsearch state=latest update_cache=yes
37 environment: "{{ env_vars }}"
38 tags:47 tags:
39 - install48 - install.real
40 - upgrade-charm49 - upgrade-charm
41 when: stat_elasticsearch_deb.stat.exists == false and apt_repository != ""50 when: stat_elasticsearch_deb.stat.exists == false and apt_repository != ""
4251
43- name: Install ElasticSearch from payload52- name: Install ElasticSearch from payload
44 command: dpkg -i {{ charm_dir }}/files/elasticsearch.deb53 command: dpkg -i {{ charm_dir }}/files/elasticsearch.deb
45 environment: "{{ env_vars }}"
46 tags:54 tags:
47 - install55 - install.real
48 - upgrade-charm56 - upgrade-charm
49 when: stat_elasticsearch_deb.stat.exists == true57 when: stat_elasticsearch_deb.stat.exists == true
5058
=== modified file 'tasks/setup-ufw.yml'
--- tasks/setup-ufw.yml 2014-10-31 03:43:31 +0000
+++ tasks/setup-ufw.yml 2017-09-15 00:48:54 +0000
@@ -27,8 +27,8 @@
27 when: firewall_enabled27 when: firewall_enabled
2828
29- name: Open the firewall for all clients29- name: Open the firewall for all clients
30 ufw: rule=allow src={{ lookup('dns', item['private-address']) }} port=9200 proto=tcp30 ufw: rule=allow src="{{lookup('dig', item.get('address', ''))}}" port=9200 proto=tcp
31 with_items: relations["client"]31 with_items: "{{relations['client']}}"
32 when: firewall_enabled32 when: firewall_enabled
3333
34- name: Deny all other requests on 920034- name: Deny all other requests on 9200
@@ -36,8 +36,8 @@
36 when: firewall_enabled36 when: firewall_enabled
3737
38- name: Open the firewall for all peers38- name: Open the firewall for all peers
39 ufw: rule=allow src={{ lookup('dns', item['private-address']) }} port=9300 proto=tcp39 ufw: rule=allow src="{{lookup('dig', item.get('address', ''))}}" port=9300 proto=tcp
40 with_items: relations["peer"]40 with_items: "{{relations['peer']}}"
41 when: firewall_enabled41 when: firewall_enabled
4242
43# Only deny incoming on 9300 once the unit is part of a cluster.43# Only deny incoming on 9300 once the unit is part of a cluster.
4444
=== modified file 'templates/elasticsearch.yml'
--- templates/elasticsearch.yml 2017-07-26 03:30:57 +0000
+++ templates/elasticsearch.yml 2017-09-15 00:48:54 +0000
@@ -4,9 +4,16 @@
4cluster.name: {{ cluster_name }}4cluster.name: {{ cluster_name }}
5http.port: 92005http.port: 9200
6network.host: ["_site_", "_local_"]6network.host: ["_site_", "_local_"]
7{% if (relations.peer is defined) and relations.peer %}7{% if not '5' in apt_repository %}
8discovery.zen.ping.multicast.enabled: false
9{% endif %}
10{% if relations.peer is defined and relations.peer|length > 0 %}
8discovery.zen.ping.unicast.hosts:11discovery.zen.ping.unicast.hosts:
9{% for reln in relations.peer %}12{% for reln in relations.peer %}
10 - {{ reln['private-address'] }}13 - {{ reln['private-address'] }}
11{% endfor %}14{% endfor %}
12{% endif %}15{% endif %}
16{% if not '5' in apt_repository %}
17# workaround for Kibana4 Export Everything bug https://github.com/elastic/kibana/issues/5524
18index.max_result_window: 2147483647
19{% endif %}
1320
=== modified file 'unit_tests/test_hooks.py'
--- unit_tests/test_hooks.py 2017-03-29 01:20:22 +0000
+++ unit_tests/test_hooks.py 2017-09-15 00:48:54 +0000
@@ -56,26 +56,26 @@
56 self.addCleanup(patcher.stop)56 self.addCleanup(patcher.stop)
5757
58 def test_installs_ansible_support(self):58 def test_installs_ansible_support(self):
59 hooks.execute(['install'])59 hooks.execute(['install.real'])
6060
61 ansible = self.mock_ansible61 ansible = self.mock_ansible
62 ansible.install_ansible_support.assert_called_once_with(62 ansible.install_ansible_support.assert_called_once_with(
63 from_ppa=False)63 from_ppa=False)
6464
65 def test_applies_install_playbook(self):65 def test_applies_install_playbook(self):
66 hooks.execute(['install'])66 hooks.execute(['install.real'])
6767
68 self.assertEqual([68 self.assertEqual([
69 mock.call('playbook.yaml', tags=['install'], extra_vars=None)69 mock.call('playbook.yaml', tags=['install.real'], extra_vars=None)
70 ], self.mock_ansible.apply_playbook.call_args_list)70 ], self.mock_ansible.apply_playbook.call_args_list)
7171
72 def test_executes_preinstall(self):72 def test_executes_preinstall(self):
73 hooks.execute(['install'])73 hooks.execute(['install.real'])
7474
75 self.mock_preinstall.assert_called_once_with()75 self.mock_preinstall.assert_called_once_with()
7676
77 def test_copys_backported_ansible_modules(self):77 def test_copys_backported_ansible_modules(self):
78 hooks.execute(['install'])78 hooks.execute(['install.real'])
7979
80 self.mock_rsync.assert_called_once_with(80 self.mock_rsync.assert_called_once_with(
81 'ansible_module_backports',81 'ansible_module_backports',

Subscribers

People subscribed via source and target branches