blob: b7f41c8e890bd3bfe05e247fb83609c1932c9966 [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
David James88e6f032013-03-02 08:13:20 -080012import time
Ryan Cuiafd6c5c2012-07-30 17:48:22 -070013
Mike Frysinger6db648e2018-07-24 19:57:58 -040014import mock
15
David Pursellcfd58872015-03-19 09:15:48 -070016from chromite.cli.cros import cros_chrome_sdk_unittest
Ryan Cuief91e702013-02-04 12:06:36 -080017from chromite.lib import chrome_util
Ryan Cuiafd6c5c2012-07-30 17:48:22 -070018from chromite.lib import cros_build_lib
19from chromite.lib import cros_test_lib
Ryan Cui686ec052013-02-12 16:39:41 -080020from chromite.lib import osutils
Ryan Cuiafd6c5c2012-07-30 17:48:22 -070021from chromite.lib import partial_mock
Robert Flack1dc7ea82014-11-26 13:50:24 -050022from chromite.lib import remote_access
Ryan Cuiafd6c5c2012-07-30 17:48:22 -070023from chromite.lib import remote_access_unittest
24from chromite.scripts import deploy_chrome
25
Ryan Cuief91e702013-02-04 12:06:36 -080026
Mike Frysinger27e21b72018-07-12 14:20:21 -040027# pylint: disable=protected-access
28
Ryan Cuiafd6c5c2012-07-30 17:48:22 -070029
30_REGULAR_TO = ('--to', 'monkey')
31_GS_PATH = 'gs://foon'
32
33
34def _ParseCommandLine(argv):
35 return deploy_chrome._ParseCommandLine(['--log-level', 'debug'] + argv)
36
37
38class InterfaceTest(cros_test_lib.OutputTestCase):
39 """Tests the commandline interface of the script."""
40
Bernie Thompson93b9ee62018-02-21 14:56:16 -080041 BOARD = 'eve'
Ryan Cui686ec052013-02-12 16:39:41 -080042
Ryan Cuiafd6c5c2012-07-30 17:48:22 -070043 def testGsLocalPathUnSpecified(self):
44 """Test no chrome path specified."""
45 with self.OutputCapturer():
46 self.assertRaises2(SystemExit, _ParseCommandLine, list(_REGULAR_TO),
47 check_attrs={'code': 2})
48
49 def testGsPathSpecified(self):
50 """Test case of GS path specified."""
51 argv = list(_REGULAR_TO) + ['--gs-path', _GS_PATH]
52 _ParseCommandLine(argv)
53
54 def testLocalPathSpecified(self):
55 """Test case of local path specified."""
Mike Frysingerd6e2df02014-11-26 02:55:04 -050056 argv = list(_REGULAR_TO) + ['--local-pkg-path', '/path/to/chrome']
Ryan Cuiafd6c5c2012-07-30 17:48:22 -070057 _ParseCommandLine(argv)
58
59 def testNoTarget(self):
60 """Test no target specified."""
61 argv = ['--gs-path', _GS_PATH]
Ryan Cuief91e702013-02-04 12:06:36 -080062 self.assertParseError(argv)
63
64 def assertParseError(self, argv):
Ryan Cuiafd6c5c2012-07-30 17:48:22 -070065 with self.OutputCapturer():
66 self.assertRaises2(SystemExit, _ParseCommandLine, argv,
67 check_attrs={'code': 2})
68
Achuith Bhandarkar31a3eb02018-03-22 16:33:48 -070069 def testNoBoard(self):
70 """Test cases where --board is not specified."""
Ryan Cui686ec052013-02-12 16:39:41 -080071 argv = ['--staging-only', '--build-dir=/path/to/nowhere']
72 self.assertParseError(argv)
73
Achuith Bhandarkar31a3eb02018-03-22 16:33:48 -070074 # Don't need --board if no stripping is necessary.
75 argv_nostrip = argv + ['--nostrip']
76 _ParseCommandLine(argv_nostrip)
77
78 # Don't need --board if strip binary is provided.
79 argv_strip_bin = argv + ['--strip-bin', 'strip.bin']
80 _ParseCommandLine(argv_strip_bin)
81
Thiago Goncales12793312013-05-23 11:26:17 -070082 def testMountOptionSetsTargetDir(self):
83 argv = list(_REGULAR_TO) + ['--gs-path', _GS_PATH, '--mount']
Mike Frysingerc3061a62015-06-04 04:16:18 -040084 options = _ParseCommandLine(argv)
Thiago Goncales12793312013-05-23 11:26:17 -070085 self.assertIsNot(options.target_dir, None)
86
87 def testMountOptionSetsMountDir(self):
88 argv = list(_REGULAR_TO) + ['--gs-path', _GS_PATH, '--mount']
Mike Frysingerc3061a62015-06-04 04:16:18 -040089 options = _ParseCommandLine(argv)
Thiago Goncales12793312013-05-23 11:26:17 -070090 self.assertIsNot(options.mount_dir, None)
91
92 def testMountOptionDoesNotOverrideTargetDir(self):
93 argv = list(_REGULAR_TO) + ['--gs-path', _GS_PATH, '--mount',
94 '--target-dir', '/foo/bar/cow']
Mike Frysingerc3061a62015-06-04 04:16:18 -040095 options = _ParseCommandLine(argv)
Thiago Goncales12793312013-05-23 11:26:17 -070096 self.assertEqual(options.target_dir, '/foo/bar/cow')
97
98 def testMountOptionDoesNotOverrideMountDir(self):
99 argv = list(_REGULAR_TO) + ['--gs-path', _GS_PATH, '--mount',
100 '--mount-dir', '/foo/bar/cow']
Mike Frysingerc3061a62015-06-04 04:16:18 -0400101 options = _ParseCommandLine(argv)
Thiago Goncales12793312013-05-23 11:26:17 -0700102 self.assertEqual(options.mount_dir, '/foo/bar/cow')
103
Adrian Eldera2c548a2017-11-07 19:01:29 -0500104 def testSshIdentityOptionSetsOption(self):
105 argv = list(_REGULAR_TO) + ['--private-key', '/foo/bar/key',
106 '--board', 'cedar',
Bernie Thompson93b9ee62018-02-21 14:56:16 -0800107 '--build-dir', '/path/to/nowhere']
Adrian Eldera2c548a2017-11-07 19:01:29 -0500108 options = _ParseCommandLine(argv)
109 self.assertEqual(options.private_key, '/foo/bar/key')
Ryan Cuiafd6c5c2012-07-30 17:48:22 -0700110
111class DeployChromeMock(partial_mock.PartialMock):
Steve Funge984a532013-11-25 17:09:25 -0800112 """Deploy Chrome Mock Class."""
Ryan Cuiafd6c5c2012-07-30 17:48:22 -0700113
114 TARGET = 'chromite.scripts.deploy_chrome.DeployChrome'
David James88e6f032013-03-02 08:13:20 -0800115 ATTRS = ('_KillProcsIfNeeded', '_DisableRootfsVerification')
Ryan Cuiafd6c5c2012-07-30 17:48:22 -0700116
David James88e6f032013-03-02 08:13:20 -0800117 def __init__(self):
Ryan Cuiafd6c5c2012-07-30 17:48:22 -0700118 partial_mock.PartialMock.__init__(self)
Robert Flack1dc7ea82014-11-26 13:50:24 -0500119 self.remote_device_mock = remote_access_unittest.RemoteDeviceMock()
Ryan Cuiafd6c5c2012-07-30 17:48:22 -0700120 # Target starts off as having rootfs verification enabled.
Ryan Cuie18f24f2012-12-03 18:39:55 -0800121 self.rsh_mock = remote_access_unittest.RemoteShMock()
David James88e6f032013-03-02 08:13:20 -0800122 self.rsh_mock.SetDefaultCmdResult(0)
Ryan Cuiafd6c5c2012-07-30 17:48:22 -0700123 self.MockMountCmd(1)
David Haddock3151d912017-10-24 03:50:32 +0000124 self.rsh_mock.AddCmdResult(
Anushruth8d797672019-10-17 12:22:31 -0700125 deploy_chrome.LSOF_COMMAND_CHROME % (deploy_chrome._CHROME_DIR,), 1)
Ryan Cuiafd6c5c2012-07-30 17:48:22 -0700126
127 def MockMountCmd(self, returnvalue):
Ryan Cuiafd6c5c2012-07-30 17:48:22 -0700128 self.rsh_mock.AddCmdResult(deploy_chrome.MOUNT_RW_COMMAND,
David James88e6f032013-03-02 08:13:20 -0800129 returnvalue)
130
131 def _DisableRootfsVerification(self, inst):
132 with mock.patch.object(time, 'sleep'):
133 self.backup['_DisableRootfsVerification'](inst)
Ryan Cuiafd6c5c2012-07-30 17:48:22 -0700134
Ryan Cui4d6fca92012-12-13 16:41:56 -0800135 def PreStart(self):
Robert Flack1dc7ea82014-11-26 13:50:24 -0500136 self.remote_device_mock.start()
Ryan Cui4d6fca92012-12-13 16:41:56 -0800137 self.rsh_mock.start()
Ryan Cuiafd6c5c2012-07-30 17:48:22 -0700138
Ryan Cui4d6fca92012-12-13 16:41:56 -0800139 def PreStop(self):
140 self.rsh_mock.stop()
Robert Flack1dc7ea82014-11-26 13:50:24 -0500141 self.remote_device_mock.stop()
Ryan Cuiafd6c5c2012-07-30 17:48:22 -0700142
Ryan Cuiafd6c5c2012-07-30 17:48:22 -0700143 def _KillProcsIfNeeded(self, _inst):
144 # Fully stub out for now.
145 pass
146
147
Ryan Cuief91e702013-02-04 12:06:36 -0800148class DeployTest(cros_test_lib.MockTempDirTestCase):
Steve Funge984a532013-11-25 17:09:25 -0800149 """Setup a deploy object with a GS-path for use in tests."""
150
Ryan Cuief91e702013-02-04 12:06:36 -0800151 def _GetDeployChrome(self, args):
Mike Frysingerc3061a62015-06-04 04:16:18 -0400152 options = _ParseCommandLine(args)
Ryan Cuia56a71e2012-10-18 18:40:35 -0700153 return deploy_chrome.DeployChrome(
154 options, self.tempdir, os.path.join(self.tempdir, 'staging'))
Ryan Cuiafd6c5c2012-07-30 17:48:22 -0700155
156 def setUp(self):
Ryan Cuif1416f32013-01-22 18:43:41 -0800157 self.deploy_mock = self.StartPatcher(DeployChromeMock())
Ryan Cuief91e702013-02-04 12:06:36 -0800158 self.deploy = self._GetDeployChrome(
Anushruth8d797672019-10-17 12:22:31 -0700159 list(_REGULAR_TO) + ['--gs-path', _GS_PATH, '--force', '--mount'])
Luigi Semenzato1bc79b22016-11-22 16:32:17 -0800160 self.remote_reboot_mock = \
161 self.PatchObject(remote_access.RemoteAccess, 'RemoteReboot',
162 return_value=True)
Ryan Cuiafd6c5c2012-07-30 17:48:22 -0700163
David James88e6f032013-03-02 08:13:20 -0800164class TestDisableRootfsVerification(DeployTest):
Ryan Cuiafd6c5c2012-07-30 17:48:22 -0700165 """Testing disabling of rootfs verification and RO mode."""
166
David James88e6f032013-03-02 08:13:20 -0800167 def testDisableRootfsVerificationSuccess(self):
168 """Test the working case, disabling rootfs verification."""
169 self.deploy_mock.MockMountCmd(0)
170 self.deploy._DisableRootfsVerification()
Steven Bennettsca73efa2018-07-10 13:36:56 -0700171 self.assertFalse(self.deploy._root_dir_is_still_readonly.is_set())
Ryan Cuiafd6c5c2012-07-30 17:48:22 -0700172
173 def testDisableRootfsVerificationFailure(self):
174 """Test failure to disable rootfs verification."""
Mike Frysinger27e21b72018-07-12 14:20:21 -0400175 # pylint: disable=unused-argument
Shuqian Zhao14e61092017-11-17 00:02:16 +0000176 def RaiseRunCommandError(timeout_sec=None):
Mike Frysinger929f3ba2019-09-12 03:24:59 -0400177 raise cros_build_lib.RunCommandError('Mock RunCommandError')
Luigi Semenzato1bc79b22016-11-22 16:32:17 -0800178 self.remote_reboot_mock.side_effect = RaiseRunCommandError
Ryan Cuiafd6c5c2012-07-30 17:48:22 -0700179 self.assertRaises(cros_build_lib.RunCommandError,
David James88e6f032013-03-02 08:13:20 -0800180 self.deploy._DisableRootfsVerification)
Luigi Semenzato1bc79b22016-11-22 16:32:17 -0800181 self.remote_reboot_mock.side_effect = None
Steven Bennettsca73efa2018-07-10 13:36:56 -0700182 self.assertFalse(self.deploy._root_dir_is_still_readonly.is_set())
David James88e6f032013-03-02 08:13:20 -0800183
184
185class TestMount(DeployTest):
186 """Testing mount success and failure."""
187
188 def testSuccess(self):
189 """Test case where we are able to mount as writable."""
Steven Bennettsca73efa2018-07-10 13:36:56 -0700190 self.assertFalse(self.deploy._root_dir_is_still_readonly.is_set())
David James88e6f032013-03-02 08:13:20 -0800191 self.deploy_mock.MockMountCmd(0)
192 self.deploy._MountRootfsAsWritable()
Steven Bennettsca73efa2018-07-10 13:36:56 -0700193 self.assertFalse(self.deploy._root_dir_is_still_readonly.is_set())
David James88e6f032013-03-02 08:13:20 -0800194
195 def testMountError(self):
196 """Test that mount failure doesn't raise an exception by default."""
Steven Bennettsca73efa2018-07-10 13:36:56 -0700197 self.assertFalse(self.deploy._root_dir_is_still_readonly.is_set())
Mike Frysinger74ccd572015-05-21 21:18:20 -0400198 self.PatchObject(remote_access.RemoteDevice, 'IsDirWritable',
Robert Flack1dc7ea82014-11-26 13:50:24 -0500199 return_value=False, autospec=True)
David James88e6f032013-03-02 08:13:20 -0800200 self.deploy._MountRootfsAsWritable()
Steven Bennettsca73efa2018-07-10 13:36:56 -0700201 self.assertTrue(self.deploy._root_dir_is_still_readonly.is_set())
Ryan Cuiafd6c5c2012-07-30 17:48:22 -0700202
203 def testMountRwFailure(self):
David James88e6f032013-03-02 08:13:20 -0800204 """Test that mount failure raises an exception if error_code_ok=False."""
205 self.assertRaises(cros_build_lib.RunCommandError,
206 self.deploy._MountRootfsAsWritable, error_code_ok=False)
Steven Bennettsca73efa2018-07-10 13:36:56 -0700207 self.assertFalse(self.deploy._root_dir_is_still_readonly.is_set())
Robert Flack1dc7ea82014-11-26 13:50:24 -0500208
209 def testMountTempDir(self):
210 """Test that mount succeeds if target dir is writable."""
Steven Bennettsca73efa2018-07-10 13:36:56 -0700211 self.assertFalse(self.deploy._root_dir_is_still_readonly.is_set())
Mike Frysinger74ccd572015-05-21 21:18:20 -0400212 self.PatchObject(remote_access.RemoteDevice, 'IsDirWritable',
Robert Flack1dc7ea82014-11-26 13:50:24 -0500213 return_value=True, autospec=True)
214 self.deploy._MountRootfsAsWritable()
Steven Bennettsca73efa2018-07-10 13:36:56 -0700215 self.assertFalse(self.deploy._root_dir_is_still_readonly.is_set())
Ryan Cuiafd6c5c2012-07-30 17:48:22 -0700216
217
Anushruth8d797672019-10-17 12:22:31 -0700218class TestMountTarget(DeployTest):
Mike Frysingerdf1d0b02019-11-12 17:44:12 -0500219 """Testing mount and umount command handling."""
Anushruth8d797672019-10-17 12:22:31 -0700220
221 def testMountTargetUmountFailure(self):
222 """Test error being thrown if umount fails.
223
224 Test that 'lsof' is run on mount-dir and 'mount -rbind' command is not run
225 if 'umount' cmd fails.
226 """
227 mount_dir = self.deploy.options.mount_dir
228 target_dir = self.deploy.options.target_dir
229 self.deploy_mock.rsh_mock.AddCmdResult(
230 deploy_chrome._UMOUNT_DIR_IF_MOUNTPOINT_CMD %
231 {'dir': mount_dir}, returncode=errno.EBUSY, stderr='Target is Busy')
232 self.deploy_mock.rsh_mock.AddCmdResult(deploy_chrome.LSOF_COMMAND %
233 (mount_dir,), returncode=0,
234 stdout='process ' + mount_dir)
235 # Check for RunCommandError being thrown.
236 self.assertRaises(cros_build_lib.RunCommandError,
237 self.deploy._MountTarget)
238 # Check for the 'mount -rbind' command not run.
239 self.deploy_mock.rsh_mock.assertCommandContains(
240 (deploy_chrome._BIND_TO_FINAL_DIR_CMD % (target_dir, mount_dir)),
241 expected=False)
242 # Check for lsof command being called.
243 self.deploy_mock.rsh_mock.assertCommandContains(
244 (deploy_chrome.LSOF_COMMAND % (mount_dir,)))
245
246
Ryan Cuief91e702013-02-04 12:06:36 -0800247class TestUiJobStarted(DeployTest):
Ryan Cuiafd6c5c2012-07-30 17:48:22 -0700248 """Test detection of a running 'ui' job."""
249
Ryan Cuif2d1a582013-02-19 14:08:13 -0800250 def MockStatusUiCmd(self, **kwargs):
David Haddock3151d912017-10-24 03:50:32 +0000251 self.deploy_mock.rsh_mock.AddCmdResult('status ui', **kwargs)
Ryan Cuiafd6c5c2012-07-30 17:48:22 -0700252
253 def testUiJobStartedFalse(self):
254 """Correct results with a stopped job."""
Ryan Cuif2d1a582013-02-19 14:08:13 -0800255 self.MockStatusUiCmd(output='ui stop/waiting')
256 self.assertFalse(self.deploy._CheckUiJobStarted())
257
258 def testNoUiJob(self):
259 """Correct results when the job doesn't exist."""
260 self.MockStatusUiCmd(error='start: Unknown job: ui', returncode=1)
Ryan Cuiafd6c5c2012-07-30 17:48:22 -0700261 self.assertFalse(self.deploy._CheckUiJobStarted())
262
263 def testCheckRootfsWriteableTrue(self):
264 """Correct results with a running job."""
Ryan Cuif2d1a582013-02-19 14:08:13 -0800265 self.MockStatusUiCmd(output='ui start/running, process 297')
Ryan Cuiafd6c5c2012-07-30 17:48:22 -0700266 self.assertTrue(self.deploy._CheckUiJobStarted())
267
268
Ryan Cuief91e702013-02-04 12:06:36 -0800269class StagingTest(cros_test_lib.MockTempDirTestCase):
270 """Test user-mode and ebuild-mode staging functionality."""
271
272 def setUp(self):
Ryan Cuief91e702013-02-04 12:06:36 -0800273 self.staging_dir = os.path.join(self.tempdir, 'staging')
274 self.build_dir = os.path.join(self.tempdir, 'build_dir')
Ryan Cui686ec052013-02-12 16:39:41 -0800275 self.common_flags = ['--build-dir', self.build_dir,
Bernie Thompson93b9ee62018-02-21 14:56:16 -0800276 '--board=eve', '--staging-only', '--cache-dir',
Ryan Cui686ec052013-02-12 16:39:41 -0800277 self.tempdir]
Ryan Cuia0215a72013-02-14 16:20:45 -0800278 self.sdk_mock = self.StartPatcher(cros_chrome_sdk_unittest.SDKFetcherMock())
Ryan Cui686ec052013-02-12 16:39:41 -0800279 self.PatchObject(
280 osutils, 'SourceEnvironment', autospec=True,
281 return_value={'STRIP': 'x86_64-cros-linux-gnu-strip'})
Ryan Cuief91e702013-02-04 12:06:36 -0800282
David Jamesa6e08892013-03-01 13:34:11 -0800283 def testSingleFileDeployFailure(self):
284 """Default staging enforces that mandatory files are copied"""
Mike Frysingerc3061a62015-06-04 04:16:18 -0400285 options = _ParseCommandLine(self.common_flags)
David Jamesa6e08892013-03-01 13:34:11 -0800286 osutils.Touch(os.path.join(self.build_dir, 'chrome'), makedirs=True)
287 self.assertRaises(
288 chrome_util.MissingPathError, deploy_chrome._PrepareStagingDir,
Daniel Eratc89829c2014-05-12 17:24:21 -0700289 options, self.tempdir, self.staging_dir, chrome_util._COPY_PATHS_CHROME)
Ryan Cuief91e702013-02-04 12:06:36 -0800290
David Jamesa6e08892013-03-01 13:34:11 -0800291 def testSloppyDeployFailure(self):
292 """Sloppy staging enforces that at least one file is copied."""
Mike Frysingerc3061a62015-06-04 04:16:18 -0400293 options = _ParseCommandLine(self.common_flags + ['--sloppy'])
David Jamesa6e08892013-03-01 13:34:11 -0800294 self.assertRaises(
295 chrome_util.MissingPathError, deploy_chrome._PrepareStagingDir,
Daniel Eratc89829c2014-05-12 17:24:21 -0700296 options, self.tempdir, self.staging_dir, chrome_util._COPY_PATHS_CHROME)
David Jamesa6e08892013-03-01 13:34:11 -0800297
298 def testSloppyDeploySuccess(self):
299 """Sloppy staging - stage one file."""
Mike Frysingerc3061a62015-06-04 04:16:18 -0400300 options = _ParseCommandLine(self.common_flags + ['--sloppy'])
David Jamesa6e08892013-03-01 13:34:11 -0800301 osutils.Touch(os.path.join(self.build_dir, 'chrome'), makedirs=True)
Steve Funge984a532013-11-25 17:09:25 -0800302 deploy_chrome._PrepareStagingDir(options, self.tempdir, self.staging_dir,
Daniel Eratc89829c2014-05-12 17:24:21 -0700303 chrome_util._COPY_PATHS_CHROME)
David Jamesa6e08892013-03-01 13:34:11 -0800304
Steve Funge984a532013-11-25 17:09:25 -0800305
306class DeployTestBuildDir(cros_test_lib.MockTempDirTestCase):
Daniel Erat1ae46382014-08-14 10:23:39 -0700307 """Set up a deploy object with a build-dir for use in deployment type tests"""
Steve Funge984a532013-11-25 17:09:25 -0800308
309 def _GetDeployChrome(self, args):
Mike Frysingerc3061a62015-06-04 04:16:18 -0400310 options = _ParseCommandLine(args)
Steve Funge984a532013-11-25 17:09:25 -0800311 return deploy_chrome.DeployChrome(
312 options, self.tempdir, os.path.join(self.tempdir, 'staging'))
313
314 def setUp(self):
315 self.staging_dir = os.path.join(self.tempdir, 'staging')
316 self.build_dir = os.path.join(self.tempdir, 'build_dir')
317 self.deploy_mock = self.StartPatcher(DeployChromeMock())
318 self.deploy = self._GetDeployChrome(
319 list(_REGULAR_TO) + ['--build-dir', self.build_dir,
Bernie Thompson93b9ee62018-02-21 14:56:16 -0800320 '--board=eve', '--staging-only', '--cache-dir',
Steve Funge984a532013-11-25 17:09:25 -0800321 self.tempdir, '--sloppy'])
322
Daniel Erat1ae46382014-08-14 10:23:39 -0700323 def getCopyPath(self, source_path):
324 """Return a chrome_util.Path or None if not present."""
325 paths = [p for p in self.deploy.copy_paths if p.src == source_path]
326 return paths[0] if paths else None
Steve Funge984a532013-11-25 17:09:25 -0800327
Daniel Erat1ae46382014-08-14 10:23:39 -0700328class TestDeploymentType(DeployTestBuildDir):
Steve Funge984a532013-11-25 17:09:25 -0800329 """Test detection of deployment type using build dir."""
330
Daniel Erat1ae46382014-08-14 10:23:39 -0700331 def testAppShellDetection(self):
332 """Check for an app_shell deployment"""
333 osutils.Touch(os.path.join(self.deploy.options.build_dir, 'app_shell'),
Steve Funge984a532013-11-25 17:09:25 -0800334 makedirs=True)
335 self.deploy._CheckDeployType()
Daniel Erat1ae46382014-08-14 10:23:39 -0700336 self.assertTrue(self.getCopyPath('app_shell'))
337 self.assertFalse(self.getCopyPath('chrome'))
Steve Funge984a532013-11-25 17:09:25 -0800338
Daniel Erat1ae46382014-08-14 10:23:39 -0700339 def testChromeAndAppShellDetection(self):
Daniel Eratf53bd3a2016-12-02 11:28:36 -0700340 """Check for a chrome deployment when app_shell also exists."""
Steve Fung63d705d2014-03-16 03:14:03 -0700341 osutils.Touch(os.path.join(self.deploy.options.build_dir, 'chrome'),
342 makedirs=True)
Daniel Erat1ae46382014-08-14 10:23:39 -0700343 osutils.Touch(os.path.join(self.deploy.options.build_dir, 'app_shell'),
Steve Fung63d705d2014-03-16 03:14:03 -0700344 makedirs=True)
345 self.deploy._CheckDeployType()
Daniel Erat1ae46382014-08-14 10:23:39 -0700346 self.assertTrue(self.getCopyPath('chrome'))
Daniel Erat9813f0e2014-11-12 11:00:28 -0700347 self.assertFalse(self.getCopyPath('app_shell'))
Steve Fung63d705d2014-03-16 03:14:03 -0700348
Steve Funge984a532013-11-25 17:09:25 -0800349 def testChromeDetection(self):
350 """Check for a regular chrome deployment"""
351 osutils.Touch(os.path.join(self.deploy.options.build_dir, 'chrome'),
352 makedirs=True)
353 self.deploy._CheckDeployType()
Daniel Erat1ae46382014-08-14 10:23:39 -0700354 self.assertTrue(self.getCopyPath('chrome'))
Daniel Erat9813f0e2014-11-12 11:00:28 -0700355 self.assertFalse(self.getCopyPath('app_shell'))