~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/canonical/buildd/tests/harness.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-08-03 11:23:34 UTC
  • mfrom: (13457.6.16 upgrade-stderr)
  • Revision ID: launchpad@pqm.canonical.com-20110803112334-acnupsa7jmzmdeet
[r=stevenk][bug=819751] Fix the implementation of several methods in
 LoggingUIFactory.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2009-2010 Canonical Ltd.  This software is licensed under the
 
2
# GNU Affero General Public License version 3 (see the file LICENSE).
 
3
 
 
4
__metaclass__ = type
 
5
__all__ = [
 
6
    'BuildlogSecurityTests',
 
7
    'BuilddTestCase',
 
8
    ]
 
9
 
 
10
import os
 
11
import tempfile
 
12
import unittest
 
13
from ConfigParser import SafeConfigParser
 
14
 
 
15
import canonical
 
16
 
 
17
from canonical.buildd.slave import BuildDSlave
 
18
from canonical.launchpad.daemons.tachandler import TacTestSetup
 
19
 
 
20
from lp.services.osutils import remove_tree
 
21
 
 
22
 
 
23
test_conffile = os.path.join(
 
24
    os.path.dirname(__file__), 'buildd-slave-test.conf')
 
25
 
 
26
 
 
27
class MockBuildManager(object):
 
28
    """Mock BuildManager class.
 
29
 
 
30
    Only implements 'is_archive_private' as False.
 
31
    """
 
32
    is_archive_private = False
 
33
 
 
34
 
 
35
class BuilddTestCase(unittest.TestCase):
 
36
    """Unit tests for logtail mechanisms."""
 
37
 
 
38
    def setUp(self):
 
39
        """Setup a BuildDSlave using the test config."""
 
40
        conf = SafeConfigParser()
 
41
        conf.read(test_conffile)
 
42
        conf.set("slave", "filecache", tempfile.mkdtemp())
 
43
 
 
44
        self.slave = BuildDSlave(conf)
 
45
        self.slave._log = True
 
46
        self.slave.manager = MockBuildManager()
 
47
 
 
48
        self.here = os.path.abspath(os.path.dirname(__file__))
 
49
 
 
50
    def tearDown(self):
 
51
        """Remove the 'filecache' directory used for the tests."""
 
52
        remove_tree(self.slave._cachepath)
 
53
 
 
54
    def makeLog(self, size):
 
55
        """Inject data into the default buildlog file."""
 
56
        f = open(self.slave.cachePath('buildlog'), 'w')
 
57
        f.write("x" * size)
 
58
        f.close()
 
59
 
 
60
 
 
61
class BuilddSlaveTestSetup(TacTestSetup):
 
62
    r"""Setup BuildSlave for use by functional tests
 
63
 
 
64
    >>> fixture = BuilddSlaveTestSetup()
 
65
    >>> fixture.setUp()
 
66
 
 
67
    Make sure the server is running
 
68
 
 
69
    >>> import xmlrpclib
 
70
    >>> s = xmlrpclib.Server('http://localhost:8221/rpc/')
 
71
    >>> s.echo('Hello World')
 
72
    ['Hello World']
 
73
    >>> fixture.tearDown()
 
74
 
 
75
    Again for luck !
 
76
 
 
77
    >>> fixture.setUp()
 
78
    >>> s = xmlrpclib.Server('http://localhost:8221/rpc/')
 
79
 
 
80
    >>> s.echo('Hello World')
 
81
    ['Hello World']
 
82
 
 
83
    >>> info = s.info()
 
84
    >>> len(info)
 
85
    3
 
86
    >>> print info[:2]
 
87
    ['1.0', 'i386']
 
88
 
 
89
    >>> for buildtype in sorted(info[2]):
 
90
    ...     print buildtype
 
91
    binarypackage
 
92
    debian
 
93
    sourcepackagerecipe
 
94
    translation-templates
 
95
 
 
96
    >>> s.status()
 
97
    ['BuilderStatus.IDLE', '']
 
98
 
 
99
    >>> fixture.tearDown()
 
100
    """
 
101
    def setUpRoot(self):
 
102
        """Recreate empty root directory to avoid problems."""
 
103
        remove_tree(self.root)
 
104
        os.mkdir(self.root)
 
105
        filecache = os.path.join(self.root, 'filecache')
 
106
        os.mkdir(filecache)
 
107
        os.environ['HOME'] = self.root
 
108
        os.environ['BUILDD_SLAVE_CONFIG'] = test_conffile
 
109
        # XXX cprov 2005-05-30:
 
110
        # When we are about running it seriously we need :
 
111
        # * install sbuild package
 
112
        # * to copy the scripts for sbuild
 
113
        self.addCleanup(remove_tree, self.root)
 
114
 
 
115
    @property
 
116
    def root(self):
 
117
        return '/var/tmp/buildd'
 
118
 
 
119
    @property
 
120
    def tacfile(self):
 
121
        return os.path.abspath(os.path.join(
 
122
            os.path.dirname(canonical.__file__), os.pardir, os.pardir,
 
123
            'daemons/buildd-slave.tac'
 
124
            ))
 
125
 
 
126
    @property
 
127
    def pidfile(self):
 
128
        return os.path.join(self.root, 'build-slave.pid')
 
129
 
 
130
    @property
 
131
    def logfile(self):
 
132
        return '/var/tmp/build-slave.log'