blob: f28abf75dd0b357d0dc9302f69e51b2e7eb8f2c2 [file] [log] [blame]
Alex Kleina2e42c42019-04-17 16:13:19 -06001# -*- coding: utf-8 -*-
2# Copyright 2019 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
6"""The test controller tests."""
7
8from __future__ import print_function
9
Michael Mortensen8ca4d3b2019-11-27 09:35:22 -070010import os
11
Evan Hernandezdc3f0bb2019-06-06 12:46:52 -060012import contextlib
Alex Kleinfa6ebdc2019-05-10 10:57:31 -060013import mock
14
Alex Klein231d2da2019-07-22 16:44:45 -060015from chromite.api import api_config
Alex Klein8cb365a2019-05-15 16:24:53 -060016from chromite.api import controller
Alex Kleina2e42c42019-04-17 16:13:19 -060017from chromite.api.controller import test as test_controller
Evan Hernandez4e388a52019-05-01 12:16:33 -060018from chromite.api.gen.chromiumos import common_pb2
Alex Kleina2e42c42019-04-17 16:13:19 -060019from chromite.api.gen.chromite.api import test_pb2
Evan Hernandeze1e05d32019-07-19 12:32:18 -060020from chromite.lib import chroot_lib
Alex Kleina2e42c42019-04-17 16:13:19 -060021from chromite.lib import cros_build_lib
22from chromite.lib import cros_test_lib
Evan Hernandezdc3f0bb2019-06-06 12:46:52 -060023from chromite.lib import image_lib
Alex Kleina2e42c42019-04-17 16:13:19 -060024from chromite.lib import osutils
25from chromite.lib import portage_util
Evan Hernandezdc3f0bb2019-06-06 12:46:52 -060026from chromite.scripts import cros_set_lsb_release
27from chromite.service import test as test_service
Mike Frysingere652ba12019-09-08 00:57:43 -040028from chromite.utils import key_value_store
Alex Kleina2e42c42019-04-17 16:13:19 -060029
30
Michael Mortensen8ca4d3b2019-11-27 09:35:22 -070031class DebugInfoTestTest(cros_test_lib.MockTempDirTestCase,
32 api_config.ApiConfigMixin):
33 """Tests for the DebugInfoTest function."""
34
35 def setUp(self):
36 self.board = 'board'
37 self.chroot_path = os.path.join(self.tempdir, 'chroot')
38 self.sysroot_path = '/build/board'
39 self.full_sysroot_path = os.path.join(self.chroot_path,
40 self.sysroot_path.lstrip(os.sep))
41 osutils.SafeMakedirs(self.full_sysroot_path)
42
43 def _GetInput(self, sysroot_path=None, build_target=None):
44 """Helper to build an input message instance."""
45 proto = test_pb2.DebugInfoTestRequest()
46 if sysroot_path:
47 proto.sysroot.path = sysroot_path
48 if build_target:
49 proto.sysroot.build_target.name = build_target
50 return proto
51
52 def _GetOutput(self):
53 """Helper to get an empty output message instance."""
54 return test_pb2.DebugInfoTestResponse()
55
56 def testValidateOnly(self):
57 """Sanity check that a validate only call does not execute any logic."""
58 patch = self.PatchObject(test_service, 'DebugInfoTest')
59 input_msg = self._GetInput(sysroot_path=self.full_sysroot_path)
60 test_controller.DebugInfoTest(input_msg, self._GetOutput(),
61 self.validate_only_config)
62 patch.assert_not_called()
63
64 def testNoBuildTargetNoSysrootFails(self):
65 """Test missing build target name and sysroot path fails."""
66 input_msg = self._GetInput()
67 output_msg = self._GetOutput()
68 with self.assertRaises(cros_build_lib.DieSystemExit):
69 test_controller.DebugInfoTest(input_msg, output_msg, self.api_config)
70
71 def testDebugInfoTest(self):
72 """Call DebugInfoTest with valid sysroot_path."""
73 request = self._GetInput(sysroot_path=self.full_sysroot_path)
74
75 test_controller.DebugInfoTest(request, self._GetOutput(), self.api_config)
76
77
Alex Klein231d2da2019-07-22 16:44:45 -060078class BuildTargetUnitTestTest(cros_test_lib.MockTempDirTestCase,
79 api_config.ApiConfigMixin):
Alex Kleina2e42c42019-04-17 16:13:19 -060080 """Tests for the UnitTest function."""
81
82 def _GetInput(self, board=None, result_path=None, chroot_path=None,
Alex Kleinf2674462019-05-16 16:47:24 -060083 cache_dir=None, empty_sysroot=None, blacklist=None):
Alex Kleina2e42c42019-04-17 16:13:19 -060084 """Helper to build an input message instance."""
Alex Kleinf2674462019-05-16 16:47:24 -060085 formatted_blacklist = []
86 for pkg in blacklist or []:
87 formatted_blacklist.append({'category': pkg.category,
88 'package_name': pkg.package})
89
Alex Kleina2e42c42019-04-17 16:13:19 -060090 return test_pb2.BuildTargetUnitTestRequest(
91 build_target={'name': board}, result_path=result_path,
Alex Kleinfa6ebdc2019-05-10 10:57:31 -060092 chroot={'path': chroot_path, 'cache_dir': cache_dir},
Alex Kleinf2674462019-05-16 16:47:24 -060093 flags={'empty_sysroot': empty_sysroot},
94 package_blacklist=formatted_blacklist,
Alex Kleina2e42c42019-04-17 16:13:19 -060095 )
96
97 def _GetOutput(self):
98 """Helper to get an empty output message instance."""
99 return test_pb2.BuildTargetUnitTestResponse()
100
Alex Klein231d2da2019-07-22 16:44:45 -0600101 def testValidateOnly(self):
102 """Sanity check that a validate only call does not execute any logic."""
103 patch = self.PatchObject(test_service, 'BuildTargetUnitTest')
104
105 input_msg = self._GetInput(board='board', result_path=self.tempdir)
106 test_controller.BuildTargetUnitTest(input_msg, self._GetOutput(),
107 self.validate_only_config)
108 patch.assert_not_called()
109
Alex Kleina2e42c42019-04-17 16:13:19 -0600110 def testNoArgumentFails(self):
111 """Test no arguments fails."""
112 input_msg = self._GetInput()
113 output_msg = self._GetOutput()
114 with self.assertRaises(cros_build_lib.DieSystemExit):
Alex Klein231d2da2019-07-22 16:44:45 -0600115 test_controller.BuildTargetUnitTest(input_msg, output_msg,
116 self.api_config)
Alex Kleina2e42c42019-04-17 16:13:19 -0600117
118 def testNoBuildTargetFails(self):
119 """Test missing build target name fails."""
120 input_msg = self._GetInput(result_path=self.tempdir)
121 output_msg = self._GetOutput()
122 with self.assertRaises(cros_build_lib.DieSystemExit):
Alex Klein231d2da2019-07-22 16:44:45 -0600123 test_controller.BuildTargetUnitTest(input_msg, output_msg,
124 self.api_config)
Alex Kleina2e42c42019-04-17 16:13:19 -0600125
126 def testNoResultPathFails(self):
127 """Test missing result path fails."""
128 # Missing result_path.
129 input_msg = self._GetInput(board='board')
130 output_msg = self._GetOutput()
131 with self.assertRaises(cros_build_lib.DieSystemExit):
Alex Klein231d2da2019-07-22 16:44:45 -0600132 test_controller.BuildTargetUnitTest(input_msg, output_msg,
133 self.api_config)
Alex Kleina2e42c42019-04-17 16:13:19 -0600134
135 def testPackageBuildFailure(self):
136 """Test handling of raised BuildPackageFailure."""
137 tempdir = osutils.TempDir(base_dir=self.tempdir)
138 self.PatchObject(osutils, 'TempDir', return_value=tempdir)
139
140 pkgs = ['cat/pkg', 'foo/bar']
141 expected = [('cat', 'pkg'), ('foo', 'bar')]
Alex Kleina2e42c42019-04-17 16:13:19 -0600142
Alex Klein38c7d9e2019-05-08 09:31:19 -0600143 result = test_service.BuildTargetUnitTestResult(1, None)
144 result.failed_cpvs = [portage_util.SplitCPV(p, strict=False) for p in pkgs]
145 self.PatchObject(test_service, 'BuildTargetUnitTest', return_value=result)
Alex Kleina2e42c42019-04-17 16:13:19 -0600146
147 input_msg = self._GetInput(board='board', result_path=self.tempdir)
148 output_msg = self._GetOutput()
149
Alex Klein231d2da2019-07-22 16:44:45 -0600150 rc = test_controller.BuildTargetUnitTest(input_msg, output_msg,
151 self.api_config)
Alex Kleina2e42c42019-04-17 16:13:19 -0600152
Alex Klein8cb365a2019-05-15 16:24:53 -0600153 self.assertEqual(controller.RETURN_CODE_UNSUCCESSFUL_RESPONSE_AVAILABLE, rc)
Alex Kleina2e42c42019-04-17 16:13:19 -0600154 self.assertTrue(output_msg.failed_packages)
155 failed = []
156 for pi in output_msg.failed_packages:
157 failed.append((pi.category, pi.package_name))
Mike Frysinger678735c2019-09-28 18:23:28 -0400158 self.assertCountEqual(expected, failed)
Alex Kleina2e42c42019-04-17 16:13:19 -0600159
160 def testOtherBuildScriptFailure(self):
161 """Test build script failure due to non-package emerge error."""
162 tempdir = osutils.TempDir(base_dir=self.tempdir)
163 self.PatchObject(osutils, 'TempDir', return_value=tempdir)
164
Alex Klein38c7d9e2019-05-08 09:31:19 -0600165 result = test_service.BuildTargetUnitTestResult(1, None)
166 self.PatchObject(test_service, 'BuildTargetUnitTest', return_value=result)
Alex Kleina2e42c42019-04-17 16:13:19 -0600167
Alex Kleinf2674462019-05-16 16:47:24 -0600168 pkgs = ['foo/bar', 'cat/pkg']
169 blacklist = [portage_util.SplitCPV(p, strict=False) for p in pkgs]
Alex Kleinfa6ebdc2019-05-10 10:57:31 -0600170 input_msg = self._GetInput(board='board', result_path=self.tempdir,
Alex Kleinf2674462019-05-16 16:47:24 -0600171 empty_sysroot=True, blacklist=blacklist)
Alex Kleina2e42c42019-04-17 16:13:19 -0600172 output_msg = self._GetOutput()
173
Alex Klein231d2da2019-07-22 16:44:45 -0600174 rc = test_controller.BuildTargetUnitTest(input_msg, output_msg,
175 self.api_config)
Alex Kleina2e42c42019-04-17 16:13:19 -0600176
Alex Klein8cb365a2019-05-15 16:24:53 -0600177 self.assertEqual(controller.RETURN_CODE_COMPLETED_UNSUCCESSFULLY, rc)
Alex Kleina2e42c42019-04-17 16:13:19 -0600178 self.assertFalse(output_msg.failed_packages)
Evan Hernandez4e388a52019-05-01 12:16:33 -0600179
180
Michael Mortensen8ca4d3b2019-11-27 09:35:22 -0700181class ChromiteUnitTestTest(cros_test_lib.MockTestCase,
182 api_config.ApiConfigMixin):
183 """Tests for the ChromiteInfoTest function."""
184
185 def setUp(self):
186 self.board = 'board'
187 self.chroot_path = '/path/to/chroot'
188
189 def _GetInput(self, chroot_path=None):
190 """Helper to build an input message instance."""
191 proto = test_pb2.ChromiteUnitTestRequest(
192 chroot={'path': chroot_path},
193 )
194 return proto
195
196 def _GetOutput(self):
197 """Helper to get an empty output message instance."""
198 return test_pb2.ChromiteUnitTestResponse()
199
200 def testValidateOnly(self):
201 """Sanity check that a validate only call does not execute any logic."""
202 patch = self.PatchObject(cros_build_lib, 'run')
203
204 input_msg = self._GetInput(chroot_path=self.chroot_path)
205 test_controller.ChromiteUnitTest(input_msg, self._GetOutput(),
206 self.validate_only_config)
207 patch.assert_not_called()
208
209 def testChromiteUnitTest(self):
210 """Call ChromiteUnitTest with mocked cros_build_lib.run."""
211 request = self._GetInput(chroot_path=self.chroot_path)
212 patch = self.PatchObject(
213 cros_build_lib, 'run',
214 return_value=cros_build_lib.CommandResult(returncode=0))
215
216 test_controller.ChromiteUnitTest(request, self._GetOutput(),
217 self.api_config)
218 patch.assert_called_once()
219
220
Alex Klein4bc8f4f2019-08-16 14:53:30 -0600221class CrosSigningTestTest(cros_test_lib.RunCommandTestCase,
222 api_config.ApiConfigMixin):
223 """CrosSigningTest tests."""
224
225 def testValidateOnly(self):
226 """Sanity check that a validate only call does not execute any logic."""
227 test_controller.CrosSigningTest(None, None, self.validate_only_config)
228 self.assertFalse(self.rc.call_count)
229
230
Michael Mortensenc28d6f12019-10-03 13:34:51 -0600231class SimpleChromeWorkflowTestTest(cros_test_lib.MockTestCase,
232 api_config.ApiConfigMixin):
233 """Test the SimpleChromeWorkflowTest endpoint."""
234
235 @staticmethod
236 def _Output():
237 return test_pb2.SimpleChromeWorkflowTestResponse()
238
239 def _Input(self, sysroot_path=None, build_target=None, chrome_root=None,
240 goma_config=None):
241 proto = test_pb2.SimpleChromeWorkflowTestRequest()
242 if sysroot_path:
243 proto.sysroot.path = sysroot_path
244 if build_target:
245 proto.sysroot.build_target.name = build_target
246 if chrome_root:
247 proto.chrome_root = chrome_root
248 if goma_config:
249 proto.goma_config = goma_config
250 return proto
251
252 def setUp(self):
253 self.chrome_path = 'path/to/chrome'
254 self.sysroot_dir = 'build/board'
255 self.build_target = 'amd64'
256 self.mock_simple_chrome_workflow_test = self.PatchObject(
257 test_service, 'SimpleChromeWorkflowTest')
258
259 def testMissingBuildTarget(self):
260 """Test VmTest dies when build_target not set."""
261 input_proto = self._Input(build_target=None, sysroot_path='/sysroot/dir',
262 chrome_root='/chrome/path')
263 with self.assertRaises(cros_build_lib.DieSystemExit):
264 test_controller.SimpleChromeWorkflowTest(input_proto, None,
265 self.api_config)
266
267 def testMissingSysrootPath(self):
268 """Test VmTest dies when build_target not set."""
269 input_proto = self._Input(build_target='board', sysroot_path=None,
270 chrome_root='/chrome/path')
271 with self.assertRaises(cros_build_lib.DieSystemExit):
272 test_controller.SimpleChromeWorkflowTest(input_proto, None,
273 self.api_config)
274
275 def testMissingChromeRoot(self):
276 """Test VmTest dies when build_target not set."""
277 input_proto = self._Input(build_target='board', sysroot_path='/sysroot/dir',
278 chrome_root=None)
279 with self.assertRaises(cros_build_lib.DieSystemExit):
280 test_controller.SimpleChromeWorkflowTest(input_proto, None,
281 self.api_config)
282
283 def testSimpleChromeWorkflowTest(self):
284 """Call SimpleChromeWorkflowTest with valid args and temp dir."""
285 request = self._Input(sysroot_path='sysroot_path', build_target='board',
286 chrome_root='/path/to/chrome')
287 response = self._Output()
288
289 test_controller.SimpleChromeWorkflowTest(request, response, self.api_config)
290 self.mock_simple_chrome_workflow_test.assert_called()
291
292 def testValidateOnly(self):
293 request = self._Input(sysroot_path='sysroot_path', build_target='board',
294 chrome_root='/path/to/chrome')
295 test_controller.SimpleChromeWorkflowTest(request, self._Output(),
296 self.validate_only_config)
297 self.mock_simple_chrome_workflow_test.assert_not_called()
298
299
Alex Klein231d2da2019-07-22 16:44:45 -0600300class VmTestTest(cros_test_lib.RunCommandTestCase, api_config.ApiConfigMixin):
Evan Hernandez4e388a52019-05-01 12:16:33 -0600301 """Test the VmTest endpoint."""
302
303 def _GetInput(self, **kwargs):
304 values = dict(
305 build_target=common_pb2.BuildTarget(name='target'),
Alex Klein311b8022019-06-05 16:00:07 -0600306 vm_path=common_pb2.Path(path='/path/to/image.bin',
307 location=common_pb2.Path.INSIDE),
Evan Hernandez4e388a52019-05-01 12:16:33 -0600308 test_harness=test_pb2.VmTestRequest.TAST,
309 vm_tests=[test_pb2.VmTestRequest.VmTest(pattern='suite')],
310 ssh_options=test_pb2.VmTestRequest.SshOptions(
Alex Klein231d2da2019-07-22 16:44:45 -0600311 port=1234, private_key_path={'path': '/path/to/id_rsa',
Alex Kleinaa705412019-06-04 15:00:30 -0600312 'location': common_pb2.Path.INSIDE}),
Evan Hernandez4e388a52019-05-01 12:16:33 -0600313 )
314 values.update(kwargs)
315 return test_pb2.VmTestRequest(**values)
316
Alex Klein231d2da2019-07-22 16:44:45 -0600317 def testValidateOnly(self):
318 """Sanity check that a validate only call does not execute any logic."""
319 test_controller.VmTest(self._GetInput(), None, self.validate_only_config)
320 self.assertEqual(0, self.rc.call_count)
Evan Hernandez4e388a52019-05-01 12:16:33 -0600321
322 def testTastAllOptions(self):
323 """Test VmTest for Tast with all options set."""
Alex Klein231d2da2019-07-22 16:44:45 -0600324 test_controller.VmTest(self._GetInput(), None, self.api_config)
325 self.assertCommandContains([
Achuith Bhandarkara9e9c3d2019-05-22 13:56:11 -0700326 'cros_run_test', '--debug', '--no-display', '--copy-on-write',
Evan Hernandez4e388a52019-05-01 12:16:33 -0600327 '--board', 'target',
328 '--image-path', '/path/to/image.bin',
329 '--tast', 'suite',
330 '--ssh-port', '1234',
331 '--private-key', '/path/to/id_rsa',
332 ])
333
334 def testAutotestAllOptions(self):
335 """Test VmTest for Autotest with all options set."""
336 input_proto = self._GetInput(test_harness=test_pb2.VmTestRequest.AUTOTEST)
Alex Klein231d2da2019-07-22 16:44:45 -0600337 test_controller.VmTest(input_proto, None, self.api_config)
338 self.assertCommandContains([
Achuith Bhandarkara9e9c3d2019-05-22 13:56:11 -0700339 'cros_run_test', '--debug', '--no-display', '--copy-on-write',
Evan Hernandez4e388a52019-05-01 12:16:33 -0600340 '--board', 'target',
341 '--image-path', '/path/to/image.bin',
342 '--autotest', 'suite',
343 '--ssh-port', '1234',
344 '--private-key', '/path/to/id_rsa',
345 '--test_that-args=--whitelist-chrome-crashes',
346 ])
347
348 def testMissingBuildTarget(self):
349 """Test VmTest dies when build_target not set."""
350 input_proto = self._GetInput(build_target=None)
351 with self.assertRaises(cros_build_lib.DieSystemExit):
Alex Klein231d2da2019-07-22 16:44:45 -0600352 test_controller.VmTest(input_proto, None, self.api_config)
Evan Hernandez4e388a52019-05-01 12:16:33 -0600353
354 def testMissingVmImage(self):
355 """Test VmTest dies when vm_image not set."""
Alex Klein311b8022019-06-05 16:00:07 -0600356 input_proto = self._GetInput(vm_path=None)
Evan Hernandez4e388a52019-05-01 12:16:33 -0600357 with self.assertRaises(cros_build_lib.DieSystemExit):
Alex Klein231d2da2019-07-22 16:44:45 -0600358 test_controller.VmTest(input_proto, None, self.api_config)
Evan Hernandez4e388a52019-05-01 12:16:33 -0600359
360 def testMissingTestHarness(self):
361 """Test VmTest dies when test_harness not specified."""
362 input_proto = self._GetInput(
363 test_harness=test_pb2.VmTestRequest.UNSPECIFIED)
364 with self.assertRaises(cros_build_lib.DieSystemExit):
Alex Klein231d2da2019-07-22 16:44:45 -0600365 test_controller.VmTest(input_proto, None, self.api_config)
Evan Hernandez4e388a52019-05-01 12:16:33 -0600366
367 def testMissingVmTests(self):
368 """Test VmTest dies when vm_tests not set."""
369 input_proto = self._GetInput(vm_tests=[])
370 with self.assertRaises(cros_build_lib.DieSystemExit):
Alex Klein231d2da2019-07-22 16:44:45 -0600371 test_controller.VmTest(input_proto, None, self.api_config)
Evan Hernandezdc3f0bb2019-06-06 12:46:52 -0600372
373
Alex Klein231d2da2019-07-22 16:44:45 -0600374class MoblabVmTestTest(cros_test_lib.MockTestCase, api_config.ApiConfigMixin):
Evan Hernandezdc3f0bb2019-06-06 12:46:52 -0600375 """Test the MoblabVmTest endpoint."""
376
377 @staticmethod
378 def _Payload(path):
379 return test_pb2.MoblabVmTestRequest.Payload(
380 path=common_pb2.Path(path=path))
381
382 @staticmethod
383 def _Output():
384 return test_pb2.MoblabVmTestResponse()
385
386 def _Input(self):
387 return test_pb2.MoblabVmTestRequest(
Evan Hernandeze1e05d32019-07-19 12:32:18 -0600388 chroot=common_pb2.Chroot(path=self.chroot_dir),
Evan Hernandezdc3f0bb2019-06-06 12:46:52 -0600389 image_payload=self._Payload(self.image_payload_dir),
390 cache_payloads=[self._Payload(self.autotest_payload_dir)])
391
392 def setUp(self):
Evan Hernandeze1e05d32019-07-19 12:32:18 -0600393 self.chroot_dir = '/chroot'
394 self.chroot_tmp_dir = '/chroot/tmp'
Evan Hernandezdc3f0bb2019-06-06 12:46:52 -0600395 self.image_payload_dir = '/payloads/image'
396 self.autotest_payload_dir = '/payloads/autotest'
397 self.builder = 'moblab-generic-vm/R12-3.4.5-67.890'
398 self.image_cache_dir = '/mnt/moblab/cache'
399 self.image_mount_dir = '/mnt/image'
400
Evan Hernandeze1e05d32019-07-19 12:32:18 -0600401 self.PatchObject(chroot_lib.Chroot, 'tempdir', osutils.TempDir)
Evan Hernandez655e8042019-06-13 12:50:44 -0600402
Evan Hernandezdc3f0bb2019-06-06 12:46:52 -0600403 self.mock_create_moblab_vms = self.PatchObject(
404 test_service, 'CreateMoblabVm')
405 self.mock_prepare_moblab_vm_image_cache = self.PatchObject(
406 test_service, 'PrepareMoblabVmImageCache',
407 return_value=self.image_cache_dir)
408 self.mock_run_moblab_vm_tests = self.PatchObject(
409 test_service, 'RunMoblabVmTest')
410 self.mock_validate_moblab_vm_tests = self.PatchObject(
411 test_service, 'ValidateMoblabVmTest')
412
413 @contextlib.contextmanager
Alex Klein38c7d9e2019-05-08 09:31:19 -0600414 def MockLoopbackPartitions(*_args, **_kwargs):
Evan Hernandezdc3f0bb2019-06-06 12:46:52 -0600415 mount = mock.MagicMock()
Evan Hernandez40ee7452019-06-13 12:51:43 -0600416 mount.Mount.return_value = [self.image_mount_dir]
Evan Hernandezdc3f0bb2019-06-06 12:46:52 -0600417 yield mount
Alex Klein231d2da2019-07-22 16:44:45 -0600418
Evan Hernandezdc3f0bb2019-06-06 12:46:52 -0600419 self.PatchObject(image_lib, 'LoopbackPartitions', MockLoopbackPartitions)
420
Alex Klein231d2da2019-07-22 16:44:45 -0600421 def testValidateOnly(self):
422 """Sanity check that a validate only call does not execute any logic."""
423 test_controller.MoblabVmTest(self._Input(), self._Output(),
424 self.validate_only_config)
425 self.mock_create_moblab_vms.assert_not_called()
426
Evan Hernandezdc3f0bb2019-06-06 12:46:52 -0600427 def testImageContainsBuilder(self):
428 """MoblabVmTest calls service with correct args."""
429 request = self._Input()
430 response = self._Output()
431
432 self.PatchObject(
Mike Frysingere652ba12019-09-08 00:57:43 -0400433 key_value_store, 'LoadFile',
Evan Hernandezdc3f0bb2019-06-06 12:46:52 -0600434 return_value={cros_set_lsb_release.LSB_KEY_BUILDER_PATH: self.builder})
435
Alex Klein231d2da2019-07-22 16:44:45 -0600436 test_controller.MoblabVmTest(request, response, self.api_config)
Evan Hernandezdc3f0bb2019-06-06 12:46:52 -0600437
438 self.assertEqual(
439 self.mock_create_moblab_vms.call_args_list,
Evan Hernandeze1e05d32019-07-19 12:32:18 -0600440 [mock.call(mock.ANY, self.chroot_dir, self.image_payload_dir)])
Evan Hernandezdc3f0bb2019-06-06 12:46:52 -0600441 self.assertEqual(
442 self.mock_prepare_moblab_vm_image_cache.call_args_list,
443 [mock.call(mock.ANY, self.builder, [self.autotest_payload_dir])])
444 self.assertEqual(
445 self.mock_run_moblab_vm_tests.call_args_list,
Evan Hernandez655e8042019-06-13 12:50:44 -0600446 [mock.call(mock.ANY, mock.ANY, self.builder, self.image_cache_dir,
447 mock.ANY)])
Evan Hernandezdc3f0bb2019-06-06 12:46:52 -0600448 self.assertEqual(
449 self.mock_validate_moblab_vm_tests.call_args_list,
450 [mock.call(mock.ANY)])
451
452 def testImageMissingBuilder(self):
453 """MoblabVmTest dies when builder path not found in lsb-release."""
454 request = self._Input()
455 response = self._Output()
456
Mike Frysingere652ba12019-09-08 00:57:43 -0400457 self.PatchObject(key_value_store, 'LoadFile', return_value={})
Evan Hernandezdc3f0bb2019-06-06 12:46:52 -0600458
459 with self.assertRaises(cros_build_lib.DieSystemExit):
Alex Klein231d2da2019-07-22 16:44:45 -0600460 test_controller.MoblabVmTest(request, response, self.api_config)