Merge lp:~lazypower/charms/precise/mediawiki/tests into lp:charms/mediawiki
- Precise Pangolin (12.04)
- tests
- Merge into trunk
Status: | Merged | ||||
---|---|---|---|---|---|
Merged at revision: | 74 | ||||
Proposed branch: | lp:~lazypower/charms/precise/mediawiki/tests | ||||
Merge into: | lp:charms/mediawiki | ||||
Diff against target: |
254 lines (+109/-117) 5 files modified
hooks/config-changed (+13/-9) tests/00_setup.sh (+13/-0) tests/100-deploy (+83/-0) tests/100_deploy.test (+0/-62) tests/get-unit-info (+0/-46) |
||||
To merge this branch: | bzr merge lp:~lazypower/charms/precise/mediawiki/tests | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
charmers | Pending | ||
Review via email: mp+202112@code.launchpad.net |
Commit message
Description of the change
Testing
Adds integration tests for unit deploy, db relationship with mysql, and cache relationship with memcached
Charles Butler (lazypower) wrote : | # |
Benjamin Saller (bcsaller) wrote : | # |
Thanks for this. I had a number of suggestions. Also if those .moved
files are in the repo that needs to be taken care of. After that is done
can you re-propose and I can approve it
https:/
File tests/00_
https:/
tests/00_
python-requests
This file appears to be an artifact of some bzr op and should be removed
https:/
File tests/100_
https:/
tests/100_
"\"{}\"
Minor but its usually better to use single quotes for the string rather
than escape as the result is more readable
'"{}";'.format(...)
https:/
File tests/10_
https:/
tests/10_
This file and the 100_deploy_
theses tests are not free we should remove one.
In general for functional tests with spin up times I prefer to assert as
much as possible in a single test. As long as you don't depend on state
manipulation beyond the initial setup that is fine.
https:/
File tests/10_
https:/
tests/10_
Again this test is very similar to the deploy_cloud test. Is there a
reason to have twice as much code at twice the runtime cost? Can we
combine theses?
https:/
File tests/lib/helper.py (right):
https:/
tests/lib/
'text/html,
as a style point defining this above the method as
LOGIN_HEADERS = {
...
}
can save you some indentation space and make things a little easier to
read.
https:/
tests/lib/
deploy as a name? This could bring up more than one unit, no?
Charles Butler (lazypower) wrote : | # |
Please take a look.
Matt Bruzek (mbruzek) wrote : | # |
I took a look at these changes and I give it a +1 on my review.
Benjamin Saller (bcsaller) wrote : | # |
LGTM
Thanks for the improvements, this version looked much cleaner than the
last.
Marco Ceppi (marcoceppi) wrote : | # |
See below, LGTM otherwise.
https:/
File tests/00_setup.sh (right):
https:/
tests/00_
This doesn't actually work
Charles Butler (lazypower) wrote : | # |
Please take a look.
Peter Petrakis (peter-petrakis) wrote : | # |
On 2014/02/14 21:22:07, lazypower wrote:
> Please take a look.
New to this service, so old school for now:
=== modified file 'hooks/
--- hooks/config-
+++ hooks/config-
@@ -59,12 +59,16 @@
...
+
+#added to prevent failure when no db relationship exists
+if [ -f /etc/mediawiki/
+ for admin in $admins ; do
+ user=`echo $admin | cut -d: -f1`
+ pass=`echo $admin | cut -d: -f2`
If "admins" is empty this will happily work, the pipe to cut will not
error. In this case I would
exit 1 with meaningful juju-log message.
+ output=`php createAndPromot
/etc/mediawiki/
+ if [ ! "$output" = "account exists." ] ; then
+ echo $output
+ exit 1
+ fi
+ done
+fi
=== added file 'tests/100-deploy'
--- tests/100-deploy 1970-01-01 00:00:00 +0000
+++ tests/100-deploy 2014-02-14 21:21:50 +0000
@@ -0,0 +1,83 @@
+#!/usr/bin/env python3
+import amulet
+from splinter import Browser
+
+seconds = 900
+
+d = amulet.Deployment()
+
+#Setup the charms, and relationships
Inconsistent comment pattern, should have a space between hash and
string
+# Perform the setup for the deployment.
+try:
+ d.setup(seconds)
+ #pings every deployed unit
+ d.sentry.
Same pattern. Also uppercase or lower case for sentence start, either is
fine just be consistent.
=== added file 'tests/100-deploy'
--- tests/100-deploy 1970-01-01 00:00:00 +0000
+++ tests/100-deploy 2014-02-14 21:21:50 +0000
...
+# Validate that the database server was set for the configuration of
MediaWiki
+#Set search term for comparison, and cache the flag in the
configuration file
+output, code = mw_unit.run("cat /etc/mediawiki/
+ | grep wgDBserver | awk '{printf $3}'")
You can do that entirely in awk, something like awk '/wgDBserver/ &&
printf $3' FILE. If you're so inclined.
...
+memcached_relation = d.sentry.
+ 'cache', 'mediawiki:cache')
+output, code = mw_unit.run("cat /etc/mediawiki/
+ | grep wgMemCachedServers | tr -d \'array\(\)\; | awk '{printf
$3}'")
Just call grep or not, arguably a style call, keeping the file to be
worked on
as the first argument.
=== removed file 'tests/
--- tests/100_
+++ tests/100_
@@ -1,62 +0,0 @@
-#!/bin/sh
-
-if [ -z "`which wget`" ] ; then
- echo SKIP: need wget to run test.
- exit 100
-fi
I know this was removed but...
backticks are typically used in in bash shell, $() in bash scripts.
Tough habit to break.
Preview Diff
1 | === modified file 'hooks/config-changed' | |||
2 | --- hooks/config-changed 2012-06-28 00:01:31 +0000 | |||
3 | +++ hooks/config-changed 2014-02-14 21:21:57 +0000 | |||
4 | @@ -59,12 +59,16 @@ | |||
5 | 59 | [ ! -f $cfile.old ] || rm $cfile.old | 59 | [ ! -f $cfile.old ] || rm $cfile.old |
6 | 60 | 60 | ||
7 | 61 | cd /usr/share/mediawiki/maintenance | 61 | cd /usr/share/mediawiki/maintenance |
17 | 62 | for admin in $admins ; do | 62 | |
18 | 63 | user=`echo $admin | cut -d: -f1` | 63 | #added to prevent failure when no db relationship exists |
19 | 64 | pass=`echo $admin | cut -d: -f2` | 64 | if [ -f /etc/mediawiki/LocalSettings.php ]; then |
20 | 65 | output=`php createAndPromote.php --conf /etc/mediawiki/LocalSettings.php $user $pass` | 65 | for admin in $admins ; do |
21 | 66 | if [ ! "$output" = "account exists." ] ; then | 66 | user=`echo $admin | cut -d: -f1` |
22 | 67 | echo $output | 67 | pass=`echo $admin | cut -d: -f2` |
23 | 68 | exit 1 | 68 | output=`php createAndPromote.php --conf /etc/mediawiki/LocalSettings.php $user $pass` |
24 | 69 | fi | 69 | if [ ! "$output" = "account exists." ] ; then |
25 | 70 | done | 70 | echo $output |
26 | 71 | exit 1 | ||
27 | 72 | fi | ||
28 | 73 | done | ||
29 | 74 | fi | ||
30 | 71 | 75 | ||
31 | === added file 'tests/00_setup.sh' | |||
32 | --- tests/00_setup.sh 1970-01-01 00:00:00 +0000 | |||
33 | +++ tests/00_setup.sh 2014-02-14 21:21:57 +0000 | |||
34 | @@ -0,0 +1,13 @@ | |||
35 | 1 | #!/bin/bash | ||
36 | 2 | |||
37 | 3 | #TODO: Some of the python3 packs may not be available in precise. | ||
38 | 4 | |||
39 | 5 | apt-get install python3-setuptools -y | ||
40 | 6 | |||
41 | 7 | apt-add-repository ppa:juju/stable -y | ||
42 | 8 | apt-get update | ||
43 | 9 | |||
44 | 10 | #I have no idea if this is running via python2 or python3, so fetch both | ||
45 | 11 | # copies of the requests lib | ||
46 | 12 | apt-get install juju amulet python3 python3-requests python3-pip phantomjs -y | ||
47 | 13 | pip3 install splinter selenium | ||
48 | 0 | \ No newline at end of file | 14 | \ No newline at end of file |
49 | 1 | 15 | ||
50 | === added file 'tests/100-deploy' | |||
51 | --- tests/100-deploy 1970-01-01 00:00:00 +0000 | |||
52 | +++ tests/100-deploy 2014-02-14 21:21:57 +0000 | |||
53 | @@ -0,0 +1,83 @@ | |||
54 | 1 | #!/usr/bin/env python3 | ||
55 | 2 | import amulet | ||
56 | 3 | from splinter import Browser | ||
57 | 4 | |||
58 | 5 | seconds = 900 | ||
59 | 6 | |||
60 | 7 | d = amulet.Deployment() | ||
61 | 8 | |||
62 | 9 | #Setup the charms, and relationships | ||
63 | 10 | d.add('mysql') | ||
64 | 11 | d.add('memcached') | ||
65 | 12 | d.add('mediawiki') | ||
66 | 13 | d.configure('mediawiki', {'admins': 'tom:swordfish', 'name': 'amulet-wiki'}) | ||
67 | 14 | d.relate('mysql:db', 'mediawiki:db') | ||
68 | 15 | d.relate('memcached:cache', 'mediawiki:cache') | ||
69 | 16 | d.expose('mediawiki') | ||
70 | 17 | |||
71 | 18 | |||
72 | 19 | # Perform the setup for the deployment. | ||
73 | 20 | try: | ||
74 | 21 | d.setup(seconds) | ||
75 | 22 | #pings every deployed unit | ||
76 | 23 | d.sentry.wait(seconds) | ||
77 | 24 | except amulet.helpers.TimeoutError: | ||
78 | 25 | message = 'The environment did not setup in %d seconds.' % seconds | ||
79 | 26 | amulet.raise_status(amulet.SKIP, msg=message) | ||
80 | 27 | except: | ||
81 | 28 | raise | ||
82 | 29 | |||
83 | 30 | mw_unit = d.sentry.unit['mediawiki/0'] | ||
84 | 31 | mysql_unit = d.sentry.unit['mysql/0'] | ||
85 | 32 | |||
86 | 33 | ############################################################# | ||
87 | 34 | # Validate the DB Relationship using Amulet Sentry | ||
88 | 35 | ############################################################# | ||
89 | 36 | sql_relation = d.sentry.unit['mysql/0'].relation('db', 'mediawiki:db') | ||
90 | 37 | |||
91 | 38 | # Validate that the database server was set for the configuration of MediaWiki | ||
92 | 39 | #Set search term for comparison, and cache the flag in the configuration file | ||
93 | 40 | output, code = mw_unit.run("cat /etc/mediawiki/LocalSettings.php \ | ||
94 | 41 | | grep wgDBserver | awk '{printf $3}'") | ||
95 | 42 | |||
96 | 43 | search_term = "\"{}\";".format(sql_relation['private-address']) | ||
97 | 44 | if search_term != output: | ||
98 | 45 | message = "Unable to Determine Remote MYSQL configuration, " \ | ||
99 | 46 | "expected: %s, got: %s" % (search_term, output) | ||
100 | 47 | |||
101 | 48 | amulet.raise_status(amulet.FAIL, msg=message) | ||
102 | 49 | |||
103 | 50 | ############################################################# | ||
104 | 51 | # Validate the Memcached Relationship using Amulet Sentry | ||
105 | 52 | ############################################################# | ||
106 | 53 | memcached_relation = d.sentry.unit['memcached/0'].relation( | ||
107 | 54 | 'cache', 'mediawiki:cache') | ||
108 | 55 | output, code = mw_unit.run("cat /etc/mediawiki/memcached_settings.php \ | ||
109 | 56 | | grep wgMemCachedServers | tr -d \'array\(\)\; | awk '{printf $3}'") | ||
110 | 57 | search_term = "%s:%s" % memcached_relation['private-address'], | ||
111 | 58 | memcached_relation['port'] | ||
112 | 59 | |||
113 | 60 | ############################################################# | ||
114 | 61 | # Validate the installation configuration using PhantomJS | ||
115 | 62 | ############################################################# | ||
116 | 63 | browser = Browser('phantomjs') | ||
117 | 64 | browser.visit("http://%s/mediawiki/index.php?" | ||
118 | 65 | "title=Special:UserLogin&returnto=Main+Page" % | ||
119 | 66 | d.sentry.unit['mediawiki/0'].info['public-address']) | ||
120 | 67 | |||
121 | 68 | |||
122 | 69 | title = str(browser.title).find("Log in") | ||
123 | 70 | if title == -1: | ||
124 | 71 | amulet.raise_status(amulet.FAIL, msg="Failed login test.") | ||
125 | 72 | |||
126 | 73 | title = str(browser.title).find("amulet-wiki") | ||
127 | 74 | if title == -1: | ||
128 | 75 | amulet.raise_status(amulet.FAIL, msg="Failed to parse provided title") | ||
129 | 76 | |||
130 | 77 | browser.fill("wpName", 'tom') | ||
131 | 78 | browser.fill('wpPassword', 'swordfish') | ||
132 | 79 | browser.find_by_id('wpLoginAttempt').first.click() | ||
133 | 80 | |||
134 | 81 | if not browser.is_text_present('tom'): | ||
135 | 82 | amulet.raise_status(amulet.FAIL, | ||
136 | 83 | msg="Failed to login with configured admin") | ||
137 | 0 | 84 | ||
138 | === removed file 'tests/100_deploy.test' | |||
139 | --- tests/100_deploy.test 2012-01-31 01:27:17 +0000 | |||
140 | +++ tests/100_deploy.test 1970-01-01 00:00:00 +0000 | |||
141 | @@ -1,62 +0,0 @@ | |||
142 | 1 | #!/bin/sh | ||
143 | 2 | |||
144 | 3 | if [ -z "`which wget`" ] ; then | ||
145 | 4 | echo SKIP: need wget to run test. | ||
146 | 5 | exit 100 | ||
147 | 6 | fi | ||
148 | 7 | |||
149 | 8 | set -e | ||
150 | 9 | |||
151 | 10 | teardown() { | ||
152 | 11 | juju destroy-service memcached | ||
153 | 12 | juju destroy-service mysql | ||
154 | 13 | juju destroy-service mediawiki | ||
155 | 14 | if [ -n "$datadir" ] ; then | ||
156 | 15 | if [ -f $datadir/passed ]; then | ||
157 | 16 | rm -r $datadir | ||
158 | 17 | else | ||
159 | 18 | echo $datadir preserved | ||
160 | 19 | fi | ||
161 | 20 | fi | ||
162 | 21 | } | ||
163 | 22 | trap teardown EXIT | ||
164 | 23 | |||
165 | 24 | |||
166 | 25 | juju deploy mediawiki | ||
167 | 26 | juju deploy mysql | ||
168 | 27 | juju deploy memcached | ||
169 | 28 | juju add-relation mediawiki:db mysql:db | ||
170 | 29 | juju add-relation memcached mediawiki | ||
171 | 30 | juju expose mediawiki | ||
172 | 31 | |||
173 | 32 | for try in `seq 1 600` ; do | ||
174 | 33 | host=`juju status | tests/get-unit-info mediawiki public-address` | ||
175 | 34 | if [ -z "$host" ] ; then | ||
176 | 35 | sleep 1 | ||
177 | 36 | else | ||
178 | 37 | break | ||
179 | 38 | fi | ||
180 | 39 | done | ||
181 | 40 | |||
182 | 41 | if [ -z "$host" ] ; then | ||
183 | 42 | echo FAIL: status timed out | ||
184 | 43 | exit 1 | ||
185 | 44 | fi | ||
186 | 45 | |||
187 | 46 | datadir=`mktemp -d ${TMPDIR:-/tmp}/wget.test.XXXXXXX` | ||
188 | 47 | echo INFO: datadir=$datadir | ||
189 | 48 | |||
190 | 49 | wget --tries=100 --timeout=6 http://$host/ -O - -a $datadir/wget.log | grep -q '<title>' || continue | ||
191 | 50 | |||
192 | 51 | if [ $try -eq 600 ] ; then | ||
193 | 52 | echo FAIL: Timed out waiting. | ||
194 | 53 | exit 1 | ||
195 | 54 | fi | ||
196 | 55 | |||
197 | 56 | touch $datadir/passed | ||
198 | 57 | |||
199 | 58 | trap - EXIT | ||
200 | 59 | teardown | ||
201 | 60 | |||
202 | 61 | echo PASS: deployed successfully | ||
203 | 62 | exit 0 | ||
204 | 63 | 0 | ||
205 | === removed file 'tests/get-unit-info' | |||
206 | --- tests/get-unit-info 2012-01-31 01:27:17 +0000 | |||
207 | +++ tests/get-unit-info 1970-01-01 00:00:00 +0000 | |||
208 | @@ -1,46 +0,0 @@ | |||
209 | 1 | #!/usr/bin/python | ||
210 | 2 | # machines: | ||
211 | 3 | # 0: {dns-name: ec2-50-17-84-127.compute-1.amazonaws.com, instance-id: i-8c5c3fec} | ||
212 | 4 | # 1: {dns-name: ec2-184-73-102-113.compute-1.amazonaws.com, instance-id: i-14a2c174} | ||
213 | 5 | # 2: {dns-name: ec2-75-101-184-93.compute-1.amazonaws.com, instance-id: i-e0a2c180} | ||
214 | 6 | # services: | ||
215 | 7 | # mysql: | ||
216 | 8 | # charm: local:mysql-11 | ||
217 | 9 | # relations: {db: wordpress} | ||
218 | 10 | # units: | ||
219 | 11 | # mysql/0: | ||
220 | 12 | # machine: 2 | ||
221 | 13 | # relations: | ||
222 | 14 | # db: {state: up} | ||
223 | 15 | # state: started | ||
224 | 16 | # wordpress: | ||
225 | 17 | # charm: local:wordpress-31 | ||
226 | 18 | # exposed: true | ||
227 | 19 | # relations: {db: mysql} | ||
228 | 20 | # units: | ||
229 | 21 | # wordpress/0: | ||
230 | 22 | # machine: 1 | ||
231 | 23 | # open-ports: [] | ||
232 | 24 | # relations: {} | ||
233 | 25 | # state: null | ||
234 | 26 | |||
235 | 27 | import yaml | ||
236 | 28 | import sys | ||
237 | 29 | from subprocess import Popen, PIPE | ||
238 | 30 | |||
239 | 31 | |||
240 | 32 | def main(): | ||
241 | 33 | d = yaml.safe_load(Popen(['juju','status'],stdout=PIPE).stdout) | ||
242 | 34 | srv = d.get("services", {}).get(sys.argv[1]) | ||
243 | 35 | if srv is None: | ||
244 | 36 | return | ||
245 | 37 | units = srv.get("units", {}) | ||
246 | 38 | if units is None: | ||
247 | 39 | return | ||
248 | 40 | item = units.items()[0][1].get(sys.argv[2]) | ||
249 | 41 | if item is None: | ||
250 | 42 | return | ||
251 | 43 | print item | ||
252 | 44 | |||
253 | 45 | if __name__ == "__main__": | ||
254 | 46 | main() |
Reviewers: mp+202112_ code.launchpad. net,
Message:
Please take a look.
Description:
Adds integration tests for unit deploy, db relationship with mysql, and
cache relationship with memcached
https:/ /code.launchpad .net/~lazypower /charms/ precise/ mediawiki/ tests/+ merge/202112
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/54600043/
Affected files (+270, -4 lines): changed setup.sh. moved deploy_ test.py deploy. test deploy_ cloud.test deploy_ with_memcached. test cache_relation_ test.py db_relation_ test.py _init__ .py.moved moved/_ _init__ .py moved/helper. py __init_ _.py
A [revision details]
M hooks/config-
A tests/00_setup.sh
A tests/00_
A tests/01_
M tests/100_
A tests/100_
A tests/100_
A tests/10_
A tests/10_
A tests/__init__.py
A tests/_
A tests/lib.
A tests/lib.
A tests/lib/
A tests/lib/helper.py