Merge lp:~lazypower/charms/precise/owncloud/refactor_amulet_tests into lp:~jose/charms/precise/owncloud/port-change+repo+ssl-support

Proposed by Charles Butler
Status: Merged
Approved by: José Antonio Rey
Approved revision: 32
Merged at revision: 33
Proposed branch: lp:~lazypower/charms/precise/owncloud/refactor_amulet_tests
Merge into: lp:~jose/charms/precise/owncloud/port-change+repo+ssl-support
Diff against target: 272 lines (+116/-147)
2 files modified
tests/100-deploy.py (+116/-0)
tests/100_deploy.test (+0/-147)
To merge this branch: bzr merge lp:~lazypower/charms/precise/owncloud/refactor_amulet_tests
Reviewer Review Type Date Requested Status
José Antonio Rey +1 Approve
Review via email: mp+219903@code.launchpad.net

Description of the change

refactors the tests for clarity, and to introduce a cleaner testing format.

To post a comment you must log in.
Revision history for this message
José Antonio Rey (jose) wrote :

Thanks a lot for working on this, Charles. Looks good to me!

review: Approve (+1)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'tests/100-deploy.py'
2--- tests/100-deploy.py 1970-01-01 00:00:00 +0000
3+++ tests/100-deploy.py 2014-05-16 20:30:30 +0000
4@@ -0,0 +1,116 @@
5+#!/usr/bin/env python3
6+# The format of this test was shamelessly ripped from Cory Johns awesome
7+# tests that resemble nosetests in the Apache Allura charm. <3
8+# http://bazaar.launchpad.net/~johnsca/charms/precise/apache-allura/
9+
10+import amulet
11+import requests
12+
13+
14+class TestDeploy(object):
15+
16+ def __init__(self, time=2500):
17+ # Attempt to load the deployment topology from a bundle.
18+ self.deploy = amulet.Deployment()
19+
20+ # If something errored out, attempt to continue by
21+ # manually specifying a standalone deployment
22+ self.deploy.add('owncloud')
23+ self.deploy.add('mysql')
24+ self.deploy.add('nfs')
25+ self.deploy.configure('owncloud', {'user': 'tom',
26+ 'password': 'swordfish'})
27+ self.deploy.relate('owncloud:db', 'mysql:db')
28+ self.deploy.relate('owncloud:shared-fs', 'nfs:nfs')
29+ self.deploy.expose('owncloud')
30+
31+ try:
32+ self.deploy.setup(time)
33+ self.deploy.sentry.wait(time)
34+ except:
35+ amulet.raise_status(amulet.FAIL, msg="Environment standup timeout")
36+ sentry = self.deploy.sentry
37+
38+ self.domain = sentry.unit['owncloud/0'].info['public-address']
39+ self.mysql_unit = self.deploy.sentry.unit['mysql/0']
40+ self.nfs_unit = self.deploy.sentry.unit['nfs/0']
41+ self.app_unit = self.deploy.sentry.unit['owncloud/0']
42+
43+ def run(self):
44+ for test in dir(self):
45+ if test.startswith('test_'):
46+ getattr(self, test)()
47+
48+ def test_standalone_http(self):
49+
50+ # r = requests.get("http://%s/" % domain, data, headers=h)
51+ r = requests.get("https://%s/index.php" % self.domain, verify=False)
52+ r.raise_for_status()
53+
54+ search_string = 'web services under your control'
55+ if r.text.find(search_string) is -1:
56+ amulet.raise_status(amulet.FAIL, msg="Unable to verify login page")
57+
58+ def test_database_relationship(self):
59+
60+ sent_config = self.mysql_unit.relation('db', 'owncloud:db')
61+ # I'm sorry this is gross, and repeats itself. This is a dirty hack
62+ # around owncloud not normalizing quotations, and field names.
63+ try:
64+ filepath = "/var/www/owncloud/config/autoconfig.php"
65+ cfg = self.deploy.sentry.unit['owncloud/0'].file_contents(filepath)
66+ cfg_to_check = {'dbuser': 'user', 'dbpass': 'password',
67+ 'dbhost': 'host'}
68+ for c_key, j_key in cfg_to_check.items():
69+ if cfg.find('"%s" => "%s"' % (c_key, sent_config[j_key])) == -1:
70+ amulet.raise_status(amulet.FAIL,
71+ msg="Unable to validate db cfg %s" % j_key)
72+ except:
73+ filepath = "/var/www/owncloud/config/config.php"
74+ cfg = self.deploy.sentry.unit['owncloud/0'].file_contents(filepath)
75+ cfg_to_check = {'dbuser': 'user', 'dbpassword': 'password',
76+ 'dbhost': 'host'}
77+ for c_key, j_key in cfg_to_check.items():
78+ if cfg.find("'%s' => '%s'" % (c_key, sent_config[j_key])) == -1:
79+ amulet.raise_status(amulet.FAIL,
80+ msg="Unable to validate db cfg %s" % j_key)
81+
82+ def term_search(self, output, term):
83+ if output.find(term) == -1:
84+ amulet.raise_status(amulet.FAIL,
85+ msg="Unable to validate NFS config %s" % term)
86+
87+ def test_nfs_relationship(self):
88+ # Cache Relationship details
89+ nfs_relation = self.nfs_unit.relation('nfs', 'owncloud:shared-fs')
90+
91+ # Leverage Amulet's exception handling if directory doesnt exist
92+ # to check for the directory, as a cheap quick fail test.
93+ try:
94+ self.app_unit.directory('/var/lib/owncloud')
95+ except:
96+ amulet.raise_status(amulet.FAIL, msg="NFS Directory not found")
97+
98+ #Fetch the contents of mtab for data validation
99+ mtab_contents = self.app_unit.file_contents('/etc/mtab')
100+
101+ self.term_search(mtab_contents, nfs_relation['private-address'])
102+ self.term_search(mtab_contents, nfs_relation['fstype'])
103+ self.term_search(mtab_contents, nfs_relation['mountpoint'])
104+ self.term_search(mtab_contents, nfs_relation['options'])
105+
106+ def test_nfs_write_pipeline(self):
107+ # Validate file write pipeline
108+ #Build a $block_size file, and ship it via NFS
109+ cmd_builder = "dd if=/dev/zero of=/var/lib/owncloud/amulet-file-test bs=8M count=1"
110+ self.app_unit.run(cmd_builder)
111+
112+ filepath = '/srv/data/relation-sentry/amulet-file-test'
113+ file_test = self.nfs_unit.file(filepath)
114+ if file_test['size'] < 8000000:
115+ amulet.raise_status(amulet.FAIL, 'File size constraint not met')
116+
117+
118+if __name__ == '__main__':
119+ runner = TestDeploy()
120+ runner.run()
121
122=== removed file 'tests/100_deploy.test'
123--- tests/100_deploy.test 2014-05-08 04:28:00 +0000
124+++ tests/100_deploy.test 1970-01-01 00:00:00 +0000
125@@ -1,147 +0,0 @@
126-#!/usr/bin/env python3
127-
128-import amulet
129-import requests
130-
131-##########################################
132-# Config Options
133-##########################################
134-scale = 2
135-seconds = 1500
136-user = 'tom'
137-password = 'swordfish'
138-block_size = "8M"
139-verify_size = 8000000
140-
141-###########################################################
142-#Deployment Setup
143-############################################################
144-d = amulet.Deployment()
145-
146-d.add('owncloud', units=scale)
147-d.add('mysql')
148-d.add('haproxy')
149-d.add('nfs')
150-d.configure('owncloud', {'user': user, 'password': password})
151-d.relate('owncloud:db', 'mysql:db')
152-d.relate('owncloud:website', 'haproxy:reverseproxy')
153-d.relate('owncloud:shared-fs', 'nfs:nfs')
154-d.expose('owncloud')
155-d.expose('haproxy')
156-
157-
158-#perform deployment
159-try:
160- d.setup(timeout=seconds)
161- d.sentry.wait()
162-except amulet.helpers.TimeoutError:
163- message = 'The environment did not setup in %d seconds.', seconds
164- amulet.raise_status(amulet.SKIP, msg=message)
165-except:
166- raise
167-
168-
169-#############################################################
170-# Check presence of HTTP services
171-#############################################################
172-def validate_status_interface():
173- h = {'User-Agent': 'Mozilla/5.0 Gecko/20100101 Firefox/12.0',
174- 'Content-Type': 'application/x-www-form-urlencoded',
175- 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*',
176- 'Accept-Encoding': 'gzip, deflate'}
177-
178- data = {'user': 'tom', 'password': 'swordfish'}
179-
180- #validate the Owncloud login screen is present
181- domain = d.sentry.unit['owncloud/0'].info['public-address']
182- d.configure('owncloud', {'domain': domain})
183- r = requests.post("https://{}".format(
184- d.sentry.unit['owncloud/0'].info['public-address']),
185- data, headers=h)
186- r.raise_for_status()
187-
188- #validate the HAProxy daemon is forwarding as expected
189- ocdomain = d.sentry.unit['haproxy/0'].info['public-address']
190- d.configure('owncloud', {'domain': ocdomain})
191- r = requests.get("https://{}".format(
192- d.sentry.unit['haproxy/0'].info['public-address']))
193- r.raise_for_status
194-
195-
196-#############################################################
197-# Validate that each service is running
198-#############################################################
199-def validate_running_services():
200- output, code = d.sentry.unit['owncloud/0'].run('service apache2 status')
201- if code != 0:
202- message = "Failed to find running Apache instance on host owncloud/0"
203- amulet.raise_status(amulet.SKIP, msg=message)
204- output, code = d.sentry.unit['mysql/0'].run('service mysql status')
205- if code != 0:
206- message = "Failed to find running MYSQL instance on host mysql/0"
207- amulet.raise_status(amulet.SKIP, msg=message)
208-
209-
210-#############################################################
211-# Validate that each service is running
212-#############################################################
213-def validate_owncloud_files():
214- index_status = d.sentry.unit['owncloud/0'].file_stat('/var/www/owncloud/index.php')
215- if index_status['size'] <= 0:
216- message = "Failed to find owncloud index.php"
217- amulet.raise_status(amulet.SKIP, msg=message)
218-
219-
220-#############################################################
221-# Validate database relationship
222-#############################################################
223-def validate_database_relationship():
224- #Connect to the sentrys and fetch the transmitted details
225- sent_config = d.sentry.unit['mysql/0'].relation('db', 'owncloud:db')
226- #Connect to owncloud's sentry and read the configuration PHP file
227- prod_config = d.sentry.unit['owncloud/0'].file_contents('/var/www/owncloud/config/config.php')
228- cfg_to_check = {'dbuser': 'user', 'dbpassword': 'password', 'dbhost': 'host'}
229-
230- #Search the return string of the config for the transmit values
231- for cfg_file_key, juju_cfg_key in cfg_to_check.items():
232- if prod_config.find("'%s' => '%s'" % (cfg_file_key, sent_config[juju_cfg_key])) == -1:
233- amulet.raise_status(amulet.SKIP, msg="Unable to validate db sent %s" % juju_cfg_key)
234-
235-
236-# Utility Method for searching output
237-def nfs_term_search(output, term):
238- if output.find(term) == -1:
239- amulet.raise_status(amulet.FAIL, msg="Unable to validate NFS export mounted with %s" % term)
240-
241-
242-###########################################################
243-# Validate NFS FileSystem Existence
244-###########################################################
245-def validate_nfs_relationship():
246- # Cache Relationship details
247- nfs_relation = d.sentry.unit['nfs/0'].relation('nfs', 'owncloud:shared-fs')
248- # Raises an error if the directory does not exist
249- d.sentry.unit['owncloud/0'].directory('/var/lib/owncloud')
250- #Fetch the contents of mtab for data validation
251- mtab_contents = d.sentry.unit['owncloud/0'].file_contents('/etc/mtab')
252-
253- nfs_term_search(mtab_contents, nfs_relation['private-address'])
254- nfs_term_search(mtab_contents, nfs_relation['fstype'])
255- nfs_term_search(mtab_contents, nfs_relation['mountpoint'])
256- nfs_term_search(mtab_contents, nfs_relation['options'])
257-
258- # Validate file write pipeline
259- #Build a $block_size file, and ship it via NFS
260- cmd_builder = "dd if=/dev/zero of=/var/lib/owncloud/amulet-file-test bs=%s count=1" % block_size
261- d.sentry.unit['owncloud/0'].run(cmd_builder)
262-
263- file_test = d.sentry.unit['nfs/0'].file('/srv/data/relation-sentry/amulet-file-test')
264- if file_test['size'] < verify_size:
265- amulet.raise_status(amulet.FAIL, 'File size constraint not met')
266-
267-
268-validate_status_interface()
269-validate_running_services()
270-validate_owncloud_files()
271-validate_database_relationship()
272-validate_nfs_relationship()

Subscribers

People subscribed via source and target branches