Merge ~cjwatson/launchpad-buildd:dynamic-test-config into launchpad-buildd:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: a42da402b9f4d332ebca1f313149d2524bc6af80
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad-buildd:dynamic-test-config
Merge into: launchpad-buildd:master
Diff against target: 128 lines (+29/-22)
4 files modified
MANIFEST.in (+1/-1)
debian/changelog (+6/-0)
dev/null (+0/-8)
lpbuildd/tests/harness.py (+22/-13)
Reviewer Review Type Date Requested Status
Jürgen Gmach Approve
Review via email: mp+419964@code.launchpad.net

Commit message

Dynamically generate configuration file in lpbuildd.tests.harness

Description of the change

This removes some reliance on state under `/var/tmp/` from the test suite, and it should also make it easier for some tests in Launchpad itself to control the behaviour of test builder instances.

To post a comment you must log in.
Revision history for this message
Jürgen Gmach (jugmac00) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/MANIFEST.in b/MANIFEST.in
index f061118..c1783cc 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -12,4 +12,4 @@ include debian/changelog
12include sbuildrc12include sbuildrc
13include template-buildd-slave.conf13include template-buildd-slave.conf
14include lpbuildd/buildd-slave.tac14include lpbuildd/buildd-slave.tac
15recursive-include lpbuildd/tests *.diff *.tar.gz buildd-slave-test.conf buildlog buildlog.long15recursive-include lpbuildd/tests *.diff *.tar.gz buildlog buildlog.long
diff --git a/debian/changelog b/debian/changelog
index c539da7..ad5eace 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
1launchpad-buildd (213) UNRELEASED; urgency=medium
2
3 * Dynamically generate configuration file in lpbuildd.tests.harness.
4
5 -- Colin Watson <cjwatson@ubuntu.com> Wed, 20 Apr 2022 16:03:01 +0100
6
1launchpad-buildd (212) focal; urgency=medium7launchpad-buildd (212) focal; urgency=medium
28
3 * Ensure that launchpad-buildd runs with lxd as a supplementary group.9 * Ensure that launchpad-buildd runs with lxd as a supplementary group.
diff --git a/lpbuildd/tests/buildd-slave-test.conf b/lpbuildd/tests/buildd-slave-test.conf
4deleted file mode 10064410deleted file mode 100644
index 34fd47d..0000000
--- a/lpbuildd/tests/buildd-slave-test.conf
+++ /dev/null
@@ -1,8 +0,0 @@
1# Test buildd configuration
2
3[builder]
4architecturetag = i386
5filecache = /var/tmp/buildd/filecache
6bindhost = localhost
7bindport = 8321
8sharepath = /var/tmp/buildd
diff --git a/lpbuildd/tests/harness.py b/lpbuildd/tests/harness.py
index 5849834..103308b 100644
--- a/lpbuildd/tests/harness.py
+++ b/lpbuildd/tests/harness.py
@@ -12,18 +12,18 @@ except ImportError:
12import os12import os
13import shutil13import shutil
14import tempfile14import tempfile
15from textwrap import dedent
15import unittest16import unittest
1617
17from fixtures import EnvironmentVariable18from fixtures import (
19 EnvironmentVariable,
20 TempDir,
21 )
18from txfixtures.tachandler import TacTestFixture22from txfixtures.tachandler import TacTestFixture
1923
20from lpbuildd.builder import Builder24from lpbuildd.builder import Builder
2125
2226
23test_conffile = os.path.join(
24 os.path.dirname(__file__), 'buildd-slave-test.conf')
25
26
27class MockBuildManager:27class MockBuildManager:
28 """Mock BuildManager class.28 """Mock BuildManager class.
2929
@@ -42,7 +42,8 @@ class BuilddTestCase(unittest.TestCase):
42 def setUp(self):42 def setUp(self):
43 """Setup a Builder using the test config."""43 """Setup a Builder using the test config."""
44 conf = SafeConfigParser()44 conf = SafeConfigParser()
45 conf.read(test_conffile)45 conf.add_section("builder")
46 conf.set("builder", "architecturetag", "i386")
46 conf.set("builder", "filecache", tempfile.mkdtemp())47 conf.set("builder", "filecache", tempfile.mkdtemp())
4748
48 self.builder = Builder(conf)49 self.builder = Builder(conf)
@@ -106,6 +107,8 @@ class BuilddTestSetup(TacTestFixture):
106 >>> fixture.tearDown()107 >>> fixture.tearDown()
107 """108 """
108109
110 _root = None
111
109 def setUp(self, **kwargs):112 def setUp(self, **kwargs):
110 # TacTestFixture defaults to /usr/bin/twistd, but on Ubuntu the113 # TacTestFixture defaults to /usr/bin/twistd, but on Ubuntu the
111 # Python 3 version of this is /usr/bin/twistd3, so that makes for a114 # Python 3 version of this is /usr/bin/twistd3, so that makes for a
@@ -115,23 +118,30 @@ class BuilddTestSetup(TacTestFixture):
115 super().setUp(**kwargs)118 super().setUp(**kwargs)
116119
117 def setUpRoot(self):120 def setUpRoot(self):
118 """Recreate empty root directory to avoid problems."""
119 if os.path.exists(self.root):
120 shutil.rmtree(self.root)
121 os.mkdir(self.root)
122 filecache = os.path.join(self.root, 'filecache')121 filecache = os.path.join(self.root, 'filecache')
123 os.mkdir(filecache)122 os.mkdir(filecache)
124 self.useFixture(EnvironmentVariable('HOME', self.root))123 self.useFixture(EnvironmentVariable('HOME', self.root))
124 test_conffile = os.path.join(self.root, "buildd.conf")
125 with open(test_conffile, "w") as f:
126 f.write(dedent(f"""\
127 [builder]
128 architecturetag = i386
129 filecache = {filecache}
130 bindhost = localhost
131 bindport = {self.daemon_port}
132 sharepath = {self.root}
133 """))
125 self.useFixture(EnvironmentVariable('BUILDD_CONFIG', test_conffile))134 self.useFixture(EnvironmentVariable('BUILDD_CONFIG', test_conffile))
126 # XXX cprov 2005-05-30:135 # XXX cprov 2005-05-30:
127 # When we are about running it seriously we need :136 # When we are about running it seriously we need :
128 # * install sbuild package137 # * install sbuild package
129 # * to copy the scripts for sbuild138 # * to copy the scripts for sbuild
130 self.addCleanup(shutil.rmtree, self.root)
131139
132 @property140 @property
133 def root(self):141 def root(self):
134 return '/var/tmp/buildd'142 if self._root is None:
143 self._root = self.useFixture(TempDir()).path
144 return self._root
135145
136 @property146 @property
137 def tacfile(self):147 def tacfile(self):
@@ -151,5 +161,4 @@ class BuilddTestSetup(TacTestFixture):
151161
152 @property162 @property
153 def daemon_port(self):163 def daemon_port(self):
154 # This must match buildd-slave-test.conf.
155 return 8321164 return 8321

Subscribers

People subscribed via source and target branches