def _checkStringDump(self, string, dump): p = cartesian_config.Parser() p.parse_string(string) dumpdata = None exec "dumpdata = " + dump self._checkDictionaries(p, dumpdata)
def get_guest_name_parser(options): cartesian_parser = cartesian_config.Parser() cfgdir = os.path.join(data_dir.get_root_dir(), options.type, "cfg") cartesian_parser.parse_file(os.path.join(cfgdir, "machines.cfg")) cartesian_parser.parse_file(os.path.join(cfgdir, "guest-os.cfg")) if options.arch: cartesian_parser.only_filter(options.arch) if options.machine_type: cartesian_parser.only_filter(options.machine_type) if options.guest_os: cartesian_parser.only_filter(options.guest_os) return cartesian_parser
def get_guest_name_parser(options): cartesian_parser = cartesian_config.Parser() machines_cfg_path = data_dir.get_backend_cfg_path(options.vt_type, 'machines.cfg') guest_os_cfg_path = data_dir.get_backend_cfg_path(options.vt_type, 'guest-os.cfg') cartesian_parser.parse_file(machines_cfg_path) cartesian_parser.parse_file(guest_os_cfg_path) if options.vt_arch: cartesian_parser.only_filter(options.vt_arch) if options.vt_machine_type: cartesian_parser.only_filter(options.vt_machine_type) if options.vt_guest_os: cartesian_parser.only_filter(options.vt_guest_os) return cartesian_parser
def test_git_repo_param_helper(self): config = """git_repo_foo_uri = git://git.foo.org/foo.git git_repo_foo_branch = next git_repo_foo_lbranch = local git_repo_foo_commit = bc732ad8b2ed8be52160b893735417b43a1e91a8 """ config_parser = cartesian_config.Parser() config_parser.parse_string(config) params = config_parser.get_dicts().next() h = build_helper.GitRepoParamHelper(params, 'foo', '/tmp/foo') self.assertEqual(h.name, 'foo') self.assertEqual(h.branch, 'next') self.assertEqual(h.lbranch, 'local') self.assertEqual(h.commit, 'bc732ad8b2ed8be52160b893735417b43a1e91a8')
def _checkConfigDump(self, config, dump): """Check if the parser output matches a config file dump""" configpath = os.path.join(testdatadir, config) dumppath = os.path.join(testdatadir, dump) if dumppath.endswith('.gz'): df = gzip.GzipFile(dumppath, 'r') else: df = open(dumppath, 'r') # we could have used pickle, but repr()-based dumps are easier to # enerate, debug, and edit dumpdata = eval(df.read()) p = cartesian_config.Parser(configpath) self._checkDictionaries(p, dumpdata)
def test_make_installer(self): config = """install_mode = test_install_mode vm_type = test""" class Installer: def __init__(self, mode, name, test, params): pass installer.INSTALLER_REGISTRY.register('test_install_mode', Installer, 'test') config_parser = cartesian_config.Parser() config_parser.parse_string(config) params = config_parser.get_dicts().next() instance = installer.make_installer("test_install_mode_test", params) self.assertTrue(isinstance(instance, Installer))
def get_guest_os_info(test_name, guest_os): """ Gets the correct asset and variant information depending on host OS, test name and guest OS. """ os_info = get_default_guest_os_info() cartesian_parser = cartesian_config.Parser() cartesian_parser.parse_file( data_dir.get_backend_cfg_path(test_name, 'guest-os.cfg')) cartesian_parser.only_filter(guest_os) for params in cartesian_parser.get_dicts(): image_name = params.get('image_name', 'image').split('/')[-1] os_info = {'asset': image_name, 'variant': guest_os} return os_info
def setUp(self): """ Runs before every test """ # MAC generator produces from incrementing byte list # at random starting point (class property). # make sure it starts counting at zero before every test utils_misc.VirtIface.LASTBYTE = -1 # These warnings are annoying during testing utils_misc.VMNet.DISCARD_WARNINGS - 1 parser = cartesian_config.Parser() parser.parse_string(self.nettests_cartesian) self.CartesianResult = [] for d in parser.get_dicts(): params = utils_misc.Params(d) self.CartesianResult.append(params) for vm_name in params.objects('vms'): vm = params.object_params(vm_name) nics = vm.get('nics') if nics and len(nics.split()) > 0: self.db_item_count += 1
def get_guest_os_info_list(test_name, guest_os): """ Returns a list of matching assets compatible with the specified test name and guest OS """ os_info_list = [] cartesian_parser = cartesian_config.Parser() cartesian_parser.parse_file(data_dir.get_backend_cfg_path(test_name, 'guest-os.cfg')) cartesian_parser.only_filter(guest_os) dicts = cartesian_parser.get_dicts() for params in dicts: image_name = params.get('image_name', 'image').split('/')[-1] shortname = params.get('shortname', guest_os) os_info_list.append({'asset': image_name, 'variant': shortname}) if not os_info_list: logging.error("Could not find any assets compatible with %s for %s", guest_os, test_name) raise ValueError("Missing compatible assets for %s", guest_os) return os_info_list
def create_subtests_cfg(t_type): root_dir = data_dir.get_root_dir() specific_test_list = [] specific_file_list = [] specific_subdirs = asset.get_test_provider_subdirs(t_type) provider_names_specific = asset.get_test_provider_names(t_type) provider_info_specific = [] for specific_provider in provider_names_specific: provider_info_specific.append(asset.get_test_provider_info(specific_provider)) for subdir in specific_subdirs: specific_test_list += data_dir.SubdirGlobList(subdir, '*.py', test_filter) specific_file_list += data_dir.SubdirGlobList(subdir, '*.cfg', config_filter) shared_test_list = [] shared_file_list = [] shared_subdirs = asset.get_test_provider_subdirs('generic') provider_names_shared = asset.get_test_provider_names('generic') provider_info_shared = [] for shared_provider in provider_names_shared: provider_info_shared.append(asset.get_test_provider_info(shared_provider)) if not t_type == 'lvsb': for subdir in shared_subdirs: shared_test_list += data_dir.SubdirGlobList(subdir, '*.py', test_filter) shared_file_list += data_dir.SubdirGlobList(subdir, '*.cfg', config_filter) all_specific_test_list = [] for test in specific_test_list: for p in provider_info_specific: provider_base_path = p['backends'][t_type]['path'] if provider_base_path in test: provider_name = p['name'] break basename = os.path.basename(test) if basename != "__init__.py": all_specific_test_list.append("%s.%s" % (provider_name, basename.split(".")[0])) all_shared_test_list = [] for test in shared_test_list: for p in provider_info_shared: provider_base_path = p['backends']['generic']['path'] if provider_base_path in test: provider_name = p['name'] break basename = os.path.basename(test) if basename != "__init__.py": all_shared_test_list.append("%s.%s" % (provider_name, basename.split(".")[0])) all_specific_test_list.sort() all_shared_test_list.sort() all_test_list = set(all_specific_test_list + all_shared_test_list) first_subtest_file = [] last_subtest_file = [] non_dropin_tests = [] tmp = [] for shared_file in shared_file_list: provider_name = None for p in provider_info_shared: provider_base_path = p['backends']['generic']['path'] if provider_base_path in shared_file: provider_name = p['name'] break shared_file_obj = open(shared_file, 'r') for line in shared_file_obj.readlines(): line = line.strip() if line.startswith("type"): cartesian_parser = cartesian_config.Parser() cartesian_parser.parse_string(line) td = cartesian_parser.get_dicts().next() values = td['type'].split(" ") for value in values: if t_type not in non_dropin_tests: non_dropin_tests.append("%s.%s" % (provider_name, value)) shared_file_name = os.path.basename(shared_file) shared_file_name = shared_file_name.split(".")[0] if shared_file_name in first_subtest[t_type]: if [provider_name, shared_file] not in first_subtest_file: first_subtest_file.append([provider_name, shared_file]) elif shared_file_name in last_subtest[t_type]: if [provider_name, shared_file] not in last_subtest_file: last_subtest_file.append([provider_name, shared_file]) else: if [provider_name, shared_file] not in tmp: tmp.append([provider_name, shared_file]) shared_file_list = tmp tmp = [] for shared_file in specific_file_list: provider_name = None for p in provider_info_specific: provider_base_path = p['backends'][t_type]['path'] if provider_base_path in shared_file: provider_name = p['name'] break shared_file_obj = open(shared_file, 'r') for line in shared_file_obj.readlines(): line = line.strip() if line.startswith("type"): cartesian_parser = cartesian_config.Parser() cartesian_parser.parse_string(line) td = cartesian_parser.get_dicts().next() values = td['type'].split(" ") for value in values: if value not in non_dropin_tests: non_dropin_tests.append("%s.%s" % (provider_name, value)) shared_file_name = os.path.basename(shared_file) shared_file_name = shared_file_name.split(".")[0] if shared_file_name in first_subtest[t_type]: if [provider_name, shared_file] not in first_subtest_file: first_subtest_file.append([provider_name, shared_file]) elif shared_file_name in last_subtest[t_type]: if [provider_name, shared_file] not in last_subtest_file: last_subtest_file.append([provider_name, shared_file]) else: if [provider_name, shared_file] not in tmp: tmp.append([provider_name, shared_file]) specific_file_list = tmp non_dropin_tests.sort() non_dropin_tests = set(non_dropin_tests) dropin_tests = all_test_list - non_dropin_tests dropin_file_list = [] tmp_dir = data_dir.get_tmp_dir() if not os.path.isdir(tmp_dir): os.makedirs(tmp_dir) for dropin_test in dropin_tests: provider = dropin_test.split(".")[0] d_type = dropin_test.split(".")[-1] autogen_cfg_path = os.path.join(tmp_dir, '%s.cfg' % dropin_test) autogen_cfg_file = open(autogen_cfg_path, 'w') autogen_cfg_file.write("# Drop-in test - auto generated snippet\n") autogen_cfg_file.write("- %s:\n" % dropin_test) autogen_cfg_file.write(" virt_test_type = %s\n" % t_type) autogen_cfg_file.write(" type = %s\n" % d_type) autogen_cfg_file.close() dropin_file_list.append([provider, autogen_cfg_path]) dropin_file_list_2 = [] dropin_tests = os.listdir(os.path.join(data_dir.get_root_dir(), "dropin")) dropin_cfg_path = os.path.join(tmp_dir, 'dropin.cfg') dropin_cfg_file = open(dropin_cfg_path, 'w') dropin_cfg_file.write("# Auto generated snippet for dropin tests\n") dropin_cfg_file.write("- dropin:\n") dropin_cfg_file.write(" variants:\n") for dropin_test in dropin_tests: if dropin_test == "README": continue dropin_cfg_file.write(" - %s:\n" % dropin_test) dropin_cfg_file.write(" virt_test_type = %s\n" % t_type) dropin_cfg_file.write(" type = dropin\n") dropin_cfg_file.write(" start_vm = no\n") dropin_cfg_file.write(" dropin_path = %s\n" % dropin_test) dropin_cfg_file.close() dropin_file_list_2.append(['io-github-autotest-qemu', dropin_cfg_path]) subtests_cfg = os.path.join(root_dir, 'backends', t_type, 'cfg', 'subtests.cfg') subtests_file = open(subtests_cfg, 'w') subtests_file.write( "# Do not edit, auto generated file from subtests config\n") subtests_file.write("variants subtest:\n") write_subtests_files(first_subtest_file, subtests_file) write_subtests_files(specific_file_list, subtests_file, t_type) write_subtests_files(shared_file_list, subtests_file) write_subtests_files(dropin_file_list, subtests_file) write_subtests_files(dropin_file_list_2, subtests_file) write_subtests_files(last_subtest_file, subtests_file) subtests_file.close()
def create_subtests_cfg(t_type): root_dir = data_dir.get_root_dir() specific_test = os.path.join(root_dir, t_type, 'tests') specific_test_list = data_dir.SubdirGlobList(specific_test, '*.py', test_filter) shared_test = os.path.join(root_dir, 'tests') shared_test_list = data_dir.SubdirGlobList(shared_test, '*.py', test_filter) all_specific_test_list = [] for test in specific_test_list: basename = os.path.basename(test) if basename != "__init__.py": all_specific_test_list.append(basename.split(".")[0]) all_shared_test_list = [] for test in shared_test_list: basename = os.path.basename(test) if basename != "__init__.py": all_shared_test_list.append(basename.split(".")[0]) all_specific_test_list.sort() all_shared_test_list.sort() all_test_list = set(all_specific_test_list + all_shared_test_list) specific_test_cfg = os.path.join(root_dir, t_type, 'tests', 'cfg') shared_test_cfg = os.path.join(root_dir, 'tests', 'cfg') shared_file_list = data_dir.SubdirGlobList(shared_test_cfg, "*.cfg", config_filter) first_subtest_file = [] last_subtest_file = [] non_dropin_tests = [] tmp = [] for shared_file in shared_file_list: shared_file_obj = open(shared_file, 'r') for line in shared_file_obj.readlines(): line = line.strip() if line.startswith("type"): cartesian_parser = cartesian_config.Parser() cartesian_parser.parse_string(line) td = cartesian_parser.get_dicts().next() values = td['type'].split(" ") for value in values: if t_type not in non_dropin_tests: non_dropin_tests.append(value) shared_file_name = os.path.basename(shared_file) shared_file_name = shared_file_name.split(".")[0] if shared_file_name in first_subtest[t_type]: if shared_file_name not in first_subtest_file: first_subtest_file.append(shared_file) elif shared_file_name in last_subtest[t_type]: if shared_file_name not in last_subtest_file: last_subtest_file.append(shared_file) else: if shared_file_name not in tmp: tmp.append(shared_file) shared_file_list = tmp shared_file_list.sort() specific_file_list = data_dir.SubdirGlobList(specific_test_cfg, "*.cfg", config_filter) tmp = [] for shared_file in specific_file_list: shared_file_obj = open(shared_file, 'r') for line in shared_file_obj.readlines(): line = line.strip() if line.startswith("type"): cartesian_parser = cartesian_config.Parser() cartesian_parser.parse_string(line) td = cartesian_parser.get_dicts().next() values = td['type'].split(" ") for value in values: if value not in non_dropin_tests: non_dropin_tests.append(value) shared_file_name = os.path.basename(shared_file) shared_file_name = shared_file_name.split(".")[0] if shared_file_name in first_subtest[t_type]: if shared_file_name not in first_subtest_file: first_subtest_file.append(shared_file) elif shared_file_name in last_subtest[t_type]: if shared_file_name not in last_subtest_file: last_subtest_file.append(shared_file) else: if shared_file_name not in tmp: tmp.append(shared_file) specific_file_list = tmp specific_file_list.sort() non_dropin_tests.sort() non_dropin_tests = set(non_dropin_tests) dropin_tests = all_test_list - non_dropin_tests dropin_file_list = [] tmp_dir = data_dir.get_tmp_dir() if not os.path.isdir(tmp_dir): os.makedirs(tmp_dir) for dropin_test in dropin_tests: autogen_cfg_path = os.path.join(tmp_dir, '%s.cfg' % dropin_test) autogen_cfg_file = open(autogen_cfg_path, 'w') autogen_cfg_file.write("# Drop-in test - auto generated snippet\n") autogen_cfg_file.write("- %s:\n" % dropin_test) autogen_cfg_file.write(" virt_test_type = %s\n" % t_type) autogen_cfg_file.write(" type = %s\n" % dropin_test) autogen_cfg_file.close() dropin_file_list.append(autogen_cfg_path) subtests_cfg = os.path.join(root_dir, t_type, 'cfg', 'subtests.cfg') subtests_file = open(subtests_cfg, 'w') subtests_file.write( "# Do not edit, auto generated file from subtests config\n") subtests_file.write("variants:\n") write_subtests_files(first_subtest_file, subtests_file) write_subtests_files(specific_file_list, subtests_file, t_type) write_subtests_files(shared_file_list, subtests_file) write_subtests_files(dropin_file_list, subtests_file) write_subtests_files(last_subtest_file, subtests_file) subtests_file.close()
def _checkStringDump(self, string, dump, defaults=False): p = cartesian_config.Parser(defaults=defaults) p.parse_string(string) self._checkDictionaries(p, dump)
def _checkStringConfig(self, string, reference): p = cartesian_config.Parser() p.parse_string(string) self._checkDictionaries(p, reference)
def bootstrap(test_name, test_dir, base_dir, default_userspace_paths, check_modules, online_docs_url, restore_image=False, download_image=True, interactive=True, selinux=False, verbose=False, update_providers=False, guest_os=DEFAULT_GUEST_OS): """ Common virt test assistant module. :param test_name: Test name, such as "qemu". :param test_dir: Path with the test directory. :param base_dir: Base directory used to hold images and isos. :param default_userspace_paths: Important programs for a successful test execution. :param check_modules: Whether we want to verify if a given list of modules is loaded in the system. :param online_docs_url: URL to an online documentation system, such as a wiki page. :param restore_image: Whether to restore the image from the pristine. :param interactive: Whether to ask for confirmation. :param verbose: Verbose output. :param selinux: Whether setup SELinux contexts for shared/data. :param update_providers: Whether to update test providers if they are already downloaded. :param guest_os: Specify the guest image used for bootstrapping. By default the JeOS image is used. :raise error.CmdError: If JeOS image failed to uncompress :raise ValueError: If 7za was not found """ if interactive: logging_manager.configure_logging(utils_misc.VirtLoggingConfig(), verbose=verbose) logging.info("%s test config helper", test_name) step = 0 logging.info("") step += 1 logging.info("%d - Updating all test providers", step) asset.download_all_test_providers(update_providers) logging.info("") step += 1 logging.info("%d - Checking the mandatory programs and headers", step) verify_mandatory_programs(test_name) logging.info("") step += 1 logging.info("%d - Checking the recommended programs", step) verify_recommended_programs(test_name) logging.info("") step += 1 logging.info("%d - Verifying directories", step) shared_dir = os.path.dirname(data_dir.get_data_dir()) sub_dir_list = ["images", "isos", "steps_data", "gpg"] for sub_dir in sub_dir_list: sub_dir_path = os.path.join(base_dir, sub_dir) if not os.path.isdir(sub_dir_path): logging.debug("Creating %s", sub_dir_path) os.makedirs(sub_dir_path) else: logging.debug("Dir %s exists, not creating", sub_dir_path) datadir = data_dir.get_data_dir() if test_name == 'libvirt': create_config_files(test_dir, shared_dir, interactive, step) create_subtests_cfg(test_name) create_guest_os_cfg(test_name) # Don't bother checking if changes can't be made if os.getuid() == 0: verify_selinux(datadir, os.path.join(datadir, 'images'), os.path.join(datadir, 'isos'), data_dir.get_tmp_dir(), interactive, selinux) # lvsb test doesn't use any shared configs elif test_name == 'lvsb': create_subtests_cfg(test_name) if os.getuid() == 0: # Don't bother checking if changes can't be made verify_selinux(datadir, os.path.join(datadir, 'images'), os.path.join(datadir, 'isos'), data_dir.get_tmp_dir(), interactive, selinux) else: # Some other test create_config_files(test_dir, shared_dir, interactive, step) create_subtests_cfg(test_name) create_guest_os_cfg(test_name) cartesian_parser = cartesian_config.Parser() cartesian_parser.parse_file( data_dir.get_backend_cfg_path(test_name, 'guest-os.cfg')) cartesian_parser.only_filter(guest_os) image_name = 'jeos-19-64' for params in cartesian_parser.get_dicts(): image_name = params.get('image_name', 'image').split('/')[-1] if download_image or restore_image: logging.info("") step += 2 logging.info("%s - Verifying (and possibly downloading) guest image", step) os_info = get_guest_os_info(test_name, guest_os) os_asset = os_info['asset'] asset.download_asset(os_asset, interactive=interactive, restore_image=restore_image) if check_modules: logging.info("") step += 1 logging.info("%d - Checking for modules %s", step, ", ".join(check_modules)) for module in check_modules: if not utils.module_is_loaded(module): logging.warning( "Module %s is not loaded. You might want to " "load it", module) else: logging.debug("Module %s loaded", module) if online_docs_url: logging.info("") step += 1 logging.info( "%d - If you wish, take a look at the online docs for " "more info", step) logging.info("") logging.info(online_docs_url)