Merge lp:~jose/charms/precise/chamilo/add-tests into lp:charms/chamilo

Proposed by José Antonio Rey
Status: Merged
Merged at revision: 10
Proposed branch: lp:~jose/charms/precise/chamilo/add-tests
Merge into: lp:charms/chamilo
Diff against target: 133 lines (+91/-3)
5 files modified
hooks/config-changed (+4/-2)
hooks/install (+1/-0)
metadata.yaml (+1/-1)
tests/00-setup (+5/-0)
tests/10-deploy (+80/-0)
To merge this branch: bzr merge lp:~jose/charms/precise/chamilo/add-tests
Reviewer Review Type Date Requested Status
Charles Butler (community) Approve
Review Queue (community) automated testing Needs Fixing
Review via email: mp+241363@code.launchpad.net

Description of the change

Added tests for Chamilo, verifying that the site is up and the relation with mysql.

To post a comment you must log in.
Revision history for this message
Review Queue (review-queue) wrote :

This items has failed automated testing! Results available here http://reports.vapour.ws/charm-tests/charm-bundle-test-10344-results

review: Needs Fixing (automated testing)
Revision history for this message
Cory Johns (johnsca) wrote :

The test looks great except that it has a timing / race condition which is causing the failure. I've created a suggested fix in this MP to your branch: https://code.launchpad.net/~johnsca/charms/precise/chamilo/add-test-review/+merge/245207

Thanks for the otherwise great test!

19. By José Antonio Rey

Added timing/race condition to tests, thanks Cory!

Revision history for this message
Charles Butler (lazypower) wrote :

+1 LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/config-changed'
2--- hooks/config-changed 2014-06-25 23:43:23 +0000
3+++ hooks/config-changed 2014-12-19 17:36:18 +0000
4@@ -47,5 +47,7 @@
5 echo "$PASS" > .pass
6 fi
7
8-juju-log "Restarting server"
9-service apache2 restart
10+if [ -f .started ]; then
11+ juju-log "Restarting server"
12+ service apache2 restart
13+fi
14
15=== modified file 'hooks/install'
16--- hooks/install 2014-06-23 05:08:55 +0000
17+++ hooks/install 2014-12-19 17:36:18 +0000
18@@ -3,6 +3,7 @@
19 set -eux
20
21 juju-log "Installing dependencies"
22+apt-get update
23 apt-get install -y apache2 php5 php5-mysqlnd php5-gd makepasswd mysql-client php5-intl php5-curl
24
25 juju-log "Downloading Chamilo and verifying integrity"
26
27=== modified file 'metadata.yaml'
28--- metadata.yaml 2014-05-03 04:31:38 +0000
29+++ metadata.yaml 2014-12-19 17:36:18 +0000
30@@ -1,6 +1,6 @@
31 name: chamilo
32 summary: E-learning & Collaboration Suite
33-maintainer: José Antonio Rey <jose@ubuntu.com>
34+maintainer: Jose Antonio Rey <jose@ubuntu.com>
35 description: |
36 Chamilo is an open-source e-learning and content management system, aimed at
37 improving access to education and knowledge globally. It is backed up by the
38
39=== added directory 'tests'
40=== added file 'tests/00-setup'
41--- tests/00-setup 1970-01-01 00:00:00 +0000
42+++ tests/00-setup 2014-12-19 17:36:18 +0000
43@@ -0,0 +1,5 @@
44+#!/bin/bash
45+
46+sudo add-apt-repository ppa:juju/stable -y
47+sudo apt-get update
48+sudo apt-get install amulet python3-requests -y
49
50=== added file 'tests/10-deploy'
51--- tests/10-deploy 1970-01-01 00:00:00 +0000
52+++ tests/10-deploy 2014-12-19 17:36:18 +0000
53@@ -0,0 +1,80 @@
54+#!/usr/bin/env python3
55+
56+import amulet
57+import requests
58+import unittest
59+import time
60+
61+
62+class TestDeployment(unittest.TestCase):
63+ @classmethod
64+ def setUpClass(cls):
65+ cls.deployment = amulet.Deployment(series='precise')
66+
67+ cls.deployment.add('chamilo')
68+ cls.deployment.add('mysql')
69+ cls.user = 'admin'
70+ cls.password = 'ubuntu'
71+ cls.deployment.configure('chamilo', {'user': cls.user, 'pass':
72+ cls.password})
73+ cls.deployment.relate('mysql:db', 'chamilo:db')
74+ cls.deployment.expose('chamilo')
75+
76+ try:
77+ cls.deployment.setup(timeout=900)
78+ cls.deployment.sentry.wait()
79+ except amulet.helpers.TimeoutError:
80+ amulet.raise_status(amulet.SKIP, msg="Environment wasn't stood up \
81+ in time")
82+ except:
83+ raise
84+ cls.chamilounit = cls.deployment.sentry.unit['chamilo/0']
85+ cls.mysqlunit = cls.deployment.sentry.unit['mysql/0']
86+ cls.domain = cls.chamilounit.info['public-address']
87+ cls.deployment.configure('chamilo', {'domain': cls.domain})
88+
89+ def wait_for(self, callback, timeout=30):
90+ start = time.time()
91+ while time.time() - start < timeout:
92+ if callback():
93+ return True
94+ time.sleep(1)
95+ return False
96+
97+ def test_1_check_apache_status(self):
98+ apache2status = 'sudo service apache2 status'
99+ test = lambda: self.chamilounit.run(apache2status)[1] == 0
100+ if not self.wait_for(test):
101+ message = 'Apache2 does not seem to be running on %s' % self.domain
102+ amulet.raise_status(amulet.FAIL, msg=message)
103+
104+ def test_2_check_mysql_relation(self):
105+ mysqlrelation = self.mysqlunit.relation('db', 'chamilo:db')
106+ ip = mysqlrelation['host']
107+ password = mysqlrelation['password']
108+ user = mysqlrelation['user']
109+ mysqlstatus = 'mysqladmin status -h {0} -u {1} --password={2}'.format(ip, user, password)
110+ test = lambda: self.mysqlunit.run(mysqlstatus)[1] == 0
111+ if not self.wait_for(test):
112+ message = 'Unable to get MySQL status at %s' % ip
113+ amulet.raise_status(amulet.FAIL, msg=message)
114+ else:
115+ print('Chamilo <-> MySQL relation verified succesfully!')
116+
117+ def test_3_check_chamilo_install(self):
118+ def test():
119+ r = requests.get('http://%s/' % self.domain)
120+ if r.status_code != 200:
121+ return False
122+
123+ return 'My Organisation' in r.text
124+
125+ if self.wait_for(test):
126+ print('Chamilo is running on %s!' % self.domain)
127+ else:
128+ message = 'Unable to get the correct title for the Chamilo \
129+ instance at %s' % self.domain
130+ amulet.raise_status(amulet.FAIL, msg=message)
131+
132+if __name__ == '__main__':
133+ unittest.main()

Subscribers

People subscribed via source and target branches

to all changes: