def get_tmp_dir(public=True): """ Get the most appropriate tmp dir location. :param public: If public for all users' access """ persistent_dir = get_settings_value('vt.common', 'tmp_dir', default="") if persistent_dir != "": return persistent_dir tmp_dir = None # apparmor deny /tmp/* /var/tmp/* and cause failure across tests # it is better to handle here if distro.detect().name == 'Ubuntu': tmp_dir = "/var/lib/libvirt/images" if not utils_path.usable_rw_dir(tmp_dir): logging.warning("Unable to write in '/var/lib/libvirt/images' " "on Ubuntu, apparmor might complain...") tmp_dir = None tmp_dir = data_dir.get_tmp_dir(basedir=tmp_dir) if public: tmp_dir_st = os.stat(tmp_dir) os.chmod( tmp_dir, tmp_dir_st.st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH | stat.S_IRGRP | stat.S_IROTH) return tmp_dir
def configure(self, parser): """ Add the subparser for the run action. :param parser: Main test runner parser. """ run_subcommand_parser = parser.subcommands.choices.get('run', None) if run_subcommand_parser is None: return vt_compat_group_common = run_subcommand_parser.add_argument_group( 'Virt-Test compat layer - Common options') vt_compat_group_qemu = run_subcommand_parser.add_argument_group( 'Virt-Test compat layer - QEMU options') vt_compat_group_libvirt = run_subcommand_parser.add_argument_group( 'Virt-Test compat layer - Libvirt options') add_basic_vt_options(vt_compat_group_common) add_qemu_bin_vt_option(vt_compat_group_qemu) vt_compat_group_qemu.add_argument("--vt-extra-params", nargs='*', dest="vt.extra_params", help="List of 'key=value' pairs " "passed to cartesian parser.") supported_uris = ", ".join(SUPPORTED_LIBVIRT_URIS) msg = ("Choose test connect uri for libvirt (E.g: %s). " "Current: %%(default)s" % supported_uris) uri_current = get_settings_value('vt.libvirt', 'connect_uri', default=None) vt_compat_group_libvirt.add_argument("--vt-connect-uri", action="store", dest="vt.libvirt.connect_uri", default=uri_current, help=msg)
def __init__(self, **kwargs): self.log = logging.getLogger("avocado.app") lock_dir = get_settings_value("plugins.vtjoblock", "dir", key_type=str, default='/tmp') self.lock_dir = os.path.expanduser(lock_dir) self.lock_file = None
def add_qemu_bin_vt_option(parser): """ Add qemu-bin vt option to parser """ def _str_or_none(arg): if arg is None: return "Could not find one" else: return arg try: qemu_bin_path = standalone_test.find_default_qemu_paths()[0] except (RuntimeError, utils_path.CmdNotFoundError): qemu_bin_path = None qemu_bin = get_settings_value('vt.qemu', 'qemu_bin', default=None) if qemu_bin is None: # Allow default to be None when not set in setting default_qemu_bin = None qemu_bin = qemu_bin_path else: default_qemu_bin = qemu_bin help_msg = ("Path to a custom qemu binary to be tested. If --vt-config is " "provided and this flag is omitted, no attempt to set the " "qemu binaries will be made. Current: %s" % _str_or_none(qemu_bin)) add_option(parser, dest='vt.qemu.qemu_bin', arg='--vt-qemu-bin', default=default_qemu_bin, help=help_msg) qemu_dst = get_settings_value('vt.qemu', 'qemu_dst_bin', default=qemu_bin_path) help_msg = ("Path to a custom qemu binary to be tested for the destination" " of a migration, overrides --vt-qemu-bin. If --vt-config is " "provided and this flag is omitted, no attempt to set the qemu" " binaries will be made. Current: %s" % _str_or_none(qemu_dst)) add_option(parser, dest='vt.qemu.qemu_dst_bin', arg='--vt-qemu-dst-bin', default=qemu_dst, help=help_msg)
def add_basic_vt_options(parser): """ Add basic vt options to parser """ parser.add_argument("--vt-config", action="store", dest="vt.config", help="Explicitly choose a cartesian config. When " "choosing this, some options will be ignored (see " "options below)") msg = ("Choose test type (%s). Default: %%(default)s" % ", ".join(SUPPORTED_TEST_TYPES)) parser.add_argument("--vt-type", action="store", dest="vt.type", help=msg, default=SUPPORTED_TEST_TYPES[0]) arch = get_settings_value('vt.common', 'arch', default=None) parser.add_argument("--vt-arch", help="Choose the VM architecture. " "Default: %(default)s", default=arch, dest='vt.common.arch') machine = get_settings_value('vt.common', 'machine_type', default=defaults.DEFAULT_MACHINE_TYPE) parser.add_argument("--vt-machine-type", help="Choose the VM machine type." " Default: %(default)s", default=machine, dest='vt.common.machine_type') parser.add_argument("--vt-guest-os", action="store", dest="vt.guest_os", default=defaults.DEFAULT_GUEST_OS, help="Select the guest OS to be used. If --vt-config " "is provided, this will be ignored. Default: " "%(default)s") parser.add_argument("--vt-no-filter", action="store", dest="vt.no_filter", default="", help="List of space separated 'no' filters" " to be passed to the config parser. Default: " "'%(default)s'") parser.add_argument("--vt-only-filter", action="store", dest="vt.only_filter", default="", help="List of space" " separated 'only' filters to be passed to the config " "parser. Default: '%(default)s'") parser.add_argument("--vt-filter-default-filters", nargs='+', help="Allows to selectively skip certain default " "filters. This uses directly 'tests-shared.cfg' and " "instead of '$provider/tests.cfg' and applies " "following lists of default filters, unless they are " "specified as arguments: no_9p_export,no_virtio_rng," "no_pci_assignable,smallpages,default_bios,bridge," "image_backend,multihost. This can be used to eg. " "run hugepages tests by filtering 'smallpages' via " "this option.", dest='vt.filter.default_filters')
def add_basic_vt_options(parser): """ Add basic vt options to parser """ help_msg = ("Explicitly choose a cartesian config. When choosing this, " "some options will be ignored (see options below)") add_option(parser, dest='vt.config', arg='--vt-config', help=help_msg) help_msg = "Save the resulting cartesian config to a file" add_option(parser, dest='vt.save_config', arg='--vt-save-config', help=help_msg) help_msg = ("Choose test type (%s). Default: %%(default)s" % ", ".join(SUPPORTED_TEST_TYPES)) add_option(parser, dest='vt.type', arg='--vt-type', default=SUPPORTED_TEST_TYPES[0], help=help_msg) arch = get_settings_value('vt.common', 'arch', default=None) help_msg = "Choose the VM architecture. Default: %(default)s" add_option(parser, dest='vt.common.arch', arg='--vt-arch', default=arch, help=help_msg) machine = get_settings_value('vt.common', 'machine_type', default=defaults.DEFAULT_MACHINE_TYPE) help_msg = "Choose the VM machine type. Default: %(default)s" add_option(parser, dest='vt.common.machine_type', arg='--vt-machine-type', default=machine, help=help_msg) help_msg = ("Select the guest OS to be used. If --vt-config is provided, " "this will be ignored. Default: %(default)s") add_option(parser, dest='vt.guest_os', arg='--vt-guest-os', default=defaults.DEFAULT_GUEST_OS, help=help_msg) help_msg = ("List of space separated 'no' filters to be passed to the " "config parser. Default: '%(default)s'") add_option(parser, dest='vt.no_filter', arg='--vt-no-filter', default="", help=help_msg) help_msg = ("List of space separated 'only' filters to be passed to the " "config parser. Default: '%(default)s'") add_option(parser, dest='vt.only_filter', arg='--vt-only-filter', default="", help=help_msg) help_msg = ( "Allows to selectively skip certain default filters. This uses " "directly 'tests-shared.cfg' and instead of " "'$provider/tests.cfg' and applies following lists of default " "filters, unless they are specified as arguments: " "no_9p_export,no_virtio_rng,no_pci_assignable,smallpages," "default_bios,bridge,image_backend,multihost. This can be used" " to eg. run hugepages tests by filtering 'smallpages' via " "this option.") add_option(parser, dest='vt.filter.default_filters', arg='--vt-filter-default-filters', nargs='+', help=help_msg)
SETUP_MODULES = imp.load_source('autotest_setup_modules', SETUP_MODULES_PATH) SETUP_MODULES.setup(base_path=CLIENT_DIR, root_module_name="autotest.client") # The code below is used by this plugin to find the virt test directory, # so that it can load the virttest python lib, used by the plugin code. # If the user doesn't provide the proper configuration, the plugin will # fail to load. VIRT_TEST_PATH = None if 'VIRT_TEST_PATH' in os.environ: VIRT_TEST_PATH = os.environ['VIRT_TEST_PATH'] else: VIRT_TEST_PATH = get_settings_value(section='virt_test', key='virt_test_path', default=None) if VIRT_TEST_PATH is not None: sys.path.append(os.path.expanduser(VIRT_TEST_PATH)) from virttest import data_dir # pylint: disable=C0413 _PROVIDERS_DOWNLOAD_DIR = os.path.join(data_dir.get_test_providers_dir(), 'downloads') try: assert len(os.listdir(_PROVIDERS_DOWNLOAD_DIR)) != 0 except (OSError, AssertionError): raise EnvironmentError("Bootstrap missing. " "Execute 'avocado vt-bootstrap' or disable this "
def initialize(self): if not is_registering_settings_required(): return # [vt] section section = 'vt' help_msg = ('Explicitly choose a cartesian config. When choosing ' 'this, some options will be ignored (see options ' 'below)') settings.register_option(section, key='config', default=None, help_msg=help_msg) help_msg = 'Save the resulting cartesian config to a file' settings.register_option(section, key='save_config', default=None, help_msg=help_msg) help_msg = ("Choose test type (%s). Default: %%(default)s" % ", ".join(SUPPORTED_TEST_TYPES)) settings.register_option(section, key='type', default=SUPPORTED_TEST_TYPES[0], help_msg=help_msg) help_msg = ("Select the guest OS to be used. If --vt-config is " "provided, this will be ignored. Default: %s" % DEFAULT_GUEST_OS) settings.register_option(section, key='guest_os', default=DEFAULT_GUEST_OS, help_msg=help_msg) help_msg = ("List of space separated 'no' filters to be passed to " "the config parser.") settings.register_option(section, key='no_filter', default='', help_msg=help_msg) help_msg = ("List of space separated 'only' filters to be passed " "to the config parser.") settings.register_option(section, key='only_filter', default='', help_msg=help_msg) help_msg = "List of 'key=value' pairs passed to cartesian parser." settings.register_option(section, key='extra_params', nargs='*', default=None, help_msg=help_msg) help_msg = ("Also list the available guests (this option ignores " "the --vt-config and --vt-guest-os)") settings.register_option(section, key='list_guests', key_type=bool, default=False, help_msg=help_msg) help_msg = ("Also list the available arch/machines for the given " "guest OS. (Use \"--vt-guest-os ''\" to see all " "combinations; --vt-config --vt-machine-type and " "--vt-arch args are ignored)") settings.register_option(section, key='list_archs', key_type=bool, default=False, help_msg=help_msg) # [vt.setup] section section = 'vt.setup' help_msg = 'Backup image before testing (if not already backed up)' settings.register_option(section, 'backup_image_before_test', help_msg=help_msg, key_type=bool, default=True) help_msg = 'Restore image after testing (if backup present)' settings.register_option(section, 'restore_image_after_test', help_msg=help_msg, key_type=bool, default=True) help_msg = 'Keep guest running between tests (faster, but unsafe)' settings.register_option(section, 'keep_guest_running', help_msg=help_msg, key_type=bool, default=False) # [vt.common] section section = 'vt.common' help_msg = ('Data dir path. If none specified, the default ' 'virt-test data dir will be used') settings.register_option(section, 'data_dir', help_msg=help_msg, default='') help_msg = ('Make the temporary dir path persistent across jobs if' ' needed. By default the data in the temporary ' 'directory will be wiped after each test in some cases' ' and after each job in others.') settings.register_option(section, 'tmp_dir', help_msg=help_msg, default='') help_msg = ('Enable only type specific tests. Shared tests will ' 'not be tested') settings.register_option(section, 'type_specific_only', help_msg=help_msg, key_type=bool, default=False) help_msg = ('RAM dedicated to the main VM. Usually defaults to ' '1024, as set in "base.cfg", but can be a different ' 'value depending on the various other configuration ' 'files such as configuration files under "guest-os" ' 'and test provider specific files') settings.register_option(section, 'mem', help_msg=help_msg, default=None) help_msg = 'Architecture under test' settings.register_option(section, 'arch', help_msg=help_msg, default=None) help_msg = 'Machine type under test' settings.register_option(section, 'machine_type', help_msg=help_msg, default=DEFAULT_MACHINE_TYPE) help_msg = 'Nettype (bridge, user, none)' settings.register_option(section, 'nettype', help_msg=help_msg, default='') help_msg = 'Bridge name to be used if you select bridge as a nettype' settings.register_option(section, 'netdst', help_msg=help_msg, default='virbr0') # [vt.qemu] section section = 'vt.qemu' try: default_qemu_bin_path = find_default_qemu_paths()[0] except (RuntimeError, utils_path.CmdNotFoundError): default_qemu_bin_path = None qemu_bin = get_settings_value(section, 'qemu_bin', default=None) if qemu_bin is None: # Allow default to be None when not set in setting default_qemu_bin = None else: default_qemu_bin = qemu_bin help_msg = 'Path to a custom qemu binary to be tested' settings.register_option(section, 'qemu_bin', help_msg=help_msg, default=default_qemu_bin) help_msg = ('Path to a custom qemu binary to be tested for the ' 'destination of a migration, overrides qemu_bin for ' 'that particular purpose') settings.register_option(section, 'qemu_dst_bin', help_msg=help_msg, default=default_qemu_bin_path) help_msg = 'Accelerator used to run qemu (kvm or tcg)' settings.register_option(section, 'accel', help_msg=help_msg, default='kvm') help_msg = ('Whether to enable vhost for qemu (on/off/force). ' 'Depends on nettype=bridge') settings.register_option(section, 'vhost', help_msg=help_msg, default='off') help_msg = 'Monitor type (human or qmp)' settings.register_option(section, 'monitor', help_msg=help_msg, default='') help_msg = 'Number of virtual cpus to use (1 or 2)' settings.register_option(section, 'smp', help_msg=help_msg, default='2') help_msg = 'Image format type to use (any valid qemu format)' settings.register_option(section, 'image_type', help_msg=help_msg, default=SUPPORTED_IMAGE_TYPES[0]) help_msg = 'Guest network card model (any valid qemu card)' settings.register_option(section, 'nic_model', help_msg=help_msg, default=SUPPORTED_NIC_MODELS[0]) help_msg = ('Guest disk bus for main image. One of ide, scsi, ' 'virtio_blk, virtio_scsi, lsi_scsi, ahci, usb2 ' 'or xenblk. Note: Older qemu versions and/or ' 'operating systems (such as WinXP) might not support ' 'virtio_scsi. Please use virtio_blk or ide instead.') settings.register_option(section, 'disk_bus', help_msg=help_msg, default=SUPPORTED_DISK_BUSES[0]) help_msg = 'Enable qemu sandboxing (on/off)' settings.register_option(section, 'sandbox', help_msg=help_msg, default='on') help_msg = ('Prevent qemu from loading sysconfdir/qemu.conf ' 'and sysconfdir/target-ARCH.conf at startup (yes/no)') settings.register_option(section, 'defconfig', help_msg=help_msg, default='yes') help_msg = ('Use MALLOC_PERTURB_ env variable set to 1 to help ' 'catch memory allocation problems on qemu (yes/no)') settings.register_option(section, 'malloc_perturb', help_msg=help_msg, default='yes') # [vt.libvirt] section section = 'vt.libvirt' uri_current = get_settings_value(section, 'connect_uri', default=None) help_msg = ('Test connect URI for libvirt (qemu:///system, ' 'lxc:///)') settings.register_option(section, 'connect_uri', help_msg=help_msg, default=uri_current) # [vt.debug] section help_msg = ('Do not clean up tmp files or VM processes at the end ' 'of a virt-test execution') settings.register_option('vt.debug', 'no_cleanup', help_msg=help_msg, key_type=bool, default=False) # [vt.filter] section help_msg = ("Allows to selectively skip certain default filters. " "This uses directly 'tests-shared.cfg' and instead of " "'$provider/tests.cfg' and applies following lists of " "default filters, unless they are specified as " "arguments: no_9p_export,no_virtio_rng," "no_pci_assignable,smallpages,default_bios,ridge," "image_backend,multihost. This can be used to eg. run " "hugepages tests by filtering 'smallpages' via this " "option.") settings.register_option('vt.filter', key='default_filters', nargs='+', default=None, help_msg=help_msg) # [plugins.vtjoblock] section help_msg = 'Directory in which to write the lock file' settings.register_option('plugins.vtjoblock', 'dir', help_msg=help_msg, default='/tmp') virt_loader = getattr(importlib.import_module('avocado_vt.loader'), 'VirtTestLoader') loader.register_plugin(virt_loader)