Add --dest-bucket to chromite/scripts/pushimage.py

Add flag so that dest bucket can be set to chromeos-throwaway-bucket,
so that we can get new release builders running without actually
modifying our production bucket (chromeos-releases).
Also, Use this flag in the PushImage Build API endpoint.

BUG=chromium:1159569
TEST=run_tests

Cq-Depend: chromium:2599476
Change-Id: I594502a111adc0ba65a4683a9695afcd44c9d93c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/2599290
Reviewed-by: George Engelbrecht <engeg@google.com>
Commit-Queue: Jack Neus <jackneus@google.com>
Tested-by: Jack Neus <jackneus@google.com>
diff --git a/api/controller/image.py b/api/controller/image.py
index b7968e9..0a75bad 100644
--- a/api/controller/image.py
+++ b/api/controller/image.py
@@ -303,13 +303,18 @@
   if config.validate_only:
     return controller.RETURN_CODE_VALID_INPUT
 
+  kwargs = {}
+  if input_proto.profile.name:
+    kwargs['profile'] = input_proto.profile.name
+  if input_proto.dest_bucket:
+    kwargs['dest_bucket'] = input_proto.dest_bucket
   try:
     pushimage.PushImage(
         input_proto.gs_image_dir,
         input_proto.sysroot.build_target.name,
         dry_run=input_proto.dryrun,
-        profile=input_proto.profile.name,
-        sign_types=sign_types)
+        sign_types=sign_types,
+        **kwargs)
     return controller.RETURN_CODE_SUCCESS
   except Exception:
     return controller.RETURN_CODE_COMPLETED_UNSUCCESSFULLY
diff --git a/api/controller/image_unittest.py b/api/controller/image_unittest.py
index c647e11..6fabccf 100644
--- a/api/controller/image_unittest.py
+++ b/api/controller/image_unittest.py
@@ -415,13 +415,14 @@
 
     request = self._GetRequest(
         dryrun=False, profile='', sign_types=[common_pb2.IMAGE_TYPE_RECOVERY])
+    request.dest_bucket = 'gs://foo'
     image_controller.PushImage(request, self.response, self.api_config)
     patch.assert_called_with(
         request.gs_image_dir,
         request.sysroot.build_target.name,
         dry_run=request.dryrun,
-        profile=request.profile.name,
-        sign_types=['recovery'])
+        sign_types=['recovery'],
+        dest_bucket=request.dest_bucket)
 
   def testCallSucceeds(self):
     """Check that a (dry run) call is made successfully."""
diff --git a/scripts/pushimage.py b/scripts/pushimage.py
index 49a0b58..90ee2fd 100644
--- a/scripts/pushimage.py
+++ b/scripts/pushimage.py
@@ -292,7 +292,8 @@
 
 def PushImage(src_path, board, versionrev=None, profile=None, priority=50,
               sign_types=None, dry_run=False, mock=False, force_keysets=(),
-              force_channels=None, buildroot=constants.SOURCE_ROOT):
+              force_channels=None, buildroot=constants.SOURCE_ROOT,
+              dest_bucket=constants.RELEASE_BUCKET):
   """Push the image from the archive bucket to the release bucket.
 
   Args:
@@ -309,6 +310,7 @@
     force_keysets: Set of keysets to use rather than what the inputs say.
     force_channels: Set of channels to use rather than what the inputs say.
     buildroot: Buildroot in which to look for signing instructions.
+    dest_bucket: Bucket to push results to.
 
   Returns:
     A dictionary that maps 'channel' -> ['gs://signer_instruction_uri1',
@@ -371,7 +373,7 @@
     gs_base = os.path.join(tbs_base, getpass.getuser())
   else:
     logging.info('Upload mode: normal; signers will process the images')
-    tbs_base = gs_base = constants.RELEASE_BUCKET
+    tbs_base = gs_base = dest_bucket
 
   sect_general = {
       'config_board': board,
@@ -616,6 +618,8 @@
                       help='Buildroot to use. Defaults to current.')
   parser.add_argument('--yes', action='store_true', default=False,
                       help='answer yes to all prompts')
+  parser.add_argument('--dest-bucket', default=constants.RELEASE_BUCKET,
+                      help='dest bucket. Default to %(default)s')
 
   return parser
 
@@ -644,4 +648,4 @@
             profile=opts.profile, priority=opts.priority,
             sign_types=opts.sign_types, dry_run=opts.dry_run, mock=opts.mock,
             force_keysets=force_keysets, force_channels=opts.channels,
-            buildroot=opts.buildroot)
+            buildroot=opts.buildroot, dest_bucket=opts.dest_bucket)