Exemplo n.º 1
0
def run(test, params, env):
    """
    Acpi hmat test

    :param test: QEMU test object
    :param params: Dictionary with the test parameters
    :param env: Dictionary with test environment.
    """
    qemu_path = utils_misc.get_qemu_binary(params)
    qemu_version = env_process._get_qemu_version(qemu_path)
    version_pattern = r'%s-(\d+\.\d+\.\d+)' % os.path.basename(qemu_path)
    host_qemu = re.findall(version_pattern, qemu_version)[0]
    if host_qemu in VersionInterval('[,5.2.0)'):
        params['numa_hmat_caches_size_hmat_cache1'] = '50K'
        params['numa_hmat_caches_size_hmat_cache2'] = '40K'
        params['numa_hmat_caches_size_hmat_cache3'] = '80K'
        params['numa_hmat_caches_size_hmat_cache4'] = '70K'
        params['numa_hmat_caches_size_hmat_cache5'] = '60K'
    else:
        params['numa_hmat_caches_size_hmat_cache1'] = '40K'
        params['numa_hmat_caches_size_hmat_cache2'] = '50K'
        params['numa_hmat_caches_size_hmat_cache3'] = '60K'
        params['numa_hmat_caches_size_hmat_cache4'] = '70K'
        params['numa_hmat_caches_size_hmat_cache5'] = '80K'

    params['start_vm'] = 'yes'
    vm_name = params['main_vm']
    env_process.preprocess_vm(test, params, env, vm_name)
    vm = env.get_vm(vm_name)
    vm.wait_for_login()
Exemplo n.º 2
0
    def change_throttle_group(self, image, group_id):
        """
        Change image to other throttle group.

        :param image: Image name of disk.
        :param group_id: New throttle group id.
        """

        node_name = "drive_" + image

        throttle_blockdev = self._vm.devices.get_by_qid(node_name)[0]

        old_throttle_group = self._vm.devices.get_by_qid(
            throttle_blockdev.get_param("throttle-group"))[0]
        new_throttle_group = self._vm.devices.get_by_qid(group_id)[0]
        file = throttle_blockdev.get_param("file")
        args = {"driver": "throttle", "node-name": node_name, "file": file,
                "throttle-group": group_id}
        if self._vm.devices.qemu_version in VersionInterval("[6.1.0, )"):
            self._monitor.blockdev_reopen({"options": [args]})
        else:
            self._monitor.x_blockdev_reopen(args)

        for bus in old_throttle_group.child_bus:
            bus.remove(throttle_blockdev)

        throttle_blockdev.parent_bus = (
            {"busid": group_id}, {"type": "ThrottleGroup"})
        throttle_blockdev.set_param("throttle-group", group_id)

        for bus in new_throttle_group.child_bus:
            bus.insert(throttle_blockdev)
Exemplo n.º 3
0
 def wait_mirror_jobs_done(self):
     qemu_binary = utils_misc.get_qemu_binary(self.params)
     qemu_version = utils_qemu.get_qemu_version(qemu_binary)[0]
     required_qemu_version = self.params["required_qemu_version"]
     if qemu_version in VersionInterval(required_qemu_version):
         self.wait_mirror_jobs_cancelled()
     else:
         self.wait_mirror_jobs_auto_completed()
Exemplo n.º 4
0
class TShark3ToLatest(TSharkSniffer):
    """
    TShark sniffer class for version 3.0.0 - latest.
    """

    options = (
        "-npi any -T fields -E separator=/s -E occurrence=f "
        "-E header=y -e ip.src -e ip.dst -e dhcp.type -e dhcp.id "
        "-e dhcp.hw.mac_addr -e dhcp.ip.your -e dhcp.option.dhcp "
        "-e ipv6.src -e ipv6.dst "
        # Positional arguments must be the last arguments
        "'port 68 or port 546'")
    supported_versions = VersionInterval("[3.0.0,)")
 def _verify_map_output(output):
     """"Verify qemu map output."""
     qemu_path = utils_misc.get_qemu_binary(params)
     qemu_version = env_process._get_qemu_version(qemu_path)
     match = re.search(r'[0-9]+\.[0-9]+\.[0-9]+(\-[0-9]+)?', qemu_version)
     host_qemu = match.group(0)
     if host_qemu in VersionInterval('[6.1.0,)'):
         expected = {
             "length":
             int(
                 utils_numeric.normalize_data_size(params["write_size"],
                                                   "B")),
             "start":
             0,
             "depth":
             0,
             "present":
             True,
             "zero":
             True,
             "data":
             False
         }
     else:
         expected = {
             "length":
             int(
                 utils_numeric.normalize_data_size(params["write_size"],
                                                   "B")),
             "start":
             0,
             "depth":
             0,
             "zero":
             True,
             "data":
             False
         }
     if expected not in json.loads(output.stdout_text):
         test.fail("Commit failed, data from 0 to %s are not zero" %
                   params["write_size"])
 def reopen_backing_image(self, node_name):
     opts = []
     fmt_node = self.main_vm.devices.get_by_qid(node_name)[0]
     file_node = fmt_node.get_param("file")
     driver = fmt_node.get_param("driver")
     item = {
         "driver": driver,
         "node-name": node_name,
         "file": file_node,
         "read-only": False
     }
     qemu_binary = utils_misc.get_qemu_binary(self.params)
     qemu_version = utils_qemu.get_qemu_version(qemu_binary)[0]
     required_qemu_version = self.params["required_qemu_version"]
     if qemu_version in VersionInterval(required_qemu_version):
         opts.append(item)
         args = {"options": opts}
         self.main_vm.monitor.blockdev_reopen(args)
     else:
         args = item
         self.main_vm.monitor.x_blockdev_reopen(args)
 def stream_to_invalid_node(self):
     snapshot_tags = self.params.get("snapshot_tags").split()
     stream_node_tag = random.choice(snapshot_tags)
     device_node = self.get_node_name(stream_node_tag)
     try:
         cmd, arguments = backup_utils.blockdev_stream_qmp_cmd(device_node)
         self.main_vm.monitor.cmd(cmd, arguments)
     except QMPCmdError as e:
         qemu_binary = utils_misc.get_qemu_binary(self.params)
         qemu_version = utils_qemu.get_qemu_version(qemu_binary)[0]
         required_qemu_version = self.params["required_qemu_version"]
         if qemu_version in VersionInterval(required_qemu_version):
             qmp_error_msg = self.params[
                 "qmp_error_since_6_1"] % self.device_node
         else:
             qmp_error_msg = self.params[
                 "qmp_error_before_6_1"] % self.device_node
         if qmp_error_msg not in str(e.data):
             self.test.fail(str(e))
     else:
         self.test.fail("Can stream to an invalid node:%s" % device_node)
Exemplo n.º 8
0
    def check_environment(vm, params):
        """
        Check the test environment

        :param vm: VM object
        :param params: Dictionary with the test parameters
        """
        libvirt_version.is_libvirt_feature_supported(params)
        utils_misc.is_qemu_function_supported(params)

        guest_required_kernel = params.get('guest_required_kernel')
        if guest_required_kernel:
            if not vm.is_alive():
                vm.start()
            vm_session = vm.wait_for_login()
            vm_kerv = vm_session.cmd_output('uname -r').strip().split('-')[0]
            vm_session.close()
            if vm_kerv not in VersionInterval(guest_required_kernel):
                test.cancel("Got guest kernel version:%s, which is not in %s" %
                            (vm_kerv, guest_required_kernel))

        if params.get("start_vm", "no") == "no":
            vm.destroy()
 def do_full_backup(self):
     """
     Backup source image to target image
     """
     src = self._source_nodes[0]
     dst = self._full_bk_nodes[0]
     backup_cmd = backup_utils.blockdev_backup_qmp_cmd
     cmd, arguments = backup_cmd(src, dst, **self._full_backup_options)
     try:
         self.main_vm.monitor.cmd(cmd, arguments)
     except QMPCmdError as e:
         sync_mode = self._full_backup_options.get("sync")
         qemu_binary = utils_misc.get_qemu_binary(self.params)
         qemu_version = utils_qemu.get_qemu_version(qemu_binary)[0]
         required_qemu_version = self.params["required_qemu_version"]
         if qemu_version in VersionInterval(required_qemu_version):
             qmp_error_msg = self.params["qmp_error_after_6_2"] % sync_mode
         else:
             qmp_error_msg = self.params["qmp_error_before_6_2"] % sync_mode
         if not re.search(qmp_error_msg, str(e.data)):
             self.test.fail(str(e))
     else:
         self.test.fail("Do full backup with an invalid sync mode")
Exemplo n.º 10
0
 def _verify_qemu_img_map(output, str_len):
     """Verify qemu-img map's output."""
     logging.info("Verify the dumped mete-data of the unaligned image.")
     qemu_path = utils_misc.get_qemu_binary(params)
     qemu_version = env_process._get_qemu_version(qemu_path)
     match = re.search(r'[0-9]+\.[0-9]+\.[0-9]+(\-[0-9]+)?', qemu_version)
     host_qemu = match.group(0)
     if host_qemu in VersionInterval('[6.1.0,)'):
         expected = [
             {"start": 0, "length": str_len, "depth": 0, "present": True,
              "zero": False, "data": True, "offset": 0},
             {"start": str_len, "length": 512 - (str_len % 512), "depth": 0,
              "present": True, "zero": True, "data": False,
              "offset": str_len}]
     else:
         expected = [{"start": 0, "length": str_len, "depth": 0,
                      "zero": False, "data": True, "offset": 0},
                     {"start": str_len, "length": 512 - (str_len % 512),
                      "depth": 0, "zero": True, "data": False,
                      "offset": str_len}]
     res = json.loads(output)
     if res != expected:
         test.fail("The dumped mete-data of the unaligned "
                   "image '%s' is not correct." % img.image_filename)
Exemplo n.º 11
0
def run(test, params, env):
    """
    cpuinfo query test:
    1). run query cmd. e.g -cpu ?cpuid
    2). check the expected info is included in the cmd output.
    3). Boot guest and check the output of qmp command "qom-list-types"
    4). Check the output of qmp command "query-cpu-definitions"
    5). Check the output of qmp command "query-cpu-model-expansion"
    """
    def remove_models(model_list):
        """
        Remove models from cpu_types
        :param model_list: The list of models to be removed
        """
        for model in model_list:
            try:
                cpu_types.remove(model)
            except ValueError:
                logging.warning('The model to be removed is not'
                                ' in the list: %s' % model)
                continue

    def get_patterns(p_list):
        """
        Return all possible patterns for given flags
        :param p_list: The list of flags
        """
        r_list = []
        replace_char = [('_', ''), ('_', '-'), ('.', '-'), ('.', ''),
                        ('.', '_')]
        for p in p_list:
            r_list.extend(list(map(lambda x: p.replace(*x), replace_char)))
        return set(r_list)

    cpu_types = []
    list(map(cpu_types.extend, list(cpu.CPU_TYPES.values())))

    qemu_path = utils_misc.get_qemu_binary(params)
    qemu_version = env_process._get_qemu_version(qemu_path)
    match = re.search(r'[0-9]+\.[0-9]+\.[0-9]+(\-[0-9]+)?', qemu_version)
    host_qemu = match.group(0)
    remove_models(params.objects('remove_list'))
    if host_qemu in VersionInterval('[,4.2.0)'):
        remove_models(params.objects('cpu_model_8'))
    if host_qemu in VersionInterval('[,3.1.0)'):
        remove_models(params.objects('cpu_model_3_1_0'))
    if host_qemu in VersionInterval('[,2.12.0)'):
        remove_models(params.objects('cpu_model_2_12_0'))
    qemu_binary = utils_misc.get_qemu_binary(params)
    logging.info('Query cpu models by qemu command')
    query_cmd = "%s -cpu ? | awk '{print $2}'" % qemu_binary
    qemu_binary_output = process.system_output(
        query_cmd, shell=True).decode().splitlines()
    cpuid_index = qemu_binary_output.index('CPUID')
    cpu_models_binary = qemu_binary_output[1:cpuid_index - 1]
    cpu_flags_binary = qemu_binary_output[cpuid_index + 1:]
    params['start_vm'] = 'yes'
    vm_name = params['main_vm']
    env_process.preprocess_vm(test, params, env, vm_name)
    vm = env.get_vm(vm_name)
    # query cpu model supported by qemu
    logging.info('Query cpu model supported by qemu by qemu monitor')
    qmp_model_output = str(vm.monitor.cmd('qom-list-types'))
    qmp_def_output = str(vm.monitor.cmd('query-cpu-definitions'))

    # Check if all the output contain expected cpu models
    output_list = {
        'qemu-kvm': cpu_models_binary,
        'qom-list-types': qmp_model_output,
        'query-cpu-definitions': qmp_def_output
    }
    missing = dict.fromkeys(output_list.keys(), [])
    for cpu_model in cpu_types:
        logging.info('Check cpu model %s from qemu command output and'
                     ' qemu monitor output' % cpu_model)
        for key, value in output_list.items():
            if cpu_model not in value:
                missing[key].append(cpu_model)
    for key, value in missing.items():
        if value:
            test.fail('%s is missing in the %s output: %s\n' %
                      (', '.join(value), key, output_list[key]))

    # Check if qemu command output matches qmp output
    missing = []
    logging.info('Check if qemu command output matches qemu monitor output')
    for cpu_model in cpu_models_binary:
        if cpu_model not in qmp_model_output:
            missing.append(cpu_model)
    if missing:
        test.fail('The qemu monitor output does not included all the cpu'
                  ' model in qemu command output, missing: \n %s' %
                  ', '.join(missing))

    # Check if the flags in qmp output matches expectation
    args = {'type': 'full', 'model': {'name': vm.cpuinfo.model}}
    output = vm.monitor.cmd('query-cpu-model-expansion', args)
    model = output.get('model')
    model_name = model.get('name')
    if model_name != vm.cpuinfo.model:
        test.fail('Command query-cpu-model-expansion return'
                  ' wrong model: %s' % model_name)
    model_prop = model.get('props')
    for flag in cpu.CPU_TYPES_RE.get(model_name).split(','):
        logging.info('Check flag %s from qemu monitor output' % flag)
        flags = get_patterns(flag.split('|'))
        for f in flags:
            if model_prop.get(f) is True:
                break
        else:
            test.fail('Check cpu model props failed, %s is not True' % flag)

    # Check if the flags in qmp output matches qemu command output
    missing = []
    logging.info('Check if the flags in qemu monitor output matches'
                 ' qemu command output')
    for flag in cpu_flags_binary:
        if flag not in str(output):
            missing.append(flag)
    if missing:
        test.fail('The monitor output does not included all the cpu flags'
                  ' in qemu  command output, missing: \n %s' %
                  ', '.join(missing))
Exemplo n.º 12
0
def run(test, params, env):
    """
    Test hotplug maximum vCPU device.

    1) Launch a guest without vCPU device.
    2) Hotplug all vCPU devices and check successfully or not. (qemu side)
    3) Check if the number of CPUs in guest changes accordingly. (guest side)
    4) Reboot guest.
    5) Hotunplug all vCPU devices and check successfully or not. (qemu side)

    :param test:   QEMU test object.
    :param params: Dictionary with the test parameters.
    :param env:    Dictionary with test environment.
    """
    os_type = params["os_type"]
    machine_type = params["machine_type"]
    reboot_timeout = params.get_numeric("reboot_timeout")
    mismatch_text = "Actual number of guest CPUs is not equal to the expected"
    not_equal_text = "CPU quantity mismatched! Guest got %s but expected is %s"
    # Many vCPUs will be plugged, it takes some time to bring them online.
    verify_wait_timeout = params.get_numeric("verify_wait_timeout", 300)
    qemu_binary = utils_misc.get_qemu_binary(params)
    machine_info = utils_qemu.get_machines_info(qemu_binary)[machine_type]
    machine_info = re.search(r'\(alias of (\S+)\)', machine_info)
    current_machine = machine_info.group(1) if machine_info else machine_type
    supported_maxcpus = (params.get_numeric("vcpu_maxcpus")
                         or utils_qemu.get_maxcpus_hard_limit(
                             qemu_binary, current_machine))
    if not params.get_boolean("allow_pcpu_overcommit"):
        supported_maxcpus = min(supported_maxcpus, cpu.online_count())

    logging.info("Define the CPU topology of guest")
    vcpu_devices = []
    if (cpu.get_vendor() == "amd" and params.get_numeric("vcpu_threads") != 1):
        test.cancel("AMD cpu does not support multi threads")
    elif machine_type.startswith("pseries"):
        host_kernel_ver = uname()[2].split("-")[0]
        if params.get_numeric("vcpu_threads") == 8:
            supported_maxcpus -= divmod(supported_maxcpus, 8)[1]
            vcpu_devices = [
                "vcpu%d" % c for c in range(1, supported_maxcpus // 8)
            ]
        # The maximum value of vcpu_id in 'linux-3.x' is 2048, so
        # (vcpu_id * ms->smp.threads / spapr->vsmt) <= 256, need to adjust it
        elif (supported_maxcpus > 256
              and host_kernel_ver not in VersionInterval("[4, )")):
            supported_maxcpus = 256
    vcpu_devices = vcpu_devices or [
        "vcpu%d" % vcpu for vcpu in range(1, supported_maxcpus)
    ]
    params["vcpu_maxcpus"] = str(supported_maxcpus)
    params["vcpu_devices"] = " ".join(vcpu_devices)
    params["start_vm"] = "yes"

    vm = env.get_vm(params["main_vm"])
    vm.create(params=params)
    vm.verify_alive()
    session = vm.wait_for_login()
    cpuinfo = vm.cpuinfo
    smp = cpuinfo.smp
    vcpus_count = vm.params.get_numeric("vcpus_count")

    error_context.context("Hotplug all vCPU devices", logging.info)
    for vcpu_device in vcpu_devices:
        vm.hotplug_vcpu_device(vcpu_device)

    error_context.context("Check Number of vCPU in guest", logging.info)
    if not utils_misc.wait_for(lambda: vm.get_cpu_count() == supported_maxcpus,
                               verify_wait_timeout,
                               first=5,
                               step=10):
        logging.error(not_equal_text, vm.get_cpu_count(), supported_maxcpus)
        test.fail(mismatch_text)
    logging.info("CPU quantity is as expected: %s", supported_maxcpus)

    error_context.context("Check CPU topology of guest", logging.info)
    if not cpu_utils.check_guest_cpu_topology(session, os_type, cpuinfo):
        test.fail("CPU topology of guest is not as expected.")
    session = vm.reboot(session, timeout=reboot_timeout)
    if not cpu_utils.check_guest_cpu_topology(session, os_type, cpuinfo):
        test.fail("CPU topology of guest is not as expected after reboot.")

    error_context.context("Hotunplug all vCPU devices", logging.info)
    for vcpu_device in reversed(vcpu_devices):
        vm.hotunplug_vcpu_device(vcpu_device, 10 * vcpus_count)
    if not utils_misc.wait_for(lambda: vm.get_cpu_count() == smp,
                               verify_wait_timeout,
                               first=5,
                               step=10):
        logging.error(not_equal_text, vm.get_cpu_count(), smp)
        test.fail(mismatch_text)
    logging.info("CPU quantity is as expected after hotunplug: %s", smp)
    session.close()