Merge lp:~tvansteenburgh/charms/trusty/mongodb/test-refactor into lp:charms/trusty/mongodb
- Trusty Tahr (14.04)
- test-refactor
- Merge into trunk
Status: | Merged |
---|---|
Merge reported by: | Matt Bruzek |
Merged at revision: | not available |
Proposed branch: | lp:~tvansteenburgh/charms/trusty/mongodb/test-refactor |
Merge into: | lp:charms/trusty/mongodb |
Diff against target: |
491 lines (+102/-215) 10 files modified
Makefile (+1/-1) hooks/hooks.py (+15/-13) tests/00-setup (+1/-1) tests/01_test_write_log_rotate_config.py (+41/-0) tests/10-unit.test (+0/-12) tests/100_configs.test (+0/-73) tests/200_deploy.test (+2/-2) tests/200_relate_ceilometer.test (+42/-32) tests/get-unit-info (+0/-46) tests/test_write_log_rotate_config.py (+0/-35) |
To merge this branch: | bzr merge lp:~tvansteenburgh/charms/trusty/mongodb/test-refactor |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Matt Bruzek (community) | Approve | ||
Whit Morriss (community) | Approve | ||
Review via email: mp+240740@code.launchpad.net |
Commit message
Description of the change
Refactor tests. No tests have been removed, only restructured.
Ryan Beisner (1chb1n) wrote : | # |
Ryan Beisner (1chb1n) wrote : | # |
UOSCI bot says:
charm_unit_test #760 trusty-mongodb for tvansteenburgh mp240740
UNIT FAIL: unit-test missing
UNIT Results (max last 5 lines):
INFO:root:Workspace dir: /var/lib/
INFO:root:Reading file: Makefile
INFO:root:Searching for: ['nosetest', 'unit.test']
INFO:root:Search string not found in makefile target commands.
ERROR:root:No make target was executed.
Full unit test output: http://
Build: http://
Ryan Beisner (1chb1n) wrote : | # |
UOSCI bot says:
charm_amulet_test #343 trusty-mongodb for tvansteenburgh mp240740
AMULET FAIL: amulet-test missing
AMULET Results (max last 5 lines):
INFO:root:Workspace dir: /var/lib/
INFO:root:Reading file: Makefile
INFO:root:Searching for: ['@juju test']
INFO:root:Search string not found in makefile target commands.
ERROR:root:No make target was executed.
Full amulet test output: http://
Build: http://
Whit Morriss (whitmo) wrote : | # |
+1 LGTM
After finally getting the right version set up, tests ran and passed on 1.21beta2
Preview Diff
1 | === modified file 'Makefile' |
2 | --- Makefile 2014-07-08 18:53:07 +0000 |
3 | +++ Makefile 2014-11-05 15:54:19 +0000 |
4 | @@ -16,7 +16,7 @@ |
5 | PYTHON := /usr/bin/env python |
6 | |
7 | unittest: |
8 | - tests/10-unit.test |
9 | + tests/01_test_write_log_rotate_config.py |
10 | |
11 | sync: |
12 | @mkdir -p bin |
13 | |
14 | === modified file 'hooks/hooks.py' |
15 | --- hooks/hooks.py 2014-08-20 23:48:43 +0000 |
16 | +++ hooks/hooks.py 2014-11-05 15:54:19 +0000 |
17 | @@ -468,14 +468,14 @@ |
18 | current_try = 0 |
19 | while (process_check_pidfile('/var/run/mongodb/configsvr.pid') != |
20 | (None, None)) and not port_check( |
21 | - unit_get('public-address'), |
22 | + unit_get('private-address'), |
23 | config_data['config_server_port']) and current_try < max_tries: |
24 | juju_log("configsvr_status: Waiting for Config Server to be ready ...") |
25 | time.sleep(wait_for) |
26 | current_try += 1 |
27 | retVal = ( |
28 | process_check_pidfile('/var/run/mongodb/configsvr.pid') != (None, None) |
29 | - ) == port_check(unit_get('public-address'), |
30 | + ) == port_check(unit_get('private-address'), |
31 | config_data['config_server_port']) is True |
32 | if retVal: |
33 | return(process_check_pidfile('/var/run/mongodb/configsvr.pid')) |
34 | @@ -558,14 +558,14 @@ |
35 | current_try = 0 |
36 | while (process_check_pidfile('/var/run/mongodb/mongos.pid') != |
37 | (None, None)) and not port_check( |
38 | - unit_get('public-address'), |
39 | + unit_get('private-address'), |
40 | config_data['mongos_port']) and current_try < max_tries: |
41 | juju_log("mongos_status: Waiting for Mongo shell to be ready ...") |
42 | time.sleep(wait_for) |
43 | current_try += 1 |
44 | retVal = \ |
45 | (process_check_pidfile('/var/run/mongodb/mongos.pid') != |
46 | - (None, None)) == port_check(unit_get('public-address'), |
47 | + (None, None)) == port_check(unit_get('private-address'), |
48 | config_data['mongos_port']) is True |
49 | if retVal: |
50 | return(process_check_pidfile('/var/run/mongodb/mongos.pid')) |
51 | @@ -645,7 +645,7 @@ |
52 | |
53 | |
54 | def restart_mongod(wait_for=default_wait_for, max_tries=default_max_tries): |
55 | - my_hostname = unit_get('public-address') |
56 | + my_hostname = unit_get('private-address') |
57 | my_port = config('port') |
58 | current_try = 0 |
59 | |
60 | @@ -776,6 +776,8 @@ |
61 | print "current_mongodb_port: ", current_mongodb_port |
62 | public_address = unit_get('public-address') |
63 | print "public_address: ", public_address |
64 | + private_address = unit_get('private-address') |
65 | + print "private_address: ", private_address |
66 | |
67 | # Update mongodb configuration file |
68 | mongodb_config = mongodb_conf(config_data) |
69 | @@ -808,7 +810,7 @@ |
70 | |
71 | # attach to replSet ( if needed ) |
72 | if config_data['replicaset_master'] != "auto": |
73 | - join_replset(config_data['replicaset_master'], public_address) |
74 | + join_replset(config_data['replicaset_master'], private_address) |
75 | |
76 | # arbiter |
77 | if config_data['replicaset_master'] != 'auto': |
78 | @@ -816,7 +818,7 @@ |
79 | config_data['replicaset_master'] != "auto": |
80 | if config_data['arbiter'] == 'enable': |
81 | enable_arbiter(config_data['replicaset_master'], |
82 | - "%s:%s" % (public_address, config_data['port'])) |
83 | + "%s:%s" % (private_address, config_data['port'])) |
84 | else: |
85 | enable_arbiter(config_data['replicaset_master'], |
86 | config_data['arbiter']) |
87 | @@ -892,7 +894,7 @@ |
88 | @hooks.hook('database-relation-joined') |
89 | def database_relation_joined(): |
90 | juju_log("database_relation_joined") |
91 | - my_hostname = unit_get('public-address') |
92 | + my_hostname = unit_get('private-address') |
93 | my_port = config('port') |
94 | my_replset = config('replicaset') |
95 | juju_log("my_hostname: %s" % my_hostname) |
96 | @@ -910,7 +912,7 @@ |
97 | @hooks.hook('replicaset-relation-joined') |
98 | def replica_set_relation_joined(): |
99 | juju_log("replica_set_relation_joined") |
100 | - my_hostname = unit_get('public-address') |
101 | + my_hostname = unit_get('private-address') |
102 | my_port = config('port') |
103 | my_replset = config('replicaset') |
104 | my_install_order = os.environ['JUJU_UNIT_NAME'].split('/')[1] |
105 | @@ -933,7 +935,7 @@ |
106 | @hooks.hook('replicaset-relation-changed') |
107 | def replica_set_relation_changed(): |
108 | juju_log("replica_set_relation_changed") |
109 | - my_hostname = unit_get('public-address') |
110 | + my_hostname = unit_get('private-address') |
111 | my_port = config('port') |
112 | my_install_order = os.environ['JUJU_UNIT_NAME'].split('/')[1] |
113 | my_replicaset_master = config('replicaset_master') |
114 | @@ -1014,7 +1016,7 @@ |
115 | @hooks.hook('configsvr-relation-joined') |
116 | def configsvr_relation_joined(): |
117 | juju_log("configsvr_relation_joined") |
118 | - my_hostname = unit_get('public-address') |
119 | + my_hostname = unit_get('private-address') |
120 | my_port = config('config_server_port') |
121 | my_install_order = os.environ['JUJU_UNIT_NAME'].split('/')[1] |
122 | relation_set(relation_id(), |
123 | @@ -1038,7 +1040,7 @@ |
124 | @hooks.hook('mongos-relation-joined') |
125 | def mongos_relation_joined(): |
126 | juju_log("mongos_relation_joined") |
127 | - my_hostname = unit_get('public-address') |
128 | + my_hostname = unit_get('private-address') |
129 | my_port = config('mongos_port') |
130 | my_install_order = os.environ['JUJU_UNIT_NAME'].split('/')[1] |
131 | relation_set(relation_id(), |
132 | @@ -1079,7 +1081,7 @@ |
133 | elif rel_type == 'database': |
134 | if mongos_ready(): |
135 | mongos_host = "%s:%s" % ( |
136 | - unit_get('public-address'), |
137 | + unit_get('private-address'), |
138 | config('mongos_port')) |
139 | shard_command1 = "sh.addShard(\"%s:%s\")" % (hostname, port) |
140 | mongo_client(mongos_host, shard_command1) |
141 | |
142 | === modified file 'tests/00-setup' (properties changed: -x to +x) |
143 | --- tests/00-setup 2014-07-30 17:48:09 +0000 |
144 | +++ tests/00-setup 2014-11-05 15:54:19 +0000 |
145 | @@ -8,4 +8,4 @@ |
146 | sudo apt-get update |
147 | |
148 | |
149 | -sudo apt-get install amulet python3 python3-requests python3-pymongo juju-core charm-tools python-mock python-pymongo -y |
150 | +sudo apt-get install amulet python3 python3-requests python3-pymongo python-mock juju-core charm-tools -y |
151 | |
152 | === added file 'tests/01_test_write_log_rotate_config.py' |
153 | --- tests/01_test_write_log_rotate_config.py 1970-01-01 00:00:00 +0000 |
154 | +++ tests/01_test_write_log_rotate_config.py 2014-11-05 15:54:19 +0000 |
155 | @@ -0,0 +1,41 @@ |
156 | +#!/usr/bin/env python |
157 | + |
158 | +import mock |
159 | +import os |
160 | +import unittest |
161 | +import tempfile |
162 | +import sys |
163 | +sys.path.append('hooks') |
164 | +import hooks |
165 | + |
166 | + |
167 | +class TestWriteLogrotateConfigFile(unittest.TestCase): |
168 | + |
169 | + def test_success(self): |
170 | + logpath = '/tmp/foo/foo.log' |
171 | + config_data = { |
172 | + 'logpath': logpath, |
173 | + 'logrotate-frequency': 'daily', |
174 | + 'logrotate-maxsize': '5G', |
175 | + 'logrotate-rotate': 5, |
176 | + } |
177 | + fd, temp_fn = tempfile.mkstemp() |
178 | + os.close(fd) |
179 | + with mock.patch('hooks.juju_log') as mock_juju_log: |
180 | + with mock.patch('hooks.open', create=True) as mock_open: |
181 | + mock_open.return_value = mock.MagicMock(spec=file) |
182 | + hooks.write_logrotate_config(config_data, temp_fn) |
183 | + os.unlink(temp_fn) |
184 | + mock_juju_log.assert_called_once_with('Writing {}.'.format(temp_fn)) |
185 | + mock_open.assert_called_once_with(temp_fn, 'w') |
186 | + mock_file = mock_open().__enter__() |
187 | + call_args = mock_file.write.call_args[0][0] |
188 | + self.assertTrue(mock_file.write.called) |
189 | + self.assertIn(logpath, call_args) |
190 | + self.assertIn('daily', call_args) |
191 | + self.assertIn('maxsize 5G', call_args) |
192 | + self.assertIn('rotate 5', call_args) |
193 | + |
194 | + |
195 | +if __name__ == '__main__': |
196 | + unittest.main() |
197 | |
198 | === removed file 'tests/10-unit.test' |
199 | --- tests/10-unit.test 2013-12-11 13:17:03 +0000 |
200 | +++ tests/10-unit.test 1970-01-01 00:00:00 +0000 |
201 | @@ -1,12 +0,0 @@ |
202 | -#!/usr/bin/python |
203 | - |
204 | -"""Unit test suite.""" |
205 | - |
206 | -import os |
207 | -import sys |
208 | -import unittest |
209 | - |
210 | -runner = unittest.TextTestRunner(verbosity=2) |
211 | -suite = unittest.TestLoader().discover(os.path.dirname(__file__)) |
212 | -result = runner.run(suite) |
213 | -sys.exit(not result.wasSuccessful()) |
214 | |
215 | === removed file 'tests/100_configs.test' |
216 | --- tests/100_configs.test 2014-02-25 21:37:07 +0000 |
217 | +++ tests/100_configs.test 1970-01-01 00:00:00 +0000 |
218 | @@ -1,73 +0,0 @@ |
219 | -#!/bin/sh |
220 | - |
221 | -set -e |
222 | - |
223 | -teardown() { |
224 | - juju destroy-service mongodb |
225 | -} |
226 | -trap teardown EXIT |
227 | - |
228 | -juju deploy mongodb |
229 | -juju expose mongodb |
230 | - |
231 | -for try in `seq 1 600` ; do |
232 | - host=`juju status | tests/get-unit-info mongodb public-address` |
233 | - |
234 | - if [ -z "$host" ] ; then |
235 | - sleep 10 |
236 | - else |
237 | - break |
238 | - fi |
239 | -done |
240 | - |
241 | -if [ -z "$host" ] ; then |
242 | - echo FAIL: host timed out |
243 | - exit 1 |
244 | -fi |
245 | - |
246 | -assert_unit_ready() { |
247 | - for try in `seq 1 600` ; do |
248 | - status=`juju status | tests/get-unit-info mongodb agent-state` |
249 | - if [ "$status" != "started" ] ; then |
250 | - sleep 10 |
251 | - else |
252 | - echo "found status as $status" |
253 | - break |
254 | - fi |
255 | - done |
256 | - |
257 | - if [ -z "$status" ] ; then |
258 | - echo FAIL: status timed out |
259 | - exit 1 |
260 | - fi |
261 | -} |
262 | - |
263 | -assert_is_listening() { |
264 | - local port=$1 |
265 | - tries=$2 |
266 | - listening="" |
267 | - for try in `seq 1 $tries` ; do |
268 | - if ! nc $host $port < /dev/null ; then |
269 | - continue |
270 | - fi |
271 | - listening="27017" |
272 | - break |
273 | - done |
274 | - |
275 | - if [ -z "$listening" ] ; then |
276 | - echo "FAIL: not listening on port $port after $tries retries" |
277 | - return 1 |
278 | - else |
279 | - echo "PASS: listening on port $port" |
280 | - return 0 |
281 | - fi |
282 | -} |
283 | - |
284 | -assert_unit_ready |
285 | - |
286 | -assert_is_listening 27017 10 |
287 | - |
288 | -juju set mongodb port=55555 |
289 | -assert_is_listening 55555 200000 |
290 | -echo PASS: config changes tests passed. |
291 | -exit 0 |
292 | |
293 | === modified file 'tests/200_deploy.test' |
294 | --- tests/200_deploy.test 2014-02-03 22:18:52 +0000 |
295 | +++ tests/200_deploy.test 2014-11-05 15:54:19 +0000 |
296 | @@ -8,12 +8,12 @@ |
297 | # Test Quick Config |
298 | ######################################################### |
299 | scale = 1 |
300 | -seconds = 1400 |
301 | +seconds = 2500 |
302 | |
303 | ######################################################### |
304 | # 3shard cluster configuration |
305 | ######################################################### |
306 | -d = amulet.Deployment() |
307 | +d = amulet.Deployment(series='trusty') |
308 | |
309 | d.add('configsvr', charm='mongodb', units=scale) |
310 | d.add('mongos', charm='mongodb', units=scale) |
311 | |
312 | === modified file 'tests/200_relate_ceilometer.test' |
313 | --- tests/200_relate_ceilometer.test 2014-07-29 19:57:17 +0000 |
314 | +++ tests/200_relate_ceilometer.test 2014-11-05 15:54:19 +0000 |
315 | @@ -1,43 +1,53 @@ |
316 | #!/usr/bin/env python3 |
317 | |
318 | +import unittest |
319 | +import subprocess |
320 | import amulet |
321 | -import pdb |
322 | - |
323 | -class TestDeploy(object): |
324 | - |
325 | - def __init__(self, time=2500): |
326 | - # Attempt to load the deployment topology from a bundle. |
327 | - self.deploy = amulet.Deployment(series="trusty") |
328 | - |
329 | - # If something errored out, attempt to continue by |
330 | - # manually specifying a standalone deployment |
331 | - self.deploy.add('mongodb') |
332 | - self.deploy.add('ceilometer', 'cs:trusty/ceilometer') |
333 | - # send blank configs to finalize the objects in the deployment map |
334 | - self.deploy.configure('mongodb', {}) |
335 | - self.deploy.configure('ceilometer', {}) |
336 | - |
337 | - self.deploy.relate('mongodb:database', 'ceilometer:shared-db') |
338 | + |
339 | + |
340 | +class TestDeploy(unittest.TestCase): |
341 | + |
342 | + @classmethod |
343 | + def setUpClass(cls): |
344 | + time = 2500 |
345 | + |
346 | + d = amulet.Deployment(series="trusty") |
347 | + d.add('mongodb') |
348 | + d.add('ceilometer', 'cs:trusty/ceilometer') |
349 | + d.relate('mongodb:database', 'ceilometer:shared-db') |
350 | + d.expose('mongodb') |
351 | |
352 | try: |
353 | - self.deploy.setup(time) |
354 | - self.deploy.sentry.wait(time) |
355 | + d.setup(time) |
356 | + d.sentry.wait(time) |
357 | + except amulet.helpers.TimeoutError: |
358 | + amulet.raise_status(amulet.FAIL, msg="Environment standup timeout") |
359 | except: |
360 | - amulet.raise_status(amulet.FAIL, msg="Environment standup timeout") |
361 | - # sentry = self.deploy.sentry |
362 | + raise |
363 | |
364 | - def run(self): |
365 | - for test in dir(self): |
366 | - if test.startswith('test_'): |
367 | - getattr(self, test)() |
368 | + cls.mongo = d.sentry['mongodb/0'] |
369 | + cls.ceilometer = d.sentry['ceilometer/0'] |
370 | + cls.deployment = d |
371 | |
372 | def test_mongo_relation(self): |
373 | - unit = self.deploy.sentry.unit['ceilometer/0'] |
374 | - mongo = self.deploy.sentry.unit['mongodb/0'].info['public-address'] |
375 | - cont = unit.file_contents('/etc/ceilometer/ceilometer.conf') |
376 | - if mongo not in cont: |
377 | - amulet.raise_status(amulet.FAIL, "Unable to verify ceilometer cfg") |
378 | + """Test that ceilometer config contains mongo host address""" |
379 | + mongo_private_address, _ = self.mongo.run('unit-get private-address') |
380 | + conf = self.ceilometer.file_contents('/etc/ceilometer/ceilometer.conf') |
381 | + self.assertTrue(mongo_private_address in conf) |
382 | + |
383 | + def test_port_change(self): |
384 | + """Test that mongo can be reached on its configured port""" |
385 | + host = self.mongo.info['public-address'] |
386 | + netcat = 'nc {} {} </dev/null' |
387 | + |
388 | + def check_port(port): |
389 | + self.deployment.configure('mongodb', {'port': port}) |
390 | + self.deployment.sentry.wait() |
391 | + return subprocess.call(netcat.format(host, port), shell=True) |
392 | + |
393 | + self.assertEqual(0, check_port(55555)) |
394 | + self.assertEqual(0, check_port(27017)) |
395 | + |
396 | |
397 | if __name__ == '__main__': |
398 | - runner = TestDeploy() |
399 | - runner.run() |
400 | + unittest.main() |
401 | |
402 | === removed file 'tests/get-unit-info' |
403 | --- tests/get-unit-info 2012-01-31 01:19:12 +0000 |
404 | +++ tests/get-unit-info 1970-01-01 00:00:00 +0000 |
405 | @@ -1,46 +0,0 @@ |
406 | -#!/usr/bin/python |
407 | -# machines: |
408 | -# 0: {dns-name: ec2-50-17-84-127.compute-1.amazonaws.com, instance-id: i-8c5c3fec} |
409 | -# 1: {dns-name: ec2-184-73-102-113.compute-1.amazonaws.com, instance-id: i-14a2c174} |
410 | -# 2: {dns-name: ec2-75-101-184-93.compute-1.amazonaws.com, instance-id: i-e0a2c180} |
411 | -# services: |
412 | -# mysql: |
413 | -# charm: local:mysql-11 |
414 | -# relations: {db: wordpress} |
415 | -# units: |
416 | -# mysql/0: |
417 | -# machine: 2 |
418 | -# relations: |
419 | -# db: {state: up} |
420 | -# state: started |
421 | -# wordpress: |
422 | -# charm: local:wordpress-31 |
423 | -# exposed: true |
424 | -# relations: {db: mysql} |
425 | -# units: |
426 | -# wordpress/0: |
427 | -# machine: 1 |
428 | -# open-ports: [] |
429 | -# relations: {} |
430 | -# state: null |
431 | - |
432 | -import yaml |
433 | -import sys |
434 | -from subprocess import Popen, PIPE |
435 | - |
436 | - |
437 | -def main(): |
438 | - d = yaml.safe_load(Popen(['juju','status'],stdout=PIPE).stdout) |
439 | - srv = d.get("services", {}).get(sys.argv[1]) |
440 | - if srv is None: |
441 | - return |
442 | - units = srv.get("units", {}) |
443 | - if units is None: |
444 | - return |
445 | - item = units.items()[0][1].get(sys.argv[2]) |
446 | - if item is None: |
447 | - return |
448 | - print item |
449 | - |
450 | -if __name__ == "__main__": |
451 | - main() |
452 | |
453 | === removed file 'tests/test_write_log_rotate_config.py' |
454 | --- tests/test_write_log_rotate_config.py 2014-04-11 22:00:15 +0000 |
455 | +++ tests/test_write_log_rotate_config.py 1970-01-01 00:00:00 +0000 |
456 | @@ -1,35 +0,0 @@ |
457 | -import mock |
458 | -import os |
459 | -import unittest |
460 | -import tempfile |
461 | -import sys |
462 | -sys.path.append('hooks') |
463 | -import hooks |
464 | - |
465 | - |
466 | -class TestWriteLogrotateConfigFile(unittest.TestCase): |
467 | - |
468 | - def test_success(self): |
469 | - logpath = '/tmp/foo/foo.log' |
470 | - config_data = { |
471 | - 'logpath': logpath, |
472 | - 'logrotate-frequency': 'daily', |
473 | - 'logrotate-maxsize': '5G', |
474 | - 'logrotate-rotate': 5, |
475 | - } |
476 | - fd, temp_fn = tempfile.mkstemp() |
477 | - os.close(fd) |
478 | - with mock.patch('hooks.juju_log') as mock_juju_log: |
479 | - with mock.patch('hooks.open', create=True) as mock_open: |
480 | - mock_open.return_value = mock.MagicMock(spec=file) |
481 | - hooks.write_logrotate_config(config_data, temp_fn) |
482 | - os.unlink(temp_fn) |
483 | - mock_juju_log.assert_called_once_with('Writing {}.'.format(temp_fn)) |
484 | - mock_open.assert_called_once_with(temp_fn, 'w') |
485 | - mock_file = mock_open().__enter__() |
486 | - call_args = mock_file.write.call_args[0][0] |
487 | - self.assertTrue(mock_file.write.called) |
488 | - self.assertIn(logpath, call_args) |
489 | - self.assertIn('daily', call_args) |
490 | - self.assertIn('maxsize 5G', call_args) |
491 | - self.assertIn('rotate 5', call_args) |
UOSCI bot says:
charm_lint_check #925 trusty-mongodb for tvansteenburgh mp240740
LINT FAIL: lint-test missing
LINT Results (max last 5 lines): jenkins/ workspace/ charm_lint_ check
INFO:root:Workspace dir: /var/lib/
INFO:root:Reading file: Makefile
INFO:root:Searching for: ['@flake8']
INFO:root:Search string not found in makefile target commands.
ERROR:root:No make target was executed.
Full lint test output: http:// paste.ubuntu. com/8837661/ 10.98.191. 181:8080/ job/charm_ lint_check/ 925/
Build: http://