Merge lp:~tanuki/charms/trusty/tanuki-result-enum-api/trunk-add-conn-check-support into lp:~tanuki/charms/trusty/tanuki-result-enum-api/trunk

Proposed by Thomi Richards
Status: Merged
Approved by: Guillermo Gonzalez
Approved revision: 27
Merged at revision: 16
Proposed branch: lp:~tanuki/charms/trusty/tanuki-result-enum-api/trunk-add-conn-check-support
Merge into: lp:~tanuki/charms/trusty/tanuki-result-enum-api/trunk
Diff against target: 154 lines (+82/-8)
4 files modified
config.yaml (+10/-5)
hooks/actions.py (+64/-1)
hooks/services.py (+4/-1)
metadata.yaml (+4/-1)
To merge this branch: bzr merge lp:~tanuki/charms/trusty/tanuki-result-enum-api/trunk-add-conn-check-support
Reviewer Review Type Date Requested Status
Guillermo Gonzalez Approve
Review via email: mp+267897@code.launchpad.net

Commit message

Hook up conn-check support.

Description of the change

Hook up conn-check support.

To post a comment you must log in.
22. By Thomi Richards

Merge trunk.

23. By Thomi Richards

Remove commented out code.

24. By Thomi Richards

Remove commented out code.

25. By Thomi Richards

Undo accidental removal of config option when merging trunk.

26. By Thomi Richards

Clean up indentation.

Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :

Note: the whitespace change inconfig.yaml is to clean up the indentation in that file :D

27. By Thomi Richards

Encode content as utf8.

Revision history for this message
Guillermo Gonzalez (verterok) wrote :

looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'config.yaml'
2--- config.yaml 2015-08-12 13:18:35 +0000
3+++ config.yaml 2015-08-13 05:36:34 +0000
4@@ -13,9 +13,14 @@
5 default: ""
6 description: |
7 Used by the nrpe subordinate charms.
8+ conn_check_config:
9+ type: string
10+ default: ""
11+ description: |
12+ A base64 encoded YAML config file for conn-check.
13 nagios_servicegroups:
14- default: ""
15- type: string
16- description: |
17- A comma-separated list of nagios servicegroups.
18- If left empty, the nagios_context will be used as the servicegroup
19+ default: ""
20+ type: string
21+ description: |
22+ A comma-separated list of nagios servicegroups.
23+ If left empty, the nagios_context will be used as the servicegroup
24
25=== modified file 'hooks/actions.py'
26--- hooks/actions.py 2015-08-11 00:00:58 +0000
27+++ hooks/actions.py 2015-08-13 05:36:34 +0000
28@@ -1,6 +1,7 @@
29 import base64
30 import configparser
31 import os
32+import os.path
33 import subprocess
34
35 from charmhelpers import fetch
36@@ -15,7 +16,10 @@
37
38
39 REQUIRED_PACKAGES = [
40- 'python-virtualenv', 'python3-dev', 'python3-jinja2'
41+ 'python-virtualenv',
42+ 'python3-dev',
43+ 'python3-jinja2',
44+ 'python3-yaml',
45 ]
46
47 WSGI_USER = 'www-data'
48@@ -26,6 +30,7 @@
49 BASE_DIR = '/srv/result-enum-api/{}'.format(config['environment'])
50 SERVICE_DIR = os.path.join(BASE_DIR, 'result-enum-api')
51 LOG_DIR = os.path.join(BASE_DIR, 'logs')
52+ETC_DIR = os.path.join(BASE_DIR, 'etc')
53
54
55 def log_start(service_name):
56@@ -128,6 +133,64 @@
57 return data
58
59
60+class ConnCheckRelation(helpers.RelationContext):
61+
62+ name = 'conn-check'
63+ interface = 'conn-check'
64+ required_keys = []
65+
66+ def provide_data(self):
67+ import yaml
68+ config = hookenv.config()
69+ conn_check_config = []
70+ base64_config = config.get('conn_check_config')
71+ if base64_config:
72+ conn_check_config.extend(
73+ yaml.safe_load(base64.b64decode(base64_config))
74+ )
75+ conn_check_config.extend(self._get_mongodb_checks())
76+ # save the yaml conn-check config file
77+ content = yaml.dump(conn_check_config, default_flow_style=False)
78+ conn_check_config_path = os.path.join(
79+ ETC_DIR,
80+ 'conn-check-config.yaml'
81+ )
82+ conn_check_config_dir = os.path.dirname(conn_check_config_path)
83+ if not os.path.exists(conn_check_config_dir):
84+ host.mkdir(conn_check_config_dir)
85+ host.write_file(
86+ conn_check_config_path,
87+ content.encode('utf8'),
88+ owner='ubuntu',
89+ group='nagios',
90+ perms=0o440
91+ )
92+ # notify the relation
93+ return dict(config_path=conn_check_config_path,
94+ nagios_servicegroups=config['nagios_context'])
95+
96+ def _get_mongodb_checks(self):
97+ config = hookenv.config()
98+ checks = []
99+ db_rels = hookenv.relations_of_type('mongodb')
100+
101+ config_content = base64.b64decode(config['config-file']).decode()
102+ parser = configparser.ConfigParser()
103+ parser.read_string(config_content)
104+ database = parser['mongodb'].get('dbname', 'testresults')
105+ for server in db_rels:
106+ if 'private-address' not in server:
107+ continue
108+ db_check = {
109+ 'type': 'mongodb',
110+ 'host': server['private-address'],
111+ 'port': int(server.get('port', '27017')),
112+ 'database': database,
113+ }
114+ checks.append(db_check)
115+ return checks
116+
117+
118 def nrpe_external_master_relation(service_name):
119 ''' Configure the nrpe-external-master relation '''
120 nrpe_compat = nrpe.NRPE()
121
122=== added symlink 'hooks/conn-check-relation-changed'
123=== target is u'hooks.py'
124=== modified file 'hooks/services.py'
125--- hooks/services.py 2015-08-10 15:39:51 +0000
126+++ hooks/services.py 2015-08-13 05:36:34 +0000
127@@ -18,7 +18,10 @@
128 manager = ServiceManager([
129 {
130 'service': 'result-enum-api',
131- 'provided_data': [actions.WebsiteRelation()],
132+ 'provided_data': [
133+ actions.WebsiteRelation(),
134+ actions.ConnCheckRelation(),
135+ ],
136 'required_data': [config, MongoRelation()],
137 'data_ready': [
138 actions.ensure_directories,
139
140=== modified file 'metadata.yaml'
141--- metadata.yaml 2015-08-05 01:21:23 +0000
142+++ metadata.yaml 2015-08-13 05:36:34 +0000
143@@ -10,6 +10,9 @@
144 nrpe-external-master:
145 interface: nrpe-external-master
146 scope: container
147+ conn-check:
148+ interface: conn-check
149+ scope: container
150 requires:
151 mongodb:
152- interface: mongodb
153\ No newline at end of file
154+ interface: mongodb

Subscribers

People subscribed via source and target branches

to all changes: