Initial xBuddy for devserver

Contains most of the basic functionality of the xBuddy rpc, as outlined
in the Design Doc found in ChromeOs Installer.
  - xbuddy, xbuddy_list, xbuddy_capacity rpcs on devserver
  - xbuddy's path translation:
    - defined default version aliases
    - defined default xbuddy artifact aliases
  - xbuddy build cache:
    - on build_id cache hit, serves corresponding image/artifact
    - on build_id cache miss, downloads from Google Storage, then serves
    - maintains a cache of 5 downloaded builds & record of their last
      access time in a separate timestamp directory

Plus some housekeeping of devserver constants

BUG=chromium:252941
TEST=manual and unit tests

Manual (for testing devserver rpcs): Run the devserver locally, attempt
to access each of the following addresses from browser

  1. http://localhost:8080/xbuddy?path=/parrot-release/R21-2461.0.0/
  test&return_update_url=t
  Expect: Several seconds of lag as image is downloaded, then a
  url to the image dir, such as
  http://localhost:8080/static/parrot-release/R21-2461.0.0
  [Note, using an IP address instead of localhost should return that IP
  address]

  2. http://localhost:8080/xbuddy?path=/parrot-release/R21-2461.0.0/test
  Expect: A download of the right chromeos_test_image.bin

  3. http://localhost:8080/xbuddy_capacity/
  Expect: Just '5', the default xbuddy capacity

  4. http://localhost:8080/xbuddy_list/
  Expect: A string that lists the previously requested build and how
  long ago it was accessed

  5. More combinations of board/version/alias should work as well, with
  xbuddy_list and the default devserver static folder's contents
  reflecting normal caching behavior.

Unit Tests (for xbuddy functions): run xbuddy_unittests.py

Change-Id: I612cbb3ee907bb70907669d6db20f266157c0244
Reviewed-on: https://gerrit.chromium.org/gerrit/59287
Reviewed-by: Joy Chen <joychen@chromium.org>
Tested-by: Joy Chen <joychen@chromium.org>
Commit-Queue: Joy Chen <joychen@chromium.org>
diff --git a/build_artifact.py b/build_artifact.py
index 3fa64b8..2cbd6ae 100644
--- a/build_artifact.py
+++ b/build_artifact.py
@@ -11,6 +11,7 @@
 
 import artifact_info
 import common_util
+import devserver_constants
 import gsutil_util
 import log_util
 
@@ -24,10 +25,11 @@
 AU_SUITE_FILE = 'au_control.tar.bz2'
 AUTOTEST_FILE = 'autotest.tar'
 AUTOTEST_COMPRESSED_FILE = 'autotest.tar.bz2'
+BASE_IMAGE_FILE = 'chromiumos_base_image.bin'
 DEBUG_SYMBOLS_FILE = 'debug.tgz'
 FIRMWARE_FILE = 'firmware_from_source.tar.bz2'
 IMAGE_FILE = 'image.zip'
-ROOT_UPDATE_FILE = 'update.gz'
+RECOVERY_IMAGE_FILE = 'recovery_image.bin'
 STATEFUL_UPDATE_FILE = 'stateful.tgz'
 TEST_IMAGE_FILE = 'chromiumos_test_image.bin'
 TEST_SUITES_FILE = 'test_suites.tar.bz2'
@@ -192,7 +194,8 @@
 
     # Rename to update.gz.
     install_path = os.path.join(self.install_dir, self.name)
-    new_install_path = os.path.join(self.install_dir, ROOT_UPDATE_FILE)
+    new_install_path = os.path.join(self.install_dir,
+                                    devserver_constants.ROOT_UPDATE_FILE)
     shutil.move(install_path, new_install_path)
 
 
@@ -296,7 +299,8 @@
     super(AutotestTarballBuildArtifact, self)._Stage()
 
     # Deal with older autotest packages that may not be bundled.
-    autotest_dir = os.path.join(self.install_dir, 'autotest')
+    autotest_dir = os.path.join(self.install_dir,
+                                devserver_constants.AUTOTEST_DIR)
     autotest_pkgs_dir = os.path.join(autotest_dir, 'packages')
     if not os.path.exists(autotest_pkgs_dir):
       os.makedirs(autotest_pkgs_dir)
@@ -365,9 +369,9 @@
 
   artifact_info.BASE_IMAGE:
       ImplDescription(ZipfileBuildArtifact, IMAGE_FILE,
-                      ['chromiumos_base_image.bin']),
+                      [BASE_IMAGE_FILE]),
   artifact_info.RECOVERY_IMAGE:
-      ImplDescription(ZipfileBuildArtifact, IMAGE_FILE, ['recovery_image.bin']),
+      ImplDescription(ZipfileBuildArtifact, IMAGE_FILE, [RECOVERY_IMAGE_FILE]),
   artifact_info.TEST_IMAGE:
       ImplDescription(ZipfileBuildArtifact, IMAGE_FILE, [TEST_IMAGE_FILE]),