def filter_configs(configs, suite_name=None, filter_in=None, filter_out=None, filter_all=None, filter_fragments=True): """ Returns a generator for pairs of description and fragment paths. Usage: configs = build_matrix(path, subset, seed) for description, fragments in filter_configs(configs): pass """ for item in configs: fragment_paths = item[1] description = combine_path(suite_name, item[0]) \ if suite_name else item[0] base_frag_paths = [strip_fragment_path(x) for x in fragment_paths] def matches(f): if f in description: return True if filter_fragments and \ any(f in path for path in base_frag_paths): return True return False if filter_all: if not all(matches(f) for f in filter_all): continue if filter_in: if not any(matches(f) for f in filter_in): continue if filter_out: if any(matches(f) for f in filter_out): continue yield ([description, fragment_paths])
def test_combine_path(self): result = build_matrix.combine_path("/path/to/left", "right/side") assert result == "/path/to/left/right/side"
def get_combinations(suite_dir, fields, subset, limit, filter_in, filter_out, include_facet): """ Describes the combinations of a suite, optionally limiting or filtering output based on the given parameters. Includes columns for the subsuite and facets when include_facet is True. Returns a tuple of (headers, rows) where both elements are lists of strings. """ configs = [(combine_path(suite_dir, item[0]), item[1]) for item in build_matrix(suite_dir, subset)] num_listed = 0 rows = [] facet_headers = set() dirs = {} max_dir_depth = 0 for _, fragment_paths in configs: if limit > 0 and num_listed >= limit: break if filter_in and not any( [f in path for f in filter_in for path in fragment_paths]): continue if filter_out and any( [f in path for f in filter_out for path in fragment_paths]): continue fragment_fields = [ extract_info(path, fields) for path in fragment_paths ] # merge fields from multiple fragments by joining their values with \n metadata = {} for fragment_meta in fragment_fields: for field, value in fragment_meta.items(): if value == '': continue if field in metadata: metadata[field] += '\n' + str(value) else: metadata[field] = str(value) if include_facet: # map final dir (facet) -> filename without the .yaml suffix for path in fragment_paths: facet_dir = os.path.dirname(path) facet = os.path.basename(facet_dir) metadata[facet] = os.path.basename(path)[:-5] facet_headers.add(facet) facet_dirs = facet_dir.split('/')[:-1] for i, dir_ in enumerate(facet_dirs): if i not in dirs: dirs[i] = set() dirs[i].add(dir_) metadata['_dir_' + str(i)] = os.path.basename(dir_) max_dir_depth = max(max_dir_depth, i) rows.append(metadata) num_listed += 1 subsuite_headers = [] if include_facet: first_subsuite_depth = max_dir_depth for i in range(max_dir_depth): if len(dirs[i]) > 1: first_subsuite_depth = i break subsuite_headers = [ 'subsuite depth ' + str(i) for i in range(0, max_dir_depth - first_subsuite_depth + 1) ] for row in rows: for i in range(first_subsuite_depth, max_dir_depth + 1): row[subsuite_headers[i - first_subsuite_depth]] = \ row.get('_dir_' + str(i), '') headers = subsuite_headers + sorted(facet_headers) + fields return headers, sorted([[row.get(field, '') for field in headers] for row in rows])
def test_combine_path_no_right(self): result = build_matrix.combine_path("/path/to/left", None) assert result == "/path/to/left"
def schedule_suite(self): """ Schedule the suite-run. Returns the number of jobs scheduled. """ name = self.name arch = util.get_arch(self.base_config.machine_type) suite_name = self.base_config.suite suite_path = os.path.normpath(os.path.join( self.suite_repo_path, self.args.suite_relpath, 'suites', self.base_config.suite.replace(':', '/'), )) log.debug('Suite %s in %s' % (suite_name, suite_path)) configs = [ (combine_path(suite_name, item[0]), item[1]) for item in build_matrix(suite_path, subset=self.args.subset, seed=self.args.seed) ] log.info('Suite %s in %s generated %d jobs (not yet filtered)' % ( suite_name, suite_path, len(configs))) if self.args.dry_run: log.debug("Base job config:\n%s" % self.base_config) # create, but do not write, the temp file here, so it can be # added to the args in collect_jobs, but not filled until # any backtracking is done base_yaml_path = NamedTemporaryFile( prefix='schedule_suite_', delete=False ).name self.base_yaml_paths.insert(0, base_yaml_path) # if newest, do this until there are no missing packages # if not, do it once backtrack = 0 limit = self.args.newest while backtrack <= limit: jobs_missing_packages, jobs_to_schedule = \ self.collect_jobs(arch, configs, self.args.newest) if jobs_missing_packages and self.args.newest: new_sha1 = \ util.find_git_parent('ceph', self.base_config.sha1) if new_sha1 is None: util.schedule_fail('Backtrack for --newest failed', name) # rebuild the base config to resubstitute sha1 self.config_input['ceph_hash'] = new_sha1 self.base_config = self.build_base_config() backtrack += 1 continue if backtrack: log.info("--newest supplied, backtracked %d commits to %s" % (backtrack, self.base_config.sha1)) break else: if self.args.newest: util.schedule_fail( 'Exceeded %d backtracks; raise --newest value' % limit, name, ) if self.args.dry_run: log.debug("Base job config:\n%s" % self.base_config) with open(base_yaml_path, 'w+b') as base_yaml: base_yaml.write(str(self.base_config)) if jobs_to_schedule: self.write_rerun_memo() self.schedule_jobs(jobs_missing_packages, jobs_to_schedule, name) os.remove(base_yaml_path) count = len(jobs_to_schedule) missing_count = len(jobs_missing_packages) log.info( 'Suite %s in %s scheduled %d jobs.' % (suite_name, suite_path, count) ) log.info('%d/%d jobs were filtered out.', (len(configs) - count), len(configs)) if missing_count: log.warn('Scheduled %d/%d jobs that are missing packages!', missing_count, count) return count
def schedule_suite(self): """ Schedule the suite-run. Returns the number of jobs scheduled. """ name = self.name arch = util.get_arch(self.base_config.machine_type) suite_name = self.base_config.suite suite_path = os.path.normpath( os.path.join( self.suite_repo_path, self.args.suite_relpath, 'suites', self.base_config.suite.replace(':', '/'), )) log.debug('Suite %s in %s' % (suite_name, suite_path)) configs = [ (combine_path(suite_name, item[0]), item[1]) for item in build_matrix( suite_path, subset=self.args.subset, seed=self.args.seed) ] log.info('Suite %s in %s generated %d jobs (not yet filtered)' % (suite_name, suite_path, len(configs))) if self.args.dry_run: log.debug("Base job config:\n%s" % self.base_config) # create, but do not write, the temp file here, so it can be # added to the args in collect_jobs, but not filled until # any backtracking is done base_yaml_path = NamedTemporaryFile(prefix='schedule_suite_', delete=False).name self.base_yaml_paths.insert(0, base_yaml_path) # compute job limit in respect of --sleep-before-teardown job_limit = self.args.limit or 0 sleep_before_teardown = int(self.args.sleep_before_teardown or 0) if sleep_before_teardown: if job_limit == 0: log.warning('The --sleep-before-teardown option was provided: ' 'only 1 job will be scheduled. ' 'Use --limit to run more jobs') # give user a moment to read this warning time.sleep(5) job_limit = 1 elif self.args.non_interactive: log.warning('The --sleep-before-teardown option is active. ' 'There will be a maximum {} jobs running ' 'which will fall asleep for {}'.format( job_limit, format_timespan(sleep_before_teardown))) elif job_limit > 4: are_you_insane = ( 'There are {total} configs and {maximum} job limit is used. ' 'Do you really want to lock all machines needed for ' 'this run for {that_long}? (y/N):'.format( that_long=format_timespan(sleep_before_teardown), total=len(configs), maximum=job_limit)) while True: insane = (input(are_you_insane) or 'n').lower() if insane == 'y': break elif insane == 'n': exit(0) # if newest, do this until there are no missing packages # if not, do it once backtrack = 0 limit = self.args.newest while backtrack <= limit: jobs_missing_packages, jobs_to_schedule = \ self.collect_jobs(arch, configs, self.args.newest, job_limit) if jobs_missing_packages and self.args.newest: new_sha1 = \ util.find_git_parent('ceph', self.base_config.sha1) if new_sha1 is None: util.schedule_fail('Backtrack for --newest failed', name) # rebuild the base config to resubstitute sha1 self.config_input['ceph_hash'] = new_sha1 self.base_config = self.build_base_config() backtrack += 1 continue if backtrack: log.info("--newest supplied, backtracked %d commits to %s" % (backtrack, self.base_config.sha1)) break else: if self.args.newest: util.schedule_fail( 'Exceeded %d backtracks; raise --newest value' % limit, name, ) if self.args.dry_run: log.debug("Base job config:\n%s" % self.base_config) with open(base_yaml_path, 'w+b') as base_yaml: base_yaml.write(str(self.base_config).encode()) if jobs_to_schedule: self.write_rerun_memo() self.schedule_jobs(jobs_missing_packages, jobs_to_schedule, name) os.remove(base_yaml_path) count = len(jobs_to_schedule) missing_count = len(jobs_missing_packages) log.info('Suite %s in %s scheduled %d jobs.' % (suite_name, suite_path, count)) log.info('%d/%d jobs were filtered out.', (len(configs) - count), len(configs)) if missing_count: log.warn('Scheduled %d/%d jobs that are missing packages!', missing_count, count) return count
def get_combinations(suite_dir, fields, subset, limit, filter_in, filter_out, include_facet): """ Describes the combinations of a suite, optionally limiting or filtering output based on the given parameters. Includes columns for the subsuite and facets when include_facet is True. Returns a tuple of (headers, rows) where both elements are lists of strings. """ configs = [(combine_path(suite_dir, item[0]), item[1]) for item in build_matrix(suite_dir, subset)] num_listed = 0 rows = [] facet_headers = set() dirs = {} max_dir_depth = 0 for _, fragment_paths in configs: if limit > 0 and num_listed >= limit: break if filter_in and not any([f in path for f in filter_in for path in fragment_paths]): continue if filter_out and any([f in path for f in filter_out for path in fragment_paths]): continue fragment_fields = [extract_info(path, fields) for path in fragment_paths] # merge fields from multiple fragments by joining their values with \n metadata = {} for fragment_meta in fragment_fields: for field, value in fragment_meta.items(): if value == '': continue if field in metadata: metadata[field] += '\n' + str(value) else: metadata[field] = str(value) if include_facet: # map final dir (facet) -> filename without the .yaml suffix for path in fragment_paths: facet_dir = os.path.dirname(path) facet = os.path.basename(facet_dir) metadata[facet] = os.path.basename(path)[:-5] facet_headers.add(facet) facet_dirs = facet_dir.split('/')[:-1] for i, dir_ in enumerate(facet_dirs): if i not in dirs: dirs[i] = set() dirs[i].add(dir_) metadata['_dir_' + str(i)] = os.path.basename(dir_) max_dir_depth = max(max_dir_depth, i) rows.append(metadata) num_listed += 1 subsuite_headers = [] if include_facet: first_subsuite_depth = max_dir_depth for i in range(max_dir_depth): if len(dirs[i]) > 1: first_subsuite_depth = i break subsuite_headers = ['subsuite depth ' + str(i) for i in range(0, max_dir_depth - first_subsuite_depth + 1)] for row in rows: for i in range(first_subsuite_depth, max_dir_depth + 1): row[subsuite_headers[i - first_subsuite_depth]] = \ row.get('_dir_' + str(i), '') headers = subsuite_headers + sorted(facet_headers) + fields return headers, sorted([[row.get(field, '') for field in headers] for row in rows])