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

Side by Side Diff: native_client_sdk/src/build_tools/tests/test_update_nacl_manifest.py

Issue 11421138: [NaCl SDK] update_nacl_manifest: Allow manual updating of a version. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 os 9 import os
10 import posixpath 10 import posixpath
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 129
130 def Add(self, host_oses, channel, version): 130 def Add(self, host_oses, channel, version):
131 for host_os in host_oses: 131 for host_os in host_oses:
132 timestamp = self.datetime.strftime('%Y-%m-%d %H:%M:%S.%f') 132 timestamp = self.datetime.strftime('%Y-%m-%d %H:%M:%S.%f')
133 self.history.append((host_os, channel, version, timestamp)) 133 self.history.append((host_os, channel, version, timestamp))
134 self.datetime += datetime.timedelta(0, -3600) # one hour earlier 134 self.datetime += datetime.timedelta(0, -3600) # one hour earlier
135 self.datetime += datetime.timedelta(-1) # one day earlier 135 self.datetime += datetime.timedelta(-1) # one day earlier
136 136
137 137
138 class MakeFiles(dict): 138 class MakeFiles(dict):
139 def AddOnlineManifest(self, manifest_string):
140 self['naclsdk_manifest2.json'] = manifest_string
141
139 def Add(self, bundle, add_archive_for_os=OS_MLW, add_json_for_os=OS_MLW): 142 def Add(self, bundle, add_archive_for_os=OS_MLW, add_json_for_os=OS_MLW):
140 for archive in bundle.GetArchives(): 143 for archive in bundle.GetArchives():
141 if not archive.host_os in add_archive_for_os: 144 if not archive.host_os in add_archive_for_os:
142 continue 145 continue
143 146
144 # add a dummy file for each archive 147 # add a dummy file for each archive
145 path = GetPathFromHttpsUrl(archive.url) 148 path = GetPathFromHttpsUrl(archive.url)
146 self[path] = 'My Dummy Archive' 149 self[path] = 'My Dummy Archive'
147 150
148 if archive.host_os in add_json_for_os: 151 if archive.host_os in add_json_for_os:
149 # add .json manifest snippet, it should look like a normal Bundle, but 152 # add .json manifest snippet, it should look like a normal Bundle, but
150 # only has one archive. 153 # only has one archive.
151 new_bundle = manifest_util.Bundle('') 154 new_bundle = manifest_util.Bundle('')
152 new_bundle.CopyFrom(bundle) 155 new_bundle.CopyFrom(bundle)
153 del new_bundle.archives[:] 156 del new_bundle.archives[:]
154 new_bundle.AddArchive(archive) 157 new_bundle.AddArchive(archive)
155 self[path + '.json'] = new_bundle.GetDataAsString() 158 self[path + '.json'] = new_bundle.GetDataAsString()
156 159
157 160
158 class TestDelegate(update_nacl_manifest.Delegate): 161 class TestDelegate(update_nacl_manifest.Delegate):
159 def __init__(self, manifest, history, files, version_mapping): 162 def __init__(self, manifest, history, files, version_mapping):
160 self.manifest = manifest 163 self.manifest = manifest
161 self.history = history 164 self.history = history
162 self.files = files 165 self.files = files
163 self.version_mapping = version_mapping 166 self.version_mapping = version_mapping
164 self.dryrun = 0 167 self.dryrun = 0
168 self.called_gsutil_cp = False
165 169
166 def GetRepoManifest(self): 170 def GetRepoManifest(self):
167 return self.manifest 171 return self.manifest
168 172
169 def GetHistory(self): 173 def GetHistory(self):
170 return self.history 174 return self.history
171 175
172 def GetTrunkRevision(self, version): 176 def GetTrunkRevision(self, version):
173 return self.version_mapping[version] 177 return self.version_mapping[version]
174 178
175 def GsUtil_ls(self, url): 179 def GsUtil_ls(self, url):
176 path = GetPathFromGsUrl(url) 180 path = GetPathFromGsUrl(url)
177 result = [] 181 result = []
178 for filename, _ in self.files.iteritems(): 182 for filename, _ in self.files.iteritems():
179 if filename.startswith(path): 183 if filename.startswith(path):
180 result.append(MakeGsUrl(filename)) 184 result.append(MakeGsUrl(filename))
181 return result 185 return result
182 186
183 def GsUtil_cat(self, url): 187 def GsUtil_cat(self, url):
184 path = GetPathFromGsUrl(url) 188 path = GetPathFromGsUrl(url)
185 if path not in self.files: 189 if path not in self.files:
186 raise subprocess.CalledProcessError(1, 'gsutil cat %s' % (url,)) 190 raise subprocess.CalledProcessError(1, 'gsutil cat %s' % (url,))
187 return self.files[path] 191 return self.files[path]
188 192
189 def GsUtil_cp(self, src, dest, stdin=None): 193 def GsUtil_cp(self, src, dest, stdin=None):
194 self.called_gsutil_cp = True
190 dest_path = GetPathFromGsUrl(dest) 195 dest_path = GetPathFromGsUrl(dest)
191 if src == '-': 196 if src == '-':
192 self.files[dest_path] = stdin 197 self.files[dest_path] = stdin
193 else: 198 else:
194 src_path = GetPathFromGsUrl(src) 199 src_path = GetPathFromGsUrl(src)
195 if src_path not in self.files: 200 if src_path not in self.files:
196 raise subprocess.CalledProcessError(1, 'gsutil cp %s %s' % (src, dest)) 201 raise subprocess.CalledProcessError(1, 'gsutil cp %s %s' % (src, dest))
197 self.files[dest_path] = self.files[src_path] 202 self.files[dest_path] = self.files[src_path]
198 203
199 def Print(self, *args): 204 def Print(self, *args):
(...skipping 30 matching lines...) Expand all
230 self.files = MakeFiles() 235 self.files = MakeFiles()
231 self.version_mapping = {} 236 self.version_mapping = {}
232 self.delegate = None 237 self.delegate = None
233 self.uploaded_manifest = None 238 self.uploaded_manifest = None
234 self.manifest = None 239 self.manifest = None
235 240
236 def _MakeDelegate(self): 241 def _MakeDelegate(self):
237 self.delegate = TestDelegate(self.manifest, self.history.history, 242 self.delegate = TestDelegate(self.manifest, self.history.history,
238 self.files, self.version_mapping) 243 self.files, self.version_mapping)
239 244
240 def _Run(self, host_oses): 245 def _Run(self, host_oses, fixed_bundle_versions=None):
241 update_nacl_manifest.Run(self.delegate, host_oses) 246 update_nacl_manifest.Run(self.delegate, host_oses, fixed_bundle_versions)
242 247
243 def _HasUploadedManifest(self): 248 def _HasUploadedManifest(self):
244 return 'naclsdk_manifest2.json' in self.files 249 return 'naclsdk_manifest2.json' in self.files
245 250
246 def _ReadUploadedManifest(self): 251 def _ReadUploadedManifest(self):
247 self.uploaded_manifest = manifest_util.SDKManifest() 252 self.uploaded_manifest = manifest_util.SDKManifest()
248 self.uploaded_manifest.LoadDataFromString( 253 self.uploaded_manifest.LoadDataFromString(
249 self.files['naclsdk_manifest2.json']) 254 self.files['naclsdk_manifest2.json'])
250 255
251 def _AssertUploadedManifestHasBundle(self, bundle, stability): 256 def _AssertUploadedManifestHasBundle(self, bundle, stability):
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 self.files.Add(B18_0_1025_163_R1_MLW) 528 self.files.Add(B18_0_1025_163_R1_MLW)
524 self.files.Add(B19_0_1084_41_R1_MLW) 529 self.files.Add(B19_0_1084_41_R1_MLW)
525 self._MakeDelegate() 530 self._MakeDelegate()
526 self._Run(OS_MLW) 531 self._Run(OS_MLW)
527 self._ReadUploadedManifest() 532 self._ReadUploadedManifest()
528 p18_bundle = self.uploaded_manifest.GetBundle(B18_R1_NONE.name) 533 p18_bundle = self.uploaded_manifest.GetBundle(B18_R1_NONE.name)
529 self.assertEqual(p18_bundle.stability, POST_STABLE) 534 self.assertEqual(p18_bundle.stability, POST_STABLE)
530 p19_bundle = self.uploaded_manifest.GetBundle(B19_R1_NONE.name) 535 p19_bundle = self.uploaded_manifest.GetBundle(B19_R1_NONE.name)
531 self.assertEqual(p19_bundle.stability, STABLE) 536 self.assertEqual(p19_bundle.stability, STABLE)
532 537
538 def testDontPushIfNoChange(self):
539 # Make an online manifest that already has this bundle.
540 online_manifest = MakeManifest(B18_0_1025_163_R1_MLW)
541 self.files.AddOnlineManifest(online_manifest.GetDataAsString())
542
543 self.manifest = MakeManifest(B18_R1_NONE)
544 self.history.Add(OS_MLW, DEV, V18_0_1025_163)
545 self.files.Add(B18_0_1025_163_R1_MLW)
546
547 self._MakeDelegate()
548 self._Run(OS_MLW)
549 self.assertEqual(False, self.delegate.called_gsutil_cp)
Sam Clegg 2012/11/29 19:39:10 assertFalse() here and below?
binji 2012/11/30 18:55:00 Done.
550
551 def testDontPushIfRollback(self):
552 # Make an online manifest that has a newer bundle
553 online_manifest = MakeManifest(B18_0_1025_184_R1_MLW)
554 self.files.AddOnlineManifest(online_manifest.GetDataAsString())
555
556 self.manifest = MakeManifest(B18_R1_NONE)
557 self.history.Add(OS_MLW, DEV, V18_0_1025_163)
558 self.files.Add(B18_0_1025_163_R1_MLW)
559
560 self._MakeDelegate()
561 self._Run(OS_MLW)
562 self.assertEqual(False, self.delegate.called_gsutil_cp)
563
564 def testRunWithFixedBundleVersions(self):
565 self.manifest = MakeManifest(B18_R1_NONE)
566 self.history.Add(OS_MLW, BETA, V18_0_1025_163)
567 self.files.Add(B18_0_1025_163_R1_MLW)
568 self.files.Add(B18_0_1025_184_R1_MLW)
569
570 self._MakeDelegate()
571 self._Run(OS_MLW, [('pepper_18', '18.0.1025.184')])
572 self._ReadUploadedManifest()
573 self._AssertUploadedManifestHasBundle(B18_0_1025_184_R1_MLW, BETA)
574 self.assertEqual(len(self.uploaded_manifest.GetBundles()), 1)
575
576 def testRunWithMissingFixedBundleVersions(self):
577 self.manifest = MakeManifest(B18_R1_NONE)
578 self.history.Add(OS_MLW, BETA, V18_0_1025_163)
579 self.files.Add(B18_0_1025_163_R1_MLW)
580
581 self._MakeDelegate()
582 self._Run(OS_MLW, [('pepper_18', '18.0.1025.184')])
583 # Nothing should be uploaded if the user gives a missing fixed version.
584 self.assertEqual(False, self.delegate.called_gsutil_cp)
585
533 586
534 class TestUpdateVitals(unittest.TestCase): 587 class TestUpdateVitals(unittest.TestCase):
535 def setUp(self): 588 def setUp(self):
536 f = tempfile.NamedTemporaryFile('w', prefix="test_update_nacl_manifest") 589 f = tempfile.NamedTemporaryFile('w', prefix="test_update_nacl_manifest")
537 self.test_file = f.name 590 self.test_file = f.name
538 f.close() 591 f.close()
539 test_data = "Some test data" 592 test_data = "Some test data"
540 self.sha1 = hashlib.sha1(test_data).hexdigest() 593 self.sha1 = hashlib.sha1(test_data).hexdigest()
541 self.data_len = len(test_data) 594 self.data_len = len(test_data)
542 with open(self.test_file, 'w') as f: 595 with open(self.test_file, 'w') as f:
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 '23.0.1271.89': '167132', 632 '23.0.1271.89': '167132',
580 '24.0.1305.4': '164971', 633 '24.0.1305.4': '164971',
581 } 634 }
582 for version, revision in revision_dict.iteritems(): 635 for version, revision in revision_dict.iteritems():
583 self.assertEqual('trunk.%s' % revision, 636 self.assertEqual('trunk.%s' % revision,
584 self.delegate.GetTrunkRevision(version)) 637 self.delegate.GetTrunkRevision(version))
585 638
586 639
587 if __name__ == '__main__': 640 if __name__ == '__main__':
588 sys.exit(unittest.main()) 641 sys.exit(unittest.main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698