~frankban/charms/trusty/mediawiki/trunk

« back to all changes in this revision

Viewing changes to tests/100-deploy

  • Committer: Marco Ceppi
  • Author(s): Charles Butler
  • Date: 2014-02-14 21:56:32 UTC
  • mfrom: (73.1.8 mediawiki)
  • Revision ID: marco@ceppi.net-20140214215632-s8hmk1f6gvusw8dl
Testing

Adds integration tests for unit deploy, db relationship with mysql, and cache relationship with memcached

R=
CC=
https://codereview.appspot.com/54600043

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python3
 
2
import amulet
 
3
from splinter import Browser
 
4
 
 
5
seconds = 900
 
6
 
 
7
d = amulet.Deployment()
 
8
 
 
9
#Setup the charms, and relationships
 
10
d.add('mysql')
 
11
d.add('memcached')
 
12
d.add('mediawiki')
 
13
d.configure('mediawiki', {'admins': 'tom:swordfish', 'name': 'amulet-wiki'})
 
14
d.relate('mysql:db', 'mediawiki:db')
 
15
d.relate('memcached:cache', 'mediawiki:cache')
 
16
d.expose('mediawiki')
 
17
 
 
18
 
 
19
# Perform the setup for the deployment.
 
20
try:
 
21
    d.setup(seconds)
 
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)
 
27
except:
 
28
    raise
 
29
 
 
30
mw_unit = d.sentry.unit['mediawiki/0']
 
31
mysql_unit = d.sentry.unit['mysql/0']
 
32
 
 
33
#############################################################
 
34
# Validate the DB Relationship using Amulet Sentry
 
35
#############################################################
 
36
sql_relation = d.sentry.unit['mysql/0'].relation('db', 'mediawiki:db')
 
37
 
 
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}'")
 
42
 
 
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)
 
47
 
 
48
    amulet.raise_status(amulet.FAIL, msg=message)
 
49
 
 
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']
 
59
 
 
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'])
 
67
 
 
68
 
 
69
title = str(browser.title).find("Log in")
 
70
if title == -1:
 
71
    amulet.raise_status(amulet.FAIL, msg="Failed login test.")
 
72
 
 
73
title = str(browser.title).find("amulet-wiki")
 
74
if title == -1:
 
75
    amulet.raise_status(amulet.FAIL, msg="Failed to parse provided title")
 
76
 
 
77
browser.fill("wpName", 'tom')
 
78
browser.fill('wpPassword', 'swordfish')
 
79
browser.find_by_id('wpLoginAttempt').first.click()
 
80
 
 
81
if not browser.is_text_present('tom'):
 
82
    amulet.raise_status(amulet.FAIL,
 
83
                        msg="Failed to login with configured admin")