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, BIONIC_CANARY_BUNDLE_NAME | 24 from update_nacl_manifest import 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 | |
59 def MakeGsUrl(rel_path): | 54 def MakeGsUrl(rel_path): |
60 return update_nacl_manifest.GS_BUCKET_PATH + rel_path | 55 return update_nacl_manifest.GS_BUCKET_PATH + rel_path |
61 | 56 |
62 | 57 |
63 def GetPathFromGsUrl(url): | 58 def GetPathFromGsUrl(url): |
64 assert url.startswith(update_nacl_manifest.GS_BUCKET_PATH) | 59 assert url.startswith(update_nacl_manifest.GS_BUCKET_PATH) |
65 return url[len(update_nacl_manifest.GS_BUCKET_PATH):] | 60 return url[len(update_nacl_manifest.GS_BUCKET_PATH):] |
66 | 61 |
67 | 62 |
68 def GetPathFromHttpsUrl(url): | 63 def GetPathFromHttpsUrl(url): |
69 assert url.startswith(HTTPS_BASE_URL) | 64 assert url.startswith(HTTPS_BASE_URL) |
70 return url[len(HTTPS_BASE_URL):] | 65 return url[len(HTTPS_BASE_URL):] |
71 | 66 |
72 | 67 |
73 def MakeArchive(url, host_os): | 68 def MakeArchive(url, host_os): |
74 archive = manifest_util.Archive(host_os) | 69 archive = manifest_util.Archive(host_os) |
75 archive.url = url | 70 archive.url = url |
76 # dummy values that won't succeed if we ever use them, but will pass | 71 # dummy values that won't succeed if we ever use them, but will pass |
77 # validation. :) | 72 # validation. :) |
78 archive.checksum = {'sha1': 'foobar'} | 73 archive.checksum = {'sha1': 'foobar'} |
79 archive.size = 1 | 74 archive.size = 1 |
80 return archive | 75 return archive |
81 | 76 |
82 | 77 |
83 def MakePlatformArchive(host_os, version): | 78 def MakePlatformArchive(host_os, version): |
84 return MakeArchive(GetPlatformArchiveUrl(host_os, version), host_os) | 79 return MakeArchive(GetPlatformArchiveUrl(host_os, version), host_os) |
85 | 80 |
86 | 81 |
87 def MakeBionicArchive(host_os, version): | |
88 return MakeArchive(GetBionicArchiveUrl(version), host_os) | |
89 | |
90 | |
91 def MakeNonPlatformArchive(basename, version): | 82 def MakeNonPlatformArchive(basename, version): |
92 return MakeArchive(GetArchiveURL(basename, version), 'all') | 83 return MakeArchive(GetArchiveURL(basename, version), 'all') |
93 | 84 |
94 | 85 |
95 def MakeNonPepperBundle(name, with_archives=False): | 86 def MakeNonPepperBundle(name, with_archives=False): |
96 bundle = manifest_util.Bundle(name) | 87 bundle = manifest_util.Bundle(name) |
97 bundle.version = 1 | 88 bundle.version = 1 |
98 bundle.revision = 1 | 89 bundle.revision = 1 |
99 bundle.description = 'Dummy bundle' | 90 bundle.description = 'Dummy bundle' |
100 bundle.recommended = 'yes' | 91 bundle.recommended = 'yes' |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 B19_NONE = MakePlatformBundle(19) | 269 B19_NONE = MakePlatformBundle(19) |
279 BCANARY_NONE = MakePepperBundle(0, stability=CANARY, | 270 BCANARY_NONE = MakePepperBundle(0, stability=CANARY, |
280 bundle_name=CANARY_BUNDLE_NAME) | 271 bundle_name=CANARY_BUNDLE_NAME) |
281 B21_0_1145_0_MLW = MakePlatformBundle(21, 138079, V21_0_1145_0, OS_MLW) | 272 B21_0_1145_0_MLW = MakePlatformBundle(21, 138079, V21_0_1145_0, OS_MLW) |
282 B21_0_1166_0_MW = MakePlatformBundle(21, 140819, V21_0_1166_0, OS_MW) | 273 B21_0_1166_0_MW = MakePlatformBundle(21, 140819, V21_0_1166_0, OS_MW) |
283 B21_NONE = MakePlatformBundle(21) | 274 B21_NONE = MakePlatformBundle(21) |
284 B26_NONE = MakePlatformBundle(26) | 275 B26_NONE = MakePlatformBundle(26) |
285 B26_0_1386_0_MLW = MakePlatformBundle(26, 177362, V26_0_1386_0, OS_MLW) | 276 B26_0_1386_0_MLW = MakePlatformBundle(26, 177362, V26_0_1386_0, OS_MLW) |
286 B26_0_1386_1_MLW = MakePlatformBundle(26, 177439, V26_0_1386_1, OS_MLW) | 277 B26_0_1386_1_MLW = MakePlatformBundle(26, 177439, V26_0_1386_1, OS_MLW) |
287 BTRUNK_140819_MLW = MakePlatformBundle(21, 140819, VTRUNK_140819, OS_MLW) | 278 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) | |
291 NON_PEPPER_BUNDLE_NOARCHIVES = MakeNonPepperBundle('foo') | 279 NON_PEPPER_BUNDLE_NOARCHIVES = MakeNonPepperBundle('foo') |
292 NON_PEPPER_BUNDLE_ARCHIVES = MakeNonPepperBundle('bar', with_archives=True) | 280 NON_PEPPER_BUNDLE_ARCHIVES = MakeNonPepperBundle('bar', with_archives=True) |
293 | 281 |
294 | 282 |
295 class TestUpdateManifest(unittest.TestCase): | 283 class TestUpdateManifest(unittest.TestCase): |
296 def setUp(self): | 284 def setUp(self): |
297 self.history = MakeHistory() | 285 self.history = MakeHistory() |
298 self.files = MakeFiles() | 286 self.files = MakeFiles() |
299 self.version_mapping = {} | 287 self.version_mapping = {} |
300 self.delegate = None | 288 self.delegate = None |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 | 680 |
693 uploaded_bundle = self.uploaded_manifest.GetBundle('pepper_18') | 681 uploaded_bundle = self.uploaded_manifest.GetBundle('pepper_18') |
694 self.assertEqual(uploaded_bundle, B18_0_1025_163_MLW) | 682 self.assertEqual(uploaded_bundle, B18_0_1025_163_MLW) |
695 | 683 |
696 def testBundleWithoutHistoryOrOnlineRaises(self): | 684 def testBundleWithoutHistoryOrOnlineRaises(self): |
697 self.manifest = MakeManifest(B18_NONE) | 685 self.manifest = MakeManifest(B18_NONE) |
698 self._MakeDelegate() | 686 self._MakeDelegate() |
699 self.assertRaises(update_nacl_manifest.UnknownLockedBundleException, | 687 self.assertRaises(update_nacl_manifest.UnknownLockedBundleException, |
700 self._Run, OS_MLW) | 688 self._Run, OS_MLW) |
701 | 689 |
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 | |
714 | 690 |
715 class TestUpdateVitals(unittest.TestCase): | 691 class TestUpdateVitals(unittest.TestCase): |
716 def setUp(self): | 692 def setUp(self): |
717 f = tempfile.NamedTemporaryFile('w', prefix="test_update_nacl_manifest") | 693 f = tempfile.NamedTemporaryFile('w', prefix="test_update_nacl_manifest") |
718 self.test_file = f.name | 694 self.test_file = f.name |
719 f.close() | 695 f.close() |
720 test_data = "Some test data" | 696 test_data = "Some test data" |
721 self.sha1 = hashlib.sha1(test_data).hexdigest() | 697 self.sha1 = hashlib.sha1(test_data).hexdigest() |
722 self.data_len = len(test_data) | 698 self.data_len = len(test_data) |
723 with open(self.test_file, 'w') as f: | 699 with open(self.test_file, 'w') as f: |
(...skipping 21 matching lines...) Expand all Loading... |
745 self.assertRaises(manifest_util.Error, manifest.Validate) | 721 self.assertRaises(manifest_util.Error, manifest.Validate) |
746 | 722 |
747 manifest.Validate(add_missing_info=True) | 723 manifest.Validate(add_missing_info=True) |
748 | 724 |
749 self.assertEqual(archive['size'], self.data_len) | 725 self.assertEqual(archive['size'], self.data_len) |
750 self.assertEqual(archive['checksum']['sha1'], self.sha1) | 726 self.assertEqual(archive['checksum']['sha1'], self.sha1) |
751 | 727 |
752 | 728 |
753 if __name__ == '__main__': | 729 if __name__ == '__main__': |
754 unittest.main() | 730 unittest.main() |
OLD | NEW |