Beispiel #1
0
def run_stress_boot(test, params, env):
    """
    Boots VMs until one of them becomes unresponsive, and records the maximum
    number of VMs successfully started:
    1) boot the first vm
    2) boot the second vm cloned from the first vm, check whether it boots up
       and all booted vms respond to shell commands
    3) go on until cannot create VM anymore or cannot allocate memory for VM

    @param test:   kvm test object
    @param params: Dictionary with the test parameters
    @param env:    Dictionary with test environment.
    """
    error.base_context("waiting for the first guest to be up", logging.info)
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()
    login_timeout = float(params.get("login_timeout", 240))
    session = vm.wait_for_login(timeout=login_timeout)

    num = 2
    sessions = [session]

    # Boot the VMs
    try:
        while num <= int(params.get("max_vms")):
            # Clone vm according to the first one
            error.base_context("booting guest #%d" % num, logging.info)
            vm_name = "vm%d" % num
            vm_params = vm.params.copy()
            curr_vm = vm.clone(vm_name, vm_params)
            env.register_vm(vm_name, curr_vm)
            virt_env_process.preprocess_vm(test, vm_params, env, vm_name)
            params["vms"] += " " + vm_name

            sessions.append(curr_vm.wait_for_login(timeout=login_timeout))
            logging.info("Guest #%d booted up successfully", num)

            # Check whether all previous shell sessions are responsive
            for i, se in enumerate(sessions):
                error.context("checking responsiveness of guest #%d" % (i + 1),
                              logging.debug)
                se.cmd(params.get("alive_test_cmd"))
            num += 1
    finally:
        for se in sessions:
            se.close()
        logging.info("Total number booted: %d" % (num -1))
Beispiel #2
0
def run_stress_boot(test, params, env):
    """
    Boots VMs until one of them becomes unresponsive, and records the maximum
    number of VMs successfully started:
    1) boot the first vm
    2) boot the second vm cloned from the first vm, check whether it boots up
       and all booted vms respond to shell commands
    3) go on until cannot create VM anymore or cannot allocate memory for VM

    @param test:   kvm test object
    @param params: Dictionary with the test parameters
    @param env:    Dictionary with test environment.
    """
    error.base_context("waiting for the first guest to be up", logging.info)
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()
    login_timeout = float(params.get("login_timeout", 240))
    session = vm.wait_for_login(timeout=login_timeout)

    num = 2
    sessions = [session]

    # Boot the VMs
    try:
        while num <= int(params.get("max_vms")):
            # Clone vm according to the first one
            error.base_context("booting guest #%d" % num, logging.info)
            vm_name = "vm%d" % num
            vm_params = vm.params.copy()
            curr_vm = vm.clone(vm_name, vm_params)
            env.register_vm(vm_name, curr_vm)
            virt_env_process.preprocess_vm(test, vm_params, env, vm_name)
            params["vms"] += " " + vm_name

            sessions.append(curr_vm.wait_for_login(timeout=login_timeout))
            logging.info("Guest #%d booted up successfully", num)

            # Check whether all previous shell sessions are responsive
            for i, se in enumerate(sessions):
                error.context("checking responsiveness of guest #%d" % (i + 1),
                              logging.debug)
                se.cmd(params.get("alive_test_cmd"))
            num += 1
    finally:
        for se in sessions:
            se.close()
        logging.info("Total number booted: %d" % (num - 1))
def run_trans_hugepage_swapping(test, params, env):
    """
    KVM khugepage user side test:
    1) Verify that the hugepages can be swapped in/out.

    @param test: KVM test object.
    @param params: Dictionary with test parameters.
    @param env: Dictionary with the test environment.
    """
    def get_args(args_list):
        """
        Get the memory arguments from system
        """
        args_list_tmp = args_list.copy()
        for line in file('/proc/meminfo', 'r').readlines():
            for key in args_list_tmp.keys():
                if line.startswith("%s" % args_list_tmp[key]):
                    args_list_tmp[key] = int(re.split('\s+', line)[1])
        return args_list_tmp

    test_config = virt_test_setup.TransparentHugePageConfig(test, params)
    try:
        test_config.setup()
        # Swapping test
        logging.info("Swapping test start")
        # Parameters of memory information
        # @total: Memory size
        # @free: Free memory size
        # @swap_size: Swap size
        # @swap_free: Free swap size
        # @hugepage_size: Page size of one hugepage
        # @page_size: The biggest page size that app can ask for
        args_dict_check = {"free" : "MemFree", "swap_size" : "SwapTotal",
                           "swap_free" : "SwapFree", "total" : "MemTotal",
                           "hugepage_size" : "Hugepagesize",}
        args_dict = get_args(args_dict_check)
        swap_free = []
        total = int(args_dict['total']) / 1024
        free = int(args_dict['free']) / 1024
        swap_size = int(args_dict['swap_size']) / 1024
        swap_free.append(int(args_dict['swap_free'])/1024)
        hugepage_size = int(args_dict['hugepage_size']) / 1024
        dd_timeout = float(params.get("dd_timeout", 900))
        login_timeout = float(params.get("login_timeout", 360))
        check_cmd_timeout = float(params.get("check_cmd_timeout", 900))
        mem_path = os.path.join(test.tmpdir, 'thp_space')
        tmpfs_path = "/space"

        # If swap is enough fill all memory with dd
        if swap_free > (total - free):
            count = total / hugepage_size
            tmpfs_size = total
        else:
            count = free / hugepage_size
            tmpfs_size = free

        if swap_size <= 0:
            raise logging.info("Host does not have swap enabled")
        session = None
        try:
            if not os.path.isdir(mem_path):
                os.makedirs(mem_path)
            utils.run("mount -t tmpfs  -o size=%sM none %s" % (tmpfs_size,
                                                               mem_path))

            # Set the memory size of vm
            # To ignore the oom killer set it to the free swap size
            vm = virt_test_utils.get_living_vm(env, params.get("main_vm"))
            if int(params['mem']) > swap_free[0]:
                vm.destroy()
                vm_name = 'vmsw'
                vm0 =  params.get("main_vm")
                vm0_key = virt_utils.env_get_vm(env, vm0)
                params['vms'] = params['vms'] + " " + vm_name
                params['mem'] = str(swap_free[0])
                vm_key = vm0_key.clone(vm0, params)
                virt_utils.env_register_vm(env, vm_name, vm_key)
                virt_env_process.preprocess_vm(test, params, env, vm_name)
                vm_key.create()
                session = virt_utils.wait_for(vm_key.remote_login,
                                              timeout=login_timeout)
            else:
                session = virt_test_utils.wait_for_login(vm,
                                                        timeout=login_timeout)

            error.context("making guest to swap memory")
            cmd = ("dd if=/dev/zero of=%s/zero bs=%s000000 count=%s" %
                   (mem_path, hugepage_size, count))
            utils.run(cmd)

            args_dict = get_args(args_dict_check)
            swap_free.append(int(args_dict['swap_free'])/1024)

            if swap_free[1] - swap_free[0] >= 0:
                raise error.TestFail("No data was swapped to memory")

            # Try harder to make guest memory to be swapped
            session.cmd("find / -name \"*\"", timeout=check_cmd_timeout)
        finally:
            if session is not None:
                utils.run("umount %s" % mem_path)

        logging.info("Swapping test succeed")

    finally:
        session.close()
        test_config.cleanup()
Beispiel #4
0
    # Associate pidfile name
    params['pid_' + vm_name] = virt_utils.generate_tmp_file_name(vm_name,
                                                                'pid')
    if not params.get('extra_params'):
        params['extra_params'] = ' '
    params['extra_params_' + vm_name] = params.get('extra_params')
    params['extra_params_' + vm_name] += (" -pidfile %s" %
                                          (params.get('pid_' + vm_name)))
    params['extra_params'] = params.get('extra_params_'+vm_name)

    # ksm_size: amount of memory used by allocator
    ksm_size = mem - guest_reserve
    logging.debug("Memory used by allocator on guests = %dM", ksm_size)

    # Creating the first guest
    virt_env_process.preprocess_vm(test, params, env, vm_name)
    lvms.append(env.get_vm(vm_name))
    if not lvms[0]:
        raise error.TestError("VM object not found in environment")
    if not lvms[0].is_alive():
        raise error.TestError("VM seems to be dead; Test requires a living "
                              "VM")

    logging.debug("Booting first guest %s", lvms[0].name)

    lsessions.append(lvms[0].wait_for_login(timeout=360))
    # Associate vm PID
    try:
        tmp = open(params.get('pid_' + vm_name), 'r')
        params['pid_' + vm_name] = int(tmp.readline())
    except Exception:
Beispiel #5
0
def run_smbios_table(test, params, env):
    """
    Check smbios table :
    1) Boot a guest with smbios options
    2) verify if host bios options have been emulated

    @param test: KVM test object.
    @param params: Dictionary with the test parameters.
    @param env: Dictionary with test environment.
    """
    vendor_cmd = "dmidecode --type 0 | grep Vendor | awk '{print $2}'"
    date_cmd = "dmidecode --type 0 | grep Date | awk '{print $3}'"
    version_cmd = "dmidecode --type 0 | grep Version | awk '{print $2}'"

    error.context("getting smbios table on host")
    host_vendor = utils.system_output(vendor_cmd)
    host_date = utils.system_output(date_cmd)
    host_version = utils.system_output(version_cmd)

    smbios = (" -smbios type=0,vendor=%s,version=%s,date=%s" %
              (host_vendor, host_version, host_date))

    extra_params = params.get("extra_params", "")
    params["extra_params"] = extra_params + smbios

    logging.debug("Booting guest %s", params.get("main_vm"))
    virt_env_process.preprocess_vm(test, params, env, params.get("main_vm"))
    vm = env.get_vm(params["main_vm"])
    vm.create()
    login_timeout = float(params.get("login_timeout", 360))
    session = vm.wait_for_login(timeout=login_timeout)

    error.context("getting smbios table on guest")
    guest_vendor = session.cmd(vendor_cmd).strip()
    guest_date = session.cmd(date_cmd).strip()
    guest_version = session.cmd(version_cmd).strip()

    failures = []

    if host_vendor != guest_vendor:
        e_msg = ("Vendor str mismatch -> host: %s guest: %s" %
                 (guest_vendor, host_vendor))
        logging.error(e_msg)
        failures.append(e_msg)

    if host_date != guest_date:
        e_msg = ("Date str mismatch -> host: %s guest: %s" %
                 (guest_date, host_date))
        logging.error(e_msg)
        failures.append(e_msg)

    if host_version != guest_version:
        e_msg = ("Version str mismatch -> host: %s guest: %s" %
                 (guest_version, host_version))
        logging.error(e_msg)
        failures.append(e_msg)

    error.context("")
    if failures:
        raise error.TestFail("smbios table test reported %s failures:\n%s" %
                             (len(failures), "\n".join(failures)))
Beispiel #6
0
    # Associate pidfile name
    params['pid_' + vm_name] = virt_utils.generate_tmp_file_name(
        vm_name, 'pid')
    if not params.get('extra_params'):
        params['extra_params'] = ' '
    params['extra_params_' + vm_name] = params.get('extra_params')
    params['extra_params_' + vm_name] += (" -pidfile %s" %
                                          (params.get('pid_' + vm_name)))
    params['extra_params'] = params.get('extra_params_' + vm_name)

    # ksm_size: amount of memory used by allocator
    ksm_size = mem - guest_reserve
    logging.debug("Memory used by allocator on guests = %dM", ksm_size)

    # Creating the first guest
    virt_env_process.preprocess_vm(test, params, env, vm_name)
    lvms.append(env.get_vm(vm_name))
    if not lvms[0]:
        raise error.TestError("VM object not found in environment")
    if not lvms[0].is_alive():
        raise error.TestError("VM seems to be dead; Test requires a living "
                              "VM")

    logging.debug("Booting first guest %s", lvms[0].name)

    lsessions.append(lvms[0].wait_for_login(timeout=360))
    # Associate vm PID
    try:
        tmp = open(params.get('pid_' + vm_name), 'r')
        params['pid_' + vm_name] = int(tmp.readline())
    except Exception:
Beispiel #7
0
    def commit_test(cmd):
        """
        Subcommand 'qemu-img commit' test.
        1) Create a backing file of the qemu harddisk specified by image_name.
        2) Start a VM using the backing file as its harddisk.
        3) Touch a file "commit_testfile" in the backing_file, and shutdown the
           VM.
        4) Make sure touching the file does not affect the original harddisk.
        5) Commit the change to the original harddisk by executing
           "qemu-img commit" command.
        6) Start the VM using the original harddisk.
        7) Check if the file "commit_testfile" exists.

        @param cmd: qemu-img base command.
        """
        cmd += " commit"

        logging.info("Commit testing started!")
        image_name = params.get("image_name", "image")
        image_format = params.get("image_format", "qcow2")
        backing_file_name = "%s_bak" % (image_name)

        try:
            # Remove the existing backing file
            backing_file = "%s.%s" % (backing_file_name, image_format)
            if os.path.isfile(backing_file):
                os.remove(backing_file)

            # Create the new backing file
            create_cmd = "qemu-img create -b %s.%s -f %s %s.%s" % (image_name,
                                                                  image_format,
                                                                  image_format,
                                                             backing_file_name,
                                                                  image_format)
            try:
                utils.system(create_cmd)
            except error.CmdError, e:
                raise error.TestFail("Could not create a backing file!")
            logging.info("backing_file created!")

            # Set the qemu harddisk to the backing file
            logging.info("Original image_name is: %s", params.get('image_name'))
            params['image_name'] = backing_file_name
            logging.info("Param image_name changed to: %s",
                         params.get('image_name'))

            # Start a new VM, using backing file as its harddisk
            vm_name = params.get('main_vm')
            virt_env_process.preprocess_vm(test, params, env, vm_name)
            vm = env.get_vm(vm_name)
            vm.create()
            timeout = int(params.get("login_timeout", 360))
            session = vm.wait_for_login(timeout=timeout)

            # Do some changes to the backing_file harddisk
            try:
                output = session.cmd("touch /commit_testfile")
                logging.info("Output of touch /commit_testfile: %s", output)
                output = session.cmd("ls / | grep commit_testfile")
                logging.info("Output of ls / | grep commit_testfile: %s",
                             output)
            except Exception, e:
                raise error.TestFail("Could not create commit_testfile in the "
                                     "backing file %s", e)
    def commit_test(cmd):
        """
        Subcommand 'qemu-img commit' test.
        1) Create a backing file of the qemu harddisk specified by image_name.
        2) Start a VM using the backing file as its harddisk.
        3) Touch a file "commit_testfile" in the backing_file, and shutdown the
           VM.
        4) Make sure touching the file does not affect the original harddisk.
        5) Commit the change to the original harddisk by executing
           "qemu-img commit" command.
        6) Start the VM using the original harddisk.
        7) Check if the file "commit_testfile" exists.

        @param cmd: qemu-img base command.
        """
        cmd += " commit"

        logging.info("Commit testing started!")
        image_name = params.get("image_name", "image")
        image_format = params.get("image_format", "qcow2")
        backing_file_name = "%s_bak" % (image_name)

        try:
            # Remove the existing backing file
            backing_file = "%s.%s" % (backing_file_name, image_format)
            if os.path.isfile(backing_file):
                os.remove(backing_file)

            # Create the new backing file
            create_cmd = "qemu-img create -b %s.%s -f %s %s.%s" % (
                image_name, image_format, image_format, backing_file_name,
                image_format)
            try:
                utils.system(create_cmd)
            except error.CmdError, e:
                raise error.TestFail("Could not create a backing file!")
            logging.info("backing_file created!")

            # Set the qemu harddisk to the backing file
            logging.info("Original image_name is: %s",
                         params.get('image_name'))
            params['image_name'] = backing_file_name
            logging.info("Param image_name changed to: %s",
                         params.get('image_name'))

            # Start a new VM, using backing file as its harddisk
            vm_name = params.get('main_vm')
            virt_env_process.preprocess_vm(test, params, env, vm_name)
            vm = env.get_vm(vm_name)
            vm.create()
            timeout = int(params.get("login_timeout", 360))
            session = vm.wait_for_login(timeout=timeout)

            # Do some changes to the backing_file harddisk
            try:
                output = session.cmd("touch /commit_testfile")
                logging.info("Output of touch /commit_testfile: %s", output)
                output = session.cmd("ls / | grep commit_testfile")
                logging.info("Output of ls / | grep commit_testfile: %s",
                             output)
            except Exception, e:
                raise error.TestFail(
                    "Could not create commit_testfile in the "
                    "backing file %s", e)
def run_unittest(test, params, env):
    """
    KVM RHEL-6 style unit test:
    1) Resume a stopped VM
    2) Wait for VM to terminate
    3) If qemu exited with code = 0, the unittest passed. Otherwise, it failed
    4) Collect all logs generated

    @param test: kvm test object
    @param params: Dictionary with the test parameters
    @param env: Dictionary with test environment
    """
    unittest_dir = os.path.join(test.bindir, 'unittests')
    if not os.path.isdir(unittest_dir):
        raise error.TestError("No unittest dir %s available (did you run the "
                              "build test first?)" % unittest_dir)
    os.chdir(unittest_dir)
    unittest_list = glob.glob('*.flat')
    if not unittest_list:
        raise error.TestError("No unittest files available (did you run the "
                              "build test first?)")
    logging.debug('Flat file list: %s', unittest_list)

    unittest_cfg = os.path.join(unittest_dir, 'unittests.cfg')
    parser = ConfigParser.ConfigParser()
    parser.read(unittest_cfg)
    test_list = parser.sections()

    if not test_list:
        raise error.TestError("No tests listed on config file %s" %
                              unittest_cfg)
    logging.debug('Unit test list: %s', test_list)

    if params.get('test_list'):
        test_list = params.get('test_list').split()
        logging.info('Original test list overriden by user')
        logging.info('User defined unit test list: %s', test_list)

    nfail = 0
    tests_failed = []

    timeout = int(params.get('unittest_timeout', 600))

    extra_params_original = params['extra_params']

    for t in test_list:
        logging.info('Running %s', t)

        flat_file = None
        if parser.has_option(t, 'file'):
            flat_file = parser.get(t, 'file')

        if flat_file is None:
            nfail += 1
            tests_failed.append(t)
            logging.error(
                'Unittest config file %s has section %s but no '
                'mandatory option file', unittest_cfg, t)
            continue

        if flat_file not in unittest_list:
            nfail += 1
            tests_failed.append(t)
            logging.error(
                'Unittest file %s referenced in config file %s but '
                'was not find under the unittest dir', flat_file, unittest_cfg)
            continue

        smp = None
        if parser.has_option(t, 'smp'):
            smp = int(parser.get(t, 'smp'))
            params['smp'] = smp

        extra_params = None
        if parser.has_option(t, 'extra_params'):
            extra_params = parser.get(t, 'extra_params')
            params['extra_params'] += ' %s' % extra_params

        vm_name = params.get("main_vm")
        params['kernel'] = os.path.join(unittest_dir, flat_file)
        testlog_path = os.path.join(test.debugdir, "%s.log" % t)

        try:
            try:
                vm_name = params.get('main_vm')
                virt_env_process.preprocess_vm(test, params, env, vm_name)
                vm = env.get_vm(vm_name)
                vm.create()
                vm.monitor.cmd("cont")
                logging.info(
                    "Waiting for unittest %s to complete, timeout %s, "
                    "output in %s", t, timeout, vm.get_testlog_filename())
                if not virt_utils.wait_for(vm.is_dead, timeout):
                    raise error.TestFail("Timeout elapsed (%ss)" % timeout)
                # Check qemu's exit status
                status = vm.process.get_status()
                if status != 0:
                    nfail += 1
                    tests_failed.append(t)
                    logging.error("Unit test %s failed", t)
            except Exception, e:
                nfail += 1
                tests_failed.append(t)
                logging.error('Exception happened during %s: %s', t, str(e))
        finally:
            try:
                shutil.copy(vm.get_testlog_filename(), testlog_path)
                logging.info("Unit test log collected and available under %s",
                             testlog_path)
            except (NameError, IOError):
                logging.error("Not possible to collect logs")

        # Restore the extra params so other tests can run normally
        params['extra_params'] = extra_params_original

    if nfail != 0:
        raise error.TestFail("Unit tests failed: %s" % " ".join(tests_failed))
Beispiel #10
0
def run_unittest(test, params, env):
    """
    KVM RHEL-6 style unit test:
    1) Resume a stopped VM
    2) Wait for VM to terminate
    3) If qemu exited with code = 0, the unittest passed. Otherwise, it failed
    4) Collect all logs generated

    @param test: kvm test object
    @param params: Dictionary with the test parameters
    @param env: Dictionary with test environment
    """
    unittest_dir = os.path.join(test.bindir, 'unittests')
    if not os.path.isdir(unittest_dir):
        raise error.TestError("No unittest dir %s available (did you run the "
                              "build test first?)" % unittest_dir)
    os.chdir(unittest_dir)
    unittest_list = glob.glob('*.flat')
    if not unittest_list:
        raise error.TestError("No unittest files available (did you run the "
                              "build test first?)")
    logging.debug('Flat file list: %s', unittest_list)

    unittest_cfg = os.path.join(unittest_dir, 'unittests.cfg')
    parser = ConfigParser.ConfigParser()
    parser.read(unittest_cfg)
    test_list = parser.sections()

    if not test_list:
        raise error.TestError("No tests listed on config file %s" %
                              unittest_cfg)
    logging.debug('Unit test list: %s', test_list)

    if params.get('test_list'):
        test_list = params.get('test_list').split()
        logging.info('Original test list overriden by user')
        logging.info('User defined unit test list: %s', test_list)

    nfail = 0
    tests_failed = []

    timeout = int(params.get('unittest_timeout', 600))

    extra_params_original = params['extra_params']

    for t in test_list:
        logging.info('Running %s', t)

        flat_file = None
        if parser.has_option(t, 'file'):
            flat_file = parser.get(t, 'file')

        if flat_file is None:
            nfail += 1
            tests_failed.append(t)
            logging.error('Unittest config file %s has section %s but no '
                          'mandatory option file', unittest_cfg, t)
            continue

        if flat_file not in unittest_list:
            nfail += 1
            tests_failed.append(t)
            logging.error('Unittest file %s referenced in config file %s but '
                          'was not find under the unittest dir', flat_file,
                          unittest_cfg)
            continue

        smp = None
        if parser.has_option(t, 'smp'):
            smp = int(parser.get(t, 'smp'))
            params['smp'] = smp

        extra_params = None
        if parser.has_option(t, 'extra_params'):
            extra_params = parser.get(t, 'extra_params')
            params['extra_params'] += ' %s' % extra_params

        vm_name = params.get("main_vm")
        params['kernel'] = os.path.join(unittest_dir, flat_file)
        testlog_path = os.path.join(test.debugdir, "%s.log" % t)

        try:
            try:
                vm_name = params.get('main_vm')
                virt_env_process.preprocess_vm(test, params, env, vm_name)
                vm = env.get_vm(vm_name)
                vm.create()
                vm.monitor.cmd("cont")
                logging.info("Waiting for unittest %s to complete, timeout %s, "
                             "output in %s", t, timeout,
                             vm.get_testlog_filename())
                if not virt_utils.wait_for(vm.is_dead, timeout):
                    raise error.TestFail("Timeout elapsed (%ss)" % timeout)
                # Check qemu's exit status
                status = vm.process.get_status()
                if status != 0:
                    nfail += 1
                    tests_failed.append(t)
                    logging.error("Unit test %s failed", t)
            except Exception, e:
                nfail += 1
                tests_failed.append(t)
                logging.error('Exception happened during %s: %s', t, str(e))
        finally:
            try:
                shutil.copy(vm.get_testlog_filename(), testlog_path)
                logging.info("Unit test log collected and available under %s",
                             testlog_path)
            except (NameError, IOError):
                logging.error("Not possible to collect logs")

        # Restore the extra params so other tests can run normally
        params['extra_params'] = extra_params_original

    if nfail != 0:
        raise error.TestFail("Unit tests failed: %s" % " ".join(tests_failed))