← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad-buildd:apt-retries into launchpad-buildd:master

 

Colin Watson has proposed merging ~cjwatson/launchpad-buildd:apt-retries into launchpad-buildd:master.

Commit message:
Configure apt to automatically retry downloads on failures

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #1949473 in launchpad-buildd: "Tell apt to automatically retry download on failures"
  https://bugs.launchpad.net/launchpad-buildd/+bug/1949473

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

This helps with slightly flaky networking infrastructure.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad-buildd:apt-retries into launchpad-buildd:master.
diff --git a/debian/changelog b/debian/changelog
index 5c972b4..8c8872b 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+launchpad-buildd (204) UNRELEASED; urgency=medium
+
+  * Configure apt to automatically retry downloads on failures
+    (LP: #1949473).
+
+ -- Colin Watson <cjwatson@xxxxxxxxxx>  Tue, 02 Nov 2021 13:42:13 +0000
+
 launchpad-buildd (203) bionic; urgency=medium
 
   * Remove some more "slave" terminology from tests.
diff --git a/lpbuildd/target/apt.py b/lpbuildd/target/apt.py
index fc1827a..49b1650 100644
--- a/lpbuildd/target/apt.py
+++ b/lpbuildd/target/apt.py
@@ -39,6 +39,12 @@ class OverrideSourcesList(Operation):
             sources_list.flush()
             os.fchmod(sources_list.fileno(), 0o644)
             self.backend.copy_in(sources_list.name, "/etc/apt/sources.list")
+        with tempfile.NamedTemporaryFile(mode="w+") as apt_retries_conf:
+            print('Acquire::Retries "3";', file=apt_retries_conf)
+            apt_retries_conf.flush()
+            os.fchmod(apt_retries_conf.fileno(), 0o644)
+            self.backend.copy_in(
+                apt_retries_conf.name, "/etc/apt/apt.conf.d/99retries")
         if self.args.apt_proxy_url is not None:
             with tempfile.NamedTemporaryFile(mode="w+") as apt_proxy_conf:
                 print(
diff --git a/lpbuildd/target/tests/test_apt.py b/lpbuildd/target/tests/test_apt.py
index 2827d00..a946e38 100644
--- a/lpbuildd/target/tests/test_apt.py
+++ b/lpbuildd/target/tests/test_apt.py
@@ -52,6 +52,10 @@ class TestOverrideSourcesList(TestCase):
                 deb http://ppa.launchpad.net/launchpad/ppa/ubuntu xenial main
                 """).encode("UTF-8"), stat.S_IFREG | 0o644),
             override_sources_list.backend.backend_fs["/etc/apt/sources.list"])
+        self.assertEqual(
+            (b'Acquire::Retries "3";\n', stat.S_IFREG | 0o644),
+            override_sources_list.backend.backend_fs[
+                "/etc/apt/apt.conf.d/99retries"])
 
     def test_apt_proxy(self):
         args = [
@@ -68,6 +72,10 @@ class TestOverrideSourcesList(TestCase):
                 """).encode("UTF-8"), stat.S_IFREG | 0o644),
             override_sources_list.backend.backend_fs["/etc/apt/sources.list"])
         self.assertEqual(
+            (b'Acquire::Retries "3";\n', stat.S_IFREG | 0o644),
+            override_sources_list.backend.backend_fs[
+                "/etc/apt/apt.conf.d/99retries"])
+        self.assertEqual(
             (dedent("""\
                 Acquire::http::Proxy "http://apt-proxy.example:3128/";;
                 """).encode("UTF-8"), stat.S_IFREG | 0o644),