Merge ~afreiberger/charm-elasticsearch:bug/1864169 into charm-elasticsearch:master

Proposed by Drew Freiberger
Status: Merged
Merged at revision: e1c568f4666db32747b3c27f84a48d1767c795a0
Proposed branch: ~afreiberger/charm-elasticsearch:bug/1864169
Merge into: charm-elasticsearch:master
Diff against target: 149 lines (+48/-13)
7 files modified
.gitignore (+2/-0)
Makefile (+23/-6)
charm-helpers (+1/-1)
hooks/hooks.py (+9/-4)
playbook.yaml (+1/-0)
tasks/install-elasticsearch.yml (+11/-1)
tasks/setup-ufw.yml (+1/-1)
Reviewer Review Type Date Requested Status
Xav Paice (community) Approve
Drew Freiberger (community) Needs Resubmitting
Review via email: mp+387779@code.launchpad.net

Commit message

Updated elasticsearch charm to continue trusty support

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Unable to determine commit message from repository - please click "Set commit message" and enter the commit message manually.

Revision history for this message
Drew Freiberger (afreiberger) wrote :
Revision history for this message
Xav Paice (xavpaice) wrote :

Installs fine on Trusty, but on Bionic with a proxy it's not connecting.

2020-07-21 23:56:31 DEBUG install TASK [Add apt key.] ************************************************************
2020-07-21 23:58:42 DEBUG install fatal: [localhost]: FAILED! => {"changed": false, "msg": "Failed to connect to artifacts.elastic.co at port 443: [Errno 101] Network is unreachable"}
2020-07-21 23:58:42 DEBUG install to retry, use: --limit @/var/lib/juju/agents/unit-elast-bionic-0/charm/playbook.retry
2020-07-21 23:58:42 DEBUG install
2020-07-21 23:58:42 DEBUG install PLAY RECAP *********************************************************************
2020-07-21 23:58:42 DEBUG install localhost : ok=2 changed=1 unreachable=0 failed=1
2020-07-21 23:58:42 DEBUG install
2020-07-21 23:58:42 DEBUG install Traceback (most recent call last):
2020-07-21 23:58:42 DEBUG install File "/var/lib/juju/agents/unit-elast-bionic-0/charm/hooks/install", line 189, in <module>
2020-07-21 23:58:42 DEBUG install hooks.execute(sys.argv)
2020-07-21 23:58:42 DEBUG install File "/var/lib/juju/agents/unit-elast-bionic-0/charm/hooks/charmhelpers/contrib/ansible/__init__.py", line 229, in execute
2020-07-21 23:58:42 DEBUG install self.playbook_path, tags=[hook_name], extra_vars=extra_vars)
2020-07-21 23:58:42 DEBUG install File "/var/lib/juju/agents/unit-elast-bionic-0/charm/hooks/charmhelpers/contrib/ansible/__init__.py", line 161, in apply_playbook
2020-07-21 23:58:42 DEBUG install subprocess.check_call(call, env=env)
2020-07-21 23:58:42 DEBUG install File "/usr/lib/python3.6/subprocess.py", line 311, in check_call
2020-07-21 23:58:42 DEBUG install raise CalledProcessError(retcode, cmd)
2020-07-21 23:58:42 DEBUG install subprocess.CalledProcessError: Command '['ansible-playbook', '-c', 'local', 'playbook.yaml', '--tags', 'install']' returned non-zero exit status 2.
2020-07-21 23:58:42 ERROR juju.worker.uniter.operation runhook.go:136 hook "install" (via explicit, bespoke hook script) failed: exit status 1

The model has juju-http-proxy and juju-https-proxy set.

review: Needs Fixing
Revision history for this message
Drew Freiberger (afreiberger) wrote :

https://bugs.launchpad.net/ubuntu/+source/software-properties/+bug/1433761
https://github.com/ansible/ansible/issues/31691

Looks like there may be other ways to work around this. Seems add-key is deprecated as of bionic and one should just download keys into trusted.gpg.d (per comments on the ubuntu bug link).

But there's a potential workaround mentioned in the ansible issue #31691 that lists use of environment variables in apt_key:

  - name: Ensure the Sensu APT repo GPG key is present
     apt_key:
       url: https://sensu.global.ssl.fastly.net/apt/pubkey.gpg
       state: present
     environment:
       http_proxy: 'http://172.31.255.254:8888'
       https_proxy: 'http://172.31.255.254:8888'

So we may be able to add environment https_proxy: {{ lookup('env','JUJU_CHARM_HTTPS_PROXY') }} to apt_key for non-trusty.

Revision history for this message
Drew Freiberger (afreiberger) wrote :

Latest merge configures apt_key section of playbook for non-trusty to also use juju-https-proxy properly if it exists. I've tested with models with proxy set and unset with both models completing successful installs on all four supported distros.

Test model configs and status:
https://pastebin.canonical.com/p/4Hfb6fFfVT/

review: Needs Resubmitting
Revision history for this message
Xav Paice (xavpaice) wrote :

LGTM, tests well on Trusty plus others.

review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Failed to merge change (unable to merge source repository due to conflicts), setting status to needs review.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/.gitignore b/.gitignore
2index 948c035..a9bc955 100644
3--- a/.gitignore
4+++ b/.gitignore
5@@ -7,5 +7,7 @@ revision
6 exec.d
7 local.yaml
8
9+repo-info
10+.idea/
11 *.pyc
12 __pycache__
13diff --git a/Makefile b/Makefile
14index 50fc07f..c81f7cd 100644
15--- a/Makefile
16+++ b/Makefile
17@@ -1,13 +1,27 @@
18 #!/usr/bin/make
19 PYTHON := /usr/bin/env python3
20-
21-build: sync-charm-helpers-stable test
22-
23-lint:
24+CHARM_HELPERS = charm-helpers/.gitignore
25+PYTHON := /usr/bin/python3
26+export PYTHONPATH := hooks
27+PROJECTPATH = $(dir $(realpath $(MAKEFILE_LIST)))
28+METADATA_FILE = "metadata.yaml"
29+CHARM_NAME = $(shell cat ${PROJECTPATH}/${METADATA_FILE} | grep -E '^name:' | awk '{print $$2}')
30+ifndef CHARM_BUILD_DIR
31+ CHARM_BUILD_DIR := /tmp/charm-builds
32+ $(warning Warning CHARM_BUILD_DIR was not set, defaulting to $(CHARM_BUILD_DIR))
33+endif
34+
35+build: test
36+ @echo "Building charm to base directory $(CHARM_BUILD_DIR)/$(CHARM_NAME)"
37+ @-git describe --tags > ./repo-info
38+ @mkdir -p $(CHARM_BUILD_DIR)/$(CHARM_NAME)
39+ @cp -r * $(CHARM_BUILD_DIR)/$(CHARM_NAME)
40+
41+lint: $(CHARM_HELPERS)
42 @tox -e pep8
43 @charm proof
44
45-test:
46+test: $(CHARM_HELPERS)
47 @echo Starting unit tests...
48 @tox -e py3
49
50@@ -18,7 +32,10 @@ deploy:
51 health:
52 juju ssh elasticsearch/0 "curl http://localhost:9200/_cluster/health?pretty=true"
53
54-sync-charm-helpers-stable:
55+.PHONY: sync-charm-helpers-stable
56+sync-charm-helpers-stable: $(CHARM_HELPERS)
57+
58+$(CHARM_HELPERS): .gitmodules
59 @git submodule update --init
60
61 sync-charm-helpers-master:
62diff --git a/charm-helpers b/charm-helpers
63index 068fa70..a9810ba 160000
64--- a/charm-helpers
65+++ b/charm-helpers
66@@ -1 +1 @@
67-Subproject commit 068fa70b4604b4247811691d31bd057cad9ab8c8
68+Subproject commit a9810baa1d34b30f20f0a97b577b0ceaee3a66dd
69diff --git a/hooks/hooks.py b/hooks/hooks.py
70index 483065c..3a483b0 100755
71--- a/hooks/hooks.py
72+++ b/hooks/hooks.py
73@@ -4,16 +4,21 @@ import os
74 import shutil
75 import sys
76 import json
77-import requests
78-
79 import charmhelpers.contrib.ansible
80 import charmhelpers.payload.execd
81 import charmhelpers.core.host
82 from charmhelpers.core import hookenv
83-from charmhelpers.fetch import add_source
84-from charmhelpers.fetch import apt_update
85+from charmhelpers.fetch import add_source, apt_update, install
86 from charmhelpers.contrib.charmsupport import nrpe
87
88+
89+try:
90+ import requests
91+except ImportError:
92+ install(['python3-requests'])
93+ import requests
94+
95+
96 mountpoint = '/srv/elasticsearch'
97
98 hooks = charmhelpers.contrib.ansible.AnsibleHooks(
99diff --git a/playbook.yaml b/playbook.yaml
100index 311542d..d1333ad 100644
101--- a/playbook.yaml
102+++ b/playbook.yaml
103@@ -62,6 +62,7 @@
104 - install
105 - upgrade-charm
106 - client-relation-joined
107+ - update-status
108 shell: apt-cache policy elasticsearch | grep -oe 'Installed:.*' | cut -d' ' -f2
109 register: es_version
110
111diff --git a/tasks/install-elasticsearch.yml b/tasks/install-elasticsearch.yml
112index c0f2b8b..2a18b97 100644
113--- a/tasks/install-elasticsearch.yml
114+++ b/tasks/install-elasticsearch.yml
115@@ -8,13 +8,23 @@
116 command: gpgconf --kill gpg-agent
117 ignore_errors: yes
118
119+- name: Add apt key (trusty).
120+ tags:
121+ - install
122+ - upgrade-charm
123+ - config-changed
124+ shell: HTTPS_PROXY={{ lookup('env','JUJU_CHARM_HTTPS_PROXY') }} curl -s {{ apt_key_url }} | apt-key add -
125+ when: (apt_key_url != "" and gpg_key == "" and ansible_distribution == 'Ubuntu' and ansible_distribution_release == 'trusty')
126+
127 - name: Add apt key.
128 tags:
129 - install
130 - upgrade-charm
131 - config-changed
132 apt_key: url={{ apt_key_url }} state=present id={{gpg_key_id}}
133- when: (apt_key_url != "" and gpg_key == "")
134+ environment:
135+ https_proxy: "{{ lookup('env','JUJU_CHARM_HTTPS_PROXY') }}"
136+ when: (apt_key_url != "" and gpg_key == "" and ansible_distribution == 'Ubuntu' and ansible_distribution_release != 'trusty')
137
138 - name: Add an apt key in a raw format.
139 tags:
140diff --git a/tasks/setup-ufw.yml b/tasks/setup-ufw.yml
141index 9d64353..32c74a7 100644
142--- a/tasks/setup-ufw.yml
143+++ b/tasks/setup-ufw.yml
144@@ -49,4 +49,4 @@
145
146 - name: Deny all incoming requests on 9300 once unit is part of cluster
147 ufw: rule=deny port=9300
148- when: firewall_enabled and cluster_health is success and cluster_health.json.number_of_nodes > 1
149+ when: firewall_enabled and cluster_health is defined and cluster_health is success and cluster_health.json.number_of_nodes > 1

Subscribers

People subscribed via source and target branches

to all changes: