aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Chiu <samchiu@google.com>2020-02-15 13:28:55 +0000
committerSam Chiu <samchiu@google.com>2020-02-15 13:28:55 +0000
commit1036d637ef54ea5923a3a5bf6ff2c08b2af6fd2d (patch)
treee5037e36b2bcd00dc7744f848ebd4a13c7cc93a0
parent655a8107616897c392549c92a8f3e25af49a8bde (diff)
parent07644f03cec849096c7c9a9e8f805579e10d5a61 (diff)
downloadacloud-1036d637ef54ea5923a3a5bf6ff2c08b2af6fd2d.tar.gz
Merge "Install cuttlefish-common from github." am: 07644f03ce
Change-Id: Idacdca83ca49c450c8133dede83074e482fa074f
-rw-r--r--setup/host_setup_runner.py63
-rw-r--r--setup/host_setup_runner_test.py35
-rw-r--r--setup/setup.py2
3 files changed, 90 insertions, 10 deletions
diff --git a/setup/host_setup_runner.py b/setup/host_setup_runner.py
index a334c2c0..9a668e5e 100644
--- a/setup/host_setup_runner.py
+++ b/setup/host_setup_runner.py
@@ -23,7 +23,10 @@ from __future__ import print_function
import getpass
import logging
+import os
+import shutil
import sys
+import tempfile
from acloud.internal import constants
from acloud.internal.lib import utils
@@ -33,17 +36,20 @@ from acloud.setup import setup_common
logger = logging.getLogger(__name__)
-# Install cuttlefish-common will probably not work now.
-# TODO: update this to pull from the proper repo.
-_AVD_REQUIRED_PKGS = ["cuttlefish-common",
- # TODO(b/117613492): This is all qemu related, take this
- # out once they are added back in as deps for
- # cuttlefish-common.
- "qemu-kvm", "qemu-system-common", "qemu-system-x86",
- "qemu-utils", "libvirt-clients", "libvirt-daemon-system"]
+# Packages "devscripts" and "equivs" are required for "mk-build-deps".
+_AVD_REQUIRED_PKGS = [
+ "devscripts", "equivs", "libvirt-clients", "libvirt-daemon-system"]
_BASE_REQUIRED_PKGS = ["ssvnc", "lzop"]
+_CUTTLEFISH_COMMOM_PKG = "cuttlefish-common"
+_CF_COMMOM_FOLDER = "cf-common"
_LIST_OF_MODULES = ["kvm_intel", "kvm"]
_UPDATE_APT_GET_CMD = "sudo apt-get update"
+_INSTALL_CUTTLEFISH_COMMOM_CMD = [
+ "git clone https://github.com/google/android-cuttlefish.git {git_folder}",
+ "cd {git_folder}",
+ "yes | sudo mk-build-deps -i -r -B",
+ "dpkg-buildpackage -uc -us",
+ "sudo apt-get install -y -f ../cuttlefish-common_*_amd64.deb"]
class BasePkgInstaller(base_task_runner.BaseTaskRunner):
@@ -109,6 +115,47 @@ class HostBasePkgInstaller(BasePkgInstaller):
PACKAGES = _BASE_REQUIRED_PKGS
+class CuttlefishCommonPkgInstaller(base_task_runner.BaseTaskRunner):
+ """Subtask base runner class for installing cuttlefish-common."""
+
+ WELCOME_MESSAGE_TITLE = "Install cuttlefish-common packages on the host"
+ WELCOME_MESSAGE = ("This step will walk you through the cuttlefish-common "
+ "packages installation for your host.")
+
+ def ShouldRun(self):
+ """Check if cuttlefish-common package is installed.
+
+ Returns:
+ Boolean, True if cuttlefish-common is not installed.
+ """
+ if not utils.IsSupportedPlatform():
+ return False
+
+ # Any required package is not installed or not up-to-date will need to
+ # run installation task.
+ if not setup_common.PackageInstalled(_CUTTLEFISH_COMMOM_PKG):
+ return True
+ return False
+
+ def _Run(self):
+ """Install cuttlefilsh-common packages."""
+ cf_common_path = os.path.join(tempfile.mkdtemp(), _CF_COMMOM_FOLDER)
+ logger.debug("cuttlefish-common path: %s", cf_common_path)
+ cmd = "\n".join(sub_cmd.format(git_folder=cf_common_path)
+ for sub_cmd in _INSTALL_CUTTLEFISH_COMMOM_CMD)
+
+ if not utils.GetUserAnswerYes("\nStart to install cuttlefish-common :\n%s"
+ "\nPress 'y' to continue or anything "
+ "else to do it myself and run acloud "
+ "again[y/N]: " % cmd):
+ sys.exit(constants.EXIT_BY_USER)
+ try:
+ setup_common.CheckCmdOutput(cmd, shell=True)
+ finally:
+ shutil.rmtree(os.path.dirname(cf_common_path))
+ logger.info("Cuttlefish-common package installed now.")
+
+
class CuttlefishHostSetup(base_task_runner.BaseTaskRunner):
"""Subtask class that setup host for cuttlefish."""
diff --git a/setup/host_setup_runner_test.py b/setup/host_setup_runner_test.py
index b424db57..111540e2 100644
--- a/setup/host_setup_runner_test.py
+++ b/setup/host_setup_runner_test.py
@@ -13,13 +13,17 @@
# limitations under the License.
"""Tests for host_setup_runner."""
import platform
+import shutil
+import tempfile
import unittest
+import mock
from acloud.internal.lib import driver_test_lib
from acloud.internal.lib import utils
from acloud.setup import setup_common
-from acloud.setup.host_setup_runner import CuttlefishHostSetup
from acloud.setup.host_setup_runner import AvdPkgInstaller
+from acloud.setup.host_setup_runner import CuttlefishCommonPkgInstaller
+from acloud.setup.host_setup_runner import CuttlefishHostSetup
class CuttlefishHostSetupTest(driver_test_lib.BaseDriverTest):
@@ -85,9 +89,36 @@ class AvdPkgInstallerTest(driver_test_lib.BaseDriverTest):
def testShouldNotRun(self):
"""Test ShoudRun should raise error in non-linux os."""
self.Patch(platform, "system", return_value="Mac")
-
self.assertFalse(self.AvdPkgInstaller.ShouldRun())
+class CuttlefishCommonPkgInstallerTest(driver_test_lib.BaseDriverTest):
+ """Test CuttlefishCommonPkgInstallerTest."""
+
+ # pylint: disable=invalid-name
+ def setUp(self):
+ """Set up the test."""
+ super(CuttlefishCommonPkgInstallerTest, self).setUp()
+ self.CuttlefishCommonPkgInstaller = CuttlefishCommonPkgInstaller()
+
+ def testShouldRun(self):
+ """Test ShoudRun."""
+ self.Patch(platform, "system", return_value="Linux")
+ self.Patch(setup_common, "PackageInstalled", return_value=False)
+ self.assertTrue(self.CuttlefishCommonPkgInstaller.ShouldRun())
+
+ @mock.patch.object(shutil, "rmtree")
+ @mock.patch.object(setup_common, "CheckCmdOutput")
+ def testRun(self, mock_cmd, mock_rmtree):
+ """Test Run."""
+ fake_tmp_folder = "/tmp/cf-common"
+ self.Patch(tempfile, "mkdtemp", return_value=fake_tmp_folder)
+ self.Patch(utils, "GetUserAnswerYes", return_value="y")
+ self.Patch(CuttlefishCommonPkgInstaller, "ShouldRun", return_value=True)
+ self.CuttlefishCommonPkgInstaller.Run()
+ self.assertEqual(mock_cmd.call_count, 1)
+ mock_rmtree.assert_called_once_with(fake_tmp_folder)
+
+
if __name__ == "__main__":
unittest.main()
diff --git a/setup/setup.py b/setup/setup.py
index 36b6ffd9..39513dc4 100644
--- a/setup/setup.py
+++ b/setup/setup.py
@@ -48,6 +48,7 @@ def Run(args):
# 2.Init all subtasks in queue and traverse them.
host_base_runner = host_setup_runner.HostBasePkgInstaller()
host_avd_runner = host_setup_runner.AvdPkgInstaller()
+ host_cf_common_runner = host_setup_runner.CuttlefishCommonPkgInstaller()
host_env_runner = host_setup_runner.CuttlefishHostSetup()
gcp_runner = gcp_setup_runner.GcpTaskRunner(args.config_file)
task_queue = []
@@ -55,6 +56,7 @@ def Run(args):
if args.host:
task_queue.append(host_base_runner)
task_queue.append(host_avd_runner)
+ task_queue.append(host_cf_common_runner)
task_queue.append(host_env_runner)
# We should do these setup tasks if specified or if no args were used.
if args.host_base or (not args.host and not args.gcp_init):