~frankban/charms/oneiric/buildbot-master/02-14

« back to all changes in this revision

Viewing changes to tests/buildbot-master.test

[r=bac] add a test for more of the charm configuration options and harden another test

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
    encode_file,
8
8
    run,
9
9
    unit_info,
 
10
    wait_for_page_contents,
10
11
    wait_for_unit,
11
12
    )
12
 
import base64
13
13
import os.path
 
14
import tempfile
14
15
import unittest
15
 
import urllib2
 
16
import yaml
16
17
 
17
18
juju = command('juju')
18
19
 
 
20
def make_charm_config_file(charm_config):
 
21
    charm_config_file = tempfile.NamedTemporaryFile()
 
22
    charm_config_file.write(yaml.dump(charm_config))
 
23
    charm_config_file.flush()
 
24
    # The NamedTemporaryFile instance is returned instead of just the name
 
25
    # because we want to take advantage of garbage collection-triggered
 
26
    # deletion of the temp file when it goes out of scope in the caller.
 
27
    return charm_config_file
 
28
 
 
29
 
 
30
def deploy(charm_config):
 
31
    charm_config_file = make_charm_config_file(charm_config)
 
32
    juju('deploy', 'buildbot-master', '--config='+charm_config_file.name)
 
33
    wait_for_unit('buildbot-master')
 
34
    addr = unit_info('buildbot-master', 'public-address')
 
35
    url = 'http://{}:8010'.format(addr)
 
36
    wait_for_page_contents(url, 'Welcome to the Buildbot')
 
37
 
 
38
 
19
39
class TestCharm(unittest.TestCase):
20
40
 
21
41
    def tearDown(self):
30
50
        self.assertEqual(unit_info('buildbot-master', 'state'), 'started')
31
51
 
32
52
    def test_port_opened(self):
33
 
        juju('deploy', 'buildbot-master')
34
 
        juju('set', 'buildbot-master', 'extra-packages=git')
35
 
        config_path = os.path.join(os.path.dirname(__file__), 'test.cfg')
36
 
        config = encode_file(config_path)
37
 
        juju('set', 'buildbot-master', 'config-file='+config)
38
 
        wait_for_unit('buildbot-master')
39
 
        addr = unit_info('buildbot-master', 'public-address')
40
 
        try:
41
 
            page = urllib2.urlopen('http://{}:8010'.format(addr)).read()
42
 
        except urllib2.URLError:
43
 
            self.fail('could not fetch buildbot master status page')
44
 
        self.assertIn('Welcome to the Buildbot', page)
 
53
        # Deploying a buildbot master should result in it opening a port and
 
54
        # serving its status via HTTP.
 
55
        bb_config_path = os.path.join(os.path.dirname(__file__), 'test.cfg')
 
56
        charm_config = {
 
57
            'buildbot-master': {
 
58
                'extra-packages': 'git',
 
59
                'installdir': '/tmp/buildbot',
 
60
                'config-file': encode_file(bb_config_path),
 
61
            }}
 
62
        deploy(charm_config)
 
63
 
 
64
    def test_lpbuildbot(self):
 
65
        # Deploying a Launchpad-specific buildbot master does a good job of
 
66
        # exercising the configuration parameters.  For example, the
 
67
        # configuration in this test adds a repositroy (lucid main universe),
 
68
        # installs a non-default buildbot package, and fetches the buildbot
 
69
        # configuration from bzr.
 
70
        charm_config = {
 
71
            'buildbot-master': {
 
72
                'buildbot-pkg': 'buildbot/lucid',
 
73
                'config-transport': 'bzr',
 
74
                'config-url':
 
75
                    'http://bazaar.launchpad.net/~launchpad/lpbuildbot/public',
 
76
                'extra-repository':
 
77
                    'deb http://us.archive.ubuntu.com/ubuntu/'
 
78
                    ' lucid main universe',
 
79
                'installdir': '/var/lib/buildbot/masters/lpbuildbot',
 
80
            }}
 
81
        deploy(charm_config)
45
82
 
46
83
 
47
84
if __name__ == '__main__':