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