← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~cjwatson/launchpad/snap-upload-model into lp:launchpad

 

Colin Watson has proposed merging lp:~cjwatson/launchpad/snap-upload-model into lp:launchpad with lp:~cjwatson/launchpad/snap-series as a prerequisite.

Commit message:
Add basic model for Snap/SnapBuild store upload columns.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #1572605 in Launchpad itself: "Automatically upload snap builds to store"
  https://bugs.launchpad.net/launchpad/+bug/1572605

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/snap-upload-model/+merge/293648

Add basic model for Snap/SnapBuild store upload columns.  This doesn't do anything interesting yet and I haven't exported any of the attributes; I just wanted to have this in place to make it easier to submit subsequent branches.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/snap-upload-model into lp:launchpad.
=== added file 'lib/lp/snappy/enums.py'
--- lib/lp/snappy/enums.py	1970-01-01 00:00:00 +0000
+++ lib/lp/snappy/enums.py	2016-05-03 16:06:20 +0000
@@ -0,0 +1,42 @@
+# Copyright 2016 Canonical Ltd.  This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Enumerations used in the lp/snappy modules."""
+
+from __future__ import absolute_import, print_function, unicode_literals
+
+__metaclass__ = type
+__all__ = [
+    'SnapStoreUploadStatus',
+    ]
+
+from lazr.enum import (
+    DBEnumeratedType,
+    DBItem,
+    )
+
+
+class SnapStoreUploadStatus(DBEnumeratedType):
+    """Snap Store Upload Status
+
+    Launchpad can optionally upload snap package builds to the store.  This
+    enumeration tracks the status of such uploads.
+    """
+
+    PENDING = DBItem(1, """
+        Pending
+
+        This snap package will be uploaded to the store in due course.
+        """)
+
+    DONE = DBItem(2, """
+        Done
+
+        This snap package has been successfully uploaded to the store.
+        """)
+
+    FAILED = DBItem(3, """
+        Failed
+
+        Launchpad tried to upload this snap package to the store, but failed.
+        """)

=== modified file 'lib/lp/snappy/interfaces/snap.py'
--- lib/lp/snappy/interfaces/snap.py	2016-02-28 17:23:53 +0000
+++ lib/lp/snappy/interfaces/snap.py	2016-05-03 16:06:20 +0000
@@ -86,6 +86,7 @@
     PublicPersonChoice,
     )
 from lp.services.webhooks.interfaces import IWebhookTarget
+from lp.snappy.interfaces.snapseries import ISnapSeries
 from lp.soyuz.interfaces.archive import IArchive
 from lp.soyuz.interfaces.distroarchseries import IDistroArchSeries
 
@@ -354,6 +355,34 @@
             "The Git branch containing a snapcraft.yaml recipe at the top "
             "level.")))
 
+    store_upload = Bool(
+        title=_("Automatically upload to store"),
+        required=True, readonly=False,
+        description=_(
+            "Whether builds of this snap package are automatically uploaded "
+            "to the store."))
+
+    store_series = ReferenceChoice(
+        title=_("Store series"),
+        schema=ISnapSeries, vocabulary="SnapSeries",
+        required=False, readonly=False,
+        description=_(
+            "The series in which this snap package should be published in the "
+            "store."))
+
+    store_name = TextLine(
+        title=_("Registered store package name"),
+        required=False, readonly=False,
+        description=_(
+            "The registered name of this snap package in the store."))
+
+    store_tokens = List(
+        value_type=TextLine(), title=_("Store upload tokens"),
+        required=False, readonly=False,
+        description=_(
+            "Serialized tokens issued by the store and the login service to "
+            "authorize uploads of this snap package."))
+
 
 class ISnapAdminAttributes(Interface):
     """`ISnap` attributes that can be edited by admins.
@@ -401,7 +430,9 @@
     @operation_for_version("devel")
     def new(registrant, owner, distro_series, name, description=None,
             branch=None, git_ref=None, require_virtualized=True,
-            processors=None, date_created=None, private=False):
+            processors=None, date_created=None, private=False,
+            store_upload=False, store_series=None, store_name=None,
+            store_tokens=None):
         """Create an `ISnap`."""
 
     def exists(owner, name):

=== modified file 'lib/lp/snappy/interfaces/snapbuild.py'
--- lib/lp/snappy/interfaces/snapbuild.py	2016-01-19 17:41:11 +0000
+++ lib/lp/snappy/interfaces/snapbuild.py	2016-05-03 16:06:20 +0000
@@ -36,6 +36,7 @@
 from lp.registry.interfaces.pocket import PackagePublishingPocket
 from lp.services.database.constants import DEFAULT
 from lp.services.librarian.interfaces import ILibraryFileAlias
+from lp.snappy.enums import SnapStoreUploadStatus
 from lp.snappy.interfaces.snap import ISnap
 from lp.soyuz.interfaces.archive import IArchive
 from lp.soyuz.interfaces.distroarchseries import IDistroArchSeries
@@ -103,6 +104,10 @@
         required=True, readonly=True,
         description=_("Whether this build record can be cancelled.")))
 
+    store_upload_status = Choice(
+        title=_("The status of uploading this build to the store."),
+        vocabulary=SnapStoreUploadStatus, required=True, readonly=True)
+
     def getFiles():
         """Retrieve the build's `ISnapFile` records.
 

=== modified file 'lib/lp/snappy/model/snap.py'
--- lib/lp/snappy/model/snap.py	2016-02-28 17:40:10 +0000
+++ lib/lp/snappy/model/snap.py	2016-05-03 16:06:20 +0000
@@ -12,6 +12,7 @@
     DateTime,
     Desc,
     Int,
+    JSON,
     Not,
     Reference,
     Store,
@@ -148,10 +149,20 @@
 
     private = Bool(name='private')
 
+    store_upload = Bool(name='store_upload', allow_none=False)
+
+    store_series_id = Int(name='store_series', allow_none=True)
+    store_series = Reference(store_series_id, 'SnapSeries.id')
+
+    store_name = Unicode(name='store_name', allow_none=True)
+
+    store_tokens = JSON('store_tokens', allow_none=True)
+
     def __init__(self, registrant, owner, distro_series, name,
                  description=None, branch=None, git_ref=None,
                  require_virtualized=True, date_created=DEFAULT,
-                 private=False):
+                 private=False, store_upload=False, store_series=None,
+                 store_name=None, store_tokens=None):
         """Construct a `Snap`."""
         if not getFeatureFlag(SNAP_FEATURE_FLAG):
             raise SnapFeatureDisabled
@@ -168,6 +179,10 @@
         self.date_created = date_created
         self.date_last_modified = date_created
         self.private = private
+        self.store_upload = store_upload
+        self.store_series = store_series
+        self.store_name = store_name
+        self.store_tokens = store_tokens
 
     @property
     def valid_webhook_event_types(self):
@@ -389,7 +404,9 @@
 
     def new(self, registrant, owner, distro_series, name, description=None,
             branch=None, git_ref=None, require_virtualized=True,
-            processors=None, date_created=DEFAULT, private=False):
+            processors=None, date_created=DEFAULT, private=False,
+            store_upload=False, store_series=None, store_name=None,
+            store_tokens=None):
         """See `ISnapSet`."""
         if not registrant.inTeam(owner):
             if owner.is_team:
@@ -414,7 +431,9 @@
             registrant, owner, distro_series, name, description=description,
             branch=branch, git_ref=git_ref,
             require_virtualized=require_virtualized, date_created=date_created,
-            private=private)
+            private=private, store_upload=store_upload,
+            store_series=store_series, store_name=store_name,
+            store_tokens=store_tokens)
         store.add(snap)
 
         if processors is None:

=== modified file 'lib/lp/snappy/model/snapbuild.py'
--- lib/lp/snappy/model/snapbuild.py	2016-02-19 14:18:22 +0000
+++ lib/lp/snappy/model/snapbuild.py	2016-05-03 16:06:20 +0000
@@ -53,6 +53,7 @@
     LibraryFileAlias,
     LibraryFileContent,
     )
+from lp.snappy.enums import SnapStoreUploadStatus
 from lp.snappy.interfaces.snap import (
     ISnapSet,
     SNAP_FEATURE_FLAG,
@@ -150,6 +151,10 @@
 
     failure_count = Int(name='failure_count', allow_none=False)
 
+    store_upload_status = DBEnum(
+        name='store_upload_status', enum=SnapStoreUploadStatus,
+        allow_none=True)
+
     def __init__(self, build_farm_job, requester, snap, archive,
                  distro_arch_series, pocket, processor, virtualized,
                  date_created):

=== modified file 'lib/lp/testing/factory.py'
--- lib/lp/testing/factory.py	2016-05-03 16:06:20 +0000
+++ lib/lp/testing/factory.py	2016-05-03 16:06:20 +0000
@@ -4607,7 +4607,8 @@
     def makeSnap(self, registrant=None, owner=None, distroseries=None,
                  name=None, branch=None, git_ref=None,
                  require_virtualized=True, processors=None,
-                 date_created=DEFAULT, private=False):
+                 date_created=DEFAULT, private=False, store_upload=False,
+                 store_series=None, store_name=None, store_tokens=None):
         """Make a new Snap."""
         if registrant is None:
             registrant = self.makePerson()
@@ -4623,7 +4624,9 @@
             registrant, owner, distroseries, name,
             require_virtualized=require_virtualized, processors=processors,
             date_created=date_created, branch=branch, git_ref=git_ref,
-            private=private)
+            private=private, store_upload=store_upload,
+            store_series=store_series, store_name=store_name,
+            store_tokens=store_tokens)
         IStore(snap).flush()
         return snap
 


Follow ups