6
##########################################
8
##########################################
12
password = 'swordfish'
16
###########################################################
18
############################################################
19
d = amulet.Deployment()
21
d.add('owncloud', units=scale)
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')
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)
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'}
52
data = {'user': 'tom', 'password': 'swordfish'}
54
#validate the Owncloud login screen is present
55
r = requests.post("http://{}".format(
56
d.sentry.unit['owncloud/0'].info['public-address']),
60
#validate the HAProxy daemon is forwarding as expected
61
r = requests.get("http://{}".format(
62
d.sentry.unit['haproxy/0'].info['public-address']))
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')
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')
76
message = "Failed to find running MYSQL instance on host mysql/0"
77
amulet.raise_status(amulet.SKIP, msg=message)
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)
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'}
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)
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)
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')
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'])
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)
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')
138
validate_status_interface()
139
validate_running_services()
140
validate_owncloud_files()
141
validate_database_relationship()
142
validate_nfs_relationship()