api.payload: Have GeneratePayload return paths

We should have this endpoint tell us where it placed the artifacts it
generated. We'll constrain this to the local delta path as well as the
remote path if it was configured to upload.

In the future we might consider changing lib/paygen to give us a
complete listing of generated files, as some files here still escape
(i.e. are placed on gs but not returned). These include hashes and other
control files.

BUG=chromium:1122854
TEST=./run_tests.py

Change-Id: I2ba07c222980493b67b3dd22cfa3b0e87a699ed0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/2535713
Reviewed-by: LaMont Jones <lamontjones@chromium.org>
Commit-Queue: George Engelbrecht <engeg@google.com>
Tested-by: George Engelbrecht <engeg@google.com>
diff --git a/api/controller/payload.py b/api/controller/payload.py
index 4e36742..1253406 100644
--- a/api/controller/payload.py
+++ b/api/controller/payload.py
@@ -86,20 +86,23 @@
     return controller.RETURN_CODE_VALID_INPUT
 
   # Do payload generation.
-  paygen_ok = payload_config.GeneratePayload()
-  _SetGeneratePayloadOutputProto(output_proto, paygen_ok)
+  local_path, remote_uri = payload_config.GeneratePayload()
+  _SetGeneratePayloadOutputProto(output_proto, local_path, remote_uri)
 
-  if paygen_ok:
+  if remote_uri or not upload and local_path:
     return controller.RETURN_CODE_SUCCESS
   else:
     return controller.RETURN_CODE_COMPLETED_UNSUCCESSFULLY
 
 
-def _SetGeneratePayloadOutputProto(output_proto, generate_payload_ok):
+def _SetGeneratePayloadOutputProto(output_proto, local_path, remote_uri):
   """Set the output proto with the results from the service class.
 
   Args:
     output_proto (PayloadGenerationResult_pb2): The output proto.
-    generate_payload_ok (bool): value to set output_proto.success.
+    local_path (str): set output_proto with the local path, or None.
+    remote_uri (str): set output_proto with the remote uri, or None.
   """
-  output_proto.success = generate_payload_ok
+  output_proto.success = True
+  output_proto.local_path = local_path
+  output_proto.remote_uri = remote_uri
diff --git a/api/controller/payload_unittest.py b/api/controller/payload_unittest.py
index 3d06849..9b8c0cd 100644
--- a/api/controller/payload_unittest.py
+++ b/api/controller/payload_unittest.py
@@ -17,7 +17,7 @@
 
 
 class PayloadApiTests(cros_test_lib.MockTestCase, api_config.ApiConfigMixin):
-  """Unittests for SetBinhost."""
+  """Unittests for PayloadApi."""
 
   def setUp(self):
     self.response = payload_pb2.GenerationResponse()
@@ -44,7 +44,10 @@
         keyset='update_signer',
         dryrun=False)
 
-    self.result = payload_pb2.GenerationResponse()
+    self.result = payload_pb2.GenerationResponse(
+        success=True,
+        local_path='/tmp/aohiwdadoi/delta.bin',
+        remote_uri='gs://something')
 
   def testValidateOnly(self):
     """Sanity check that a validate only call does not execute any logic."""
@@ -56,7 +59,8 @@
   def testCallSucceeds(self):
     """Check that a call is made successfully."""
     # Deep patch the paygen lib, this is a full run through service as well.
-    self.PatchObject(paygen_payload_lib, 'PaygenPayload')
+    patch_obj = self.PatchObject(paygen_payload_lib, 'PaygenPayload')
+    patch_obj.return_value.Run.return_value = 'gs://something'
     res = payload.GeneratePayload(self.req, self.result, self.api_config)
     self.assertEqual(res, controller.RETURN_CODE_SUCCESS)