Merge lp:~benji/charms/oneiric/buildbot-master/tests-with-config-up-front into lp:~yellow/charms/oneiric/buildbot-master/trunk

Proposed by Benji York
Status: Merged
Approved by: Brad Crittenden
Approved revision: 23
Merged at revision: 23
Proposed branch: lp:~benji/charms/oneiric/buildbot-master/tests-with-config-up-front
Merge into: lp:~yellow/charms/oneiric/buildbot-master/trunk
Diff against target: 89 lines (+51/-14)
1 file modified
tests/buildbot-master.test (+51/-14)
To merge this branch: bzr merge lp:~benji/charms/oneiric/buildbot-master/tests-with-config-up-front
Reviewer Review Type Date Requested Status
Brad Crittenden (community) code Approve
Review via email: mp+92377@code.launchpad.net

Description of the change

This branch adds tests for the configure-things-up-front scenario.

All the configuration options for the buildbot-master should be covered
now except for config-user and config-private-key, both of which I
/think/ can go away.

Tests pass:

    % python hooks/tests.py
    ..............
    ----------------------------------------------------------------------
    Ran 14 tests in 0.047s

    % RESOLVE_TEST_CHARMS=1 tests/buildbot-master.test; beep
    ...
    ----------------------------------------------------------------------
    Ran 3 tests in 119.182s

To post a comment you must log in.
24. By Benji York

add a comment about temp file deletion

Revision history for this message
Brad Crittenden (bac) wrote :

Firstly, let's not get rid of the user/key stuff just yet. It may need to be repurposed for the "persist history before dying" effort.

As we discussed on IRC please comment why you use flush() on the temporary file so someone doesn't inadvertantly "fix" it.

We also discussed how our test method encode_file doesn't work in the manner we'd use in real life so it may be better to rewrite it to use the UNIX 'base64' command. We used to suggest 'uuencode' which didn't work with our decoding. So I do think we should test the method we suggest people use.

Otherwise a nice addition to the tests.

review: Approve (code)
Revision history for this message
Benji York (benji) wrote :

> As we discussed on IRC please comment why you use flush() on the temporary
> file so someone doesn't inadvertantly "fix" it.

I added a comment explaining the apparent oddity.

> We also discussed how our test method encode_file doesn't work in the manner
> we'd use in real life so it may be better to rewrite it to use the UNIX
> 'base64' command. We used to suggest 'uuencode' which didn't work with our
> decoding. So I do think we should test the method we suggest people use.

Yep, we should have a test like that. If we don't remove the need for base64
encoding alltogether, I'll add one in another branch.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'tests/buildbot-master.test'
--- tests/buildbot-master.test 2012-02-08 22:01:59 +0000
+++ tests/buildbot-master.test 2012-02-10 13:13:18 +0000
@@ -7,15 +7,35 @@
7 encode_file,7 encode_file,
8 run,8 run,
9 unit_info,9 unit_info,
10 wait_for_page_contents,
10 wait_for_unit,11 wait_for_unit,
11 )12 )
12import base64
13import os.path13import os.path
14import tempfile
14import unittest15import unittest
15import urllib216import yaml
1617
17juju = command('juju')18juju = command('juju')
1819
20def 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
30def 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
19class TestCharm(unittest.TestCase):39class TestCharm(unittest.TestCase):
2040
21 def tearDown(self):41 def tearDown(self):
@@ -30,18 +50,35 @@
30 self.assertEqual(unit_info('buildbot-master', 'state'), 'started')50 self.assertEqual(unit_info('buildbot-master', 'state'), 'started')
3151
32 def test_port_opened(self):52 def test_port_opened(self):
33 juju('deploy', 'buildbot-master')53 # Deploying a buildbot master should result in it opening a port and
34 juju('set', 'buildbot-master', 'extra-packages=git')54 # serving its status via HTTP.
35 config_path = os.path.join(os.path.dirname(__file__), 'test.cfg')55 bb_config_path = os.path.join(os.path.dirname(__file__), 'test.cfg')
36 config = encode_file(config_path)56 charm_config = {
37 juju('set', 'buildbot-master', 'config-file='+config)57 'buildbot-master': {
38 wait_for_unit('buildbot-master')58 'extra-packages': 'git',
39 addr = unit_info('buildbot-master', 'public-address')59 'installdir': '/tmp/buildbot',
40 try:60 'config-file': encode_file(bb_config_path),
41 page = urllib2.urlopen('http://{}:8010'.format(addr)).read()61 }}
42 except urllib2.URLError:62 deploy(charm_config)
43 self.fail('could not fetch buildbot master status page')63
44 self.assertIn('Welcome to the Buildbot', page)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)
4582
4683
47if __name__ == '__main__':84if __name__ == '__main__':

Subscribers

People subscribed via source and target branches

to all changes: