Merge lp:~verterok/charms/trusty/logstash/fix-the-thing into lp:~tanuki/charms/trusty/logstash/trunk

Proposed by Guillermo Gonzalez on 2015-09-08
Status: Merged
Approved by: Guillermo Gonzalez on 2015-09-08
Approved revision: 56
Merged at revision: 55
Proposed branch: lp:~verterok/charms/trusty/logstash/fix-the-thing
Merge into: lp:~tanuki/charms/trusty/logstash/trunk
Diff against target: 58 lines (+19/-13)
2 files modified
hooks/client-relation-changed (+15/-13)
hooks/config-changed (+4/-0)
To merge this branch: bzr merge lp:~verterok/charms/trusty/logstash/fix-the-thing
Reviewer Review Type Date Requested Status
Celso Providelo (community) 2015-09-08 Approve on 2015-09-08
Review via email: mp+270426@code.launchpad.net

Commit message

Fix config-changed to not overwrite ES config. Also make cache_hosts (in hooks/client-relation-changed) iterate over all client relations instead of just the current one.

Description of the change

- Make cache_hosts (in hooks/client-relation-changed) generic by iterate over all client relations, and fix identation.
  This simplified debugging the hooks. can remove it if there are any objections
- Fix copy_config (hooks/config-changed) to not overwrite output-elasticsearch.conf

To post a comment you must log in.
Celso Providelo (cprov) wrote :

Guillermo,

As pointed on IRC, good catch on the "output" template overwrite.

I am not sure how iterating over all "client" relations would affect us, specially when we have multiple ES units. However it's not a problem for now.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/client-relation-changed'
2--- hooks/client-relation-changed 2014-09-23 16:59:13 +0000
3+++ hooks/client-relation-changed 2015-09-08 16:27:29 +0000
4@@ -34,24 +34,26 @@
5
6 out = os.path.join(BASEPATH, 'conf.d', 'output-elasticsearch.conf')
7 with open(out, 'w') as p:
8- p.write(render(os.path.basename(out), opts))
9-
10+ p.write(render(os.path.basename(out), opts))
11
12
13 def cache_hosts():
14- host = hookenv.relation_get('host')
15- if not host:
16- log('No host received. Assuming nothing to do.')
17- sys.exit(0)
18-
19+ rels = hookenv.relations_of_type("client")
20+ if not rels:
21+ log('No client relations. Assuming nothing to do.')
22+ sys.exit(0)
23 if not os.path.exists('host_cache'):
24 open('host_cache', 'a').close()
25-
26- with open('host_cache', 'r') as f:
27- hosts = f.readlines()
28- if not host in hosts:
29- with open('host_cache', 'a') as f:
30- f.write('{}\n'.format(host))
31+ for rel in rels:
32+ host = rel.get('host')
33+ if not host:
34+ log('No host received for relation: {}.'.format(rel))
35+ continue
36+ with open('host_cache', 'r') as f:
37+ hosts = f.readlines()
38+ if host not in hosts:
39+ with open('host_cache', 'a') as f:
40+ f.write('{}\n'.format(host))
41
42
43 if __name__ == "__main__":
44
45=== modified file 'hooks/config-changed'
46--- hooks/config-changed 2015-09-01 22:03:23 +0000
47+++ hooks/config-changed 2015-09-08 16:27:29 +0000
48@@ -59,6 +59,10 @@
49 key_file = os.path.join(cert_dir, 'logstash.key')
50
51 for f in files:
52+ # skip output-elasticsearch.conf, is managed by
53+ # hooks/client-relation-changed
54+ if os.path.basename(f) == "output-elasticsearch.conf":
55+ continue
56 if os.path.basename(f) != lumberjack_template:
57 with open(os.path.join(BASEPATH, 'conf.d', f), 'w') as p:
58 p.write(render(os.path.basename(f), opts))

Subscribers

People subscribed via source and target branches