← Back to team overview

launchpad-reviewers team mailing list archive

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

 

Colin Watson has proposed merging ~cjwatson/launchpad-buildd:dynamic-test-config into launchpad-buildd:master.

Commit message:
Dynamically generate configuration file in lpbuildd.tests.harness

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad-buildd/+git/launchpad-buildd/+merge/419964

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.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad-buildd:dynamic-test-config into launchpad-buildd:master.
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
 include sbuildrc
 include template-buildd-slave.conf
 include lpbuildd/buildd-slave.tac
-recursive-include lpbuildd/tests *.diff *.tar.gz buildd-slave-test.conf buildlog buildlog.long
+recursive-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 @@
+launchpad-buildd (213) UNRELEASED; urgency=medium
+
+  * Dynamically generate configuration file in lpbuildd.tests.harness.
+
+ -- Colin Watson <cjwatson@xxxxxxxxxx>  Wed, 20 Apr 2022 16:03:01 +0100
+
 launchpad-buildd (212) focal; urgency=medium
 
   * 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
deleted file mode 100644
index 34fd47d..0000000
--- a/lpbuildd/tests/buildd-slave-test.conf
+++ /dev/null
@@ -1,8 +0,0 @@
-# Test buildd configuration
-
-[builder]
-architecturetag = i386
-filecache = /var/tmp/buildd/filecache
-bindhost = localhost
-bindport = 8321
-sharepath = /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:
 import os
 import shutil
 import tempfile
+from textwrap import dedent
 import unittest
 
-from fixtures import EnvironmentVariable
+from fixtures import (
+    EnvironmentVariable,
+    TempDir,
+    )
 from txfixtures.tachandler import TacTestFixture
 
 from lpbuildd.builder import Builder
 
 
-test_conffile = os.path.join(
-    os.path.dirname(__file__), 'buildd-slave-test.conf')
-
-
 class MockBuildManager:
     """Mock BuildManager class.
 
@@ -42,7 +42,8 @@ class BuilddTestCase(unittest.TestCase):
     def setUp(self):
         """Setup a Builder using the test config."""
         conf = SafeConfigParser()
-        conf.read(test_conffile)
+        conf.add_section("builder")
+        conf.set("builder", "architecturetag", "i386")
         conf.set("builder", "filecache", tempfile.mkdtemp())
 
         self.builder = Builder(conf)
@@ -106,6 +107,8 @@ class BuilddTestSetup(TacTestFixture):
     >>> fixture.tearDown()
     """
 
+    _root = None
+
     def setUp(self, **kwargs):
         # TacTestFixture defaults to /usr/bin/twistd, but on Ubuntu the
         # Python 3 version of this is /usr/bin/twistd3, so that makes for a
@@ -115,23 +118,30 @@ class BuilddTestSetup(TacTestFixture):
         super().setUp(**kwargs)
 
     def setUpRoot(self):
-        """Recreate empty root directory to avoid problems."""
-        if os.path.exists(self.root):
-            shutil.rmtree(self.root)
-        os.mkdir(self.root)
         filecache = os.path.join(self.root, 'filecache')
         os.mkdir(filecache)
         self.useFixture(EnvironmentVariable('HOME', self.root))
+        test_conffile = os.path.join(self.root, "buildd.conf")
+        with open(test_conffile, "w") as f:
+            f.write(dedent(f"""\
+                [builder]
+                architecturetag = i386
+                filecache = {filecache}
+                bindhost = localhost
+                bindport = {self.daemon_port}
+                sharepath = {self.root}
+                """))
         self.useFixture(EnvironmentVariable('BUILDD_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(shutil.rmtree, self.root)
 
     @property
     def root(self):
-        return '/var/tmp/buildd'
+        if self._root is None:
+            self._root = self.useFixture(TempDir()).path
+        return self._root
 
     @property
     def tacfile(self):
@@ -151,5 +161,4 @@ class BuilddTestSetup(TacTestFixture):
 
     @property
     def daemon_port(self):
-        # This must match buildd-slave-test.conf.
         return 8321