def main(argv): """Standard main routine. @param argv Command line arguments including `sys.argv[0]`. """ def balancer(i, board): """Balance the specified board. @param i The index of the board. @param board The board name. """ if i > 0: _log_message('') _balance_board(arguments, afe, board, start_time, end_time) arguments = _parse_command(argv) end_time = time.time() start_time = end_time - 24 * 60 * 60 afe = frontend.AFE(server=None) boards = arguments.boards if arguments.all_boards: boards = host_label_utils.get_all_boards( labels=[_POOL_PREFIX + arguments.pool]) board_args = list(enumerate(boards)) try: parallel.RunTasksInProcessPool(balancer, board_args, processes=8) except KeyboardInterrupt: pass
def _install_dut(arguments, host_attr_dict, hostname): """Deploy or repair a single DUT. Implementation note: This function is expected to run in a subprocess created by a multiprocessing Pool object. As such, it can't (shouldn't) write to shared files like `sys.stdout`. @param hostname Host name of the DUT to install on. @param arguments Command line arguments with options. @param host_attr_dict Dict of host attributes to store in the AFE. @return On success, return `None`. On failure, return a string with an error message. """ logpath = os.path.join(arguments.logdir, hostname + '.log') logfile = open(logpath, 'w') # In some cases, autotest code that we call during install may # put stuff onto stdout with 'print' statements. Most notably, # the AFE frontend may print 'FAILED RPC CALL' (boo, hiss). We # want nothing from this subprocess going to the output we # inherited from our parent, so redirect stdout and stderr here, # before we make any AFE calls. Note that this does what we # want only because we're in a subprocess. sys.stderr = sys.stdout = logfile _configure_logging_to_file(logfile) afe = frontend.AFE(server=arguments.web) try: _install_and_update_afe(afe, hostname, arguments, host_attr_dict) except Exception as e: logging.exception('Original exception: %s', e) return str(e) return None
def allocate_packet_capturer(lock_manager, hostname, prefix): """Allocates a machine to capture packets. Locks the allocated machine if the machine was discovered via AFE to prevent tests stomping on each other. @param lock_manager HostLockManager object. @param hostname string optional hostname of a packet capture machine. @param prefix string chamber location (ex. chromeos3, chromeos5, chromeos7) @return: An SSHHost object representing a locked packet_capture machine. """ if hostname is not None: return hosts.SSHHost(hostname) afe = frontend.AFE(debug=True, server=site_utils.get_global_afe_hostname()) available_pcaps = afe.get_hosts(label='packet_capture') for pcap in available_pcaps: pcap_prefix = pcap.hostname.split('-')[0] # Ensure the pcap and dut are in the same subnet if pcap_prefix == prefix: if lock_manager.lock([pcap.hostname]): return hosts.SSHHost(pcap.hostname + '.cros') else: logging.info('Unable to lock %s', pcap.hostname) continue raise error.TestError( 'Unable to lock any pcaps - check in cautotest if ' 'pcaps in %s are locked.', prefix)
def main(): jobdirs = get_job_dirs(options.resultsdir) afe = frontend.AFE() # the way AFE API is right now is to give a whole list of jobs and can't # get specific jobs so minimize the queries caching the result finished_jobs = afe.get_jobs(finished=True) if options.jobname_pattern: jobname_pattern = re.compile(options.jobname_pattern) else: jobname_pattern = None # for each unpublished possible jobdir find it in the database and see # if it is completed for jobdir in jobdirs: job_id = int(os.path.basename(jobdir).split('-')[0]) job = [job for job in finished_jobs if job.id == job_id] if len(job) != 1: continue if jobname_pattern: # does it match the jobname pattern? if not jobname_pattern.match(job[0].name): continue # does it match the wanted job owner if options.job_owner and options.job_owner != job[0].owner: continue publish_job(jobdir)
def main(): parser = optparse.OptionParser(usage='%prog [options]\n\n' + __doc__.strip()) parser.add_option('-w', dest='server', default='autotest', help='Hostname of the autotest frontend RPC server.') parser.add_option('-b', dest='label', default=None, type=str, help='A label to restrict the set of hosts reverified.') options, unused_args = parser.parse_args(sys.argv) afe_client = frontend.AFE(debug=False, server=options.server) hostnames = afe_client.reverify_hosts(status='Repair Failed', label=options.label) # The old RPC interface didn't return anything. # A more recent one returns a list of hostnames to make this message useful. if hostnames: print 'The following Repair Failed hosts on', options.server, print 'will be reverified:' print ' '.join(hostnames) else: print 'Repair Failed hosts on', options.server, 'will be reverified.'
def run_once(self): """ Tests the moblab's connected DUTs to see if the current configuration is valid for storage qual """ afe = frontend.AFE(server='localhost', user='******') # get autotest statuses that indicate a live host live_statuses = afe.host_statuses(live=True) # get the hosts connected to autotest, find the live ones hosts = [] for host in afe.get_hosts(): if host.status in live_statuses: logging.info('Host %s is live, status %s' % (host.hostname, host.status)) hosts.append(host) else: logging.info('Host %s is not live, status %s' % (host.hostname, host.status)) pools = self._group_hosts_into_pools(hosts) # verify that each pool is set up to run storage qual # err on the side of caution by requiring all pools to have the correct # setup, so it is clear to partners that they could run storage qual # with any configuration on RunSuite page required_set = set(self.REQUIRED_LABELS) for pool_name, pool_hosts in pools.iteritems(): provided_set = set() logging.info('Pool %s' % pool_name) for host in pool_hosts: host_provided_labels = set(host['labels']) & required_set # check that each DUT has at most 1 storage qual label if len(host_provided_labels) > 1: raise error.TestFail( ('Host %s is assigned more than ' 'one storage qual label %s') % (host['host'], str(host_provided_labels))) if len(host_provided_labels) == 0: continue # check that each label is only on one DUT in the pool provided_label = host_provided_labels.pop() if provided_label in provided_set: raise error.TestFail( ('Host %s is assigned label %s, which is already ' 'assigned to another DUT in pool %s') % (host['host'], provided_label, pool_name)) provided_set.add(provided_label) logging.info(' - %s %s' % (host['host'], provided_label)) # check that all storage qual labels are accounted for in the pool missing_labels = required_set - provided_set if len(missing_labels) > 0: raise error.TestFail('Pool %s is missing required labels %s' % (pool_name, str(missing_labels))) return
def test_result_notify(self): class fake_job(object): result = True name = 'nameFoo' id = 'idFoo' results_platform_map = {'NORAD': {'Seeking_Joshua': ['WOPR']}} GLOBAL_CONFIG.override_config_value('SERVER', 'hostname', 'chess') rpc_client_lib.authorization_headers.expect_call( 'david', 'http://chess').and_return({'AUTHORIZATION': 'david'}) rpc_client_lib.get_proxy.expect_call( 'http://chess/afe/server/rpc/', headers={'AUTHORIZATION': 'david'}) self.god.stub_function(utils, 'send_email') utils.send_email.expect_any_call() my_afe = frontend.AFE(user='******') fake_stdout = StringIO() self.god.stub_with(sys, 'stdout', fake_stdout) my_afe.result_notify(fake_job, 'userA', 'userB') self.god.unstub(sys, 'stdout') fake_stdout = fake_stdout.getvalue() self.god.check_playback() self.assert_('PASSED' in fake_stdout) self.assert_('WOPR' in fake_stdout) self.assert_('http://chess/tko/compose_query.cgi?' in fake_stdout) self.assert_('columns=test' in fake_stdout) self.assert_('rows=machine_group' in fake_stdout) self.assert_("condition=tag~'idFoo-%25'" in fake_stdout) self.assert_('title=Report' in fake_stdout) self.assert_('Sending email' in fake_stdout)
def _install_dut(arguments, host_attr_dict, hostname): """Deploy or repair a single DUT. @param arguments Command line arguments with options. @param host_attr_dict Dict mapping hostnames to attributes to be stored in the AFE. @param hostname Host name of the DUT to install on. @return On success, return `None`. On failure, return a string with an error message. """ # In some cases, autotest code that we call during install may # put stuff onto stdout with 'print' statements. Most notably, # the AFE frontend may print 'FAILED RPC CALL' (boo, hiss). We # want nothing from this subprocess going to the output we # inherited from our parent, so redirect stdout and stderr, before # we make any AFE calls. Note that this is reasonable because we're # in a subprocess. logpath = os.path.join(arguments.logdir, hostname + '.log') logfile = open(logpath, 'w') sys.stderr = sys.stdout = logfile _configure_logging_to_file(logfile) afe = frontend.AFE(server=arguments.web) try: _install_and_update_afe(afe, hostname, host_attr_dict.get(hostname, {}), arguments) except Exception as e: logging.exception('Original exception: %s', e) return str(e) return None
def __init__(self, rf_switch_host): """Constructor for RF Switch Controller. @param rf_switch_host: An AFE Host object of RF Switch. """ self.rf_switch_host = rf_switch_host self.rf_switch_labels = rf_switch_host.labels # RF Switches are named as rf_switch_1, rf_switch_2 using labels. # To find the rf_switch, find label starting with 'rf_switch_' labels = [ s for s in self.rf_switch_labels if s.startswith(RF_SWITCH_STR) ] afe = frontend.AFE(debug=True, server=site_utils.get_global_afe_hostname()) self.hosts = afe.get_hosts(label=labels[0]) self.ap_boxes = [] self.client_boxes = [] for host in self.hosts: if RF_SWITCH_APS in host.labels: self.ap_boxes.append(rf_switch_ap_box.APBox(host)) elif RF_SWITCH_CLIENT in host.labels: self.client_boxes.append(rf_switch_client_box.ClientBox(host)) if not self.ap_boxes: logging.error('No AP boxes available for the RF Switch.') if not self.client_boxes: logging.error('No Client boxes available for the RF Switch.')
def __init__(self, hostname): """ @param hostname: hostname of server to monitor, string """ self._hostname = hostname self._afe = frontend.AFE(server=self._hostname) self._metric_fields = {'target_hostname': self._hostname}
def install_duts(argv, full_deploy): """Install a test image on DUTs, and deploy them. This handles command line parsing for both the repair and deployment commands. The two operations are largely identical; the main difference is that full deployment includes flashing dev-signed firmware on the DUT prior to installing the test image. @param argv Command line arguments to be parsed. @param full_deploy If true, do the full deployment that includes flashing dev-signed RO firmware onto the DUT. """ # Override tempfile.tempdir. Some of the autotest code we call # will create temporary files that don't get cleaned up. So, we # put the temp files in our results directory, so that we can # clean up everything in one fell swoop. tempfile.tempdir = tempfile.mkdtemp() # MALCOLM: # Be comforted. # Let's make us med'cines of our great revenge, # To cure this deadly grief. atexit.register(shutil.rmtree, tempfile.tempdir) arguments = commandline.parse_command(argv, full_deploy) if not arguments: sys.exit(1) sys.stderr.write('Installation output logs in %s\n' % arguments.logdir) # We don't want to distract the user with logging output, so we catch # logging output in a file. logging_file_path = os.path.join(arguments.logdir, 'debug.log') logfile = open(logging_file_path, 'w') _configure_logging_to_file(logfile) report_log_path = os.path.join(arguments.logdir, 'report.log') with open(report_log_path, 'w') as report_log_file: report_log = _MultiFileWriter([report_log_file, sys.stdout]) afe = frontend.AFE(server=arguments.web) current_build = _update_build(afe, report_log, arguments) host_attr_dict = _get_host_attributes(arguments.host_info_list, afe) install_pool = multiprocessing.Pool(len(arguments.hostnames)) install_function = functools.partial(_install_dut, arguments, host_attr_dict) results_list = install_pool.map(install_function, arguments.hostnames) _report_results(afe, report_log, arguments.hostnames, results_list) gspath = _get_upload_log_path(arguments) report_log.write('Logs will be uploaded to %s\n' % (gspath, )) try: _upload_logs(arguments.logdir, gspath) except Exception as e: upload_failure_log_path = os.path.join(arguments.logdir, 'gs_upload_failure.log') with open(upload_failure_log_path, 'w') as file: traceback.print_exc(limit=None, file=file) sys.stderr.write('Failed to upload logs;' ' failure details are stored in {}.\n'.format( upload_failure_log_path))
def _allocate_dut(self, host_name=None, board_name=None): """Allocates a machine to the DUT pool for running the test. Locks the allocated machine if the machine was discovered via AFE to prevent tests stomping on each other. @param host_name: Host name for the DUT. @param board_name: Board name Label to use for finding the DUT. @return: hostname of the device locked in AFE. """ hostname = None if host_name: if self.lock_manager.lock([host_name]): logging.info('Locked device %s.', host_name) hostname = host_name else: logging.error('Unable to lock device %s.', host_name) else: afe = frontend.AFE(debug=True, server=site_utils.get_global_afe_hostname()) labels = [] labels.append(constants.BOARD_PREFIX + board_name) labels.append('clique_dut') try: hostname = site_utils.lock_host_with_labels( afe, self.lock_manager, labels=labels) + '.cros' except error.NoEligibleHostException as e: raise error.TestError("Unable to find a suitable device.") except error.TestError as e: logging.error(e) return hostname
def _is_conductive(hostname): if utils.host_could_be_in_afe(hostname): conductive = site_utils.get_label_from_afe(hostname.split('.')[0], 'conductive:', frontend.AFE()) if conductive and conductive.lower() == 'true': return True return False
def is_primary_server(): """Check if this server's status is primary @return: True if primary, False otherwise. """ server = frontend.AFE(server=GLOBAL_AFE).run( 'get_servers', hostname=socket.getfqdn()) if server and server[0]['status'] == 'primary': return True return False
def update_allowed_networks(project, instance, afe=None, extra_servers=None): """Update the "Allowed Networks" list of the given CloudSQL instance. @param project: Name of the Google Cloud project. @param instance: Name of the CloudSQL instance. @param afe: Server of the frontend RPC, default to None to use the server specified in global config. @param extra_servers: Extra servers to be included in the "Allowed Networks" list. Default is None. """ # Get the IP address of all servers need access to CloudSQL instance. rpc = frontend.AFE(server=afe) servers = [ s['hostname'] for s in rpc.run('get_servers') if s['status'] != 'repair_required' and ROLES_REQUIRE_TKO_ACCESS.intersection(s['roles']) ] if extra_servers: servers.extend(extra_servers.split(',')) # Extra servers can be listed in CLOUD/tko_access_servers shadow config. tko_servers = global_config.global_config.get_config_value( 'CLOUD', 'tko_access_servers', default='') if tko_servers: servers.extend(tko_servers.split(',')) print 'Adding servers %s to access list for projects %s' % (servers, instance) print 'Fetching their IP addresses...' ips = [] for name in servers: try: ips.append(socket.gethostbyname(name)) except socket.gaierror: print 'Failed to resolve IP address for name %s' % name raise print '...Done: %s' % ips cidr_ips = [str(ip) + '/32' for ip in ips] login = False while True: try: utils.run('gcloud config set project %s -q' % project) cmd = ('gcloud sql instances patch %s --authorized-networks %s ' '-q' % (instance, ','.join(cidr_ips))) print 'Running command to update whitelists: "%s"' % cmd utils.run(cmd, stdout_tee=sys.stdout, stderr_tee=sys.stderr) return except error.CmdError: if login: raise # Try to login and retry if the command failed. gcloud_login(project) login = True
def deallocate_rf_switch(rf_switch_host): """Unlocks a RF Switch. @param rf_switch_host: an instance of AFE Host object to unlock. @return True if rf_switch is unlocked, False otherwise. """ afe = frontend.AFE(debug=True, server=site_utils.get_global_afe_hostname()) afe.unlock_hosts([rf_switch_host.hostname]) rf_switch = afe.get_hosts(hostnames=(rf_switch_host.hostname, )) return not rf_switch[0].locked
def main(argv): """Standard main routine. @param argv Command line arguments including `sys.argv[0]`. """ arguments = _parse_args(argv) afe = frontend.AFE(server=arguments.web) try: _dispatch_command(afe, arguments) except _CommandError as exc: print >>sys.stderr, 'Error: %s' % str(exc) sys.exit(1)
def run_once(self, required_duts=1, required_labels=[]): """ Tests the moblab's connected DUTs to see if the current configuration is valid for a specific test. @param required_duts [int] number of _live_ DUTs required to run the test in question. A DUT is not live if it is in a failed repair state @param required_labels [list<string>] list of labels that are required to be on at least one _live_ DUT for this test. """ logging.info('required_duts=%d required_labels=%s' % (required_duts, str(required_labels))) # creating a client to connect to autotest rpc interface # all available rpc calls are defined in # src/third_party/autotest/files/server/frontend.py afe = frontend.AFE(server='localhost', user='******') # get autotest statuses that indicate a live host live_statuses = afe.host_statuses(live=True) hosts = [] # get the hosts connected to autotest, find the live ones for host in afe.get_hosts(): if host.status in live_statuses: logging.info('Host %s is live, status %s' % (host.hostname, host.status)) hosts.append(host) else: logging.info('Host %s is not live, status %s' % (host.hostname, host.status)) # check that we have the required number of live duts if len(hosts) < required_duts: raise error.TestFail(('Suite requires %d DUTs, only %d connected' % (required_duts, len(hosts)))) required_labels_found = {} for label in required_labels: required_labels_found[label] = False # check that at least one DUT has each required label for host in hosts: for label in host.get_labels(): if label.name in required_labels_found: required_labels_found[label.name] = True # note: pools are stored as specially formatted labels # to find if a DUT is in a pool, # check if it has the label pool:mypoolname for key in required_labels_found: if not required_labels_found[key]: raise error.TestFail('No DUT with required label %s' % key) return
def initialize(self, host): self._install_pyshark() if utils.host_could_be_in_afe(host.hostname): # There are some DUTs that have different types of wifi modules. # In order to generate separate performance graphs, a variant # name is needed. Writing this key will generate results with # the name of <board>-<variant>. afe = frontend.AFE(debug=True) variant_name = site_utils.get_label_from_afe( host.hostname, 'variant:', afe) if variant_name: self.write_test_keyval({constants.VARIANT_KEY: variant_name})
def main(argv): """Standard main() for command line processing. @param argv Command line arguments (normally sys.argv). """ arguments = _parse_command(argv) afe = frontend.AFE(server=arguments.web) history_list = _validate_command(afe, arguments) if arguments.oneline: _print_host_summaries(history_list, arguments) else: _print_hosts(history_list, arguments)
def main(argv): parser = GetParser() options = parser.parse_args(argv) afe = None if options.afe: afe = frontend.AFE(server=options.afe) tko = frontend.TKO() special_tasks = [] builds = [] # Handle a JSON file being specified. if options.input: with open(options.input) as f: data = json.load(f) for build in data.get('builds', []): # For each build, amend it to include the list of # special tasks for its suite's jobs. build.setdefault('special_tasks', {}) for suite_job_id in build['suite_ids']: suite_tasks = FindSpecialTasks( suite_job_id, name_filter=options.name_filter, status_filter=options.status_filter, afe=afe, tko=tko) special_tasks.extend(suite_tasks) build['special_tasks'][suite_job_id] = suite_tasks logging.debug(build) builds.append(build) # Handle and specifically specified suite IDs. for suite_job_id in options.suite_ids: special_tasks.extend( FindSpecialTasks(suite_job_id, name_filter=options.name_filter, status_filter=options.status_filter, afe=afe, tko=tko)) # Output a resulting JSON file. with open(options.output, 'w') if options.output else sys.stdout as f: output = { 'special_tasks': special_tasks, 'name_filter': options.name_filter, 'status_filter': options.status_filter, } if len(builds): output['builds'] = builds json.dump(output, f)
def main(): """" Entry point for add_detected_host_labels script. """ parser = argparse.ArgumentParser() parser.add_argument('-s', '--silent', dest='silent', action='store_true', help='Suppress all but critical logging messages.') parser.add_argument('-i', '--info', dest='info_only', action='store_true', help='Suppress logging messages below INFO priority.') parser.add_argument('-m', '--machines', dest='machines', help='Comma separated list of machines to check.') options = parser.parse_args() if options.silent and options.info_only: print 'The -i and -s flags cannot be used together.' parser.print_help() return 0 if options.silent: logging.disable(logging.CRITICAL) if options.info_only: logging.disable(logging.DEBUG) threadpool = pool.ThreadPool() afe = frontend.AFE() if options.machines: hostnames = [m.strip() for m in options.machines.split(',')] else: hostnames = afe.get_hostnames() successes = sum( threadpool.imap_unordered(lambda x: add_missing_labels(afe, x), hostnames)) attempts = len(hostnames) logging.info( 'Label updating finished. Failed update on %d out of %d ' 'hosts.', attempts - successes, attempts) return 0
def main(argv): """Standard main routine. @param argv Command line arguments including `sys.argv[0]`. """ def balancer(i, board, pool): """Balance the specified board. @param i The index of the board. @param board The board name. @param pool The pool to rebalance for the board. """ if i > 0: _log_message('') _balance_board(arguments, afe, board, pool, start_time, end_time) arguments = _parse_command(argv) end_time = time.time() start_time = end_time - 24 * 60 * 60 afe = frontend.AFE(server=None) boards = arguments.boards pools = (lab_inventory.CRITICAL_POOLS if arguments.pool == _ALL_CRITICAL_POOLS else [arguments.pool]) board_info = [] if arguments.all_boards: inventory = lab_inventory.get_inventory(afe) for pool in pools: if _too_many_broken_boards(inventory, pool, arguments): _log_error('Refusing to balance all boards for %s pool, ' 'too many boards with at least 1 broken DUT ' 'detected.', pool) else: boards_in_pool = inventory.get_managed_boards(pool=pool) current_len_board_info = len(board_info) board_info.extend([(i + current_len_board_info, board, pool) for i, board in enumerate(boards_in_pool)]) else: # We have specified boards with a specified pool, setup the args to the # balancer properly. for pool in pools: current_len_board_info = len(board_info) board_info.extend([(i + current_len_board_info, board, pool) for i, board in enumerate(boards)]) try: parallel.RunTasksInProcessPool(balancer, board_info, processes=8) except KeyboardInterrupt: pass
def __init__(self, email_handler=None): """ RPMFrontendServer constructor. Initializes instance variables. """ self._dispatcher_minheap = [] self._entry_dict = {} self._lock = threading.Lock() self._mapping_last_modified = os.path.getmtime(MAPPING_FILE) self._servo_interface = utils.load_servo_interface_mapping() self._rpm_dict = {} self._afe = frontend.AFE() self._rpm_info = utils.LRUCache(size=LRU_SIZE) self._email_handler = email_handler
def main(): """Main.""" args = parse_args() log_dir = os.path.join(common.autotest_dir, 'logs') if not os.path.exists(log_dir): os.makedirs(log_dir) log_name = LOG_NAME_TEMPLATE % args.build.replace('/', '_') log_name = os.path.join(log_dir, log_name) utils.setup_logging(logfile=log_name, prefix=True) afe = frontend.AFE() name = SUITE_JOB_NAME_TEMPLATE % (args.build, args.name) abort_suites(afe, name) return 0
def _start_servod(machine): """Try to start servod in moblab if it's not already running or running with different board or port. @param machine: Name of the dut used for test. """ if not utils.is_moblab(): return logging.debug('Trying to start servod.') try: afe = frontend.AFE() board = server_utils.get_board_from_afe(machine, afe) hosts = afe.get_hosts(hostname=machine) servo_host = hosts[0].attributes.get('servo_host', None) servo_port = hosts[0].attributes.get('servo_port', 9999) if not servo_host in ['localhost', '127.0.0.1']: logging.warn('Starting servod is aborted. The dut\'s servo_host ' 'attribute is not set to localhost.') return except (urllib2.HTTPError, urllib2.URLError): # Ignore error if RPC failed to get board logging.error('Failed to get board name from AFE. Start servod is ' 'aborted') return try: pid = utils.run('pgrep servod').stdout cmd_line = utils.run('ps -fp %s' % pid).stdout if ('--board %s' % board in cmd_line and '--port %s' % servo_port in cmd_line): logging.debug( 'Servod is already running with given board and port.' ' There is no need to restart servod.') return logging.debug('Servod is running with different board or port. ' 'Stopping existing servod.') utils.run('sudo stop servod') except error.CmdError: # servod is not running. pass try: utils.run(START_SERVOD_CMD % (board, servo_port)) logging.debug('Servod is started') except error.CmdError as e: logging.error('Servod failed to be started, error: %s', e)
def allocate_packet_capturer(lock_manager, hostname): """Allocates a machine to capture packets. Locks the allocated machine if the machine was discovered via AFE to prevent tests stomping on each other. @param lock_manager HostLockManager object. @param hostname string optional hostname of a packet capture machine. @return: An SSHHost object representing a locked packet_capture machine. """ if hostname is not None: return hosts.SSHHost(hostname) afe = frontend.AFE(debug=True, server=site_utils.get_global_afe_hostname()) return hosts.SSHHost(site_utils.lock_host_with_labels( afe, lock_manager, labels=['packet_capture']) + '.cros')
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)
def get_devices_using_labels(self, labels): """Returns all devices with the passed labels in the Client Box. @params labels: List of host labels. @returns a list of string containing the hostnames. """ afe = frontend.AFE(debug=True, server=site_utils.get_global_afe_hostname()) hosts = afe.get_hosts(label=self.client_box_label) labels.append(self.rf_switch_label) devices = [] for host in hosts: labels_list = list( itertools.ifilter(lambda x: x in host.labels, labels)) if len(labels) == len(labels_list): devices.append(host.hostname) return devices
def allocate_webdriver_instance(lock_manager): """Allocates a machine to capture webdriver instance. Locks the allocated machine if the machine was discovered via AFE to prevent tests stomping on each other. @param lock_manager HostLockManager object. @return An SSHHost object representing a locked webdriver instance. """ afe = frontend.AFE(debug=True, server=site_utils.get_global_afe_hostname()) hostname = '%s.cros' % site_utils.lock_host_with_labels( afe, lock_manager, labels=['webdriver']) webdriver_host = hosts.SSHHost(hostname) if webdriver_host is not None: return webdriver_host logging.error("Unable to allocate VM instance") return None