Merge lp:~kwmonroe/charms/trusty/mediawiki/test-updates into lp:~tvansteenburgh/charms/trusty/mediawiki/fix-tests

Proposed by Kevin W Monroe
Status: Needs review
Proposed branch: lp:~kwmonroe/charms/trusty/mediawiki/test-updates
Merge into: lp:~tvansteenburgh/charms/trusty/mediawiki/fix-tests
Diff against target: 67 lines (+23/-9)
2 files modified
hooks/config-changed (+7/-3)
tests/100-deploy (+16/-6)
To merge this branch: bzr merge lp:~kwmonroe/charms/trusty/mediawiki/test-updates
Reviewer Review Type Date Requested Status
Charles Butler (community) Approve
Tim Van Steenburgh Pending
Review via email: mp+274793@code.launchpad.net

Description of the change

actually test the login capabilities at the end of 100-deploy

To post a comment you must log in.
86. By Kevin W Monroe

handle adding a new admin better (set -e causes us to fail fast if adding an existing user; trick it with "|| true" so we can properly inform the user of the problem).

87. By Kevin W Monroe

add our test admin after the db relation has been validated. the config-changed hook wont add an admin unless certain files are present (meaning we have a db connection). setting this config too early looks like it works, but the admin is never actually created.

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

+1'd and rolled into tvansteenburgh's MP upstream

review: Approve

Unmerged revisions

87. By Kevin W Monroe

add our test admin after the db relation has been validated. the config-changed hook wont add an admin unless certain files are present (meaning we have a db connection). setting this config too early looks like it works, but the admin is never actually created.

86. By Kevin W Monroe

handle adding a new admin better (set -e causes us to fail fast if adding an existing user; trick it with "|| true" so we can properly inform the user of the problem).

85. By Kevin W Monroe

update test to exercise login

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'hooks/config-changed'
--- hooks/config-changed 2014-07-14 21:50:00 +0000
+++ hooks/config-changed 2015-10-16 23:18:46 +0000
@@ -82,9 +82,13 @@
82 for admin in $admins ; do82 for admin in $admins ; do
83 user=`echo $admin | cut -d: -f1`83 user=`echo $admin | cut -d: -f1`
84 pass=`echo $admin | cut -d: -f2`84 pass=`echo $admin | cut -d: -f2`
85 output=`php createAndPromote.php --conf /etc/mediawiki/LocalSettings.php $user $pass`85 # createAndPromote.php will exit non-zero if the user already exists.
86 if [ ! "$output" = "account exists." ] ; then86 # Since this hook is set -e, it would exit immediately unless we used
87 echo $output87 # ' || true' at the end. This lets us properly inform the user of the
88 # error, versus having a failed config-changed hook with no message.
89 user_count=`php createAndPromote.php --conf /etc/mediawiki/LocalSettings.php $user $pass 2>&1 | grep -c "account exists" || true`
90 if [ $user_count -gt 0 ] ; then
91 echo "ERROR: $user account already exists"
88 exit 192 exit 1
89 fi93 fi
90 done94 done
9195
=== modified file 'tests/100-deploy'
--- tests/100-deploy 2015-10-16 20:40:21 +0000
+++ tests/100-deploy 2015-10-16 23:18:46 +0000
@@ -1,6 +1,7 @@
1#!/usr/bin/env python31#!/usr/bin/env python3
2import amulet2import amulet
3import requests3import requests
4import time
45
5seconds = 9006seconds = 900
67
@@ -10,7 +11,7 @@
10d.add('mysql')11d.add('mysql')
11d.add('memcached')12d.add('memcached')
12d.add('mediawiki')13d.add('mediawiki')
13d.configure('mediawiki', {'admins': 'tom:swordfish', 'name': 'amulet-wiki'})14d.configure('mediawiki', {'name': 'amulet-wiki'})
14d.configure('memcached', {'allow-ufw-ip6-softfail': True})15d.configure('memcached', {'allow-ufw-ip6-softfail': True})
15d.relate('mysql:db', 'mediawiki:db')16d.relate('mysql:db', 'mediawiki:db')
16d.relate('memcached:cache', 'mediawiki:cache')17d.relate('memcached:cache', 'mediawiki:cache')
@@ -70,11 +71,20 @@
70 amulet.raise_status(amulet.FAIL,71 amulet.raise_status(amulet.FAIL,
71 "Unable to validate configuration for wiki-name")72 "Unable to validate configuration for wiki-name")
7273
73login_url = "http://%s/mediawiki/index.php?title=" % mw_ip74# Add an admin (now that we validated a good db connection)
74payload = {'wpName': 'tom', 'wpPassword': 'swordfish'}75d.configure('mediawiki', {'admins': 'tom:swordfish'})
76# Give the config-changed hook 30s to settle
77time.sleep(30)
78login_url = "http://%s/mediawiki/api.php?action=login&lgname=tom&lgpassword=swordfish&format=json" % mw_ip
7579
80# Test that we can login with the newly created admin
76with requests.Session() as s:81with requests.Session() as s:
82 # hit the login url with credentials, retrieve a token to use for later validation
83 resp = s.post(login_url)
84 token = resp.json()['login']['token']
7785
78 resp = s.post(login_url, data=payload)86 # hit the login url again with creds+token to verify if we are successfully logged in
79 if resp.text.find("<title>amulet-wiki") == -1:87 resp2 = s.post(login_url+'&lgtoken=%s' % token, cookies=resp.cookies)
80 amulet.raise_status(amulet.FAIL, "Unable to validate admin login")88 result = resp2.json()['login']['result']
89 if result != "Success":
90 amulet.raise_status(amulet.FAIL, "Unable to validate admin login: %s" % result)

Subscribers

People subscribed via source and target branches