| Index: bin/cbuildbot_unittest.py
|
| diff --git a/bin/cbuildbot_unittest.py b/bin/cbuildbot_unittest.py
|
| index 57742b9c780a3f044e12b27f15a014199d311ec8..e699f0c9cb496c6d8726b6db6d86cf47bf9f5542 100755
|
| --- a/bin/cbuildbot_unittest.py
|
| +++ b/bin/cbuildbot_unittest.py
|
| @@ -8,6 +8,9 @@
|
|
|
| import __builtin__
|
| import mox
|
| +import os
|
| +import posix
|
| +import shutil
|
| import unittest
|
|
|
| # Fixes circular dependency error.
|
| @@ -20,6 +23,7 @@ class CBuildBotTest(mox.MoxTestBase):
|
| mox.MoxTestBase.setUp(self)
|
| # Always stub RunCommmand out as we use it in every method.
|
| self.mox.StubOutWithMock(cbuildbot, 'RunCommand')
|
| + self.tracking_branch = 'cros/master'
|
| self._test_repos = [['kernel', 'third_party/kernel/files'],
|
| ['login_manager', 'platform/login_manager']
|
| ]
|
| @@ -102,6 +106,55 @@ class CBuildBotTest(mox.MoxTestBase):
|
| # self._test_board)
|
| # self.mox.VerifyAll()
|
|
|
| + def testArchiveTestResults(self):
|
| + """Test if we can archive the latest results dir as well as clean up."""
|
| + self.mox.StubOutWithMock(os.path, 'exists')
|
| + self.mox.StubOutWithMock(os, 'listdir')
|
| + self.mox.StubOutWithMock(os, 'stat')
|
| + self.mox.StubOutWithMock(shutil, 'rmtree')
|
| + self.mox.StubOutWithMock(shutil, 'copytree')
|
| + self.mox.StubOutWithMock(shutil, 'copyfile')
|
| +
|
| + # Create mock stats so that file2 is older than file1.
|
| + dir_listing = ['file1', 'file2']
|
| + stat1 = self.mox.CreateMock(posix.stat_result)
|
| + stat2 = self.mox.CreateMock(posix.stat_result)
|
| + stat1.st_mtime = 99999
|
| + stat2.st_mtime = 10000
|
| +
|
| + # Set vars for call.
|
| + buildroot = '/fake_dir'
|
| + test_results_dir = 'fake_results_dir'
|
| + archive_dir = 1234
|
| + board = 'fake-board'
|
| +
|
| + # Expected calls.
|
| + os.path.exists(cbuildbot.ARCHIVE_BASE).AndReturn(True)
|
| + os.listdir(os.path.join(cbuildbot.ARCHIVE_BASE)).AndReturn(dir_listing)
|
| + os.stat('file1').AndReturn(stat1)
|
| + os.stat('file2').AndReturn(stat2)
|
| + # Should remove the oldest path.
|
| + shutil.rmtree(os.path.join(cbuildbot.ARCHIVE_BASE, 'file2'))
|
| +
|
| + # Convenience variables to make archive easier to understand.
|
| + path_to_results = os.path.join(buildroot, 'chroot', test_results_dir)
|
| + path_to_archive_dir = os.path.join(cbuildbot.ARCHIVE_BASE, str(archive_dir))
|
| + path_to_image = os.path.join(buildroot, 'src', 'build', 'images', board,
|
| + 'latest', 'chromiumos_qemu_image.bin')
|
| + # Archive logic
|
| + os.path.exists(path_to_archive_dir).AndReturn(False)
|
| + cbuildbot.RunCommand(['sudo', 'chmod', '-R', '+r', path_to_results])
|
| + shutil.copytree(path_to_results, path_to_archive_dir)
|
| + cbuildbot.RunCommand(['gzip', '-f', path_to_image])
|
| + shutil.copyfile(path_to_image + '.gz', os.path.join(
|
| + path_to_archive_dir, 'chromiumos_qemu_image.bin.gz'))
|
| +
|
| + self.mox.ReplayAll()
|
| + cbuildbot.ARCHIVE_COUNT = 2 # Set equal to list size so we force clean up.
|
| + cbuildbot._ArchiveTestResults(buildroot, board, archive_dir,
|
| + test_results_dir)
|
| + self.mox.VerifyAll()
|
| +
|
| # TODO(sosa): Remove once we un-comment above.
|
| def testUprevPackages(self):
|
| """Test if we get actual revisions in revisions.pfq."""
|
| @@ -114,13 +167,14 @@ class CBuildBotTest(mox.MoxTestBase):
|
| m_file.close()
|
|
|
| cbuildbot.RunCommand(['./cros_mark_as_stable', '--all',
|
| + '--board=%s' % self._test_board,
|
| '--tracking_branch="cros/master"', 'commit'],
|
| cwd='%s/src/scripts' % self._buildroot,
|
| enter_chroot=True)
|
|
|
| self.mox.ReplayAll()
|
| - cbuildbot._UprevPackages(self._buildroot, self._revision_file,
|
| - self._test_board)
|
| + cbuildbot._UprevPackages(self._buildroot, self.tracking_branch,
|
| + self._revision_file, self._test_board)
|
| self.mox.VerifyAll()
|
|
|
| def testUprevAllPackages(self):
|
| @@ -134,13 +188,14 @@ class CBuildBotTest(mox.MoxTestBase):
|
| m_file.close()
|
|
|
| cbuildbot.RunCommand(['./cros_mark_as_stable', '--all',
|
| + '--board=%s' % self._test_board,
|
| '--tracking_branch="cros/master"', 'commit'],
|
| cwd='%s/src/scripts' % self._buildroot,
|
| enter_chroot=True)
|
|
|
| self.mox.ReplayAll()
|
| - cbuildbot._UprevPackages(self._buildroot, self._revision_file,
|
| - self._test_board)
|
| + cbuildbot._UprevPackages(self._buildroot, self.tracking_branch,
|
| + self._revision_file, self._test_board)
|
| self.mox.VerifyAll()
|
|
|
|
|
|
|