def _get_control_file_list(self, suite_name=''): """ Gather a list of paths to control files under |self._paths|. Searches under |self._paths| for files that match |self._CONTROL_PATTERN|. Populates |self._files| with that list and then returns the paths to all useful files in the list. @param suite_name: The name of a suite we would like control files for. @return A list of files that match |self._CONTROL_PATTERN|. @throws NoControlFileList if we find no files. """ if suite_name: logging.debug('Getting control files for a specific suite has ' 'not been implemented for FileSystemGetter. ' 'Getting all control files instead.') regexp = re.compile(self._CONTROL_PATTERN) directories = self._paths # Some of our callers are ill-considered and request that we # search all of /usr/local/autotest (crbug.com/771823). # Fixing the callers immediately is somewhere between a # nuisance and hard. So, we have a blacklist, hoping two # wrongs will somehow make it right. blacklist = { 'site-packages', 'venv', 'results', 'logs', 'containers', } while len(directories) > 0: directory = directories.pop() if not os.path.exists(directory): continue try: for name in os.listdir(directory): if name in blacklist: continue fullpath = os.path.join(directory, name) if os.path.isfile(fullpath): if regexp.search(name): # if we are a control file self._files.append(fullpath) elif (not os.path.islink(fullpath) and os.path.isdir(fullpath)): directories.append(fullpath) except OSError: # Some directories under results/ like the Chrome Crash # Reports will cause issues when attempted to be searched. logging.error( 'Unable to search directory %s for control ' 'files.', directory) pass if not self._files: msg = 'No control files under ' + ','.join(self._paths) raise error.NoControlFileList(msg) return [f for f in self._files if self._is_useful_file(f)]
def _get_control_file_list(self, suite_name=''): """ Gather a list of paths to control files under |self._paths|. Searches under |self._paths| for files that match |self._CONTROL_PATTERN|. Populates |self._files| with that list and then returns the paths to all useful files in the list. @param suite_name: The name of a suite we would like control files for. @return A list of files that match |self._CONTROL_PATTERN|. @throws NoControlFileList if we find no files. """ if suite_name: logging.debug('Getting control files for a specific suite has ' 'not been implemented for FileSystemGetter. ' 'Getting all control files instead.') regexp = re.compile(self._CONTROL_PATTERN) directories = self._paths # Do not explore site-packages. (crbug.com/771823) # Do not explore venv. (b/67416549) # (Do not pass Go. Do not collect $200.) blacklist = {'site-packages', 'venv'} while len(directories) > 0: directory = directories.pop() if not os.path.exists(directory): continue # TODO(crbug.com/771827): This traverses everything, # including results and containers. Make it stop doing that. try: for name in os.listdir(directory): if name in blacklist: continue fullpath = os.path.join(directory, name) if os.path.isfile(fullpath): if regexp.search(name): # if we are a control file self._files.append(fullpath) elif os.path.isdir(fullpath): directories.append(fullpath) except OSError: # Some directories under results/ like the Chrome Crash # Reports will cause issues when attempted to be searched. logging.error( 'Unable to search directory %s for control ' 'files.', directory) pass if not self._files: msg = 'No control files under ' + ','.join(self._paths) raise error.NoControlFileList(msg) return [f for f in self._files if self._is_useful_file(f)]
def _get_control_file_list(self, suite_name=''): """ Gather a list of paths to control files from |self._dev_server|. Get a listing of all the control files for |self._build| on |self._dev_server|. Populates |self._files| with that list and then returns paths (under the autotest dir) to them. If suite_name is specified, this method populates |self._files| with the control files from just the specified suite. @param suite_name: The name of a suite we would like control files for. @return A list of control file paths. @throws NoControlFileList if there is an error while listing. """ try: return self._dev_server.list_control_files(self._build, suite_name=suite_name) except dev_server.DevServerException as e: raise error.NoControlFileList(e)
def _get_control_file_list(self, suite_name=''): """ Gather a list of paths to control files under |self._paths|. Searches under |self._paths| for files that match |self._CONTROL_PATTERN|. Populates |self._files| with that list and then returns the paths to all useful files in the list. @param suite_name: The name of a suite we would like control files for. @return A list of files that match |self._CONTROL_PATTERN|. @throws NoControlFileList if we find no files. """ if suite_name: logging.debug('Getting control files for a specific suite has ' 'not been implemented for FileSystemGetter. ' 'Getting all control files instead.') regexp = re.compile(self._CONTROL_PATTERN) directories = self._paths while len(directories) > 0: directory = directories.pop() if not os.path.exists(directory): continue try: for name in os.listdir(directory): fullpath = os.path.join(directory, name) if os.path.isfile(fullpath): if regexp.search(name): # if we are a control file self._files.append(fullpath) elif os.path.isdir(fullpath): directories.append(fullpath) except OSError: # Some directories under results/ like the Chrome Crash # Reports will cause issues when attempted to be searched. logging.error( 'Unable to search directory %d for control ' 'files.', directory) pass if not self._files: msg = 'No control files under ' + ','.join(self._paths) raise error.NoControlFileList(msg) return [f for f in self._files if self._is_useful_file(f)]
def testGetControlFileListFail(self): """Ensure that a failure to get needed control file fails the RPC.""" self._mockDevServerGetter() self.dev_server.url().AndReturn('mox_url') self.dev_server.get_server_name(mox.IgnoreArg()).AndReturn('mox_url') self.dev_server.stage_artifacts(self._BUILD, ['test_suites']).AndReturn(True) self.dev_server.url().AndReturn('mox_url') self.dev_server.get_server_name(mox.IgnoreArg()).AndReturn('mox_url') self.getter.get_control_file_contents_by_name( self._SUITE_NAME).AndRaise(error.NoControlFileList()) self.mox.ReplayAll() self.assertRaises(error.NoControlFileList, site_rpc_interface.create_suite_job, name=self._NAME, board=self._BOARD, build=self._BUILD, pool=None)