3
from splinter import Browser
7
d = amulet.Deployment()
9
#Setup the charms, and relationships
13
d.configure('mediawiki', {'admins': 'tom:swordfish', 'name': 'amulet-wiki'})
14
d.relate('mysql:db', 'mediawiki:db')
15
d.relate('memcached:cache', 'mediawiki:cache')
19
# Perform the setup for the deployment.
22
#pings every deployed unit
23
d.sentry.wait(seconds)
24
except amulet.helpers.TimeoutError:
25
message = 'The environment did not setup in %d seconds.' % seconds
26
amulet.raise_status(amulet.SKIP, msg=message)
30
mw_unit = d.sentry.unit['mediawiki/0']
31
mysql_unit = d.sentry.unit['mysql/0']
33
#############################################################
34
# Validate the DB Relationship using Amulet Sentry
35
#############################################################
36
sql_relation = d.sentry.unit['mysql/0'].relation('db', 'mediawiki:db')
38
# Validate that the database server was set for the configuration of MediaWiki
39
#Set search term for comparison, and cache the flag in the configuration file
40
output, code = mw_unit.run("cat /etc/mediawiki/LocalSettings.php \
41
| grep wgDBserver | awk '{printf $3}'")
43
search_term = "\"{}\";".format(sql_relation['private-address'])
44
if search_term != output:
45
message = "Unable to Determine Remote MYSQL configuration, " \
46
"expected: %s, got: %s" % (search_term, output)
48
amulet.raise_status(amulet.FAIL, msg=message)
50
#############################################################
51
# Validate the Memcached Relationship using Amulet Sentry
52
#############################################################
53
memcached_relation = d.sentry.unit['memcached/0'].relation(
54
'cache', 'mediawiki:cache')
55
output, code = mw_unit.run("cat /etc/mediawiki/memcached_settings.php \
56
| grep wgMemCachedServers | tr -d \'array\(\)\; | awk '{printf $3}'")
57
search_term = "%s:%s" % memcached_relation['private-address'],
58
memcached_relation['port']
60
#############################################################
61
# Validate the installation configuration using PhantomJS
62
#############################################################
63
browser = Browser('phantomjs')
64
browser.visit("http://%s/mediawiki/index.php?"
65
"title=Special:UserLogin&returnto=Main+Page" %
66
d.sentry.unit['mediawiki/0'].info['public-address'])
69
title = str(browser.title).find("Log in")
71
amulet.raise_status(amulet.FAIL, msg="Failed login test.")
73
title = str(browser.title).find("amulet-wiki")
75
amulet.raise_status(amulet.FAIL, msg="Failed to parse provided title")
77
browser.fill("wpName", 'tom')
78
browser.fill('wpPassword', 'swordfish')
79
browser.find_by_id('wpLoginAttempt').first.click()
81
if not browser.is_text_present('tom'):
82
amulet.raise_status(amulet.FAIL,
83
msg="Failed to login with configured admin")