Merge ~jugmac00/launchpad:expose-build-metadata-via-api into launchpad:master

Proposed by Jürgen Gmach
Status: Rejected
Rejected by: Ines Almeida
Proposed branch: ~jugmac00/launchpad:expose-build-metadata-via-api
Merge into: launchpad:master
Diff against target: 72 lines (+32/-0)
3 files modified
lib/lp/snappy/interfaces/snapbuild.py (+9/-0)
lib/lp/snappy/model/snapbuild.py (+7/-0)
lib/lp/snappy/tests/test_snapbuild.py (+16/-0)
Reviewer Review Type Date Requested Status
Launchpad code reviewers Pending
Review via email: mp+464639@code.launchpad.net

Commit message

Expose the URL to download the metadata file of the fetch service via API

To post a comment you must log in.
Revision history for this message
Ines Almeida (ines-almeida) wrote :

I know this isn't tested, but just a initial review!

Revision history for this message
Simone Pelosi (pelpsi) wrote :

I just add there what we found during the peer programming session :)

Revision history for this message
Jürgen Gmach (jugmac00) wrote :

I updated the code - unfortunately once again without being able to run the tests.

It is impossible to apply any meaningful changes without a working test environment.

So we either need to merge this as is (after somebody has checked it out and ran the tests) and apply some changes later on (as adding more tests, refactor to an attribute), or somebody needs to pull these changes, use a cherry pick for the commit, and create a new merge proposal, so we have this merged today.

Revision history for this message
Ines Almeida (ines-almeida) :
Revision history for this message
Ines Almeida (ines-almeida) wrote :

Unmerged commits

4261543... by Jürgen Gmach

Expose the URL to download the metadata file of the fetch service via API

Succeeded
[SUCCEEDED] docs:0 (build)
[SUCCEEDED] lint:0 (build)
[SUCCEEDED] mypy:0 (build)
13 of 3 results

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/snappy/interfaces/snapbuild.py b/lib/lp/snappy/interfaces/snapbuild.py
2index 52019bf..fea9d5f 100644
3--- a/lib/lp/snappy/interfaces/snapbuild.py
4+++ b/lib/lp/snappy/interfaces/snapbuild.py
5@@ -17,6 +17,7 @@ import http.client
6 from lazr.enum import EnumeratedType, Item
7 from lazr.restful.declarations import (
8 error_status,
9+ export_operation_as,
10 export_read_operation,
11 export_write_operation,
12 exported,
13@@ -370,6 +371,14 @@ class ISnapBuildView(IPackageBuildView, IPrivacy):
14
15 :return: A collection of URLs for this build."""
16
17+ @export_operation_as("build_metadata_url")
18+ @export_read_operation()
19+ @operation_for_version("devel")
20+ def getBuildMetadataUrl():
21+ """URL of the metadata file generated by the fetch service
22+
23+ :return: URL of the metadata if present."""
24+
25
26 class ISnapBuildEdit(IBuildFarmJobEdit):
27 """`ISnapBuild` attributes that require launchpad.Edit."""
28diff --git a/lib/lp/snappy/model/snapbuild.py b/lib/lp/snappy/model/snapbuild.py
29index df2e2c2..2f2bbcc 100644
30--- a/lib/lp/snappy/model/snapbuild.py
31+++ b/lib/lp/snappy/model/snapbuild.py
32@@ -425,6 +425,13 @@ class SnapBuild(PackageBuildMixin, StormBase):
33 def getFileUrls(self):
34 return [self.lfaUrl(lfa) for _, lfa, _ in self.getFiles()]
35
36+ def getBuildMetadataUrl(self):
37+ for url in self.getFileUrls():
38+ # XXX jugmac00 2024-04-19: reference the place there the file
39+ # naming is specified
40+ if url.endswith("metadata.json"):
41+ return url
42+
43 @cachedproperty
44 def eta(self):
45 """The datetime when the build job is estimated to complete.
46diff --git a/lib/lp/snappy/tests/test_snapbuild.py b/lib/lp/snappy/tests/test_snapbuild.py
47index d8b7758..2a45683 100644
48--- a/lib/lp/snappy/tests/test_snapbuild.py
49+++ b/lib/lp/snappy/tests/test_snapbuild.py
50@@ -1009,6 +1009,22 @@ class TestSnapBuildWebservice(TestCaseWithFactory):
51 for file_url in file_urls:
52 self.assertCanOpenRedirectedUrl(browser, file_url)
53
54+ def test_getBuildMetadataUrl(self):
55+ # API clients can fetch the metadata from the build, generated by the
56+ # fetch service
57+ db_build = self.factory.makeSnapBuild(requester=self.person)
58+ with person_logged_in(self.person):
59+ metadata_file = self.factory.makeLibraryFileAlias(
60+ content="some_json",
61+ filename="xxx_metadata.json",
62+ )
63+ db_build.addFile(metadata_file)
64+
65+ build_url = api_url(db_build)
66+ logout()
67+ response = self.webservice.named_get(build_url, "build_metadata_url")
68+ self.assertEndsWith(response.jsonBody(), "metadata.json")
69+
70
71 class TestSnapBuildMacaroonIssuer(MacaroonTestMixin, TestCaseWithFactory):
72 """Test SnapBuild macaroon issuing and verification."""

Subscribers

People subscribed via source and target branches

to status/vote changes: