def testCreateDevicesWithAdbPort(self):
     """Test Create Devices with adb port for cuttlefish avd type."""
     self.Patch(utils, "_ExecuteCommand")
     self.Patch(utils, "PickFreePort", return_value=56789)
     self.Patch(shlex, "split", return_value=[])
     cfg = self._CreateCfg()
     _report = common_operations.CreateDevices(self.CMD, cfg,
                                               self.device_factory, 1,
                                               "cuttlefish",
                                               autoconnect=True,
                                               client_adb_port=12345)
     self.assertEqual(_report.command, self.CMD)
     self.assertEqual(_report.status, report.Status.SUCCESS)
     self.assertEqual(
         _report.data,
         {"devices": [{
             "ip": self.IP.external,
             "instance_name": self.INSTANCE,
             "branch": self.BRANCH,
             "build_id": self.BUILD_ID,
             "adb_port": 12345,
             "vnc_port": 56789,
             "build_target": self.BUILD_TARGET,
             "gcs_bucket_build_id": self.BUILD_ID,
         }]})
Exemple #2
0
    def _CreateAVD(self, avd_spec, no_prompts):
        """Create the AVD.

        Args:
            avd_spec: AVDSpec object that tells us what we're going to create.
            no_prompts: Boolean, True to skip all prompts.

        Returns:
            A Report instance.
        """
        device_factory = remote_instance_cf_device_factory.RemoteInstanceDeviceFactory(
            avd_spec,
            avd_spec.local_image_artifact,
            create_common.GetCvdHostPackage())
        report = common_operations.CreateDevices(
            "create_cf", avd_spec.cfg, device_factory, num=1,
            report_internal_ip=avd_spec.report_internal_ip,
            autoconnect=avd_spec.autoconnect,
            avd_type=constants.TYPE_CF,
            boot_timeout_secs=avd_spec.boot_timeout_secs,
            unlock_screen=avd_spec.unlock_screen,
            wait_for_boot=False,
            connect_webrtc=avd_spec.connect_webrtc)
        # Launch vnc client if we're auto-connecting.
        if avd_spec.connect_vnc:
            utils.LaunchVNCFromReport(report, avd_spec, no_prompts)
        return report
Exemple #3
0
    def _CreateAVD(self, avd_spec, no_prompts):
        """Create the AVD.

        Args:
            avd_spec: AVDSpec object that tells us what we're going to create.
            no_prompts: Boolean, True to skip all prompts.

        Returns:
            A Report instance.
        """
        logger.info("Creating a cheeps device in project %s, build_id: %s",
                    avd_spec.cfg.project,
                    avd_spec.remote_image[constants.BUILD_ID])

        device_factory = CheepsDeviceFactory(avd_spec.cfg, avd_spec)

        report = common_operations.CreateDevices(
            command="create_cheeps",
            cfg=avd_spec.cfg,
            device_factory=device_factory,
            num=avd_spec.num,
            report_internal_ip=avd_spec.report_internal_ip,
            autoconnect=avd_spec.autoconnect,
            avd_type=constants.TYPE_CHEEPS,
            client_adb_port=avd_spec.client_adb_port,
            boot_timeout_secs=avd_spec.boot_timeout_secs)

        # Launch vnc client if we're auto-connecting.
        if avd_spec.connect_vnc:
            utils.LaunchVNCFromReport(report, avd_spec, no_prompts)

        return report
 def testCreateDevices(self):
     """Test Create Devices."""
     cfg = self._CreateCfg()
     _report = common_operations.CreateDevices(self.CMD, cfg,
                                               self.device_factory, 1,
                                               self.AVD_TYPE)
     self.assertEqual(_report.command, self.CMD)
     self.assertEqual(_report.status, report.Status.SUCCESS)
     self.assertEqual(
         _report.data,
         {"devices": [{
             "ip": self.IP.external,
             "instance_name": self.INSTANCE,
             "branch": self.BRANCH,
             "build_id": self.BUILD_ID,
             "build_target": self.BUILD_TARGET,
             "gcs_bucket_build_id": self.BUILD_ID,
         }]})
Exemple #5
0
def CreateDevices(avd_spec=None,
                  cfg=None,
                  build_target=None,
                  build_id=None,
                  emulator_build_id=None,
                  emulator_branch=None,
                  kernel_build_id=None,
                  kernel_branch=None,
                  kernel_build_target=None,
                  gpu=None,
                  num=1,
                  serial_log_file=None,
                  autoconnect=False,
                  branch=None,
                  tags=None,
                  report_internal_ip=False,
                  boot_timeout_secs=None):
    """Create one or multiple Goldfish devices.

    Args:
        avd_spec: An AVDSpec instance.
        cfg: An AcloudConfig instance.
        build_target: String, the build target, e.g. aosp_x86-eng.
        build_id: String, Build id, e.g. "2263051", "P2804227"
        branch: String, Branch name for system image.
        emulator_build_id: String, emulator build id.
        emulator_branch: String, Emulator branch name.
        gpu: String, GPU to attach to the device or None. e.g. "nvidia-k80"
        kernel_build_id: Kernel build id, a string.
        kernel_branch: Kernel branch name, a string.
        kernel_build_target: Kernel build artifact, a string.
        num: Integer, Number of devices to create.
        serial_log_file: String, A path to a file where serial output should
                        be saved to.
        autoconnect: Boolean, Create ssh tunnel(s) and adb connect after device
                     creation.
        branch: String, Branch name for system image.
        tags: A list of tags to associate with the instance. e.g.
              ["http-server", "https-server"]
        report_internal_ip: Boolean to report the internal ip instead of
                            external ip.
        boot_timeout_secs: Integer, the maximum time in seconds used to
                           wait for the AVD to boot.

    Returns:
        A Report instance.
    """
    client_adb_port = None
    if avd_spec:
        cfg = avd_spec.cfg
        build_target = avd_spec.remote_image[constants.BUILD_TARGET]
        build_id = avd_spec.remote_image[constants.BUILD_ID]
        branch = avd_spec.remote_image[constants.BUILD_BRANCH]
        num = avd_spec.num
        emulator_build_id = avd_spec.emulator_build_id
        gpu = avd_spec.gpu
        serial_log_file = avd_spec.serial_log_file
        autoconnect = avd_spec.autoconnect
        report_internal_ip = avd_spec.report_internal_ip
        client_adb_port = avd_spec.client_adb_port
        boot_timeout_secs = avd_spec.boot_timeout_secs

    # If emulator_build_id and emulator_branch is None, retrieve emulator
    # build id from platform build emulator-info.txt artifact
    # Example: require version-emulator=5292001
    if not emulator_build_id and not emulator_branch:
        logger.info(
            "emulator_build_id not provided. "
            "Try to get %s from build %s/%s.", _EMULATOR_INFO_FILENAME,
            build_id, build_target)
        emulator_build_id = _FetchBuildIdFromFile(cfg, build_target, build_id,
                                                  _EMULATOR_INFO_FILENAME)

    if not emulator_build_id:
        raise errors.CommandArgError("Emulator build id not found "
                                     "in %s" % _EMULATOR_INFO_FILENAME)

    # If build_id and branch is None, retrieve build_id from
    # emulator build android-info.txt artifact
    # Example: version-sysimage-git_pi-dev-sdk_gphone_x86_64-userdebug=4833817
    if not build_id and not branch:
        build_id = _FetchBuildIdFromFile(cfg, cfg.emulator_build_target,
                                         emulator_build_id,
                                         _SYSIMAGE_INFO_FILENAME)

    if not build_id:
        raise errors.CommandArgError(
            "Emulator system image build id not found "
            "in %s" % _SYSIMAGE_INFO_FILENAME)
    logger.info(
        "Creating a goldfish device in project %s, build_target: %s, "
        "build_id: %s, emulator_bid: %s, kernel_build_id: %s, "
        "kernel_branch: %s, kernel_build_target: %s, GPU: %s, num: %s, "
        "serial_log_file: %s, "
        "autoconnect: %s", cfg.project, build_target, build_id,
        emulator_build_id, kernel_build_id, kernel_branch, kernel_build_target,
        gpu, num, serial_log_file, autoconnect)

    device_factory = GoldfishDeviceFactory(
        cfg,
        build_target,
        build_id,
        cfg.emulator_build_target,
        emulator_build_id,
        gpu=gpu,
        avd_spec=avd_spec,
        tags=tags,
        branch=branch,
        emulator_branch=emulator_branch,
        kernel_build_id=kernel_build_id,
        kernel_branch=kernel_branch,
        kernel_build_target=kernel_build_target)

    return common_operations.CreateDevices("create_gf", cfg, device_factory,
                                           num, constants.TYPE_GF,
                                           report_internal_ip, autoconnect,
                                           serial_log_file, client_adb_port,
                                           boot_timeout_secs)
Exemple #6
0
def CreateDevices(cfg,
                  build_target=None,
                  build_id=None,
                  branch=None,
                  kernel_build_id=None,
                  kernel_branch=None,
                  kernel_build_target=None,
                  system_branch=None,
                  system_build_id=None,
                  system_build_target=None,
                  gpu=None,
                  num=1,
                  serial_log_file=None,
                  autoconnect=False,
                  report_internal_ip=False,
                  boot_timeout_secs=None,
                  ins_timeout_secs=None):
    """Create one or multiple Cuttlefish devices.

    Args:
        cfg: An AcloudConfig instance.
        build_target: String, Target name.
        build_id: String, Build id, e.g. "2263051", "P2804227"
        branch: Branch name, a string, e.g. aosp_master
        kernel_build_id: String, Kernel build id.
        kernel_branch: String, Kernel branch name.
        kernel_build_target: String, Kernel build target name.
        system_branch: Branch name to consume the system.img from, a string.
        system_build_id: System branch build id, a string.
        system_build_target: System image build target, a string.
        gpu: String, GPU to attach to the device or None. e.g. "nvidia-tesla-k80"
        num: Integer, Number of devices to create.
        serial_log_file: String, A path to a tar file where serial output should
                         be saved to.
        autoconnect: Boolean, Create ssh tunnel(s) and adb connect after device
                     creation.
        report_internal_ip: Boolean to report the internal ip instead of
                            external ip.
        boot_timeout_secs: Integer, the maximum time in seconds used to wait
                           for the AVD to boot.
        ins_timeout_secs: Integer, the maximum time in seconds used to wait for
                          the instance ready.

    Returns:
        A Report instance.
    """
    client_adb_port = None
    unlock_screen = False
    wait_for_boot = True
    logger.info(
        "Creating a cuttlefish device in project %s, "
        "build_target: %s, "
        "build_id: %s, "
        "branch: %s, "
        "kernel_build_id: %s, "
        "kernel_branch: %s, "
        "kernel_build_target: %s, "
        "system_branch: %s, "
        "system_build_id: %s, "
        "system_build_target: %s, "
        "gpu: %s"
        "num: %s, "
        "serial_log_file: %s, "
        "autoconnect: %s, "
        "report_internal_ip: %s", cfg.project, build_target,
        build_id, branch, kernel_build_id, kernel_branch, kernel_build_target,
        system_branch, system_build_id, system_build_target, gpu, num,
        serial_log_file, autoconnect, report_internal_ip)
    # If multi_stage enable, launch_cvd don't write serial log to instance. So
    # it doesn't go WaitForBoot function.
    if cfg.enable_multi_stage:
        wait_for_boot = False
    device_factory = CuttlefishDeviceFactory(
        cfg, build_target, build_id, branch=branch,
        kernel_build_id=kernel_build_id, kernel_branch=kernel_branch,
        kernel_build_target=kernel_build_target, system_branch=system_branch,
        system_build_id=system_build_id,
        system_build_target=system_build_target,
        boot_timeout_secs=boot_timeout_secs,
        ins_timeout_secs=ins_timeout_secs,
        report_internal_ip=report_internal_ip,
        gpu=gpu)
    return common_operations.CreateDevices("create_cf", cfg, device_factory,
                                           num, constants.TYPE_CF,
                                           report_internal_ip, autoconnect,
                                           serial_log_file, client_adb_port,
                                           boot_timeout_secs, unlock_screen,
                                           wait_for_boot)