コード例 #1
0
def main(argv):
    """
    Standard main routine.

    @param argv  Command line arguments including `sys.argv[0]`.
    """
    arguments = _parse_command_line(argv)
    afe = frontend_wrappers.RetryingAFE(server=None)
    updater = arguments.updater_mode(afe)
    updater.announce()
    boards = (set(arguments.extra_boards)
              | lab_inventory.get_managed_boards(afe))

    cros_version_map = updater.select_version_map(afe.CROS_IMAGE_TYPE)
    cros_versions = cros_version_map.get_all_versions()
    omaha_versions = _make_omaha_versions(_read_gs_json_data(_OMAHA_STATUS))
    upgrade_versions, new_default = (_get_upgrade_versions(
        cros_versions, omaha_versions, boards))
    _apply_cros_upgrades(updater, cros_versions, upgrade_versions, new_default)

    updater.report('\nApplying firmware updates:')
    firmware_version_map = updater.select_version_map(afe.FIRMWARE_IMAGE_TYPE)
    fw_versions = firmware_version_map.get_all_versions()
    firmware_upgrades = _get_firmware_upgrades(cros_version_map,
                                               upgrade_versions)
    _apply_firmware_upgrades(updater, fw_versions, firmware_upgrades)
コード例 #2
0
    def _execute_add_one_host(self, host):
        # Always add the hosts as locked to avoid the host
        # being picked up by the scheduler before it's ACL'ed.
        self.data['locked'] = True
        if not self.locked:
            self.data['lock_reason'] = 'Forced lock on device creation'
        self.execute_rpc('add_host',
                         hostname=host,
                         status="Ready",
                         **self.data)
        # If there are labels avaliable for host, use them.
        host_info = self.host_info_map[host]
        labels = set(self.labels)
        if host_info.labels:
            labels.update(host_info.labels)
        # Now add the platform label.
        # If a platform was not provided and we were able to retrieve it
        # from the host, use the retrieved platform.
        platform = self.platform if self.platform else host_info.platform
        if platform:
            labels.add(platform)

        if len(labels):
            self.execute_rpc('host_add_labels', id=host, labels=list(labels))

        if self.serials:
            afe = frontend_wrappers.RetryingAFE(timeout_min=5, delay_sec=10)
            afe.set_host_attribute('serials',
                                   ','.join(self.serials),
                                   hostname=host)
コード例 #3
0
    def _get_fetch_location_from_host_attribute(self):
        """Get repo to use for packages from host attribute, if possible.

        Hosts are tagged with an attribute containing the URL
        from which to source packages when running a test on that host.
        If self.host is set, attempt to look this attribute up by calling out
        to the AFE.

        @returns value of the 'job_repo_url' host attribute, if present.
        """
        try:
            from autotest_lib.server.cros.dynamic_suite import frontend_wrappers
            if self.host:
                afe = frontend_wrappers.RetryingAFE(timeout_min=5,
                                                    delay_sec=10)
                hosts = afe.get_hosts(hostname=self.host.hostname)
                if hosts and JOB_REPO_URL in hosts[0].attributes:
                    logging.info('Get job repo url from host attributes: %s',
                                 hosts[0].attributes[JOB_REPO_URL])
                    return hosts[0].attributes[JOB_REPO_URL]
                logging.warning("No %s for %s", JOB_REPO_URL, self.host)
        except (ImportError, urllib2.URLError):
            logging.warning('Not attempting to look for %s', JOB_REPO_URL)
            pass
        return None
コード例 #4
0
ファイル: dynamic_suite.py プロジェクト: AOSP8146/external
def run_provision_suite(**dargs):
    """
    Run a provision suite.

    Will re-image a number of devices (of the specified board) with the
    provided builds by scheduling dummy_Pass.

    @param job: an instance of client.common_lib.base_job representing the
                currently running suite job.

    @raises AsynchronousBuildFailure: if there was an issue finishing staging
                                      from the devserver.
    @raises MalformedDependenciesException: if the dependency_info file for
                                            the required build fails to parse.
    """
    spec = _SuiteSpec(**dargs)

    afe = frontend_wrappers.RetryingAFE(timeout_min=30,
                                        delay_sec=10,
                                        user=spec.job.user,
                                        debug=False)
    tko = frontend_wrappers.RetryingTKO(timeout_min=30,
                                        delay_sec=10,
                                        user=spec.job.user,
                                        debug=False)

    try:
        my_job_id = int(tko_utils.get_afe_job_id(spec.job.tag))
        logging.debug('Determined own job id: %d', my_job_id)
    except ValueError:
        my_job_id = None
        logging.warning('Could not determine own job id.')

    suite = ProvisionSuite(tag=spec.name,
                           builds=spec.builds,
                           board=spec.board,
                           devserver=spec.devserver,
                           count=1,
                           afe=afe,
                           tko=tko,
                           pool=spec.pool,
                           results_dir=spec.job.resultdir,
                           max_runtime_mins=spec.max_runtime_mins,
                           timeout_mins=spec.timeout_mins,
                           file_bugs=spec.file_bugs,
                           suite_job_id=my_job_id,
                           extra_deps=spec.suite_dependencies,
                           priority=spec.priority,
                           wait_for_results=spec.wait_for_results,
                           job_retry=spec.job_retry,
                           max_retries=spec.max_retries,
                           offload_failures_only=spec.offload_failures_only,
                           test_source_build=spec.test_source_build,
                           run_prod_code=spec.run_prod_code,
                           job_keyvals=spec.job_keyvals,
                           test_args=spec.test_args)

    _run_suite_with_spec(suite, spec)

    logging.debug('Returning from dynamic_suite.run_provision_suite')
コード例 #5
0
def is_server_in_prod(server_name, afe):
    """Validate server's role and status.

    @param server_name: the server name to be validated.
    @param afe: the afe server to get role & status info in server_db.

    @return: A boolean value, True when the server_name is in prod, False
             otherwise, or if RPC fails.
    """
    logging.info('Validating server: %s', server_name)
    afe = frontend_wrappers.RetryingAFE(timeout_min=5,
                                        delay_sec=10,
                                        server=afe)
    is_prod_proxy_server = False
    try:
        if afe.run('get_servers',
                   hostname=server_name,
                   status='primary',
                   role='golo_proxy'):
            is_prod_proxy_server = True

    except urllib2.URLError as e:
        logging.warning('RPC get_servers failed on afe %s: %s', afe, str(e))
    finally:
        metrics.Counter(metrics_template % 'server_in_prod_check').increment(
            fields={'success': is_prod_proxy_server})
        return is_prod_proxy_server
コード例 #6
0
def main(argv):
    """Standard main() for command line processing.

    @param argv Command line arguments (normally sys.argv).
    """

    parser = GetParser()
    options = parser.parse_args(argv[1:])

    with ts_mon_config.SetupTsMonGlobalState('dump_suite_report'):

        afe = frontend_wrappers.RetryingAFE(timeout_min=5,
                                            delay_sec=10,
                                            server=options.afe)
        tko = frontend_wrappers.RetryingTKO(timeout_min=5, delay_sec=10)

        # Look up and generate entries for all jobs.
        entries = []
        for suite_job_id in options.job_ids:
            logging.debug('Suite job %s:' % suite_job_id)
            suite_entries = suite_report.generate_suite_report(suite_job_id,
                                                               afe=afe,
                                                               tko=tko)
            logging.debug('... generated %d entries' % len(suite_entries))
            entries.extend(suite_entries)

        # Write all entries as JSON.
        if options.output:
            with open(options.output, 'w') as f:
                suite_report.dump_entries_as_json(entries, f)
        else:
            suite_report.dump_entries_as_json(entries, sys.stdout)
コード例 #7
0
    def update_labels(self, host):
        """
        Retrieve the labels from the host and update if needed.

        @param host: The host to update the labels for.
        """
        # If we haven't yet grabbed our list of known labels, do so now.
        if not self.label_full_names and not self.label_prefix_names:
            self._populate_known_labels(self._labels)

        afe = frontend_wrappers.RetryingAFE(timeout_min=5, delay_sec=10)
        old_labels = set(host._afe_host.labels)
        logging.info('existing labels: %s', old_labels)
        known_labels = set([l for l in old_labels
                            if self._is_known_label(l)])
        new_labels = set(self.get_labels(host))

        # TODO(pprabhu) Replace this update logic using AfeHostInfoBackend.
        # Remove old labels.
        labels_to_remove = list(old_labels & (known_labels - new_labels))
        if labels_to_remove:
            logging.info('removing labels: %s', labels_to_remove)
            afe.run('host_remove_labels', id=host.hostname,
                    labels=labels_to_remove)

        # Add in new labels that aren't already there.
        labels_to_add = list(new_labels - old_labels)
        if labels_to_add:
            logging.info('adding labels: %s', labels_to_add)
            afe.run('host_add_labels', id=host.hostname, labels=labels_to_add)
コード例 #8
0
def reimage_and_run(**dargs):
    """
    Backward-compatible API for dynamic_suite.

    Will re-image a number of devices (of the specified board) with the
    provided builds, and then run the indicated test suite on them.
    Guaranteed to be compatible with any build from stable to dev.

    @param dargs: Dictionary containing the arguments passed to _SuiteSpec().
    @raises AsynchronousBuildFailure: if there was an issue finishing staging
                                      from the devserver.
    @raises MalformedDependenciesException: if the dependency_info file for
                                            the required build fails to parse.
    """
    suite_spec = _SuiteSpec(**dargs)

    afe = frontend_wrappers.RetryingAFE(timeout_min=30, delay_sec=10,
                                        user=suite_spec.job.user, debug=False)
    tko = frontend_wrappers.RetryingTKO(timeout_min=30, delay_sec=10,
                                        user=suite_spec.job.user, debug=False)

    try:
        my_job_id = int(tko_utils.get_afe_job_id(dargs['job'].tag))
        logging.debug('Determined own job id: %d', my_job_id)
    except ValueError:
        my_job_id = None
        logging.warning('Could not determine own job id.')

    _perform_reimage_and_run(suite_spec, afe, tko, suite_job_id=my_job_id)

    logging.debug('Returning from dynamic_suite.reimage_and_run.')
コード例 #9
0
 def __init__(self, global_afe_hostname, shard_hostname, tick_pause_sec):
     self.afe = frontend_wrappers.RetryingAFE(server=global_afe_hostname,
                                              timeout_min=RPC_TIMEOUT_MIN,
                                              delay_sec=RPC_DELAY_SEC)
     self.hostname = shard_hostname
     self.tick_pause_sec = tick_pause_sec
     self._shutdown = False
     self._shard = None
コード例 #10
0
def create_chameleon_host(dut, chameleon_args):
    """Create a ChameleonHost object.

    There three possible cases:
    1) If the DUT is in Cros Lab and has a chameleon board, then create
       a ChameleonHost object pointing to the board. chameleon_args
       is ignored.
    2) If not case 1) and chameleon_args is neither None nor empty, then
       create a ChameleonHost object using chameleon_args.
    3) If neither case 1) or 2) applies, return None.

    @param dut: host name of the host that chameleon connects. It can be used
                to lookup the chameleon in test lab using naming convention.
                If dut is an IP address, it can not be used to lookup the
                chameleon in test lab.
    @param chameleon_args: A dictionary that contains args for creating
                           a ChameleonHost object,
                           e.g. {'chameleon_host': '172.11.11.112',
                                 'chameleon_port': 9992}.

    @returns: A ChameleonHost object or None.

    """
    if not utils.is_in_container():
        is_moblab = utils.is_moblab()
    else:
        is_moblab = _CONFIG.get_config_value('SSP',
                                             'is_moblab',
                                             type=bool,
                                             default=False)

    if not is_moblab:
        dut_is_hostname = not dnsname_mangler.is_ip_address(dut)
        if dut_is_hostname:
            chameleon_hostname = chameleon.make_chameleon_hostname(dut)
            if utils.host_is_in_lab_zone(chameleon_hostname):
                # Be more tolerant on chameleon in the lab because
                # we don't want dead chameleon blocks non-chameleon tests.
                if utils.ping(chameleon_hostname, deadline=3):
                    logging.warning(
                        'Chameleon %s is not accessible. Please file a bug'
                        ' to test lab', chameleon_hostname)
                    return None
                return ChameleonHost(chameleon_host=chameleon_hostname)
        if chameleon_args:
            return ChameleonHost(**chameleon_args)
        else:
            return None
    else:
        afe = frontend_wrappers.RetryingAFE(timeout_min=5, delay_sec=10)
        hosts = afe.get_hosts(hostname=dut)
        if hosts and CHAMELEON_HOST_ATTR in hosts[0].attributes:
            return ChameleonHost(
                chameleon_host=hosts[0].attributes[CHAMELEON_HOST_ATTR],
                chameleon_port=hosts[0].attributes.get(CHAMELEON_PORT_ATTR,
                                                       9992))
        else:
            return None
コード例 #11
0
def main(argv):
    """Standard main routine.
    @param argv  Command line arguments including `sys.argv[0]`.
    """
    arguments = _parse_command(argv)
    if not arguments:
        sys.exit(1)
    _configure_logging(arguments)
    try:
        end_time = int(time.time())
        start_time = end_time - arguments.duration * 60 * 60
        timestamp = time.strftime('%Y-%m-%d.%H',
                                  time.localtime(end_time))
        logging.debug('Starting lab inventory for %s', timestamp)
        if arguments.board_notify:
            if arguments.recommend:
                logging.debug('Will include repair recommendations')
            logging.debug('Will include board inventory')
        if arguments.pool_notify:
            logging.debug('Will include pool inventory')

        afe = frontend_wrappers.RetryingAFE(server=None)
        inventory = _LabInventory.create_inventory(
                afe, start_time, end_time, arguments.boardnames)
        logging.info('Found %d hosts across %d boards',
                         inventory.get_num_duts(),
                         inventory.get_num_boards())

        if arguments.debug:
            _populate_board_counts(inventory)

        if arguments.board_notify:
            if arguments.recommend:
                recommend_message = _generate_repair_recommendation(
                        inventory, arguments.recommend) + '\n\n\n'
            else:
                recommend_message = ''
            board_message = _generate_board_inventory_message(inventory)
            _send_email(arguments,
                        'boards-%s.txt' % timestamp,
                        'DUT board inventory %s' % timestamp,
                        arguments.board_notify,
                        recommend_message + board_message)

        if arguments.pool_notify:
            pool_message = _generate_pool_inventory_message(inventory)
            idle_message = _generate_idle_inventory_message(inventory)
            _send_email(arguments,
                        'pools-%s.txt' % timestamp,
                        'DUT pool inventory %s' % timestamp,
                        arguments.pool_notify,
                        pool_message + '\n\n\n' + idle_message)
    except KeyboardInterrupt:
        pass
    except EnvironmentError as e:
        logging.exception('Unexpected OS error: %s', e)
    except Exception as e:
        logging.exception('Unexpected exception: %s', e)
コード例 #12
0
 def _needs_synchronized_reboot(self):
     """Does this servohost need synchronized reboot across multiple DUTs"""
     # TODO(pprabhu) Use HostInfo in this check instead of hitting AFE.
     afe = frontend_wrappers.RetryingAFE(
         timeout_min=5,
         delay_sec=10,
         server=server_utils.get_global_afe_hostname())
     dut_list = self.get_attached_duts(afe)
     return len(dut_list) > 1
コード例 #13
0
    def __init__(self, afe=None, file_bug=False):
        """Constructor

        @param afe: an instance of AFE as defined in server/frontend.py.
                    Defaults to a frontend_wrappers.RetryingAFE instance.
        """
        self._afe = afe or frontend_wrappers.RetryingAFE(timeout_min=30,
                                                         delay_sec=10,
                                                         debug=False)
        self._file_bug = file_bug
コード例 #14
0
 def repair(self, host):
     if host.is_localhost() or not host.is_cros_host():
         raise hosts.AutoservRepairError(
             'Target servo is not a test lab servo')
     host.update_image(wait_for_update=True)
     afe = frontend_wrappers.RetryingAFE(timeout_min=5, delay_sec=10)
     dut_list = host.get_attached_duts(afe)
     if len(dut_list) > 1:
         host.schedule_synchronized_reboot(dut_list, afe, force_reboot=True)
     else:
         super(_ServoRebootRepair, self).repair(host)
コード例 #15
0
    def __init__(self, afe=None):
        """
        Constructor

        @param afe: an instance of AFE as defined in server/frontend.py.
        """
        self._afe = afe or frontend_wrappers.RetryingAFE(
            timeout_min=30,
            delay_sec=10,
            debug=False,
            server=site_utils.get_global_afe_hostname())
        # Keep track of hosts locked by this instance.
        self._locked_hosts = set()
コード例 #16
0
def _create_inventory(arguments, end_time):
    """Create the `_LabInventory` instance to use for reporting.

    @param end_time   A UNIX timestamp for the end of the time range
                      to be searched in this inventory run.
    """
    start_time = end_time - arguments.duration * 60 * 60
    afe = frontend_wrappers.RetryingAFE(server=None)
    inventory = _LabInventory.create_inventory(afe, start_time, end_time,
                                               arguments.modelnames)
    logging.info('Found %d hosts across %d models', inventory.get_num_duts(),
                 inventory.get_num_models())
    return inventory
コード例 #17
0
 def __init__(self, hostname, afe=None):
     """
     @param hostname: The name of the host for which we want to track host
             information.
     @param afe: A frontend.AFE object to make RPC calls. Will create one
             internally if None.
     """
     super(AfeStore, self).__init__()
     self._hostname = hostname
     self._afe = afe
     if self._afe is None:
         self._afe = frontend_wrappers.RetryingAFE(
             timeout_min=self._RETRYING_AFE_TIMEOUT_MIN,
             delay_sec=self._RETRYING_AFE_RETRY_DELAY_SEC)
コード例 #18
0
def _assign_stable_images(arguments):
    afe = frontend_wrappers.RetryingAFE(server=arguments.web)
    updater = _VersionUpdater(afe, dry_run=arguments.dry_run)

    cros_versions = updater.select_version_map(afe.CROS_IMAGE_TYPE)
    omaha_versions = build_data.get_omaha_version_map()
    upgrade_versions, new_default = (_get_upgrade_versions(
        cros_versions, omaha_versions, lab_inventory.get_managed_boards(afe)))
    _apply_cros_upgrades(updater, cros_versions, upgrade_versions, new_default)

    logging.info('Applying firmware updates.')
    fw_versions = updater.select_version_map(afe.FIRMWARE_IMAGE_TYPE)
    firmware_upgrades = _get_firmware_upgrades(upgrade_versions)
    _apply_firmware_upgrades(updater, fw_versions, firmware_upgrades)
コード例 #19
0
 def repair(self, host):
     if host.is_localhost() or not host.is_cros_host():
         raise hosts.AutoservRepairError(
             'Target servo is not a test lab servo',
             'servo_not_applicable_to_host_outside_lab')
     host.update_image(wait_for_update=True)
     afe = frontend_wrappers.RetryingAFE(timeout_min=5, delay_sec=10)
     dut_list = host.get_attached_duts(afe)
     if len(dut_list) > 1:
         raise hosts.AutoservRepairError(
             'Repairing labstation with > 1 host not supported.'
             ' See crbug.com/843358',
             'can_not_repair_labstation_with_multiple_hosts')
     else:
         super(_ServoRebootRepair, self).repair(host)
コード例 #20
0
 def _initialize(self, *args, **dargs):
     super(MoblabHost, self)._initialize(*args, **dargs)
     # Clear the Moblab Image Storage so that staging an image is properly
     # tested.
     if dargs.get('retain_image_storage') is not True:
         self.run('rm -rf %s/*' % MOBLAB_IMAGE_STORAGE)
     self._dhcpd_leasefile = None
     self.web_address = dargs.get('web_address', self.hostname)
     timeout_min = dargs.get('rpc_timeout_min', 1)
     self.afe = frontend_wrappers.RetryingAFE(timeout_min=timeout_min,
                                              user='******',
                                              server=self.web_address)
     self.tko = frontend_wrappers.RetryingTKO(timeout_min=timeout_min,
                                              user='******',
                                              server=self.web_address)
コード例 #21
0
    def schedule(self, job, timeout_mins, machine):
        """
        Sequence a job on the running AFE.

        Will schedule a given test on the job machine(s).
        Support a subset of tests:
        - server job
        - no hostless.
        - no cleanup around tests.

        @param job: server_job object that will server as parent.
        @param timeout_mins: timeout to set up: if the test last more than
           timeout_mins, the test will fail.
        @param machine: machine to run the test on.

        @returns a maximal time in minutes that the sequence can take.
        """
        afe = frontend_wrappers.RetryingAFE(timeout_min=30, delay_sec=10,
                                            user=job.user, debug=False)
        # job_directores.get_job_id_or_task_id() will return a non-int opaque id
        # for Chrome OS Skylab tasks. But sequences will break in that case
        # anyway, because they try to create AFE jobs internally.
        current_job_id = int(
                job_directories.get_job_id_or_task_id(job.resultdir))
        logging.debug('Current job id: %s', current_job_id)
        runtime_mins = self.child_job_timeout()
        hostname = utils.get_hostname_from_machine(machine)

        for i in xrange(0, self._iteration):
            child_job_name = self.child_job_name(hostname, i)
            logging.debug('Creating job: %s', child_job_name)
            afe.create_job(
                    self.child_control_file(),
                    name=child_job_name,
                    priority=priorities.Priority.DEFAULT,
                    control_type=control_data.CONTROL_TYPE.SERVER,
                    hosts=[hostname], meta_hosts=(), one_time_hosts=(),
                    synch_count=None, is_template=False,
                    timeout_mins=timeout_mins + (i + 1) * runtime_mins,
                    max_runtime_mins=runtime_mins,
                    run_verify=False, email_list='', dependencies=(),
                    reboot_before=None, reboot_after=None,
                    parse_failed_repair=None,
                    hostless=False, keyvals=None,
                    drone_set=None, image=None,
                    parent_job_id=current_job_id, test_retry=0, run_reset=False,
                    require_ssp=utils.is_in_container())
        return runtime_mins * self._iteration
コード例 #22
0
def run_rpc_on_multiple_hostnames(rpc_call, shard_hostnames, **kwargs):
    """Runs an rpc to multiple AFEs

    This is i.e. used to propagate changes made to hosts after they are assigned
    to a shard.

    @param rpc_call: Name of the rpc endpoint to call.
    @param shard_hostnames: List of hostnames to run the rpcs on.
    @param **kwargs: Keyword arguments to pass in the rpcs.
    """
    # Make sure this function is not called on shards but only on master.
    assert not server_utils.is_shard()
    for shard_hostname in shard_hostnames:
        afe = frontend_wrappers.RetryingAFE(server=shard_hostname,
                                            user=thread_local.get_user())
        afe.run(rpc_call, **kwargs)
コード例 #23
0
    def replacement(*args, **kwargs):
        """We need special handling when decorating an RPC that can be called
        directly using positional arguments.

        One example is rpc_interface.create_job().
        rpc_interface.create_job_page_handler() calls the function using both
        positional and keyword arguments.  Since frontend.RpcClient.run()
        takes only keyword arguments for an RPC, positional arguments of the
        RPC function need to be transformed into keyword arguments.
        """
        kwargs = _convert_to_kwargs_only(func, args, kwargs)
        if server_utils.is_shard():
            afe = frontend_wrappers.RetryingAFE(
                server=server_utils.get_global_afe_hostname(),
                user=thread_local.get_user())
            return afe.run(func.func_name, **kwargs)
        return func(**kwargs)
コード例 #24
0
    def wait_afe_up(self, timeout_min=5):
        """Wait till the AFE is up and loaded.

        Attempt to reach the Moblab's AFE and database through its RPC
        interface.

        @param timeout_min: Minutes to wait for the AFE to respond. Default is
                            5 minutes.

        @raises urllib2.HTTPError if AFE does not respond within the timeout.
        """
        # Use a new AFE object with a longer timeout to wait for the AFE to
        # load.
        afe = frontend_wrappers.RetryingAFE(timeout_min=timeout_min,
                                            server=self.hostname)
        # Verify the AFE can handle a simple request.
        afe.get_hosts()
コード例 #25
0
    def _initialize_frontend_rpcs(self, timeout_min):
        """Initialize frontends for AFE and TKO for a moblab host.

        We tunnel all communication to the frontends through an SSH tunnel as
        many testing environments block everything except SSH access to the
        moblab DUT.

        @param timeout_min: The timeout minuties for AFE services.
        """
        web_address = self.rpc_server_tracker.tunnel_connect(MOBLAB_PORT)
        # Pass timeout_min to self.afe
        self.afe = frontend_wrappers.RetryingAFE(timeout_min=timeout_min,
                                                 user='******',
                                                 server=web_address)
        # Use default timeout_min of MoblabHost for self.tko
        self.tko = frontend_wrappers.RetryingTKO(timeout_min=self.timeout_min,
                                                 user='******',
                                                 server=web_address)
コード例 #26
0
    def __init__(self, afe=None, file_bug=False):
        """Constructor

        @param afe: an instance of AFE as defined in server/frontend.py.
                    Defaults to a frontend_wrappers.RetryingAFE instance.
        """
        self._afe = afe or frontend_wrappers.RetryingAFE(
            timeout_min=30, delay_sec=10, debug=False)
        self._file_bug = file_bug

        # Number of minutes to delay a suite job from creating test jobs.
        self.delay_minutes = 0
        # Number of minutes to increase of decrease self.delay_minutes. When
        # self.delay_minutes reaches MAX_DELAY_MINUTES, it should wind down
        # to allow even distribution of test job creation.
        self.delay_minutes_interval = DELAY_MINUTES_INTERVAL
        # Lock to make sure each suite created with different delay_minutes.
        self._lock = threading.Lock()
コード例 #27
0
    def _initialize_frontend_rpcs(self, timeout_min):
        """Initialize frontends for AFE and TKO for a moblab host.

        AFE and TKO are initialized differently based on |_use_tunnel|,
        which indicates that whether to use ssh tunnel to connect to moblab.

        @param timeout_min: The timeout minuties for AFE services.
        """
        if self._use_tunnel:
            self.web_address = self.rpc_server_tracker.tunnel_connect(
                MOBLAB_PORT)
        # Pass timeout_min to self.afe
        self.afe = frontend_wrappers.RetryingAFE(timeout_min=timeout_min,
                                                 user='******',
                                                 server=self.web_address)
        # Use default timeout_min of MoblabHost for self.tko
        self.tko = frontend_wrappers.RetryingTKO(timeout_min=self.timeout_min,
                                                 user='******',
                                                 server=self.web_address)
コード例 #28
0
def main(argv):
    """Standard main routine.

    @param argv  Command line arguments including `sys.argv[0]`.
    """
    arguments = _parse_command_line(argv)
    if arguments.mode == _DRY_RUN:
        print 'Dry run; no changes will be made.'
    afe = frontend_wrappers.RetryingAFE(server=None)
    boards = (set(arguments.extra_boards)
              | lab_inventory.get_managed_boards(afe))
    # The 'get_all_stable_versions' RPC returns a dictionary mapping
    # `_DEFAULT_BOARD` to the current default version, plus a set of
    # non-default board -> version mappings.
    afe_versions = afe.run('get_all_stable_versions')
    upgrade_versions, new_default = (_get_upgrade_versions(
        afe_versions, _get_omaha_versions(), boards))
    _apply_upgrades(afe, arguments.mode, afe_versions, upgrade_versions,
                    new_default)
コード例 #29
0
def main(argv):
    """Standard main routine.

    @param argv  Command line arguments including `sys.argv[0]`.

    """
    arguments = _parse_command(argv)
    if arguments.production:
        metrics_manager = site_utils.SetupTsMonGlobalState('balance_pools',
                                                           indirect=True)
    else:
        metrics_manager = site_utils.TrivialContextManager()

    with metrics_manager:
        with metrics.SuccessCounter('chromeos/autotest/balance_pools/runs'):
            end_time = time.time()
            start_time = end_time - 24 * 60 * 60
            afe = frontend_wrappers.RetryingAFE(server=arguments.web)

            def balancer(pool, labels):
                """Balance the specified model.

                @param pool: The pool to rebalance for the model.
                @param labels: labels to restrict to balancing operations
                        within.
                """
                _balance_model(arguments, afe, pool, labels,
                               start_time, end_time)
                _log_message('')

            pools = (lab_inventory.CRITICAL_POOLS
                    if arguments.pool == _ALL_CRITICAL_POOLS
                    else [arguments.pool])
            balancer_targets = infer_balancer_targets(afe, arguments, pools)
            try:
                parallel.RunTasksInProcessPool(
                        balancer,
                        balancer_targets,
                        processes=8,
                )
            except KeyboardInterrupt:
                pass
コード例 #30
0
    def query_adb_device_serials(self):
        """Get a list of devices currently attached to the test station.

        @returns a list of adb devices.
        """
        serials = []
        # Let's see if we can get the serials via host attributes.
        afe = frontend_wrappers.RetryingAFE(timeout_min=5, delay_sec=10)
        serials_attr = afe.get_host_attribute('serials', hostname=self.hostname)
        for serial_attr in serials_attr:
            serials.extend(serial_attr.value.split(','))

        # Looks like we got nothing from afe, let's probe the test station.
        if not serials:
            # TODO(kevcheng): Refactor teststation to be a class and make the
            # ADBHost adb_devices a static method I can use here.  For now this
            # is pretty much a c/p of the _adb_devices() method from ADBHost.
            serials = adb_host.ADBHost.parse_device_serials(
                self.teststation.run('adb devices').stdout)

        return serials