config: Add simple-archive-abuildbot builder.

Create a new builder config that is a demonstration of how to upload
build artifacts to GS.

BUG=b/24949256
TEST=bin/cbuildbot --nobootstrap --noreexec --buildbot \
       --buildroot /tmp/buildroot  simple-archive-abuildbot

Change-Id: Ic265415b38ef2cf814a8e5a7f23cf426dd3ab06b
Reviewed-on: https://chromium-review.googlesource.com/308061
Reviewed-by: Don Garrett <dgarrett@chromium.org>
Tested-by: Don Garrett <dgarrett@chromium.org>
diff --git a/builders/test_builders.py b/builders/test_builders.py
index 0671132..26c6be1 100644
--- a/builders/test_builders.py
+++ b/builders/test_builders.py
@@ -6,9 +6,12 @@
 
 from __future__ import print_function
 
-from chromite.lib import cros_logging as logging
+import os
 
-from chromite.cbuildbot import manifest_version
+from chromite.lib import cros_build_lib
+from chromite.lib import cros_logging as logging
+from chromite.lib import osutils
+
 from chromite.cbuildbot.builders import generic_builders
 from chromite.cbuildbot.stages import generic_stages
 from chromite.cbuildbot.stages import sync_stages
@@ -16,10 +19,33 @@
 
 class SuccessStage(generic_stages.BuilderStage):
   """Build stage declares success!"""
+
   def PerformStage(self):
     logging.info('!!!SuccessStage, FTW!!!')
 
 
+class ArtifactStage(generic_stages.BuilderStage,
+                    generic_stages.ArchivingStageMixin):
+  """Build stage that creates/uploads a build artifact."""
+
+  def PerformStage(self):
+    working_root = osutils.GetGlobalTempDir()
+    stuffs_dir = os.path.join(working_root, 'stuffs')
+    tar_file = os.path.join(working_root, 'stuffs.tar.xz')
+
+    # Create some stuff to tar up.
+    osutils.Touch(os.path.join(stuffs_dir, 'a'), makedirs=True)
+    osutils.Touch(os.path.join(stuffs_dir, 'b'), makedirs=True)
+    osutils.Touch(os.path.join(stuffs_dir, 'c'), makedirs=True)
+
+    # Files will be added as 'stuffs/a',  'stuffs/b',  'stuffs/c'
+    cros_build_lib.CreateTarball(tar_file, working_root, inputs=['stuffs'])
+
+    # This actually uploads the artifact to GS. It will be listed in the build's
+    # artifacts linked from the final report stage.
+    self.UploadArtifact(tar_file, archive=True)
+
+
 class SyncBuilder(generic_builders.Builder):
   """Builder that performs sync, then exits."""
 
@@ -30,3 +56,15 @@
   def RunStages(self):
     """Run something after sync/reexec."""
     self._RunStage(SuccessStage)
+
+
+class ArchiveBuilder(generic_builders.Builder):
+  """Builder that performs sync, then exits."""
+
+  def GetSyncInstance(self):
+    """Returns an instance of a SyncStage that should be run."""
+    return self._GetStageInstance(sync_stages.SyncStage)
+
+  def RunStages(self):
+    """Run something after sync/reexec."""
+    self._RunStage(ArtifactStage)
diff --git a/config_dump.json b/config_dump.json
index 3724793..c07d78b 100644
--- a/config_dump.json
+++ b/config_dump.json
@@ -1,14 +1,19 @@
 {
     "_default": {
-        "manifest_repo_url": "https://chromium.googlesource.com/chromiumos/chromite/abuildbot_config"
+        "boards": [],
+        "manifest_repo_url": "https://chromium.googlesource.com/chromiumos/chromite/abuildbot_config",
+        "gs_path": "gs://abuildbot-build-archive/abuildbot"
+
     },
     "_site_params": {
     },
     "_templates": {},
 
     "sync-test-abuildbot": {
-        "boards": [],
-        "builder_class_name": "config.builders.test_builders.SyncBuilder",
-        "name": "sync-test-abuildbot"
+        "builder_class_name": "config.builders.test_builders.SyncBuilder"
+    },
+
+    "simple-archive-abuildbot": {
+        "builder_class_name": "config.builders.test_builders.ArchiveBuilder"
     }
 }