def dir_vol_wipe_pattern(params):
    """test volume download and check"""

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

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

    logger.info("the wipe algorithm given is %s" % algorithm)
    alg_str = 'libvirt.VIR_STORAGE_VOL_WIPE_ALG_%s' % algorithm.upper()
    alg_val = eval(alg_str)
    logger.info("the correspond algorithm value is %s" % alg_val)

    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))

        logger.info("wipe volume %s with algorithm value %s" %
                    (volume_path, alg_val))
        vol.wipePattern(alg_val, 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 with algorithm %s failed, digest is the same" %
                         algorithm)
            return 1
        else:
            logger.info("digest is different before and after wipe")

        logger.info("wipe with algorithm %s succeed" % algorithm)

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

    return 0
示例#2
0
def dir_vol_upload(params):
    """test volume download and check"""

    global logger
    logger = params['logger']
    poolname = params['poolname']
    volname = params['volname']
    volformat = params['volformat']
    offset = int(params['offset'])
    length = int(params['length'])
    capacity = params['capacity']
    xmlstr = params['xml']

    logger.info("the poolname is %s, volname is %s, volformat is %s" %
                (poolname, volname, volformat))
    logger.info("upload offset is: %s" % offset)
    logger.info("the data length to upload is: %s" % length)

    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)

        test_path = path_value + "/" + "vol_test"
        write_file(test_path)
        olddigest = utils.digest(test_path, 0, 0)
        logger.debug("the old file digest is: %s" % olddigest)

        if offset:
            origdigestpre = utils.digest(volume_path, 0, offset)
        else:
            origdigestpre = ''
        logger.debug("the original pre region digest is: %s" % origdigestpre)

        origdigestpost = utils.digest(volume_path, offset + 1024 * 1024, 0)
        logger.debug("the original post region digest is: %s" % origdigestpost)

        st = conn.newStream(0)

        f = open(test_path, 'r')
        logger.info("start upload")
        vol.upload(st, offset, length, 0)
        logger.info("sent all data")
        st.sendAll(handler, f)
        logger.info("finished stream")
        st.finish()
        f.close()

        newdigest = utils.digest(volume_path, offset, 1024 * 1024)
        logger.debug("the new file digest is: %s" % olddigest)

        if offset:
            newdigestpre = utils.digest(volume_path, 0, offset)
        else:
            newdigestpre = ''
        logger.debug("the new pre region digest is: %s" % origdigestpre)

        newdigestpost = utils.digest(volume_path, offset + 1024 * 1024, 0)
        logger.debug("the new post region digest is: %s" % origdigestpost)

        if newdigestpre == origdigestpre:
            logger.info("file pre region digests match")
        else:
            logger.error("file pre region digests not match")
            return 1

        if olddigest == newdigest:
            logger.info("file digests match")
        else:
            logger.error("file digests not match")
            return 1

        if newdigestpost == origdigestpost:
            logger.info("file post region digests match")
        else:
            logger.error("file post region digests not match")
            return 1

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

    return 0
def dir_vol_download(params):
    """test volume download and check"""

    global logger
    logger = params['logger']
    poolname = params['poolname']
    volname = params['volname']
    volformat = params['volformat']
    offset = int(params['offset'])
    length = int(params['length'])
    capacity = params['capacity']
    xmlstr = params['xml']

    logger.info("the poolname is %s, volname is %s, volformat is %s" %
                (poolname, volname, volformat))
    logger.info("download offset is: %s" % offset)
    logger.info("the data length to download is: %s" % length)

    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)
        origdigest = utils.digest(volume_path, offset, length)
        logger.debug("the md5 hex digest of data read from %s is: %s" %
                     (volume_path, origdigest))

        st = conn.newStream(0)

        test_path = path_value + "/" + "vol_test"

        f = open(test_path, 'w')
        logger.info("start download")
        vol.download(st, offset, length, 0)
        logger.info("downloaded all data")
        st.recvAll(handler, f)
        logger.info("finished stream")
        st.finish()
        f.close()

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

        if origdigest == newdigest:
            logger.info("file digests match, download succeed")
        else:
            logger.error("file digests not match, download failed")
            return 1

    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, e:
        logger.error("libvirt call failed: " + str(e))
        return 1
def dir_vol_wipe_pattern(params):
    """test volume download and check"""

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

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

    logger.info("the wipe algorithm given is %s" % algorithm)
    alg_str = 'libvirt.VIR_STORAGE_VOL_WIPE_ALG_%s' % algorithm.upper()
    alg_val = eval(alg_str)
    logger.info("the correspond algorithm value is %s" % alg_val)

    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))

        logger.info("wipe volume %s with algorithm value %s" %
                    (volume_path, alg_val))
        vol.wipePattern(alg_val, 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 with algorithm %s failed, digest is the same"
                         % algorithm)
            return 1
        else:
            logger.info("digest is different before and after wipe")

        logger.info("wipe with algorithm %s succeed" % algorithm)

    except libvirtError, e:
        logger.error("libvirt call failed: " + str(e))
        return 1
示例#6
0
def dir_vol_download(params):
    """test volume download and check"""

    global logger
    logger = params['logger']
    poolname = params['poolname']
    volname = params['volname']
    volformat = params['volformat']
    offset = int(params['offset'])
    length = int(params['length'])
    capacity = params['capacity']
    xmlstr = params['xml']

    logger.info("the poolname is %s, volname is %s, volformat is %s" %
                (poolname, volname, volformat))
    logger.info("download offset is: %s" % offset)
    logger.info("the data length to download is: %s" % length)

    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)
        origdigest = utils.digest(volume_path, offset, length)
        logger.debug("the md5 hex digest of data read from %s is: %s" %
                     (volume_path, origdigest))

        st = conn.newStream(0)

        test_path = path_value + "/" + "vol_test"

        f = open(test_path, 'w')
        logger.info("start download")
        vol.download(st, offset, length, 0)
        logger.info("downloaded all data")
        st.recvAll(handler, f)
        logger.info("finished stream")
        st.finish()
        f.close()

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

        if origdigest == newdigest:
            logger.info("file digests match, download succeed")
        else:
            logger.error("file digests not match, download failed")
            return 1

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

    return 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 as e:
        logger.error("libvirt call failed: " + str(e))
        return 1

    return 0