← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~pappacena/launchpad:export-oci-recipe-build into launchpad:master

 

Thiago F. Pappacena has proposed merging ~pappacena/launchpad:export-oci-recipe-build into launchpad:master.

Commit message:
Exporting OCIRecipeBuild on webservice, and also on IOCIRecipeBuildRequest.builds.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~pappacena/launchpad/+git/launchpad/+merge/383032
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~pappacena/launchpad:export-oci-recipe-build into launchpad:master.
diff --git a/lib/lp/oci/interfaces/ocirecipe.py b/lib/lp/oci/interfaces/ocirecipe.py
index ea14d04..c469886 100644
--- a/lib/lp/oci/interfaces/ocirecipe.py
+++ b/lib/lp/oci/interfaces/ocirecipe.py
@@ -164,11 +164,11 @@ class IOCIRecipeBuildRequest(Interface):
     error_message = exported(TextLine(
         title=_("Error message"), required=False, readonly=True))
 
-    builds = CollectionField(
+    builds = exported(CollectionField(
         title=_("Builds produced by this request"),
         # Really IOCIRecipeBuild, patched in lp.oci.interfaces.webservice.
         value_type=Reference(schema=Interface),
-        required=True, readonly=True)
+        required=True, readonly=True))
 
 
 class IOCIRecipeView(Interface):
diff --git a/lib/lp/oci/interfaces/ocirecipebuild.py b/lib/lp/oci/interfaces/ocirecipebuild.py
index a1fbfc0..7520458 100644
--- a/lib/lp/oci/interfaces/ocirecipebuild.py
+++ b/lib/lp/oci/interfaces/ocirecipebuild.py
@@ -17,6 +17,10 @@ from lazr.enum import (
     EnumeratedType,
     Item,
     )
+from lazr.restful.declarations import (
+    export_as_webservice_entry,
+    exported,
+    )
 from lazr.restful.fields import (
     CollectionField,
     Reference,
@@ -89,17 +93,17 @@ class IOCIRecipeBuildView(IPackageBuild):
         required=True,
         readonly=True)
 
-    eta = Datetime(
+    eta = exported(Datetime(
         title=_("The datetime when the build job is estimated to complete."),
-        readonly=True)
+        readonly=True))
 
-    estimate = Bool(
-        title=_("If true, the date value is an estimate."), readonly=True)
+    estimate = exported(Bool(
+        title=_("If true, the date value is an estimate."), readonly=True))
 
-    date = Datetime(
+    date = exported(Datetime(
         title=_(
             "The date when the build completed or is estimated to complete."),
-        readonly=True)
+        readonly=True))
 
     def getFiles():
         """Retrieve the build's `IOCIFile` records.
@@ -127,10 +131,10 @@ class IOCIRecipeBuildView(IPackageBuild):
         :return: The corresponding `ILibraryFileAlias`.
         """
 
-    distro_arch_series = Reference(
+    distro_arch_series = exported(Reference(
         IDistroArchSeries,
         title=_("The series and architecture for which to build."),
-        required=True, readonly=True)
+        required=True, readonly=True))
 
     score = Int(
         title=_("Score of the related build farm job (if any)."),
@@ -160,11 +164,11 @@ class IOCIRecipeBuildView(IPackageBuild):
     last_registry_upload_job = Reference(
         title=_("Last registry upload job for this build."), schema=Interface)
 
-    registry_upload_status = Choice(
+    registry_upload_status = exported(Choice(
         title=_("Registry upload status"),
         vocabulary=OCIRecipeBuildRegistryUploadStatus,
         required=True, readonly=False
-    )
+    ))
 
 
 class IOCIRecipeBuildEdit(Interface):
@@ -203,6 +207,8 @@ class IOCIRecipeBuildAdmin(Interface):
 class IOCIRecipeBuild(IOCIRecipeBuildAdmin, IOCIRecipeBuildEdit,
                       IOCIRecipeBuildView):
     """A build record for an OCI recipe."""
+    export_as_webservice_entry(
+        publish_web_link=True, as_of="devel", singular_name="oci_recipe_build")
 
 
 class IOCIRecipeBuildSet(ISpecificBuildFarmJobSource):
diff --git a/lib/lp/oci/interfaces/webservice.py b/lib/lp/oci/interfaces/webservice.py
index 4db31e1..b337c70 100644
--- a/lib/lp/oci/interfaces/webservice.py
+++ b/lib/lp/oci/interfaces/webservice.py
@@ -8,6 +8,7 @@ __all__ = [
     'IOCIProjectSeries',
     'IOCIPushRule',
     'IOCIRecipe',
+    'IOCIRecipeBuild',
     'IOCIRecipeBuildRequest'
     ]
 
diff --git a/lib/lp/oci/tests/test_ocirecipe.py b/lib/lp/oci/tests/test_ocirecipe.py
index 42e854a..58a2b32 100644
--- a/lib/lp/oci/tests/test_ocirecipe.py
+++ b/lib/lp/oci/tests/test_ocirecipe.py
@@ -5,9 +5,11 @@
 
 from __future__ import absolute_import, print_function, unicode_literals
 
+from datetime import datetime
 import json
 
 from fixtures import FakeLogger
+from pytz import utc
 from six import (
     ensure_text,
     string_types,
@@ -16,6 +18,7 @@ from storm.exceptions import LostObjectError
 from testtools.matchers import (
     ContainsDict,
     Equals,
+    IsInstance,
     MatchesDict,
     MatchesSetwise,
     MatchesStructure,
@@ -977,4 +980,23 @@ class TestOCIRecipeAsyncWebservice(TestCaseWithFactory):
                 date_requested=Equals(fmt_date(build_request.date_requested)),
                 date_finished=Equals(fmt_date(build_request.date_finished)),
                 error_message=Equals(build_request.error_message),
+                builds_collection_link=Equals(build_request_url + '/builds')
             )))
+
+        # Checks the structure of OCI recipe build objects created.
+        builds = self.webservice.get(
+            ws_build_request["builds_collection_link"]).jsonBody()["entries"]
+        with person_logged_in(self.person):
+            self.assertThat(builds, MatchesSetwise(*[
+                ContainsDict({
+                    "buildstate": Equals("Needs building"),
+                    "eta": IsInstance(string_types, type(None)),
+                    "date": IsInstance(string_types, type(None)),
+                    "estimate": IsInstance(bool),
+                    "distro_arch_series_link": Equals(abs_url(arch_series)),
+                    "registry_upload_status": Equals("Unscheduled"),
+                    "title": Equals(
+                        "%s build of %s" % (
+                            arch_series.processor.name, api_url(oci_recipe)))
+                })
+                for arch_series in distro_arch_series]))
diff --git a/lib/lp/services/webservice/wadl-to-refhtml.xsl b/lib/lp/services/webservice/wadl-to-refhtml.xsl
index 3a4fc2f..86d8467 100644
--- a/lib/lp/services/webservice/wadl-to-refhtml.xsl
+++ b/lib/lp/services/webservice/wadl-to-refhtml.xsl
@@ -479,6 +479,18 @@
                 <xsl:text>/+recipe/</xsl:text>
                 <var>&lt;oci_recipe.name&gt;</var>
             </xsl:when>
+            <xsl:when test="@id = 'oci_recipe_build'">
+                <xsl:text>/~</xsl:text>
+                <var>&lt;person.name&gt;</var>
+                <xsl:text>/</xsl:text>
+                <var>&lt;distribution.name&gt;</var>
+                <xsl:text>/+oci/</xsl:text>
+                <var>&lt;oci_project.name&gt;</var>
+                <xsl:text>/+recipe/</xsl:text>
+                <var>&lt;oci_recipe.name&gt;</var>
+                <xsl:text>/+build/</xsl:text>
+                <var>&lt;oci_recipe_build.id&gt;</var>
+            </xsl:when>
             <xsl:when test="@id = 'oci_recipe_build_request'">
                 <xsl:text>/~</xsl:text>
                 <var>&lt;person.name&gt;</var>