def setUp(self):
     """Set up test."""
     super(AndroidBuildClientTest, self).setUp()
     self.Patch(android_build_client.AndroidBuildClient,
                "InitResourceHandle")
     self.client = android_build_client.AndroidBuildClient(mock.MagicMock())
     self.client._service = mock.MagicMock()
def DownloadRemoteArtifact(cfg,
                           build_target,
                           build_id,
                           artifact,
                           extract_path,
                           decompress=False):
    """Download remote artifact.

    Args:
        cfg: An AcloudConfig instance.
        build_target: String, the build target, e.g. cf_x86_phone-userdebug.
        build_id: String, Build id, e.g. "2263051", "P2804227"
        artifact: String, zip image or cvd host package artifact.
        extract_path: String, a path include extracted files.
        decompress: Boolean, if true decompress the artifact.
    """
    build_client = android_build_client.AndroidBuildClient(
        auth.CreateCredentials(cfg))
    temp_file = os.path.join(extract_path, artifact)
    build_client.DownloadArtifact(build_target, build_id, artifact, temp_file)
    if decompress:
        utils.Decompress(temp_file, extract_path)
        try:
            os.remove(temp_file)
            logger.debug("Deleted temporary file %s", temp_file)
        except OSError as e:
            logger.error("Failed to delete temporary file: %s", str(e))
Beispiel #3
0
 def __init__(self, cfg, devices=None):
     self._devices = devices or []
     self._cfg = cfg
     credentials = auth.CreateCredentials(cfg)
     self._build_client = android_build_client.AndroidBuildClient(
         credentials)
     self._storage_client = gstorage_client.StorageClient(credentials)
     self._compute_client = android_compute_client.AndroidComputeClient(
         cfg, credentials)
Beispiel #4
0
    def __init__(self,
                 cfg,
                 build_target,
                 build_id,
                 emulator_build_target,
                 emulator_build_id,
                 kernel_build_id=None,
                 kernel_branch=None,
                 kernel_build_target=None,
                 gpu=None,
                 avd_spec=None,
                 tags=None,
                 branch=None,
                 emulator_branch=None):
        """Initialize.

        Args:
            cfg: An AcloudConfig instance.
            build_target: String, the build target, e.g. aosp_x86-eng.
            build_id: String, Build id, e.g. "2263051", "P2804227"
            emulator_build_target: String, the emulator build target, e.g. aosp_x86-eng.
            emulator_build_id: String, emulator build id.
            gpu: String, GPU to attach to the device or None. e.g. "nvidia-tesla-k80"
            avd_spec: An AVDSpec instance.
            tags: A list of tags to associate with the instance. e.g.
                  ["http-server", "https-server"]
            branch: String, branch of the emulator build target.
            emulator_branch: String, branch of the emulator.
        """

        self.credentials = auth.CreateCredentials(cfg)

        compute_client = goldfish_compute_client.GoldfishComputeClient(
            cfg, self.credentials)
        super(GoldfishDeviceFactory, self).__init__(compute_client)

        # Private creation parameters
        self._cfg = cfg
        self._gpu = gpu
        self._avd_spec = avd_spec
        self._blank_data_disk_size_gb = cfg.extra_data_disk_size_gb
        self._extra_scopes = cfg.extra_scopes
        self._tags = tags

        # Configure clients
        self._build_client = android_build_client.AndroidBuildClient(
            self.credentials)

        # Get build info
        self.build_info = self._build_client.GetBuildInfo(
            build_target, build_id, branch)
        self.emulator_build_info = self._build_client.GetBuildInfo(
            emulator_build_target, emulator_build_id, emulator_branch)
        self.kernel_build_info = self._build_client.GetBuildInfo(
            kernel_build_target or cfg.kernel_build_target, kernel_build_id,
            kernel_branch)
    def _ProcessRemoteBuildArgs(self, args):
        """Get the remote build args.

        Some of the acloud magic happens here, we will infer some of these
        values if the user hasn't specified them.

        Args:
            args: Namespace object from argparse.parse_args.
        """
        self._remote_image = {}
        self._remote_image[constants.BUILD_BRANCH] = args.branch
        if not self._remote_image[constants.BUILD_BRANCH]:
            self._remote_image[constants.BUILD_BRANCH] = self._GetBuildBranch(
                args.build_id, args.build_target)

        self._remote_image[constants.BUILD_TARGET] = args.build_target
        if not self._remote_image[constants.BUILD_TARGET]:
            self._remote_image[constants.BUILD_TARGET] = self._GetBuildTarget(
                args)
        else:
            # If flavor isn't specified, try to infer it from build target,
            # if we can't, just default to phone flavor.
            self._flavor = args.flavor or self._GetFlavorFromString(
                self._remote_image[
                    constants.BUILD_TARGET]) or constants.FLAVOR_PHONE
            # infer avd_type from build_target.
            for avd_type, avd_type_abbr in constants.AVD_TYPES_MAPPING.items():
                if re.match(r"(.*_)?%s_" % avd_type_abbr,
                            self._remote_image[constants.BUILD_TARGET]):
                    self._avd_type = avd_type
                    break

        self._remote_image[constants.BUILD_ID] = args.build_id
        if not self._remote_image[constants.BUILD_ID]:
            build_client = android_build_client.AndroidBuildClient(
                auth.CreateCredentials(self._cfg))

            self._remote_image[constants.BUILD_ID] = build_client.GetLKGB(
                self._remote_image[constants.BUILD_TARGET],
                self._remote_image[constants.BUILD_BRANCH])

        self._remote_image[constants.CHEEPS_BETTY_IMAGE] = (
            args.cheeps_betty_image)

        # Process system image and kernel image.
        self._system_build_info = {
            constants.BUILD_ID: args.system_build_id,
            constants.BUILD_BRANCH: args.system_branch,
            constants.BUILD_TARGET: args.system_build_target
        }
        self._kernel_build_info = {
            constants.BUILD_ID: args.kernel_build_id,
            constants.BUILD_BRANCH: args.kernel_branch,
            constants.BUILD_TARGET: args.kernel_build_target
        }
Beispiel #6
0
    def __init__(self,
                 cfg,
                 build_target,
                 build_id,
                 branch=None,
                 kernel_build_id=None,
                 kernel_branch=None,
                 kernel_build_target=None,
                 system_branch=None,
                 system_build_id=None,
                 system_build_target=None,
                 boot_timeout_secs=None,
                 ins_timeout_secs=None,
                 report_internal_ip=None,
                 gpu=None):

        self.credentials = auth.CreateCredentials(cfg)

        if cfg.enable_multi_stage:
            compute_client = cvd_compute_client_multi_stage.CvdComputeClient(
                cfg, self.credentials, boot_timeout_secs, ins_timeout_secs,
                report_internal_ip, gpu)
        else:
            compute_client = cvd_compute_client.CvdComputeClient(
                cfg, self.credentials)
        super(CuttlefishDeviceFactory, self).__init__(compute_client)

        # Private creation parameters
        self._cfg = cfg
        self._build_target = build_target
        self._build_id = build_id
        self._branch = branch
        self._kernel_build_id = kernel_build_id
        self._blank_data_disk_size_gb = cfg.extra_data_disk_size_gb
        self._extra_scopes = cfg.extra_scopes

        # Configure clients for interaction with GCE/Build servers
        self._build_client = android_build_client.AndroidBuildClient(
            self.credentials)

        # Get build_info namedtuple for platform, kernel, system build
        self.build_info = self._build_client.GetBuildInfo(
            build_target, build_id, branch)
        self.kernel_build_info = self._build_client.GetBuildInfo(
            kernel_build_target or cfg.kernel_build_target, kernel_build_id,
            kernel_branch)
        self.system_build_info = self._build_client.GetBuildInfo(
            system_build_target or build_target, system_build_id,
            system_branch)
    def _GetBuildBranch(self, build_id, build_target):
        """Infer build branch if user didn't specify branch name.

        Args:
            build_id: String, Build id, e.g. "2263051", "P2804227"
            build_target: String, the build target, e.g. cf_x86_phone-userdebug

        Returns:
            String, name of build branch.
        """
        # Infer branch from build_target and build_id
        if build_id and build_target:
            build_client = android_build_client.AndroidBuildClient(
                auth.CreateCredentials(self._cfg))
            return build_client.GetBranch(build_target, build_id)

        return self._GetBranchFromRepo()
Beispiel #8
0
    def __init__(self,
                 acloud_config,
                 oauth2_credentials,
                 boot_timeout_secs=None,
                 ins_timeout_secs=None,
                 report_internal_ip=None,
                 gpu=None):
        """Initialize.

        Args:
            acloud_config: An AcloudConfig object.
            oauth2_credentials: An oauth2client.OAuth2Credentials instance.
            boot_timeout_secs: Integer, the maximum time to wait for the AVD
                               to boot up.
            ins_timeout_secs: Integer, the maximum time to wait for the
                              instance ready.
            report_internal_ip: Boolean to report the internal ip instead of
                                external ip.
            gpu: String, GPU to attach to the device.
        """
        super(CvdComputeClient, self).__init__(acloud_config,
                                               oauth2_credentials)

        self._fetch_cvd_version = acloud_config.fetch_cvd_version
        self._build_api = (
            android_build_client.AndroidBuildClient(oauth2_credentials))
        self._ssh_private_key_path = acloud_config.ssh_private_key_path
        self._boot_timeout_secs = boot_timeout_secs
        self._ins_timeout_secs = ins_timeout_secs
        self._report_internal_ip = report_internal_ip
        self._gpu = gpu
        # Store all failures result when creating one or multiple instances.
        self._all_failures = dict()
        self._extra_args_ssh_tunnel = acloud_config.extra_args_ssh_tunnel
        self._ssh = None
        self._ip = None
        self._user = constants.GCE_USER
        self._stage = constants.STAGE_INIT
        self._execution_time = {
            _FETCH_ARTIFACT: 0,
            _GCE_CREATE: 0,
            _LAUNCH_CVD: 0
        }
Beispiel #9
0
def _FetchBuildIdFromFile(cfg, build_target, build_id, filename):
    """Parse and fetch build id from a file based on a pattern.

    Verify if one of the system image or emulator binary build id is missing.
    If found missing, then update according to the resource file.

    Args:
        cfg: An AcloudConfig instance.
        build_target: Target name.
        build_id: Build id, a string, e.g. "2263051", "P2804227"
        filename: Name of file containing the build info.

    Returns:
        A build id or None
    """
    build_client = android_build_client.AndroidBuildClient(
        auth.CreateCredentials(cfg))

    with utils.TempDir() as tempdir:
        temp_filename = os.path.join(tempdir, filename)
        build_client.DownloadArtifact(build_target, build_id, filename,
                                      temp_filename)

        return ParseBuildInfo(temp_filename)