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

Proposed by Guillermo Gonzalez
Status: Merged
Approved by: Guillermo Gonzalez
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) Approve
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.
Revision history for this message
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
=== modified file 'hooks/client-relation-changed'
--- hooks/client-relation-changed 2014-09-23 16:59:13 +0000
+++ hooks/client-relation-changed 2015-09-08 16:27:29 +0000
@@ -34,24 +34,26 @@
3434
35 out = os.path.join(BASEPATH, 'conf.d', 'output-elasticsearch.conf')35 out = os.path.join(BASEPATH, 'conf.d', 'output-elasticsearch.conf')
36 with open(out, 'w') as p:36 with open(out, 'w') as p:
37 p.write(render(os.path.basename(out), opts))37 p.write(render(os.path.basename(out), opts))
38
3938
4039
41def cache_hosts():40def cache_hosts():
42 host = hookenv.relation_get('host')41 rels = hookenv.relations_of_type("client")
43 if not host:42 if not rels:
44 log('No host received. Assuming nothing to do.')43 log('No client relations. Assuming nothing to do.')
45 sys.exit(0)44 sys.exit(0)
46
47 if not os.path.exists('host_cache'):45 if not os.path.exists('host_cache'):
48 open('host_cache', 'a').close()46 open('host_cache', 'a').close()
4947 for rel in rels:
50 with open('host_cache', 'r') as f:48 host = rel.get('host')
51 hosts = f.readlines()49 if not host:
52 if not host in hosts:50 log('No host received for relation: {}.'.format(rel))
53 with open('host_cache', 'a') as f:51 continue
54 f.write('{}\n'.format(host))52 with open('host_cache', 'r') as f:
53 hosts = f.readlines()
54 if host not in hosts:
55 with open('host_cache', 'a') as f:
56 f.write('{}\n'.format(host))
5557
5658
57if __name__ == "__main__":59if __name__ == "__main__":
5860
=== modified file 'hooks/config-changed'
--- hooks/config-changed 2015-09-01 22:03:23 +0000
+++ hooks/config-changed 2015-09-08 16:27:29 +0000
@@ -59,6 +59,10 @@
59 key_file = os.path.join(cert_dir, 'logstash.key')59 key_file = os.path.join(cert_dir, 'logstash.key')
6060
61 for f in files:61 for f in files:
62 # skip output-elasticsearch.conf, is managed by
63 # hooks/client-relation-changed
64 if os.path.basename(f) == "output-elasticsearch.conf":
65 continue
62 if os.path.basename(f) != lumberjack_template:66 if os.path.basename(f) != lumberjack_template:
63 with open(os.path.join(BASEPATH, 'conf.d', f), 'w') as p:67 with open(os.path.join(BASEPATH, 'conf.d', f), 'w') as p:
64 p.write(render(os.path.basename(f), opts))68 p.write(render(os.path.basename(f), opts))

Subscribers

People subscribed via source and target branches