← Back to team overview

launchpad-reviewers team mailing list archive

Re: [Merge] ~pappacena/launchpad:oci-upload-prevent-superseded into launchpad:master

 

Pushed the requested changes.

Diff comments:

> diff --git a/lib/lp/oci/interfaces/ocirecipebuild.py b/lib/lp/oci/interfaces/ocirecipebuild.py
> index 3273271..f005e95 100644
> --- a/lib/lp/oci/interfaces/ocirecipebuild.py
> +++ b/lib/lp/oci/interfaces/ocirecipebuild.py
> @@ -94,6 +94,13 @@ class OCIRecipeBuildRegistryUploadStatus(EnumeratedType):
>          This OCI build was successfully uploaded to a registry.
>          """)
>  
> +    SUPERSEDED = Item("""
> +        Superseded
> +
> +        The upload has been canceled because another build will upload a

Ok!

> +        more recent version.
> +    """)
> +
>  
>  class IOCIRecipeBuildView(IPackageBuild):
>      """`IOCIRecipeBuild` attributes that require launchpad.View permission."""
> diff --git a/lib/lp/oci/model/ocirecipebuild.py b/lib/lp/oci/model/ocirecipebuild.py
> index eda6fa3..7c003bc 100644
> --- a/lib/lp/oci/model/ocirecipebuild.py
> +++ b/lib/lp/oci/model/ocirecipebuild.py
> @@ -479,6 +481,20 @@ class OCIRecipeBuild(PackageBuildMixin, Storm):
>                  "uploaded.")
>          getUtility(IOCIRegistryUploadJobSource).create(self)
>  
> +    def hasMoreRecentBuild(self):
> +        """See `IOCIRecipeBuild`."""
> +        status = [
> +            BuildStatus.NEEDSBUILD, BuildStatus.FULLYBUILT,
> +            BuildStatus.BUILDING, BuildStatus.UPLOADING

It makes sense. I'll filter for only FULLYBUILT here.

> +        ]
> +        recent_builds = IStore(self).find(
> +            OCIRecipeBuild,
> +            OCIRecipeBuild.recipe == self.recipe,
> +            OCIRecipeBuild.processor == self.processor,
> +            OCIRecipeBuild.status.is_in(status),
> +            OCIRecipeBuild.date_created > self.date_created)
> +        return not recent_builds.is_empty()
> +
>  
>  @implementer(IOCIRecipeBuildSet)
>  class OCIRecipeBuildSet(SpecificBuildFarmJobSourceMixin):
> diff --git a/lib/lp/oci/model/ociregistryclient.py b/lib/lp/oci/model/ociregistryclient.py
> index 2b920cd..2567006 100644
> --- a/lib/lp/oci/model/ociregistryclient.py
> +++ b/lib/lp/oci/model/ociregistryclient.py
> @@ -420,10 +423,30 @@ class OCIRegistryClient:
>          return current_manifest
>  
>      @classmethod
> +    def updateSupersededBuilds(cls, build):
> +        """Checks if the given build was superseded by another build,
> +        updating it's status in case it should have been superseded.

Ok!

> +
> +        :return: True if the build was superseded.
> +        """
> +        if build.status == BuildStatus.SUPERSEDED:
> +            return True
> +        if build.hasMoreRecentBuild():
> +            build.updateStatus(BuildStatus.SUPERSEDED)
> +            return True
> +        return False
> +
> +    @classmethod
>      def uploadManifestList(cls, build_request, uploaded_builds):
>          """Uploads to all build_request.recipe.push_rules the manifest list
>          for the builds in the given build_request.
>          """
> +        # First, double check that the builds that will be updated in the
> +        # manifest files were not superseded by newer builds.
> +        uploaded_builds = [build for build in uploaded_builds
> +                           if not cls.updateSupersededBuilds(build)]
> +        if not uploaded_builds:
> +            return
>          for push_rule in build_request.recipe.push_rules:
>              http_client = RegistryHTTPClient.getInstance(push_rule)
>              multi_manifest_content = cls.makeMultiArchManifest(


-- 
https://code.launchpad.net/~pappacena/launchpad/+git/launchpad/+merge/394269
Your team Launchpad code reviewers is subscribed to branch ~pappacena/launchpad:oci-upload-manifest-upsert.


References