def _save_parser_cartesian_config(self, parser): path = get_opt(self.config, 'vt.save_config') if path is None: return with open(path, 'w') as cartesian_config: cartesian_config.write("include %s\n" % parser.filename) for statement in (parser.only_filters + parser.no_filters + parser.assignments): cartesian_config.write("%s\n" % statement)
def _process_libvirt_specific_options(self): """ Calls for processing all options specific to libvirt test. """ uri_setting = 'config vt.libvirt.connect_uri' if get_opt(self.config, 'vt.libvirt.connect_uri'): driver_found = False for driver in SUPPORTED_LIBVIRT_DRIVERS: if get_opt(self.config, 'vt.libvirt.connect_uri').count(driver): driver_found = True self.cartesian_parser.only_filter(driver) if not driver_found: raise ValueError( "Unsupported %s '%s'" % (uri_setting, get_opt(self.config, 'vt.libvbirt.connect_uri'))) else: self.cartesian_parser.only_filter("qemu")
def discover(self, url, which_tests=LOADER_DEFAULT): try: cartesian_parser = self._get_parser() except Exception as details: return self._report_bad_discovery(url, details, which_tests) if url is not None: try: cartesian_parser.only_filter(url) # If we have a LexerError, this means # the url passed is invalid in the cartesian # config parser, hence it should be ignored. # just return an empty params list and let # the other test plugins to handle the URL. except cartesian_config.ParserError as details: return self._report_bad_discovery(url, details, which_tests) elif which_tests is LOADER_DEFAULT and not get_opt( self.args, 'vt_config'): # By default don't run anythinig unless vt_config provided return [] # Create test_suite test_suite = [] for params in (_ for _ in cartesian_parser.get_dicts()): # Evaluate the proper avocado-vt test name test_name = None if get_opt(self.args, 'vt_config'): test_name = params.get("shortname") elif get_opt(self.args, 'vt_type') == "spice": short_name_map_file = params.get("_short_name_map_file") if "tests-variants.cfg" in short_name_map_file: test_name = short_name_map_file["tests-variants.cfg"] if test_name is None: test_name = params.get("_short_name_map_file")["subtests.cfg"] # We want avocado to inject params coming from its multiplexer into # the test params. This will allow users to access avocado params # from inside virt tests. This feature would only work if the virt # test in question is executed from inside avocado. params['id'] = test_name test_parameters = {'name': test_name, 'vt_params': params} test_suite.append((VirtTest, test_parameters)) if which_tests is LOADER_ALL and not test_suite: return self._report_bad_discovery(url, "No matching tests", which_tests) return test_suite
def _process_options(self): """ Process the options given in the command line. """ cfg = None vt_type_setting = 'option --vt-type' vt_config_setting = 'option --vt-config' vt_type = get_opt(self.options, 'vt_type') vt_config = get_opt(self.options, 'vt_config') if (not vt_type) and (not vt_config): raise ValueError("No %s or %s specified" % (vt_type_setting, vt_config_setting)) if vt_type: if vt_type not in SUPPORTED_TEST_TYPES: raise ValueError( "Invalid %s %s. Valid values: %s. " % (vt_type_setting, vt_type, " ".join(SUPPORTED_TEST_TYPES))) self.cartesian_parser = cartesian_config.Parser(debug=False) if vt_config: cfg = os.path.abspath(vt_config) self.cartesian_parser.parse_file(cfg) elif get_opt(self.options, 'vt_filter_default_filters'): cfg = data_dir.get_backend_cfg_path(vt_type, 'tests-shared.cfg') self.cartesian_parser.parse_file(cfg) for arg in ('no_9p_export', 'no_virtio_rng', 'no_pci_assignable', 'smallpages', 'default_bios', 'bridge'): if arg not in get_opt(self.options, 'vt_filter_default_filters'): self.cartesian_parser.only_filter(arg) if 'image_backend' not in get_opt(self.options, 'vt_filter_default_filters'): self.cartesian_parser.only_filter('(image_backend=' 'filesystem)') if 'multihost' not in get_opt(self.options, 'vt_filter_default_filters'): self.cartesian_parser.no_filter('multihost') else: cfg = data_dir.get_backend_cfg_path(vt_type, 'tests.cfg') self.cartesian_parser.parse_file(cfg) if vt_type != 'lvsb': self._process_general_options() if vt_type == 'qemu': self._process_qemu_specific_options() elif vt_type == 'lvsb': self._process_lvsb_specific_options() elif vt_type == 'openvswitch': self._process_qemu_specific_options() elif vt_type == 'libvirt': self._process_libvirt_specific_options() elif vt_type == 'spice': self._process_spice_specific_options() self._process_extra_params()
def _process_qemu_bin(self): """ Puts the value of the qemu bin option in the cartesian parser command. """ qemu_bin_setting = ('option --vt-qemu-bin or ' 'config vt.qemu.qemu_bin') if (get_opt(self.config, 'vt.config') and get_opt(self.config, 'vt.qemu.qemu_bin') is None): LOG.info( "Config provided and no %s set. Not trying " "to automatically set qemu bin.", qemu_bin_setting) else: (qemu_bin_path, qemu_img_path, qemu_io_path, qemu_dst_bin_path) = standalone_test.find_default_qemu_paths( get_opt(self.config, 'vt.qemu.qemu_bin'), get_opt(self.config, 'vt.qemu.qemu_dst_bin')) self.cartesian_parser.assign("qemu_binary", qemu_bin_path) self.cartesian_parser.assign("qemu_img_binary", qemu_img_path) self.cartesian_parser.assign("qemu_io_binary", qemu_io_path) if qemu_dst_bin_path is not None: self.cartesian_parser.assign("qemu_dst_binary", qemu_dst_bin_path)
def guest_listing(options): """ List available guest os and info about image availability """ if get_opt(options, 'vt_type') == 'lvsb': raise ValueError("No guest types available for lvsb testing") LOG.debug("Using %s for guest images\n", os.path.join(data_dir.get_data_dir(), 'images')) LOG.info("Available guests in config:") guest_name_parser = standalone_test.get_guest_name_parser(options) for params in guest_name_parser.get_dicts(): base_dir = params.get("images_base_dir", data_dir.get_data_dir()) image_name = storage.get_image_filename(params, base_dir) machine_type = get_opt(options, 'vt_machine_type') name = params['name'].replace('.%s' % machine_type, '') if os.path.isfile(image_name): out = name else: missing = "(missing %s)" % os.path.basename(image_name) out = (name + " " + output.TERM_SUPPORT.warn_header_str(missing)) LOG.debug(out) LOG.debug("")
def convert_parameters(self, params): """ Evaluates the proper avocado-vt test name and params. :param params: cartesian config parameters :type params: dict :return: dict with test name and vt parameters """ test_name = params.get("_short_name_map_file")["subtests.cfg"] if (get_opt(self.config, 'vt.config') and get_opt(self.config, 'vt.short_names_when_config')): test_name = params.get("shortname") elif get_opt(self.config, 'vt.type') == "spice": short_name_map_file = params.get("_short_name_map_file") if "tests-variants.cfg" in short_name_map_file: test_name = short_name_map_file.get("tests-variants.cfg", test_name) # We want avocado to inject params coming from its multiplexer into # the test params. This will allow users to access avocado params # from inside virt tests. This feature would only work if the virt # test in question is executed from inside avocado. params['id'] = test_name test_parameters = {'name': test_name, 'vt_params': params} return test_parameters
def _process_vhost(self): nettype_setting = 'config vt.qemu.nettype' vhost_setting = 'config vt.qemu.vhost' if not get_opt(self.options, 'vt_config'): if get_opt(self.options, 'vt_nettype') == "bridge": if get_opt(self.options, 'vt_vhost') == "on": self.cartesian_parser.assign("vhost", "on") elif get_opt(self.options, 'vt_vhost') == "force": self.cartesian_parser.assign("netdev_extra_params", '",vhostforce=on"') self.cartesian_parser.assign("vhost", "on") else: if get_opt(self.options, 'vt_vhost') in ["on", "force"]: raise ValueError( "%s '%s' is incompatible with %s '%s'" % (nettype_setting, get_opt(self.options, 'vt_nettype'), vhost_setting, get_opt(self.options, 'vt_vhost'))) else: logging.info("Config provided, ignoring %s", vhost_setting)
def _process_guest_os(self): guest_os_setting = 'option --vt-guest-os' if get_opt(self.config, 'vt.type') == 'spice': LOG.info("Ignoring predefined OS: %s", guest_os_setting) return if not get_opt(self.config, 'vt.config'): if len(standalone_test.get_guest_name_list(self.config)) == 0: raise ValueError( "%s '%s' is not on the known guest os for " "arch '%s' and machine type '%s'. (see " "--vt-list-guests)" % (guest_os_setting, get_opt(self.config, 'vt.guest_os'), get_opt(self.config, 'vt.common.arch'), get_opt(self.config, 'vt.common.machine_type'))) self.cartesian_parser.only_filter( get_opt(self.config, 'vt.guest_os') or defaults.DEFAULT_GUEST_OS) else: LOG.info("Config provided, ignoring %s", guest_os_setting)
def _process_no_filter(self): if get_opt(self.options, 'vt_no_filter'): for item in get_opt(self.options, 'vt_no_filter').split(' '): self.cartesian_parser.no_filter(item)
def _process_only_type_specific(self): if not get_opt(self.config, 'vt.config'): if get_opt(self.config, 'vt.type_specific'): self.cartesian_parser.only_filter("(subtest=type_specific)")
def _add_if_not_exist(arg, value): if not get_opt(self.args, arg): set_opt(self.args, arg, value)
def _process_only_filter(self): if get_opt(self.config, 'vt.only_filter'): for item in get_opt(self.config, 'vt.only_filter').split(' '): self.cartesian_parser.only_filter(item)
def _process_extra_params(self): if get_opt(self.config, "vt.extra_params"): for param in get_opt(self.config, "vt.extra_params"): key, value = param.split('=', 1) self.cartesian_parser.assign(key, value)
def _process_mem(self): if not get_opt(self.config, 'vt.config'): mem = get_opt(self.config, 'vt.common.mem') if mem is not None: self.cartesian_parser.assign("mem", mem)
def _process_restart_vm(self): if not get_opt(self.config, 'vt.config'): if not get_opt(self.config, 'vt.setup.keep_guest_running'): self.cartesian_parser.assign("kill_vm", "yes")
def _process_malloc_perturb(self): self.cartesian_parser.assign( "malloc_perturb", get_opt(self.options, 'vt_malloc_perturb'))
def _process_qemu_accel(self): """ Puts the value of the qemu bin option in the cartesian parser command. """ if get_opt(self.config, 'vt.qemu.accel') == 'tcg': self.cartesian_parser.assign("disable_kvm", "yes")
def _process_malloc_perturb(self): self.cartesian_parser.assign( "malloc_perturb", get_opt(self.config, 'vt.qemu.malloc_perturb'))