Merge lp:~billy-olsen/charms/trusty/mongodb/lp1513094 into lp:charms/trusty/mongodb
- Trusty Tahr (14.04)
- lp1513094
- Merge into trunk
Status: | Merged |
---|---|
Merged at revision: | 89 |
Proposed branch: | lp:~billy-olsen/charms/trusty/mongodb/lp1513094 |
Merge into: | lp:charms/trusty/mongodb |
Diff against target: |
319 lines (+83/-91) 5 files modified
hooks/hooks.py (+60/-86) tests/01_deploy_single.py (+1/-1) tests/02_deploy_shard_test.py (+2/-2) tests/03_deploy_replicaset.py (+2/-2) unit_tests/test_hooks.py (+18/-0) |
To merge this branch: | bzr merge lp:~billy-olsen/charms/trusty/mongodb/lp1513094 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ryan Beisner (community) | Needs Information | ||
Andrew McLeod (community) | Needs Fixing | ||
Review Queue (community) | automated testing | Needs Fixing | |
Review via email: mp+294565@code.launchpad.net |
Commit message
Description of the change
uosci-testing-bot (uosci-testing-bot) wrote : | # |
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_unit_test #1989 mongodb for billy-olsen mp294565
UNIT OK: passed
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #743 mongodb for billy-olsen mp294565
AMULET FAIL: amulet-test failed
AMULET Results (max last 2 lines):
make: *** [functional_test] Error 1
ERROR:root:Make target returned non-zero.
Full amulet test output: http://
Build: http://
Review Queue (review-queue) wrote : | # |
This item has failed automated testing! Results available here http://
Review Queue (review-queue) wrote : | # |
This item has failed automated testing! Results available here http://
Andrew McLeod (admcleod) wrote : | # |
Hi there Billy,
This is failing with the following. I wonder if this is just a matter of naming in the tests?
bundletester -vFt tests/ -l DEBUG -e sneerAWS --no-destroy
With the following 2 errors:
Failed to find running MongoDB on host config-sentry
Failed to find running MongoDB on host mongodb1-sentry
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_unit_test #6 mongodb for billy-olsen mp294565
UNIT FAIL: unit-test failed
UNIT Results (max last 2 lines):
Makefile:35: recipe for target 'test' failed
ERROR:root:Make target returned non-zero.
Full unit test output: http://
Build: http://
Ryan Beisner (1chb1n) wrote : | # |
Can we please refactor the unit test and bundletester test environments here to build a virtualenv, use tox, ostestr, etc., a la OpenStack Charms? Extra credit for that! ;-)
Bottom line is the test suite won't pass anymore in OSCI, as we're getting very strict with tests that try to bring in arbitrary debs.
The litmus test is this:
A fresh Xenial instance. Juju, juju-deployer, charm-tools debs installed. Everything else in a venv. Tests should exec and pass.
Thank you!
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_lint_check #17 mongodb for billy-olsen mp294565
LINT OK: passed
Preview Diff
1 | === modified file 'hooks/hooks.py' |
2 | --- hooks/hooks.py 2016-02-26 14:00:17 +0000 |
3 | +++ hooks/hooks.py 2016-05-12 20:29:50 +0000 |
4 | @@ -46,6 +46,7 @@ |
5 | from charmhelpers.core.hookenv import ( |
6 | close_port, |
7 | config, |
8 | + is_relation_made, |
9 | open_port, |
10 | unit_get, |
11 | relation_get, |
12 | @@ -331,6 +332,10 @@ |
13 | if not config_data['web_admin_ui']: |
14 | config.append("nohttpinterface = true") |
15 | config.append("") |
16 | + else: |
17 | + config.append("rest = true") |
18 | + config.append("httpinterface = true") |
19 | + config.append("") |
20 | |
21 | # noscripting |
22 | if config_data['noscripting']: |
23 | @@ -367,14 +372,23 @@ |
24 | config.append("mms-interval = %s" % config_data['mms-interval']) |
25 | config.append("") |
26 | |
27 | - # master/slave |
28 | - if config_data['master'] == "self": |
29 | - config.append("master = true") |
30 | + # Set either replica-set or master, depending upon whether the |
31 | + # the replica-set (peer) relation is established. If the user |
32 | + # chooses to use juju scale out (e.g. juju add-unit) then the |
33 | + # charm will use replica-set replication. The user may opt to |
34 | + # do master/slave replication or sharding as a different form |
35 | + # of scaleout. |
36 | + if is_relation_made('replica-set'): |
37 | + config.append("replSet = %s" % config_data['replicaset']) |
38 | config.append("") |
39 | else: |
40 | - config.append("slave = true") |
41 | - config.append("source = %s" % config_data['master']) |
42 | - config.append("") |
43 | + if config_data['master'] == "self": |
44 | + config.append("master = true") |
45 | + config.append("") |
46 | + else: |
47 | + config.append("slave = true") |
48 | + config.append("source = %s" % config_data['master']) |
49 | + config.append("") |
50 | |
51 | # arbiter |
52 | if config_data['arbiter'] != "disabled" and \ |
53 | @@ -405,6 +419,27 @@ |
54 | return('\n'.join(config)) |
55 | |
56 | |
57 | +def get_current_mongo_config(): |
58 | + """Reads the current mongo configuration file and returns a dict |
59 | + containing the key/value pairs found in the configuration file. |
60 | + |
61 | + :returns dict: key/value pairs of the configuration file. |
62 | + """ |
63 | + results = {} |
64 | + with open(default_mongodb_config, 'r') as f: |
65 | + for line in f: |
66 | + line = line.strip() |
67 | + |
68 | + # Skip over comments, blank lines, and any other line |
69 | + # that appears to not contain a key = value pair. |
70 | + if line.startswith('#') or '=' not in line: |
71 | + continue |
72 | + |
73 | + key, value = line.split('=', 1) |
74 | + results[key.strip()] = value.strip() |
75 | + return results |
76 | + |
77 | + |
78 | def mongo_client(host=None, command=None): |
79 | if host is None or command is None: |
80 | return(False) |
81 | @@ -541,22 +576,19 @@ |
82 | try: |
83 | juju_log('enable_replset: trying to get lock on: %s' % |
84 | default_mongodb_init_config) |
85 | - with FileLock(INIT_LOCKFILE): |
86 | - juju_log('enable_replset: lock acquired', level=DEBUG) |
87 | - with open(default_mongodb_init_config) as mongo_init_file: |
88 | - mongodb_init_config = mongo_init_file.read() |
89 | - if re.search(' --replSet %s ' % replicaset_name, |
90 | - mongodb_init_config, re.MULTILINE) is None: |
91 | - juju_log('enable_replset: --replset not preset,' |
92 | - ' enabling', |
93 | - level=DEBUG) |
94 | - mongodb_init_config = regex_sub([(' -- ', |
95 | - ' -- --replSet %s ' % |
96 | - replicaset_name)], |
97 | - mongodb_init_config) |
98 | - update_file(default_mongodb_init_config, |
99 | - mongodb_init_config) |
100 | - retVal = True |
101 | + |
102 | + current_config = get_current_mongo_config() |
103 | + config_data = config() |
104 | + |
105 | + if 'replSet' in current_config and \ |
106 | + current_config['replSet'] == config_data['replicaset']: |
107 | + juju_log('enable_replset: replica set is already enabled', |
108 | + level=DEBUG) |
109 | + else: |
110 | + juju_log('enable_replset: enabling replicaset %s' % |
111 | + config_data['replicaset'], level=DEBUG) |
112 | + mongodb_config = mongodb_conf(config_data) |
113 | + retVal = update_file(default_mongodb_config, mongodb_config) |
114 | |
115 | juju_log('enable_replset will return: %s' % str(retVal), level=DEBUG) |
116 | |
117 | @@ -582,64 +614,6 @@ |
118 | return(update_file(default_mongodb_init_config, mongodb_init_config)) |
119 | |
120 | |
121 | -def disable_replset(replicaset_name=None): |
122 | - if replicaset_name is None: |
123 | - retVal = False |
124 | - try: |
125 | - mongodb_init_config = open(default_mongodb_init_config).read() |
126 | - if re.search(' --replSet %s ' % replicaset_name, |
127 | - mongodb_init_config, re.MULTILINE) is not None: |
128 | - mongodb_init_config = regex_sub([ |
129 | - (' --replSet %s ' % replicaset_name, ' ') |
130 | - ], mongodb_init_config) |
131 | - retVal = update_file(default_mongodb_init_config, mongodb_init_config) |
132 | - except Exception, e: |
133 | - juju_log(str(e)) |
134 | - retVal = False |
135 | - finally: |
136 | - return(retVal) |
137 | - |
138 | - |
139 | -def enable_web_admin_ui(port=None): |
140 | - if port is None: |
141 | - juju_log("enable_web_admin_ui: port not defined.") |
142 | - return(False) |
143 | - try: |
144 | - mongodb_init_config = open(default_mongodb_init_config).read() |
145 | - if re.search(' --rest ', mongodb_init_config, re.MULTILINE) is None: |
146 | - mongodb_init_config = regex_sub([(' -- ', ' -- --rest ')], |
147 | - mongodb_init_config) |
148 | - retVal = update_file(default_mongodb_init_config, mongodb_init_config) |
149 | - except Exception, e: |
150 | - juju_log(str(e)) |
151 | - retVal = False |
152 | - finally: |
153 | - if retVal: |
154 | - open_port(port) |
155 | - return(retVal) |
156 | - |
157 | - |
158 | -def disable_web_admin_ui(port=None): |
159 | - if port is None: |
160 | - juju_log("disable_web_admin_ui: port not defined.") |
161 | - return(False) |
162 | - try: |
163 | - mongodb_init_config = open(default_mongodb_init_config).read() |
164 | - if re.search(' --rest ', |
165 | - mongodb_init_config, |
166 | - re.MULTILINE) is not None: |
167 | - mongodb_init_config = regex_sub([(' --rest ', ' ')], |
168 | - mongodb_init_config) |
169 | - retVal = update_file(default_mongodb_init_config, mongodb_init_config) |
170 | - except Exception, e: |
171 | - juju_log(str(e)) |
172 | - retVal = False |
173 | - finally: |
174 | - if retVal: |
175 | - close_port(port) |
176 | - return(retVal) |
177 | - |
178 | - |
179 | def enable_arbiter(master_node=None, host=None): |
180 | juju_log("enable_arbiter: master_node: %s, host: %s" % |
181 | (master_node, host)) |
182 | @@ -1002,9 +976,9 @@ |
183 | |
184 | # web_admin_ui |
185 | if config_data['web_admin_ui']: |
186 | - enable_web_admin_ui(new_web_admin_ui_port) |
187 | + open_port(new_web_admin_ui_port) |
188 | else: |
189 | - disable_web_admin_ui(current_web_admin_ui_port) |
190 | + close_port(current_web_admin_ui_port) |
191 | |
192 | # replicaset_master |
193 | if config_data['replicaset_master'] != "auto": |
194 | @@ -1141,7 +1115,7 @@ |
195 | relation_set(relation_id(), relation_data) |
196 | |
197 | |
198 | -@hooks.hook('replicaset-relation-joined') |
199 | +@hooks.hook('replica-set-relation-joined') |
200 | def replica_set_relation_joined(): |
201 | juju_log("replica_set_relation_joined-start") |
202 | my_hostname = unit_get('private-address') |
203 | @@ -1194,7 +1168,7 @@ |
204 | raise TimeoutException('Unable to determine if local unit is primary') |
205 | |
206 | |
207 | -@hooks.hook('replicaset-relation-changed') |
208 | +@hooks.hook('replica-set-relation-changed') |
209 | def replica_set_relation_changed(): |
210 | private_address = unit_get('private-address') |
211 | remote_hostname = relation_get('hostname') |
212 | @@ -1228,7 +1202,7 @@ |
213 | juju_log('replica_set_relation_changed-finish') |
214 | |
215 | |
216 | -@hooks.hook('replicaset-relation-departed') |
217 | +@hooks.hook('replica-set-relation-departed') |
218 | def replica_set_relation_departed(): |
219 | juju_log('replica_set_relation_departed-start') |
220 | |
221 | @@ -1259,7 +1233,7 @@ |
222 | juju_log('replica_set_relation_departed-finish') |
223 | |
224 | |
225 | -@hooks.hook('replicaset-relation-broken') |
226 | +@hooks.hook('replica-set-relation-broken') |
227 | def replica_set_relation_broken(): |
228 | juju_log('replica_set_relation_broken-start') |
229 | |
230 | |
231 | === modified file 'tests/01_deploy_single.py' |
232 | --- tests/01_deploy_single.py 2015-11-17 22:00:56 +0000 |
233 | +++ tests/01_deploy_single.py 2016-05-12 20:29:50 +0000 |
234 | @@ -36,7 +36,7 @@ |
235 | amulet.raise_status(amulet.FAIL, msg="Failed to insert test data") |
236 | # Can we delete from a shard using the Mongos hub? |
237 | result = db.amulet.remove(insert_id) |
238 | - if result['err'] is not None: |
239 | + if 'err' in result and result['err'] is not None: |
240 | amulet.raise_status(amulet.FAIL, msg="Failed to remove test data") |
241 | |
242 | |
243 | |
244 | === modified file 'tests/02_deploy_shard_test.py' |
245 | --- tests/02_deploy_shard_test.py 2015-12-03 22:49:56 +0000 |
246 | +++ tests/02_deploy_shard_test.py 2016-05-12 20:29:50 +0000 |
247 | @@ -92,7 +92,7 @@ |
248 | def validate_running_services(): |
249 | for service in sentry_dict: |
250 | output = sentry_dict[service].run('service mongodb status') |
251 | - service_active = str(output).find('mongodb start/running') |
252 | + service_active = str(output).find('active (running)') |
253 | if service_active == -1: |
254 | message = "Failed to find running MongoDB on host {}".format( |
255 | service) |
256 | @@ -115,7 +115,7 @@ |
257 | amulet.raise_status(amulet.FAIL, msg="Failed to insert test data") |
258 | # Can we delete from a shard using the Mongos hub? |
259 | result = db.amulet.remove(insert_id) |
260 | - if result['err'] is not None: |
261 | + if 'err' in result and result['err'] is not None: |
262 | amulet.raise_status(amulet.FAIL, msg="Failed to remove test data") |
263 | |
264 | |
265 | |
266 | === modified file 'tests/03_deploy_replicaset.py' |
267 | --- tests/03_deploy_replicaset.py 2015-12-02 22:50:09 +0000 |
268 | +++ tests/03_deploy_replicaset.py 2016-05-12 20:29:50 +0000 |
269 | @@ -63,7 +63,7 @@ |
270 | def validate_running_services(): |
271 | for service in sentry_dict: |
272 | output = sentry_dict[service].run('service mongodb status') |
273 | - service_active = str(output).find('mongodb start/running') |
274 | + service_active = str(output).find('active (running)') |
275 | if service_active == -1: |
276 | message = "Failed to find running MongoDB on host {}".format( |
277 | service) |
278 | @@ -158,7 +158,7 @@ |
279 | amulet.raise_status(amulet.FAIL, msg="Failed to insert test data") |
280 | # Can we delete from a shard using the Mongos hub? |
281 | result = db.amulet.remove(insert_id) |
282 | - if result['err'] is not None: |
283 | + if 'err' in result and result['err'] is not None: |
284 | amulet.raise_status(amulet.FAIL, msg="Failed to remove test data") |
285 | |
286 | |
287 | |
288 | === modified file 'unit_tests/test_hooks.py' |
289 | --- unit_tests/test_hooks.py 2015-07-28 18:53:19 +0000 |
290 | +++ unit_tests/test_hooks.py 2016-05-12 20:29:50 +0000 |
291 | @@ -3,6 +3,7 @@ |
292 | import hooks |
293 | |
294 | from test_utils import CharmTestCase |
295 | +from test_utils import mock_open |
296 | from pymongo.errors import OperationFailure |
297 | from subprocess import CalledProcessError |
298 | |
299 | @@ -339,3 +340,20 @@ |
300 | |
301 | call1 = call('juju-local:27017', 'juju-remote:27017') |
302 | mock_leave_replset.assert_has_calls([call1]) |
303 | + |
304 | + def test_get_current_mongo_config(self): |
305 | + test_config = u""" |
306 | + # Comment |
307 | + key = value |
308 | + one=two |
309 | + |
310 | + three =four |
311 | + """ |
312 | + expected = { |
313 | + 'key': 'value', |
314 | + 'one': 'two', |
315 | + 'three': 'four' |
316 | + } |
317 | + with mock_open('/etc/mongodb.conf', test_config): |
318 | + results = hooks.get_current_mongo_config() |
319 | + self.assertEqual(results, expected) |
charm_lint_check #2558 mongodb for billy-olsen mp294565
LINT OK: passed
Build: http:// 10.245. 162.36: 8080/job/ charm_lint_ check/2558/