← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~pelpsi/launchpad-buildd:deb822-extend-supported-options into launchpad-buildd:master

 

Simone Pelosi has proposed merging ~pelpsi/launchpad-buildd:deb822-extend-supported-options into launchpad-buildd:master.

Commit message:
Extend the supported deb options
    
There was a regression due the unsopported Trusted option.


Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~pelpsi/launchpad-buildd/+git/launchpad-buildd/+merge/474613
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~pelpsi/launchpad-buildd:deb822-extend-supported-options into launchpad-buildd:master.
diff --git a/lpbuildd/target/apt.py b/lpbuildd/target/apt.py
index 82d7294..c65687d 100644
--- a/lpbuildd/target/apt.py
+++ b/lpbuildd/target/apt.py
@@ -3,10 +3,10 @@
 
 import logging
 import os
+import re
 import subprocess
 import sys
 import time
-import re
 from textwrap import dedent
 
 from lpbuildd.target.operation import Operation
@@ -15,63 +15,68 @@ logger = logging.getLogger(__name__)
 
 
 def split_options(raw):
-    table = str.maketrans({
-        "[": None,
-        "]": None
-    })
-    options = raw.translate(table).split(' ')
+    table = str.maketrans({"[": None, "]": None})
+    options = raw.translate(table).split(" ")
 
     return options
 
 
 def prepare_source(line):
     pattern = re.compile(
-        r'^(?: *(?P<type>deb|deb-src)) +'
-        r'(?P<options>\[.+\] ?)*'
-        r'(?P<uri>\w+:\/\/\S+) +'
-        r'(?P<suite>\S+)'
-        r'(?: +(?P<components>.*))?$'
+        r"^(?: *(?P<type>deb|deb-src)) +"
+        r"(?P<options>\[.+\] ?)*"
+        r"(?P<uri>\w+:\/\/\S+) +"
+        r"(?P<suite>\S+)"
+        r"(?: +(?P<components>.*))?$"
     )
+
+    old_to_deb822 = {
+        "arch": "Architectures",
+        "singned-by": "Signed-By",
+        "lang": "Languages",
+        "target": "Targets",
+        "trusted": "Trusted",
+        "by-hash": "By-Hash",
+        "pdiffs": "PDiffs",
+        "allow-insecure": "Allow-Insecure",
+        "allow-weak": "Allow-Weak",
+        "allow-downgrade-to-insecure": "Allow-Downgrade-To-Insecure",
+        "snapshot": "Snapshot",
+        "inrelease-path": "InRelease-Path",
+        "check-valid-until": "Check-Valid-Until",
+        "valid-until-min": "Valid-Until-Min",
+        "valid-until-max": "Valid-Until-Max",
+        "check-date": "Check-Date",
+        "date-max-future": "Date-Max-Future",
+    }
+
     matches = re.match(pattern, line)
     source = {}
     if matches is not None:
         options = {}
-        if matches.group('options'):
-            for option in split_options(matches['options']):
+        if matches.group("options"):
+            for option in split_options(matches["options"]):
                 if "=" in option:
                     key, value = option.split("=")
                     options[key] = value
         source = {
-            "Types": {matches['type']},
-            "URIs": matches['uri'],
+            "Types": {matches["type"]},
+            "URIs": matches["uri"],
             "Enabled": "yes",
         }
-        if matches.group('suite'):
-            source["Suites"] = set(matches['suite'].split(' '))
-        if matches.group('components'):
-            source["Components"] = set(
-                matches['components'].split(' ')
-            )
-        if "arch" in options:
-            if "Architectures" in source:
-                source["Architectures"].append(options["arch"])
-            else:
-                source["Architectures"] = {options["arch"]}
-        if "signed-by" in options:
-            if "Signed-by" in source:
-                source["Signed-by"].append(options["signed-by"])
-            else:
-                source["Signed-by"] = {options["signed-by"]}
-        if "lang" in options:
-            if "Languages" in source:
-                source["Languages"].append(options["lang"])
-            else:
-                source["Languages"] = {options["lang"]}
-        if "target" in options:
-            if "Targets" in source:
-                source["Targets"].append(options["target"])
+        if matches.group("suite"):
+            source["Suites"] = set(matches["suite"].split(" "))
+        if matches.group("components"):
+            source["Components"] = set(matches["components"].split(" "))
+        for key in options.keys():
+            if key in old_to_deb822:
+                if old_to_deb822[key] in source:
+                    source[old_to_deb822[key]].append(options[key])
+                else:
+                    source[old_to_deb822[key]] = {options[key]}
             else:
-                source["Targets"] = {options["target"]}
+                # reject the source
+                return {}
     return source
 
 
@@ -93,7 +98,11 @@ class OverrideSourcesList(Operation):
         # If the ubuntu version is < 24.04 then use the old one line format
         # for backward compatibility.
         if self.backend.series in [
-            "trusty", "xenial", "bionic", "focal", "jammy"
+            "trusty",
+            "xenial",
+            "bionic",
+            "focal",
+            "jammy",
         ]:
             with self.backend.open(
                 "/etc/apt/sources.list", mode="w+"
@@ -117,10 +126,10 @@ class OverrideSourcesList(Operation):
                         continue
                     for key, value in source.items():
                         if isinstance(value, str):
-                            sources_list.write("{}: {}\n".format(key, value))
+                            sources_list.write(f"{key}: {value}\n")
                         else:
                             sources_list.write(
-                                "{}: {}\n".format(key, ' '.join(value))
+                                "{}: {}\n".format(key, " ".join(value))
                             )
                     sources_list.write("\n")
                 os.fchmod(sources_list.fileno(), 0o644)
diff --git a/lpbuildd/target/tests/test_apt.py b/lpbuildd/target/tests/test_apt.py
index b358166..fca65cb 100644
--- a/lpbuildd/target/tests/test_apt.py
+++ b/lpbuildd/target/tests/test_apt.py
@@ -8,7 +8,6 @@ import time
 from textwrap import dedent
 
 from fixtures import FakeLogger
-
 from systemfixtures import FakeTime
 from testtools import TestCase
 from testtools.matchers import (
@@ -21,11 +20,8 @@ from testtools.matchers import (
 )
 
 from lpbuildd.target.cli import parse_args
+from lpbuildd.target.tests.matchers import RanAptGet, RanCommand
 from lpbuildd.tests.fakebuilder import FakeMethod
-from lpbuildd.target.tests.matchers import (
-    RanAptGet,
-    RanCommand,
-)
 
 
 class MockCopyIn(FakeMethod):
@@ -106,8 +102,8 @@ class TestOverrideSourcesList(TestCase):
             "--series=oracular",
             "--arch=amd64",
             "1",
-            "deb http://archive.ubuntu.com/ubuntu oracular main",
-            "deb http://ppa.launchpad.net/launchpad/ppa/ubuntu oracular main"
+            "deb [trusted=yes] http://archive.ubuntu.com/ubuntu oracular main",
+            "deb [ arch=amd64,armel lang=en_US,en_CA ] http://ppa.launchpad.net/launchpad/ppa/ubuntu oracular main",  # noqa: E501
         ]
         override_sources_list = parse_args(args=args).operation
         self.assertEqual(0, override_sources_list.run())
@@ -120,12 +116,15 @@ class TestOverrideSourcesList(TestCase):
                     Enabled: yes
                     Suites: oracular
                     Components: main
+                    Trusted: yes
 
                     Types: deb
                     URIs: http://ppa.launchpad.net/launchpad/ppa/ubuntu
                     Enabled: yes
                     Suites: oracular
                     Components: main
+                    Architectures: amd64,armel
+                    Languages: en_US,en_CA
 
                 """
                 ).encode("UTF-8"),
@@ -138,17 +137,17 @@ class TestOverrideSourcesList(TestCase):
         self.assertThat(
             override_sources_list.backend.run.calls,
             MatchesAll(
-                AnyMatch(RanCommand(
-                    ["rm", "-f", "/etc/apt/sources.list.d/ubuntu.sources"]
-                )),
+                AnyMatch(
+                    RanCommand(
+                        ["rm", "-f", "/etc/apt/sources.list.d/ubuntu.sources"]
+                    )
+                ),
             ),
         )
         self.assertThat(
             override_sources_list.backend.run.calls,
             MatchesAll(
-                AnyMatch(RanCommand(
-                    ["rm", "-f", "/etc/apt/sources.list"]
-                )),
+                AnyMatch(RanCommand(["rm", "-f", "/etc/apt/sources.list"])),
             ),
         )
 
@@ -160,13 +159,15 @@ class TestOverrideSourcesList(TestCase):
             "--arch=amd64",
             "1",
             "bad-source.com",
+            "deb [reject=yes] http://archive.ubuntu.com/ubuntu oracular main",
         ]
         logger = self.useFixture(FakeLogger())
         override_sources_list = parse_args(args=args).operation
         self.assertEqual(0, override_sources_list.run())
         self.assertEqual(
             "Overriding sources.list in build-1\n"
-            "Error parsing source: bad-source.com\n",
+            "Error parsing source: bad-source.com\n"
+            "Error parsing source: deb [reject=yes] http://archive.ubuntu.com/ubuntu oracular main\n",  # noqa: E501
             logger.output,
         )
 
@@ -308,7 +309,7 @@ class TestAddTrustedKeys(TestCase):
                 )
 
 
-class RanAptGet(MatchesListwise):
+class RanAptGet(MatchesListwise):  # noqa: F811
     def __init__(self, args_list):
         super().__init__(
             [

Follow ups