~jose/charms/precise/owncloud/fix-poodle

« back to all changes in this revision

Viewing changes to tests/100_deploy.test

  • Committer: Charles Butler
  • Date: 2014-07-21 22:03:13 UTC
  • mfrom: (24.1.17 owncloud)
  • Revision ID: chuck@dasroot.net-20140721220313-fkp6gi45czkd3zw8
  José Antonio Rey 2014-07-21 Updated Release key sha1sum, updated source to version 6.0.4
    José Antonio Rey 2014-06-20 Updated the author's email address
    José Antonio Rey 2014-06-20 Fixed default behaviour when domain wasn't set and made setup test +x
    José Antonio Rey 2014-06-17 Fixed various bugs
    José Antonio Rey 2014-06-03 Fixed password idempotency issue
    José Antonio Rey 2014-06-03 Added install dependency for mysql
    José Antonio Rey 2014-06-03 Solved some bugs
    José Antonio Rey 2014-06-03 Solved idempotency issue with username
    José Antonio Rey 2014-05-16 [merge] Fixed amulet tests. Thanks ~lazypower!
    Charles Butler 2014-05-12 Move expose to before setup in deploy test
    Charles Butler 2014-05-12 Refactor tests to resemble nose tests
    José Antonio Rey 2014-05-16 Fixed bug in website-relation-joined
    José Antonio Rey 2014-05-10 Fixed README and added default 'not configured' page
    José Antonio Rey 2014-05-07 Partially fixed tests
    José Antonio Rey 2014-05-01 Added db-relation-departed hook
    José Antonio Rey 2014-04-23 Fixed tests to comply with new settings
    José Antonio Rey 2014-04-23 Re-written part of the README, added SSL support and taken maintai...
    José Antonio Rey 2014-04-19 Fixed bug
    José Antonio Rey 2014-04-11 Added port change support and support to install from a repo

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python3
2
 
 
3
 
import amulet
4
 
import requests
5
 
 
6
 
##########################################
7
 
# Config Options
8
 
##########################################
9
 
scale = 2
10
 
seconds = 1200
11
 
user = 'tom'
12
 
password = 'swordfish'
13
 
block_size = "8M"
14
 
verify_size = 8000000
15
 
 
16
 
###########################################################
17
 
#Deployment Setup
18
 
############################################################
19
 
d = amulet.Deployment()
20
 
 
21
 
d.add('owncloud', units=scale)
22
 
d.add('mysql')
23
 
d.add('haproxy')
24
 
d.add('nfs')
25
 
d.configure('owncloud', {'user': user, 'password': password})
26
 
d.relate('owncloud:db', 'mysql:db')
27
 
d.relate('owncloud:website', 'haproxy:reverseproxy')
28
 
d.relate('owncloud:shared-fs', 'nfs:nfs')
29
 
d.expose('owncloud')
30
 
d.expose('haproxy')
31
 
 
32
 
 
33
 
#perform deployment
34
 
try:
35
 
    d.setup(timeout=seconds)
36
 
except amulet.helpers.TimeoutError:
37
 
    message = 'The environment did not setup in %d seconds.', seconds
38
 
    amulet.raise_status(amulet.SKIP, msg=message)
39
 
except:
40
 
    raise
41
 
 
42
 
 
43
 
#############################################################
44
 
# Check presence of HTTP services
45
 
#############################################################
46
 
def validate_status_interface():
47
 
    h = {'User-Agent': 'Mozilla/5.0 Gecko/20100101 Firefox/12.0',
48
 
         'Content-Type': 'application/x-www-form-urlencoded',
49
 
         'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*',
50
 
         'Accept-Encoding': 'gzip, deflate'}
51
 
 
52
 
    data = {'user': 'tom', 'password': 'swordfish'}
53
 
 
54
 
    #validate the Owncloud login screen is present
55
 
    r = requests.post("http://{}".format(
56
 
        d.sentry.unit['owncloud/0'].info['public-address']),
57
 
        data, headers=h)
58
 
    r.raise_for_status()
59
 
 
60
 
    #validate the HAProxy daemon is forwarding as expected
61
 
    r = requests.get("http://{}".format(
62
 
        d.sentry.unit['haproxy/0'].info['public-address']))
63
 
    r.raise_for_status
64
 
 
65
 
 
66
 
#############################################################
67
 
# Validate that each service is running
68
 
#############################################################
69
 
def validate_running_services():
70
 
    output, code = d.sentry.unit['owncloud/0'].run('service apache2 status')
71
 
    if code != 0:
72
 
        message = "Failed to find running Apache instance on host owncloud/0"
73
 
        amulet.raise_status(amulet.SKIP, msg=message)
74
 
    output, code = d.sentry.unit['mysql/0'].run('service mysql status')
75
 
    if code != 0:
76
 
        message = "Failed to find running MYSQL instance on host mysql/0"
77
 
        amulet.raise_status(amulet.SKIP, msg=message)
78
 
 
79
 
 
80
 
#############################################################
81
 
# Validate that each service is running
82
 
#############################################################
83
 
def validate_owncloud_files():
84
 
    index_status = d.sentry.unit['owncloud/0'].file_stat('/var/www/owncloud/index.php')
85
 
    if index_status['size'] <= 0:
86
 
        message = "Failed to find owncloud index.php"
87
 
        amulet.raise_status(amulet.SKIP, msg=message)
88
 
 
89
 
 
90
 
#############################################################
91
 
# Validate database relationship
92
 
#############################################################
93
 
def validate_database_relationship():
94
 
    #Connect to the sentrys and fetch the transmitted details
95
 
    sent_config = d.sentry.unit['mysql/0'].relation('db', 'owncloud:db')
96
 
    #Connect to owncloud's sentry and read the configuration PHP file
97
 
    prod_config = d.sentry.unit['owncloud/0'].file_contents('/var/www/owncloud/config/config.php')
98
 
    cfg_to_check = {'dbuser': 'user', 'dbpassword': 'password', 'dbhost': 'host'}
99
 
 
100
 
    #Search the return string of the config for the transmit values
101
 
    for cfg_file_key, juju_cfg_key in cfg_to_check.items():
102
 
        if prod_config.find("'%s' => '%s'" % (cfg_file_key, sent_config[juju_cfg_key])) == -1:
103
 
                amulet.raise_status(amulet.SKIP, msg="Unable to validate db sent %s" % juju_cfg_key)
104
 
 
105
 
 
106
 
# Utility Method for searching output
107
 
def nfs_term_search(output, term):
108
 
    if output.find(term) == -1:
109
 
        amulet.raise_status(amulet.FAIL, msg="Unable to validate NFS export mounted with %s" % term)
110
 
 
111
 
 
112
 
###########################################################
113
 
# Validate NFS FileSystem Existence
114
 
###########################################################
115
 
def validate_nfs_relationship():
116
 
    # Cache Relationship details
117
 
    nfs_relation = d.sentry.unit['nfs/0'].relation('nfs', 'owncloud:shared-fs')
118
 
    # Raises an error if the directory does not exist
119
 
    d.sentry.unit['owncloud/0'].directory('/var/lib/owncloud')
120
 
    #Fetch the contents of mtab for data validation
121
 
    mtab_contents = d.sentry.unit['owncloud/0'].file_contents('/etc/mtab')
122
 
 
123
 
    nfs_term_search(mtab_contents, nfs_relation['private-address'])
124
 
    nfs_term_search(mtab_contents, nfs_relation['fstype'])
125
 
    nfs_term_search(mtab_contents, nfs_relation['mountpoint'])
126
 
    nfs_term_search(mtab_contents, nfs_relation['options'])
127
 
 
128
 
    # Validate file write pipeline
129
 
    #Build a $block_size file, and ship it via NFS
130
 
    cmd_builder = "dd if=/dev/zero of=/var/lib/owncloud/amulet-file-test bs=%s count=1" % block_size
131
 
    d.sentry.unit['owncloud/0'].run(cmd_builder)
132
 
 
133
 
    file_test = d.sentry.unit['nfs/0'].file('/srv/data/relation-sentry/amulet-file-test')
134
 
    if file_test['size'] < verify_size:
135
 
        amulet.raise_status(amulet.FAIL, 'File size constraint not met')
136
 
 
137
 
 
138
 
validate_status_interface()
139
 
validate_running_services()
140
 
validate_owncloud_files()
141
 
validate_database_relationship()
142
 
validate_nfs_relationship()