def env_check(enable_kvm): """ Check if the environment is proper """ logger.info("Check for environment") # create a folder to store all edited multiplexer files if not os.path.isdir("/tmp/mux/"): logger.info("Creating temporary mux dir") os.makedirs("/tmp/mux/") not_found = [] (env_ver, env_type, cmd_pat) = helper.get_env_type(enable_kvm) # try to check base packages using major version numbers env_ver = env_ver.split('.')[0] env_deps = [] if not CONFIGFILE.has_section('deps_%s' % env_ver): # Fallback to base name if specific version is not found dist = helper.get_dist() env_ver = dist[0] if CONFIGFILE.has_section('deps_%s' % env_ver): packages = CONFIGFILE.get('deps_%s' % env_ver, 'packages') if packages != '': env_deps = packages.split(',') for dep in env_deps: if helper.runcmd(cmd_pat % dep, ignore_status=True)[0] != 0: not_found.append(dep) env_deps = [] # try to check env specific packages if CONFIGFILE.has_section('deps_%s_%s' % (env_ver, env_type)): packages = CONFIGFILE.get('deps_%s_%s' % (env_ver, env_type), 'packages') if packages != '': env_deps = packages.split(',') for dep in env_deps: if helper.runcmd(cmd_pat % dep, ignore_status=True)[0] != 0: not_found.append(dep) if not_found: if args.no_deps_check: logger.warning( "No dependancy check flag is set, proceeding with bootstrap") logger.info("Please install following " "dependancy packages %s", " ".join(not_found)) elif args.install_deps: logger.warning("Installing missing packages %s", " ".join(not_found)) if helper.install_packages(not_found): logger.error("Some packages not installed") sys.exit(1) else: logger.error("Please install following " "dependancy packages %s", " ".join(not_found)) sys.exit(1)
def env_check(enable_kvm): """ Check if the environment is proper """ logger.info("Check for environment") not_found = [] (env_ver, env_type, cmd_pat) = helper.get_env_type(enable_kvm) # try to check base packages using major version numbers env_ver = env_ver.split('.')[0] env_deps = [] if not CONFIGFILE.has_section('deps_%s' % env_ver): # Fallback to base name if specific version is not found dist = helper.get_dist() env_ver = dist[0] if CONFIGFILE.has_section('deps_%s' % env_ver): packages = CONFIGFILE.get('deps_%s' % env_ver, 'packages') if packages != '': env_deps = packages.split(',') for dep in env_deps: if helper.runcmd(cmd_pat % dep, ignore_status=True)[0] != 0: not_found.append(dep) env_deps = [] # try to check env specific packages if CONFIGFILE.has_section('deps_%s_%s' % (env_ver, env_type)): packages = CONFIGFILE.get('deps_%s_%s' % (env_ver, env_type), 'packages') if packages != '': env_deps = packages.split(',') for dep in env_deps: if helper.runcmd(cmd_pat % dep, ignore_status=True)[0] != 0: not_found.append(dep) if not_found: if args.install_deps: logger.warning("Installing missing packages %s", " ".join(not_found)) if helper.install_packages(not_found): logger.error("Some packages not installed") sys.exit(1) else: logger.error("Please install following " "dependancy packages %s", " ".join(not_found)) sys.exit(1)
def parse_test_config(test_config_file, avocado_bin, enable_kvm): """ Parses Test Config file and returns list of indivual tests dictionaries, with test path and yaml file path. """ test_config_type = test_config_file[:test_config_file.find("_")] test_config_name = test_config_file[test_config_file.find("_") + 1:] test_config_file = "%s/%s/%s.cfg" % (TEST_CONF_PATH, test_config_type, test_config_name) if not os.path.isfile(test_config_file): logger.error("Test Config %s not present", test_config_file) else: (env_ver, env_type, cmdpat) = helper.get_env_type(enable_kvm) norun_tests = [] # Get common set of not needed tests dist = 'norun_%s' % helper.get_dist()[0] major = 'norun_%s' % env_ver.split('.')[0] minor = 'norun_%s' % env_ver minor_env = 'norun_%s_%s' % (env_ver, env_type) for section in [dist, major, minor, minor_env]: if NORUNTESTFILE.has_section(section): norun_tests.extend( NORUNTESTFILE.get(section, 'tests').split(',')) with open(test_config_file, 'r') as fp: test_config_contents = fp.read() test_list = [] mux_flag = 0 for line in test_config_contents.splitlines(): test_dic = {} if line in norun_tests: continue if line.startswith("#") or not line: continue line = line.split() test_dic['test'] = line[0].strip('$') test_dic['name'] = test_dic['test'].split("/")[-1] if ":" in test_dic['test'].split("/")[-1]: test_dic['name'] = "%s_%s" % (test_dic['name'].split( ".")[0], test_dic['name'].split(":")[-1].replace(".", "_")) test_dic['test'] = "%s$" % test_dic['test'] else: test_dic['name'] = test_dic['name'].split(".")[0] cmd = "%s list %s 2> /dev/null" % (avocado_bin, test_dic['test']) if helper.runcmd(cmd, ignore_status=True)[0] != 0: logger.debug("%s does not exist", test_dic['test']) continue if len(line) > 1: test_dic['mux'] = line[1] mux_flag = 1 test_dic['name'] = "%s_%s" % ( test_dic['name'], test_dic['mux'].split("/")[-1].split(".")[0]) if args.inputfile: mux_file = os.path.join(TEST_DIR, test_dic['mux']) if not os.path.isfile(mux_file): logger.debug("%s does not exist", mux_file) continue tmp_mux_path = os.path.join( '/tmp/mux/', "%s_%s.yaml" % (test_config_name, test_dic['name'])) edit_mux_file(test_config_name, mux_file, tmp_mux_path) test_dic['mux'] = tmp_mux_path count = 0 for list_dic in test_list: if test_dic['name'] == list_dic['name'].split('.')[0]: count += 1 if count: test_dic['name'] += ".%d" % (count + 1) if len(line) > 2: test_dic['args'] = " --execution-order %s " % line[2] test_list.append(test_dic) if mux_flag == 0: single_test_dic = {} single_test_dic['name'] = test_config_name single_test_dic['test'] = '' for test in test_list: single_test_dic['test'] += " %s" % test['test'] return [single_test_dic] return test_list
def parse_test_config(test_config_file, avocado_bin, enable_kvm): """ Parses Test Config file and returns list of indivual tests dictionaries, with test path and yaml file path. """ test_config_type = test_config_file[:test_config_file.find("_")] test_config_name = test_config_file[test_config_file.find("_") + 1:] test_config_file = "%s/%s/%s.cfg" % (TEST_CONF_PATH, test_config_type, test_config_name) if not os.path.isfile(test_config_file): logger.error("Test Config %s not present", test_config_file) else: (env_ver, env_type, cmdpat) = helper.get_env_type(enable_kvm) norun_tests = [] # Get common set of not needed tests env = 'norun_%s' % env_type dist = 'norun_%s' % helper.get_dist()[0] major = 'norun_%s' % env_ver.split('.')[0] minor = 'norun_%s' % env_ver minor_env = 'norun_%s_%s' % (env_ver, env_type) for section in [env, dist, major, minor, minor_env]: if NORUNTESTFILE.has_section(section): norun_tests.extend(NORUNTESTFILE.get(section, 'tests').split(',')) norun_tests = list(filter(None, norun_tests)) with open(test_config_file, 'r') as fp: test_config_contents = fp.read() test_list = [] mux_flag = 0 arg_flag = 0 for line in test_config_contents.splitlines(): norun_flag = False test_dic = {} # Comment line or Empty line filtering if line.startswith("#") or not line: norun_flag = True # Filtering <test yaml> combination elif line in norun_tests: norun_flag = True # Filtering <string*> pattern else: for norun_test in norun_tests: if norun_test.endswith('*') and line.startswith(norun_test[:-1]): norun_flag = True break if norun_flag: continue # split line ignoring quotes used for additional args line = shlex.split(line) test_dic['test'] = line[0].strip('$') test_dic['name'] = test_dic['test'].split("/")[-1] if ":" in test_dic['test'].split("/")[-1]: test_dic['name'] = "%s_%s" % (test_dic['name'].split(".")[0], test_dic['name'].split(":")[-1].replace(".", "_")) test_dic['test'] = "%s$" % test_dic['test'] else: test_dic['name'] = test_dic['name'].split(".")[0] cmd = "%s list %s 2> /dev/null" % (avocado_bin, test_dic['test']) if helper.runcmd(cmd, ignore_status=True)[0] != 0: logger.debug("%s does not exist", test_dic['test']) continue # Handling parameters after test from cfg if len(line) > 1: # Handling yaml file from second param if '.yaml' in line[1]: test_dic['mux'] = line[1] mux_flag = 1 test_dic['name'] = "%s_%s" % (test_dic['name'], test_dic['mux'].split("/")[-1].split(".")[0]) if args.inputfile: mux_file = os.path.join(TEST_DIR, test_dic['mux']) if not os.path.isfile(mux_file): logger.debug("%s does not exist", mux_file) continue tmp_mux_path = os.path.join('/tmp/mux/', "%s_%s.yaml" % (test_config_name, test_dic['name'])) edit_mux_file(test_config_name, mux_file, tmp_mux_path) test_dic['mux'] = tmp_mux_path # Handling additional args from second param else: arg_flag = 1 test_dic['args'] = " %s" % line[1] count = 0 for list_dic in test_list: if test_dic['name'] == list_dic['name'].split('.')[0]: count += 1 if count: test_dic['name'] += ".%d" % (count + 1) # Handle additional args after yaml(second arg) from third param if len(line) > 2: arg_flag = 1 test_dic['args'] = " %s" % line[2] test_list.append(test_dic) if mux_flag == 0 and arg_flag == 0: single_test_dic = {} single_test_dic['name'] = test_config_name single_test_dic['test'] = '' for test in test_list: single_test_dic['test'] += " %s" % test['test'] return [single_test_dic] return test_list