Пример #1
0
def load_kvm_modules(module_dir):
    """
    Unload previously loaded kvm modules, then load modules present on any
    sub directory of module_dir. Function will walk through module_dir until
    it finds the modules.

    @param module_dir: Directory where the KVM modules are located. 
    """
    vendor = "intel"
    if os.system("grep vmx /proc/cpuinfo 1>/dev/null") != 0:
        vendor = "amd"
    logging.debug("Detected CPU vendor as '%s'" %(vendor))

    logging.debug("Killing any qemu processes that might be left behind")
    utils.system("pkill qemu", ignore_status=True)

    logging.info("Unloading previously loaded KVM modules")
    kvm_utils.unload_module("kvm")
    if utils.module_is_loaded("kvm"):
        message = "Failed to remove old KVM modules"
        logging.error(message)
        raise error.TestError(message)

    logging.info("Loading new KVM modules...")
    kvm_module_path = None
    kvm_vendor_module_path = None
    # Search for the built KVM modules
    for folder, subdirs, files in os.walk(module_dir):
        if "kvm.ko" in files:
            kvm_module_path = os.path.join(folder, "kvm.ko")
            kvm_vendor_module_path = os.path.join(folder, "kvm-%s.ko" % vendor)
    abort = False
    if not kvm_module_path:
        logging.error("Need a directory containing both kernel module and "
                      "userspace sources.")
        logging.error("If you are trying to build only KVM userspace and use "
                      "the KVM modules you have already loaded, put "
                      "'load_modules': 'no' on the control file 'params' "
                      "dictionary.")
        raise error.TestError("Could not find a built kvm.ko module on the "
                              "source dir.")
    elif not os.path.isfile(kvm_vendor_module_path):
        logging.error("Could not find KVM (%s) module that was supposed to be"
                      " built on the source dir", vendor)
        abort = True
    if abort:
        raise error.TestError("Could not load KVM modules.")
    utils.system("/sbin/insmod %s" % kvm_module_path)
    time.sleep(1)
    utils.system("/sbin/insmod %s" % kvm_vendor_module_path)

    if not utils.module_is_loaded("kvm"):
        message = "Failed to load the KVM modules built for the test"
        logging.error(message)
        raise error.TestError(message)
    def try_load_mod(self, module):
        """
        Try to load a (non-crypto) module using the crypto UAPI
        @param module: name of the kernel module to try to load
        """
        if utils.module_is_loaded(module):
            utils.unload_module(module)

        path = os.path.join(self.srcdir, 'crypto_load_mod ')
        utils.system(path + module)

        if utils.module_is_loaded(module):
            utils.unload_module(module)
            raise error.TestFail('Able to load module "%s" using crypto UAPI' %
                                 module)
    def run_once(self):
        """
        This test will run the firmware request kernel self test (from
        upstream). This tests that the request_firmware() and
        request_firmware_nowait() kernel APIs are somewhat sane. It tries to
        load the empty filename ("") as well as a small toy firmware, and
        checks that it matches. It also makes sure a non-existent firmware
        cannot be found.

        We rerun the same test several times to increase the probability of
        catching errors.

        Needs to disable module locking so we can load test firmwares from
        non-standard locations (e.g., /tmp)
        """

        num_loops = 50
        module_name = "test_firmware"

        if not self.test_is_valid():
            raise error.TestNAError(
                "FW test module is not available for this test")

        utils.load_module(module_name)
        if not utils.module_is_loaded(module_name):
            raise error.TestNAError(
                "FW test module is not available for this test")

        try:
            self.set_module_locking(False)

            logging.info("iterations: %d", num_loops)

            for i in range(0, num_loops):
                self.do_fw_test()

        finally:
            self.set_module_locking(True)
            utils.unload_module(module_name)
Пример #4
0
    destination = os.path.join(base_dir, 'isos', 'windows')
    check_iso(url, destination, hash)

    logging.info("5 - Checking if qemu is installed (certify qemu and qemu-kvm "
                 "are in the place the default config expects)")
    qemu_default_paths = ['/usr/bin/qemu-kvm', '/usr/bin/qemu-img']
    for qemu_path in qemu_default_paths:
        if not os.path.isfile(qemu_path):
            logging.warning("No %s found. You might need to install qemu-kvm.",
                            qemu_path)
        else:
            logging.debug("%s present", qemu_path)

    logging.info("6 - Checking for the KVM module (make sure kvm is loaded "
                 "to accelerate qemu-kvm)")
    if not utils.module_is_loaded("kvm"):
        logging.warning("KVM module is not loaded. You might want to load it")
    else:
        logging.debug("KVM module loaded")

    logging.info("7 - Verify needed packages to get started")
    logging.info("Please take a look at the online documentation "
                 "http://www.linux-kvm.org/page/KVM-Autotest/Client_Install "
                 "(session 'Install Prerequisite packages')")

    client_dir = os.path.abspath(os.path.join(kvm_test_dir, "..", ".."))
    autotest_bin = os.path.join(client_dir, 'bin', 'autotest')
    control_file = os.path.join(kvm_test_dir, 'control')
    logging.info("When you are done fixing eventual warnings found, "
                 "you can run the kvm test using the command line AS ROOT:")
    logging.info("%s --verbose %s", autotest_bin, control_file)
        "are in the place the default config expects)")
    qemu_default_paths = ['/usr/bin/qemu-kvm', '/usr/bin/qemu-img']
    for qemu_path in qemu_default_paths:
        if not os.path.isfile(qemu_path):
            logging.warning("No %s found. You might need to install qemu-kvm.",
                            qemu_path)
        else:
            logging.debug("%s present", qemu_path)
    logging.info(
        "If you wish to change qemu-kvm to qemu or other binary path, "
        "you will have to modify tests.cfg")

    logging.info("")
    logging.info("6 - Checking for the KVM module (make sure kvm is loaded "
                 "to accelerate qemu-kvm)")
    if not utils.module_is_loaded("kvm"):
        logging.warning("KVM module is not loaded. You might want to load it")
    else:
        logging.debug("KVM module loaded")

    logging.info("")
    logging.info("7 - Verify needed packages to get started")
    logging.info("Please take a look at the online documentation "
                 "http://www.linux-kvm.org/page/KVM-Autotest/Client_Install "
                 "(session 'Install Prerequisite packages')")

    client_dir = os.path.abspath(os.path.join(kvm_test_dir, "..", ".."))
    autotest_bin = os.path.join(client_dir, 'bin', 'autotest')
    control_file = os.path.join(kvm_test_dir, 'control')

    logging.info("")