Esempio n. 1
0
def fwrw_version_to_label(image):
    """
    Returns the proper label name for a RW firmware build of |image|.

    @param image: A string of the form 'lumpy-release/R28-3993.0.0'
    @returns: A string that is the appropriate label name.

    """
    warnings.warn('fwrw_version_to_label is deprecated', stacklevel=2)
    keyval_label = labellib.KeyvalLabel(Key.FIRMWARE_RW_VERSION, image)
    return labellib.format_keyval_label(keyval_label)
Esempio n. 2
0
 def test_format_keyval_label_with_colon_in_value(self):
     got = labellib.format_keyval_label(
             labellib.KeyvalLabel('pool', 'suites:penthouse'))
     self.assertEqual(got, 'pool:suites:penthouse')
Esempio n. 3
0
def perform_local_run(afe,
                      autotest_path,
                      tests,
                      remote,
                      fast_mode,
                      build=NO_BUILD,
                      board=NO_BOARD,
                      args=None,
                      pretend=False,
                      no_experimental=False,
                      ignore_deps=True,
                      results_directory=None,
                      ssh_verbosity=0,
                      ssh_options=None,
                      autoserv_verbose=False,
                      iterations=1,
                      host_attributes={}):
    """Perform local run of tests.

    This method enforces satisfaction of test dependencies for tests that are
    run as a part of a suite.

    @param afe: A direct_afe object used to interact with local afe database.
    @param autotest_path: Absolute path of autotest installed in sysroot or
                          custom autotest path set by --autotest_dir.
    @param tests: List of strings naming tests and suites to run. Suite strings
                  should be formed like "suite:smoke".
    @param remote: Remote hostname.
    @param fast_mode: bool to use fast mode (disables slow autotest features).
    @param build: String specifying build for local run.
    @param board: String specifyinb board for local run.
    @param args: String that should be passed as args parameter to autoserv,
                 and then ultimitely to test itself.
    @param pretend: If True, will print out autoserv commands rather than
                    running them.
    @param no_experimental: Skip experimental tests when scheduling a suite.
    @param ignore_deps: If True, test dependencies will be ignored.
    @param results_directory: Directory to store results in. Defaults to None,
                              in which case results will be stored in a new
                              subdirectory of /tmp
    @param ssh_verbosity: SSH verbosity level, passed through to
                          autoserv_utils.
    @param ssh_options: Additional ssh options to be passed to autoserv_utils
    @param autoserv_verbose: If true, pass the --verbose flag to autoserv.
    @param iterations: int number of times to schedule tests.
    @param host_attributes: Dict of host attributes to pass into autoserv.

    @returns: A list of return codes each job that has run. Or [1] if
              provision failed prior to running any jobs.
    """
    args = _set_default_servo_args(args)
    # Create host in afe, add board and build labels.
    cros_version_label = labellib.format_keyval_label(
        labellib.KeyvalLabel(labellib.Key.CROS_VERSION, build))

    build_label = afe.create_label(cros_version_label)
    board_label = afe.create_label(constants.BOARD_PREFIX + board)
    new_host = afe.create_host(remote)
    new_host.add_labels([build_label.name, board_label.name])
    if not ignore_deps:
        logging.info('Auto-detecting labels for %s', remote)
        _auto_detect_labels(afe, remote)
    # Provision the host to |build|.
    if build != NO_BUILD:
        logging.info('Provisioning %s...', cros_version_label)
        try:
            run_provisioning_job(cros_version_label, remote, autotest_path,
                                 results_directory, fast_mode, ssh_verbosity,
                                 ssh_options, pretend, autoserv_verbose)
        except TestThatProvisioningError as e:
            logging.error(
                'Provisioning %s to %s failed, tests are aborted, '
                'failure reason: %s', remote, cros_version_label, e)
            return [1]

    # Create suites that will be scheduled.
    suites_and_descriptions = []
    for test in tests:
        (predicate, description) = get_predicate_for_test_arg(test)
        logging.info('Fetching suite for %s...', description)
        suite = fetch_local_suite(autotest_path,
                                  predicate,
                                  afe,
                                  test_arg=test,
                                  remote=remote,
                                  build=build,
                                  board=board,
                                  results_directory=results_directory,
                                  no_experimental=no_experimental,
                                  ignore_deps=ignore_deps)
        suites_and_descriptions.append((suite, description))

    jobs_to_suites = {}
    null_logger = lambda log_entry, log_in_subdir=False: None
    # Schedule the suites, looping over iterations if necessary.
    for iteration in range(iterations):
        if iteration > 0:
            logging.info('Repeating scheduling for iteration %d:', iteration)

        for suite, description in suites_and_descriptions:
            logging.info('Scheduling suite for %s...', description)
            ntests = suite.schedule(null_logger)
            logging.debug(
                'jobs: %s nonzero job_retries: %s', len(suite._jobs_to_tests),
                len([True for (job_id, test) in suite._jobs_to_tests.items()]))
            logging.info('... scheduled %s job(s).', ntests)
            for job in suite.jobs:
                jobs_to_suites[job.id] = suite

    if not afe.get_jobs():
        logging.info('No jobs scheduled. End of local run.')
        return []

    last_job_id = afe.get_jobs()[-1].id
    job_id_digits = len(str(last_job_id))
    codes = []
    job_queue = afe.get_jobs()
    completed_job_ids = set()
    while job_queue:
        logging.info('%s jobs in job queue', len(job_queue))
        for job in job_queue:
            suite = jobs_to_suites.get(job.id)
            if not suite:
                logging.error('Job %s not run, no associated suite.', job.id)
            else:
                logging.debug('Running job %s of test %s', job.id,
                              suite.test_name_from_job(job.id))
                code, abs_dir = run_job(job, remote, autotest_path,
                                        results_directory, fast_mode,
                                        job_id_digits, ssh_verbosity,
                                        ssh_options, args, pretend,
                                        autoserv_verbose, host_attributes)
                codes.append(code)
                logging.debug("Code: %s, Results in %s", code, abs_dir)
                new_id = suite.handle_local_result(job.id, abs_dir,
                                                   null_logger)
                if new_id:
                    jobs_to_suites[new_id] = jobs_to_suites[job.id]
            completed_job_ids.add(job.id)
        all_jobs = afe.get_jobs(not_yet_run=True, running=True)
        new_jobs = set(job for job in all_jobs
                       if job.id not in completed_job_ids)
        logging.debug('%s incomplete jobs, %s jobs total', len(new_jobs),
                      len(all_jobs))
        job_queue = list(new_jobs)
    return codes
Esempio n. 4
0
 def test_format_keyval_label(self):
     got = labellib.format_keyval_label(
             labellib.KeyvalLabel('pool', 'suites'))
     self.assertEqual(got, 'pool:suites')