1
# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
12
from ConfigParser import SafeConfigParser
14
from txfixtures.tachandler import TacTestFixture
16
from canonical.buildd.slave import BuildDSlave
18
from lp.services.osutils import remove_tree
21
test_conffile = os.path.join(
22
os.path.dirname(__file__), 'buildd-slave-test.conf')
25
class MockBuildManager(object):
26
"""Mock BuildManager class.
28
Only implements 'is_archive_private' as False.
30
is_archive_private = False
33
class BuilddTestCase(unittest.TestCase):
34
"""Unit tests for logtail mechanisms."""
37
"""Setup a BuildDSlave using the test config."""
38
conf = SafeConfigParser()
39
conf.read(test_conffile)
40
conf.set("slave", "filecache", tempfile.mkdtemp())
42
self.slave = BuildDSlave(conf)
43
self.slave._log = True
44
self.slave.manager = MockBuildManager()
46
self.here = os.path.abspath(os.path.dirname(__file__))
49
"""Remove the 'filecache' directory used for the tests."""
50
remove_tree(self.slave._cachepath)
52
def makeLog(self, size):
53
"""Inject data into the default buildlog file."""
54
f = open(self.slave.cachePath('buildlog'), 'w')
59
class BuilddSlaveTestSetup(TacTestFixture):
60
r"""Setup BuildSlave for use by functional tests
62
>>> fixture = BuilddSlaveTestSetup()
65
Make sure the server is running
68
>>> s = xmlrpclib.Server('http://localhost:8221/rpc/')
69
>>> s.echo('Hello World')
71
>>> fixture.tearDown()
76
>>> s = xmlrpclib.Server('http://localhost:8221/rpc/')
78
>>> s.echo('Hello World')
87
>>> for buildtype in sorted(info[2]):
95
['BuilderStatus.IDLE', '']
97
>>> fixture.tearDown()
100
"""Recreate empty root directory to avoid problems."""
101
remove_tree(self.root)
103
filecache = os.path.join(self.root, 'filecache')
105
os.environ['HOME'] = self.root
106
os.environ['BUILDD_SLAVE_CONFIG'] = test_conffile
107
# XXX cprov 2005-05-30:
108
# When we are about running it seriously we need :
109
# * install sbuild package
110
# * to copy the scripts for sbuild
111
self.addCleanup(remove_tree, self.root)
115
return '/var/tmp/buildd'
119
return os.path.abspath(os.path.join(
120
os.path.dirname(__file__),
127
return os.path.join(self.root, 'build-slave.pid')
131
return '/var/tmp/build-slave.log'
133
def _hasDaemonStarted(self):
134
"""Called by the superclass to check if the daemon is listening.
136
The slave is ready when it's accepting connections.
138
# This must match buildd-slave-test.conf.
139
return self._isPortListening('localhost', 8221)