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

Unified Diff: bin/cbuildbot_unittest.py

Issue 4062003: Archive test results and image after running vm suite. (Closed) Base URL: http://git.chromium.org/git/crosutils.git
Patch Set: Remove pass Created 10 years, 2 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « bin/cbuildbot.py ('k') | bin/cros_run_vm_test » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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()
« no previous file with comments | « bin/cbuildbot.py ('k') | bin/cros_run_vm_test » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698