Merge lp:~lazypower/charms/precise/owncloud/tests into lp:charms/owncloud

Proposed by Charles Butler on 2014-01-30
Status: Merged
Merged at revision: 22
Proposed branch: lp:~lazypower/charms/precise/owncloud/tests
Merge into: lp:charms/owncloud
Diff against target: 175 lines (+152/-2)
3 files modified
hooks/shared-fs-relation-changed (+2/-2)
tests/00_setup.sh (+8/-0)
tests/100_deploy.test (+142/-0)
To merge this branch: bzr merge lp:~lazypower/charms/precise/owncloud/tests
Reviewer Review Type Date Requested Status
charmers 2014-01-30 Pending
Review via email: mp+204059@code.launchpad.net

Description of the change

test updates

added relationship tests for :db relationship between mysql. Adds additional
pre-condition installation routine for charmtester

https://codereview.appspot.com/60740045/

To post a comment you must log in.
Charles Butler (lazypower) wrote :

Please take a look.

28. By Charles Butler on 2014-02-07

Adds NFS filesystem validation tests

29. By Charles Butler on 2014-02-07

[merge] - tenative fix for testing purposes

30. By Charles Butler on 2014-02-07

Cleanup test errors

Charles Butler (lazypower) wrote :

Reviewers: mp+204059_code.launchpad.net,

Message:
Please take a look.

Description:
test updates

added relationship tests for :db relationship between mysql. Adds
additional
pre-condition installation routine for charmtester

https://code.launchpad.net/~lazypower/charms/precise/owncloud/tests/+merge/204059

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/60740045/

Affected files (+156, -2 lines):
   [revision details]
   hooks/shared-fs-relation-changed
   tests/00_setup.sh
   tests/100_deploy.test

31. By Charles Butler on 2014-02-10

Cleanup for pyflakes and adds missing parens on r.raise_for_status()

Charles Butler (lazypower) wrote :
Matt Bruzek (mbruzek) wrote :

Just a nit, that you might want to add so the script can be called
non-interactively

https://codereview.appspot.com/60740045/diff/20001/tests/00_setup.sh
File tests/00_setup.sh (right):

https://codereview.appspot.com/60740045/diff/20001/tests/00_setup.sh#newcode8
tests/00_setup.sh:8: sudo apt-get install amulet python3-requests
python-requests amulet python3
Use the -y tag here to install non-interactively.

https://codereview.appspot.com/60740045/

32. By Charles Butler on 2014-02-10

Cleanup setup script

Charles Butler (lazypower) wrote :
Charles Butler (lazypower) wrote :

On 2014/02/10 22:34:00, mbruzek wrote:
> Just a nit, that you might want to add so the script can be called
> non-interactively

> https://codereview.appspot.com/60740045/diff/20001/tests/00_setup.sh
> File tests/00_setup.sh (right):

https://codereview.appspot.com/60740045/diff/20001/tests/00_setup.sh#newcode8
> tests/00_setup.sh:8: sudo apt-get install amulet python3-requests
> python-requests amulet python3
> Use the -y tag here to install non-interactively.

Patched and uploaded. Cleaned up by removing the Python2 Dependencies
since all amulet tests are Python3 at the moment.

https://codereview.appspot.com/60740045/

Preview Diff

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

Subscribers

People subscribed via source and target branches

to status/vote changes: