| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import copy | 6 import copy |
| 7 import datetime | 7 import datetime |
| 8 import hashlib | 8 import hashlib |
| 9 import logging | 9 import logging |
| 10 import os | 10 import os |
| 11 import posixpath | 11 import posixpath |
| 12 import subprocess | 12 import subprocess |
| 13 import sys | 13 import sys |
| 14 import tempfile | 14 import tempfile |
| 15 import unittest | 15 import unittest |
| 16 import urlparse | 16 import urlparse |
| 17 | 17 |
| 18 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) | 18 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 19 BUILD_TOOLS_DIR = os.path.dirname(SCRIPT_DIR) | 19 BUILD_TOOLS_DIR = os.path.dirname(SCRIPT_DIR) |
| 20 | 20 |
| 21 sys.path.append(BUILD_TOOLS_DIR) | 21 sys.path.append(BUILD_TOOLS_DIR) |
| 22 import manifest_util | 22 import manifest_util |
| 23 import update_nacl_manifest | 23 import update_nacl_manifest |
| 24 from update_nacl_manifest import CANARY_BUNDLE_NAME | 24 from update_nacl_manifest import CANARY_BUNDLE_NAME, BIONIC_CANARY_BUNDLE_NAME |
| 25 | 25 |
| 26 | 26 |
| 27 HTTPS_BASE_URL = 'https://storage.googleapis.com' \ | 27 HTTPS_BASE_URL = 'https://storage.googleapis.com' \ |
| 28 '/nativeclient_mirror/nacl/nacl_sdk/' | 28 '/nativeclient_mirror/nacl/nacl_sdk/' |
| 29 | 29 |
| 30 OS_CR = ('cros',) | 30 OS_CR = ('cros',) |
| 31 OS_L = ('linux',) | 31 OS_L = ('linux',) |
| 32 OS_M = ('mac',) | 32 OS_M = ('mac',) |
| 33 OS_ML = ('mac', 'linux') | 33 OS_ML = ('mac', 'linux') |
| 34 OS_MW = ('mac', 'win') | 34 OS_MW = ('mac', 'win') |
| 35 OS_LW = ('linux', 'win') | 35 OS_LW = ('linux', 'win') |
| 36 OS_MLW = ('mac', 'linux', 'win') | 36 OS_MLW = ('mac', 'linux', 'win') |
| 37 OS_ALL = ('all',) | 37 OS_ALL = ('all',) |
| 38 POST_STABLE = 'post_stable' | 38 POST_STABLE = 'post_stable' |
| 39 STABLE = 'stable' | 39 STABLE = 'stable' |
| 40 BETA = 'beta' | 40 BETA = 'beta' |
| 41 DEV = 'dev' | 41 DEV = 'dev' |
| 42 CANARY = 'canary' | 42 CANARY = 'canary' |
| 43 | 43 |
| 44 | 44 |
| 45 def GetArchiveURL(basename, version): | 45 def GetArchiveURL(basename, version): |
| 46 return urlparse.urljoin(HTTPS_BASE_URL, posixpath.join(version, basename)) | 46 return urlparse.urljoin(HTTPS_BASE_URL, posixpath.join(version, basename)) |
| 47 | 47 |
| 48 | 48 |
| 49 def GetPlatformArchiveUrl(host_os, version): | 49 def GetPlatformArchiveUrl(host_os, version): |
| 50 basename = 'naclsdk_%s.tar.bz2' % (host_os,) | 50 basename = 'naclsdk_%s.tar.bz2' % (host_os,) |
| 51 return GetArchiveURL(basename, version) | 51 return GetArchiveURL(basename, version) |
| 52 | 52 |
| 53 | 53 |
| 54 def GetBionicArchiveUrl(version): |
| 55 basename = 'naclsdk_bionic.tar.bz2' |
| 56 return GetArchiveURL(basename, version) |
| 57 |
| 58 |
| 54 def MakeGsUrl(rel_path): | 59 def MakeGsUrl(rel_path): |
| 55 return update_nacl_manifest.GS_BUCKET_PATH + rel_path | 60 return update_nacl_manifest.GS_BUCKET_PATH + rel_path |
| 56 | 61 |
| 57 | 62 |
| 58 def GetPathFromGsUrl(url): | 63 def GetPathFromGsUrl(url): |
| 59 assert url.startswith(update_nacl_manifest.GS_BUCKET_PATH) | 64 assert url.startswith(update_nacl_manifest.GS_BUCKET_PATH) |
| 60 return url[len(update_nacl_manifest.GS_BUCKET_PATH):] | 65 return url[len(update_nacl_manifest.GS_BUCKET_PATH):] |
| 61 | 66 |
| 62 | 67 |
| 63 def GetPathFromHttpsUrl(url): | 68 def GetPathFromHttpsUrl(url): |
| 64 assert url.startswith(HTTPS_BASE_URL) | 69 assert url.startswith(HTTPS_BASE_URL) |
| 65 return url[len(HTTPS_BASE_URL):] | 70 return url[len(HTTPS_BASE_URL):] |
| 66 | 71 |
| 67 | 72 |
| 68 def MakeArchive(url, host_os): | 73 def MakeArchive(url, host_os): |
| 69 archive = manifest_util.Archive(host_os) | 74 archive = manifest_util.Archive(host_os) |
| 70 archive.url = url | 75 archive.url = url |
| 71 # dummy values that won't succeed if we ever use them, but will pass | 76 # dummy values that won't succeed if we ever use them, but will pass |
| 72 # validation. :) | 77 # validation. :) |
| 73 archive.checksum = {'sha1': 'foobar'} | 78 archive.checksum = {'sha1': 'foobar'} |
| 74 archive.size = 1 | 79 archive.size = 1 |
| 75 return archive | 80 return archive |
| 76 | 81 |
| 77 | 82 |
| 78 def MakePlatformArchive(host_os, version): | 83 def MakePlatformArchive(host_os, version): |
| 79 return MakeArchive(GetPlatformArchiveUrl(host_os, version), host_os) | 84 return MakeArchive(GetPlatformArchiveUrl(host_os, version), host_os) |
| 80 | 85 |
| 81 | 86 |
| 87 def MakeBionicArchive(host_os, version): |
| 88 return MakeArchive(GetBionicArchiveUrl(version), host_os) |
| 89 |
| 90 |
| 82 def MakeNonPlatformArchive(basename, version): | 91 def MakeNonPlatformArchive(basename, version): |
| 83 return MakeArchive(GetArchiveURL(basename, version), 'all') | 92 return MakeArchive(GetArchiveURL(basename, version), 'all') |
| 84 | 93 |
| 85 | 94 |
| 86 def MakeNonPepperBundle(name, with_archives=False): | 95 def MakeNonPepperBundle(name, with_archives=False): |
| 87 bundle = manifest_util.Bundle(name) | 96 bundle = manifest_util.Bundle(name) |
| 88 bundle.version = 1 | 97 bundle.version = 1 |
| 89 bundle.revision = 1 | 98 bundle.revision = 1 |
| 90 bundle.description = 'Dummy bundle' | 99 bundle.description = 'Dummy bundle' |
| 91 bundle.recommended = 'yes' | 100 bundle.recommended = 'yes' |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 B19_NONE = MakePlatformBundle(19) | 278 B19_NONE = MakePlatformBundle(19) |
| 270 BCANARY_NONE = MakePepperBundle(0, stability=CANARY, | 279 BCANARY_NONE = MakePepperBundle(0, stability=CANARY, |
| 271 bundle_name=CANARY_BUNDLE_NAME) | 280 bundle_name=CANARY_BUNDLE_NAME) |
| 272 B21_0_1145_0_MLW = MakePlatformBundle(21, 138079, V21_0_1145_0, OS_MLW) | 281 B21_0_1145_0_MLW = MakePlatformBundle(21, 138079, V21_0_1145_0, OS_MLW) |
| 273 B21_0_1166_0_MW = MakePlatformBundle(21, 140819, V21_0_1166_0, OS_MW) | 282 B21_0_1166_0_MW = MakePlatformBundle(21, 140819, V21_0_1166_0, OS_MW) |
| 274 B21_NONE = MakePlatformBundle(21) | 283 B21_NONE = MakePlatformBundle(21) |
| 275 B26_NONE = MakePlatformBundle(26) | 284 B26_NONE = MakePlatformBundle(26) |
| 276 B26_0_1386_0_MLW = MakePlatformBundle(26, 177362, V26_0_1386_0, OS_MLW) | 285 B26_0_1386_0_MLW = MakePlatformBundle(26, 177362, V26_0_1386_0, OS_MLW) |
| 277 B26_0_1386_1_MLW = MakePlatformBundle(26, 177439, V26_0_1386_1, OS_MLW) | 286 B26_0_1386_1_MLW = MakePlatformBundle(26, 177439, V26_0_1386_1, OS_MLW) |
| 278 BTRUNK_140819_MLW = MakePlatformBundle(21, 140819, VTRUNK_140819, OS_MLW) | 287 BTRUNK_140819_MLW = MakePlatformBundle(21, 140819, VTRUNK_140819, OS_MLW) |
| 288 BBIONIC_NONE = MakePepperBundle(0, stability=CANARY, |
| 289 bundle_name=BIONIC_CANARY_BUNDLE_NAME) |
| 290 BBIONIC_TRUNK_277776 = MakeBionicBundle(37, 277776, VTRUNK_277776, OS_L) |
| 279 NON_PEPPER_BUNDLE_NOARCHIVES = MakeNonPepperBundle('foo') | 291 NON_PEPPER_BUNDLE_NOARCHIVES = MakeNonPepperBundle('foo') |
| 280 NON_PEPPER_BUNDLE_ARCHIVES = MakeNonPepperBundle('bar', with_archives=True) | 292 NON_PEPPER_BUNDLE_ARCHIVES = MakeNonPepperBundle('bar', with_archives=True) |
| 281 | 293 |
| 282 | 294 |
| 283 class TestUpdateManifest(unittest.TestCase): | 295 class TestUpdateManifest(unittest.TestCase): |
| 284 def setUp(self): | 296 def setUp(self): |
| 285 self.history = MakeHistory() | 297 self.history = MakeHistory() |
| 286 self.files = MakeFiles() | 298 self.files = MakeFiles() |
| 287 self.version_mapping = {} | 299 self.version_mapping = {} |
| 288 self.delegate = None | 300 self.delegate = None |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 | 692 |
| 681 uploaded_bundle = self.uploaded_manifest.GetBundle('pepper_18') | 693 uploaded_bundle = self.uploaded_manifest.GetBundle('pepper_18') |
| 682 self.assertEqual(uploaded_bundle, B18_0_1025_163_MLW) | 694 self.assertEqual(uploaded_bundle, B18_0_1025_163_MLW) |
| 683 | 695 |
| 684 def testBundleWithoutHistoryOrOnlineRaises(self): | 696 def testBundleWithoutHistoryOrOnlineRaises(self): |
| 685 self.manifest = MakeManifest(B18_NONE) | 697 self.manifest = MakeManifest(B18_NONE) |
| 686 self._MakeDelegate() | 698 self._MakeDelegate() |
| 687 self.assertRaises(update_nacl_manifest.UnknownLockedBundleException, | 699 self.assertRaises(update_nacl_manifest.UnknownLockedBundleException, |
| 688 self._Run, OS_MLW) | 700 self._Run, OS_MLW) |
| 689 | 701 |
| 702 def testUpdateBionic(self): |
| 703 bionic_bundle = copy.deepcopy(BBIONIC_NONE) |
| 704 self.manifest = MakeManifest(bionic_bundle) |
| 705 self.history.Add(OS_MW, CANARY, V37_0_2054_0) |
| 706 self.files.Add(BBIONIC_TRUNK_277776) |
| 707 self.version_mapping[V37_0_2054_0] = VTRUNK_277776 |
| 708 self._MakeDelegate() |
| 709 self._Run(OS_MLW) |
| 710 self._ReadUploadedManifest() |
| 711 self._AssertUploadedManifestHasBundle(BBIONIC_TRUNK_277776, CANARY, |
| 712 bundle_name=BIONIC_CANARY_BUNDLE_NAME) |
| 713 |
| 690 | 714 |
| 691 class TestUpdateVitals(unittest.TestCase): | 715 class TestUpdateVitals(unittest.TestCase): |
| 692 def setUp(self): | 716 def setUp(self): |
| 693 f = tempfile.NamedTemporaryFile('w', prefix="test_update_nacl_manifest") | 717 f = tempfile.NamedTemporaryFile('w', prefix="test_update_nacl_manifest") |
| 694 self.test_file = f.name | 718 self.test_file = f.name |
| 695 f.close() | 719 f.close() |
| 696 test_data = "Some test data" | 720 test_data = "Some test data" |
| 697 self.sha1 = hashlib.sha1(test_data).hexdigest() | 721 self.sha1 = hashlib.sha1(test_data).hexdigest() |
| 698 self.data_len = len(test_data) | 722 self.data_len = len(test_data) |
| 699 with open(self.test_file, 'w') as f: | 723 with open(self.test_file, 'w') as f: |
| (...skipping 21 matching lines...) Expand all Loading... |
| 721 self.assertRaises(manifest_util.Error, manifest.Validate) | 745 self.assertRaises(manifest_util.Error, manifest.Validate) |
| 722 | 746 |
| 723 manifest.Validate(add_missing_info=True) | 747 manifest.Validate(add_missing_info=True) |
| 724 | 748 |
| 725 self.assertEqual(archive['size'], self.data_len) | 749 self.assertEqual(archive['size'], self.data_len) |
| 726 self.assertEqual(archive['checksum']['sha1'], self.sha1) | 750 self.assertEqual(archive['checksum']['sha1'], self.sha1) |
| 727 | 751 |
| 728 | 752 |
| 729 if __name__ == '__main__': | 753 if __name__ == '__main__': |
| 730 unittest.main() | 754 unittest.main() |
| OLD | NEW |