def install_linux_check(params):
    """check guest status after installation, including network ping,
       read/write option in guest. return value: 0 - ok; 1 - bad
    """
    global logger
    logger = params['logger']
    params.pop('logger')

    guestname = params.get('guestname')
    virt_type = params.get('virt_type')

    logger.info("the name of guest is %s" % guestname)

    # Connect to local hypervisor connection URI
    hypervisor = utils.get_hypervisor()

    logger.info("the type of hypervisor is %s" % hypervisor)

    conn = sharedmod.libvirtobj['conn']
    domobj = conn.lookupByName(guestname)
    state = domobj.info()[0]

    if(state == libvirt.VIR_DOMAIN_SHUTOFF):
        logger.info("guest is shutoff, if u want to run this case, \
                     guest must be started")
        return 1

    logger.info("get the mac address of vm %s" % guestname)
    mac = utils.get_dom_mac_addr(guestname)
    logger.info("the mac address of vm %s is %s" % (guestname, mac))

    timeout = 300
    while timeout:
        ipaddr = utils.mac_to_ip(mac, 180)
        if not ipaddr:
            logger.info(str(timeout) + "s left")
            time.sleep(10)
            timeout -= 10
        else:
            logger.info("the ip address of vm %s is %s" % (guestname, ipaddr))
            break

    if timeout == 0:
        logger.info("vm %s fail to get ip address" % guestname)
        return 1

    time.sleep(120)

    logger.info("Now checking guest health after installation")

    domain_name=guestname
    blk_type=params['hddriver']
    nic_type=params['nicdriver']
    Test_Result = 0

    # Ping guest from host
    logger.info("check point1: ping guest from host")
    if utils.do_ping(ipaddr, 20) == 1:
        logger.info("ping current guest successfull")
    else:
        logger.error("Error: can't ping current guest")
        Test_Result = 1
        return Test_Result

    # Creat file and read file in guest.
    logger.info("check point2: creat and read dirctory/file in guest")
    if utils.create_dir(ipaddr, "root", "redhat") == 0:
        logger.info("create dir - /tmp/test successfully")
        if utils.write_file(ipaddr, "root", "redhat") == 0:
            logger.info("write and read file: /tmp/test/test.log successfully")
        else:
            logger.error("Error: fail to write/read file - /tmp/test/test.log")
            Test_Result = 1
            return Test_Result
    else:
        logger.error("Error: fail to create dir - /tmp/test")
        Test_Result = 1
        return Test_Result

    # Check whether vcpu equals the value set in geust config xml
    logger.info("check point3: check cpu number in guest equals to \
                 the value set in domain config xml")
    vcpunum_expect = int(utils.get_num_vcpus(domain_name))
    logger.info("vcpu number in domain config xml - %s is %s" % \
                 (domain_name, vcpunum_expect))
    vcpunum_actual = int(utils.get_remote_vcpus(ipaddr, "root", "redhat"))
    logger.info("The actual vcpu number in guest - %s is %s" %
                 (domain_name, vcpunum_actual))
    if vcpunum_expect == vcpunum_actual:
        logger.info("The actual vcpu number in guest is \
                     equal to the setting your domain config xml")
    else:
        logger.error("Error: The actual vcpu number in guest is \
                      NOT equal to the setting your domain config xml")
        Test_Result = 1
        return Test_Result

    # Check whether mem in guest is equal to the value set in domain config xml
    logger.info("check point4: check whether mem in guest is equal to \
                 the value set in domain config xml")
    mem_expect = utils.get_size_mem(domain_name)
    logger.info("current mem size in domain config xml - %s is %s" %
                 (domain_name, mem_expect))
    mem_actual = utils.get_remote_memory(ipaddr, "root", "redhat")
    logger.info("The actual mem size in guest - %s is %s" %
                (domain_name, mem_actual))
    diff_range = int(mem_expect) * 0.07
    diff = int(mem_expect) - int(mem_actual)
    if int(math.fabs(diff)) < int(diff_range):
        logger.info("The actual mem size in guest is almost equal to \
                    the setting your domain config xml")
    else:
        logger.error("Error: The actual mem size in guest is NOT equal to \
                      the setting your domain config xml")
        Test_Result = 1
        return Test_Result

    # Check app works fine in guest, such as: wget
    logger.info("check point5: check app works fine in guest, such as: wget")
    logger.info("get system environment information")
    envfile = os.path.join(HOME_PATH, 'global.cfg')
    logger.info("the environment file is %s" % envfile)

    envparser = env_parser.Envparser(envfile)
    file_url = envparser.get_value("other", "wget_url")

    if utils.run_wget_app(ipaddr, "root", "redhat", file_url, logger) == 0:
        logger.info("run wget successfully in guest.")
    else:
        logger.error("Error: fail to run wget in guest")
        Test_Result = 1
        return Test_Result

    # Check nic and blk driver in guest
    if 'kvm' in virt_type or 'xenfv' in virt_type:
        logger.info("check point6: check nic and blk driver in guest is \
                     expected as your config:")
        if utils.validate_remote_nic_type(ipaddr, "root", "redhat",
           nic_type, logger) == 0 and \
           utils.validate_remote_blk_type(ipaddr, "root", "redhat",
                                        blk_type, logger) == 0:
            logger.info("nic type - %s and blk type - %s check successfully" %
                       (nic_type, blk_type))
        else:
            logger.error("Error: nic type - %s or blk type - %s check failed" %
                        (nic_type, blk_type))
            Test_Result = 1
            return Test_Result

    return Test_Result
Пример #2
0
def cpu_affinity(params):
    """set vcpu of virtual machine to value of parameter vcpu
       call libvirt API function to set cpu affinity
       check the result after cpupin
    """
    global logger
    logger = params['logger']
    params.pop('logger')
    domain_name = params['guestname']
    vcpu = params['vcpu']

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

    conn = sharedmod.libvirtobj['conn']
    uri = conn.getURI()
    hypervisor = uri.split(':')[0]

    # Get cpu affinity
    guest_names = []
    ids = conn.listDomainsID()
    for id in ids:
        obj = conn.lookupByID(id)
        guest_names.append(obj.name())

    if domain_name not in guest_names:
        logger.error("guest %s doesn't exist or not be running." %
                      domain_name)
        return 1

    domobj = conn.lookupByName(domain_name)

    vcpunum = utils.get_num_vcpus(domain_name)
    logger.info("the current vcpu number of guest %s is %s" % \
                (domain_name, vcpunum))

    if vcpunum != vcpu:
        logger.info("set the vcpu of the guest to %s" % vcpu)
        ret = set_vcpus(domobj, domain_name, vcpu)
        if ret != 0:
            return 1

    vcpunum_after_set = utils.get_num_vcpus(domain_name)
    logger.info("after setting, the current vcpu number the guest is %s" % \
                 vcpunum_after_set)
    vcpu_list = range(int(vcpunum_after_set))

    physical_cpu_num = utils.get_host_cpus()
    logger.info("in the host, we have %s physical cpu" % physical_cpu_num)

    cpu_affinity = ()
    for i in range(physical_cpu_num):
        cpu_affinity = cpu_affinity + (False,)

    retflag = 0
    for i in range(physical_cpu_num):
        cpu_affinity_test = ()
        for affinity_num in range(len(cpu_affinity)):
            if affinity_num == i:
                cpu_affinity_test = cpu_affinity_test + (True,)
            else:
                cpu_affinity_test = cpu_affinity_test + \
                                    (cpu_affinity[affinity_num],)

        logger.debug("the data for testing is")
        logger.debug(cpu_affinity_test)

        for vcpu_pinned in vcpu_list:
            try:
                logger.info("Now, we pin vcpu %s to physical vcpu %s" %
                            (vcpu_pinned, i))

                shell_cmd = "virsh vcpuinfo %s" % domain_name
                text = commands.getstatusoutput(shell_cmd)[1]
                logger.debug("before pinning, the vcpu status is %s" % text)

                domobj.pinVcpu(vcpu_pinned, cpu_affinity_test)
            except libvirtError, e:
                logger.error("API error message: %s, error code is %s" \
                             % (e.message, e.get_error_code()))
                logger.error("fail to vcpupin domain")
                return 1

            ret = vcpu_affinity_check(domain_name, vcpu_pinned, i, hypervisor)
            retflag = retflag + ret
            if ret:
                logger.error("vcpu affinity checking failed.")
            else:
                logger.info("vcpu affinity checking successed.")
Пример #3
0
def cpu_affinity(params):
    """set vcpu of virtual machine to value of parameter vcpu
       call libvirt API function to set cpu affinity
       check the result after cpupin
    """
    global logger
    logger = params['logger']
    params.pop('logger')
    domain_name = params['guestname']
    vcpu = params['vcpu']

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

    conn = sharedmod.libvirtobj['conn']
    uri = conn.getURI()
    hypervisor = uri.split(':')[0]

    # Get cpu affinity
    guest_names = []
    ids = conn.listDomainsID()
    for id in ids:
        obj = conn.lookupByID(id)
        guest_names.append(obj.name())

    if domain_name not in guest_names:
        logger.error("guest %s doesn't exist or not be running." % domain_name)
        return 1

    domobj = conn.lookupByName(domain_name)

    vcpunum = utils.get_num_vcpus(domain_name)
    logger.info("the current vcpu number of guest %s is %s" % \
                (domain_name, vcpunum))

    if vcpunum != vcpu:
        logger.info("set the vcpu of the guest to %s" % vcpu)
        ret = set_vcpus(domobj, domain_name, vcpu)
        if ret != 0:
            return 1

    vcpunum_after_set = utils.get_num_vcpus(domain_name)
    logger.info("after setting, the current vcpu number the guest is %s" % \
                 vcpunum_after_set)
    vcpu_list = range(int(vcpunum_after_set))

    physical_cpu_num = utils.get_host_cpus()
    logger.info("in the host, we have %s physical cpu" % physical_cpu_num)

    cpu_affinity = ()
    for i in range(physical_cpu_num):
        cpu_affinity = cpu_affinity + (False, )

    retflag = 0
    for i in range(physical_cpu_num):
        cpu_affinity_test = ()
        for affinity_num in range(len(cpu_affinity)):
            if affinity_num == i:
                cpu_affinity_test = cpu_affinity_test + (True, )
            else:
                cpu_affinity_test = cpu_affinity_test + \
                                    (cpu_affinity[affinity_num],)

        logger.debug("the data for testing is")
        logger.debug(cpu_affinity_test)

        for vcpu_pinned in vcpu_list:
            try:
                logger.info("Now, we pin vcpu %s to physical vcpu %s" %
                            (vcpu_pinned, i))

                shell_cmd = "virsh vcpuinfo %s" % domain_name
                text = commands.getstatusoutput(shell_cmd)[1]
                logger.debug("before pinning, the vcpu status is %s" % text)

                domobj.pinVcpu(vcpu_pinned, cpu_affinity_test)
            except libvirtError, e:
                logger.error("API error message: %s, error code is %s" \
                             % (e.message, e.get_error_code()))
                logger.error("fail to vcpupin domain")
                return 1

            ret = vcpu_affinity_check(domain_name, vcpu_pinned, i, hypervisor)
            retflag = retflag + ret
            if ret:
                logger.error("vcpu affinity checking failed.")
            else:
                logger.info("vcpu affinity checking successed.")