blob: 01c52fa9d5b490eb5176de9d3b9f1df84047e018 [file] [log] [blame]
Mike Frysingere58c0e22017-10-04 15:43:30 -04001# -*- coding: utf-8 -*-
Ryan Cuiafd6c5c2012-07-30 17:48:22 -07002# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
Steve Funge984a532013-11-25 17:09:25 -08006"""Unit tests for the deploy_chrome script."""
Ryan Cuiafd6c5c2012-07-30 17:48:22 -07007
Mike Frysinger383367e2014-09-16 15:06:17 -04008from __future__ import print_function
9
Anushruth8d797672019-10-17 12:22:31 -070010import errno
Ryan Cuiafd6c5c2012-07-30 17:48:22 -070011import os
Mike Frysinger6165cdc2020-02-21 02:38:07 -050012import sys
David James88e6f032013-03-02 08:13:20 -080013import time
Ryan Cuiafd6c5c2012-07-30 17:48:22 -070014
Mike Frysinger6db648e2018-07-24 19:57:58 -040015import mock
16
David Pursellcfd58872015-03-19 09:15:48 -070017from chromite.cli.cros import cros_chrome_sdk_unittest
Ryan Cuief91e702013-02-04 12:06:36 -080018from chromite.lib import chrome_util
Ryan Cuiafd6c5c2012-07-30 17:48:22 -070019from chromite.lib import cros_build_lib
20from chromite.lib import cros_test_lib
Ryan Cui686ec052013-02-12 16:39:41 -080021from chromite.lib import osutils
Ryan Cuiafd6c5c2012-07-30 17:48:22 -070022from chromite.lib import partial_mock
Robert Flack1dc7ea82014-11-26 13:50:24 -050023from chromite.lib import remote_access
Ryan Cuiafd6c5c2012-07-30 17:48:22 -070024from chromite.lib import remote_access_unittest
25from chromite.scripts import deploy_chrome
26
Ryan Cuief91e702013-02-04 12:06:36 -080027
Mike Frysinger6165cdc2020-02-21 02:38:07 -050028assert sys.version_info >= (3, 6), 'This module requires Python 3.6+'
29
30
Mike Frysinger27e21b72018-07-12 14:20:21 -040031# pylint: disable=protected-access
32
Ryan Cuiafd6c5c2012-07-30 17:48:22 -070033
34_REGULAR_TO = ('--to', 'monkey')
35_GS_PATH = 'gs://foon'
36
37
38def _ParseCommandLine(argv):
39 return deploy_chrome._ParseCommandLine(['--log-level', 'debug'] + argv)
40
41
42class InterfaceTest(cros_test_lib.OutputTestCase):
43 """Tests the commandline interface of the script."""
44
Malay Keshave7a071e2020-05-21 20:07:44 +000045 BOARD = 'eve'
46
Ryan Cuiafd6c5c2012-07-30 17:48:22 -070047 def testGsLocalPathUnSpecified(self):
48 """Test no chrome path specified."""
49 with self.OutputCapturer():
Malay Keshave7a071e2020-05-21 20:07:44 +000050 self.assertRaises2(SystemExit, _ParseCommandLine, list(_REGULAR_TO),
Ryan Cuiafd6c5c2012-07-30 17:48:22 -070051 check_attrs={'code': 2})
52
53 def testGsPathSpecified(self):
54 """Test case of GS path specified."""
Malay Keshave7a071e2020-05-21 20:07:44 +000055 argv = list(_REGULAR_TO) + ['--gs-path', _GS_PATH]
Ryan Cuiafd6c5c2012-07-30 17:48:22 -070056 _ParseCommandLine(argv)
57
58 def testLocalPathSpecified(self):
59 """Test case of local path specified."""
Malay Keshave7a071e2020-05-21 20:07:44 +000060 argv = list(_REGULAR_TO) + ['--local-pkg-path', '/path/to/chrome']
Ryan Cuiafd6c5c2012-07-30 17:48:22 -070061 _ParseCommandLine(argv)
62
63 def testNoTarget(self):
64 """Test no target specified."""
Malay Keshave7a071e2020-05-21 20:07:44 +000065 argv = ['--gs-path', _GS_PATH]
Ryan Cuief91e702013-02-04 12:06:36 -080066 self.assertParseError(argv)
67
68 def assertParseError(self, argv):
Ryan Cuiafd6c5c2012-07-30 17:48:22 -070069 with self.OutputCapturer():
70 self.assertRaises2(SystemExit, _ParseCommandLine, argv,
71 check_attrs={'code': 2})
72
Malay Keshave7a071e2020-05-21 20:07:44 +000073 def testNoBoard(self):
74 """Test cases where --board is not specified."""
75 argv = ['--staging-only', '--build-dir=/path/to/nowhere']
76 self.assertParseError(argv)
77
78 # Don't need --board if no stripping is necessary.
79 argv_nostrip = argv + ['--nostrip']
80 _ParseCommandLine(argv_nostrip)
81
82 # Don't need --board if strip binary is provided.
83 argv_strip_bin = argv + ['--strip-bin', 'strip.bin']
84 _ParseCommandLine(argv_strip_bin)
85
Thiago Goncales12793312013-05-23 11:26:17 -070086 def testMountOptionSetsTargetDir(self):
Malay Keshave7a071e2020-05-21 20:07:44 +000087 argv = list(_REGULAR_TO) + ['--gs-path', _GS_PATH, '--mount']
Mike Frysingerc3061a62015-06-04 04:16:18 -040088 options = _ParseCommandLine(argv)
Thiago Goncales12793312013-05-23 11:26:17 -070089 self.assertIsNot(options.target_dir, None)
90
91 def testMountOptionSetsMountDir(self):
Malay Keshave7a071e2020-05-21 20:07:44 +000092 argv = list(_REGULAR_TO) + ['--gs-path', _GS_PATH, '--mount']
Mike Frysingerc3061a62015-06-04 04:16:18 -040093 options = _ParseCommandLine(argv)
Thiago Goncales12793312013-05-23 11:26:17 -070094 self.assertIsNot(options.mount_dir, None)
95
96 def testMountOptionDoesNotOverrideTargetDir(self):
Malay Keshave7a071e2020-05-21 20:07:44 +000097 argv = list(_REGULAR_TO) + ['--gs-path', _GS_PATH, '--mount',
98 '--target-dir', '/foo/bar/cow']
Mike Frysingerc3061a62015-06-04 04:16:18 -040099 options = _ParseCommandLine(argv)
Thiago Goncales12793312013-05-23 11:26:17 -0700100 self.assertEqual(options.target_dir, '/foo/bar/cow')
101
102 def testMountOptionDoesNotOverrideMountDir(self):
Malay Keshave7a071e2020-05-21 20:07:44 +0000103 argv = list(_REGULAR_TO) + ['--gs-path', _GS_PATH, '--mount',
104 '--mount-dir', '/foo/bar/cow']
Mike Frysingerc3061a62015-06-04 04:16:18 -0400105 options = _ParseCommandLine(argv)
Thiago Goncales12793312013-05-23 11:26:17 -0700106 self.assertEqual(options.mount_dir, '/foo/bar/cow')
107
Adrian Eldera2c548a2017-11-07 19:01:29 -0500108 def testSshIdentityOptionSetsOption(self):
Malay Keshave7a071e2020-05-21 20:07:44 +0000109 argv = list(_REGULAR_TO) + ['--private-key', '/foo/bar/key',
110 '--board', 'cedar',
Bernie Thompson93b9ee62018-02-21 14:56:16 -0800111 '--build-dir', '/path/to/nowhere']
Adrian Eldera2c548a2017-11-07 19:01:29 -0500112 options = _ParseCommandLine(argv)
113 self.assertEqual(options.private_key, '/foo/bar/key')
Ryan Cuiafd6c5c2012-07-30 17:48:22 -0700114
115class DeployChromeMock(partial_mock.PartialMock):
Steve Funge984a532013-11-25 17:09:25 -0800116 """Deploy Chrome Mock Class."""
Ryan Cuiafd6c5c2012-07-30 17:48:22 -0700117
118 TARGET = 'chromite.scripts.deploy_chrome.DeployChrome'
David James88e6f032013-03-02 08:13:20 -0800119 ATTRS = ('_KillProcsIfNeeded', '_DisableRootfsVerification')
Ryan Cuiafd6c5c2012-07-30 17:48:22 -0700120
David James88e6f032013-03-02 08:13:20 -0800121 def __init__(self):
Ryan Cuiafd6c5c2012-07-30 17:48:22 -0700122 partial_mock.PartialMock.__init__(self)
Robert Flack1dc7ea82014-11-26 13:50:24 -0500123 self.remote_device_mock = remote_access_unittest.RemoteDeviceMock()
Ryan Cuiafd6c5c2012-07-30 17:48:22 -0700124 # Target starts off as having rootfs verification enabled.
Ryan Cuie18f24f2012-12-03 18:39:55 -0800125 self.rsh_mock = remote_access_unittest.RemoteShMock()
David James88e6f032013-03-02 08:13:20 -0800126 self.rsh_mock.SetDefaultCmdResult(0)
Ryan Cuiafd6c5c2012-07-30 17:48:22 -0700127 self.MockMountCmd(1)
David Haddock3151d912017-10-24 03:50:32 +0000128 self.rsh_mock.AddCmdResult(
Anushruth8d797672019-10-17 12:22:31 -0700129 deploy_chrome.LSOF_COMMAND_CHROME % (deploy_chrome._CHROME_DIR,), 1)
Ryan Cuiafd6c5c2012-07-30 17:48:22 -0700130
131 def MockMountCmd(self, returnvalue):
Ryan Cuiafd6c5c2012-07-30 17:48:22 -0700132 self.rsh_mock.AddCmdResult(deploy_chrome.MOUNT_RW_COMMAND,
David James88e6f032013-03-02 08:13:20 -0800133 returnvalue)
134
135 def _DisableRootfsVerification(self, inst):
136 with mock.patch.object(time, 'sleep'):
137 self.backup['_DisableRootfsVerification'](inst)
Ryan Cuiafd6c5c2012-07-30 17:48:22 -0700138
Ryan Cui4d6fca92012-12-13 16:41:56 -0800139 def PreStart(self):
Robert Flack1dc7ea82014-11-26 13:50:24 -0500140 self.remote_device_mock.start()
Ryan Cui4d6fca92012-12-13 16:41:56 -0800141 self.rsh_mock.start()
Ryan Cuiafd6c5c2012-07-30 17:48:22 -0700142
Ryan Cui4d6fca92012-12-13 16:41:56 -0800143 def PreStop(self):
144 self.rsh_mock.stop()
Robert Flack1dc7ea82014-11-26 13:50:24 -0500145 self.remote_device_mock.stop()
Ryan Cuiafd6c5c2012-07-30 17:48:22 -0700146
Ryan Cuiafd6c5c2012-07-30 17:48:22 -0700147 def _KillProcsIfNeeded(self, _inst):
148 # Fully stub out for now.
149 pass
150
151
Ryan Cuief91e702013-02-04 12:06:36 -0800152class DeployTest(cros_test_lib.MockTempDirTestCase):
Steve Funge984a532013-11-25 17:09:25 -0800153 """Setup a deploy object with a GS-path for use in tests."""
154
Ryan Cuief91e702013-02-04 12:06:36 -0800155 def _GetDeployChrome(self, args):
Mike Frysingerc3061a62015-06-04 04:16:18 -0400156 options = _ParseCommandLine(args)
Ryan Cuia56a71e2012-10-18 18:40:35 -0700157 return deploy_chrome.DeployChrome(
158 options, self.tempdir, os.path.join(self.tempdir, 'staging'))
Ryan Cuiafd6c5c2012-07-30 17:48:22 -0700159
160 def setUp(self):
Ryan Cuif1416f32013-01-22 18:43:41 -0800161 self.deploy_mock = self.StartPatcher(DeployChromeMock())
Malay Keshave7a071e2020-05-21 20:07:44 +0000162 self.deploy = self._GetDeployChrome(
163 list(_REGULAR_TO) + ['--gs-path', _GS_PATH, '--force', '--mount'])
Luigi Semenzato1bc79b22016-11-22 16:32:17 -0800164 self.remote_reboot_mock = \
165 self.PatchObject(remote_access.RemoteAccess, 'RemoteReboot',
166 return_value=True)
Ryan Cuiafd6c5c2012-07-30 17:48:22 -0700167
David James88e6f032013-03-02 08:13:20 -0800168class TestDisableRootfsVerification(DeployTest):
Ryan Cuiafd6c5c2012-07-30 17:48:22 -0700169 """Testing disabling of rootfs verification and RO mode."""
170
David James88e6f032013-03-02 08:13:20 -0800171 def testDisableRootfsVerificationSuccess(self):
172 """Test the working case, disabling rootfs verification."""
173 self.deploy_mock.MockMountCmd(0)
174 self.deploy._DisableRootfsVerification()
Steven Bennettsca73efa2018-07-10 13:36:56 -0700175 self.assertFalse(self.deploy._root_dir_is_still_readonly.is_set())
Ryan Cuiafd6c5c2012-07-30 17:48:22 -0700176
177 def testDisableRootfsVerificationFailure(self):
178 """Test failure to disable rootfs verification."""
Mike Frysinger27e21b72018-07-12 14:20:21 -0400179 # pylint: disable=unused-argument
Shuqian Zhao14e61092017-11-17 00:02:16 +0000180 def RaiseRunCommandError(timeout_sec=None):
Mike Frysinger929f3ba2019-09-12 03:24:59 -0400181 raise cros_build_lib.RunCommandError('Mock RunCommandError')
Luigi Semenzato1bc79b22016-11-22 16:32:17 -0800182 self.remote_reboot_mock.side_effect = RaiseRunCommandError
Ryan Cuiafd6c5c2012-07-30 17:48:22 -0700183 self.assertRaises(cros_build_lib.RunCommandError,
David James88e6f032013-03-02 08:13:20 -0800184 self.deploy._DisableRootfsVerification)
Luigi Semenzato1bc79b22016-11-22 16:32:17 -0800185 self.remote_reboot_mock.side_effect = None
Steven Bennettsca73efa2018-07-10 13:36:56 -0700186 self.assertFalse(self.deploy._root_dir_is_still_readonly.is_set())
David James88e6f032013-03-02 08:13:20 -0800187
188
189class TestMount(DeployTest):
190 """Testing mount success and failure."""
191
192 def testSuccess(self):
193 """Test case where we are able to mount as writable."""
Steven Bennettsca73efa2018-07-10 13:36:56 -0700194 self.assertFalse(self.deploy._root_dir_is_still_readonly.is_set())
David James88e6f032013-03-02 08:13:20 -0800195 self.deploy_mock.MockMountCmd(0)
196 self.deploy._MountRootfsAsWritable()
Steven Bennettsca73efa2018-07-10 13:36:56 -0700197 self.assertFalse(self.deploy._root_dir_is_still_readonly.is_set())
David James88e6f032013-03-02 08:13:20 -0800198
199 def testMountError(self):
200 """Test that mount failure doesn't raise an exception by default."""
Steven Bennettsca73efa2018-07-10 13:36:56 -0700201 self.assertFalse(self.deploy._root_dir_is_still_readonly.is_set())
Malay Keshave7a071e2020-05-21 20:07:44 +0000202 self.PatchObject(remote_access.RemoteDevice, 'IsDirWritable',
Robert Flack1dc7ea82014-11-26 13:50:24 -0500203 return_value=False, autospec=True)
David James88e6f032013-03-02 08:13:20 -0800204 self.deploy._MountRootfsAsWritable()
Steven Bennettsca73efa2018-07-10 13:36:56 -0700205 self.assertTrue(self.deploy._root_dir_is_still_readonly.is_set())
Ryan Cuiafd6c5c2012-07-30 17:48:22 -0700206
207 def testMountRwFailure(self):
Mike Frysingerf5a3b2d2019-12-12 14:36:17 -0500208 """Test that mount failure raises an exception if check=True."""
David James88e6f032013-03-02 08:13:20 -0800209 self.assertRaises(cros_build_lib.RunCommandError,
Mike Frysingerf5a3b2d2019-12-12 14:36:17 -0500210 self.deploy._MountRootfsAsWritable, check=True)
Steven Bennettsca73efa2018-07-10 13:36:56 -0700211 self.assertFalse(self.deploy._root_dir_is_still_readonly.is_set())
Robert Flack1dc7ea82014-11-26 13:50:24 -0500212
213 def testMountTempDir(self):
214 """Test that mount succeeds if target dir is writable."""
Steven Bennettsca73efa2018-07-10 13:36:56 -0700215 self.assertFalse(self.deploy._root_dir_is_still_readonly.is_set())
Malay Keshave7a071e2020-05-21 20:07:44 +0000216 self.PatchObject(remote_access.RemoteDevice, 'IsDirWritable',
Robert Flack1dc7ea82014-11-26 13:50:24 -0500217 return_value=True, autospec=True)
218 self.deploy._MountRootfsAsWritable()
Steven Bennettsca73efa2018-07-10 13:36:56 -0700219 self.assertFalse(self.deploy._root_dir_is_still_readonly.is_set())
Ryan Cuiafd6c5c2012-07-30 17:48:22 -0700220
221
Anushruth8d797672019-10-17 12:22:31 -0700222class TestMountTarget(DeployTest):
Mike Frysingerdf1d0b02019-11-12 17:44:12 -0500223 """Testing mount and umount command handling."""
Anushruth8d797672019-10-17 12:22:31 -0700224
225 def testMountTargetUmountFailure(self):
226 """Test error being thrown if umount fails.
227
228 Test that 'lsof' is run on mount-dir and 'mount -rbind' command is not run
229 if 'umount' cmd fails.
230 """
231 mount_dir = self.deploy.options.mount_dir
232 target_dir = self.deploy.options.target_dir
233 self.deploy_mock.rsh_mock.AddCmdResult(
234 deploy_chrome._UMOUNT_DIR_IF_MOUNTPOINT_CMD %
235 {'dir': mount_dir}, returncode=errno.EBUSY, stderr='Target is Busy')
236 self.deploy_mock.rsh_mock.AddCmdResult(deploy_chrome.LSOF_COMMAND %
237 (mount_dir,), returncode=0,
238 stdout='process ' + mount_dir)
239 # Check for RunCommandError being thrown.
240 self.assertRaises(cros_build_lib.RunCommandError,
241 self.deploy._MountTarget)
242 # Check for the 'mount -rbind' command not run.
243 self.deploy_mock.rsh_mock.assertCommandContains(
244 (deploy_chrome._BIND_TO_FINAL_DIR_CMD % (target_dir, mount_dir)),
245 expected=False)
246 # Check for lsof command being called.
247 self.deploy_mock.rsh_mock.assertCommandContains(
248 (deploy_chrome.LSOF_COMMAND % (mount_dir,)))
249
250
Ryan Cuief91e702013-02-04 12:06:36 -0800251class TestUiJobStarted(DeployTest):
Ryan Cuiafd6c5c2012-07-30 17:48:22 -0700252 """Test detection of a running 'ui' job."""
253
Ryan Cuif2d1a582013-02-19 14:08:13 -0800254 def MockStatusUiCmd(self, **kwargs):
David Haddock3151d912017-10-24 03:50:32 +0000255 self.deploy_mock.rsh_mock.AddCmdResult('status ui', **kwargs)
Ryan Cuiafd6c5c2012-07-30 17:48:22 -0700256
257 def testUiJobStartedFalse(self):
258 """Correct results with a stopped job."""
Ryan Cuif2d1a582013-02-19 14:08:13 -0800259 self.MockStatusUiCmd(output='ui stop/waiting')
260 self.assertFalse(self.deploy._CheckUiJobStarted())
261
262 def testNoUiJob(self):
263 """Correct results when the job doesn't exist."""
264 self.MockStatusUiCmd(error='start: Unknown job: ui', returncode=1)
Ryan Cuiafd6c5c2012-07-30 17:48:22 -0700265 self.assertFalse(self.deploy._CheckUiJobStarted())
266
267 def testCheckRootfsWriteableTrue(self):
268 """Correct results with a running job."""
Ryan Cuif2d1a582013-02-19 14:08:13 -0800269 self.MockStatusUiCmd(output='ui start/running, process 297')
Ryan Cuiafd6c5c2012-07-30 17:48:22 -0700270 self.assertTrue(self.deploy._CheckUiJobStarted())
271
272
Ryan Cuief91e702013-02-04 12:06:36 -0800273class StagingTest(cros_test_lib.MockTempDirTestCase):
274 """Test user-mode and ebuild-mode staging functionality."""
275
276 def setUp(self):
Ryan Cuief91e702013-02-04 12:06:36 -0800277 self.staging_dir = os.path.join(self.tempdir, 'staging')
278 self.build_dir = os.path.join(self.tempdir, 'build_dir')
Malay Keshave7a071e2020-05-21 20:07:44 +0000279 self.common_flags = ['--build-dir', self.build_dir,
280 '--board=eve', '--staging-only', '--cache-dir',
281 self.tempdir]
Ryan Cuia0215a72013-02-14 16:20:45 -0800282 self.sdk_mock = self.StartPatcher(cros_chrome_sdk_unittest.SDKFetcherMock())
Ryan Cui686ec052013-02-12 16:39:41 -0800283 self.PatchObject(
284 osutils, 'SourceEnvironment', autospec=True,
285 return_value={'STRIP': 'x86_64-cros-linux-gnu-strip'})
Ryan Cuief91e702013-02-04 12:06:36 -0800286
David Jamesa6e08892013-03-01 13:34:11 -0800287 def testSingleFileDeployFailure(self):
288 """Default staging enforces that mandatory files are copied"""
Mike Frysingerc3061a62015-06-04 04:16:18 -0400289 options = _ParseCommandLine(self.common_flags)
David Jamesa6e08892013-03-01 13:34:11 -0800290 osutils.Touch(os.path.join(self.build_dir, 'chrome'), makedirs=True)
291 self.assertRaises(
292 chrome_util.MissingPathError, deploy_chrome._PrepareStagingDir,
Daniel Eratc89829c2014-05-12 17:24:21 -0700293 options, self.tempdir, self.staging_dir, chrome_util._COPY_PATHS_CHROME)
Ryan Cuief91e702013-02-04 12:06:36 -0800294
David Jamesa6e08892013-03-01 13:34:11 -0800295 def testSloppyDeployFailure(self):
296 """Sloppy staging enforces that at least one file is copied."""
Mike Frysingerc3061a62015-06-04 04:16:18 -0400297 options = _ParseCommandLine(self.common_flags + ['--sloppy'])
David Jamesa6e08892013-03-01 13:34:11 -0800298 self.assertRaises(
299 chrome_util.MissingPathError, deploy_chrome._PrepareStagingDir,
Daniel Eratc89829c2014-05-12 17:24:21 -0700300 options, self.tempdir, self.staging_dir, chrome_util._COPY_PATHS_CHROME)
David Jamesa6e08892013-03-01 13:34:11 -0800301
302 def testSloppyDeploySuccess(self):
303 """Sloppy staging - stage one file."""
Mike Frysingerc3061a62015-06-04 04:16:18 -0400304 options = _ParseCommandLine(self.common_flags + ['--sloppy'])
David Jamesa6e08892013-03-01 13:34:11 -0800305 osutils.Touch(os.path.join(self.build_dir, 'chrome'), makedirs=True)
Steve Funge984a532013-11-25 17:09:25 -0800306 deploy_chrome._PrepareStagingDir(options, self.tempdir, self.staging_dir,
Daniel Eratc89829c2014-05-12 17:24:21 -0700307 chrome_util._COPY_PATHS_CHROME)
David Jamesa6e08892013-03-01 13:34:11 -0800308
Steve Funge984a532013-11-25 17:09:25 -0800309
310class DeployTestBuildDir(cros_test_lib.MockTempDirTestCase):
Daniel Erat1ae46382014-08-14 10:23:39 -0700311 """Set up a deploy object with a build-dir for use in deployment type tests"""
Steve Funge984a532013-11-25 17:09:25 -0800312
313 def _GetDeployChrome(self, args):
Mike Frysingerc3061a62015-06-04 04:16:18 -0400314 options = _ParseCommandLine(args)
Steve Funge984a532013-11-25 17:09:25 -0800315 return deploy_chrome.DeployChrome(
316 options, self.tempdir, os.path.join(self.tempdir, 'staging'))
317
318 def setUp(self):
319 self.staging_dir = os.path.join(self.tempdir, 'staging')
320 self.build_dir = os.path.join(self.tempdir, 'build_dir')
321 self.deploy_mock = self.StartPatcher(DeployChromeMock())
322 self.deploy = self._GetDeployChrome(
Malay Keshave7a071e2020-05-21 20:07:44 +0000323 list(_REGULAR_TO) + ['--build-dir', self.build_dir,
324 '--board=eve', '--staging-only', '--cache-dir',
325 self.tempdir, '--sloppy'])
Steve Funge984a532013-11-25 17:09:25 -0800326
Daniel Erat1ae46382014-08-14 10:23:39 -0700327 def getCopyPath(self, source_path):
328 """Return a chrome_util.Path or None if not present."""
329 paths = [p for p in self.deploy.copy_paths if p.src == source_path]
330 return paths[0] if paths else None
Steve Funge984a532013-11-25 17:09:25 -0800331
Daniel Erat1ae46382014-08-14 10:23:39 -0700332class TestDeploymentType(DeployTestBuildDir):
Steve Funge984a532013-11-25 17:09:25 -0800333 """Test detection of deployment type using build dir."""
334
Daniel Erat1ae46382014-08-14 10:23:39 -0700335 def testAppShellDetection(self):
336 """Check for an app_shell deployment"""
337 osutils.Touch(os.path.join(self.deploy.options.build_dir, 'app_shell'),
Steve Funge984a532013-11-25 17:09:25 -0800338 makedirs=True)
339 self.deploy._CheckDeployType()
Daniel Erat1ae46382014-08-14 10:23:39 -0700340 self.assertTrue(self.getCopyPath('app_shell'))
341 self.assertFalse(self.getCopyPath('chrome'))
Steve Funge984a532013-11-25 17:09:25 -0800342
Daniel Erat1ae46382014-08-14 10:23:39 -0700343 def testChromeAndAppShellDetection(self):
Daniel Eratf53bd3a2016-12-02 11:28:36 -0700344 """Check for a chrome deployment when app_shell also exists."""
Steve Fung63d705d2014-03-16 03:14:03 -0700345 osutils.Touch(os.path.join(self.deploy.options.build_dir, 'chrome'),
346 makedirs=True)
Daniel Erat1ae46382014-08-14 10:23:39 -0700347 osutils.Touch(os.path.join(self.deploy.options.build_dir, 'app_shell'),
Steve Fung63d705d2014-03-16 03:14:03 -0700348 makedirs=True)
349 self.deploy._CheckDeployType()
Daniel Erat1ae46382014-08-14 10:23:39 -0700350 self.assertTrue(self.getCopyPath('chrome'))
Daniel Erat9813f0e2014-11-12 11:00:28 -0700351 self.assertFalse(self.getCopyPath('app_shell'))
Steve Fung63d705d2014-03-16 03:14:03 -0700352
Steve Funge984a532013-11-25 17:09:25 -0800353 def testChromeDetection(self):
354 """Check for a regular chrome deployment"""
355 osutils.Touch(os.path.join(self.deploy.options.build_dir, 'chrome'),
356 makedirs=True)
357 self.deploy._CheckDeployType()
Daniel Erat1ae46382014-08-14 10:23:39 -0700358 self.assertTrue(self.getCopyPath('chrome'))
Daniel Erat9813f0e2014-11-12 11:00:28 -0700359 self.assertFalse(self.getCopyPath('app_shell'))