def _get_payload_url(self, build=None, full_payload=True):
        """
        Gets the GStorage URL of the full or delta payload for this build.

        @param build: build string e.g samus-release/R65-10225.0.0.
        @param full_payload: True for full payload. False for delta.

        @returns the payload URL.

        """
        if build is None:
            if self._job_repo_url is None:
                self._job_repo_url = self._get_job_repo_url()
            _, build = tools.get_devserver_build_from_package_url(
                self._job_repo_url)

        gs = dev_server._get_image_storage_server()
        if full_payload:
            # Example: chromeos_R65-10225.0.0_samus_full_dev.bin
            regex = 'chromeos_%s*_full_*' % build.rpartition('/')[2]
        else:
            # Example: chromeos_R65-10225.0.0_R65-10225.0.0_samus_delta_dev.bin
            regex = 'chromeos_%s*_delta_*' % build.rpartition('/')[2]
        payload_url_regex = gs + build + '/' + regex
        logging.debug('Trying to find payloads at %s', payload_url_regex)
        payloads = utils.gs_ls(payload_url_regex)
        if not payloads:
            raise error.TestFail('Could not find payload for %s', build)
        logging.debug('Payloads found: %s', payloads)
        return payloads[0]
    def _get_build_from_job_repo_url(self, host):
        """
        Gets the build string from a hosts job_repo_url.

        @param host: Object representing host.

        """
        info = host.host_info_store.get()
        repo_url = info.attributes.get(host.job_repo_url_attribute, '')
        if not repo_url:
            raise error.TestFail('There was no job_repo_url for %s so we '
                                 'cant get a payload to use.' % host.hostname)
        return tools.get_devserver_build_from_package_url(repo_url)
Beispiel #3
0
def get_updater_from_repo_url(host, job_repo_url=None):
    """Returns the autoupdater instance to use for a given autoupdate test.

    All server-side tests that run in the lab have an associated job_repo_url
    assigned to their host that is associated with the version of the build that
    is currently installed on them. Given most autoupdate tests need to
    update to some build as part of the test, we conveniently re-update to the
    same version installed. This method serves as a helper to get the
    instantiated autoupdater instance for that build.

    This method guarantees that the devserver associated with the autoupdater
    has already staged the necessary files for autoupdate.

    @param host: The host for the DUT of the server-side test.
    @param job_repo_url: If set, the job_repo_url to use.

    @raise error.TestError: If we fail to get a job_repo_url.
    """
    # Get the job_repo_url -- if not present, attempt to use the one
    # specified in the host attributes for the host.
    if not job_repo_url:
        try:
            job_repo_url = host.lookup_job_repo_url()
        except KeyError:
            logging.fatal('Could not lookup job_repo_url from afe.')

        if not job_repo_url:
            raise error.TestError(
                'Could not find a job_repo_url for the given host.')

    # Get the devserver url and build (image) from the repo url e.g.
    # 'http://mydevserver:8080', 'x86-alex-release/R27-123.0.0'
    ds_url, build = tools.get_devserver_build_from_package_url(job_repo_url)
    devserver = dev_server.ImageServer(ds_url)
    devserver.stage_artifacts(build, ['full_payload', 'stateful'])

    # We only need to update stateful to do this test.
    return autoupdater.ChromiumOSUpdater(devserver.get_update_url(build),
                                         host=host)
    def stage_server_side_package(self, image=None):
        """Stage autotest server-side package on devserver.

        @param image: Full path of an OS image to install or a build name.

        @return: A url to the autotest server-side package.

        @raise: error.AutoservError if fail to locate the build to test with, or
                fail to stage server-side package.
        """
        if image:
            image_name = tools.get_build_from_image(image)
            if not image_name:
                raise error.AutoservError(
                    'Failed to parse build name from %s' % image)
            ds = dev_server.ImageServer.resolve(image_name)
        else:
            job_repo_url = afe_utils.get_host_attribute(
                self, ds_constants.JOB_REPO_URL)
            if job_repo_url:
                devserver_url, image_name = (
                    tools.get_devserver_build_from_package_url(job_repo_url))
                ds = dev_server.ImageServer.resolve(image_name)
            else:
                labels = afe_utils.get_labels(self, self.VERSION_PREFIX)
                if not labels:
                    raise error.AutoservError(
                        'Failed to stage server-side package. The host has '
                        'no job_report_url attribute or version label.')
                image_name = labels[0][len(self.VERSION_PREFIX + ':'):]
                ds = dev_server.ImageServer.resolve(image_name)

        ds.stage_artifacts(image_name, ['autotest_server_package'],
                           archive_url=ARCHIVE_URL + image_name)
        return '%s/static/%s/%s' % (ds.url(), image_name,
                                    'autotest_server_package.tar.bz2')
    def get_update_url_for_test(self,
                                job_repo_url,
                                full_payload=True,
                                critical_update=False,
                                max_updates=1,
                                cellular=False):
        """
        Get the correct update URL for autoupdate tests to use.

        There are bunch of different update configurations that are required
        by AU tests. Some tests need a full payload, some need a delta payload.
        Some require the omaha response to be critical or be able to handle
        multiple DUTs etc. This function returns the correct update URL to the
        test based on the inputs parameters.

        Ideally all updates would use an existing lab devserver to handle the
        updates. However the lab devservers default setup does not work for
        all test needs. So we also kick off our own omaha_devserver for the
        test run some times.

        This tests expects the test to set self._host or self._hosts.

        @param job_repo_url: string url containing the current build.
        @param full_payload: bool whether we want a full payload.
        @param critical_update: bool whether we need a critical update.
        @param max_updates: int number of updates the test will perform. This
                            is passed to src/platform/dev/devserver.py if we
                            create our own deverver.
        @param cellular: update will be done over cellular connection.

        @returns an update url string.

        """
        if job_repo_url is None:
            self._job_repo_url = self._get_job_repo_url()
        else:
            self._job_repo_url = job_repo_url
        if not self._job_repo_url:
            raise error.TestFail('There was no job_repo_url so we cannot get '
                                 'a payload to use.')
        ds_url, build = tools.get_devserver_build_from_package_url(
            self._job_repo_url)

        # We always stage the payloads on the existing lab devservers.
        self._autotest_devserver = dev_server.ImageServer(ds_url)

        if cellular:
            # Get the google storage url of the payload. We will be copying
            # the payload to a public google storage bucket (similar location
            # to updates via autest command).
            payload_url = self._get_payload_url(build,
                                                full_payload=full_payload)
            return self._copy_payload_to_public_bucket(payload_url)

        if full_payload:
            self._autotest_devserver.stage_artifacts(build, ['full_payload'])
            if not critical_update:
                # We can use the same lab devserver to handle the update.
                return self._autotest_devserver.get_update_url(build)
            else:
                staged_url = self._autotest_devserver._get_image_url(build)
        else:
            # We need to stage delta ourselves due to crbug.com/793434.
            delta_payload = self._get_payload_url(build, full_payload=False)
            staged_url = self._stage_payload_by_uri(delta_payload)

        # We need to start our own devserver for the rest of the cases.
        self._omaha_devserver = omaha_devserver.OmahaDevserver(
            self._autotest_devserver.hostname,
            staged_url,
            max_updates=max_updates,
            critical_update=critical_update)
        self._omaha_devserver.start_devserver()
        return self._omaha_devserver.get_update_url()