Update test_toolchains.py to save tar files of the images used.

This is for generating a weekly report that compares the nightly
test results.  All of the nightly test results are cached, but in
order to find the correct cache results, you need the image from
which the results were created.  Due to disk space, some of the
chroots will be deleted before the weekly report gets generated.
Therefore, this modification tars up the test & vanilla image
directories and stores them separately, where they can be accessed
for generating the weekly report.

BUG=None
TEST=Used this successfully last night for nightly test runs.

Change-Id: I01b457a402c3649d7904a478b37bad60b3395300
Reviewed-on: https://chrome-internal-review.googlesource.com/164879
Reviewed-by: Yunlian Jiang <yunlian@google.com>
Commit-Queue: Caroline Tice <cmtice@google.com>
Tested-by: Caroline Tice <cmtice@google.com>
diff --git a/test_toolchains.py b/test_toolchains.py
index d8b750a..0135c0d 100644
--- a/test_toolchains.py
+++ b/test_toolchains.py
@@ -6,11 +6,14 @@
 import sys
 import build_chromeos
 import setup_chromeos
+import time
 from utils import command_executer
 from utils import misc
 from utils import logger
 
 
+WEEKLY_REPORTS_ROOT="/usr/local/google/crostc/weekly_test_data"
+
 class GCCConfig(object):
   def __init__(self, githash):
     self.githash = githash
@@ -163,6 +166,28 @@
                             "chromiumos_test_image.bin"),
                image_args)
         print >>f, experiment_image
+    images_path = os.path.join(os.path.realpath(self._chromeos_root),
+                               "src/build/images", self._board)
+    weekday = time.strftime("%a")
+    for l in labels:
+      test_path = os.path.join(images_path, l)
+      if os.path.exists(test_path):
+        data_dir = os.path.join(WEEKLY_REPORTS_ROOT, self._board)
+        if l == "vanilla":
+          label_name = l
+        else:
+          label_name = "test"
+        tar_file_name = "%s_%s_image.tar" % (weekday, label_name)
+        dest_dir = os.path.join (data_dir, weekday)
+        if not os.path.exists(dest_dir):
+          os.makedirs(dest_dir)
+        cmd="cd %s; tar -cvf %s %s/*; cp %s %s/." % (images_path,tar_file_name,
+                                                     l, tar_file_name,
+                                                     dest_dir)
+        tar_ret = self._ce.RunCommand(cmd)
+        if tar_ret:
+          self._l.LogOutput("Error while creating/copying test tar file (%s)."
+                            % tar_file_name)
     crosperf = os.path.join(os.path.dirname(__file__),
                             "crosperf",
                             "crosperf")