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

Side by Side Diff: bin/cbuildbot_unittest.py

Issue 4864001: Change _ArchiveTestResults to upload to Google Storage (Closed) Base URL: http://git.chromium.org/git/crosutils.git@master
Patch Set: Fix unit test testArchiveTestResults Created 10 years, 1 month 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
« no previous file with comments | « bin/cbuildbot.py ('k') | lib/cros_build_lib.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 2
3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """Unittests for cbuildbot. Needs to be run inside of chroot for mox.""" 7 """Unittests for cbuildbot. Needs to be run inside of chroot for mox."""
8 8
9 import __builtin__ 9 import __builtin__
10 import mox 10 import mox
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 # self._test_dict).AndReturn( 105 # self._test_dict).AndReturn(
106 # self._test_parsed_string_array) 106 # self._test_parsed_string_array)
107 # cbuildbot._UprevFromRevisionList(self._buildroot, 107 # cbuildbot._UprevFromRevisionList(self._buildroot,
108 # self._test_parsed_string_array) 108 # self._test_parsed_string_array)
109 # self.mox.ReplayAll() 109 # self.mox.ReplayAll()
110 # cbuildbot._UprevPackages(self._buildroot, self._revision_file, 110 # cbuildbot._UprevPackages(self._buildroot, self._revision_file,
111 # self._test_board) 111 # self._test_board)
112 # self.mox.VerifyAll() 112 # self.mox.VerifyAll()
113 113
114 def testArchiveTestResults(self): 114 def testArchiveTestResults(self):
115 """Test if we can archive the latest results dir as well as clean up.""" 115 """Test if we can archive the latest results dir to Google Storage."""
116 self.mox.StubOutWithMock(os.path, 'exists')
117 self.mox.StubOutWithMock(os, 'listdir')
118 self.mox.StubOutWithMock(os, 'stat')
119 self.mox.StubOutWithMock(shutil, 'rmtree')
120 self.mox.StubOutWithMock(shutil, 'copytree')
121 self.mox.StubOutWithMock(shutil, 'copyfile')
122
123 # Create mock stats so that file2 is older than file1.
124 dir_listing = ['file1', 'file2']
125 stat1 = self.mox.CreateMock(posix.stat_result)
126 stat2 = self.mox.CreateMock(posix.stat_result)
127 stat1.st_mtime = 99999
128 stat2.st_mtime = 10000
129
130 # Set vars for call. 116 # Set vars for call.
131 buildroot = '/fake_dir' 117 buildroot = '/fake_dir'
118 board = 'fake-board'
132 test_results_dir = 'fake_results_dir' 119 test_results_dir = 'fake_results_dir'
120 gsutil_path='/fake/gsutil/path'
133 archive_dir = 1234 121 archive_dir = 1234
134 board = 'fake-board' 122 acl = 'fake_acl'
135 123 num_retries = 5
136 # Expected calls.
137 os.path.exists(cbuildbot.ARCHIVE_BASE).AndReturn(True)
138 os.listdir(os.path.join(cbuildbot.ARCHIVE_BASE)).AndReturn(dir_listing)
139 os.stat(os.path.join(cbuildbot.ARCHIVE_BASE, 'file1')).AndReturn(stat1)
140 os.stat(os.path.join(cbuildbot.ARCHIVE_BASE, 'file2')).AndReturn(stat2)
141 # Should remove the oldest path.
142 shutil.rmtree(os.path.join(cbuildbot.ARCHIVE_BASE, 'file2'))
143 124
144 # Convenience variables to make archive easier to understand. 125 # Convenience variables to make archive easier to understand.
145 path_to_results = os.path.join(buildroot, 'chroot', test_results_dir) 126 path_to_results = os.path.join(buildroot, 'chroot', test_results_dir)
146 path_to_archive_dir = os.path.join(cbuildbot.ARCHIVE_BASE, str(archive_dir))
147 path_to_image = os.path.join(buildroot, 'src', 'build', 'images', board, 127 path_to_image = os.path.join(buildroot, 'src', 'build', 'images', board,
148 'latest', 'chromiumos_qemu_image.bin') 128 'latest', 'chromiumos_qemu_image.bin')
149 # Archive logic 129
150 os.path.exists(path_to_archive_dir).AndReturn(False)
151 cbuildbot.RunCommand(['sudo', 'chmod', '-R', '+r', path_to_results]) 130 cbuildbot.RunCommand(['sudo', 'chmod', '-R', '+r', path_to_results])
152 shutil.copytree(path_to_results, path_to_archive_dir) 131 cbuildbot.RunCommand([gsutil_path, 'cp', '-R', path_to_results,
132 archive_dir], num_retries=num_retries)
133 cbuildbot.RunCommand([gsutil_path, 'setacl', acl, archive_dir])
153 cbuildbot.RunCommand(['gzip', '-f', '--fast', path_to_image]) 134 cbuildbot.RunCommand(['gzip', '-f', '--fast', path_to_image])
154 shutil.copyfile(path_to_image + '.gz', os.path.join( 135 cbuildbot.RunCommand([gsutil_path, 'cp', path_to_image + '.gz',
155 path_to_archive_dir, 'chromiumos_qemu_image.bin.gz')) 136 archive_dir], num_retries=num_retries)
156 137
157 self.mox.ReplayAll() 138 self.mox.ReplayAll()
158 cbuildbot.ARCHIVE_COUNT = 2 # Set equal to list size so we force clean up. 139 cbuildbot._ArchiveTestResults(buildroot, board, test_results_dir,
159 cbuildbot._ArchiveTestResults(buildroot, board, archive_dir, 140 gsutil_path, archive_dir, acl)
160 test_results_dir)
161 self.mox.VerifyAll() 141 self.mox.VerifyAll()
162 142
163 # TODO(sosa): Remove once we un-comment above. 143 # TODO(sosa): Remove once we un-comment above.
164 def testUprevPackages(self): 144 def testUprevPackages(self):
165 """Test if we get actual revisions in revisions.pfq.""" 145 """Test if we get actual revisions in revisions.pfq."""
166 self.mox.StubOutWithMock(__builtin__, 'open') 146 self.mox.StubOutWithMock(__builtin__, 'open')
167 147
168 # Mock out file interaction. 148 # Mock out file interaction.
169 m_file = self.mox.CreateMock(file) 149 m_file = self.mox.CreateMock(file)
170 __builtin__.open(self._revision_file).AndReturn(m_file) 150 __builtin__.open(self._revision_file).AndReturn(m_file)
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 183
204 self.mox.ReplayAll() 184 self.mox.ReplayAll()
205 cbuildbot._UprevPackages(self._buildroot, self.tracking_branch, 185 cbuildbot._UprevPackages(self._buildroot, self.tracking_branch,
206 self._revision_file, self._test_board, 186 self._revision_file, self._test_board,
207 self._overlays) 187 self._overlays)
208 self.mox.VerifyAll() 188 self.mox.VerifyAll()
209 189
210 190
211 if __name__ == '__main__': 191 if __name__ == '__main__':
212 unittest.main() 192 unittest.main()
OLDNEW
« no previous file with comments | « bin/cbuildbot.py ('k') | lib/cros_build_lib.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698