~abentley/charms/trusty/apache2/apache-website

« back to all changes in this revision

Viewing changes to tests/20-mpm-test.py

  • Committer: Aaron Bentley
  • Date: 2015-04-15 20:23:01 UTC
  • mfrom: (56.4.7 apache2)
  • Revision ID: aaron.bentley@canonical.com-20150415202301-8sbei1eiol8ywp6a
Merged trunk into apache2-website-interface.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python3
 
2
import os
 
3
import time
 
4
import unittest
 
5
import amulet
 
6
 
 
7
 
 
8
class BundleTest(unittest.TestCase):
 
9
    """ Create a class for testing the charm in the unit test framework. """
 
10
    @classmethod
 
11
    def setUpClass(cls):
 
12
        """ Set up an amulet deployment using the bundle. """
 
13
        d = amulet.Deployment(series='trusty')
 
14
        d.add('apache2', os.path.join(os.path.dirname(__file__), os.pardir))
 
15
        d.setup(180)
 
16
        cls.d = d
 
17
        cls.unit = d.sentry.unit['apache2/0']
 
18
        output, code = cls.unit.run('curl localhost')
 
19
 
 
20
    def assert_mpm(self, mpm):
 
21
        cmd = (". /etc/apache2/envvars && apache2 -V 2>/dev/null "
 
22
               "| grep MPM | awk -F: '{print $2}' | xargs")
 
23
        self.d.configure('apache2', {'mpm_type': mpm})
 
24
        self.d.sentry.wait()
 
25
        # the above doesn't seem to work
 
26
        time.sleep(10)
 
27
        # enable default web site so we can check for a valid config
 
28
        output, code = self.unit.run(
 
29
            'a2ensite 000-default.conf && service apache2 reload')
 
30
        time.sleep(10)
 
31
        # enable default web site so we can check for a valid config
 
32
        output, code = self.unit.run(cmd)
 
33
        self.assertEqual(code, 0)
 
34
        self.assertIn(mpm, output)
 
35
        output, code = self.unit.run('curl localhost')
 
36
        if code != 0:
 
37
            raise Exception(output)
 
38
        self.assertEqual(code, 0)
 
39
 
 
40
    def test_mpm_worker(self):
 
41
        self.assert_mpm('worker')
 
42
 
 
43
    def test_mpm_prefork(self):
 
44
        self.assert_mpm('prefork')
 
45
 
 
46
    def test_mpm_event(self):
 
47
        self.assert_mpm('event')
 
48
 
 
49
 
 
50
if __name__ == '__main__':
 
51
    unittest.main()