[autotest] Archive exiting autotest logs directory

When updating from M56 to M57 the logs directory changes from an actual
directory to a simlink, the actual directory needs to be archived to
allow the install to work correctly.

TEST=manual testing on affected moblab
BUG=chromium:709697

Change-Id: Ia1fd14ae035e98cd5c29ecd4f4a948d3106f578f
Reviewed-on: https://chromium-review.googlesource.com/474169
Commit-Ready: Keith Haddow <haddowk@chromium.org>
Tested-by: Keith Haddow <haddowk@chromium.org>
Reviewed-by: Keith Haddow <haddowk@chromium.org>
Reviewed-by: Michael Tang <ntang@chromium.org>
(cherry picked from commit eeffcd9b06488e1db083dcce759be4a14866065d)
Reviewed-on: https://chromium-review.googlesource.com/475090
Commit-Queue: Keith Haddow <haddowk@chromium.org>
diff --git a/chromeos-base/autotest-server/autotest-server-0.0.1-r3191.ebuild b/chromeos-base/autotest-server/autotest-server-0.0.1-r3191.ebuild
new file mode 100644
index 0000000..deeba3f
--- /dev/null
+++ b/chromeos-base/autotest-server/autotest-server-0.0.1-r3191.ebuild
@@ -0,0 +1,63 @@
+# Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=4
+CROS_WORKON_COMMIT="37e1a29ec9a83661d1702d9e298df93dd8cc5673"
+CROS_WORKON_TREE="8b3d2b4ab60485b5fd5b100ef1d611be1a16a9bf"
+CROS_WORKON_PROJECT="chromiumos/third_party/autotest"
+CROS_WORKON_LOCALNAME=../third_party/autotest
+CROS_WORKON_SUBDIR=files
+CROS_WORKON_SUBDIR_BLACKLIST=( "Documentation" "ExternalSource" "logs" "manifest-versions" "packages" "results" "site-packages" "frontend/client/www" "containers")
+
+inherit cros-workon cros-constants
+
+DESCRIPTION="Autotest scripts and tools"
+HOMEPAGE="http://dev.chromium.org/chromium-os/testing"
+SRC_URI=""
+LICENSE="GPL-2"
+SLOT="0"
+KEYWORDS="*"
+
+RDEPEND="
+	chromeos-base/autotest-server-deps
+	chromeos-base/autotest-web-frontend
+"
+
+DEPEND=""
+
+AUTOTEST_WORK="${WORKDIR}/autotest-work"
+AUTOTEST_BASE="/autotest"
+
+src_prepare() {
+	mkdir -p "${AUTOTEST_WORK}"
+	cp -fpru "${S}"/* "${AUTOTEST_WORK}/" &>/dev/null
+	find "${AUTOTEST_WORK}" -name '*.pyc' -delete
+
+	# Remove the shadow_config.ini file.
+	rm "${AUTOTEST_WORK}"/shadow_config.ini
+}
+
+src_compile() {
+	protoc --proto_path "${S}" --python_out="${AUTOTEST_WORK}" "${S}/tko/tko.proto"
+}
+
+src_configure() {
+	cros-workon_src_configure
+}
+
+src_install() {
+	insinto "${AUTOTEST_BASE}"
+	doins -r "${AUTOTEST_WORK}"/*
+	chmod a+x "${D}/${AUTOTEST_BASE}"/tko/*.cgi
+
+	dosym /var/log/autotest "${AUTOTEST_BASE}"/logs
+
+	insinto /etc/init
+	doins "${FILESDIR}"/*.conf
+}
+
+src_test() {
+	# Run the autotest unit tests.
+	./utils/unittest_suite.py --debug || die "Autotest unit tests failed."
+}
+
diff --git a/chromeos-base/autotest-server/files/autotest_setup.conf b/chromeos-base/autotest-server/files/autotest_setup.conf
index f3beb0b..69ac53a 100644
--- a/chromeos-base/autotest-server/files/autotest_setup.conf
+++ b/chromeos-base/autotest-server/files/autotest_setup.conf
@@ -11,7 +11,15 @@
   echo 0 > /proc/sys/kernel/hung_task_timeout_secs
   # TODO(sbasi) (crbug.com/345138) - Switch to running only after autoupdate
   # rather than every boot.
+
+  # M56 creates a logs directory that needs to be moved out of the way so
+  # the simlink to /var/log/autotest can be installed. crbug/709697
+  # TODO(haddowk) remove this check when no one could possibly do upgrade from
+  # M56
   AUTOTEST_DIR=/usr/local/autotest
+  if [ -d "${AUTOTEST_DIR}/logs" ]; then
+    mv "${AUTOTEST_DIR}/logs" "${AUTOTEST_DIR}/logs.$(date +%F_%R)"
+  fi
   rsync -a /autotest/ "${AUTOTEST_DIR}/"
 
   # If the shadow_config does no exist, create one.