← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~twom/launchpad:oci-show-cancelled-builds-correctly into launchpad:master

 

Tom Wardill has proposed merging ~twom/launchpad:oci-show-cancelled-builds-correctly into launchpad:master.

Commit message:
Show cancelled builds as failed in the buildset

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~twom/launchpad/+git/launchpad/+merge/407035
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~twom/launchpad:oci-show-cancelled-builds-correctly into launchpad:master.
diff --git a/lib/lp/oci/browser/tests/test_ocirecipe.py b/lib/lp/oci/browser/tests/test_ocirecipe.py
index 913b849..408c032 100644
--- a/lib/lp/oci/browser/tests/test_ocirecipe.py
+++ b/lib/lp/oci/browser/tests/test_ocirecipe.py
@@ -1364,6 +1364,84 @@ class TestOCIRecipeView(BaseTestOCIRecipeView):
             "This OCI recipe contains Public information",
             extract_text(privacy_tag))
 
+    def test_index_cancelled_build(self):
+        oci_project = self.factory.makeOCIProject(
+            pillar=self.distroseries.distribution)
+        oci_project_display = oci_project.display_name
+        [ref] = self.factory.makeGitRefs(
+            owner=self.person, target=self.person, name="recipe-repository",
+            paths=["refs/heads/v1.0-20.04"])
+        recipe = self.makeRecipe(
+            processor_names=["amd64", "386"],
+            build_file="Dockerfile", git_ref=ref,
+            oci_project=oci_project, registrant=self.person, owner=self.person)
+        build_request = recipe.requestBuilds(self.person)
+        builds = recipe.requestBuildsFromJob(self.person, build_request)
+        job = removeSecurityProxy(build_request).job
+        removeSecurityProxy(job).builds = builds
+
+        for build in builds:
+            removeSecurityProxy(build).updateStatus(
+                    BuildStatus.BUILDING, builder=None,
+                    date_started=build.date_created)
+            removeSecurityProxy(build).updateStatus(
+                BuildStatus.CANCELLED, builder=None,
+                date_finished=build.date_started + timedelta(minutes=30))
+
+        # We also need to account for builds that don't have a build_request
+        build = self.makeBuild(
+            recipe=recipe, status=BuildStatus.FULLYBUILT,
+            duration=timedelta(minutes=30))
+
+        browser = self.getViewBrowser(build_request.recipe)
+        login_person(self.person)
+        self.assertTextMatchesExpressionIgnoreWhitespace("""\
+            .*
+            OCI recipe information
+            Owner: Test Person
+            OCI project: %s
+            Source: ~test-person/\\+git/recipe-repository:v1.0-20.04
+            Build file path: Dockerfile
+            Build context directory: %s
+            Build schedule: Built on request
+            Official recipe:
+            No
+            Latest builds
+            Build status
+            Upload status
+            When requested
+            When complete
+            There were build failures.
+            No registry upload requested.
+            a moment ago
+            in 29 minutes
+            amd64
+            Cancelled build
+            386
+            Cancelled build
+            amd64
+            in 29 minutes
+            386
+            in 29 minutes
+            All builds were built successfully.
+            No registry upload requested.
+            1 hour ago
+            30 minutes ago
+            386
+            Successfully built
+            386
+            30 minutes ago
+            Recipe push rules
+            This OCI recipe has no push rules defined yet.
+            """ % (oci_project_display, recipe.build_path),
+            extract_text(find_main_content(browser.contents)))
+
+        # Check portlet on side menu.
+        privacy_tag = find_tag_by_id(browser.contents, "privacy")
+        self.assertTextMatchesExpressionIgnoreWhitespace(
+            "This OCI recipe contains Public information",
+            extract_text(privacy_tag))
+
     def test_index_for_private_recipe_shows_banner(self):
         recipe = self.factory.makeOCIRecipe(
             registrant=self.person, owner=self.person,
diff --git a/lib/lp/oci/model/ocirecipe.py b/lib/lp/oci/model/ocirecipe.py
index adab5b9..5e491a7 100644
--- a/lib/lp/oci/model/ocirecipe.py
+++ b/lib/lp/oci/model/ocirecipe.py
@@ -972,6 +972,7 @@ class OCIRecipeSet:
         building = collect_builds(BuildStatus.BUILDING,
                                   BuildStatus.UPLOADING)
         successful = collect_builds(BuildStatus.FULLYBUILT)
+        cancelled = collect_builds(BuildStatus.CANCELLED)
 
         # Note: the BuildStatus DBItems are used here to summarize the
         # status of a set of builds:s
@@ -987,7 +988,7 @@ class OCIRecipeSet:
                 'status': BuildSetStatus.NEEDSBUILD,
                 'builds': needsbuild,
                 }
-        elif len(failed) != 0:
+        elif len(failed) != 0 or len(cancelled) != 0:
             return {
                 'status': BuildSetStatus.FAILEDTOBUILD,
                 'builds': failed,