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
1diff --git a/MANIFEST.in b/MANIFEST.in
2index f061118..c1783cc 100644
3--- a/MANIFEST.in
4+++ b/MANIFEST.in
5@@ -12,4 +12,4 @@ include debian/changelog
6 include sbuildrc
7 include template-buildd-slave.conf
8 include lpbuildd/buildd-slave.tac
9-recursive-include lpbuildd/tests *.diff *.tar.gz buildd-slave-test.conf buildlog buildlog.long
10+recursive-include lpbuildd/tests *.diff *.tar.gz buildlog buildlog.long
11diff --git a/debian/changelog b/debian/changelog
12index c539da7..ad5eace 100644
13--- a/debian/changelog
14+++ b/debian/changelog
15@@ -1,3 +1,9 @@
16+launchpad-buildd (213) UNRELEASED; urgency=medium
17+
18+ * Dynamically generate configuration file in lpbuildd.tests.harness.
19+
20+ -- Colin Watson <cjwatson@ubuntu.com> Wed, 20 Apr 2022 16:03:01 +0100
21+
22 launchpad-buildd (212) focal; urgency=medium
23
24 * Ensure that launchpad-buildd runs with lxd as a supplementary group.
25diff --git a/lpbuildd/tests/buildd-slave-test.conf b/lpbuildd/tests/buildd-slave-test.conf
26deleted file mode 100644
27index 34fd47d..0000000
28--- a/lpbuildd/tests/buildd-slave-test.conf
29+++ /dev/null
30@@ -1,8 +0,0 @@
31-# Test buildd configuration
32-
33-[builder]
34-architecturetag = i386
35-filecache = /var/tmp/buildd/filecache
36-bindhost = localhost
37-bindport = 8321
38-sharepath = /var/tmp/buildd
39diff --git a/lpbuildd/tests/harness.py b/lpbuildd/tests/harness.py
40index 5849834..103308b 100644
41--- a/lpbuildd/tests/harness.py
42+++ b/lpbuildd/tests/harness.py
43@@ -12,18 +12,18 @@ except ImportError:
44 import os
45 import shutil
46 import tempfile
47+from textwrap import dedent
48 import unittest
49
50-from fixtures import EnvironmentVariable
51+from fixtures import (
52+ EnvironmentVariable,
53+ TempDir,
54+ )
55 from txfixtures.tachandler import TacTestFixture
56
57 from lpbuildd.builder import Builder
58
59
60-test_conffile = os.path.join(
61- os.path.dirname(__file__), 'buildd-slave-test.conf')
62-
63-
64 class MockBuildManager:
65 """Mock BuildManager class.
66
67@@ -42,7 +42,8 @@ class BuilddTestCase(unittest.TestCase):
68 def setUp(self):
69 """Setup a Builder using the test config."""
70 conf = SafeConfigParser()
71- conf.read(test_conffile)
72+ conf.add_section("builder")
73+ conf.set("builder", "architecturetag", "i386")
74 conf.set("builder", "filecache", tempfile.mkdtemp())
75
76 self.builder = Builder(conf)
77@@ -106,6 +107,8 @@ class BuilddTestSetup(TacTestFixture):
78 >>> fixture.tearDown()
79 """
80
81+ _root = None
82+
83 def setUp(self, **kwargs):
84 # TacTestFixture defaults to /usr/bin/twistd, but on Ubuntu the
85 # Python 3 version of this is /usr/bin/twistd3, so that makes for a
86@@ -115,23 +118,30 @@ class BuilddTestSetup(TacTestFixture):
87 super().setUp(**kwargs)
88
89 def setUpRoot(self):
90- """Recreate empty root directory to avoid problems."""
91- if os.path.exists(self.root):
92- shutil.rmtree(self.root)
93- os.mkdir(self.root)
94 filecache = os.path.join(self.root, 'filecache')
95 os.mkdir(filecache)
96 self.useFixture(EnvironmentVariable('HOME', self.root))
97+ test_conffile = os.path.join(self.root, "buildd.conf")
98+ with open(test_conffile, "w") as f:
99+ f.write(dedent(f"""\
100+ [builder]
101+ architecturetag = i386
102+ filecache = {filecache}
103+ bindhost = localhost
104+ bindport = {self.daemon_port}
105+ sharepath = {self.root}
106+ """))
107 self.useFixture(EnvironmentVariable('BUILDD_CONFIG', test_conffile))
108 # XXX cprov 2005-05-30:
109 # When we are about running it seriously we need :
110 # * install sbuild package
111 # * to copy the scripts for sbuild
112- self.addCleanup(shutil.rmtree, self.root)
113
114 @property
115 def root(self):
116- return '/var/tmp/buildd'
117+ if self._root is None:
118+ self._root = self.useFixture(TempDir()).path
119+ return self._root
120
121 @property
122 def tacfile(self):
123@@ -151,5 +161,4 @@ class BuilddTestSetup(TacTestFixture):
124
125 @property
126 def daemon_port(self):
127- # This must match buildd-slave-test.conf.
128 return 8321

Subscribers

People subscribed via source and target branches