Bläddra i källkod

[cipd] Add presubmit support for checking *.digests file.

Not enabling it yet, since PRESUBMIT.py uses presubmit_canned_checks.py from
depot_tools at HEAD, not from a CL (thus enabling this check in this CL will
make it fail the presubmit).

R=nodir@chromium.org
BUG=870166

Change-Id: I97802ec37f1f7513dfca3950f7f38a5c51ab0350
Reviewed-on: https://chromium-review.googlesource.com/1227432
Reviewed-by: Nodir Turakulov <nodir@chromium.org>
Commit-Queue: Vadim Shtayura <vadimsh@chromium.org>
Vadim Shtayura 7 år sedan
förälder
incheckning
2174136d25
3 ändrade filer med 37 tillägg och 2 borttagningar
  1. 23 0
      presubmit_canned_checks.py
  2. 1 1
      tests/cipd_bootstrap_test.py
  3. 13 1
      tests/presubmit_unittest.py

+ 23 - 0
presubmit_canned_checks.py

@@ -1181,6 +1181,29 @@ def CheckCIPDPackages(input_api, output_api, platforms, packages):
   return CheckCIPDManifest(input_api, output_api, content='\n'.join(manifest))
   return CheckCIPDManifest(input_api, output_api, content='\n'.join(manifest))
 
 
 
 
+def CheckCIPDClientDigests(input_api, output_api, client_version_file):
+  """Verifies that *.digests file was correctly regenerated.
+
+  <client_version_file>.digests file contains pinned hashes of the CIPD client.
+  It is consulted during CIPD client bootstrap and self-update. It should be
+  regenerated each time CIPD client version file changes.
+
+  Args:
+    client_version_file (str): Path to a text file with CIPD client version.
+  """
+  cmd = [
+    'cipd' if not input_api.is_windows else 'cipd.bat',
+    'selfupdate-roll', '-check', '-version-file', client_version_file,
+  ]
+  if input_api.verbose:
+    cmd += ['-log-level', 'debug']
+  return input_api.Command(
+      'Check CIPD client_version_file.digests file',
+      cmd,
+      {'shell': True} if input_api.is_windows else {},  # to resolve cipd.bat
+      output_api.PresubmitError)
+
+
 def CheckVPythonSpec(input_api, output_api, file_filter=None):
 def CheckVPythonSpec(input_api, output_api, file_filter=None):
   """Validates any changed .vpython files with vpython verification tool.
   """Validates any changed .vpython files with vpython verification tool.
 
 

+ 1 - 1
tests/cipd_bootstrap_test.py

@@ -18,7 +18,7 @@ ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
 # This version is from Aug 2018. Digests were generated using:
 # This version is from Aug 2018. Digests were generated using:
 #   cipd selfupdate-roll -version-file tmp \
 #   cipd selfupdate-roll -version-file tmp \
 #        -version git_revision:ea6c07cfcb596be6b63a1e6deb95bba79524b0c8
 #        -version git_revision:ea6c07cfcb596be6b63a1e6deb95bba79524b0c8
-#   cat tmp.cat
+#   cat tmp.digests
 OLD_VERSION = 'git_revision:ea6c07cfcb596be6b63a1e6deb95bba79524b0c8'
 OLD_VERSION = 'git_revision:ea6c07cfcb596be6b63a1e6deb95bba79524b0c8'
 OLD_DIGESTS = """
 OLD_DIGESTS = """
 linux-386       sha256  ee90bd655b90baf7586ab80c289c00233b96bfac3fa70e64cc5c48feb1998971
 linux-386       sha256  ee90bd655b90baf7586ab80c289c00233b96bfac3fa70e64cc5c48feb1998971

+ 13 - 1
tests/presubmit_unittest.py

@@ -1777,7 +1777,7 @@ class CannedChecksUnittest(PresubmitTestsBase):
       'GetCodereviewOwnerAndReviewers',
       'GetCodereviewOwnerAndReviewers',
       'GetPythonUnitTests', 'GetPylint',
       'GetPythonUnitTests', 'GetPylint',
       'GetUnitTests', 'GetUnitTestsInDirectory', 'GetUnitTestsRecursively',
       'GetUnitTests', 'GetUnitTestsInDirectory', 'GetUnitTestsRecursively',
-      'CheckCIPDManifest', 'CheckCIPDPackages',
+      'CheckCIPDManifest', 'CheckCIPDPackages', 'CheckCIPDClientDigests',
       'CheckChangedLUCIConfigs',
       'CheckChangedLUCIConfigs',
     ]
     ]
     # If this test fails, you should add the relevant test.
     # If this test fails, you should add the relevant test.
@@ -2935,6 +2935,18 @@ class CannedChecksUnittest(PresubmitTestsBase):
         'stderr': subprocess.STDOUT,
         'stderr': subprocess.STDOUT,
     })
     })
 
 
+  def testCheckCIPDClientDigests(self):
+    input_api = self.MockInputApi(None, False)
+    input_api.verbose = True
+    self.mox.ReplayAll()
+
+    command = presubmit_canned_checks.CheckCIPDClientDigests(
+        input_api, presubmit.OutputApi, client_version_file='ver')
+    self.assertEquals(command.cmd, [
+      'cipd', 'selfupdate-roll', '-check', '-version-file', 'ver',
+      '-log-level', 'debug',
+    ])
+
   def testCannedCheckVPythonSpec(self):
   def testCannedCheckVPythonSpec(self):
     change = presubmit.Change('a', 'b', self.fake_root_dir, None, 0, 0, None)
     change = presubmit.Change('a', 'b', self.fake_root_dir, None, 0, 0, None)
     input_api = self.MockInputApi(change, False)
     input_api = self.MockInputApi(change, False)