Merge lp:~lazypower/charms/precise/mongodb/tests into lp:charms/mongodb

Proposed by Charles Butler
Status: Merged
Merged at revision: 40
Proposed branch: lp:~lazypower/charms/precise/mongodb/tests
Merge into: lp:charms/mongodb
Diff against target: 147 lines (+138/-0)
2 files modified
tests/00_setup.sh (+11/-0)
tests/200_deploy.test (+127/-0)
To merge this branch: bzr merge lp:~lazypower/charms/precise/mongodb/tests
Reviewer Review Type Date Requested Status
charmers Pending
Review via email: mp+203560@code.launchpad.net

Description of the change

added amulet testing scaffold

Deploys a set similar to the bundle, with 2 shards, a mongo shell, and
configserver. Tests reachability of the ManagementUI, and accessability
between nodes, validates setup by issuing service mongodb status

https://codereview.appspot.com/56640044/

To post a comment you must log in.
Revision history for this message
Charles Butler (lazypower) wrote :

Reviewers: mp+203560_code.launchpad.net,

Message:
Please take a look.

Description:
added amulet testing scaffold

Deploys a set similar to the bundle, with 2 shards, a mongo shell, and
configserver. Tests reachability of the ManagementUI, and accessability
between nodes, validates setup by issuing service mongodb status

https://code.launchpad.net/~lazypower/charms/precise/mongodb/tests/+merge/203560

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/56640044/

Affected files (+118, -0 lines):
   A [revision details]
   A tests/00_setup.sh
   A tests/200_deploy.test

Revision history for this message
Matt Bruzek (mbruzek) wrote :

Looks good Chuck. I had a few comments on the setup script.

https://codereview.appspot.com/56640044/diff/1/tests/00_setup.sh
File tests/00_setup.sh (right):

https://codereview.appspot.com/56640044/diff/1/tests/00_setup.sh#newcode3
tests/00_setup.sh:3: sudo apt-get install python-setuptools
What about python3-setuptools ?
Add -y to make the script non-interactive.

https://codereview.appspot.com/56640044/diff/1/tests/00_setup.sh#newcode6
tests/00_setup.sh:6: sudo add-apt-repository ppa:juju/stable
If you add the new repository I think you need to apt-get update
Also add the -y flag to make the script non-interactive.

https://codereview.appspot.com/56640044/diff/1/tests/00_setup.sh#newcode9
tests/00_setup.sh:9: sudo apt-get install amulet python3
python3-requests python3-pymongo juju-core charm-tools
Add the -y flag to make the script non-interactive.

https://codereview.appspot.com/56640044/

Revision history for this message
Matt Bruzek (mbruzek) wrote :

The python code looks good to me. +1 review from mbruzek

https://codereview.appspot.com/56640044/

Revision history for this message
Charles Butler (lazypower) wrote :

Thanks Matt,

I responded to one of your comments, and will push the requested
revisions. (good catch about non-interactive)

https://codereview.appspot.com/56640044/diff/1/tests/00_setup.sh
File tests/00_setup.sh (right):

https://codereview.appspot.com/56640044/diff/1/tests/00_setup.sh#newcode3
tests/00_setup.sh:3: sudo apt-get install python-setuptools
On 2014/01/28 16:02:06, mbruzek wrote:
> What about python3-setuptools ?
> Add -y to make the script non-interactive.

Python2 setup tools provides the add-apt-repository, which is the reason
behind adding that package first. I dont feel there is a need to
introduce python3-setuptools yet, as im' not familiar with what the
package provides.

https://codereview.appspot.com/56640044/

41. By Charles Butler

Changes apt lines to be non-interactive

Revision history for this message
Charles Butler (lazypower) wrote :
42. By Charles Butler

Added missing apt-get update

Revision history for this message
Charles Butler (lazypower) wrote :
Revision history for this message
Marco Ceppi (marcoceppi) wrote :

I'd like to see a more extensive test. More configuration options
exercised, and more relation data verified

https://codereview.appspot.com/56640044/diff/40001/tests/00_setup.sh
File tests/00_setup.sh (right):

https://codereview.appspot.com/56640044/diff/40001/tests/00_setup.sh#newcode11
tests/00_setup.sh:11: sudo apt-get install amulet python3
python3-requests python3-pymongo juju-core charm-tools -y
You install python3-pymongo but never use it. I'd like to see a test
which connected to mongodb from the test server

https://codereview.appspot.com/56640044/diff/40001/tests/200_deploy.test
File tests/200_deploy.test (right):

https://codereview.appspot.com/56640044/diff/40001/tests/200_deploy.test#newcode20
tests/200_deploy.test:20: d.add('shard2', charm='mongodb', units=scale)
I like this, you've really exercised the full length of the mongodb
charm

https://codereview.appspot.com/56640044/diff/40001/tests/200_deploy.test#newcode87
tests/200_deploy.test:87: d.sentry.unit['shard2/0'].relation('database',
'mongos:mongos')
You should validate the data being sent on the wire, to ensure the charm
doesn't inadvertently change and break backwards compatibility

https://codereview.appspot.com/56640044/

43. By Charles Butler

Added pymongo validation of mongo shell connectivity

Revision history for this message
Charles Butler (lazypower) wrote :
44. By Charles Butler

Removed stale comment

Revision history for this message
Charles Butler (lazypower) wrote :
Revision history for this message
Marco Ceppi (marcoceppi) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'tests/00_setup.sh'
2--- tests/00_setup.sh 1970-01-01 00:00:00 +0000
3+++ tests/00_setup.sh 2014-02-03 22:19:04 +0000
4@@ -0,0 +1,11 @@
5+#!/bin/bash
6+
7+sudo apt-get install python-setuptools -y
8+
9+if [ -f '/etc/apt.d/sources.list.d/juju-stable-precise.list' ]; then
10+ sudo add-apt-repository ppa:juju/stable -y
11+fi
12+
13+sudo apt-get update
14+
15+sudo apt-get install amulet python3 python3-requests python3-pymongo juju-core charm-tools -y
16
17=== added file 'tests/200_deploy.test'
18--- tests/200_deploy.test 1970-01-01 00:00:00 +0000
19+++ tests/200_deploy.test 2014-02-03 22:19:04 +0000
20@@ -0,0 +1,127 @@
21+#!/usr/bin/env python3
22+
23+import amulet
24+import requests
25+from pymongo import MongoClient
26+
27+#########################################################
28+# Test Quick Config
29+#########################################################
30+scale = 1
31+seconds = 1400
32+
33+#########################################################
34+# 3shard cluster configuration
35+#########################################################
36+d = amulet.Deployment()
37+
38+d.add('configsvr', charm='mongodb', units=scale)
39+d.add('mongos', charm='mongodb', units=scale)
40+d.add('shard1', charm='mongodb', units=scale)
41+d.add('shard2', charm='mongodb', units=scale)
42+
43+#Setup the config svr
44+d.configure('configsvr', {'replicaset': 'configsvr'})
45+
46+# define each shardset
47+d.configure('shard1', {'replicaset': 'shard1'})
48+d.configure('shard2', {'replicaset': 'shard2'})
49+
50+d.configure('mongos', {})
51+
52+#Connect the config servers to mongo shell
53+d.relate('configsvr:configsvr', 'mongos:mongos-cfg')
54+
55+#connect each shard to the mongo shell
56+d.relate('mongos:mongos', 'shard1:database')
57+d.relate('mongos:mongos', 'shard2:database')
58+d.expose('configsvr')
59+d.expose('mongos')
60+
61+# Perform the setup for the deployment.
62+try:
63+ d.setup(seconds)
64+ d.sentry.wait(seconds)
65+except amulet.helpers.TimeoutError:
66+ message = 'The environment did not setup in %d seconds.', seconds
67+ amulet.raise_status(amulet.SKIP, msg=message)
68+except:
69+ raise
70+
71+sentry_dict = {
72+ 'config-sentry': d.sentry.unit['configsvr/0'],
73+ 'mongos-sentry': d.sentry.unit['mongos/0'],
74+ 'shard1-sentry': d.sentry.unit['shard1/0'],
75+ 'shard2-sentry': d.sentry.unit['shard2/0']
76+}
77+
78+
79+#############################################################
80+# Check presence of MongoDB GUI HEALTH Status
81+#############################################################
82+def validate_status_interface():
83+ r = requests.get("http://{}:28017".format(
84+ sentry_dict['config-sentry'].info['public-address']),
85+ verify=False)
86+ r.raise_for_status
87+
88+
89+#############################################################
90+# Validate that each unit has an active mongo service
91+#############################################################
92+def validate_running_services():
93+ for service in sentry_dict:
94+ output = sentry_dict[service].run('service mongodb status')
95+ service_active = str(output).find('mongodb start/running')
96+ if service_active == -1:
97+ message = "Failed to find running MongoDB on host {}".format(service)
98+ amulet.raise_status(amulet.SKIP, msg=message)
99+
100+
101+#############################################################
102+# Validate connectivity from $WORLD
103+#############################################################
104+def validate_world_connectivity():
105+ client = MongoClient(d.sentry.unit['mongos/0'].info['public-address'])
106+
107+ db = client['test']
108+ #Can we successfully insert?
109+ insert_id = db.amulet.insert({'assert': True})
110+ if insert_id is None:
111+ amulet.raise_status(amulet.FAIL, msg="Failed to insert test data")
112+ #Can we delete from a shard using the Mongos hub?
113+ result = db.amulet.remove(insert_id)
114+ if result['err'] is not None:
115+ amulet.raise_status(amulet.FAIL, msg="Failed to remove test data")
116+
117+
118+#############################################################
119+# Validate relationships
120+#############################################################
121+#broken pending 1273312
122+def validate_relationships():
123+ d.sentry.unit['configsvr/0'].relation('configsvr', 'mongos:mongos-cfg')
124+ d.sentry.unit['shard1/0'].relation('database', 'mongos:mongos')
125+ d.sentry.unit['shard2/0'].relation('database', 'mongos:mongos')
126+ print(d.sentry.unit['shard1/0'].relation('database', 'mongos:mongos'))
127+
128+
129+def validate_manual_connection():
130+ output, code = d.sentry.unit['shard1/0'].run("mongo {}".format(
131+ d.sentry.unit['mongos/0'].info['public-address']))
132+ if code != 0:
133+ message = "Manual Connection failed for unit shard1"
134+ amulet.raise_status(amulet.SKIP, msg=message)
135+
136+ output, code = d.sentry.unit['shard2/0'].run("mongo {}".format(
137+ d.sentry.unit['mongos/0'].info['public-address']))
138+ if code != 0:
139+ message = "Manual Connection failed for unit shard2"
140+ amulet.raise_status(amulet.SKIP, msg=message)
141+
142+
143+validate_status_interface()
144+validate_running_services()
145+#validate_relationships()
146+validate_manual_connection()
147+validate_world_connectivity()

Subscribers

People subscribed via source and target branches