예제 #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)
예제 #2
0
파일: build.py 프로젝트: wenhann/chromiumos
def load_kvm_modules(module_dir=None, load_stock=False, extra_modules=None):
    """
    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.
    @param load_stock: Whether we are going to load system kernel modules.
    @param extra_modules: List of extra modules to load.
    """
    vendor = "intel"
    if os.system("grep vmx /proc/cpuinfo 1>/dev/null") != 0:
        vendor = "amd"
    logging.debug("Detected CPU vendor as '%s'" %(vendor))

    kill_qemu_processes()

    logging.info("Unloading previously loaded KVM modules")
    kvm_utils.unload_module("kvm")
    if extra_modules:
        for module in extra_modules:
            kvm_utils.unload_module(module)

    if module_dir:
        logging.info("Loading the built KVM modules...")
        kvm_module_path = None
        kvm_vendor_module_path = None
        abort = False

        list_modules = ['kvm.ko', 'kvm-%s.ko' % vendor]
        if extra_modules:
            for extra_module in extra_modules:
                list_modules.append('%s.ko' % extra_module)

        list_module_paths = []
        for folder, subdirs, files in os.walk(module_dir):
            for module in list_modules:
                if module in files:
                    module_path = os.path.join(folder, module)
                    list_module_paths.append(module_path)

        # We might need to arrange the modules in the correct order
        # to avoid module load problems
        list_modules_load = []
        for module in list_modules:
            for module_path in list_module_paths:
                if os.path.basename(module_path) == module:
                    list_modules_load.append(module_path)

        if len(list_module_paths) != len(list_modules):
            logging.error("KVM modules not found. If you don't want to use the "
                          "modules built by this test, make sure the option "
                          "load_modules: 'no' is marked on the test control "
                          "file.")
            raise error.TestError("The modules %s were requested to be loaded, "
                                  "but the only modules found were %s" %
                                  (list_modules, list_module_paths))

        for module_path in list_modules_load:
            try:
                utils.system("insmod %s" % module_path)
            except Exception, e:
                raise error.TestFail("Failed to load KVM modules: %s" % e)