Initial version of payload build_api endpoint
This is the initial version of the payload build_api endpoint,
and should be considered a work in progress as we fill out the
functionality/tests and get the existing production infrastructure
to a state which will be compatible. The end state is to have
this be called by a recipe that originates in a swarming
task created by a builder.
Further down the road this allows us to decouple the payload
step entirely from the legacy builders.
BUG=chromium:1000894
TEST=./tests
Change-Id: Iee7b27fd416aa24d04f77475cb60e444bcfe41b1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/1910360
Tested-by: George Engelbrecht <engeg@google.com>
Auto-Submit: George Engelbrecht <engeg@google.com>
Reviewed-by: Alex Klein <saklein@chromium.org>
diff --git a/api/controller/payload_unittest.py b/api/controller/payload_unittest.py
new file mode 100644
index 0000000..16cfe47
--- /dev/null
+++ b/api/controller/payload_unittest.py
@@ -0,0 +1,57 @@
+# -*- coding: utf-8 -*-
+# Copyright 2019 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Payload operations."""
+
+from __future__ import print_function
+
+from chromite.api import api_config
+from chromite.api import controller
+from chromite.api.controller import payload
+from chromite.api.gen.chromite.api import payload_pb2
+from chromite.api.gen.chromiumos import common_pb2
+from chromite.lib import cros_test_lib
+from chromite.lib.paygen import paygen_payload_lib
+
+
+class PayloadApiTests(cros_test_lib.MockTestCase, api_config.ApiConfigMixin):
+ """Unittests for SetBinhost."""
+
+ def setUp(self):
+ self.response = payload_pb2.PayloadGenerationResult()
+
+ src_build = payload_pb2.Build(version='1.0.0', bucket='test',
+ channel='test-channel', build_target=
+ common_pb2.BuildTarget(name='cave'))
+
+ src_image = payload_pb2.UnsignedImage(
+ build=src_build, image_type=6, milestone='R70')
+
+ tgt_build = payload_pb2.Build(version='2.0.0', bucket='test',
+ channel='test-channel', build_target=
+ common_pb2.BuildTarget(name='cave'))
+
+ tgt_image = payload_pb2.UnsignedImage(
+ build=tgt_build, image_type=6, milestone='R70')
+
+ self.req = payload_pb2.PayloadGenerationRequest(
+ tgt_unsigned_image=tgt_image, src_unsigned_image=src_image,
+ bucket='test-destination-bucket', verify=True, keyset='update_signer')
+
+ self.result = payload_pb2.PayloadGenerationResult()
+
+ def testValidateOnly(self):
+ """Sanity check that a validate only call does not execute any logic."""
+
+ res = payload.GeneratePayload(self.req, self.result,
+ self.validate_only_config)
+ self.assertEqual(res, controller.RETURN_CODE_VALID_INPUT)
+
+ def testCallSucceeds(self):
+ """Check that a call is made succesfully."""
+ # Deep patch the paygen lib, this is a full run through service as well.
+ self.PatchObject(paygen_payload_lib, 'PaygenPayload')
+ res = payload.GeneratePayload(self.req, self.result, self.api_config)
+ self.assertEqual(res, controller.RETURN_CODE_SUCCESS)