def run_single(name, call): """Run a single function, keeping track of results and time. @param name: name of part @param call: call to make @return_value: a tuple of result and fail count """ res = {'name': name, 'time': 0, 'errors': [], 'success': False} failed = 0 start_time = time.time() try: call() except Exception as e: failed += 1 res['errors'].append(str(e)) LOG.error('stage part: %s encountered error: %s', name, str(e)) trace = traceback.extract_tb(sys.exc_info()[-1]) LOG.error('traceback:\n%s', ''.join(traceback.format_list(trace))) res['time'] = time.time() - start_time if failed == 0: res['success'] = True return res, failed
def run_single(name, call): """Run a single function, keeping track of results and time. @param name: name of part @param call: call to make @return_value: a tuple of result and fail count """ res = { 'name': name, 'time': 0, 'errors': [], 'success': False } failed = 0 start_time = time.time() try: call() except Exception as e: failed += 1 res['errors'].append(str(e)) LOG.error('stage part: %s encountered error: %s', name, str(e)) trace = traceback.extract_tb(sys.exc_info()[-1]) LOG.error('traceback:\n%s', ''.join(traceback.format_list(trace))) res['time'] = time.time() - start_time if failed == 0: res['success'] = True return res, failed
def normalize_bddeb_args(args): """Normalize BDDEB arguments. @param args: parsed args @return_value: updated args, or None if errors encountered """ # make sure cloud-init dir is accessible if not (args.cloud_init and os.path.isdir(args.cloud_init)): LOG.error('invalid cloud-init tree path') return None return args
def normalize_output_deb_args(args): """Normalize OUTPUT_DEB arguments. @param args: parsed args @return_value: updated args, or None if erros occurred """ # make sure to use abspath for deb args.deb = os.path.abspath(args.deb) if not args.deb.endswith('.deb'): LOG.error('output filename does not end in ".deb"') return None return args
def normalize_create_args(args): """Normalize CREATE arguments. @param args: parsed args @return_value: updated args, or None if errors occurred """ # ensure valid name for new test if len(args.name.split('/')) != 2: LOG.error('invalid test name: %s', args.name) return None if os.path.exists(config.name_to_path(args.name)): msg = 'test: {} already exists'.format(args.name) if args.force: LOG.warning('%s but ignoring due to --force', msg) else: LOG.error(msg) return None # ensure test config valid if specified if isinstance(args.config, str) and len(args.config) == 0: LOG.error('test config cannot be empty if specified') return None # ensure description valid if specified if (isinstance(args.description, str) and (len(args.description) > 70 or len(args.description) == 0)): LOG.error('test description must be between 1 and 70 characters') return None return args
def normalize_collect_args(args): """ normalize COLLECT arguments args: parsed args return_value: updated args, or None if errors occurred """ # platform should default to all supported if len(args.platform) == 0: args.platform = config.list_enabled_platforms() args.platform = util.sorted_unique(args.platform) # os name should default to all enabled # if os name is provided ensure that all provided are supported if len(args.os_name) == 0: args.os_name = config.list_enabled_distros() else: supported = config.list_enabled_distros() invalid = [ os_name for os_name in args.os_name if os_name not in supported ] if len(invalid) != 0: LOG.error('invalid os name(s): %s', invalid) return None args.os_name = util.sorted_unique(args.os_name) # test configs should default to all enabled # if test configs are provided, ensure that all provided are valid if len(args.test_config) == 0: args.test_config = config.list_test_configs() else: valid = [] invalid = [] for name in args.test_config: if os.path.exists(name): valid.append(name) elif os.path.exists(config.name_to_path(name)): valid.append(config.name_to_path(name)) else: invalid.append(name) if len(invalid) != 0: LOG.error('invalid test config(s): %s', invalid) return None else: args.test_config = valid args.test_config = util.sorted_unique(args.test_config) return args
def run_stage(parent_name, calls, continue_after_error=True): """Run a stage of collection, keeping track of results and failures. @param parent_name: name of stage calls are under @param calls: list of function call taking no params. must return a tuple of results and failures. may raise exceptions @param continue_after_error: whether or not to proceed to the next call after catching an exception or recording a failure @return_value: a tuple of results and failures, with result containing results from the function call under 'stages', and a list of errors (if any on this level), and elapsed time running stage, and the name """ res = { 'name': parent_name, 'time': 0, 'errors': [], 'stages': [], 'success': False, } failed = 0 start_time = time.time() for call in calls: try: (call_res, call_failed) = call() res['stages'].append(call_res) except Exception as e: call_failed = 1 res['errors'].append(str(e)) LOG.error('stage: %s encountered error: %s', parent_name, str(e)) trace = traceback.extract_tb(sys.exc_info()[-1]) LOG.error('traceback:\n%s', ''.join(traceback.format_list(trace))) failed += call_failed if call_failed and not continue_after_error: break res['time'] = time.time() - start_time if not failed: res['success'] = True return (res, failed)
def normalize_setup_args(args): """Normalize SETUP arguments. @param args: parsed args @return_value: updated_args, or None if errors occurred """ # ensure deb or rpm valid if specified for pkg in (args.deb, args.rpm): if pkg is not None and not os.path.exists(pkg): LOG.error('cannot find package: %s', pkg) return None # if repo or ppa to be enabled run upgrade if args.repo or args.ppa: args.upgrade = True # if ppa is specified, remove leading 'ppa:' if any _ppa_header = 'ppa:' if args.ppa and args.ppa.startswith(_ppa_header): args.ppa = args.ppa[len(_ppa_header):] return args
def normalize_output_args(args): """Normalize OUTPUT arguments. @param args: parsed args @return_value: updated args, or None if errors occurred """ if args.data_dir: args.data_dir = os.path.abspath(args.data_dir) if not os.path.exists(args.data_dir): os.mkdir(args.data_dir) if not args.data_dir: args.data_dir = None # ensure clean output dir if collect # ensure data exists if verify if args.subcmd == 'collect': if not util.is_clean_writable_dir(args.data_dir): LOG.error('data_dir must be empty/new and must be writable') return None return args
def normalize_collect_args(args): """Normalize COLLECT arguments. @param args: parsed args @return_value: updated args, or None if errors occurred """ # platform should default to all supported if len(args.platform) == 0: args.platform = config.ENABLED_PLATFORMS args.platform = util.sorted_unique(args.platform) # os name should default to all enabled # if os name is provided ensure that all provided are supported if len(args.os_name) == 0: args.os_name = config.ENABLED_DISTROS else: supported = config.ENABLED_DISTROS invalid = [ os_name for os_name in args.os_name if os_name not in supported ] if len(invalid) != 0: LOG.error('invalid os name(s): %s', invalid) return None args.os_name = util.sorted_unique(args.os_name) # test configs should default to all enabled # if test configs are provided, ensure that all provided are valid if len(args.test_config) == 0: args.test_config = config.list_test_configs() else: valid = [] invalid = [] for name in args.test_config: if os.path.exists(name): valid.append(name) elif os.path.exists(config.name_to_path(name)): valid.append(config.name_to_path(name)) else: invalid.append(name) if len(invalid) != 0: LOG.error('invalid test config(s): %s', invalid) return None else: args.test_config = valid args.test_config = util.sorted_unique(args.test_config) # parse feature flag overrides and ensure all are valid if args.feature_override: overrides = args.feature_override args.feature_override = util.parse_conf_list( overrides, boolean=True, valid=config.list_feature_flags()) if not args.feature_override: LOG.error('invalid feature flag override(s): %s', overrides) return None else: args.feature_override = {} return args
def normalize_collect_args(args): """Normalize COLLECT arguments. @param args: parsed args @return_value: updated args, or None if errors occurred """ # platform should default to lxd if len(args.platform) == 0: args.platform = ['lxd'] args.platform = util.sorted_unique(args.platform) # os name should default to all enabled # if os name is provided ensure that all provided are supported if len(args.os_name) == 0: args.os_name = config.ENABLED_DISTROS else: supported = config.ENABLED_DISTROS invalid = [os_name for os_name in args.os_name if os_name not in supported] if len(invalid) != 0: LOG.error('invalid os name(s): %s', invalid) return None args.os_name = util.sorted_unique(args.os_name) # test configs should default to all enabled # if test configs are provided, ensure that all provided are valid if len(args.test_config) == 0: args.test_config = config.list_test_configs() else: valid = [] invalid = [] for name in args.test_config: if os.path.exists(name): valid.append(name) elif os.path.exists(config.name_to_path(name)): valid.append(config.name_to_path(name)) else: invalid.append(name) if len(invalid) != 0: LOG.error('invalid test config(s): %s', invalid) return None else: args.test_config = valid args.test_config = util.sorted_unique(args.test_config) # parse feature flag overrides and ensure all are valid if args.feature_override: overrides = args.feature_override args.feature_override = util.parse_conf_list( overrides, boolean=True, valid=config.list_feature_flags()) if not args.feature_override: LOG.error('invalid feature flag override(s): %s', overrides) return None else: args.feature_override = {} return args
def normalize_output_args(args): """ normalize OUTPUT arguments args: parsed args return_value: updated args, or None if errors occurred """ if not args.data_dir: LOG.error('--data-dir must be specified') return None # ensure clean output dir if collect # ensure data exists if verify if args.subcmd == 'collect': if not util.is_clean_writable_dir(args.data_dir): LOG.error('data_dir must be empty/new and must be writable') return None elif args.subcmd == 'verify': if not os.path.exists(args.data_dir): LOG.error('data_dir %s does not exist', args.data_dir) return None return args