Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 1 | # Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
Steve Fung | e984a53 | 2013-11-25 17:09:25 -0800 | [diff] [blame] | 5 | """Unit tests for the deploy_chrome script.""" |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 6 | |
Mike Frysinger | 383367e | 2014-09-16 15:06:17 -0400 | [diff] [blame] | 7 | from __future__ import print_function |
| 8 | |
Mike Frysinger | ea838d1 | 2014-12-08 11:55:32 -0500 | [diff] [blame] | 9 | import mock |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 10 | import os |
David James | 88e6f03 | 2013-03-02 08:13:20 -0800 | [diff] [blame] | 11 | import time |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 12 | |
David Pursell | cfd5887 | 2015-03-19 09:15:48 -0700 | [diff] [blame] | 13 | from chromite.cli.cros import cros_chrome_sdk_unittest |
Ryan Cui | ef91e70 | 2013-02-04 12:06:36 -0800 | [diff] [blame] | 14 | from chromite.lib import chrome_util |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 15 | from chromite.lib import cros_build_lib |
| 16 | from chromite.lib import cros_test_lib |
Ryan Cui | 686ec05 | 2013-02-12 16:39:41 -0800 | [diff] [blame] | 17 | from chromite.lib import osutils |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 18 | from chromite.lib import partial_mock |
Robert Flack | 1dc7ea8 | 2014-11-26 13:50:24 -0500 | [diff] [blame] | 19 | from chromite.lib import remote_access |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 20 | from chromite.lib import remote_access_unittest |
Ryan Cui | cbd9bb6 | 2013-04-30 11:17:02 -0700 | [diff] [blame] | 21 | from chromite.lib import stats |
| 22 | from chromite.lib import stats_unittest |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 23 | from chromite.scripts import deploy_chrome |
| 24 | |
Ryan Cui | ef91e70 | 2013-02-04 12:06:36 -0800 | [diff] [blame] | 25 | |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 26 | # pylint: disable=W0212 |
| 27 | |
| 28 | _REGULAR_TO = ('--to', 'monkey') |
| 29 | _GS_PATH = 'gs://foon' |
| 30 | |
| 31 | |
| 32 | def _ParseCommandLine(argv): |
| 33 | return deploy_chrome._ParseCommandLine(['--log-level', 'debug'] + argv) |
| 34 | |
| 35 | |
| 36 | class InterfaceTest(cros_test_lib.OutputTestCase): |
| 37 | """Tests the commandline interface of the script.""" |
| 38 | |
Ryan Cui | 686ec05 | 2013-02-12 16:39:41 -0800 | [diff] [blame] | 39 | BOARD = 'lumpy' |
| 40 | |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 41 | def testGsLocalPathUnSpecified(self): |
| 42 | """Test no chrome path specified.""" |
| 43 | with self.OutputCapturer(): |
| 44 | self.assertRaises2(SystemExit, _ParseCommandLine, list(_REGULAR_TO), |
| 45 | check_attrs={'code': 2}) |
| 46 | |
| 47 | def testGsPathSpecified(self): |
| 48 | """Test case of GS path specified.""" |
| 49 | argv = list(_REGULAR_TO) + ['--gs-path', _GS_PATH] |
| 50 | _ParseCommandLine(argv) |
| 51 | |
| 52 | def testLocalPathSpecified(self): |
| 53 | """Test case of local path specified.""" |
Mike Frysinger | d6e2df0 | 2014-11-26 02:55:04 -0500 | [diff] [blame] | 54 | argv = list(_REGULAR_TO) + ['--local-pkg-path', '/path/to/chrome'] |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 55 | _ParseCommandLine(argv) |
| 56 | |
| 57 | def testNoTarget(self): |
| 58 | """Test no target specified.""" |
| 59 | argv = ['--gs-path', _GS_PATH] |
Ryan Cui | ef91e70 | 2013-02-04 12:06:36 -0800 | [diff] [blame] | 60 | self.assertParseError(argv) |
| 61 | |
| 62 | def assertParseError(self, argv): |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 63 | with self.OutputCapturer(): |
| 64 | self.assertRaises2(SystemExit, _ParseCommandLine, argv, |
| 65 | check_attrs={'code': 2}) |
| 66 | |
Ryan Cui | ef91e70 | 2013-02-04 12:06:36 -0800 | [diff] [blame] | 67 | def testStagingFlagsNoStrict(self): |
| 68 | """Errors out when --staging-flags is set without --strict.""" |
| 69 | argv = ['--staging-only', '--build-dir=/path/to/nowhere', |
Ryan Cui | 686ec05 | 2013-02-12 16:39:41 -0800 | [diff] [blame] | 70 | '--board=%s' % self.BOARD, '--staging-flags=highdpi'] |
Ryan Cui | ef91e70 | 2013-02-04 12:06:36 -0800 | [diff] [blame] | 71 | self.assertParseError(argv) |
| 72 | |
| 73 | def testStrictNoBuildDir(self): |
| 74 | """Errors out when --strict is set without --build-dir.""" |
| 75 | argv = ['--staging-only', '--strict', '--gs-path', _GS_PATH] |
| 76 | self.assertParseError(argv) |
| 77 | |
Ryan Cui | 686ec05 | 2013-02-12 16:39:41 -0800 | [diff] [blame] | 78 | def testNoBoardBuildDir(self): |
| 79 | argv = ['--staging-only', '--build-dir=/path/to/nowhere'] |
| 80 | self.assertParseError(argv) |
| 81 | |
Thiago Goncales | 1279331 | 2013-05-23 11:26:17 -0700 | [diff] [blame] | 82 | def testMountOptionSetsTargetDir(self): |
| 83 | argv = list(_REGULAR_TO) + ['--gs-path', _GS_PATH, '--mount'] |
| 84 | options, _ = _ParseCommandLine(argv) |
| 85 | self.assertIsNot(options.target_dir, None) |
| 86 | |
| 87 | def testMountOptionSetsMountDir(self): |
| 88 | argv = list(_REGULAR_TO) + ['--gs-path', _GS_PATH, '--mount'] |
| 89 | options, _ = _ParseCommandLine(argv) |
| 90 | 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'] |
| 95 | options, _ = _ParseCommandLine(argv) |
| 96 | 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'] |
| 101 | options, _ = _ParseCommandLine(argv) |
| 102 | self.assertEqual(options.mount_dir, '/foo/bar/cow') |
| 103 | |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 104 | |
| 105 | class DeployChromeMock(partial_mock.PartialMock): |
Steve Fung | e984a53 | 2013-11-25 17:09:25 -0800 | [diff] [blame] | 106 | """Deploy Chrome Mock Class.""" |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 107 | |
| 108 | TARGET = 'chromite.scripts.deploy_chrome.DeployChrome' |
David James | 88e6f03 | 2013-03-02 08:13:20 -0800 | [diff] [blame] | 109 | ATTRS = ('_KillProcsIfNeeded', '_DisableRootfsVerification') |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 110 | |
David James | 88e6f03 | 2013-03-02 08:13:20 -0800 | [diff] [blame] | 111 | def __init__(self): |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 112 | partial_mock.PartialMock.__init__(self) |
Robert Flack | 1dc7ea8 | 2014-11-26 13:50:24 -0500 | [diff] [blame] | 113 | self.remote_device_mock = remote_access_unittest.RemoteDeviceMock() |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 114 | # Target starts off as having rootfs verification enabled. |
Ryan Cui | e18f24f | 2012-12-03 18:39:55 -0800 | [diff] [blame] | 115 | self.rsh_mock = remote_access_unittest.RemoteShMock() |
David James | 88e6f03 | 2013-03-02 08:13:20 -0800 | [diff] [blame] | 116 | self.rsh_mock.SetDefaultCmdResult(0) |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 117 | self.MockMountCmd(1) |
Pawel Osciak | 577773a | 2013-03-05 10:52:12 -0800 | [diff] [blame] | 118 | self.rsh_mock.AddCmdResult( |
| 119 | deploy_chrome.LSOF_COMMAND % (deploy_chrome._CHROME_DIR,), 1) |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 120 | |
| 121 | def MockMountCmd(self, returnvalue): |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 122 | self.rsh_mock.AddCmdResult(deploy_chrome.MOUNT_RW_COMMAND, |
David James | 88e6f03 | 2013-03-02 08:13:20 -0800 | [diff] [blame] | 123 | returnvalue) |
| 124 | |
| 125 | def _DisableRootfsVerification(self, inst): |
| 126 | with mock.patch.object(time, 'sleep'): |
| 127 | self.backup['_DisableRootfsVerification'](inst) |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 128 | |
Ryan Cui | 4d6fca9 | 2012-12-13 16:41:56 -0800 | [diff] [blame] | 129 | def PreStart(self): |
Robert Flack | 1dc7ea8 | 2014-11-26 13:50:24 -0500 | [diff] [blame] | 130 | self.remote_device_mock.start() |
Ryan Cui | 4d6fca9 | 2012-12-13 16:41:56 -0800 | [diff] [blame] | 131 | self.rsh_mock.start() |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 132 | |
Ryan Cui | 4d6fca9 | 2012-12-13 16:41:56 -0800 | [diff] [blame] | 133 | def PreStop(self): |
| 134 | self.rsh_mock.stop() |
Robert Flack | 1dc7ea8 | 2014-11-26 13:50:24 -0500 | [diff] [blame] | 135 | self.remote_device_mock.stop() |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 136 | |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 137 | def _KillProcsIfNeeded(self, _inst): |
| 138 | # Fully stub out for now. |
| 139 | pass |
| 140 | |
| 141 | |
Ryan Cui | cbd9bb6 | 2013-04-30 11:17:02 -0700 | [diff] [blame] | 142 | class MainTest(cros_test_lib.MockLoggingTestCase): |
Steve Fung | e984a53 | 2013-11-25 17:09:25 -0800 | [diff] [blame] | 143 | """Main tests.""" |
Ryan Cui | cbd9bb6 | 2013-04-30 11:17:02 -0700 | [diff] [blame] | 144 | |
| 145 | def setUp(self): |
| 146 | self.PatchObject(deploy_chrome.DeployChrome, 'Perform', autospec=True) |
| 147 | self.stats_module_mock = stats_unittest.StatsModuleMock() |
| 148 | self.StartPatcher(self.stats_module_mock) |
| 149 | |
| 150 | def testStatsUpload(self, call_count=1): |
| 151 | """The stats upload path.""" |
| 152 | deploy_chrome.main(['--board=lumpy', '--staging-only', |
| 153 | '--build-dir=/tmp/abc']) |
| 154 | self.assertEquals(stats.StatsUploader._Upload.call_count, call_count) |
| 155 | |
| 156 | def testStatsUploadError(self): |
| 157 | """Don't upload stats if we fail to create it.""" |
| 158 | self.stats_module_mock.stats_mock.init_exception = True |
| 159 | with cros_test_lib.LoggingCapturer(): |
| 160 | self.testStatsUpload(call_count=0) |
| 161 | |
| 162 | |
Ryan Cui | ef91e70 | 2013-02-04 12:06:36 -0800 | [diff] [blame] | 163 | class DeployTest(cros_test_lib.MockTempDirTestCase): |
Steve Fung | e984a53 | 2013-11-25 17:09:25 -0800 | [diff] [blame] | 164 | """Setup a deploy object with a GS-path for use in tests.""" |
| 165 | |
Ryan Cui | ef91e70 | 2013-02-04 12:06:36 -0800 | [diff] [blame] | 166 | def _GetDeployChrome(self, args): |
| 167 | options, _ = _ParseCommandLine(args) |
Ryan Cui | a56a71e | 2012-10-18 18:40:35 -0700 | [diff] [blame] | 168 | return deploy_chrome.DeployChrome( |
| 169 | options, self.tempdir, os.path.join(self.tempdir, 'staging')) |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 170 | |
| 171 | def setUp(self): |
Ryan Cui | f1416f3 | 2013-01-22 18:43:41 -0800 | [diff] [blame] | 172 | self.deploy_mock = self.StartPatcher(DeployChromeMock()) |
Ryan Cui | ef91e70 | 2013-02-04 12:06:36 -0800 | [diff] [blame] | 173 | self.deploy = self._GetDeployChrome( |
David James | 88e6f03 | 2013-03-02 08:13:20 -0800 | [diff] [blame] | 174 | list(_REGULAR_TO) + ['--gs-path', _GS_PATH, '--force']) |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 175 | |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 176 | |
David James | 88e6f03 | 2013-03-02 08:13:20 -0800 | [diff] [blame] | 177 | class TestDisableRootfsVerification(DeployTest): |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 178 | """Testing disabling of rootfs verification and RO mode.""" |
| 179 | |
David James | 88e6f03 | 2013-03-02 08:13:20 -0800 | [diff] [blame] | 180 | def testDisableRootfsVerificationSuccess(self): |
| 181 | """Test the working case, disabling rootfs verification.""" |
| 182 | self.deploy_mock.MockMountCmd(0) |
| 183 | self.deploy._DisableRootfsVerification() |
Robert Flack | 1dc7ea8 | 2014-11-26 13:50:24 -0500 | [diff] [blame] | 184 | self.assertFalse(self.deploy._target_dir_is_still_readonly.is_set()) |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 185 | |
| 186 | def testDisableRootfsVerificationFailure(self): |
| 187 | """Test failure to disable rootfs verification.""" |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 188 | self.assertRaises(cros_build_lib.RunCommandError, |
David James | 88e6f03 | 2013-03-02 08:13:20 -0800 | [diff] [blame] | 189 | self.deploy._DisableRootfsVerification) |
Robert Flack | 1dc7ea8 | 2014-11-26 13:50:24 -0500 | [diff] [blame] | 190 | self.assertFalse(self.deploy._target_dir_is_still_readonly.is_set()) |
David James | 88e6f03 | 2013-03-02 08:13:20 -0800 | [diff] [blame] | 191 | |
| 192 | |
| 193 | class TestMount(DeployTest): |
| 194 | """Testing mount success and failure.""" |
| 195 | |
| 196 | def testSuccess(self): |
| 197 | """Test case where we are able to mount as writable.""" |
Robert Flack | 1dc7ea8 | 2014-11-26 13:50:24 -0500 | [diff] [blame] | 198 | self.assertFalse(self.deploy._target_dir_is_still_readonly.is_set()) |
David James | 88e6f03 | 2013-03-02 08:13:20 -0800 | [diff] [blame] | 199 | self.deploy_mock.MockMountCmd(0) |
| 200 | self.deploy._MountRootfsAsWritable() |
Robert Flack | 1dc7ea8 | 2014-11-26 13:50:24 -0500 | [diff] [blame] | 201 | self.assertFalse(self.deploy._target_dir_is_still_readonly.is_set()) |
David James | 88e6f03 | 2013-03-02 08:13:20 -0800 | [diff] [blame] | 202 | |
| 203 | def testMountError(self): |
| 204 | """Test that mount failure doesn't raise an exception by default.""" |
Robert Flack | 1dc7ea8 | 2014-11-26 13:50:24 -0500 | [diff] [blame] | 205 | self.assertFalse(self.deploy._target_dir_is_still_readonly.is_set()) |
Mike Frysinger | 74ccd57 | 2015-05-21 21:18:20 -0400 | [diff] [blame] | 206 | self.PatchObject(remote_access.RemoteDevice, 'IsDirWritable', |
Robert Flack | 1dc7ea8 | 2014-11-26 13:50:24 -0500 | [diff] [blame] | 207 | return_value=False, autospec=True) |
David James | 88e6f03 | 2013-03-02 08:13:20 -0800 | [diff] [blame] | 208 | self.deploy._MountRootfsAsWritable() |
Robert Flack | 1dc7ea8 | 2014-11-26 13:50:24 -0500 | [diff] [blame] | 209 | self.assertTrue(self.deploy._target_dir_is_still_readonly.is_set()) |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 210 | |
| 211 | def testMountRwFailure(self): |
David James | 88e6f03 | 2013-03-02 08:13:20 -0800 | [diff] [blame] | 212 | """Test that mount failure raises an exception if error_code_ok=False.""" |
| 213 | self.assertRaises(cros_build_lib.RunCommandError, |
| 214 | self.deploy._MountRootfsAsWritable, error_code_ok=False) |
Robert Flack | 1dc7ea8 | 2014-11-26 13:50:24 -0500 | [diff] [blame] | 215 | self.assertFalse(self.deploy._target_dir_is_still_readonly.is_set()) |
| 216 | |
| 217 | def testMountTempDir(self): |
| 218 | """Test that mount succeeds if target dir is writable.""" |
| 219 | self.assertFalse(self.deploy._target_dir_is_still_readonly.is_set()) |
Mike Frysinger | 74ccd57 | 2015-05-21 21:18:20 -0400 | [diff] [blame] | 220 | self.PatchObject(remote_access.RemoteDevice, 'IsDirWritable', |
Robert Flack | 1dc7ea8 | 2014-11-26 13:50:24 -0500 | [diff] [blame] | 221 | return_value=True, autospec=True) |
| 222 | self.deploy._MountRootfsAsWritable() |
| 223 | self.assertFalse(self.deploy._target_dir_is_still_readonly.is_set()) |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 224 | |
| 225 | |
Ryan Cui | ef91e70 | 2013-02-04 12:06:36 -0800 | [diff] [blame] | 226 | class TestUiJobStarted(DeployTest): |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 227 | """Test detection of a running 'ui' job.""" |
| 228 | |
Ryan Cui | f2d1a58 | 2013-02-19 14:08:13 -0800 | [diff] [blame] | 229 | def MockStatusUiCmd(self, **kwargs): |
| 230 | self.deploy_mock.rsh_mock.AddCmdResult('status ui', **kwargs) |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 231 | |
| 232 | def testUiJobStartedFalse(self): |
| 233 | """Correct results with a stopped job.""" |
Ryan Cui | f2d1a58 | 2013-02-19 14:08:13 -0800 | [diff] [blame] | 234 | self.MockStatusUiCmd(output='ui stop/waiting') |
| 235 | self.assertFalse(self.deploy._CheckUiJobStarted()) |
| 236 | |
| 237 | def testNoUiJob(self): |
| 238 | """Correct results when the job doesn't exist.""" |
| 239 | self.MockStatusUiCmd(error='start: Unknown job: ui', returncode=1) |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 240 | self.assertFalse(self.deploy._CheckUiJobStarted()) |
| 241 | |
| 242 | def testCheckRootfsWriteableTrue(self): |
| 243 | """Correct results with a running job.""" |
Ryan Cui | f2d1a58 | 2013-02-19 14:08:13 -0800 | [diff] [blame] | 244 | self.MockStatusUiCmd(output='ui start/running, process 297') |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 245 | self.assertTrue(self.deploy._CheckUiJobStarted()) |
| 246 | |
| 247 | |
Ryan Cui | ef91e70 | 2013-02-04 12:06:36 -0800 | [diff] [blame] | 248 | class StagingTest(cros_test_lib.MockTempDirTestCase): |
| 249 | """Test user-mode and ebuild-mode staging functionality.""" |
| 250 | |
| 251 | def setUp(self): |
Ryan Cui | ef91e70 | 2013-02-04 12:06:36 -0800 | [diff] [blame] | 252 | self.staging_dir = os.path.join(self.tempdir, 'staging') |
| 253 | self.build_dir = os.path.join(self.tempdir, 'build_dir') |
Ryan Cui | 686ec05 | 2013-02-12 16:39:41 -0800 | [diff] [blame] | 254 | self.common_flags = ['--build-dir', self.build_dir, |
| 255 | '--board=lumpy', '--staging-only', '--cache-dir', |
| 256 | self.tempdir] |
Ryan Cui | a0215a7 | 2013-02-14 16:20:45 -0800 | [diff] [blame] | 257 | self.sdk_mock = self.StartPatcher(cros_chrome_sdk_unittest.SDKFetcherMock()) |
Ryan Cui | 686ec05 | 2013-02-12 16:39:41 -0800 | [diff] [blame] | 258 | self.PatchObject( |
| 259 | osutils, 'SourceEnvironment', autospec=True, |
| 260 | return_value={'STRIP': 'x86_64-cros-linux-gnu-strip'}) |
Ryan Cui | ef91e70 | 2013-02-04 12:06:36 -0800 | [diff] [blame] | 261 | |
David James | a6e0889 | 2013-03-01 13:34:11 -0800 | [diff] [blame] | 262 | def testSingleFileDeployFailure(self): |
| 263 | """Default staging enforces that mandatory files are copied""" |
Ryan Cui | ef91e70 | 2013-02-04 12:06:36 -0800 | [diff] [blame] | 264 | options, _ = _ParseCommandLine(self.common_flags) |
David James | a6e0889 | 2013-03-01 13:34:11 -0800 | [diff] [blame] | 265 | osutils.Touch(os.path.join(self.build_dir, 'chrome'), makedirs=True) |
| 266 | self.assertRaises( |
| 267 | chrome_util.MissingPathError, deploy_chrome._PrepareStagingDir, |
Daniel Erat | c89829c | 2014-05-12 17:24:21 -0700 | [diff] [blame] | 268 | options, self.tempdir, self.staging_dir, chrome_util._COPY_PATHS_CHROME) |
Ryan Cui | ef91e70 | 2013-02-04 12:06:36 -0800 | [diff] [blame] | 269 | |
David James | a6e0889 | 2013-03-01 13:34:11 -0800 | [diff] [blame] | 270 | def testSloppyDeployFailure(self): |
| 271 | """Sloppy staging enforces that at least one file is copied.""" |
| 272 | options, _ = _ParseCommandLine(self.common_flags + ['--sloppy']) |
| 273 | self.assertRaises( |
| 274 | chrome_util.MissingPathError, deploy_chrome._PrepareStagingDir, |
Daniel Erat | c89829c | 2014-05-12 17:24:21 -0700 | [diff] [blame] | 275 | options, self.tempdir, self.staging_dir, chrome_util._COPY_PATHS_CHROME) |
David James | a6e0889 | 2013-03-01 13:34:11 -0800 | [diff] [blame] | 276 | |
| 277 | def testSloppyDeploySuccess(self): |
| 278 | """Sloppy staging - stage one file.""" |
| 279 | options, _ = _ParseCommandLine(self.common_flags + ['--sloppy']) |
| 280 | osutils.Touch(os.path.join(self.build_dir, 'chrome'), makedirs=True) |
Steve Fung | e984a53 | 2013-11-25 17:09:25 -0800 | [diff] [blame] | 281 | deploy_chrome._PrepareStagingDir(options, self.tempdir, self.staging_dir, |
Daniel Erat | c89829c | 2014-05-12 17:24:21 -0700 | [diff] [blame] | 282 | chrome_util._COPY_PATHS_CHROME) |
David James | a6e0889 | 2013-03-01 13:34:11 -0800 | [diff] [blame] | 283 | |
Ryan Cui | ef91e70 | 2013-02-04 12:06:36 -0800 | [diff] [blame] | 284 | def testEmptyDeployStrict(self): |
David James | a6e0889 | 2013-03-01 13:34:11 -0800 | [diff] [blame] | 285 | """Strict staging fails when there are no files.""" |
Ryan Cui | ef91e70 | 2013-02-04 12:06:36 -0800 | [diff] [blame] | 286 | options, _ = _ParseCommandLine( |
| 287 | self.common_flags + ['--gyp-defines', 'chromeos=1', '--strict']) |
Ryan Cui | 686ec05 | 2013-02-12 16:39:41 -0800 | [diff] [blame] | 288 | |
Ryan Cui | ef91e70 | 2013-02-04 12:06:36 -0800 | [diff] [blame] | 289 | self.assertRaises( |
| 290 | chrome_util.MissingPathError, deploy_chrome._PrepareStagingDir, |
Daniel Erat | c89829c | 2014-05-12 17:24:21 -0700 | [diff] [blame] | 291 | options, self.tempdir, self.staging_dir, chrome_util._COPY_PATHS_CHROME) |
Steve Fung | e984a53 | 2013-11-25 17:09:25 -0800 | [diff] [blame] | 292 | |
| 293 | |
| 294 | class DeployTestBuildDir(cros_test_lib.MockTempDirTestCase): |
Daniel Erat | 1ae4638 | 2014-08-14 10:23:39 -0700 | [diff] [blame] | 295 | """Set up a deploy object with a build-dir for use in deployment type tests""" |
Steve Fung | e984a53 | 2013-11-25 17:09:25 -0800 | [diff] [blame] | 296 | |
| 297 | def _GetDeployChrome(self, args): |
| 298 | options, _ = _ParseCommandLine(args) |
| 299 | return deploy_chrome.DeployChrome( |
| 300 | options, self.tempdir, os.path.join(self.tempdir, 'staging')) |
| 301 | |
| 302 | def setUp(self): |
| 303 | self.staging_dir = os.path.join(self.tempdir, 'staging') |
| 304 | self.build_dir = os.path.join(self.tempdir, 'build_dir') |
| 305 | self.deploy_mock = self.StartPatcher(DeployChromeMock()) |
| 306 | self.deploy = self._GetDeployChrome( |
| 307 | list(_REGULAR_TO) + ['--build-dir', self.build_dir, |
| 308 | '--board=lumpy', '--staging-only', '--cache-dir', |
| 309 | self.tempdir, '--sloppy']) |
| 310 | |
Daniel Erat | 1ae4638 | 2014-08-14 10:23:39 -0700 | [diff] [blame] | 311 | def getCopyPath(self, source_path): |
| 312 | """Return a chrome_util.Path or None if not present.""" |
| 313 | paths = [p for p in self.deploy.copy_paths if p.src == source_path] |
| 314 | return paths[0] if paths else None |
Steve Fung | e984a53 | 2013-11-25 17:09:25 -0800 | [diff] [blame] | 315 | |
Daniel Erat | 1ae4638 | 2014-08-14 10:23:39 -0700 | [diff] [blame] | 316 | class TestDeploymentType(DeployTestBuildDir): |
Steve Fung | e984a53 | 2013-11-25 17:09:25 -0800 | [diff] [blame] | 317 | """Test detection of deployment type using build dir.""" |
| 318 | |
Daniel Erat | 9813f0e | 2014-11-12 11:00:28 -0700 | [diff] [blame] | 319 | def testEnvoyDetection(self): |
| 320 | """Check for an envoy deployment""" |
| 321 | osutils.Touch(os.path.join(self.deploy.options.build_dir, 'envoy_shell'), |
| 322 | makedirs=True) |
| 323 | self.deploy._CheckDeployType() |
| 324 | self.assertTrue(self.getCopyPath('envoy_shell')) |
| 325 | self.assertFalse(self.getCopyPath('app_shell')) |
| 326 | self.assertFalse(self.getCopyPath('chrome')) |
| 327 | |
Daniel Erat | 1ae4638 | 2014-08-14 10:23:39 -0700 | [diff] [blame] | 328 | def testAppShellDetection(self): |
| 329 | """Check for an app_shell deployment""" |
| 330 | osutils.Touch(os.path.join(self.deploy.options.build_dir, 'app_shell'), |
Steve Fung | e984a53 | 2013-11-25 17:09:25 -0800 | [diff] [blame] | 331 | makedirs=True) |
| 332 | self.deploy._CheckDeployType() |
Daniel Erat | 1ae4638 | 2014-08-14 10:23:39 -0700 | [diff] [blame] | 333 | self.assertTrue(self.getCopyPath('app_shell')) |
| 334 | self.assertFalse(self.getCopyPath('chrome')) |
Daniel Erat | 9813f0e | 2014-11-12 11:00:28 -0700 | [diff] [blame] | 335 | self.assertFalse(self.getCopyPath('envoy_shell')) |
Steve Fung | e984a53 | 2013-11-25 17:09:25 -0800 | [diff] [blame] | 336 | |
Daniel Erat | 1ae4638 | 2014-08-14 10:23:39 -0700 | [diff] [blame] | 337 | def testChromeAndAppShellDetection(self): |
Daniel Erat | 9813f0e | 2014-11-12 11:00:28 -0700 | [diff] [blame] | 338 | """Check for a chrome deployment when app_shell/envoy_shell also exist.""" |
Steve Fung | 63d705d | 2014-03-16 03:14:03 -0700 | [diff] [blame] | 339 | osutils.Touch(os.path.join(self.deploy.options.build_dir, 'chrome'), |
| 340 | makedirs=True) |
Daniel Erat | 1ae4638 | 2014-08-14 10:23:39 -0700 | [diff] [blame] | 341 | osutils.Touch(os.path.join(self.deploy.options.build_dir, 'app_shell'), |
Steve Fung | 63d705d | 2014-03-16 03:14:03 -0700 | [diff] [blame] | 342 | makedirs=True) |
Daniel Erat | 9813f0e | 2014-11-12 11:00:28 -0700 | [diff] [blame] | 343 | osutils.Touch(os.path.join(self.deploy.options.build_dir, 'envoy_shell'), |
| 344 | makedirs=True) |
Steve Fung | 63d705d | 2014-03-16 03:14:03 -0700 | [diff] [blame] | 345 | self.deploy._CheckDeployType() |
Daniel Erat | 1ae4638 | 2014-08-14 10:23:39 -0700 | [diff] [blame] | 346 | self.assertTrue(self.getCopyPath('chrome')) |
Daniel Erat | 9813f0e | 2014-11-12 11:00:28 -0700 | [diff] [blame] | 347 | self.assertFalse(self.getCopyPath('app_shell')) |
| 348 | self.assertFalse(self.getCopyPath('envoy_shell')) |
Steve Fung | 63d705d | 2014-03-16 03:14:03 -0700 | [diff] [blame] | 349 | |
Steve Fung | e984a53 | 2013-11-25 17:09:25 -0800 | [diff] [blame] | 350 | def testChromeDetection(self): |
| 351 | """Check for a regular chrome deployment""" |
| 352 | osutils.Touch(os.path.join(self.deploy.options.build_dir, 'chrome'), |
| 353 | makedirs=True) |
| 354 | self.deploy._CheckDeployType() |
Daniel Erat | 1ae4638 | 2014-08-14 10:23:39 -0700 | [diff] [blame] | 355 | self.assertTrue(self.getCopyPath('chrome')) |
Daniel Erat | 9813f0e | 2014-11-12 11:00:28 -0700 | [diff] [blame] | 356 | self.assertFalse(self.getCopyPath('app_shell')) |
| 357 | self.assertFalse(self.getCopyPath('envoy_shell')) |