cipd_bootstrap_test.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #!/usr/bin/env vpython3
  2. # Copyright (c) 2018 The Chromium Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. import os
  6. import shutil
  7. import subprocess
  8. import sys
  9. import unittest
  10. import tempfile
  11. # TODO: Should fix these warnings.
  12. # pylint: disable=line-too-long
  13. ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  14. # CIPD client version to use for self-update from an "old" checkout to the tip.
  15. #
  16. # This version is from Aug 2018. Digests were generated using:
  17. # cipd selfupdate-roll -version-file tmp \
  18. # -version git_revision:ea6c07cfcb596be6b63a1e6deb95bba79524b0c8
  19. # cat tmp.digests
  20. OLD_VERSION = 'git_revision:ea6c07cfcb596be6b63a1e6deb95bba79524b0c8'
  21. OLD_DIGESTS = """
  22. linux-386 sha256 ee90bd655b90baf7586ab80c289c00233b96bfac3fa70e64cc5c48feb1998971
  23. linux-amd64 sha256 73bd62cb72cde6f12d9b42cda12941c53e1e21686f6f2b1cd98db5c6718b7bed
  24. linux-arm64 sha256 1f2619f3e7f5f6876d0a446bacc6cc61eb32ca1464315d7230034a832500ed64
  25. linux-armv6l sha256 98c873097c460fe8f6b4311f6e00b4df41ca50e9bd2d26f06995913a9d647d3a
  26. linux-mips64 sha256 05e37c85502eb2b72abd8a51ff13a4914c5e071e25326c9c8fc257290749138a
  27. linux-mips64le sha256 5b3af8be6ea8a62662006f1a86fdc387dc765edace9f530acbeca77c0850a32d
  28. linux-mipsle sha256 cfa6539af00db69b7da00d46316f1aaaa90b38a5e6b33ce4823be17533e71810
  29. linux-ppc64 sha256 faa49f2b59a25134e8a13b68f5addb00c434c7feeee03940413917eca1d333e6
  30. linux-ppc64le sha256 6fa51348e6039b864171426b02cfbfa1d533b9f86e3c72875e0ed116994a2fec
  31. linux-s390x sha256 6cd4bfff7e2025f2d3da55013036e39eea4e8f631060a5e2b32b9975fab08b0e
  32. mac-amd64 sha256 6427b87fdaa1615a229d45c2fab1ba7fdb748ce785f2c09cd6e10adc48c58a66
  33. windows-386 sha256 809c727a31e5f8c34656061b96839fbca63833140b90cab8e2491137d6e4fc4c
  34. windows-amd64 sha256 3e21561b45acb2845c309a04cbedb2ce1e0567b7b24bf89857e7673607b09216
  35. """
  36. class CipdBootstrapTest(unittest.TestCase):
  37. """Tests that CIPD client can bootstrap from scratch and self-update from some
  38. old version to a most recent one.
  39. WARNING: This integration test touches real network and real CIPD backend and
  40. downloads several megabytes of stuff.
  41. """
  42. def setUp(self):
  43. self.tempdir = tempfile.mkdtemp('depot_tools_cipd')
  44. def tearDown(self):
  45. shutil.rmtree(self.tempdir)
  46. def stage_files(self, cipd_version=None, digests=None):
  47. """Copies files needed for cipd bootstrap into the temp dir.
  48. Args:
  49. cipd_version: if not None, a value to put into cipd_client_version file.
  50. """
  51. names = (
  52. '.cipd_impl.ps1',
  53. 'cipd',
  54. 'cipd.bat',
  55. 'cipd_client_version',
  56. 'cipd_client_version.digests',
  57. )
  58. for f in names:
  59. shutil.copy2(os.path.join(ROOT_DIR, f),
  60. os.path.join(self.tempdir, f))
  61. if cipd_version is not None:
  62. with open(os.path.join(self.tempdir, 'cipd_client_version'),
  63. 'wt') as f:
  64. f.write(cipd_version + '\n')
  65. if digests is not None:
  66. p = os.path.join(self.tempdir, 'cipd_client_version.digests')
  67. with open(p, 'wt') as f:
  68. f.write(digests + '\n')
  69. def call_cipd_help(self):
  70. """Calls 'cipd help' bootstrapping the client in tempdir.
  71. Returns (exit code, merged stdout and stderr).
  72. """
  73. exe = 'cipd.bat' if sys.platform == 'win32' else 'cipd'
  74. p = subprocess.Popen([os.path.join(self.tempdir, exe), 'help'],
  75. stdout=subprocess.PIPE,
  76. stderr=subprocess.STDOUT)
  77. out, _ = p.communicate()
  78. return p.returncode, out
  79. def test_new_bootstrap(self):
  80. """Bootstrapping the client from scratch."""
  81. self.stage_files()
  82. ret, out = self.call_cipd_help()
  83. if ret:
  84. self.fail('Bootstrap from scratch failed:\n%s' % out)
  85. def test_self_update(self):
  86. """Updating the existing client in-place."""
  87. self.stage_files(cipd_version=OLD_VERSION, digests=OLD_DIGESTS)
  88. ret, out = self.call_cipd_help()
  89. if ret:
  90. self.fail('Update to %s fails:\n%s' % (OLD_VERSION, out))
  91. self.stage_files()
  92. ret, out = self.call_cipd_help()
  93. if ret:
  94. self.fail('Update from %s to the tip fails:\n%s' %
  95. (OLD_VERSION, out))
  96. if __name__ == '__main__':
  97. unittest.main()