blob: 478e07c9ba95774d55d849eeff7fb319707d3874 [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
Mike Frysinger6db648e2018-07-24 19:57:58 -040012import mock
13
Alex Klein231d2da2019-07-22 16:44:45 -060014from chromite.api import api_config
Alex Klein8cb365a2019-05-15 16:24:53 -060015from chromite.api import controller
16from chromite.api.controller import image as image_controller
Alex Klein7107bdd2019-03-14 17:14:31 -060017from chromite.api.gen.chromite.api import image_pb2
David Burger13e06be2019-05-13 20:33:16 -060018from chromite.api.gen.chromiumos import common_pb2
Jack Neus761e1842020-12-01 18:20:11 +000019from chromite.api.gen.chromite.api import sysroot_pb2
Alex Klein56355682019-02-07 10:36:54 -070020from chromite.lib import constants
Alex Klein4f0eb432019-05-02 13:56:04 -060021from chromite.lib import cros_build_lib
Alex Klein2966e302019-01-17 13:29:38 -070022from chromite.lib import cros_test_lib
Michael Mortensenc83c9952019-08-05 12:15:12 -060023from chromite.lib import image_lib
Alex Klein2966e302019-01-17 13:29:38 -070024from chromite.lib import osutils
Jack Neus761e1842020-12-01 18:20:11 +000025from chromite.scripts import pushimage
Alex Kleinb7cdbe62019-02-22 11:41:32 -070026from chromite.service import image as image_service
Alex Klein2966e302019-01-17 13:29:38 -070027
28
Alex Klein231d2da2019-07-22 16:44:45 -060029class CreateTest(cros_test_lib.MockTempDirTestCase, api_config.ApiConfigMixin):
Alex Klein56355682019-02-07 10:36:54 -070030 """Create image tests."""
31
Alex Klein231d2da2019-07-22 16:44:45 -060032 def setUp(self):
33 self.response = image_pb2.CreateImageResult()
34
Jack Neus761e1842020-12-01 18:20:11 +000035 def _GetRequest(self,
36 board=None,
37 types=None,
38 version=None,
39 builder_path=None,
Alex Klein21b95022019-05-09 14:14:46 -060040 disable_rootfs_verification=False):
41 """Helper to build a request instance."""
42 return image_pb2.CreateImageRequest(
43 build_target={'name': board},
44 image_types=types,
45 disable_rootfs_verification=disable_rootfs_verification,
46 version=version,
47 builder_path=builder_path,
48 )
49
Alex Klein231d2da2019-07-22 16:44:45 -060050 def testValidateOnly(self):
51 """Sanity check that a validate only call does not execute any logic."""
52 patch = self.PatchObject(image_service, 'Build')
Alex Klein21b95022019-05-09 14:14:46 -060053
Alex Klein231d2da2019-07-22 16:44:45 -060054 request = self._GetRequest(board='board')
55 image_controller.Create(request, self.response, self.validate_only_config)
56 patch.assert_not_called()
57
Michael Mortensen10146cf2019-11-19 19:59:22 -070058 def testMockCall(self):
59 """Test that mock call does not execute any logic, returns mocked value."""
60 patch = self.PatchObject(image_service, 'Build')
61
62 request = self._GetRequest(board='board')
63 image_controller.Create(request, self.response, self.mock_call_config)
64 patch.assert_not_called()
65 self.assertEqual(self.response.success, True)
66
Michael Mortensen85d38402019-12-12 09:50:29 -070067 def testMockError(self):
68 """Test that mock call does not execute any logic, returns error."""
69 patch = self.PatchObject(image_service, 'Build')
70
71 request = self._GetRequest(board='board')
72 rc = image_controller.Create(request, self.response, self.mock_error_config)
73 patch.assert_not_called()
74 self.assertEqual(controller.RETURN_CODE_COMPLETED_UNSUCCESSFULLY, rc)
75
Alex Klein231d2da2019-07-22 16:44:45 -060076 def testNoBoard(self):
77 """Test no board given fails."""
78 request = self._GetRequest()
Alex Klein56355682019-02-07 10:36:54 -070079
80 # No board should cause it to fail.
Alex Klein4f0eb432019-05-02 13:56:04 -060081 with self.assertRaises(cros_build_lib.DieSystemExit):
Alex Klein231d2da2019-07-22 16:44:45 -060082 image_controller.Create(request, self.response, self.api_config)
Alex Klein56355682019-02-07 10:36:54 -070083
Alex Klein21b95022019-05-09 14:14:46 -060084 def testNoTypeSpecified(self):
85 """Test the image type default."""
86 request = self._GetRequest(board='board')
Alex Klein21b95022019-05-09 14:14:46 -060087
Alex Klein1bcd9882019-03-19 13:25:24 -060088 # Failed result to avoid the success handling logic.
89 result = image_service.BuildResult(1, [])
90 build_patch = self.PatchObject(image_service, 'Build', return_value=result)
Alex Klein56355682019-02-07 10:36:54 -070091
Alex Klein231d2da2019-07-22 16:44:45 -060092 image_controller.Create(request, self.response, self.api_config)
Jack Neus761e1842020-12-01 18:20:11 +000093 build_patch.assert_called_with(
94 images=[constants.IMAGE_TYPE_BASE], board='board', config=mock.ANY)
Alex Klein56355682019-02-07 10:36:54 -070095
Alex Klein21b95022019-05-09 14:14:46 -060096 def testSingleTypeSpecified(self):
97 """Test it's properly using a specified type."""
98 request = self._GetRequest(board='board', types=[common_pb2.DEV])
Alex Klein21b95022019-05-09 14:14:46 -060099
100 # Failed result to avoid the success handling logic.
101 result = image_service.BuildResult(1, [])
102 build_patch = self.PatchObject(image_service, 'Build', return_value=result)
103
Alex Klein231d2da2019-07-22 16:44:45 -0600104 image_controller.Create(request, self.response, self.api_config)
Jack Neus761e1842020-12-01 18:20:11 +0000105 build_patch.assert_called_with(
106 images=[constants.IMAGE_TYPE_DEV], board='board', config=mock.ANY)
Alex Klein56355682019-02-07 10:36:54 -0700107
Alex Klein21b95022019-05-09 14:14:46 -0600108 def testMultipleAndImpliedTypes(self):
109 """Test multiple types and implied type handling."""
110 # The TEST_VM type should force it to build the test image.
111 types = [common_pb2.BASE, common_pb2.TEST_VM]
112 expected_images = [constants.IMAGE_TYPE_BASE, constants.IMAGE_TYPE_TEST]
113
114 request = self._GetRequest(board='board', types=types)
Alex Klein21b95022019-05-09 14:14:46 -0600115
116 # Failed result to avoid the success handling logic.
117 result = image_service.BuildResult(1, [])
118 build_patch = self.PatchObject(image_service, 'Build', return_value=result)
119
Alex Klein231d2da2019-07-22 16:44:45 -0600120 image_controller.Create(request, self.response, self.api_config)
Jack Neus761e1842020-12-01 18:20:11 +0000121 build_patch.assert_called_with(
122 images=expected_images, board='board', config=mock.ANY)
Alex Klein56355682019-02-07 10:36:54 -0700123
George Engelbrecht9f4f8322021-03-08 12:04:17 -0700124 def testRecoveryImpliedTypes(self):
125 """Test implied type handling of recovery images."""
126 # The TEST_VM type should force it to build the test image.
127 types = [common_pb2.IMAGE_TYPE_RECOVERY]
128
129 request = self._GetRequest(board='board', types=types)
130
131 # Failed result to avoid the success handling logic.
132 result = image_service.BuildResult(1, [])
133 build_patch = self.PatchObject(image_service, 'Build', return_value=result)
134
135 image_controller.Create(request, self.response, self.api_config)
136 build_patch.assert_called_with(
137 images=[constants.IMAGE_TYPE_BASE], board='board', config=mock.ANY)
138
Alex Klein1bcd9882019-03-19 13:25:24 -0600139 def testFailedPackageHandling(self):
140 """Test failed packages are populated correctly."""
141 result = image_service.BuildResult(1, ['foo/bar', 'cat/pkg'])
142 expected_packages = [('foo', 'bar'), ('cat', 'pkg')]
143 self.PatchObject(image_service, 'Build', return_value=result)
144
Alex Klein231d2da2019-07-22 16:44:45 -0600145 input_proto = self._GetRequest(board='board')
Alex Klein1bcd9882019-03-19 13:25:24 -0600146
Alex Klein231d2da2019-07-22 16:44:45 -0600147 rc = image_controller.Create(input_proto, self.response, self.api_config)
148
Alex Klein8cb365a2019-05-15 16:24:53 -0600149 self.assertEqual(controller.RETURN_CODE_UNSUCCESSFUL_RESPONSE_AVAILABLE, rc)
Alex Klein231d2da2019-07-22 16:44:45 -0600150 for package in self.response.failed_packages:
Alex Klein1bcd9882019-03-19 13:25:24 -0600151 self.assertIn((package.category, package.package_name), expected_packages)
152
Alex Klein2557b4f2019-07-11 14:34:00 -0600153 def testNoPackagesFailureHandling(self):
154 """Test failed packages are populated correctly."""
155 result = image_service.BuildResult(1, [])
156 self.PatchObject(image_service, 'Build', return_value=result)
Alex Kleinb7cdbe62019-02-22 11:41:32 -0700157
Alex Klein2557b4f2019-07-11 14:34:00 -0600158 input_proto = image_pb2.CreateImageRequest()
159 input_proto.build_target.name = 'board'
Alex Klein2557b4f2019-07-11 14:34:00 -0600160
Alex Klein231d2da2019-07-22 16:44:45 -0600161 rc = image_controller.Create(input_proto, self.response, self.api_config)
Alex Klein2557b4f2019-07-11 14:34:00 -0600162 self.assertTrue(rc)
163 self.assertNotEqual(controller.RETURN_CODE_UNSUCCESSFUL_RESPONSE_AVAILABLE,
164 rc)
Alex Klein231d2da2019-07-22 16:44:45 -0600165 self.assertFalse(self.response.failed_packages)
Alex Klein2557b4f2019-07-11 14:34:00 -0600166
167
Alex Klein231d2da2019-07-22 16:44:45 -0600168class ImageSignerTestTest(cros_test_lib.MockTempDirTestCase,
169 api_config.ApiConfigMixin):
Michael Mortensenc83c9952019-08-05 12:15:12 -0600170 """Image signer test tests."""
171
172 def setUp(self):
173 self.image_path = os.path.join(self.tempdir, 'image.bin')
Michael Mortensenc83c9952019-08-05 12:15:12 -0600174 self.result_directory = os.path.join(self.tempdir, 'results')
175
176 osutils.SafeMakedirs(self.result_directory)
177 osutils.Touch(self.image_path)
178
Alex Klein231d2da2019-07-22 16:44:45 -0600179 def testValidateOnly(self):
180 """Sanity check that validate-only calls don't execute any logic."""
181 patch = self.PatchObject(image_lib, 'SecurityTest', return_value=True)
182 input_proto = image_pb2.TestImageRequest()
183 input_proto.image.path = self.image_path
184 output_proto = image_pb2.TestImageResult()
185
186 image_controller.SignerTest(input_proto, output_proto,
187 self.validate_only_config)
188
189 patch.assert_not_called()
190
Michael Mortensen10146cf2019-11-19 19:59:22 -0700191 def testMockCall(self):
192 """Test that mock call does not execute any logic, returns mocked value."""
193 patch = self.PatchObject(image_lib, 'SecurityTest', return_value=True)
194 input_proto = image_pb2.TestImageRequest()
195 input_proto.image.path = self.image_path
196 output_proto = image_pb2.TestImageResult()
197
198 image_controller.SignerTest(input_proto, output_proto,
199 self.mock_call_config)
200
201 patch.assert_not_called()
202 self.assertEqual(output_proto.success, True)
203
Michael Mortensen85d38402019-12-12 09:50:29 -0700204 def testMockError(self):
205 """Test that mock call does not execute any logic, returns error."""
206 patch = self.PatchObject(image_lib, 'SecurityTest', return_value=True)
207 input_proto = image_pb2.TestImageRequest()
208 input_proto.image.path = self.image_path
209 output_proto = image_pb2.TestImageResult()
210
211 rc = image_controller.SignerTest(input_proto, output_proto,
212 self.mock_error_config)
213
214 patch.assert_not_called()
215 self.assertEqual(controller.RETURN_CODE_COMPLETED_UNSUCCESSFULLY, rc)
216
Alex Klein231d2da2019-07-22 16:44:45 -0600217 def testSignerTestNoImage(self):
218 """Test function argument validation."""
Michael Mortensenc83c9952019-08-05 12:15:12 -0600219 input_proto = image_pb2.TestImageRequest()
220 output_proto = image_pb2.TestImageResult()
221
222 # Nothing provided.
223 with self.assertRaises(cros_build_lib.DieSystemExit):
Alex Klein231d2da2019-07-22 16:44:45 -0600224 image_controller.SignerTest(input_proto, output_proto, self.api_config)
Michael Mortensenc83c9952019-08-05 12:15:12 -0600225
Alex Klein231d2da2019-07-22 16:44:45 -0600226 def testSignerTestSuccess(self):
227 """Test successful call handling."""
228 self.PatchObject(image_lib, 'SecurityTest', return_value=True)
229 input_proto = image_pb2.TestImageRequest()
Michael Mortensenc83c9952019-08-05 12:15:12 -0600230 input_proto.image.path = self.image_path
Alex Klein231d2da2019-07-22 16:44:45 -0600231 output_proto = image_pb2.TestImageResult()
Michael Mortensenc83c9952019-08-05 12:15:12 -0600232
Alex Klein231d2da2019-07-22 16:44:45 -0600233 image_controller.SignerTest(input_proto, output_proto, self.api_config)
234
235 def testSignerTestFailure(self):
Michael Mortensenc83c9952019-08-05 12:15:12 -0600236 """Test function output tests."""
237 input_proto = image_pb2.TestImageRequest()
238 input_proto.image.path = self.image_path
Michael Mortensenc83c9952019-08-05 12:15:12 -0600239 output_proto = image_pb2.TestImageResult()
240
Michael Mortensenc83c9952019-08-05 12:15:12 -0600241 self.PatchObject(image_lib, 'SecurityTest', return_value=False)
Alex Klein231d2da2019-07-22 16:44:45 -0600242 image_controller.SignerTest(input_proto, output_proto, self.api_config)
Michael Mortensenc83c9952019-08-05 12:15:12 -0600243 self.assertFalse(output_proto.success)
244
Michael Mortensenc83c9952019-08-05 12:15:12 -0600245
Alex Klein231d2da2019-07-22 16:44:45 -0600246class ImageTestTest(cros_test_lib.MockTempDirTestCase,
247 api_config.ApiConfigMixin):
Alex Klein2557b4f2019-07-11 14:34:00 -0600248 """Image test tests."""
Alex Klein2966e302019-01-17 13:29:38 -0700249
250 def setUp(self):
251 self.image_path = os.path.join(self.tempdir, 'image.bin')
252 self.board = 'board'
253 self.result_directory = os.path.join(self.tempdir, 'results')
254
255 osutils.SafeMakedirs(self.result_directory)
256 osutils.Touch(self.image_path)
257
Alex Klein231d2da2019-07-22 16:44:45 -0600258 def testValidateOnly(self):
259 """Sanity check that a validate only call does not execute any logic."""
260 patch = self.PatchObject(image_service, 'Test')
261
262 input_proto = image_pb2.TestImageRequest()
263 input_proto.image.path = self.image_path
264 input_proto.build_target.name = self.board
265 input_proto.result.directory = self.result_directory
266 output_proto = image_pb2.TestImageResult()
267
268 image_controller.Test(input_proto, output_proto, self.validate_only_config)
269 patch.assert_not_called()
270
Michael Mortensen10146cf2019-11-19 19:59:22 -0700271 def testMockCall(self):
272 """Test that mock call does not execute any logic, returns mocked value."""
273 patch = self.PatchObject(image_service, 'Test')
274
275 input_proto = image_pb2.TestImageRequest()
276 input_proto.image.path = self.image_path
277 input_proto.build_target.name = self.board
278 input_proto.result.directory = self.result_directory
279 output_proto = image_pb2.TestImageResult()
280
281 image_controller.Test(input_proto, output_proto, self.mock_call_config)
282 patch.assert_not_called()
283 self.assertEqual(output_proto.success, True)
284
Michael Mortensen85d38402019-12-12 09:50:29 -0700285 def testMockError(self):
286 """Test that mock call does not execute any logic, returns error."""
287 patch = self.PatchObject(image_service, 'Test')
288
289 input_proto = image_pb2.TestImageRequest()
290 input_proto.image.path = self.image_path
291 input_proto.build_target.name = self.board
292 input_proto.result.directory = self.result_directory
293 output_proto = image_pb2.TestImageResult()
294
295 rc = image_controller.Test(input_proto, output_proto,
296 self.mock_error_config)
297 patch.assert_not_called()
298 self.assertEqual(controller.RETURN_CODE_COMPLETED_UNSUCCESSFULLY, rc)
299
Alex Klein2966e302019-01-17 13:29:38 -0700300 def testTestArgumentValidation(self):
301 """Test function argument validation tests."""
Alex Kleinb7cdbe62019-02-22 11:41:32 -0700302 self.PatchObject(image_service, 'Test', return_value=True)
Alex Klein2966e302019-01-17 13:29:38 -0700303 input_proto = image_pb2.TestImageRequest()
304 output_proto = image_pb2.TestImageResult()
305
306 # Nothing provided.
Alex Klein4f0eb432019-05-02 13:56:04 -0600307 with self.assertRaises(cros_build_lib.DieSystemExit):
Alex Klein231d2da2019-07-22 16:44:45 -0600308 image_controller.Test(input_proto, output_proto, self.api_config)
Alex Klein2966e302019-01-17 13:29:38 -0700309
310 # Just one argument.
311 input_proto.build_target.name = self.board
Alex Klein4f0eb432019-05-02 13:56:04 -0600312 with self.assertRaises(cros_build_lib.DieSystemExit):
Alex Klein231d2da2019-07-22 16:44:45 -0600313 image_controller.Test(input_proto, output_proto, self.api_config)
Alex Klein2966e302019-01-17 13:29:38 -0700314
315 # Two arguments provided.
316 input_proto.result.directory = self.result_directory
Alex Klein4f0eb432019-05-02 13:56:04 -0600317 with self.assertRaises(cros_build_lib.DieSystemExit):
Alex Klein231d2da2019-07-22 16:44:45 -0600318 image_controller.Test(input_proto, output_proto, self.api_config)
Alex Klein2966e302019-01-17 13:29:38 -0700319
320 # Invalid image path.
321 input_proto.image.path = '/invalid/image/path'
Alex Klein4f0eb432019-05-02 13:56:04 -0600322 with self.assertRaises(cros_build_lib.DieSystemExit):
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 # All valid arguments.
326 input_proto.image.path = self.image_path
Alex Klein231d2da2019-07-22 16:44:45 -0600327 image_controller.Test(input_proto, output_proto, self.api_config)
Alex Klein2966e302019-01-17 13:29:38 -0700328
329 def testTestOutputHandling(self):
330 """Test function output tests."""
331 input_proto = image_pb2.TestImageRequest()
332 input_proto.image.path = self.image_path
333 input_proto.build_target.name = self.board
334 input_proto.result.directory = self.result_directory
335 output_proto = image_pb2.TestImageResult()
336
Alex Kleinb7cdbe62019-02-22 11:41:32 -0700337 self.PatchObject(image_service, 'Test', return_value=True)
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.assertTrue(output_proto.success)
340
Alex Kleinb7cdbe62019-02-22 11:41:32 -0700341 self.PatchObject(image_service, 'Test', return_value=False)
Alex Klein231d2da2019-07-22 16:44:45 -0600342 image_controller.Test(input_proto, output_proto, self.api_config)
Alex Klein2966e302019-01-17 13:29:38 -0700343 self.assertFalse(output_proto.success)
Jack Neus761e1842020-12-01 18:20:11 +0000344
345
346class PushImageTest(cros_test_lib.MockTestCase, api_config.ApiConfigMixin):
347 """Push image test."""
348
349 def setUp(self):
350 self.response = image_pb2.PushImageResponse()
351
352 def _GetRequest(
353 self,
354 gs_image_dir='gs://chromeos-image-archive/atlas-release/R89-13604.0.0',
355 build_target_name='atlas',
356 profile='foo',
357 sign_types=None,
358 dryrun=True):
359 return image_pb2.PushImageRequest(
360 gs_image_dir=gs_image_dir,
361 sysroot=sysroot_pb2.Sysroot(
362 build_target=common_pb2.BuildTarget(name=build_target_name)),
363 profile=common_pb2.Profile(name=profile),
364 sign_types=sign_types,
365 dryrun=dryrun)
366
367 def testValidateOnly(self):
368 """Check that a validate only call does not execute any logic."""
369 patch = self.PatchObject(pushimage, 'PushImage')
370
371 req = self._GetRequest(sign_types=[
372 common_pb2.IMAGE_TYPE_RECOVERY, common_pb2.IMAGE_TYPE_FACTORY,
373 common_pb2.IMAGE_TYPE_FIRMWARE, common_pb2.IMAGE_TYPE_ACCESSORY_USBPD,
374 common_pb2.IMAGE_TYPE_ACCESSORY_RWSIG, common_pb2.IMAGE_TYPE_BASE,
375 common_pb2.IMAGE_TYPE_GSC_FIRMWARE
376 ])
377 res = image_controller.PushImage(req, self.response,
378 self.validate_only_config)
379 patch.assert_not_called()
380 self.assertEqual(res, controller.RETURN_CODE_VALID_INPUT)
381
382 def testValidateOnlyInvalid(self):
383 """Check that validate call rejects invalid sign types."""
384 patch = self.PatchObject(pushimage, 'PushImage')
385
386 # Pass unsupported image type.
387 req = self._GetRequest(sign_types=[common_pb2.IMAGE_TYPE_DLC])
388 res = image_controller.PushImage(req, self.response,
389 self.validate_only_config)
390 patch.assert_not_called()
391 self.assertEqual(res, controller.RETURN_CODE_INVALID_INPUT)
392
393 def testMockCall(self):
394 """Test that mock call does not execute any logic, returns mocked value."""
395 patch = self.PatchObject(pushimage, 'PushImage')
396
397 rc = image_controller.PushImage(self._GetRequest(), self.response,
398 self.mock_call_config)
399 patch.assert_not_called()
400 self.assertEqual(controller.RETURN_CODE_SUCCESS, rc)
401
402 def testMockError(self):
403 """Test that mock call does not execute any logic, returns error."""
404 patch = self.PatchObject(pushimage, 'PushImage')
405
406 rc = image_controller.PushImage(self._GetRequest(), self.response,
407 self.mock_error_config)
408 patch.assert_not_called()
409 self.assertEqual(controller.RETURN_CODE_COMPLETED_UNSUCCESSFULLY, rc)
410
411 def testNoBuildTarget(self):
412 """Test no build target given fails."""
413 request = self._GetRequest(build_target_name='')
414
415 # No build target should cause it to fail.
416 with self.assertRaises(cros_build_lib.DieSystemExit):
417 image_controller.PushImage(request, self.response, self.api_config)
418
419 def testNoGsImageDir(self):
420 """Test no image dir given fails."""
421 request = self._GetRequest(gs_image_dir='')
422
423 # No image dir should cause it to fail.
424 with self.assertRaises(cros_build_lib.DieSystemExit):
425 image_controller.PushImage(request, self.response, self.api_config)
426
427 def testCallCorrect(self):
428 """Check that a call is called with the correct parameters."""
429 patch = self.PatchObject(pushimage, 'PushImage')
430
431 request = self._GetRequest(
432 dryrun=False, profile='', sign_types=[common_pb2.IMAGE_TYPE_RECOVERY])
Jack Neus485a9d22020-12-21 03:15:15 +0000433 request.dest_bucket = 'gs://foo'
Jack Neus761e1842020-12-01 18:20:11 +0000434 image_controller.PushImage(request, self.response, self.api_config)
435 patch.assert_called_with(
436 request.gs_image_dir,
437 request.sysroot.build_target.name,
438 dry_run=request.dryrun,
Jack Neus485a9d22020-12-21 03:15:15 +0000439 sign_types=['recovery'],
440 dest_bucket=request.dest_bucket)
Jack Neus761e1842020-12-01 18:20:11 +0000441
442 def testCallSucceeds(self):
443 """Check that a (dry run) call is made successfully."""
444 request = self._GetRequest(sign_types=[common_pb2.IMAGE_TYPE_RECOVERY])
445 res = image_controller.PushImage(request, self.response, self.api_config)
446 self.assertEqual(res, controller.RETURN_CODE_SUCCESS)
447
448 def testCallFailsWithBadImageDir(self):
449 """Check that a (dry run) call fails when given a bad gs_image_dir."""
450 request = self._GetRequest(gs_image_dir='foo')
451 res = image_controller.PushImage(request, self.response, self.api_config)
452 self.assertEqual(res, controller.RETURN_CODE_COMPLETED_UNSUCCESSFULLY)