def _get_least_loaded_devserver(self, test_conf):
        """Find a devserver to use.

        We first try to pick a devserver with the least load. In case all
        devservers' load are higher than threshold, fall back to
        the old behavior by picking a devserver based on the payload URI,
        with which ImageServer.resolve will return a random devserver based on
        the hash of the URI. The picked devserver needs to respect the
        location of the host if 'prefer_local_devserver' is set to True or
        'restricted_subnets' is  set.

        @param test_conf: a dictionary of test settings.
        """
        hostname = self._host.hostname if self._host else None
        least_loaded_devserver = dev_server.get_least_loaded_devserver(
            hostname=hostname)
        if least_loaded_devserver:
            logging.debug('Choosing the least loaded devserver: %s',
                          least_loaded_devserver)
            autotest_devserver = dev_server.ImageServer(least_loaded_devserver)
        else:
            logging.warning('No devserver meets the maximum load requirement. '
                            'Picking a random devserver to use.')
            autotest_devserver = dev_server.ImageServer.resolve(
                test_conf['target_payload_uri'], self._host.hostname)
        devserver_hostname = urlparse.urlparse(
            autotest_devserver.url()).hostname

        logging.info('Devserver chosen for this run: %s', devserver_hostname)
        return autotest_devserver
Esempio n. 2
0
    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()
            ds_url, build = tools.get_devserver_build_from_package_url(
                self._job_repo_url)
            self._autotest_devserver = dev_server.ImageServer(ds_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]
Esempio n. 3
0
 def setUp(self):
     super(DevServerTest, self).setUp()
     self.crash_server = dev_server.CrashServer(DevServerTest._CRASH_HOST)
     self.dev_server = dev_server.ImageServer(DevServerTest._HOST)
     self.android_dev_server = dev_server.AndroidBuildServer(
         DevServerTest._HOST)
     self.mox.StubOutWithMock(urllib2, 'urlopen')
     # Hide local restricted_subnets setting.
     dev_server.RESTRICTED_SUBNETS = []
Esempio n. 4
0
    def setUp(self):
        """Setup."""
        super(SuiteTest, self).setUp()
        self.maxDiff = None
        self.use_batch = SuiteBase.ENABLE_CONTROLS_IN_BATCH
        SuiteBase.ENABLE_CONTROLS_IN_BATCH = False
        self.afe = self.mox.CreateMock(frontend.AFE)
        self.tko = self.mox.CreateMock(frontend.TKO)

        self.tmpdir = tempfile.mkdtemp(suffix=type(self).__name__)

        self.getter = self.mox.CreateMock(
            control_file_getter.ControlFileGetter)
        self.devserver = dev_server.ImageServer(self._DEVSERVER_HOST)

        self.files = OrderedDict([
            ('one',
             FakeControlData(self._TAG,
                             self._ATTR,
                             'data_one',
                             'FAST',
                             job_retries=None)),
            ('two',
             FakeControlData(self._TAG,
                             self._ATTR,
                             'data_two',
                             'SHORT',
                             dependencies=['feta'])),
            ('three',
             FakeControlData(self._TAG, self._ATTR, 'data_three', 'MEDIUM')),
            ('four',
             FakeControlData('other',
                             self._ATTR,
                             'data_four',
                             'LONG',
                             dependencies=['arugula'])),
            ('five',
             FakeControlData(self._TAG, {'other'},
                             'data_five',
                             'LONG',
                             dependencies=['arugula', 'caligula'])),
            ('six',
             FakeControlData(self._TAG, self._ATTR, 'data_six', 'LENGTHY')),
            ('seven',
             FakeControlData(self._TAG,
                             self._ATTR,
                             'data_seven',
                             'FAST',
                             job_retries=1))
        ])

        self.files_to_filter = {
            'with/deps/...':
            FakeControlData(self._TAG, self._ATTR, 'gets filtered'),
            'with/profilers/...':
            FakeControlData(self._TAG, self._ATTR, 'gets filtered')
        }
    def run_once(self, host, test_conf):
        """Performs a complete auto update test.

        @param host: a host object representing the DUT
        @param test_conf: a dictionary containing test configuration values

        @raise error.TestError if anything went wrong with setting up the test;
               error.TestFail if any part of the test has failed.
        """
        self._host = host
        logging.debug('The test configuration supplied: %s', test_conf)

        # Find a devserver to use. We first try to pick a devserver with the
        # least load. In case all devservers' load are higher than threshold,
        # fall back to the old behavior by picking a devserver based on the
        # payload URI, with which ImageServer.resolve will return a random
        # devserver based on the hash of the URI.
        # The picked devserver needs to respect the location of the host if
        # 'prefer_local_devserver' is set to True or 'restricted_subnets' is
        # set.
        hostname = self._host.hostname if self._host else None
        least_loaded_devserver = dev_server.get_least_loaded_devserver(
            hostname=hostname)
        if least_loaded_devserver:
            logging.debug('Choosing the least loaded devserver: %s',
                          least_loaded_devserver)
            autotest_devserver = dev_server.ImageServer(least_loaded_devserver)
        else:
            logging.warning('No devserver meets the maximum load requirement. '
                            'Picking a random devserver to use.')
            autotest_devserver = dev_server.ImageServer.resolve(
                test_conf['target_payload_uri'], host.hostname)
        devserver_hostname = urlparse.urlparse(
            autotest_devserver.url()).hostname

        logging.info('Devserver chosen for this run: %s', devserver_hostname)

        # Obtain a test platform implementation.
        test_platform = TestPlatform.create(host)
        test_platform.initialize(autotest_devserver, self.job.resultdir)

        # Stage source images and update payloads onto the devserver.
        staged_urls = test_platform.prep_artifacts(test_conf)
        self._source_image_installed = bool(staged_urls.source_url)

        # Prepare the DUT (install source version etc).
        test_platform.prep_device_for_update(test_conf['source_payload_uri'])

        # Start the update.
        try:
            self.run_update_test(test_platform, test_conf)
        except ExpectedUpdateEventChainFailed:
            self._dump_update_engine_log(test_platform)
            raise

        test_platform.check_device_after_update()
    def _get_latest_release_version_from_server(dut_board):
        """Gets the latest release version for a given board from a dev server.

        @param dut_board: A string representing the board of the remote host.

        @return: A string representing the release version.
        """
        build_target = dut_board + "-release"
        config = global_config.global_config
        server_url_list = config.get_config_value('CROS',
                                                  'dev_server',
                                                  type=list,
                                                  default=[])
        ds = dev_server.ImageServer(server_url_list[0])
        return ds.get_latest_build_in_server(build_target)
Esempio n. 7
0
def main():
    """Stage a build on the devserver."""
    options = parse_args()
    if options.server:
        server = 'http://%s/' % options.server
        ds = dev_server.ImageServer(server)
    else:
        ds = dev_server.ImageServer.resolve(options.build)

    print "Downloading %s..." % options.build
    ds.stage_artifacts(
        options.build,
        ['full_payload', 'stateful', 'control_files', 'autotest_packages'])
    if options.host:
        print "Poking job_repo_url on %s..." % options.host
        repo_url = tools.get_package_url(ds.url(), options.build)
        AFE = frontend.AFE()
        AFE.set_host_attribute('job_repo_url', repo_url, hostname=options.host)
Esempio n. 8
0
def main():
    """main script."""
    # Parse filepath from cmd line.
    parser = argparse.ArgumentParser(description='Create attribute whitelist.')
    parser.add_argument('path',
                        metavar='WHITELIST_FILE_PATH',
                        help='Path to the file whitelist is written to. E.g. '
                        './attribute_whitelist.txt')
    args = parser.parse_args()

    # Get all the suites from current test control files, and order them.
    fs_getter = Suite.create_fs_getter(common.autotest_dir)
    devserver = dev_server.ImageServer('')
    suite_list = Suite.list_all_suites('', devserver, fs_getter)
    suite_list.sort(key=str.lower)

    # Parse attributes from suites, and write to a file
    whitelist = ['suite:' + x for x in suite_list]
    _WriteToFile(whitelist, args.path)
Esempio n. 9
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)
Esempio n. 10
0
def list_image_dir_contents(update_url):
    """Lists the contents of the devserver for a given build/update_url.

    @param update_url: An update url. Eg: http://devserver:port/update/build.
    """
    if not update_url:
        logging.warning('Need update_url to list contents of the devserver.')
        return
    error_msg = 'Cannot check contents of devserver, update url %s' % update_url
    try:
        devserver_url, build = _get_devserver_build_from_update_url(update_url)
    except ValueError as e:
        logging.warning('%s: %s', error_msg, e)
        return
    devserver = dev_server.ImageServer(devserver_url)
    try:
        devserver.list_image_dir(build)
    # The devserver will retry on URLError to avoid flaky connections, but will
    # eventually raise the URLError if it persists. All HTTPErrors get
    # converted to DevServerExceptions.
    except (dev_server.DevServerException, urllib2.URLError) as e:
        logging.warning('%s: %s', error_msg, e)
def main():
    """Entry point to run the suite enumerator command."""
    parser, options, args = parse_options()
    if options.listall:
        if args:
            print 'Cannot use suite_name with --listall'
            parser.print_help()
    elif not args or len(args) != 1:
        parser.print_help()
        return

    fs_getter = Suite.create_fs_getter(options.autotest_dir)
    devserver = dev_server.ImageServer('')
    if options.listall:
        for suite in Suite.list_all_suites('', devserver, fs_getter):
            print suite
        return

    suite = Suite.create_from_name(args[0], {}, '', devserver, fs_getter)
    # If in test list, print firmware_FAFTSetup before other tests
    # NOTE: the test.name value can be *different* from the directory
    # name that appears in test.path
    PRETEST_LIST = [
        'firmware_FAFTSetup',
    ]
    for test in filter(lambda test: test.name in \
                              PRETEST_LIST, suite.stable_tests()):
        print test.path
    for test in filter(lambda test: test.name not in \
                       PRETEST_LIST, suite.stable_tests()):
        print test.path

    # Check if test_suites/control.suite_name exists.
    control_path = os.path.join(options.autotest_dir, 'test_suites',
                                'control.' + args[0])
    if not os.path.exists(control_path):
        print >> sys.stderr, ('Warning! control file is missing: %s' %
                              control_path)
Esempio n. 12
0
def fetch_local_suite(autotest_path,
                      suite_predicate,
                      afe,
                      test_arg,
                      remote,
                      build=NO_BUILD,
                      board=NO_BOARD,
                      results_directory=None,
                      no_experimental=False,
                      ignore_deps=True):
    """Create a suite from the given suite predicate.

    Satisfaction of dependencies is enforced by Suite.schedule() if
    ignore_deps is False. Note that this method assumes only one host,
    i.e. |remote|, was added to afe. Suite.schedule() will not
    schedule a job if none of the hosts in the afe (in our case,
    just one host |remote|) has a label that matches a requested
    test dependency.

    @param autotest_path: Absolute path to autotest (in sysroot or
                          custom autotest directory set by --autotest_dir).
    @param suite_predicate: callable that takes ControlData objects, and
                            returns True on those that should be in suite
    @param afe: afe object to schedule against (typically a directAFE)
    @param test_arg: String. An individual TEST command line argument, e.g.
                     'login_CryptohomeMounted' or 'suite:smoke'.
    @param remote: String representing the IP of the remote host.
    @param build: Build to schedule suite for.
    @param board: Board to schedule suite for.
    @param results_directory: Absolute path of directory to store results in.
                              (results will be stored in subdirectory of this).
    @param no_experimental: Skip experimental tests when scheduling a suite.
    @param ignore_deps: If True, test dependencies will be ignored.

    @returns: A LocalSuite object.

    """
    fs_getter = suite.create_fs_getter(autotest_path)
    devserver = dev_server.ImageServer('')
    my_suite = LocalSuite.create_from_predicates(
        [suite_predicate], {provision.CROS_VERSION_PREFIX: build},
        constants.BOARD_PREFIX + board,
        devserver,
        fs_getter,
        afe=afe,
        ignore_deps=ignore_deps,
        results_dir=results_directory,
        forgiving_parser=False,
        job_retry=True)
    if len(my_suite.tests) == 0:
        (similarity_predicate, similarity_description) = (
            get_predicate_for_possible_test_arg(test_arg))
        logging.error('No test found, searching for possible tests with %s',
                      similarity_description)
        possible_tests = suite.find_possible_tests(fs_getter,
                                                   similarity_predicate)
        raise ValueError('Found no tests. Check your suite name, test name, '
                         'or test matching wildcard.\nDid you mean any of '
                         'following tests?\n  %s' %
                         '\n  '.join(possible_tests))

    if not ignore_deps:
        # Log tests whose dependencies can't be satisfied.
        labels = [
            label.name for label in afe.get_labels(host__hostname=remote)
        ]
        for test in my_suite.tests:
            if test.experimental and no_experimental:
                continue
            unsatisfiable_deps = set(test.dependencies).difference(labels)
            if unsatisfiable_deps:
                logging.warning(
                    '%s will be skipped, unsatisfiable '
                    'test dependencies: %s', test.name, unsatisfiable_deps)
    return my_suite
Esempio n. 13
0
    def __init__(self,
                 build=None,
                 builds=None,
                 board=None,
                 name=None,
                 job=None,
                 pool=None,
                 num=None,
                 check_hosts=True,
                 add_experimental=True,
                 file_bugs=False,
                 file_experimental_bugs=False,
                 max_runtime_mins=24 * 60,
                 timeout=24,
                 timeout_mins=None,
                 firmware_reimage=False,
                 suite_dependencies=[],
                 version_prefix=None,
                 bug_template={},
                 devserver_url=None,
                 priority=priorities.Priority.DEFAULT,
                 predicate=None,
                 wait_for_results=True,
                 job_retry=False,
                 max_retries=None,
                 offload_failures_only=False,
                 test_source_build=None,
                 run_prod_code=False,
                 **dargs):
        """
        Vets arguments for reimage_and_run() and populates self with supplied
        values.

        TODO(dshi): crbug.com/496782 once R45 falls off stable channel, we
        should remove option build, firmware_reimage and version_prefix, as they
        will be all merged into option builds.

        Currently required args:
        @param board: which kind of devices to reimage.
        @param name: a value of the SUITE control file variable to search for.
        @param job: an instance of client.common_lib.base_job representing the
                    currently running suite job.
        @param devserver_url: url to the selected devserver.

        Currently supported optional args:
        @param build: the build to install e.g.
                      x86-alex-release/R18-1655.0.0-a1-b1584.
        @param builds: the builds to install e.g.
                       {'cros-version:': 'x86-alex-release/R18-1655.0.0',
                        'fw-version:':  'x86-alex-firmware/R36-5771.50.0'}
        @param test_source_build: Build that contains the server-side test code,
                e.g., it can be the value of builds['cros-version:'] or
                builds['fw-version:']. Default is None, that is, use
                the server-side test code from builds['cros-version:']
        @param pool: specify the pool of machines to use for scheduling purposes
                     Default: None
        @param num: the maximum number of devices to reimage.
                    Default in global_config
        @param check_hosts: require appropriate hosts to be available now.
        @param add_experimental: schedule experimental tests as well, or not.
                                 Default: True
        @param file_bugs: File bugs when tests in this suite fail.
                          Default: False
        @param file_experimental_bugs: File bugs when experimental tests in
                                       this suite fail.
                                       Default: False
        @param max_runtime_mins: Max runtime in mins for each of the sub-jobs
                                 this suite will run.
        @param timeout: Max lifetime in hours for each of the sub-jobs that
                        this suite run.
        @param firmware_reimage: True if we should use FW_RW_VERSION_PREFIX as
                                 the version_prefix.
                                 False if we should use CROS_VERSION_PREFIX as
                                 the version_prefix.
                                 (This flag has now been deprecated in favor of
                                  version_prefix.)
        @param suite_dependencies: A list of strings of suite level
                                   dependencies, which act just like test
                                   dependencies and are appended to each test's
                                   set of dependencies at job creation time.
                                   A string of comma seperated labels is
                                   accepted for backwards compatibility.
        @param bug_template: A template dictionary specifying the default bug
                             filing options for failures in this suite.
        @param version_prefix: A version prefix from provision.py that the
                               tests should be scheduled with.
        @param priority: Integer priority level.  Higher is more important.
        @param predicate: Optional argument. If present, should be a function
                          mapping ControlData objects to True if they should be
                          included in suite. If argument is absent, suite
                          behavior will default to creating a suite of based
                          on the SUITE field of control files.
        @param wait_for_results: Set to False to run the suite job without
                                 waiting for test jobs to finish. Default is
                                 True.
        @param job_retry: Set to True to enable job-level retry. Default is
                          False.
        @param max_retries: Maximum retry limit at suite level.
                            Regardless how many times each individual test
                            has been retried, the total number of retries
                            happening in the suite can't exceed _max_retries.
                            Default to None, no max.
        @param offload_failures_only: Only enable gs_offloading for failed
                                      jobs.
        @param run_prod_code: If true, the suite will run the test code that
                              lives in prod aka the test code currently on the
                              lab servers.
        @param **dargs: these arguments will be ignored.  This allows us to
                        deprecate and remove arguments in ToT while not
                        breaking branch builds.
        """
        # TODO(dshi): crbug.com/496782 Following should be added to
        # required_keywords after R45 falls off stable channel:
        # 'builds': dict,
        # To allow the transition, build is removed from the list, but the code
        # will check either build or builds should exist.
        required_keywords = {
            'board': str,
            'name': str,
            'job': base_job.base_job,
            'devserver_url': str
        }
        for key, expected in required_keywords.iteritems():
            value = locals().get(key)
            if not value or not isinstance(value, expected):
                raise error.SuiteArgumentException(
                    'reimage_and_run() needs %s=<%r>' % (key, expected))
        self._verify_builds(build, builds)

        self.board = 'board:%s' % board
        self.devserver = dev_server.ImageServer(devserver_url)

        if builds:
            self.builds = builds
        else:
            # TODO(dshi): crbug.com/496782 This warning can be removed after R45
            # falls off stable channel.
            logging.warning(
                'reimage_and_run arguments firmware_reimage and '
                'version_prefix have been deprecated. Please use '
                'a dictionary builds to specify images, e.g., '
                '{\'cros-version:\':\'peppy-release/R38-5655.0.0\','
                ' \'fw-version:\':\'peppy-firmware/R36-5371.0.0\'}')

            if version_prefix:
                prefix = version_prefix
            else:
                prefix = (provision.FW_RW_VERSION_PREFIX if firmware_reimage
                          else provision.CROS_VERSION_PREFIX)
            self.builds = {prefix: build}

        if provision.CROS_VERSION_PREFIX in self.builds:
            translated_build = self.devserver.translate(
                self.builds[provision.CROS_VERSION_PREFIX])
            self.builds[provision.CROS_VERSION_PREFIX] = translated_build

        if test_source_build:
            test_source_build = self.devserver.translate(test_source_build)

        self.test_source_build = Suite.get_test_source_build(
            self.builds, test_source_build=test_source_build)

        self.name = name
        self.job = job
        if pool:
            self.pool = 'pool:%s' % pool
        else:
            self.pool = pool
        self.num = num
        self.check_hosts = check_hosts
        self.skip_reimage = skip_reimage
        self.add_experimental = add_experimental
        self.file_bugs = file_bugs
        self.file_experimental_bugs = file_experimental_bugs
        self.dependencies = {'': []}
        self.max_runtime_mins = max_runtime_mins
        self.timeout = timeout
        self.timeout_mins = timeout_mins or timeout * 60
        if isinstance(suite_dependencies, str):
            self.suite_dependencies = [
                dep.strip(' ') for dep in suite_dependencies.split(',')
            ]
        else:
            self.suite_dependencies = suite_dependencies
        self.bug_template = bug_template
        self.priority = priority
        self.predicate = predicate
        self.wait_for_results = wait_for_results
        self.job_retry = job_retry
        self.max_retries = max_retries
        self.offload_failures_only = offload_failures_only
        self.run_prod_code = run_prod_code
Esempio n. 14
0
def main(argv):
    """Load generator for a devserver."""
    parser = get_parser()
    options = parser.parse_args(argv)

    # Parse devserver.
    if options.server:
        if re.match(r'^https?://', options.server):
            server = options.server
        else:
            server = 'http://%s/' % options.server
        ds = dev_server.ImageServer(server)
    else:
        parser.print_usage()
        logging.error('Must specify devserver')
        sys.exit(1)

    # Parse config file and determine master list of duts and their board type,
    # filtering by board type if specified.
    duts = {}
    if options.config:
        with open(options.config, 'r') as f:
            config = json.load(f)
            boards = (options.boards.split(',')
                      if options.boards else config.keys())
            duts_specified = (set(options.duts.split(','))
                              if options.duts else None)
            for board in boards:
                duts.update({
                    dut: board
                    for dut in config[board]['duts']
                    if duts_specified is None or dut in duts_specified
                })
        logging.info('Config file %s: %d boards, %d duts', options.config,
                     len(boards), len(duts))
    else:
        parser.print_usage()
        logging.error('Must specify config file')
        sys.exit(1)

    if options.ping:
        logging.info('Performing ping tests')
        duts_alive = {}
        for dut, board in duts.items():
            if ping_dut(dut):
                duts_alive[dut] = board
            else:
                logging.error(
                    'Ignoring DUT %s (%s) for failing initial '
                    'ping check', dut, board)
        duts = duts_alive
        logging.info('After ping tests: %d boards, %d duts', len(boards),
                     len(duts))

    # Set up the test runner and stage all the builds.
    outputlog = open(options.outputlog, 'a') if options.outputlog else None
    runner = Runner(ds,
                    duts,
                    config,
                    simultaneous=options.simultaneous,
                    total=options.total,
                    outputlog=outputlog,
                    ping=options.ping,
                    blacklist_consecutive=options.blacklist_consecutive,
                    blacklist_success=options.blacklist_success,
                    blacklist_total=options.blacklist_total,
                    dryrun=options.dryrun)
    if options.stage:
        runner.stage_all()

    # Run all the provisions.
    with locking.FileLock(options.config, blocking=True).lock():
        completed = runner.loop()
    logging.info('%s in %s', 'Completed' if completed else 'Interrupted',
                 runner.elapsed())
    # Write all entries as JSON.
    entries = runner.get_completed_entries()
    if options.output:
        with open(options.output, 'w') as f:
            dump_entries_as_json(entries, f)
    else:
        dump_entries_as_json(entries, sys.stdout)
    logging.info(
        'Summary: %s',
        dict(
            collections.Counter(
                [e['status'] for e in entries if e['name'] != 'Runner'])))

    # List blacklisted DUTs.
    if runner.dut_blacklist:
        logging.warn('Blacklisted DUTs:')
        for host_name in runner.dut_blacklist:
            logging.warn('  %s', host_name)
Esempio n. 15
0
 def _init_devserver(self, devserver_url):
     """Initialize devserver attribute."""
     self.devserver = dev_server.ImageServer(devserver_url)
    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()
 def _init_devserver(self, devserver_url):
     """Initialize devserver attribute."""
     if provision.ANDROID_BUILD_VERSION_PREFIX in self.builds:
         self.devserver = dev_server.AndroidBuildServer(devserver_url)
     else:
         self.devserver = dev_server.ImageServer(devserver_url)