1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
#!/usr/bin/env python3
import amulet
from splinter import Browser
seconds = 900
d = amulet.Deployment()
#Setup the charms, and relationships
d.add('mysql')
d.add('memcached')
d.add('mediawiki')
d.configure('mediawiki', {'admins': 'tom:swordfish', 'name': 'amulet-wiki'})
d.relate('mysql:db', 'mediawiki:db')
d.relate('memcached:cache', 'mediawiki:cache')
d.expose('mediawiki')
# Perform the setup for the deployment.
try:
d.setup(seconds)
#pings every deployed unit
d.sentry.wait(seconds)
except amulet.helpers.TimeoutError:
message = 'The environment did not setup in %d seconds.' % seconds
amulet.raise_status(amulet.SKIP, msg=message)
except:
raise
mw_unit = d.sentry.unit['mediawiki/0']
mysql_unit = d.sentry.unit['mysql/0']
#############################################################
# Validate the DB Relationship using Amulet Sentry
#############################################################
sql_relation = d.sentry.unit['mysql/0'].relation('db', 'mediawiki:db')
# 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/LocalSettings.php \
| grep wgDBserver | awk '{printf $3}'")
search_term = "\"{}\";".format(sql_relation['private-address'])
if search_term != output:
message = "Unable to Determine Remote MYSQL configuration, " \
"expected: %s, got: %s" % (search_term, output)
amulet.raise_status(amulet.FAIL, msg=message)
#############################################################
# Validate the Memcached Relationship using Amulet Sentry
#############################################################
memcached_relation = d.sentry.unit['memcached/0'].relation(
'cache', 'mediawiki:cache')
output, code = mw_unit.run("cat /etc/mediawiki/memcached_settings.php \
| grep wgMemCachedServers | tr -d \'array\(\)\; | awk '{printf $3}'")
search_term = "%s:%s" % (memcached_relation['private-address'],
memcached_relation['port'])
#############################################################
# Validate the installation configuration using PhantomJS
#############################################################
browser = Browser('phantomjs')
browser.visit("http://%s/mediawiki/index.php?"
"title=Special:UserLogin&returnto=Main+Page" %
d.sentry.unit['mediawiki/0'].info['public-address'])
title = str(browser.title).find("Log in")
if title == -1:
amulet.raise_status(amulet.FAIL, msg="Failed login test.")
title = str(browser.title).find("amulet-wiki")
if title == -1:
amulet.raise_status(amulet.FAIL, msg="Failed to parse provided title")
browser.fill("wpName", 'tom')
browser.fill('wpPassword', 'swordfish')
browser.find_by_id('wpLoginAttempt').first.click()
if not browser.is_text_present('tom'):
amulet.raise_status(amulet.FAIL,
msg="Failed to login with configured admin")
|