Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Unified Diff: appengine/swarming/server/task_request.py

Issue 2267363004: Add CIPD pin reporting to swarming. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-py@master
Patch Set: comments and some tests Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: appengine/swarming/server/task_request.py
diff --git a/appengine/swarming/server/task_request.py b/appengine/swarming/server/task_request.py
index e4a8062c94bbba0b4a7ea3af7a3fa85dacc37e3f..aaf73a01665f5a3d56ab6c41752da06af4e8943e 100644
--- a/appengine/swarming/server/task_request.py
+++ b/appengine/swarming/server/task_request.py
@@ -292,6 +292,9 @@ class CipdPackage(ndb.Model):
raise datastore_errors.BadValueError('CIPD package version is required')
+PinInfo = collections.namedtuple('PinInfo', ['pkg', 'pin'])
+
+
class CipdInput(ndb.Model):
"""Specifies which CIPD client and packages to install, from which server.
@@ -333,13 +336,43 @@ class CipdInput(ndb.Model):
package_names.add(p.package_name)
self.packages.sort(key=lambda p: p.package_name)
- def packages_grouped_by_path(self):
- """Returns sorted [(path), [package]) list. Used by user_task.html."""
+ def packages_grouped_by_path(self, pins):
+ """Returns sorted [(path, [PinInfo, ...])].
+
+ PinInfo is a namedtuple with two fields 'pkg' and 'pin'. 'pkg' is the
+ CipdPackage that was specified in the task request. 'pin' is the CipdPackage
+ that was resolved by the bot at runtime, and contains a full package name as
M-A Ruel 2016/08/24 19:34:07 This is really part of the result, not the request
iannucci 2016/08/25 00:14:12 On 2016/08/24 at 19:34:07, M-A Ruel wrote: > This
+ well as a package instance id.
+
+ If pinning information is unavailable, or if 'pkg' already specifies a full
+ pin, 'pin' is None. If 'version' or 'package_name' are the same between
+ 'pkg' and 'pin', then the field in 'pin' is None.
+
+ Args:
+ pins - a list of CipdPackages which represent the pin counterparts of
+ self.packages.
+
+ Used by user_task.html.
+ """
+ assert pins is None or len(pins) == len(self.packages)
+ pinned = pins is not None
+
packages = collections.defaultdict(list)
- for p in self.packages:
- packages[p.path].append(p)
+ for i, pkg in enumerate(self.packages):
+ pin = None
+ if pinned:
+ pin = pins[i]
+ if pkg.package_name == pin.package_name:
+ pin.package_name = None
+ if pkg.version == pin.version:
+ pin.version = None
+ if pin.package_name is None and pin.version is None:
+ pin = None
+ packages[pkg.path].append(PinInfo(pkg, pin))
for pkgs in packages.itervalues():
- pkgs.sort()
+ pkgs.sort(key=lambda x: (
+ x.pkg.package_name, x.pkg.version,
+ getattr(x.pin, 'package_name', None), getattr(x.pin, 'version', None)))
return sorted(packages.iteritems())

Powered by Google App Engine
This is Rietveld 408576698