blob: 9173513da6fb8d343c3a1f4a074e4a219ee2ab79 [file] [log] [blame]
Chris Sosa47a7d4e2012-03-28 11:26:55 -07001#!/usr/bin/python
2#
3# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
Gilad Arnoldc65330c2012-09-20 15:17:48 -07007"""Unit tests for build_artifact module.
Chris Sosa47a7d4e2012-03-28 11:26:55 -07008
9These unit tests take tarball from google storage locations to fully test
Chris Sosa76e44b92013-01-31 12:11:38 -080010the artifact download process. Please make sure to set up your boto file.
Chris Sosa47a7d4e2012-03-28 11:26:55 -070011"""
12
Chris Sosa47a7d4e2012-03-28 11:26:55 -070013import os
14import shutil
15import subprocess
16import tempfile
17import unittest
18
Gilad Arnoldabb352e2012-09-23 01:24:27 -070019import mox
20
Gilad Arnoldc65330c2012-09-20 15:17:48 -070021import build_artifact
Chris Sosa47a7d4e2012-03-28 11:26:55 -070022
Gilad Arnoldabb352e2012-09-23 01:24:27 -070023
Chris Sosa76e44b92013-01-31 12:11:38 -080024_VERSION = 'R26-3646.0.0-rc1'
Chris Sosa47a7d4e2012-03-28 11:26:55 -070025_TEST_GOLO_ARCHIVE = (
Chris Sosa76e44b92013-01-31 12:11:38 -080026 'gs://chromeos-image-archive/x86-generic-chromium-pfq/R26-3646.0.0-rc1')
27
28# Different as the above does not have deltas (for smaller artifacts).
29_DELTA_VERSION = 'R26-3645.0.0'
30_TEST_GOLO_FOR_DELTAS = (
31 'gs://chromeos-image-archive/x86-mario-release/R26-3645.0.0')
Yu-Ju Honge61cbe92012-07-10 14:10:26 -070032
Chris Sosa47a7d4e2012-03-28 11:26:55 -070033
Chris Sosa76e44b92013-01-31 12:11:38 -080034# pylint: disable=W0212
Gilad Arnoldc65330c2012-09-20 15:17:48 -070035class BuildArtifactTest(mox.MoxTestBase):
Chris Sosa47a7d4e2012-03-28 11:26:55 -070036
37 def setUp(self):
38 mox.MoxTestBase.setUp(self)
Chris Sosa76e44b92013-01-31 12:11:38 -080039 self.work_dir = tempfile.mkdtemp('build_artifact_unittest')
Chris Sosa47a7d4e2012-03-28 11:26:55 -070040
41 def tearDown(self):
42 shutil.rmtree(self.work_dir)
43
Chris Sosa76e44b92013-01-31 12:11:38 -080044 def testProcessBuildArtifact(self):
45 """Processes a real tarball from GSUtil and stages it."""
Gilad Arnoldc65330c2012-09-20 15:17:48 -070046 artifact = build_artifact.BuildArtifact(
Chris Sosa76e44b92013-01-31 12:11:38 -080047 self.work_dir,
48 _TEST_GOLO_ARCHIVE, build_artifact.TEST_SUITES_FILE, _VERSION)
49 artifact.Process(False)
Chris Sosa47a7d4e2012-03-28 11:26:55 -070050 self.assertTrue(os.path.exists(os.path.join(
Chris Sosa76e44b92013-01-31 12:11:38 -080051 self.work_dir, build_artifact.TEST_SUITES_FILE)))
Chris Sosa47a7d4e2012-03-28 11:26:55 -070052
Chris Sosa76e44b92013-01-31 12:11:38 -080053 def testProcessTarball(self):
Chris Sosa47a7d4e2012-03-28 11:26:55 -070054 """Downloads a real tarball and untars it."""
Gilad Arnoldc65330c2012-09-20 15:17:48 -070055 artifact = build_artifact.TarballBuildArtifact(
Chris Sosa76e44b92013-01-31 12:11:38 -080056 self.work_dir, _TEST_GOLO_ARCHIVE, build_artifact.TEST_SUITES_FILE,
57 _VERSION)
58 artifact.Process(False)
Chris Sosa47a7d4e2012-03-28 11:26:55 -070059 self.assertTrue(os.path.isdir(os.path.join(
Chris Sosa76e44b92013-01-31 12:11:38 -080060 self.work_dir, 'autotest', 'test_suites')))
Chris Sosa47a7d4e2012-03-28 11:26:55 -070061
Chris Sosa76e44b92013-01-31 12:11:38 -080062 def testProcessTarballWithFile(self):
63 """Downloads a real tarball and only untars one file from it."""
64 file_to_download = 'autotest/test_suites/control.au'
65 artifact = build_artifact.TarballBuildArtifact(
66 self.work_dir, _TEST_GOLO_ARCHIVE, build_artifact.TEST_SUITES_FILE,
67 _VERSION, [file_to_download])
68 artifact.Process(False)
69 self.assertTrue(os.path.exists(os.path.join(
70 self.work_dir, file_to_download)))
Chris Sosa47a7d4e2012-03-28 11:26:55 -070071
joychen0a8e34e2013-06-24 17:58:36 -070072 def testDownloadAutotest(self):
Yu-Ju Honge61cbe92012-07-10 14:10:26 -070073 """Downloads a real autotest tarball for test."""
Gilad Arnoldc65330c2012-09-20 15:17:48 -070074 self.mox.StubOutWithMock(build_artifact.AutotestTarballBuildArtifact,
Chris Sosa76e44b92013-01-31 12:11:38 -080075 '_Extract')
76 artifact = build_artifact.AutotestTarballBuildArtifact(
77 self.work_dir, _TEST_GOLO_ARCHIVE, build_artifact.AUTOTEST_FILE,
78 _VERSION, None, ['autotest/test_suites'])
79
joychen0a8e34e2013-06-24 17:58:36 -070080 install_dir = self.work_dir
81 artifact.staging_dir = install_dir
Chris Sosa76e44b92013-01-31 12:11:38 -080082 artifact._Download()
Chris Sosa47a7d4e2012-03-28 11:26:55 -070083 self.mox.StubOutWithMock(subprocess, 'check_call')
Chris Sosa76e44b92013-01-31 12:11:38 -080084 artifact._Extract()
joychen0a8e34e2013-06-24 17:58:36 -070085 subprocess.check_call(mox.In('autotest/utils/packager.py'), cwd=install_dir)
Chris Sosa47a7d4e2012-03-28 11:26:55 -070086 self.mox.ReplayAll()
joychen0a8e34e2013-06-24 17:58:36 -070087 artifact._Setup()
Chris Sosa47a7d4e2012-03-28 11:26:55 -070088 self.mox.VerifyAll()
Chris Sosa76e44b92013-01-31 12:11:38 -080089 self.assertTrue(os.path.isdir(
90 os.path.join(self.work_dir, 'autotest', 'packages')))
Chris Sosa47a7d4e2012-03-28 11:26:55 -070091
Gilad Arnoldc65330c2012-09-20 15:17:48 -070092 def testAUTestPayloadBuildArtifact(self):
Chris Sosa47a7d4e2012-03-28 11:26:55 -070093 """Downloads a real tarball and treats it like an AU payload."""
Gilad Arnoldc65330c2012-09-20 15:17:48 -070094 artifact = build_artifact.AUTestPayloadBuildArtifact(
Chris Sosa76e44b92013-01-31 12:11:38 -080095 self.work_dir, _TEST_GOLO_ARCHIVE, build_artifact.TEST_SUITES_FILE,
96 _VERSION)
97 artifact.Process(False)
Chris Sosa47a7d4e2012-03-28 11:26:55 -070098 self.assertTrue(os.path.exists(os.path.join(
Chris Sosa76e44b92013-01-31 12:11:38 -080099 self.work_dir, 'update.gz')))
100
101 def testDeltaPayloadsArtifact(self):
102 """Downloads delta paylaods from test bucket."""
103 artifact = build_artifact.DeltaPayloadsArtifact(
104 self.work_dir, _TEST_GOLO_FOR_DELTAS, '.*_delta_.*', _DELTA_VERSION)
105 artifact.Process(False)
106 nton_dir = os.path.join(self.work_dir, 'au', '%s_nton' % _DELTA_VERSION)
107 mton_dir = os.path.join(self.work_dir, 'au', '%s_mton' % _DELTA_VERSION)
108 self.assertTrue(os.path.exists(os.path.join(nton_dir, 'update.gz')))
109 self.assertTrue(os.path.exists(os.path.join(mton_dir, 'update.gz')))
110
111 def testImageUnzip(self):
112 """Downloads and stages a zip file and extracts a test image."""
113 artifact = build_artifact.ZipfileBuildArtifact(
114 self.work_dir, _TEST_GOLO_ARCHIVE, build_artifact.IMAGE_FILE,
115 _VERSION, ['chromiumos_test_image.bin'])
116 artifact.Process(False)
Chris Sosa47a7d4e2012-03-28 11:26:55 -0700117 self.assertTrue(os.path.exists(os.path.join(
Chris Sosa76e44b92013-01-31 12:11:38 -0800118 self.work_dir, 'chromiumos_test_image.bin')))
119
120 def testImageUnzipWithExcludes(self):
121 """Downloads and stages a zip file while excluding all large files."""
122 artifact = build_artifact.ZipfileBuildArtifact(
123 self.work_dir, _TEST_GOLO_ARCHIVE, build_artifact.IMAGE_FILE,
124 _VERSION, None, ['*.bin'])
125 artifact.Process(False)
126 self.assertFalse(os.path.exists(os.path.join(
127 self.work_dir, 'chromiumos_test_image.bin')))
Chris Sosa47a7d4e2012-03-28 11:26:55 -0700128
129
130if __name__ == '__main__':
131 unittest.main()