def numa_param_live(params):
    """set domain numa parameters with live flag and check
    """
    global logger
    logger = params['logger']
    params.pop('logger')
    guestname = params['guestname']
    nodeset = params['nodeset']
    mode = int(params['mode'])

    logger.info("the name of virtual machine is %s" % guestname)
    logger.info("the given node number is: %s" % nodeset)
    logger.info("the given mode is: %s" % mode)

    global node_num
    cmd = "lscpu|grep 'NUMA node(s)'"
    ret, output = utils.exec_cmd(cmd, shell=True)
    node_num = int(output[0].split(' ')[-1])
    node_tuple = utils.param_to_tuple(nodeset, node_num)
    logger.debug("nodeset to tuple is:")
    logger.debug(node_tuple)

    param = {'numa_nodeset': nodeset, 'numa_mode': mode}
    logger.info("numa param dict for set is: %s" % param)

    conn = sharedmod.libvirtobj['conn']

    try:
        domobj = conn.lookupByName(guestname)
        logger.info("set domain numa parameters with flag: %s" %
                    libvirt.VIR_DOMAIN_AFFECT_LIVE)
        domobj.setNumaParameters(param, libvirt.VIR_DOMAIN_AFFECT_LIVE)
        logger.info("set domain numa parameters succeed")

        logger.info("check numa parameters")
        ret = domobj.numaParameters(libvirt.VIR_DOMAIN_AFFECT_LIVE)
        logger.info("numa parameters after set is: %s" % ret)

        new_tuple = utils.param_to_tuple(ret['numa_nodeset'], node_num)
        if not new_tuple:
            logger.error("fail to parse nodeset to tuple")
            return 1

        if new_tuple == node_tuple and ret['numa_mode'] == mode:
            logger.info("numa parameters is as expected")
        else:
            logger.error("numa parameters is not as expected")
            return 1

    except libvirtError, e:
        logger.error("libvirt call failed: " + str(e))
        return 1
def numa_param_live(params):
    """set domain numa parameters with live flag and check
    """
    global logger
    logger = params['logger']
    params.pop('logger')
    guestname = params['guestname']
    nodeset = params['nodeset']
    mode = int(params['mode'])

    logger.info("the name of virtual machine is %s" % guestname)
    logger.info("the given node number is: %s" % nodeset)
    logger.info("the given mode is: %s" % mode)

    global node_num
    cmd = "lscpu|grep 'NUMA node(s)'"
    ret, output = utils.exec_cmd(cmd, shell=True)
    node_num = int(output[0].split(' ')[-1])
    node_tuple = utils.param_to_tuple(nodeset, node_num)
    logger.debug("nodeset to tuple is:")
    logger.debug(node_tuple)

    param = {'numa_nodeset': nodeset, 'numa_mode': mode}
    logger.info("numa param dict for set is: %s" % param)

    conn = sharedmod.libvirtobj['conn']

    try:
        domobj = conn.lookupByName(guestname)
        logger.info("set domain numa parameters with flag: %s" %
                    libvirt.VIR_DOMAIN_AFFECT_LIVE)
        domobj.setNumaParameters(param, libvirt.VIR_DOMAIN_AFFECT_LIVE)
        logger.info("set domain numa parameters succeed")

        logger.info("check numa parameters")
        ret = domobj.numaParameters(libvirt.VIR_DOMAIN_AFFECT_LIVE)
        logger.info("numa parameters after set is: %s" % ret)

        new_tuple = utils.param_to_tuple(ret['numa_nodeset'], node_num)
        if not new_tuple:
            logger.error("fail to parse nodeset to tuple")
            return 1

        if new_tuple == node_tuple and ret['numa_mode'] == mode:
            logger.info("numa parameters is as expected")
        else:
            logger.error("numa parameters is not as expected")
            return 1

    except libvirtError, e:
        logger.error("libvirt call failed: " + str(e))
        return 1
def check_numa_params(guestname, mode, node_tuple):
    """dump domain live xml description to check numa params and
       check memory allowed list of domain pid
    """
    cmd = "cat /var/run/libvirt/qemu/%s.pid" % guestname
    status, pid = utils.exec_cmd(cmd, shell=True)
    if status:
        logger.error("failed to get the pid of domain %s" % guestname)
        return 1

    cmd = "grep Mems_allowed_list /proc/%s/status" % pid[0]
    status, output = utils.exec_cmd(cmd, shell=True)
    nodeval = output[0].split('\t')[1]
    ret = utils.param_to_tuple(nodeset_val, node_num)
    logger.info("Mems_allowed_list in domain pid status is: %s" % nodeval)
    logger.debug("parse nodeset to tuple is:")
    logger.debug(ret)
    if not ret:
        logger.error("fail to parse nodeset to tuple")
        return 1

    # TODO: add check for mode

    if ret == node_tuple:
        return 0
    else:
        return 1
def check_numa_params(guestname, mode, node_tuple):
    """dump domain live xml description to check numa params and
       check memory allowed list of domain pid
    """
    cmd = "cat /var/run/libvirt/qemu/%s.pid" % guestname
    status, pid = utils.exec_cmd(cmd, shell=True)
    if status:
        logger.error("failed to get the pid of domain %s" % guestname)
        return 1

    cmd = "grep Mems_allowed_list /proc/%s/status" % pid[0]
    status, output = utils.exec_cmd(cmd, shell=True)
    nodeval = output[0].split('\t')[1]
    ret = utils.param_to_tuple(nodeval, node_num)
    logger.info("Mems_allowed_list in domain pid status is: %s" % nodeval)
    logger.debug("parse nodeset to tuple is:")
    logger.debug(ret)
    if not ret:
        logger.error("fail to parse nodeset to tuple")
        return 1

    # TODO: add check for mode

    if ret == node_tuple:
        return 0
    else:
        return 1
Beispiel #5
0
def check_pinemulator(guestname, maxcpu, pininfo_after):
    """check emulator status of the running virtual machine
    """

    cmd = "cat /var/run/libvirt/qemu/%s.pid" % guestname
    status, pid = utils.exec_cmd(cmd, shell=True)
    if status:
        logger.error("failed to get the pid of domain %s" % guestname)
        return 1

    cmd = "grep Cpus_allowed_list /proc/%s/task/%s/status" % (pid[0], pid[0])
    status, output = utils.exec_cmd(cmd, shell=True)
    if status:
        logger.error("failed to get Cpus_allowed_list")
        return 1

    cpu_allowed_list = output[0]
    cpulistcheck = cpu_allowed_list.split('\t')[1]
    pininfo_in_process = str(utils.param_to_tuple(cpulistcheck, maxcpu))

    if cmp(pininfo_in_process, pininfo_after):
        logger.error("domain emulator pin failed")
        return 1
    else:
        logger.info("domain emulator pin successed")
        return 0
Beispiel #6
0
def vcpupin_check(guestname, vcpu, cpumap):
    """check vcpu subprocess status of the running virtual machine
       grep Cpus_allowed_list /proc/PID/task/*/status
    """
    tmp_str = ''
    cmd = "cat /var/run/libvirt/qemu/%s.pid" % guestname
    status, pid = utils.exec_cmd(cmd, shell=True)
    if status:
        logger.error("failed to get the pid of domain %s" % guestname)
        return 1

    cmd = "grep Cpus_allowed_list /proc/%s/task/*/status" % pid[0]
    status, output = utils.exec_cmd(cmd, shell=True)
    logger.debug("command '%s' output is:" % cmd)
    for i in range(len(output)):
        tmp_str += ''.join(output[i]) + '\n'
    logger.debug(tmp_str)

    task_list = output[1:]
    vcpu_task = task_list[int(vcpu)]
    cpulist = vcpu_task.split('\t')[1]
    ret = utils.param_to_tuple(cpulist, maxcpu)

    if ret == cpumap:
        logger.info("vcpu process cpus allowed list is expected")
        return 0
    else:
        logger.error("vcpu process cpus allowed list is not expected")
        return 1
def check_pinemulator(guestname, maxcpu, pininfo_after):
    """check emulator status of the running virtual machine
    """

    cmd = "cat /var/run/libvirt/qemu/%s.pid" % guestname
    status, pid = utils.exec_cmd(cmd, shell=True)
    if status:
        logger.error("failed to get the pid of domain %s" % guestname)
        return 1

    cmd = "grep Cpus_allowed_list /proc/%s/task/%s/status" % (pid[0], pid[0])
    status, output = utils.exec_cmd(cmd, shell=True)
    if status:
        logger.error("failed to get Cpus_allowed_list")
        return 1

    cpu_allowed_list = output[0]
    cpulistcheck = cpu_allowed_list.split('\t')[1]
    pininfo_in_process = str(utils.param_to_tuple(cpulistcheck, maxcpu))

    if cmp(pininfo_in_process, pininfo_after):
        logger.error("domain emulator pin failed")
        return 1
    else:
        logger.info("domain emulator pin successed")
        return 0
def vcpupin_live(params):
    """pin domain vcpu to host cpu with live flag
    """
    global logger
    logger = params['logger']
    params.pop('logger')
    guestname = params['guestname']
    vcpu = int(params['vcpu'])
    cpulist = params['cpulist']

    logger.info("the name of virtual machine is %s" % guestname)
    logger.info("the given vcpu is %s" % vcpu)
    logger.info("the given cpulist is %s" % cpulist)

    global maxcpu
    maxcpu = utils.get_host_cpus()
    logger.info("%s physical cpu on host" % maxcpu)

    conn = sharedmod.libvirtobj['conn']

    try:
        domobj = conn.lookupByName(guestname)
        cpumap = utils.param_to_tuple(cpulist, maxcpu)
        if not cpumap:
            logger.error("cpulist: Invalid format")
            return 1

        logger.debug("cpumap for vcpu pin is:")
        logger.debug(cpumap)

        logger.info("pin domain vcpu %s to host cpu %s with flag: %s" %
                    (vcpu, cpulist, libvirt.VIR_DOMAIN_AFFECT_LIVE))
        domobj.pinVcpuFlags(vcpu, cpumap, libvirt.VIR_DOMAIN_AFFECT_LIVE)

        logger.info("check vcpus info")
        ret = domobj.vcpus()
        logger.debug("vcpus info is:")
        logger.debug(ret)
        if ret[1][vcpu] == cpumap:
            logger.info("vcpus info is expected")
        else:
            logger.error("vcpus info is not expected")
            return 1

    except libvirtError as e:
        logger.error("libvirt call failed: " + str(e))
        return 1

    logger.info("check vcpu pin status on host")
    ret = vcpupin_check(guestname, vcpu, cpulist)
    if ret:
        logger.error("domain vcpu pin failed")
        return 1
    else:
        logger.info("domain vcpu pin succeed")
        return 0
def vcpupin_config(params):
    """pin domain vcpu to host cpu with config flag
    """
    global logger
    logger = params['logger']
    params.pop('logger')
    guestname = params['guestname']
    vcpu = int(params['vcpu'])
    cpulist = params['cpulist']

    logger.info("the name of virtual machine is %s" % guestname)
    logger.info("the given vcpu is %s" % vcpu)
    logger.info("the given cpulist is %s" % cpulist)

    global maxcpu
    maxcpu = utils.get_host_cpus()
    logger.info("%s physical cpu on host" % maxcpu)

    conn = sharedmod.libvirtobj['conn']

    try:
        domobj = conn.lookupByName(guestname)
        cpumap = utils.param_to_tuple(cpulist, maxcpu)

        if not cpumap:
            logger.error("cpulist: Invalid format")
            return 1

        logger.debug("cpumap for vcpu pin is:")
        logger.debug(cpumap)

        logger.info("pin domain vcpu %s to host cpulist %s with flag: %s" %
                    (vcpu, cpulist, libvirt.VIR_DOMAIN_AFFECT_CONFIG))
        domobj.pinVcpuFlags(vcpu, cpumap, libvirt.VIR_DOMAIN_AFFECT_CONFIG)

        logger.info("check vcpu pin info")
        ret = domobj.vcpuPinInfo(libvirt.VIR_DOMAIN_AFFECT_CONFIG)
        logger.debug("vcpu pin info is:")
        logger.debug(ret)
        if ret[vcpu] == cpumap:
            logger.info("vcpu pin info is expected")
        else:
            logger.error("vcpu pin info is not expected")
            return 1
    except libvirtError as e:
        logger.error("libvirt call failed: " + str(e))
        return 1

    logger.info("check domain vcpupin configuration in xml")
    ret = vcpupin_check(domobj, vcpu, cpumap)
    if ret:
        logger.error("domain vcpu pin check failed")
        return 1
    else:
        logger.info("domain vcpu pin check succeed")
        return 0
Beispiel #10
0
def pinemulator(params):
    """Dynamically change the real CPUs which can be allocated to the
       emulator process of a domain. This function requires privileged
       access to the hypervisor. """
    global logger
    logger = params['logger']
    guestname = params['guestname']
    cpulist = params['cpulist']

    logger.info("the name of virtual machine is %s" % guestname)
    logger.info("the given cpulist is %s" % cpulist)

    maxcpu = utils.get_host_cpus()
    logger.info("%s physical cpu on host" % maxcpu)

    cpumap = utils.param_to_tuple(cpulist, maxcpu)
    if not cpumap:
        logger.error("cpulist: Invalid format")
        return 1

    conn = sharedmod.libvirtobj['conn']

    try:
        domobj = conn.lookupByName(guestname)

        pininfo_original = str(domobj.emulatorPinInfo())
        logger.info("the original emulator pin of the domain is: %s" %
                    pininfo_original)

        logger.info("pin domain emulator to host cpu %s" % cpulist)
        domobj.pinEmulator(cpumap)

        pininfo_after = str(domobj.emulatorPinInfo())
        logger.info("the revised emulator pin of the domain is: %s" %
                    pininfo_after)

        ret = check_pinemulator(guestname, maxcpu, pininfo_after)
        return ret

    except libvirtError as e:
        logger.error("libvirt call failed: " + str(e))
        return 1
Beispiel #11
0
def pinemulator(params):
    """Dynamically change the real CPUs which can be allocated to the
       emulator process of a domain. This function requires privileged
       access to the hypervisor. """
    global logger
    logger = params['logger']
    guestname = params['guestname']
    cpulist = params['cpulist']

    logger.info("the name of virtual machine is %s" % guestname)
    logger.info("the given cpulist is %s" % cpulist)

    maxcpu = utils.get_host_cpus()
    logger.info("%s physical cpu on host" % maxcpu)

    cpumap = utils.param_to_tuple(cpulist, maxcpu)
    if not cpumap:
        logger.error("cpulist: Invalid format")
        return 1

    conn = sharedmod.libvirtobj['conn']

    try:
        domobj = conn.lookupByName(guestname)

        pininfo_original = str(domobj.emulatorPinInfo())
        logger.info("the original emulator pin of the domain is: %s" %
                    pininfo_original)

        logger.info("pin domain emulator to host cpu %s" % cpulist)
        domobj.pinEmulator(cpumap)

        pininfo_after = str(domobj.emulatorPinInfo())
        logger.info("the revised emulator pin of the domain is: %s" %
                    pininfo_after)

        ret = check_pinemulator(guestname, maxcpu, pininfo_after)
        return ret

    except libvirtError as e:
        logger.error("libvirt call failed: " + str(e))
        return 1
Beispiel #12
0
def check_numa_params(domobj, mode, node_tuple):
    """dump domain config xml description to check numa params
    """
    guestxml = domobj.XMLDesc(2)
    logger.debug("domain %s xml is :\n%s" % (domobj.name(), guestxml))
    xml = minidom.parseString(guestxml)
    numatune = xml.getElementsByTagName('numatune')[0]
    mem_element = numatune.getElementsByTagName('memory')[0]

    if mem_element.hasAttribute('mode') and \
       mem_element.hasAttribute('nodeset'):
        attr = mem_element.getAttributeNode('mode')
        mode_val = attr.nodeValue
        logger.info("memory mode in config xml is: %s" % mode_val)
        if mode_val == 'strict':
            mode_num = 0
        elif mode_val == 'preferred':
            mode_num = 1
        elif mode_val == 'interleave':
            mode_num = 2
        else:
            logger.error("mode value is invalid")
            return 1

        attr = mem_element.getAttributeNode('nodeset')
        nodeset_val = attr.nodeValue
        logger.info("nodeset in config xml is: %s" % nodeset_val)
    else:
        logger.error("no 'mode' and 'nodeset' atrribute for element memory")
        return 1

    ret = utils.param_to_tuple(nodeset_val, node_num)
    logger.debug("nudeset in config xml to tuple is:")
    logger.debug(ret)
    if not ret:
        logger.error("fail to parse nodeset to tuple")
        return 1

    if mode_num == mode and ret == node_tuple:
        return 0
    else:
        return 1
def vcpupin_check(domobj, vcpu, cpumap):
    """check domain config xml with vcpupin element
    """
    guestxml = domobj.XMLDesc(2)
    logger.debug("domain %s xml :\n%s" % (domobj.name(), guestxml))

    doc = minidom.parseString(guestxml)
    vcpupin = doc.getElementsByTagName('vcpupin')
    if not vcpupin:
        logger.error("no vcpupin element in domain xml")
        return 1

    for i in range(len(vcpupin)):
        if vcpupin[i].hasAttribute('vcpu') and \
           vcpupin[i].hasAttribute('cpuset'):
            vcpu_attr = vcpupin[i].getAttributeNode('vcpu')
            cpu_attr = vcpupin[i].getAttributeNode('cpuset')
            if int(vcpu_attr.nodeValue) == vcpu:
                cpulist = cpu_attr.nodeValue
                if cpulist == '':
                    cpumap_tmp = ()
                    for i in range(maxcpu):
                        cpumap_tmp += (False, )
                else:
                    cpumap_tmp = utils.param_to_tuple(cpulist, maxcpu)

                if cpumap_tmp == cpumap:
                    logger.info("cpuset is as expected in domain xml")
                    return 0
                else:
                    logger.error("cpuset is not as expected in domain xml")
                    return 1

        if i == len(vcpupin) - 1:
            logger.error("the vcpupin element with given vcpu is not found")
            return 1
def vcpupin_check(domobj, vcpu, cpumap):
    """check domain config xml with vcpupin element
    """
    guestxml = domobj.XMLDesc(2)
    logger.debug("domain %s xml :\n%s" %(domobj.name(), guestxml))

    doc = minidom.parseString(guestxml)
    vcpupin = doc.getElementsByTagName('vcpupin')
    if not vcpupin:
        logger.error("no vcpupin element in domain xml")
        return 1

    for i in range(len(vcpupin)):
        if vcpupin[i].hasAttribute('vcpu') and \
           vcpupin[i].hasAttribute('cpuset'):
            vcpu_attr = vcpupin[i].getAttributeNode('vcpu')
            cpu_attr = vcpupin[i].getAttributeNode('cpuset')
            if int(vcpu_attr.nodeValue) == vcpu:
                cpulist = cpu_attr.nodeValue
                if cpulist == '':
                    cpumap_tmp = ()
                    for i in range(maxcpu):
                        cpumap_tmp += (False,)
                else:
                    cpumap_tmp = utils.param_to_tuple(cpulist, maxcpu)

                if cpumap_tmp == cpumap:
                    logger.info("cpuset is as expected in domain xml")
                    return 0
                else:
                    logger.error("cpuset is not as expected in domain xml")
                    return 1

        if i == len(vcpupin) - 1:
            logger.error("the vcpupin element with given vcpu is not found")
            return 1
Beispiel #15
0
def pin_iothread(params):
    """
       test API for pinIOThread in class virDomain
    """

    global logger
    logger = params["logger"]
    fail = 0

    try:
        conn = libvirt.open(params["conn"])

        logger.info("get connection to libvirtd")
        guest = params["guestname"]
        vm = conn.lookupByName(guest)
        hostcpu = utils.get_host_cpus()
        tu_cpu = ()
        logger.info("test guest name: %s" % guest)

        for i in range(hostcpu):
            if i % 2 == 0:
                tu_cpu += (1,)
            else:
                tu_cpu += (0,)

        """ test effect a running guest"""
        if vm.isActive() == 1:
            logger.info("guest is running test with running guest")

            if not find_iothreadid_fromxml(vm, 1, 1):
                logger.info("add iothread %d to running guest" % 1)
                vm.addIOThread(i, libvirt.VIR_DOMAIN_AFFECT_LIVE)

            vm.pinIOThread(1, tu_cpu, libvirt.VIR_DOMAIN_AFFECT_LIVE)
            cpuset = find_iothreadpin_fromxml(vm, 1, 1)
            if cpuset:
                if not check_iothreadpin(vm, 1, cpuset):
                    fail = 1
                tmp_cpuset = utils.param_to_tuple(cpuset, hostcpu)
                if not tmp_cpuset:
                    fail = 1
                elif tmp_cpuset != tu_cpu:
                    logger.info("FAIL: the cpuset in xml is not equal the cpuset we set")
                    fail = 1
            else:
                logger.info("FAIL: cannot find iothreadpin in XML")
                fail = 1

        """ test effect guest config"""
        logger.info("test with guest inactive XML")
        if not find_iothreadid_fromxml(vm, 0, 1):
            logger.info("add iothread 1 to guest config")
            vm.addIOThread(1, libvirt.VIR_DOMAIN_AFFECT_CONFIG)

        vm.pinIOThread(1, tu_cpu, libvirt.VIR_DOMAIN_AFFECT_LIVE)
        cpuset = find_iothreadpin_fromxml(vm, 1, 1)
        if cpuset:
            tmp_cpuset = utils.param_to_tuple(cpuset, hostcpu)
            if not tmp_cpuset:
                fail = 1
            elif tmp_cpuset != tu_cpu:
                logger.info("FAIL: the cpuset in xml is not equal the cpuset we set")
                fail = 1
        else:
            logger.info("FAIL: cannot find iothreadpin in XML")
            fail = 1

    except libvirtError, e:
        logger.error("API error message: %s" % e.message)
        fail = 1
def pin_iothread(params):
    """
       test API for pinIOThread in class virDomain
    """

    global logger
    logger = params['logger']
    fail = 0

    try:
        conn = libvirt.open(params['conn'])

        logger.info("get connection to libvirtd")
        guest = params['guestname']
        vm = conn.lookupByName(guest)
        hostcpu = utils.get_host_cpus()
        tu_cpu = ()
        logger.info("test guest name: %s" % guest)

        for i in range(hostcpu):
            if i % 2 == 0:
                tu_cpu += (1, )
            else:
                tu_cpu += (0, )
        """ test effect a running guest"""
        if vm.isActive() == 1:
            logger.info("guest is running test with running guest")

            if not find_iothreadid_fromxml(vm, 1, 1):
                logger.info("add iothread %d to running guest" % 1)
                vm.addIOThread(i, libvirt.VIR_DOMAIN_AFFECT_LIVE)

            vm.pinIOThread(1, tu_cpu, libvirt.VIR_DOMAIN_AFFECT_LIVE)
            cpuset = find_iothreadpin_fromxml(vm, 1, 1)
            if cpuset:
                if not check_iothreadpin(vm, 1, cpuset):
                    fail = 1
                tmp_cpuset = utils.param_to_tuple(cpuset, hostcpu)
                if not tmp_cpuset:
                    fail = 1
                elif tmp_cpuset != tu_cpu:
                    logger.info(
                        "FAIL: the cpuset in xml is not equal the cpuset we set"
                    )
                    fail = 1
            else:
                logger.info("FAIL: cannot find iothreadpin in XML")
                fail = 1
        """ test effect guest config"""
        logger.info("test with guest inactive XML")
        if not find_iothreadid_fromxml(vm, 0, 1):
            logger.info("add iothread 1 to guest config")
            vm.addIOThread(1, libvirt.VIR_DOMAIN_AFFECT_CONFIG)

        vm.pinIOThread(1, tu_cpu, libvirt.VIR_DOMAIN_AFFECT_LIVE)
        cpuset = find_iothreadpin_fromxml(vm, 1, 1)
        if cpuset:
            tmp_cpuset = utils.param_to_tuple(cpuset, hostcpu)
            if not tmp_cpuset:
                fail = 1
            elif tmp_cpuset != tu_cpu:
                logger.info(
                    "FAIL: the cpuset in xml is not equal the cpuset we set")
                fail = 1
        else:
            logger.info("FAIL: cannot find iothreadpin in XML")
            fail = 1

    except libvirtError, e:
        logger.error("API error message: %s" % e.message)
        fail = 1