afdo: Implement orderfile-verify-toolchain builder.
This patch implements the functionality of
orderfile-verify-toolchain builder, which is similar to release
builder and verifies if the orderfile can build Chrome without
any problems.
It adds two stages: (1) before BuildPacakges, it gets most recent
unvetted orderfile and update Chrome ebuild; (2) after the build,
copy the orderfile from unvetted to vetted GS bucket.
If the orderfile to verify is already verified, skip the remaining
part of the builder. (Make the same change to
toolchain-generate-orderfile builder)
Major operations are added to lib/toolchain_util.py. cbuildbot
stage-related changes are added to AFDO stages.
BUG=chromium:950627
TEST=orderfile-verify-toolchain-tryjob passes at https://ci.chromium.org/p/chromeos/builders/general/Try/b8908114095670262240
Change-Id: I8148fc7b976e6c1bcd1b5eafb762be0eb680de7d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/1682827
Tested-by: Tiancong Wang <tcwang@google.com>
Auto-Submit: Tiancong Wang <tcwang@google.com>
Commit-Queue: Tiancong Wang <tcwang@google.com>
Reviewed-by: Alex Klein <saklein@chromium.org>
diff --git a/api/controller/toolchain_unittest.py b/api/controller/toolchain_unittest.py
new file mode 100644
index 0000000..5175e89
--- /dev/null
+++ b/api/controller/toolchain_unittest.py
@@ -0,0 +1,77 @@
+# -*- 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.
+
+"""Unittests for Toolchain-related operations."""
+
+from __future__ import print_function
+
+import mock
+import os
+
+from chromite.api.controller import toolchain
+from chromite.api.gen.chromite.api import toolchain_pb2
+
+from chromite.lib import cros_test_lib
+from chromite.lib import gs
+from chromite.lib import toolchain_util
+
+
+class UpdateChromeEbuildWithOrderfileTest(cros_test_lib.MockTestCase):
+ """Unittests for UpdateChromeEbuildWithOrderfile."""
+
+ def setUp(self):
+ self.command = self.PatchObject(toolchain_util,
+ 'OrderfileUpdateChromeEbuild')
+ self.board = 'board'
+ self.input_proto = toolchain_pb2.UpdateChromeEbuildRequest(
+ build_target={'name': self.board})
+
+ def testSuccess(self):
+ """Test the command is called correctly."""
+ output_proto = toolchain_pb2.UpdateChromeEbuildResponse()
+ toolchain.UpdateChromeEbuildWithOrderfile(self.input_proto,
+ output_proto)
+ self.command.assert_called_once_with(self.board)
+
+
+class UploadVettedOrderfileTest(cros_test_lib.MockTestCase):
+ """Unittests for UploadVettedOrderfile."""
+
+ def setUp(self):
+ self.find_command = self.PatchObject(
+ toolchain_util,
+ 'FindLatestChromeOrderfile',
+ return_value='orderfile-3.0.tar.xz')
+ self.copy_command = self.PatchObject(gs.GSContext, 'Copy', autospec=True)
+ self.from_url = os.path.join(toolchain_util.ORDERFILE_GS_URL_UNVETTED,
+ 'orderfile-3.0.tar.xz')
+ self.to_url = os.path.join(toolchain_util.ORDERFILE_GS_URL_VETTED,
+ 'orderfile-3.0.tar.xz')
+ self.input_proto = toolchain_pb2.UploadVettedOrderfileRequest()
+
+ def testRunFail(self):
+ """Test that it fails to upload an orderfile because it's already vetted."""
+ exist_command = self.PatchObject(gs.GSContext, 'Exists', return_value=True)
+ output_proto = toolchain_pb2.UploadVettedOrderfileResponse()
+ toolchain.UploadVettedOrderfile(self.input_proto, output_proto)
+ self.assertFalse(output_proto.status)
+ self.find_command.assert_called_once_with(
+ toolchain_util.ORDERFILE_GS_URL_UNVETTED)
+ exist_command.assert_called_once_with(self.to_url)
+
+ def testRunPass(self):
+ """Test run successfully."""
+ exist_command = self.PatchObject(gs.GSContext, 'Exists', return_value=False)
+ output_proto = toolchain_pb2.UploadVettedOrderfileResponse()
+ toolchain.UploadVettedOrderfile(self.input_proto, output_proto)
+ self.assertTrue(output_proto.status)
+ self.find_command.assert_called_once_with(
+ toolchain_util.ORDERFILE_GS_URL_UNVETTED)
+ exist_command.assert_called_once_with(self.to_url)
+ self.copy_command.assert_called_once_with(
+ mock.ANY, # Placeholder for 'self'
+ self.from_url,
+ self.to_url,
+ acl='public-read')