launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #25418
[Merge] ~pappacena/launchpad:oci-fill-build-request into launchpad:master
Thiago F. Pappacena has proposed merging ~pappacena/launchpad:oci-fill-build-request into launchpad:master.
Commit message:
Setting a build request object on every OCI build created using the web interface
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~pappacena/launchpad/+git/launchpad/+merge/391574
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~pappacena/launchpad:oci-fill-build-request into launchpad:master.
diff --git a/lib/lp/oci/browser/ocirecipe.py b/lib/lp/oci/browser/ocirecipe.py
index 594b93d..6174f99 100644
--- a/lib/lp/oci/browser/ocirecipe.py
+++ b/lib/lp/oci/browser/ocirecipe.py
@@ -645,9 +645,11 @@ class OCIRecipeRequestBuildsView(LaunchpadFormView):
informational = {}
builds = []
already_pending = []
+ build_request = self.context.createBuildRequest(self.user)
for arch in data['distro_arch_series']:
try:
- build = self.context.requestBuild(self.user, arch)
+ build = self.context.requestBuild(
+ self.user, arch, build_request=build_request)
builds.append(build)
except OCIRecipeBuildAlreadyPending:
already_pending.append(arch)
diff --git a/lib/lp/oci/browser/tests/test_ocirecipe.py b/lib/lp/oci/browser/tests/test_ocirecipe.py
index c854d14..442021e 100644
--- a/lib/lp/oci/browser/tests/test_ocirecipe.py
+++ b/lib/lp/oci/browser/tests/test_ocirecipe.py
@@ -22,8 +22,10 @@ import soupmatchers
from storm.locals import Store
from testtools.matchers import (
Equals,
+ GreaterThan,
Is,
MatchesDict,
+ MatchesListwise,
MatchesSetwise,
MatchesStructure,
)
@@ -851,6 +853,12 @@ class TestOCIRecipeRequestBuildsView(BaseTestOCIRecipeView):
[build.distro_arch_series.architecturetag for build in builds])
self.assertContentEqual(
[2510], set(build.buildqueue_record.lastscore for build in builds))
+ # All builds should have the same build request.
+ self.assertThat([i.build_request for i in builds], MatchesListwise([
+ MatchesStructure(id=GreaterThan(0)),
+ MatchesStructure(id=GreaterThan(0)),
+ ]))
+ self.assertEqual(1, len({i.build_request.id for i in builds}))
def test_request_builds_rejects_duplicate(self):
# A duplicate build request causes a notification.
diff --git a/lib/lp/oci/interfaces/ocirecipe.py b/lib/lp/oci/interfaces/ocirecipe.py
index 9beb6af..687e932 100644
--- a/lib/lp/oci/interfaces/ocirecipe.py
+++ b/lib/lp/oci/interfaces/ocirecipe.py
@@ -262,6 +262,14 @@ class IOCIRecipeView(Interface):
"Whether everything is set up to allow uploading builds of "
"this OCI recipe to a registry."))
+ def createBuildRequest(self, requester):
+ """Creates a new BuildRequest object that will not be run, but can be
+ associated with build requests.
+
+ :param requester: The person requesting the build.
+ :return: `IOCIRecipeBuildRequest`.
+ """
+
def requestBuild(requester, architecture):
"""Request that the OCI recipe is built.
diff --git a/lib/lp/oci/model/ocirecipe.py b/lib/lp/oci/model/ocirecipe.py
index c167b15..3448982 100644
--- a/lib/lp/oci/model/ocirecipe.py
+++ b/lib/lp/oci/model/ocirecipe.py
@@ -405,6 +405,15 @@ class OCIRecipe(Storm, WebhookTargetMixin):
def getBuildRequest(self, job_id):
return OCIRecipeBuildRequest(self, job_id)
+ def createBuildRequest(self, requester):
+ """See `IOCIRecipe`."""
+ self._checkRequestBuild(requester)
+ job = getUtility(IOCIRecipeRequestBuildsJobSource).create(
+ self, requester, run_on_commit=False)
+ job.start()
+ job.complete()
+ return self.getBuildRequest(job.job_id)
+
def requestBuildsFromJob(self, requester, build_request=None):
self._checkRequestBuild(requester)
distro_arch_series_to_build = set(self.getAllowedArchitectures())
diff --git a/lib/lp/oci/model/ocirecipejob.py b/lib/lp/oci/model/ocirecipejob.py
index 095181e..ca501d5 100644
--- a/lib/lp/oci/model/ocirecipejob.py
+++ b/lib/lp/oci/model/ocirecipejob.py
@@ -162,12 +162,13 @@ class OCIRecipeRequestBuildsJob(OCIRecipeJobDerived):
config = config.IOCIRecipeRequestBuildsJobSource
@classmethod
- def create(cls, recipe, requester):
+ def create(cls, recipe, requester, run_on_commit=True):
"""See `OCIRecipeRequestBuildsJob`."""
metadata = {"requester": requester.id}
recipe_job = OCIRecipeJob(recipe, cls.class_job_type, metadata)
job = cls(recipe_job)
- job.celeryRunOnCommit()
+ if run_on_commit:
+ job.celeryRunOnCommit()
return job
@classmethod