← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~matiasb/launchpad-buildd/add-build-request-id into lp:launchpad-buildd

 

Matias Bordese has proposed merging lp:~matiasb/launchpad-buildd/add-build-request-id into lp:launchpad-buildd.

Commit message:
Add build_request_id to SNAPCRAFT_IMAGE_INFO if provided.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~matiasb/launchpad-buildd/add-build-request-id/+merge/366458
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~matiasb/launchpad-buildd/add-build-request-id into lp:launchpad-buildd.
=== modified file 'lpbuildd/target/build_snap.py'
--- lpbuildd/target/build_snap.py	2019-03-06 22:45:38 +0000
+++ lpbuildd/target/build_snap.py	2019-04-24 13:26:33 +0000
@@ -63,6 +63,9 @@
                 "(supported snaps: {}, snapcraft)".format(
                     ", ".join(cls.core_snap_names))))
         parser.add_argument(
+            "--build-request-id",
+            help="ID of the request triggering this build on Launchpad")
+        parser.add_argument(
             "--build-url", help="URL of this build on Launchpad")
         parser.add_argument("--proxy-url", help="builder proxy url")
         parser.add_argument(
@@ -194,7 +197,9 @@
 
     @property
     def image_info(self):
-        data = {}
+        data = OrderedDict()
+        if self.args.build_request_id is not None:
+            data["build_request_id"] = self.args.build_request_id
         if self.args.build_url is not None:
             data["build_url"] = self.args.build_url
         return json.dumps(data)

=== modified file 'lpbuildd/target/tests/test_build_snap.py'
--- lpbuildd/target/tests/test_build_snap.py	2019-03-12 16:09:00 +0000
+++ lpbuildd/target/tests/test_build_snap.py	2019-04-24 13:26:33 +0000
@@ -448,6 +448,22 @@
                 SNAPCRAFT_IMAGE_INFO="{}", SNAPCRAFT_BUILD_ENVIRONMENT="host"),
             ]))
 
+    def test_build_including_build_request_id(self):
+        args = [
+            "buildsnap",
+            "--backend=fake", "--series=xenial", "--arch=amd64", "1",
+            "--build-request-id", "13", "--branch", "lp:foo", "test-snap",
+            ]
+        build_snap = parse_args(args=args).operation
+        build_snap.build()
+        self.assertThat(build_snap.backend.run.calls, MatchesListwise([
+            RanBuildCommand(
+                ["snapcraft"], cwd="/build/test-snap",
+                SNAPCRAFT_BUILD_INFO="1",
+                SNAPCRAFT_IMAGE_INFO='{"build_request_id": "13"}',
+                SNAPCRAFT_BUILD_ENVIRONMENT="host"),
+            ]))
+
     # XXX cjwatson 2017-08-07: Test revoke_token.  It may be easiest to
     # convert it to requests first.
 
@@ -455,6 +471,7 @@
         args = [
             "buildsnap",
             "--backend=fake", "--series=xenial", "--arch=amd64", "1",
+            "--build-request-id", "13",
             "--build-url", "https://launchpad.example/build";,
             "--branch", "lp:foo", "test-snap",
             ]
@@ -471,13 +488,15 @@
                 SNAPCRAFT_LOCAL_SOURCES="1", SNAPCRAFT_SETUP_CORE="1",
                 SNAPCRAFT_BUILD_INFO="1",
                 SNAPCRAFT_IMAGE_INFO=(
-                    '{"build_url": "https://launchpad.example/build"}'),
+                    '{"build_request_id": "13",'
+                    ' "build_url": "https://launchpad.example/build"}'),
                 SNAPCRAFT_BUILD_ENVIRONMENT="host")),
             AnyMatch(RanBuildCommand(
                 ["snapcraft"], cwd="/build/test-snap",
                 SNAPCRAFT_BUILD_INFO="1",
                 SNAPCRAFT_IMAGE_INFO=(
-                    '{"build_url": "https://launchpad.example/build"}'),
+                    '{"build_request_id": "13",'
+                    ' "build_url": "https://launchpad.example/build"}'),
                 SNAPCRAFT_BUILD_ENVIRONMENT="host")),
             ))