ArtifactsService: add endpoint for creating GCE tarball from test image
BUG=b:168762436
TEST=run_tests; \
api/contrib/gen_call_scripts -b betty-arc-r && \
api/contrib/call_scripts/artifacts__bundle_gce_tarball; \
upload image to GCE, launch instance from it
Change-Id: I921df783e3ef1cf86139e65185660ad834e1d467
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/2507306
Tested-by: Shao-Chuan Lee <shaochuan@chromium.org>
Reviewed-by: Michael Mortensen <mmortensen@google.com>
Commit-Queue: Shao-Chuan Lee <shaochuan@chromium.org>
diff --git a/api/controller/artifacts_unittest.py b/api/controller/artifacts_unittest.py
index 0a03757..11b2d18 100644
--- a/api/controller/artifacts_unittest.py
+++ b/api/controller/artifacts_unittest.py
@@ -1186,3 +1186,50 @@
for artifact in self.response.artifacts:
self.assertIn(artifact.path, [expected.report, expected.warnings])
+
+
+class BundleGceTarballTest(BundleTestCase):
+ """Unittests for BundleGceTarball."""
+
+ def testValidateOnly(self):
+ """Check that a validate only call does not execute any logic."""
+ patch = self.PatchObject(artifacts_svc, 'BundleGceTarball')
+ artifacts.BundleGceTarball(self.target_request, self.response,
+ self.validate_only_config)
+ patch.assert_not_called()
+
+ def testMockCall(self):
+ """Test that a mock call does not execute logic, returns mocked value."""
+ patch = self.PatchObject(artifacts_svc, 'BundleGceTarball')
+ artifacts.BundleGceTarball(self.target_request, self.response,
+ self.mock_call_config)
+ patch.assert_not_called()
+ self.assertEqual(len(self.response.artifacts), 1)
+ self.assertEqual(self.response.artifacts[0].path,
+ os.path.join(self.output_dir,
+ constants.TEST_IMAGE_GCE_TAR))
+
+ def testBundleGceTarball(self):
+ """BundleGceTarball calls cbuildbot/commands with correct args."""
+ bundle_gce_tarball = self.PatchObject(
+ artifacts_svc, 'BundleGceTarball',
+ return_value=os.path.join(self.output_dir,
+ constants.TEST_IMAGE_GCE_TAR))
+ self.PatchObject(os.path, 'exists', return_value=True)
+ artifacts.BundleGceTarball(self.target_request, self.response,
+ self.api_config)
+ self.assertEqual(
+ [artifact.path for artifact in self.response.artifacts],
+ [os.path.join(self.output_dir, constants.TEST_IMAGE_GCE_TAR)])
+
+ latest = os.path.join(self.source_root, 'src/build/images/target/latest')
+ self.assertEqual(
+ bundle_gce_tarball.call_args_list,
+ [mock.call(self.output_dir, latest)])
+
+ def testBundleGceTarballNoImageDir(self):
+ """BundleGceTarball dies when image dir does not exist."""
+ self.PatchObject(os.path, 'exists', return_value=False)
+ with self.assertRaises(cros_build_lib.DieSystemExit):
+ artifacts.BundleGceTarball(self.target_request, self.response,
+ self.api_config)