blob: 61bc880451a12c24e30300a6e3a2b85d4669183f [file] [log] [blame]
Gabe Black3b567202015-09-23 21:07:591#!/usr/bin/python2
Chris Sosa47a7d4e2012-03-28 18:26:552#
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 22:17:487"""Unit tests for downloader module."""
Chris Sosa47a7d4e2012-03-28 18:26:558
Gabe Black3b567202015-09-23 21:07:599from __future__ import print_function
10
Chris Sosa76e44b92013-01-31 20:11:3811import mox
Chris Sosa47a7d4e2012-03-28 18:26:5512import os
13import shutil
14import tempfile
15import unittest
16
Gilad Arnoldc65330c2012-09-20 22:17:4817import build_artifact
Chris Sosa47a7d4e2012-03-28 18:26:5518import downloader
19
20
Chris Sosa76e44b92013-01-31 20:11:3821# pylint: disable=W0212,E1120
Chris Masone816e38c2012-05-02 19:22:3622class DownloaderTestBase(mox.MoxTestBase):
Simran Basi4243a862014-12-12 20:48:3323 """Downloader Unittests."""
Chris Sosa47a7d4e2012-03-28 18:26:5524
25 def setUp(self):
26 mox.MoxTestBase.setUp(self)
27 self._work_dir = tempfile.mkdtemp('downloader-test')
Chris Sosa76e44b92013-01-31 20:11:3828 self.board = 'x86-mario-release'
Chris Sosa47a7d4e2012-03-28 18:26:5529 self.build = 'R17-1413.0.0-a1-b1346'
Chris Sosa76e44b92013-01-31 20:11:3830 self.archive_url = (
31 'gs://chromeos-image-archive/%s/%s' % (self.board, self.build))
Simran Basi4243a862014-12-12 20:48:3332 self.local_path = ('/local/path/x86-mario-release/R17-1413.0.0-a1-b1346')
Chris Sosa47a7d4e2012-03-28 18:26:5533
34 def tearDown(self):
Gilad Arnold0b8c3f32012-09-19 21:35:4435 shutil.rmtree(self._work_dir, ignore_errors=True)
Chris Sosa47a7d4e2012-03-28 18:26:5536
Gabe Black3b567202015-09-23 21:07:5937 def _SimpleDownloadOfTestSuites(self, downloader_instance):
Simran Basi4243a862014-12-12 20:48:3338 """Helper to verify test_suites are downloaded correctly.
Chris Sosa47a7d4e2012-03-28 18:26:5539
Simran Basi4243a862014-12-12 20:48:3340 Args:
Gabe Black3b567202015-09-23 21:07:5941 downloader_instance: Downloader object to test with.
Chris Sosa47a7d4e2012-03-28 18:26:5542 """
Gabe Black3b567202015-09-23 21:07:5943 factory = build_artifact.ChromeOSArtifactFactory(
44 downloader_instance.GetBuildDir(), ['test_suites'],
45 None, downloader_instance.GetBuild())
Chris Sosa76e44b92013-01-31 20:11:3846 self.mox.StubOutWithMock(downloader.Downloader,
47 '_DownloadArtifactsSerially')
48 self.mox.StubOutWithMock(downloader.Downloader,
49 '_DownloadArtifactsInBackground')
Chris Sosa47a7d4e2012-03-28 18:26:5550
Chris Sosa76e44b92013-01-31 20:11:3851 downloader.Downloader._DownloadArtifactsInBackground(mox.In(mox.IsA(
Gabe Black3b567202015-09-23 21:07:5952 build_artifact.AutotestTarball)))
Chris Sosa76e44b92013-01-31 20:11:3853 downloader.Downloader._DownloadArtifactsSerially(
Gabe Black3b567202015-09-23 21:07:5954 [mox.IsA(build_artifact.BundledArtifact)], no_wait=True)
Chris Sosa47a7d4e2012-03-28 18:26:5555 self.mox.ReplayAll()
Gabe Black3b567202015-09-23 21:07:5956 downloader_instance.Download(factory)
Chris Sosa76e44b92013-01-31 20:11:3857 # Sanity check the timestamp file exists.
Alex Millera44d5022012-07-27 18:34:1658 self.assertTrue(os.path.exists(
Chris Sosa76e44b92013-01-31 20:11:3859 os.path.join(self._work_dir, self.board, self.build,
60 downloader.Downloader._TIMESTAMP_FILENAME)))
61 self.mox.VerifyAll()
Chris Sosa9164ca32012-03-28 18:04:5062
Simran Basi4243a862014-12-12 20:48:3363 def testSimpleDownloadOfTestSuitesFromGS(self):
64 """Basic test_suites test.
65
66 Verifies that if we request the test_suites from Google Storage, it gets
67 downloaded and the autotest tarball is attempted in the background.
68 """
Gabe Black3b567202015-09-23 21:07:5969 self._SimpleDownloadOfTestSuites(
70 downloader.GoogleStorageDownloader(self._work_dir, self.archive_url))
Simran Basi4243a862014-12-12 20:48:3371
72 def testSimpleDownloadOfTestSuitesFromLocal(self):
73 """Basic test_suites test.
74
75 Verifies that if we request the test_suites from a local path, it gets
76 downloaded and the autotest tarball is attempted in the background.
77 """
Gabe Black3b567202015-09-23 21:07:5978 self._SimpleDownloadOfTestSuites(
79 downloader.LocalDownloader(self._work_dir, self.local_path))
Simran Basi4243a862014-12-12 20:48:3380
Gabe Black3b567202015-09-23 21:07:5981 def _DownloadSymbolsHelper(self, downloader_instance):
Chris Sosa76e44b92013-01-31 20:11:3882 """Basic symbols download."""
Gabe Black3b567202015-09-23 21:07:5983 factory = build_artifact.ChromeOSArtifactFactory(
84 downloader_instance.GetBuildDir(), ['symbols'],
85 None, downloader_instance.GetBuild())
86
Chris Sosa76e44b92013-01-31 20:11:3887 self.mox.StubOutWithMock(downloader.Downloader,
88 '_DownloadArtifactsSerially')
89 # Should not get called but mocking so that we know it wasn't called.
90 self.mox.StubOutWithMock(downloader.Downloader,
91 '_DownloadArtifactsInBackground')
92 downloader.Downloader._DownloadArtifactsSerially(
Gabe Black3b567202015-09-23 21:07:5993 [mox.IsA(build_artifact.BundledArtifact)], no_wait=True)
Chris Masone816e38c2012-05-02 19:22:3694 self.mox.ReplayAll()
Gabe Black3b567202015-09-23 21:07:5995 downloader_instance.Download(factory)
Chris Masone816e38c2012-05-02 19:22:3696 self.mox.VerifyAll()
97
Simran Basi4243a862014-12-12 20:48:3398 def testDownloadSymbolsFromGS(self):
99 """Basic symbols download from Google Storage."""
Gabe Black3b567202015-09-23 21:07:59100 self._DownloadSymbolsHelper(
101 downloader.GoogleStorageDownloader(self._work_dir, self.archive_url))
Simran Basi4243a862014-12-12 20:48:33102
103 def testDownloadSymbolsFromLocal(self):
104 """Basic symbols download from a Local Path."""
Gabe Black3b567202015-09-23 21:07:59105 self._DownloadSymbolsHelper(
106 downloader.LocalDownloader(self._work_dir, self.local_path))
107
108
109class AndroidDownloaderTestBase(mox.MoxTestBase):
110 """Android Downloader Unittests."""
111
112 def setUp(self):
113 mox.MoxTestBase.setUp(self)
114 self._work_dir = tempfile.mkdtemp('downloader-test')
Dan Shi72b16132015-10-08 19:10:33115 self.branch = 'release'
Gabe Black3b567202015-09-23 21:07:59116 self.target = 'shamu-userdebug'
117 self.build_id = '123456'
118
119 def tearDown(self):
120 shutil.rmtree(self._work_dir, ignore_errors=True)
121
Dan Shi72b16132015-10-08 19:10:33122 def testDownloadFromAndroidBuildServer(self):
123 """Basic test to check download from Android's build server works."""
124 downloader_instance = downloader.AndroidBuildDownloader(
125 self._work_dir, self.branch, self.build_id, self.target)
Gabe Black3b567202015-09-23 21:07:59126 factory = build_artifact.AndroidArtifactFactory(
127 downloader_instance.GetBuildDir(), ['fastboot'],
128 None, downloader_instance.GetBuild())
129 self.mox.StubOutWithMock(downloader.Downloader,
130 '_DownloadArtifactsSerially')
131 self.mox.StubOutWithMock(downloader.Downloader,
132 '_DownloadArtifactsInBackground')
133
Gabe Black3b567202015-09-23 21:07:59134 downloader.Downloader._DownloadArtifactsSerially(
135 [mox.IsA(build_artifact.Artifact)], no_wait=True)
136 self.mox.ReplayAll()
137 downloader_instance.Download(factory)
138 # Sanity check the timestamp file exists.
139 self.assertTrue(os.path.exists(
Dan Shi72b16132015-10-08 19:10:33140 os.path.join(self._work_dir, self.branch, self.target, self.build_id,
Gabe Black3b567202015-09-23 21:07:59141 downloader.Downloader._TIMESTAMP_FILENAME)))
142 self.mox.VerifyAll()
Simran Basi4243a862014-12-12 20:48:33143
Chris Masone816e38c2012-05-02 19:22:36144
Chris Sosa47a7d4e2012-03-28 18:26:55145if __name__ == '__main__':
146 unittest.main()