예제 #1
0
def check_domain_image(domobj, guestname, logger):
    """ensure that the state of guest is poweroff
       and its disk image is the type of qcow2
    """
    dom_xml = domobj.XMLDesc(0)
    disk_path = utils.get_disk_path(dom_xml)
    status, ret = commands.getstatusoutput(QEMU_IMAGE_FORMAT % disk_path)
    if status:
        logger.error(
            "executing " +
            "\"" +
            QEMU_IMAGE_FORMAT %
            guestname +
            "\"" +
            " failed")
        logger.error(ret)
        return False
    else:
        format = ret
        if format == "qcow2":
            return True
        else:
            logger.error("%s has a disk %s with type %s, \
                          only qcow2 supports internal snapshot" %
                         (guestname, disk_path, format))
            return False
예제 #2
0
def check_domain_image(domobj, guestname, logger):
    """ensure that the state of guest is poweroff
       and its disk image is the type of qcow2
    """
    dom_xml = domobj.XMLDesc(0)
    disk_path = utils.get_disk_path(dom_xml)
    status, ret = commands.getstatusoutput(QEMU_IMAGE_FORMAT % disk_path)
    if status:
        logger.error("executing " + "\"" + QEMU_IMAGE_FORMAT % guestname +
                     "\"" + " failed")
        logger.error(ret)
        return False
    else:
        format = ret
        if format == "qcow2":
            return True
        else:
            logger.error("%s has a disk %s with type %s, \
                          only qcow2 supports internal snapshot"                                                                 % \
                          (guestname, disk_path, format))
            return False
def domain_nfs_start_clean(params):
    """clean testing environment"""
    logger = params['logger']
    guestname = params['guestname']


    # Connect to local hypervisor connection URI
    conn = utils.get_conn()
    domobj = conn.lookupByName(guestname)

    if domobj.info()[0] != libvirt.VIR_DOMAIN_SHUTOFF:
        domobj.destroy()

    dom_xml = domobj.XMLDesc(0)
    disk_file = utils.get_disk_path(dom_xml)
    img_dir = os.path.dirname(disk_file)
    file_name = os.path.basename(disk_file)
    temp_file = "/tmp/%s" % file_name

    if os.path.ismount(img_dir):
        umount_cmd = "umount -f %s" % img_dir
        ret, out = utils.exec_cmd(umount_cmd, shell=True)
        if ret:
            logger.error("failed to umount %s" % img_dir)

    if os.path.exists(temp_file):
        os.remove(temp_file)

    clean_nfs_conf = "sed -i '$d' /etc/exports"
    utils.exec_cmd(clean_nfs_conf, shell=True)

    clean_qemu_conf = "sed -i '$d' %s" % QEMU_CONF
    utils.exec_cmd(clean_qemu_conf, shell=True)

    cmd = "service libvirtd restart"
    utils.exec_cmd(cmd, shell=True)

    return 0
예제 #4
0
def domain_nfs_start_clean(params):
    """clean testing environment"""
    logger = params['logger']
    guestname = params['guestname']

    # Connect to local hypervisor connection URI
    conn = utils.get_conn()
    domobj = conn.lookupByName(guestname)

    if domobj.info()[0] != libvirt.VIR_DOMAIN_SHUTOFF:
        domobj.destroy()

    dom_xml = domobj.XMLDesc(0)
    disk_file = utils.get_disk_path(dom_xml)
    img_dir = os.path.dirname(disk_file)
    file_name = os.path.basename(disk_file)
    temp_file = "/tmp/%s" % file_name

    if os.path.ismount(img_dir):
        umount_cmd = "umount -f %s" % img_dir
        ret, out = utils.exec_cmd(umount_cmd, shell=True)
        if ret:
            logger.error("failed to umount %s" % img_dir)

    if os.path.exists(temp_file):
        os.remove(temp_file)

    clean_nfs_conf = "sed -i '$d' /etc/exports"
    utils.exec_cmd(clean_nfs_conf, shell=True)

    clean_qemu_conf = "sed -i '$d' %s" % QEMU_CONF
    utils.exec_cmd(clean_qemu_conf, shell=True)

    cmd = "service libvirtd restart"
    utils.exec_cmd(cmd, shell=True)

    return 0
예제 #5
0
        return 1

    if state != libvirt.VIR_DOMAIN_SHUTOFF:
        logger.info("shut down the domain %s" % guestname)
        try:
            domobj.destroy()
        except libvirtError, e:
            logger.error("API error message: %s, error code is %s" %
                         (e.message, e.get_error_code()))
            logger.error("Error: fail to destroy domain %s" % guestname)
            return 1

    logger.info("get guest img file path")
    try:
        dom_xml = domobj.XMLDesc(0)
        disk_file = utils.get_disk_path(dom_xml)
        logger.info("%s disk file path is %s" % (guestname, disk_file))
        img_dir = os.path.dirname(disk_file)
    except libvirtError, e:
        logger.error("API error message: %s, error code is %s" %
                     (e.message, e.get_error_code()))
        logger.error("Error: fail to get domain %s xml" % guestname)
        return 1

    # set env
    logger.info("prepare the environment")
    ret = prepare_env(dynamic_ownership, virt_use_nfs, guestname, root_squash,
                      disk_file, img_dir, logger)
    if ret:
        logger.error("failed to prepare the environment")
        return 1
        return 1

    if state != libvirt.VIR_DOMAIN_SHUTOFF:
        logger.info("shut down the domain %s" % guestname)
        try:
            domobj.destroy()
        except libvirtError, e:
            logger.error("API error message: %s, error code is %s" \
                         % (e.message, e.get_error_code()))
            logger.error("Error: fail to destroy domain %s" % guestname)
            return 1

    logger.info("get guest img file path")
    try:
        dom_xml = domobj.XMLDesc(0)
        disk_file = utils.get_disk_path(dom_xml)
        logger.info("%s disk file path is %s" % (guestname, disk_file))
        img_dir = os.path.dirname(disk_file)
    except libvirtError, e:
        logger.error("API error message: %s, error code is %s" \
                     % (e.message, e.get_error_code()))
        logger.error("Error: fail to get domain %s xml" % guestname)
        return 1

    # set env
    logger.info("prepare the environment")
    ret = prepare_env(dynamic_ownership, virt_use_nfs, guestname, \
                      root_squash, disk_file, img_dir, logger)
    if ret:
        logger.error("failed to prepare the environment")
        return 1