def vol_resize_delta(params):
    """test volume resize with delta flags"""

    global logger
    logger = params['logger']
    poolname = params['poolname']
    volname = params['volname']
    capacity = params['capacity']

    logger.info("the poolname is %s, volname is %s" % (poolname, volname))

    logger.info("the capacity given is %s" % capacity)
    out = utils.get_capacity_suffix_size(capacity)
    capacity_val = out['capacity_byte']
    logger.debug("the capacity to byte is %s" % capacity_val)

    conn = sharedmod.libvirtobj['conn']
    try:
        poolobj = conn.storagePoolLookupByName(poolname)
        vol = poolobj.storageVolLookupByName(volname)

        logger.info("get volume info before resize")
        out = vol.info()
        pre_capacity = out[1]
        pre_allocation = out[2]
        logger.info("volume capacity is %s bytes, allocation is %s bytes" %
                    (pre_capacity, pre_allocation))

        flag = libvirt.VIR_STORAGE_VOL_RESIZE_DELTA
        logger.info("resize %s with capacity %s in pool %s using flag: %s" %
                    (volname, capacity, poolname, flag))

        vol.resize(capacity_val, flag)

        logger.info("get volume info after resize")
        out = vol.info()
        post_capacity = out[1]
        post_allocation = out[2]
        logger.info("volume capacity is %s bytes, allocation is %s bytes" %
                    (post_capacity, post_allocation))

        logger.info("check resize effect")
        if post_capacity - pre_capacity == capacity_val:
            logger.info("increased size is expected")
        else:
            logger.error("increase size not equal to set, resize failed")
            return 1

        if pre_allocation == post_allocation:
            logger.info("allocation is expected")
        else:
            logger.error("allocation changed, resize failed")
            return 1

        logger.info("resize succeed")

    except libvirtError, e:
        logger.error("libvirt call failed: " + str(e))
        return 1
def write_file(path, capacity):
    """write test data to file
    """
    logger.info("write %s data into file %s" % (capacity, path))
    out = utils.get_capacity_suffix_size(capacity)
    f = open(path, 'w')
    datastr = ''.join(string.lowercase + string.uppercase + string.digits +
                      '.' + '\n')
    repeat = out['capacity_byte'] / 64
    data = ''.join(repeat * datastr)
    f.write(data)
    f.close()
def write_file(path, capacity):
    """write test data to file
    """
    logger.info("write %s data into file %s" % (capacity, path))
    out = utils.get_capacity_suffix_size(capacity)
    f = open(path, 'w')
    datastr = ''.join(string.lowercase + string.uppercase
                      + string.digits + '.' + '\n')
    repeat = out['capacity_byte'] / 64
    data = ''.join(repeat * datastr)
    f.write(data)
    f.close()
예제 #4
0
def vol_resize_delta(params):
    """test volume resize with delta flags"""

    global logger
    logger = params['logger']
    poolname = params['poolname']
    volname = params['volname']
    capacity = params['capacity']

    logger.info("the poolname is %s, volname is %s" %
                (poolname, volname))

    logger.info("the capacity given is %s" % capacity)
    out = utils.get_capacity_suffix_size(capacity)
    capacity_val = out['capacity_byte']
    logger.debug("the capacity to byte is %s" % capacity_val)

    conn = sharedmod.libvirtobj['conn']
    try:
        poolobj = conn.storagePoolLookupByName(poolname)
        vol = poolobj.storageVolLookupByName(volname)

        logger.info("get volume info before resize")
        out = vol.info()
        pre_capacity = out[1]
        pre_allocation = out[2]
        logger.info("volume capacity is %s bytes, allocation is %s bytes" %
                    (pre_capacity, pre_allocation))

        flag = libvirt.VIR_STORAGE_VOL_RESIZE_DELTA
        logger.info("resize %s with capacity %s in pool %s using flag: %s"
                    % (volname, capacity, poolname, flag))

        vol.resize(capacity_val, flag)

        logger.info("get volume info after resize")
        out = vol.info()
        post_capacity = out[1]
        post_allocation = out[2]
        logger.info("volume capacity is %s bytes, allocation is %s bytes" %
                    (post_capacity, post_allocation))

        logger.info("check resize effect")
        if post_capacity - pre_capacity == capacity_val:
            logger.info("increased size is expected")
        else:
            logger.error("increase size not equal to set, resize failed")
            return 1

        if pre_allocation == post_allocation:
            logger.info("allocation is expected")
        else:
            logger.error("allocation changed, resize failed")
            return 1

        logger.info("resize succeed")

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

    return 0
예제 #5
0
def dir_vol_wipe(params):
    """test volume download and check"""

    global logger
    logger = params['logger']
    poolname = params['poolname']
    volname = params['volname']
    volformat = params['volformat']
    capacity = params['capacity']
    xmlstr = params['xml']

    logger.info("the poolname is %s, volname is %s, volformat is %s" %
                (poolname, volname, volformat))

    conn = sharedmod.libvirtobj['conn']
    try:
        poolobj = conn.storagePoolLookupByName(poolname)
        path_value = get_pool_path(poolobj)
        volume_path = path_value + "/" + volname

        xmlstr = xmlstr.replace('VOLPATH', volume_path)
        xmlstr = xmlstr.replace('SUFFIX', capacity[-1])
        xmlstr = xmlstr.replace('CAP', capacity[:-1])
        logger.debug("volume xml:\n%s" % xmlstr)

        logger.info("create %s %s volume" % (volname, volformat))
        vol = poolobj.createXML(xmlstr, 0)

        write_file(volume_path, capacity)

        poolobj.refresh(0)

        origdigest = utils.digest(volume_path, 0, 0)
        logger.debug("the md5 hex digest of data read from %s is: %s" %
                     (volume_path, origdigest))

        test_path = path_value + "/" + "vol_test"
        out = utils.get_capacity_suffix_size(capacity)
        count = out['capacity_byte'] / 1024
        logger.info("write %s zero to test volume %s" % (capacity, test_path))
        cmd = "dd if=/dev/zero of=%s bs=1024 count=%s" % (test_path, count)
        utils.exec_cmd(cmd, shell=True)
        cmpdigest = utils.digest(test_path, 0, 0)
	logger.debug("the compare volume digest is: %s" % cmpdigest)

        logger.info("wipe volume %s" % volume_path)
        vol.wipe(0)

        newdigest = utils.digest(volume_path, 0, 0)
        logger.debug("the volum digest of data read from %s after wipe is: %s"
                      % (volume_path, newdigest))

        logger.info("check the digest before and after wipe")
        if newdigest == origdigest:
            logger.error("wipe failed, digest did not change")
            return 1
        else:
            logger.info("digest is different before and after wipe")

        logger.info("compare the digest after wipe with digest of volume %s" %
                    test_path)
        if not newdigest == cmpdigest:
            logger.error("wipe failed, digest is different")
            return 1
        else:
            logger.info("digest is same with zero volume %s" % test_path)

        logger.info("wipe succeed")

    except libvirtError, e:
        logger.error("libvirt call failed: " + str(e))
        return 1
def dir_vol_wipe(params):
    """test volume download and check"""

    global logger
    logger = params['logger']
    poolname = params['poolname']
    volname = params['volname']
    volformat = params['volformat']
    capacity = params['capacity']
    xmlstr = params['xml']

    logger.info("the poolname is %s, volname is %s, volformat is %s" %
                (poolname, volname, volformat))

    conn = sharedmod.libvirtobj['conn']
    try:
        poolobj = conn.storagePoolLookupByName(poolname)
        path_value = get_pool_path(poolobj)
        volume_path = path_value + "/" + volname

        xmlstr = xmlstr.replace('VOLPATH', volume_path)
        xmlstr = xmlstr.replace('SUFFIX', capacity[-1])
        xmlstr = xmlstr.replace('CAP', capacity[:-1])
        logger.debug("volume xml:\n%s" % xmlstr)

        logger.info("create %s %s volume" % (volname, volformat))
        vol = poolobj.createXML(xmlstr, 0)

        write_file(volume_path, capacity)

        poolobj.refresh(0)

        origdigest = utils.digest(volume_path, 0, 0)
        logger.debug("the md5 hex digest of data read from %s is: %s" %
                     (volume_path, origdigest))

        test_path = path_value + "/" + "vol_test"
        out = utils.get_capacity_suffix_size(capacity)
        count = out['capacity_byte'] / 1024
        logger.info("write %s zero to test volume %s" % (capacity, test_path))
        cmd = "dd if=/dev/zero of=%s bs=1024 count=%s" % (test_path, count)
        utils.exec_cmd(cmd, shell=True)
        cmpdigest = utils.digest(test_path, 0, 0)
        logger.debug("the compare volume digest is: %s" % cmpdigest)

        logger.info("wipe volume %s" % volume_path)
        vol.wipe(0)

        newdigest = utils.digest(volume_path, 0, 0)
        logger.debug(
            "the volum digest of data read from %s after wipe is: %s" %
            (volume_path, newdigest))

        logger.info("check the digest before and after wipe")
        if newdigest == origdigest:
            logger.error("wipe failed, digest did not change")
            return 1
        else:
            logger.info("digest is different before and after wipe")

        logger.info("compare the digest after wipe with digest of volume %s" %
                    test_path)
        if not newdigest == cmpdigest:
            logger.error("wipe failed, digest is different")
            return 1
        else:
            logger.info("digest is same with zero volume %s" % test_path)

        logger.info("wipe succeed")

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

    return 0