blob: 0e14a02f65c18d734c2b8ea8f37c68397e1737db [file] [log] [blame]
Alex Klein2966e302019-01-17 13:29:38 -07001# Copyright 2019 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
5"""Image service tests."""
6
Alex Klein2966e302019-01-17 13:29:38 -07007import os
8
Alex Klein231d2da2019-07-22 16:44:45 -06009from chromite.api import api_config
Alex Klein8cb365a2019-05-15 16:24:53 -060010from chromite.api import controller
11from chromite.api.controller import image as image_controller
Alex Klein7107bdd2019-03-14 17:14:31 -060012from chromite.api.gen.chromite.api import image_pb2
David Burger13e06be2019-05-13 20:33:16 -060013from chromite.api.gen.chromiumos import common_pb2
Jack Neus761e1842020-12-01 18:20:11 +000014from chromite.api.gen.chromite.api import sysroot_pb2
Alex Klein56355682019-02-07 10:36:54 -070015from chromite.lib import constants
Alex Klein4f0eb432019-05-02 13:56:04 -060016from chromite.lib import cros_build_lib
Alex Klein2966e302019-01-17 13:29:38 -070017from chromite.lib import cros_test_lib
Michael Mortensenc83c9952019-08-05 12:15:12 -060018from chromite.lib import image_lib
Alex Klein2966e302019-01-17 13:29:38 -070019from chromite.lib import osutils
Jack Neus761e1842020-12-01 18:20:11 +000020from chromite.scripts import pushimage
Alex Kleinb7cdbe62019-02-22 11:41:32 -070021from chromite.service import image as image_service
Mike Frysinger40ffb532021-02-12 07:36:08 -050022from chromite.third_party import mock
Alex Klein2966e302019-01-17 13:29:38 -070023
24
Alex Klein231d2da2019-07-22 16:44:45 -060025class CreateTest(cros_test_lib.MockTempDirTestCase, api_config.ApiConfigMixin):
Alex Klein56355682019-02-07 10:36:54 -070026 """Create image tests."""
27
Alex Klein231d2da2019-07-22 16:44:45 -060028 def setUp(self):
29 self.response = image_pb2.CreateImageResult()
30
Jack Neus761e1842020-12-01 18:20:11 +000031 def _GetRequest(self,
32 board=None,
33 types=None,
34 version=None,
35 builder_path=None,
Alex Klein21b95022019-05-09 14:14:46 -060036 disable_rootfs_verification=False):
37 """Helper to build a request instance."""
38 return image_pb2.CreateImageRequest(
39 build_target={'name': board},
40 image_types=types,
41 disable_rootfs_verification=disable_rootfs_verification,
42 version=version,
43 builder_path=builder_path,
44 )
45
Alex Klein231d2da2019-07-22 16:44:45 -060046 def testValidateOnly(self):
47 """Sanity check that a validate only call does not execute any logic."""
48 patch = self.PatchObject(image_service, 'Build')
Alex Klein21b95022019-05-09 14:14:46 -060049
Alex Klein231d2da2019-07-22 16:44:45 -060050 request = self._GetRequest(board='board')
51 image_controller.Create(request, self.response, self.validate_only_config)
52 patch.assert_not_called()
53
Michael Mortensen10146cf2019-11-19 19:59:22 -070054 def testMockCall(self):
55 """Test that mock call does not execute any logic, returns mocked value."""
56 patch = self.PatchObject(image_service, 'Build')
57
58 request = self._GetRequest(board='board')
59 image_controller.Create(request, self.response, self.mock_call_config)
60 patch.assert_not_called()
61 self.assertEqual(self.response.success, True)
62
Michael Mortensen85d38402019-12-12 09:50:29 -070063 def testMockError(self):
64 """Test that mock call does not execute any logic, returns error."""
65 patch = self.PatchObject(image_service, 'Build')
66
67 request = self._GetRequest(board='board')
68 rc = image_controller.Create(request, self.response, self.mock_error_config)
69 patch.assert_not_called()
70 self.assertEqual(controller.RETURN_CODE_COMPLETED_UNSUCCESSFULLY, rc)
71
Alex Klein231d2da2019-07-22 16:44:45 -060072 def testNoBoard(self):
73 """Test no board given fails."""
74 request = self._GetRequest()
Alex Klein56355682019-02-07 10:36:54 -070075
76 # No board should cause it to fail.
Alex Klein4f0eb432019-05-02 13:56:04 -060077 with self.assertRaises(cros_build_lib.DieSystemExit):
Alex Klein231d2da2019-07-22 16:44:45 -060078 image_controller.Create(request, self.response, self.api_config)
Alex Klein56355682019-02-07 10:36:54 -070079
Alex Klein21b95022019-05-09 14:14:46 -060080 def testNoTypeSpecified(self):
81 """Test the image type default."""
82 request = self._GetRequest(board='board')
Alex Klein21b95022019-05-09 14:14:46 -060083
Alex Klein1bcd9882019-03-19 13:25:24 -060084 # Failed result to avoid the success handling logic.
85 result = image_service.BuildResult(1, [])
86 build_patch = self.PatchObject(image_service, 'Build', return_value=result)
Alex Klein56355682019-02-07 10:36:54 -070087
Alex Klein231d2da2019-07-22 16:44:45 -060088 image_controller.Create(request, self.response, self.api_config)
Jack Neus761e1842020-12-01 18:20:11 +000089 build_patch.assert_called_with(
90 images=[constants.IMAGE_TYPE_BASE], board='board', config=mock.ANY)
Alex Klein56355682019-02-07 10:36:54 -070091
Alex Klein21b95022019-05-09 14:14:46 -060092 def testSingleTypeSpecified(self):
93 """Test it's properly using a specified type."""
George Engelbrechtc55d6312021-05-05 12:11:13 -060094 request = self._GetRequest(board='board', types=[common_pb2.IMAGE_TYPE_DEV])
Alex Klein21b95022019-05-09 14:14:46 -060095
96 # Failed result to avoid the success handling logic.
97 result = image_service.BuildResult(1, [])
98 build_patch = self.PatchObject(image_service, 'Build', return_value=result)
99
Alex Klein231d2da2019-07-22 16:44:45 -0600100 image_controller.Create(request, self.response, self.api_config)
Jack Neus761e1842020-12-01 18:20:11 +0000101 build_patch.assert_called_with(
102 images=[constants.IMAGE_TYPE_DEV], board='board', config=mock.ANY)
Alex Klein56355682019-02-07 10:36:54 -0700103
Alex Klein21b95022019-05-09 14:14:46 -0600104 def testMultipleAndImpliedTypes(self):
105 """Test multiple types and implied type handling."""
106 # The TEST_VM type should force it to build the test image.
George Engelbrechtc55d6312021-05-05 12:11:13 -0600107 types = [common_pb2.IMAGE_TYPE_BASE, common_pb2.IMAGE_TYPE_TEST_VM]
Alex Klein21b95022019-05-09 14:14:46 -0600108 expected_images = [constants.IMAGE_TYPE_BASE, constants.IMAGE_TYPE_TEST]
109
110 request = self._GetRequest(board='board', types=types)
Alex Klein21b95022019-05-09 14:14:46 -0600111
112 # Failed result to avoid the success handling logic.
113 result = image_service.BuildResult(1, [])
114 build_patch = self.PatchObject(image_service, 'Build', return_value=result)
115
Alex Klein231d2da2019-07-22 16:44:45 -0600116 image_controller.Create(request, self.response, self.api_config)
Jack Neus761e1842020-12-01 18:20:11 +0000117 build_patch.assert_called_with(
118 images=expected_images, board='board', config=mock.ANY)
Alex Klein56355682019-02-07 10:36:54 -0700119
George Engelbrecht9f4f8322021-03-08 12:04:17 -0700120 def testRecoveryImpliedTypes(self):
121 """Test implied type handling of recovery images."""
122 # The TEST_VM type should force it to build the test image.
123 types = [common_pb2.IMAGE_TYPE_RECOVERY]
124
125 request = self._GetRequest(board='board', types=types)
126
127 # Failed result to avoid the success handling logic.
128 result = image_service.BuildResult(1, [])
129 build_patch = self.PatchObject(image_service, 'Build', return_value=result)
130
131 image_controller.Create(request, self.response, self.api_config)
132 build_patch.assert_called_with(
133 images=[constants.IMAGE_TYPE_BASE], board='board', config=mock.ANY)
134
Alex Klein1bcd9882019-03-19 13:25:24 -0600135 def testFailedPackageHandling(self):
136 """Test failed packages are populated correctly."""
137 result = image_service.BuildResult(1, ['foo/bar', 'cat/pkg'])
138 expected_packages = [('foo', 'bar'), ('cat', 'pkg')]
139 self.PatchObject(image_service, 'Build', return_value=result)
140
Alex Klein231d2da2019-07-22 16:44:45 -0600141 input_proto = self._GetRequest(board='board')
Alex Klein1bcd9882019-03-19 13:25:24 -0600142
Alex Klein231d2da2019-07-22 16:44:45 -0600143 rc = image_controller.Create(input_proto, self.response, self.api_config)
144
Alex Klein8cb365a2019-05-15 16:24:53 -0600145 self.assertEqual(controller.RETURN_CODE_UNSUCCESSFUL_RESPONSE_AVAILABLE, rc)
Alex Klein231d2da2019-07-22 16:44:45 -0600146 for package in self.response.failed_packages:
Alex Klein1bcd9882019-03-19 13:25:24 -0600147 self.assertIn((package.category, package.package_name), expected_packages)
148
Alex Klein2557b4f2019-07-11 14:34:00 -0600149 def testNoPackagesFailureHandling(self):
150 """Test failed packages are populated correctly."""
151 result = image_service.BuildResult(1, [])
152 self.PatchObject(image_service, 'Build', return_value=result)
Alex Kleinb7cdbe62019-02-22 11:41:32 -0700153
Alex Klein2557b4f2019-07-11 14:34:00 -0600154 input_proto = image_pb2.CreateImageRequest()
155 input_proto.build_target.name = 'board'
Alex Klein2557b4f2019-07-11 14:34:00 -0600156
Alex Klein231d2da2019-07-22 16:44:45 -0600157 rc = image_controller.Create(input_proto, self.response, self.api_config)
Alex Klein2557b4f2019-07-11 14:34:00 -0600158 self.assertTrue(rc)
159 self.assertNotEqual(controller.RETURN_CODE_UNSUCCESSFUL_RESPONSE_AVAILABLE,
160 rc)
Alex Klein231d2da2019-07-22 16:44:45 -0600161 self.assertFalse(self.response.failed_packages)
Alex Klein2557b4f2019-07-11 14:34:00 -0600162
163
Alex Klein231d2da2019-07-22 16:44:45 -0600164class ImageSignerTestTest(cros_test_lib.MockTempDirTestCase,
165 api_config.ApiConfigMixin):
Michael Mortensenc83c9952019-08-05 12:15:12 -0600166 """Image signer test tests."""
167
168 def setUp(self):
169 self.image_path = os.path.join(self.tempdir, 'image.bin')
Michael Mortensenc83c9952019-08-05 12:15:12 -0600170 self.result_directory = os.path.join(self.tempdir, 'results')
171
172 osutils.SafeMakedirs(self.result_directory)
173 osutils.Touch(self.image_path)
174
Alex Klein231d2da2019-07-22 16:44:45 -0600175 def testValidateOnly(self):
176 """Sanity check that validate-only calls don't execute any logic."""
177 patch = self.PatchObject(image_lib, 'SecurityTest', return_value=True)
178 input_proto = image_pb2.TestImageRequest()
179 input_proto.image.path = self.image_path
180 output_proto = image_pb2.TestImageResult()
181
182 image_controller.SignerTest(input_proto, output_proto,
183 self.validate_only_config)
184
185 patch.assert_not_called()
186
Michael Mortensen10146cf2019-11-19 19:59:22 -0700187 def testMockCall(self):
188 """Test that mock call does not execute any logic, returns mocked value."""
189 patch = self.PatchObject(image_lib, 'SecurityTest', return_value=True)
190 input_proto = image_pb2.TestImageRequest()
191 input_proto.image.path = self.image_path
192 output_proto = image_pb2.TestImageResult()
193
194 image_controller.SignerTest(input_proto, output_proto,
195 self.mock_call_config)
196
197 patch.assert_not_called()
198 self.assertEqual(output_proto.success, True)
199
Michael Mortensen85d38402019-12-12 09:50:29 -0700200 def testMockError(self):
201 """Test that mock call does not execute any logic, returns error."""
202 patch = self.PatchObject(image_lib, 'SecurityTest', return_value=True)
203 input_proto = image_pb2.TestImageRequest()
204 input_proto.image.path = self.image_path
205 output_proto = image_pb2.TestImageResult()
206
207 rc = image_controller.SignerTest(input_proto, output_proto,
208 self.mock_error_config)
209
210 patch.assert_not_called()
211 self.assertEqual(controller.RETURN_CODE_COMPLETED_UNSUCCESSFULLY, rc)
212
Alex Klein231d2da2019-07-22 16:44:45 -0600213 def testSignerTestNoImage(self):
214 """Test function argument validation."""
Michael Mortensenc83c9952019-08-05 12:15:12 -0600215 input_proto = image_pb2.TestImageRequest()
216 output_proto = image_pb2.TestImageResult()
217
218 # Nothing provided.
219 with self.assertRaises(cros_build_lib.DieSystemExit):
Alex Klein231d2da2019-07-22 16:44:45 -0600220 image_controller.SignerTest(input_proto, output_proto, self.api_config)
Michael Mortensenc83c9952019-08-05 12:15:12 -0600221
Alex Klein231d2da2019-07-22 16:44:45 -0600222 def testSignerTestSuccess(self):
223 """Test successful call handling."""
224 self.PatchObject(image_lib, 'SecurityTest', return_value=True)
225 input_proto = image_pb2.TestImageRequest()
Michael Mortensenc83c9952019-08-05 12:15:12 -0600226 input_proto.image.path = self.image_path
Alex Klein231d2da2019-07-22 16:44:45 -0600227 output_proto = image_pb2.TestImageResult()
Michael Mortensenc83c9952019-08-05 12:15:12 -0600228
Alex Klein231d2da2019-07-22 16:44:45 -0600229 image_controller.SignerTest(input_proto, output_proto, self.api_config)
230
231 def testSignerTestFailure(self):
Michael Mortensenc83c9952019-08-05 12:15:12 -0600232 """Test function output tests."""
233 input_proto = image_pb2.TestImageRequest()
234 input_proto.image.path = self.image_path
Michael Mortensenc83c9952019-08-05 12:15:12 -0600235 output_proto = image_pb2.TestImageResult()
236
Michael Mortensenc83c9952019-08-05 12:15:12 -0600237 self.PatchObject(image_lib, 'SecurityTest', return_value=False)
Alex Klein231d2da2019-07-22 16:44:45 -0600238 image_controller.SignerTest(input_proto, output_proto, self.api_config)
Michael Mortensenc83c9952019-08-05 12:15:12 -0600239 self.assertFalse(output_proto.success)
240
Michael Mortensenc83c9952019-08-05 12:15:12 -0600241
Alex Klein231d2da2019-07-22 16:44:45 -0600242class ImageTestTest(cros_test_lib.MockTempDirTestCase,
243 api_config.ApiConfigMixin):
Alex Klein2557b4f2019-07-11 14:34:00 -0600244 """Image test tests."""
Alex Klein2966e302019-01-17 13:29:38 -0700245
246 def setUp(self):
247 self.image_path = os.path.join(self.tempdir, 'image.bin')
248 self.board = 'board'
249 self.result_directory = os.path.join(self.tempdir, 'results')
250
251 osutils.SafeMakedirs(self.result_directory)
252 osutils.Touch(self.image_path)
253
Alex Klein231d2da2019-07-22 16:44:45 -0600254 def testValidateOnly(self):
255 """Sanity check that a validate only call does not execute any logic."""
256 patch = self.PatchObject(image_service, 'Test')
257
258 input_proto = image_pb2.TestImageRequest()
259 input_proto.image.path = self.image_path
260 input_proto.build_target.name = self.board
261 input_proto.result.directory = self.result_directory
262 output_proto = image_pb2.TestImageResult()
263
264 image_controller.Test(input_proto, output_proto, self.validate_only_config)
265 patch.assert_not_called()
266
Michael Mortensen10146cf2019-11-19 19:59:22 -0700267 def testMockCall(self):
268 """Test that mock call does not execute any logic, returns mocked value."""
269 patch = self.PatchObject(image_service, 'Test')
270
271 input_proto = image_pb2.TestImageRequest()
272 input_proto.image.path = self.image_path
273 input_proto.build_target.name = self.board
274 input_proto.result.directory = self.result_directory
275 output_proto = image_pb2.TestImageResult()
276
277 image_controller.Test(input_proto, output_proto, self.mock_call_config)
278 patch.assert_not_called()
279 self.assertEqual(output_proto.success, True)
280
Michael Mortensen85d38402019-12-12 09:50:29 -0700281 def testMockError(self):
282 """Test that mock call does not execute any logic, returns error."""
283 patch = self.PatchObject(image_service, 'Test')
284
285 input_proto = image_pb2.TestImageRequest()
286 input_proto.image.path = self.image_path
287 input_proto.build_target.name = self.board
288 input_proto.result.directory = self.result_directory
289 output_proto = image_pb2.TestImageResult()
290
291 rc = image_controller.Test(input_proto, output_proto,
292 self.mock_error_config)
293 patch.assert_not_called()
294 self.assertEqual(controller.RETURN_CODE_COMPLETED_UNSUCCESSFULLY, rc)
295
Alex Klein2966e302019-01-17 13:29:38 -0700296 def testTestArgumentValidation(self):
297 """Test function argument validation tests."""
Alex Kleinb7cdbe62019-02-22 11:41:32 -0700298 self.PatchObject(image_service, 'Test', return_value=True)
Alex Klein2966e302019-01-17 13:29:38 -0700299 input_proto = image_pb2.TestImageRequest()
300 output_proto = image_pb2.TestImageResult()
301
302 # Nothing provided.
Alex Klein4f0eb432019-05-02 13:56:04 -0600303 with self.assertRaises(cros_build_lib.DieSystemExit):
Alex Klein231d2da2019-07-22 16:44:45 -0600304 image_controller.Test(input_proto, output_proto, self.api_config)
Alex Klein2966e302019-01-17 13:29:38 -0700305
306 # Just one argument.
307 input_proto.build_target.name = self.board
Alex Klein4f0eb432019-05-02 13:56:04 -0600308 with self.assertRaises(cros_build_lib.DieSystemExit):
Alex Klein231d2da2019-07-22 16:44:45 -0600309 image_controller.Test(input_proto, output_proto, self.api_config)
Alex Klein2966e302019-01-17 13:29:38 -0700310
311 # Two arguments provided.
312 input_proto.result.directory = self.result_directory
Alex Klein4f0eb432019-05-02 13:56:04 -0600313 with self.assertRaises(cros_build_lib.DieSystemExit):
Alex Klein231d2da2019-07-22 16:44:45 -0600314 image_controller.Test(input_proto, output_proto, self.api_config)
Alex Klein2966e302019-01-17 13:29:38 -0700315
316 # Invalid image path.
317 input_proto.image.path = '/invalid/image/path'
Alex Klein4f0eb432019-05-02 13:56:04 -0600318 with self.assertRaises(cros_build_lib.DieSystemExit):
Alex Klein231d2da2019-07-22 16:44:45 -0600319 image_controller.Test(input_proto, output_proto, self.api_config)
Alex Klein2966e302019-01-17 13:29:38 -0700320
321 # All valid arguments.
322 input_proto.image.path = self.image_path
Alex Klein231d2da2019-07-22 16:44:45 -0600323 image_controller.Test(input_proto, output_proto, self.api_config)
Alex Klein2966e302019-01-17 13:29:38 -0700324
325 def testTestOutputHandling(self):
326 """Test function output tests."""
327 input_proto = image_pb2.TestImageRequest()
328 input_proto.image.path = self.image_path
329 input_proto.build_target.name = self.board
330 input_proto.result.directory = self.result_directory
331 output_proto = image_pb2.TestImageResult()
332
Alex Kleinb7cdbe62019-02-22 11:41:32 -0700333 self.PatchObject(image_service, 'Test', return_value=True)
Alex Klein231d2da2019-07-22 16:44:45 -0600334 image_controller.Test(input_proto, output_proto, self.api_config)
Alex Klein2966e302019-01-17 13:29:38 -0700335 self.assertTrue(output_proto.success)
336
Alex Kleinb7cdbe62019-02-22 11:41:32 -0700337 self.PatchObject(image_service, 'Test', return_value=False)
Alex Klein231d2da2019-07-22 16:44:45 -0600338 image_controller.Test(input_proto, output_proto, self.api_config)
Alex Klein2966e302019-01-17 13:29:38 -0700339 self.assertFalse(output_proto.success)
Jack Neus761e1842020-12-01 18:20:11 +0000340
341
342class PushImageTest(cros_test_lib.MockTestCase, api_config.ApiConfigMixin):
343 """Push image test."""
344
345 def setUp(self):
346 self.response = image_pb2.PushImageResponse()
347
348 def _GetRequest(
349 self,
350 gs_image_dir='gs://chromeos-image-archive/atlas-release/R89-13604.0.0',
351 build_target_name='atlas',
352 profile='foo',
353 sign_types=None,
354 dryrun=True):
355 return image_pb2.PushImageRequest(
356 gs_image_dir=gs_image_dir,
357 sysroot=sysroot_pb2.Sysroot(
358 build_target=common_pb2.BuildTarget(name=build_target_name)),
359 profile=common_pb2.Profile(name=profile),
360 sign_types=sign_types,
361 dryrun=dryrun)
362
363 def testValidateOnly(self):
364 """Check that a validate only call does not execute any logic."""
365 patch = self.PatchObject(pushimage, 'PushImage')
366
367 req = self._GetRequest(sign_types=[
368 common_pb2.IMAGE_TYPE_RECOVERY, common_pb2.IMAGE_TYPE_FACTORY,
369 common_pb2.IMAGE_TYPE_FIRMWARE, common_pb2.IMAGE_TYPE_ACCESSORY_USBPD,
370 common_pb2.IMAGE_TYPE_ACCESSORY_RWSIG, common_pb2.IMAGE_TYPE_BASE,
371 common_pb2.IMAGE_TYPE_GSC_FIRMWARE
372 ])
373 res = image_controller.PushImage(req, self.response,
374 self.validate_only_config)
375 patch.assert_not_called()
376 self.assertEqual(res, controller.RETURN_CODE_VALID_INPUT)
377
378 def testValidateOnlyInvalid(self):
379 """Check that validate call rejects invalid sign types."""
380 patch = self.PatchObject(pushimage, 'PushImage')
381
382 # Pass unsupported image type.
383 req = self._GetRequest(sign_types=[common_pb2.IMAGE_TYPE_DLC])
384 res = image_controller.PushImage(req, self.response,
385 self.validate_only_config)
386 patch.assert_not_called()
387 self.assertEqual(res, controller.RETURN_CODE_INVALID_INPUT)
388
389 def testMockCall(self):
390 """Test that mock call does not execute any logic, returns mocked value."""
391 patch = self.PatchObject(pushimage, 'PushImage')
392
393 rc = image_controller.PushImage(self._GetRequest(), self.response,
394 self.mock_call_config)
395 patch.assert_not_called()
396 self.assertEqual(controller.RETURN_CODE_SUCCESS, rc)
397
398 def testMockError(self):
399 """Test that mock call does not execute any logic, returns error."""
400 patch = self.PatchObject(pushimage, 'PushImage')
401
402 rc = image_controller.PushImage(self._GetRequest(), self.response,
403 self.mock_error_config)
404 patch.assert_not_called()
405 self.assertEqual(controller.RETURN_CODE_COMPLETED_UNSUCCESSFULLY, rc)
406
407 def testNoBuildTarget(self):
408 """Test no build target given fails."""
409 request = self._GetRequest(build_target_name='')
410
411 # No build target should cause it to fail.
412 with self.assertRaises(cros_build_lib.DieSystemExit):
413 image_controller.PushImage(request, self.response, self.api_config)
414
415 def testNoGsImageDir(self):
416 """Test no image dir given fails."""
417 request = self._GetRequest(gs_image_dir='')
418
419 # No image dir should cause it to fail.
420 with self.assertRaises(cros_build_lib.DieSystemExit):
421 image_controller.PushImage(request, self.response, self.api_config)
422
423 def testCallCorrect(self):
424 """Check that a call is called with the correct parameters."""
425 patch = self.PatchObject(pushimage, 'PushImage')
426
427 request = self._GetRequest(
428 dryrun=False, profile='', sign_types=[common_pb2.IMAGE_TYPE_RECOVERY])
Jack Neus485a9d22020-12-21 03:15:15 +0000429 request.dest_bucket = 'gs://foo'
Jack Neus761e1842020-12-01 18:20:11 +0000430 image_controller.PushImage(request, self.response, self.api_config)
431 patch.assert_called_with(
432 request.gs_image_dir,
433 request.sysroot.build_target.name,
434 dry_run=request.dryrun,
Jack Neus485a9d22020-12-21 03:15:15 +0000435 sign_types=['recovery'],
436 dest_bucket=request.dest_bucket)
Jack Neus761e1842020-12-01 18:20:11 +0000437
438 def testCallSucceeds(self):
439 """Check that a (dry run) call is made successfully."""
440 request = self._GetRequest(sign_types=[common_pb2.IMAGE_TYPE_RECOVERY])
441 res = image_controller.PushImage(request, self.response, self.api_config)
442 self.assertEqual(res, controller.RETURN_CODE_SUCCESS)
443
444 def testCallFailsWithBadImageDir(self):
445 """Check that a (dry run) call fails when given a bad gs_image_dir."""
446 request = self._GetRequest(gs_image_dir='foo')
447 res = image_controller.PushImage(request, self.response, self.api_config)
448 self.assertEqual(res, controller.RETURN_CODE_COMPLETED_UNSUCCESSFULLY)