blob: fbe01dff7f34433637687f017ef31ae46b55de24 [file] [log] [blame]
Alex Klein2966e302019-01-17 13:29:38 -07001# -*- 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"""Image service tests."""
7
8from __future__ import print_function
9
10import os
11
Alex Klein231d2da2019-07-22 16:44:45 -060012from chromite.api import api_config
Alex Klein8cb365a2019-05-15 16:24:53 -060013from chromite.api import controller
14from chromite.api.controller import image as image_controller
Alex Klein7107bdd2019-03-14 17:14:31 -060015from chromite.api.gen.chromite.api import image_pb2
David Burger13e06be2019-05-13 20:33:16 -060016from chromite.api.gen.chromiumos import common_pb2
Jack Neus761e1842020-12-01 18:20:11 +000017from chromite.api.gen.chromite.api import sysroot_pb2
Alex Klein56355682019-02-07 10:36:54 -070018from chromite.lib import constants
Alex Klein4f0eb432019-05-02 13:56:04 -060019from chromite.lib import cros_build_lib
Alex Klein2966e302019-01-17 13:29:38 -070020from chromite.lib import cros_test_lib
Michael Mortensenc83c9952019-08-05 12:15:12 -060021from chromite.lib import image_lib
Alex Klein2966e302019-01-17 13:29:38 -070022from chromite.lib import osutils
Jack Neus761e1842020-12-01 18:20:11 +000023from chromite.scripts import pushimage
Alex Kleinb7cdbe62019-02-22 11:41:32 -070024from chromite.service import image as image_service
Mike Frysinger40ffb532021-02-12 07:36:08 -050025from chromite.third_party import mock
Alex Klein2966e302019-01-17 13:29:38 -070026
27
Alex Klein231d2da2019-07-22 16:44:45 -060028class CreateTest(cros_test_lib.MockTempDirTestCase, api_config.ApiConfigMixin):
Alex Klein56355682019-02-07 10:36:54 -070029 """Create image tests."""
30
Alex Klein231d2da2019-07-22 16:44:45 -060031 def setUp(self):
32 self.response = image_pb2.CreateImageResult()
33
Jack Neus761e1842020-12-01 18:20:11 +000034 def _GetRequest(self,
35 board=None,
36 types=None,
37 version=None,
38 builder_path=None,
Alex Klein21b95022019-05-09 14:14:46 -060039 disable_rootfs_verification=False):
40 """Helper to build a request instance."""
41 return image_pb2.CreateImageRequest(
42 build_target={'name': board},
43 image_types=types,
44 disable_rootfs_verification=disable_rootfs_verification,
45 version=version,
46 builder_path=builder_path,
47 )
48
Alex Klein231d2da2019-07-22 16:44:45 -060049 def testValidateOnly(self):
50 """Sanity check that a validate only call does not execute any logic."""
51 patch = self.PatchObject(image_service, 'Build')
Alex Klein21b95022019-05-09 14:14:46 -060052
Alex Klein231d2da2019-07-22 16:44:45 -060053 request = self._GetRequest(board='board')
54 image_controller.Create(request, self.response, self.validate_only_config)
55 patch.assert_not_called()
56
Michael Mortensen10146cf2019-11-19 19:59:22 -070057 def testMockCall(self):
58 """Test that mock call does not execute any logic, returns mocked value."""
59 patch = self.PatchObject(image_service, 'Build')
60
61 request = self._GetRequest(board='board')
62 image_controller.Create(request, self.response, self.mock_call_config)
63 patch.assert_not_called()
64 self.assertEqual(self.response.success, True)
65
Michael Mortensen85d38402019-12-12 09:50:29 -070066 def testMockError(self):
67 """Test that mock call does not execute any logic, returns error."""
68 patch = self.PatchObject(image_service, 'Build')
69
70 request = self._GetRequest(board='board')
71 rc = image_controller.Create(request, self.response, self.mock_error_config)
72 patch.assert_not_called()
73 self.assertEqual(controller.RETURN_CODE_COMPLETED_UNSUCCESSFULLY, rc)
74
Alex Klein231d2da2019-07-22 16:44:45 -060075 def testNoBoard(self):
76 """Test no board given fails."""
77 request = self._GetRequest()
Alex Klein56355682019-02-07 10:36:54 -070078
79 # No board should cause it to fail.
Alex Klein4f0eb432019-05-02 13:56:04 -060080 with self.assertRaises(cros_build_lib.DieSystemExit):
Alex Klein231d2da2019-07-22 16:44:45 -060081 image_controller.Create(request, self.response, self.api_config)
Alex Klein56355682019-02-07 10:36:54 -070082
Alex Klein21b95022019-05-09 14:14:46 -060083 def testNoTypeSpecified(self):
84 """Test the image type default."""
85 request = self._GetRequest(board='board')
Alex Klein21b95022019-05-09 14:14:46 -060086
Alex Klein1bcd9882019-03-19 13:25:24 -060087 # Failed result to avoid the success handling logic.
88 result = image_service.BuildResult(1, [])
89 build_patch = self.PatchObject(image_service, 'Build', return_value=result)
Alex Klein56355682019-02-07 10:36:54 -070090
Alex Klein231d2da2019-07-22 16:44:45 -060091 image_controller.Create(request, self.response, self.api_config)
Jack Neus761e1842020-12-01 18:20:11 +000092 build_patch.assert_called_with(
93 images=[constants.IMAGE_TYPE_BASE], board='board', config=mock.ANY)
Alex Klein56355682019-02-07 10:36:54 -070094
Alex Klein21b95022019-05-09 14:14:46 -060095 def testSingleTypeSpecified(self):
96 """Test it's properly using a specified type."""
George Engelbrechtc55d6312021-05-05 12:11:13 -060097 request = self._GetRequest(board='board', types=[common_pb2.IMAGE_TYPE_DEV])
Alex Klein21b95022019-05-09 14:14:46 -060098
99 # Failed result to avoid the success handling logic.
100 result = image_service.BuildResult(1, [])
101 build_patch = self.PatchObject(image_service, 'Build', return_value=result)
102
Alex Klein231d2da2019-07-22 16:44:45 -0600103 image_controller.Create(request, self.response, self.api_config)
Jack Neus761e1842020-12-01 18:20:11 +0000104 build_patch.assert_called_with(
105 images=[constants.IMAGE_TYPE_DEV], board='board', config=mock.ANY)
Alex Klein56355682019-02-07 10:36:54 -0700106
Alex Klein21b95022019-05-09 14:14:46 -0600107 def testMultipleAndImpliedTypes(self):
108 """Test multiple types and implied type handling."""
109 # The TEST_VM type should force it to build the test image.
George Engelbrechtc55d6312021-05-05 12:11:13 -0600110 types = [common_pb2.IMAGE_TYPE_BASE, common_pb2.IMAGE_TYPE_TEST_VM]
Alex Klein21b95022019-05-09 14:14:46 -0600111 expected_images = [constants.IMAGE_TYPE_BASE, constants.IMAGE_TYPE_TEST]
112
113 request = self._GetRequest(board='board', types=types)
Alex Klein21b95022019-05-09 14:14:46 -0600114
115 # Failed result to avoid the success handling logic.
116 result = image_service.BuildResult(1, [])
117 build_patch = self.PatchObject(image_service, 'Build', return_value=result)
118
Alex Klein231d2da2019-07-22 16:44:45 -0600119 image_controller.Create(request, self.response, self.api_config)
Jack Neus761e1842020-12-01 18:20:11 +0000120 build_patch.assert_called_with(
121 images=expected_images, board='board', config=mock.ANY)
Alex Klein56355682019-02-07 10:36:54 -0700122
George Engelbrecht9f4f8322021-03-08 12:04:17 -0700123 def testRecoveryImpliedTypes(self):
124 """Test implied type handling of recovery images."""
125 # The TEST_VM type should force it to build the test image.
126 types = [common_pb2.IMAGE_TYPE_RECOVERY]
127
128 request = self._GetRequest(board='board', types=types)
129
130 # Failed result to avoid the success handling logic.
131 result = image_service.BuildResult(1, [])
132 build_patch = self.PatchObject(image_service, 'Build', return_value=result)
133
134 image_controller.Create(request, self.response, self.api_config)
135 build_patch.assert_called_with(
136 images=[constants.IMAGE_TYPE_BASE], board='board', config=mock.ANY)
137
Alex Klein1bcd9882019-03-19 13:25:24 -0600138 def testFailedPackageHandling(self):
139 """Test failed packages are populated correctly."""
140 result = image_service.BuildResult(1, ['foo/bar', 'cat/pkg'])
141 expected_packages = [('foo', 'bar'), ('cat', 'pkg')]
142 self.PatchObject(image_service, 'Build', return_value=result)
143
Alex Klein231d2da2019-07-22 16:44:45 -0600144 input_proto = self._GetRequest(board='board')
Alex Klein1bcd9882019-03-19 13:25:24 -0600145
Alex Klein231d2da2019-07-22 16:44:45 -0600146 rc = image_controller.Create(input_proto, self.response, self.api_config)
147
Alex Klein8cb365a2019-05-15 16:24:53 -0600148 self.assertEqual(controller.RETURN_CODE_UNSUCCESSFUL_RESPONSE_AVAILABLE, rc)
Alex Klein231d2da2019-07-22 16:44:45 -0600149 for package in self.response.failed_packages:
Alex Klein1bcd9882019-03-19 13:25:24 -0600150 self.assertIn((package.category, package.package_name), expected_packages)
151
Alex Klein2557b4f2019-07-11 14:34:00 -0600152 def testNoPackagesFailureHandling(self):
153 """Test failed packages are populated correctly."""
154 result = image_service.BuildResult(1, [])
155 self.PatchObject(image_service, 'Build', return_value=result)
Alex Kleinb7cdbe62019-02-22 11:41:32 -0700156
Alex Klein2557b4f2019-07-11 14:34:00 -0600157 input_proto = image_pb2.CreateImageRequest()
158 input_proto.build_target.name = 'board'
Alex Klein2557b4f2019-07-11 14:34:00 -0600159
Alex Klein231d2da2019-07-22 16:44:45 -0600160 rc = image_controller.Create(input_proto, self.response, self.api_config)
Alex Klein2557b4f2019-07-11 14:34:00 -0600161 self.assertTrue(rc)
162 self.assertNotEqual(controller.RETURN_CODE_UNSUCCESSFUL_RESPONSE_AVAILABLE,
163 rc)
Alex Klein231d2da2019-07-22 16:44:45 -0600164 self.assertFalse(self.response.failed_packages)
Alex Klein2557b4f2019-07-11 14:34:00 -0600165
166
Alex Klein231d2da2019-07-22 16:44:45 -0600167class ImageSignerTestTest(cros_test_lib.MockTempDirTestCase,
168 api_config.ApiConfigMixin):
Michael Mortensenc83c9952019-08-05 12:15:12 -0600169 """Image signer test tests."""
170
171 def setUp(self):
172 self.image_path = os.path.join(self.tempdir, 'image.bin')
Michael Mortensenc83c9952019-08-05 12:15:12 -0600173 self.result_directory = os.path.join(self.tempdir, 'results')
174
175 osutils.SafeMakedirs(self.result_directory)
176 osutils.Touch(self.image_path)
177
Alex Klein231d2da2019-07-22 16:44:45 -0600178 def testValidateOnly(self):
179 """Sanity check that validate-only calls don't execute any logic."""
180 patch = self.PatchObject(image_lib, 'SecurityTest', return_value=True)
181 input_proto = image_pb2.TestImageRequest()
182 input_proto.image.path = self.image_path
183 output_proto = image_pb2.TestImageResult()
184
185 image_controller.SignerTest(input_proto, output_proto,
186 self.validate_only_config)
187
188 patch.assert_not_called()
189
Michael Mortensen10146cf2019-11-19 19:59:22 -0700190 def testMockCall(self):
191 """Test that mock call does not execute any logic, returns mocked value."""
192 patch = self.PatchObject(image_lib, 'SecurityTest', return_value=True)
193 input_proto = image_pb2.TestImageRequest()
194 input_proto.image.path = self.image_path
195 output_proto = image_pb2.TestImageResult()
196
197 image_controller.SignerTest(input_proto, output_proto,
198 self.mock_call_config)
199
200 patch.assert_not_called()
201 self.assertEqual(output_proto.success, True)
202
Michael Mortensen85d38402019-12-12 09:50:29 -0700203 def testMockError(self):
204 """Test that mock call does not execute any logic, returns error."""
205 patch = self.PatchObject(image_lib, 'SecurityTest', return_value=True)
206 input_proto = image_pb2.TestImageRequest()
207 input_proto.image.path = self.image_path
208 output_proto = image_pb2.TestImageResult()
209
210 rc = image_controller.SignerTest(input_proto, output_proto,
211 self.mock_error_config)
212
213 patch.assert_not_called()
214 self.assertEqual(controller.RETURN_CODE_COMPLETED_UNSUCCESSFULLY, rc)
215
Alex Klein231d2da2019-07-22 16:44:45 -0600216 def testSignerTestNoImage(self):
217 """Test function argument validation."""
Michael Mortensenc83c9952019-08-05 12:15:12 -0600218 input_proto = image_pb2.TestImageRequest()
219 output_proto = image_pb2.TestImageResult()
220
221 # Nothing provided.
222 with self.assertRaises(cros_build_lib.DieSystemExit):
Alex Klein231d2da2019-07-22 16:44:45 -0600223 image_controller.SignerTest(input_proto, output_proto, self.api_config)
Michael Mortensenc83c9952019-08-05 12:15:12 -0600224
Alex Klein231d2da2019-07-22 16:44:45 -0600225 def testSignerTestSuccess(self):
226 """Test successful call handling."""
227 self.PatchObject(image_lib, 'SecurityTest', return_value=True)
228 input_proto = image_pb2.TestImageRequest()
Michael Mortensenc83c9952019-08-05 12:15:12 -0600229 input_proto.image.path = self.image_path
Alex Klein231d2da2019-07-22 16:44:45 -0600230 output_proto = image_pb2.TestImageResult()
Michael Mortensenc83c9952019-08-05 12:15:12 -0600231
Alex Klein231d2da2019-07-22 16:44:45 -0600232 image_controller.SignerTest(input_proto, output_proto, self.api_config)
233
234 def testSignerTestFailure(self):
Michael Mortensenc83c9952019-08-05 12:15:12 -0600235 """Test function output tests."""
236 input_proto = image_pb2.TestImageRequest()
237 input_proto.image.path = self.image_path
Michael Mortensenc83c9952019-08-05 12:15:12 -0600238 output_proto = image_pb2.TestImageResult()
239
Michael Mortensenc83c9952019-08-05 12:15:12 -0600240 self.PatchObject(image_lib, 'SecurityTest', return_value=False)
Alex Klein231d2da2019-07-22 16:44:45 -0600241 image_controller.SignerTest(input_proto, output_proto, self.api_config)
Michael Mortensenc83c9952019-08-05 12:15:12 -0600242 self.assertFalse(output_proto.success)
243
Michael Mortensenc83c9952019-08-05 12:15:12 -0600244
Alex Klein231d2da2019-07-22 16:44:45 -0600245class ImageTestTest(cros_test_lib.MockTempDirTestCase,
246 api_config.ApiConfigMixin):
Alex Klein2557b4f2019-07-11 14:34:00 -0600247 """Image test tests."""
Alex Klein2966e302019-01-17 13:29:38 -0700248
249 def setUp(self):
250 self.image_path = os.path.join(self.tempdir, 'image.bin')
251 self.board = 'board'
252 self.result_directory = os.path.join(self.tempdir, 'results')
253
254 osutils.SafeMakedirs(self.result_directory)
255 osutils.Touch(self.image_path)
256
Alex Klein231d2da2019-07-22 16:44:45 -0600257 def testValidateOnly(self):
258 """Sanity check that a validate only call does not execute any logic."""
259 patch = self.PatchObject(image_service, 'Test')
260
261 input_proto = image_pb2.TestImageRequest()
262 input_proto.image.path = self.image_path
263 input_proto.build_target.name = self.board
264 input_proto.result.directory = self.result_directory
265 output_proto = image_pb2.TestImageResult()
266
267 image_controller.Test(input_proto, output_proto, self.validate_only_config)
268 patch.assert_not_called()
269
Michael Mortensen10146cf2019-11-19 19:59:22 -0700270 def testMockCall(self):
271 """Test that mock call does not execute any logic, returns mocked value."""
272 patch = self.PatchObject(image_service, 'Test')
273
274 input_proto = image_pb2.TestImageRequest()
275 input_proto.image.path = self.image_path
276 input_proto.build_target.name = self.board
277 input_proto.result.directory = self.result_directory
278 output_proto = image_pb2.TestImageResult()
279
280 image_controller.Test(input_proto, output_proto, self.mock_call_config)
281 patch.assert_not_called()
282 self.assertEqual(output_proto.success, True)
283
Michael Mortensen85d38402019-12-12 09:50:29 -0700284 def testMockError(self):
285 """Test that mock call does not execute any logic, returns error."""
286 patch = self.PatchObject(image_service, 'Test')
287
288 input_proto = image_pb2.TestImageRequest()
289 input_proto.image.path = self.image_path
290 input_proto.build_target.name = self.board
291 input_proto.result.directory = self.result_directory
292 output_proto = image_pb2.TestImageResult()
293
294 rc = image_controller.Test(input_proto, output_proto,
295 self.mock_error_config)
296 patch.assert_not_called()
297 self.assertEqual(controller.RETURN_CODE_COMPLETED_UNSUCCESSFULLY, rc)
298
Alex Klein2966e302019-01-17 13:29:38 -0700299 def testTestArgumentValidation(self):
300 """Test function argument validation tests."""
Alex Kleinb7cdbe62019-02-22 11:41:32 -0700301 self.PatchObject(image_service, 'Test', return_value=True)
Alex Klein2966e302019-01-17 13:29:38 -0700302 input_proto = image_pb2.TestImageRequest()
303 output_proto = image_pb2.TestImageResult()
304
305 # Nothing provided.
Alex Klein4f0eb432019-05-02 13:56:04 -0600306 with self.assertRaises(cros_build_lib.DieSystemExit):
Alex Klein231d2da2019-07-22 16:44:45 -0600307 image_controller.Test(input_proto, output_proto, self.api_config)
Alex Klein2966e302019-01-17 13:29:38 -0700308
309 # Just one argument.
310 input_proto.build_target.name = self.board
Alex Klein4f0eb432019-05-02 13:56:04 -0600311 with self.assertRaises(cros_build_lib.DieSystemExit):
Alex Klein231d2da2019-07-22 16:44:45 -0600312 image_controller.Test(input_proto, output_proto, self.api_config)
Alex Klein2966e302019-01-17 13:29:38 -0700313
314 # Two arguments provided.
315 input_proto.result.directory = self.result_directory
Alex Klein4f0eb432019-05-02 13:56:04 -0600316 with self.assertRaises(cros_build_lib.DieSystemExit):
Alex Klein231d2da2019-07-22 16:44:45 -0600317 image_controller.Test(input_proto, output_proto, self.api_config)
Alex Klein2966e302019-01-17 13:29:38 -0700318
319 # Invalid image path.
320 input_proto.image.path = '/invalid/image/path'
Alex Klein4f0eb432019-05-02 13:56:04 -0600321 with self.assertRaises(cros_build_lib.DieSystemExit):
Alex Klein231d2da2019-07-22 16:44:45 -0600322 image_controller.Test(input_proto, output_proto, self.api_config)
Alex Klein2966e302019-01-17 13:29:38 -0700323
324 # All valid arguments.
325 input_proto.image.path = self.image_path
Alex Klein231d2da2019-07-22 16:44:45 -0600326 image_controller.Test(input_proto, output_proto, self.api_config)
Alex Klein2966e302019-01-17 13:29:38 -0700327
328 def testTestOutputHandling(self):
329 """Test function output tests."""
330 input_proto = image_pb2.TestImageRequest()
331 input_proto.image.path = self.image_path
332 input_proto.build_target.name = self.board
333 input_proto.result.directory = self.result_directory
334 output_proto = image_pb2.TestImageResult()
335
Alex Kleinb7cdbe62019-02-22 11:41:32 -0700336 self.PatchObject(image_service, 'Test', return_value=True)
Alex Klein231d2da2019-07-22 16:44:45 -0600337 image_controller.Test(input_proto, output_proto, self.api_config)
Alex Klein2966e302019-01-17 13:29:38 -0700338 self.assertTrue(output_proto.success)
339
Alex Kleinb7cdbe62019-02-22 11:41:32 -0700340 self.PatchObject(image_service, 'Test', return_value=False)
Alex Klein231d2da2019-07-22 16:44:45 -0600341 image_controller.Test(input_proto, output_proto, self.api_config)
Alex Klein2966e302019-01-17 13:29:38 -0700342 self.assertFalse(output_proto.success)
Jack Neus761e1842020-12-01 18:20:11 +0000343
344
345class PushImageTest(cros_test_lib.MockTestCase, api_config.ApiConfigMixin):
346 """Push image test."""
347
348 def setUp(self):
349 self.response = image_pb2.PushImageResponse()
350
351 def _GetRequest(
352 self,
353 gs_image_dir='gs://chromeos-image-archive/atlas-release/R89-13604.0.0',
354 build_target_name='atlas',
355 profile='foo',
356 sign_types=None,
357 dryrun=True):
358 return image_pb2.PushImageRequest(
359 gs_image_dir=gs_image_dir,
360 sysroot=sysroot_pb2.Sysroot(
361 build_target=common_pb2.BuildTarget(name=build_target_name)),
362 profile=common_pb2.Profile(name=profile),
363 sign_types=sign_types,
364 dryrun=dryrun)
365
366 def testValidateOnly(self):
367 """Check that a validate only call does not execute any logic."""
368 patch = self.PatchObject(pushimage, 'PushImage')
369
370 req = self._GetRequest(sign_types=[
371 common_pb2.IMAGE_TYPE_RECOVERY, common_pb2.IMAGE_TYPE_FACTORY,
372 common_pb2.IMAGE_TYPE_FIRMWARE, common_pb2.IMAGE_TYPE_ACCESSORY_USBPD,
373 common_pb2.IMAGE_TYPE_ACCESSORY_RWSIG, common_pb2.IMAGE_TYPE_BASE,
374 common_pb2.IMAGE_TYPE_GSC_FIRMWARE
375 ])
376 res = image_controller.PushImage(req, self.response,
377 self.validate_only_config)
378 patch.assert_not_called()
379 self.assertEqual(res, controller.RETURN_CODE_VALID_INPUT)
380
381 def testValidateOnlyInvalid(self):
382 """Check that validate call rejects invalid sign types."""
383 patch = self.PatchObject(pushimage, 'PushImage')
384
385 # Pass unsupported image type.
386 req = self._GetRequest(sign_types=[common_pb2.IMAGE_TYPE_DLC])
387 res = image_controller.PushImage(req, self.response,
388 self.validate_only_config)
389 patch.assert_not_called()
390 self.assertEqual(res, controller.RETURN_CODE_INVALID_INPUT)
391
392 def testMockCall(self):
393 """Test that mock call does not execute any logic, returns mocked value."""
394 patch = self.PatchObject(pushimage, 'PushImage')
395
396 rc = image_controller.PushImage(self._GetRequest(), self.response,
397 self.mock_call_config)
398 patch.assert_not_called()
399 self.assertEqual(controller.RETURN_CODE_SUCCESS, rc)
400
401 def testMockError(self):
402 """Test that mock call does not execute any logic, returns error."""
403 patch = self.PatchObject(pushimage, 'PushImage')
404
405 rc = image_controller.PushImage(self._GetRequest(), self.response,
406 self.mock_error_config)
407 patch.assert_not_called()
408 self.assertEqual(controller.RETURN_CODE_COMPLETED_UNSUCCESSFULLY, rc)
409
410 def testNoBuildTarget(self):
411 """Test no build target given fails."""
412 request = self._GetRequest(build_target_name='')
413
414 # No build target should cause it to fail.
415 with self.assertRaises(cros_build_lib.DieSystemExit):
416 image_controller.PushImage(request, self.response, self.api_config)
417
418 def testNoGsImageDir(self):
419 """Test no image dir given fails."""
420 request = self._GetRequest(gs_image_dir='')
421
422 # No image dir should cause it to fail.
423 with self.assertRaises(cros_build_lib.DieSystemExit):
424 image_controller.PushImage(request, self.response, self.api_config)
425
426 def testCallCorrect(self):
427 """Check that a call is called with the correct parameters."""
428 patch = self.PatchObject(pushimage, 'PushImage')
429
430 request = self._GetRequest(
431 dryrun=False, profile='', sign_types=[common_pb2.IMAGE_TYPE_RECOVERY])
Jack Neus485a9d22020-12-21 03:15:15 +0000432 request.dest_bucket = 'gs://foo'
Jack Neus761e1842020-12-01 18:20:11 +0000433 image_controller.PushImage(request, self.response, self.api_config)
434 patch.assert_called_with(
435 request.gs_image_dir,
436 request.sysroot.build_target.name,
437 dry_run=request.dryrun,
Jack Neus485a9d22020-12-21 03:15:15 +0000438 sign_types=['recovery'],
439 dest_bucket=request.dest_bucket)
Jack Neus761e1842020-12-01 18:20:11 +0000440
441 def testCallSucceeds(self):
442 """Check that a (dry run) call is made successfully."""
443 request = self._GetRequest(sign_types=[common_pb2.IMAGE_TYPE_RECOVERY])
444 res = image_controller.PushImage(request, self.response, self.api_config)
445 self.assertEqual(res, controller.RETURN_CODE_SUCCESS)
446
447 def testCallFailsWithBadImageDir(self):
448 """Check that a (dry run) call fails when given a bad gs_image_dir."""
449 request = self._GetRequest(gs_image_dir='foo')
450 res = image_controller.PushImage(request, self.response, self.api_config)
451 self.assertEqual(res, controller.RETURN_CODE_COMPLETED_UNSUCCESSFULLY)