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
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 allocate_rf_switch(): """Allocates a RF Switch. Locks the available RF Switch if it was discovered via AFE to prevent tests stomping on each other. @return an instance of AFE host object or None. """ afe = frontend.AFE(debug=True, server=site_utils.get_global_afe_hostname()) # Get a list of hosts with label rf_switch that are not locked. rf_switch_hosts = afe.get_hosts(label=RF_SWITCH_LABEL, locked=False) if len(rf_switch_hosts) > 0: for rf_switch in rf_switch_hosts: # Lock the first available RF Switch in the list. if afe.lock_host(rf_switch.hostname, LOCK_REASON): return rf_switch logging.error('RF Switch %s could not be locked' % rf_switch.hostname) else: logging.debug('No RF Switches are available for tests.')
def _get_devices(self): """Return all devices in the Client Box. @returns a list of autotest_lib.server.frontend.Host objects.""" rf_switch_label = '' for label in self.labels: if label.startswith(RF_SWITCH_STR) and (label is not RF_SWITCH_CLIENT): rf_switch_label = label afe = frontend.AFE(debug=True, server=site_utils.get_global_afe_hostname()) hosts = afe.get_hosts(label=self.client_box_label) devices = [] for host in hosts: labels = list( itertools.ifilter(lambda x: x in host.labels, [RF_SWITCH_DUT, rf_switch_label])) # If host has both labels, then add to the devices list. if len(labels) == 2: devices.append(host) return devices
def _get_aps_by_lab_location(self, want_chamber_aps, ap_list): """Returns APs that are inside or outside of the chaos/clique lab. @param want_chamber_aps: True to select only APs in the chaos/clique chamber. False to select APs outside of the chaos/clique chamber. @param ap_list: a list of APConfigurator objects. @return a list of APConfigurators """ aps = [] afe = frontend_wrappers.RetryingAFE( timeout_min=10, delay_sec=5, server=site_utils.get_global_afe_hostname()) if self.test_type == ap_constants.AP_TEST_TYPE_CHAOS: ap_label = 'chaos_ap' lab_label = 'chaos_chamber' elif self.test_type == ap_constants.AP_TEST_TYPE_CLIQUE: ap_label = 'clique_ap' lab_label = 'clique_chamber' elif self.test_type == ap_constants.AP_TEST_TYPE_CASEY5: ap_label = 'casey_ap5' lab_label = 'casey_chamber5' elif self.test_type == ap_constants.AP_TEST_TYPE_CASEY7: ap_label = 'casey_ap7' lab_label = 'casey_chamber7' else: return None all_aps = set(afe.get_hostnames(label=ap_label)) chamber_devices = set(afe.get_hostnames(label=lab_label)) chamber_aps = all_aps.intersection(chamber_devices) for ap in ap_list: if want_chamber_aps and ap.host_name in chamber_aps: aps.append(ap) if not want_chamber_aps and ap.host_name not in chamber_aps: aps.append(ap) return aps
def _check_for_reboot(self, updater): """Reboot this servo host if an upgrade is waiting. If the host has successfully downloaded and finalized a new build, reboot. @param updater: a ChromiumOSUpdater instance for checking whether reboot is needed. @return Return a (status, build) tuple reflecting the update_engine status and current build of the host at the end of the call. """ current_build_number = self._get_release_version() status = updater.check_update_status() if status == autoupdater.UPDATER_NEED_REBOOT: # Check if we need to schedule an organized reboot. afe = frontend_wrappers.RetryingAFE( timeout_min=5, delay_sec=10, server=server_site_utils.get_global_afe_hostname()) dut_list = self.get_attached_duts(afe) logging.info('servo host has the following duts: %s', dut_list) if len(dut_list) > 1: logging.info('servo host has multiple duts, scheduling ' 'synchronized reboot') self.schedule_synchronized_reboot(dut_list, afe) return status, current_build_number logging.info('Rebooting servo host %s from build %s', self.hostname, current_build_number) # Tell the reboot() call not to wait for completion. # Otherwise, the call will log reboot failure if servo does # not come back. The logged reboot failure will lead to # test job failure. If the test does not require servo, we # don't want servo failure to fail the test with error: # `Host did not return from reboot` in status.log. self.reboot(fastsync=True, wait=False) # We told the reboot() call not to wait, but we need to wait # for the reboot before we continue. Alas. The code from # here below is basically a copy of Host.wait_for_restart(), # with the logging bits ripped out, so that they can't cause # the failure logging problem described above. # # The black stain that this has left on my soul can never be # erased. old_boot_id = self.get_boot_id() if not self.wait_down(timeout=self.WAIT_DOWN_REBOOT_TIMEOUT, warning_timer=self.WAIT_DOWN_REBOOT_WARNING, old_boot_id=old_boot_id): raise error.AutoservHostError( 'servo host %s failed to shut down.' % self.hostname) if self.wait_up(timeout=120): current_build_number = self._get_release_version() status = updater.check_update_status() logging.info('servo host %s back from reboot, with build %s', self.hostname, current_build_number) else: raise error.AutoservHostError( 'servo host %s failed to come back from reboot.' % self.hostname) return status, current_build_number