def mult_thread(func, num, pre_path="/"):
    #    pool = Pool(processes = num)
    thread = []
    results = []
    if pre_path != "/":
        path = pre_path + "/"
        curvefs = swig_operate.LibCurve()
        rc = curvefs.libcurve_statfs(pre_path,
                                     user_name=config.user_name,
                                     pass_word=config.pass_word)
        logger.debug("path is %s" % path)
        parentid = rc.id
    else:
        path = pre_path
        parentid = 0
    for i in xrange(num):
        #        results.append(pool.apply_async(globals().get(func),args=("/"+str(i),)))
        filename = path + str(i)
        logger.debug("filename is %s" % filename)
        t = mythread.runThread(globals().get(func), filename)
        thread.append(t)
        logger.debug("%s %s" % (func, str(i)))
    for t in thread:
        t.start()
    if str(func) == "statfs_libcurve_file":
        for t in thread:
            result = t.get_result()
            assert result.length == 10737418240, "file length is %d" % (
                result.length)
            assert result.parentid == parentid, "file parentid is %d,pre id is %d" % (
                result.parentid, parentid)
            assert result.filetype == 1, "file filetype is %d" % (
                result.filetype)
    elif str(func) == "open_libcurve_file":
        for t in thread:
            results.append(t.get_result())
            assert t.get_result(
            ) != None, "open file fd is %d" % t.get_result()
        return results
    elif str(func) == "create_libcurve_file":
        for t in thread:
            rc = t.get_result()
            logger.debug("get result is %d" % rc)
            if rc == -1:
                logger.error("file exist")
            else:
                assert rc == 0, "result is %s" % str(rc)
    elif str(func) == "delete_libcurve_file":
        for t in thread:
            rc = t.get_result()
            logger.debug("get result is %d" % rc)
            if rc == -6:
                logger.error("file not exist")
            else:
                assert rc == 0, "result is %s" % str(rc)
    else:
        for t in thread:
            rc = t.get_result()
            logger.debug("get result is %d" % rc)
            assert rc == 0, "result is %s" % str(rc)
def open_libcurve_file(file_name=config.file_name,
                       user_name=config.user_name,
                       pass_word=config.pass_word):
    curvefs = swig_operate.LibCurve()
    fd = curvefs.libcurve_open(file_name, user_name, pass_word)
    logger.info("fd=%s" % fd)
    return fd
def thrasher(fd):
    actions = []
    actions.append((
        extend_libcurve_file,
        1.0,
    ))
    actions.append((
        test,
        0.5,
    ))
    curvefs = swig_operate.LibCurve()
    #    actions.append((create_libcurve_file,1.0,))
    for i in range(1, 10):
        total = sum([y for (x, y) in actions])
        logger.debug("total %s" % (total))
        val = random.uniform(0, total)
        logger.debug("val is %s" % (val))
        for (action, prob) in actions:
            logger.info("running time %s " % (i))
            if val < prob:
                if action == extend_libcurve_file:
                    new_size = 10737418240 * i
                    logger.debug("running action %s" % (action))
                    rc = action(new_size=new_size)
                    assert rc == 0
                    rc = curvefs.libcurve_statfs(file_name=config.file_name, user_name=config.user_name, \
                                                 pass_word=config.pass_word)
                    assert rc.length == new_size, "get file length is %d" % rc.length
                else:
                    action()
            val -= prob
def write_libcurve_file_error(fd,
                              buf=config.buf,
                              offset=config.offset,
                              length=config.length):
    curvefs = swig_operate.LibCurve()
    ret = curvefs.libcurve_write(fd, buf, offset, length)
    logger.debug("write error,return id is %d" % ret)
    return ret
示例#5
0
def create_multi_dir(depth,user_name=config.user_name, pass_word=config.pass_word):
    curvefs = swig_operate.LibCurve()
    pre_path = ""
    for i in range(depth):
        dir_path = pre_path + "/" + str(i)
        rc = curvefs.libcurve_mkdir(dir_path, user_name, pass_word)
        logger.debug("create dir dir_path %s"%dir_path)
        assert rc == 0,"crate dir %s fail ,rc is %d"%(dir_path,rc)
        pre_path = dir_path
def delete_curve_file_for_shanpshot():
    curvefs = swig_operate.LibCurve()
    rc = curvefs.libcurve_delete(config.snapshot_file_name, config.user_name,
                                 config.pass_word)
    if rc != 0:
        logger.info("delete_curve_file_for_shanpshot file fail. rc = %s" % rc)
        return rc
    else:
        return rc
示例#7
0
def delete_libcurve_dir(dir_path = config.dir_path, user_name = config.user_name, pass_word = config.pass_word):
    curvefs = swig_operate.LibCurve()
    rc = curvefs.libcurve_rmdir(dir_path, user_name, pass_word)
    if rc != 0:
        #logger.error("delete libcurve dir fail. rc = %s" %rc)
        return rc
        #raise AssertionError
    else:
        return rc
def close_libcurve_file(fd):
    curvefs = swig_operate.LibCurve()
    rc = curvefs.libcurve_close(fd)
    if rc != 0:
        logger.error("close libcurve file fail. rc = %s" % rc)
        return rc
        #raise AssertionError
    else:

        return rc
示例#9
0
def write_libcurve_file(fd, buf=config.buf, offset=config.offset, length=config.length):
    curvefs = swig_operate.LibCurve()
    logger.info("fd=%s, buf=%s, offset=%s, length=%s" % (fd, buf, offset, length))
    rc = curvefs.libcurve_write(fd, buf, offset, length)
    if rc < 0:
        logger.error("write libcurve file fail. rc = %s" %rc)
        return rc
        raise AssertionError
    else:
        return rc
示例#10
0
def delete_libcurve_file(file_name = config.file_name, user_name = config.user_name, pass_word = config.pass_word):
    curvefs = swig_operate.LibCurve()
    rc = curvefs.libcurve_delete(file_name, user_name, pass_word)
    if rc != 0:
        logger.debug("delete libcurve file %s fail. rc = %s" %(file_name,str(rc)))
        return rc
        #raise AssertionError
    else:
        logger.debug("delete libcurve file %s success. rc = %s" %(file_name,str(rc)))
        return rc
示例#11
0
def statfs_libcurve_dir(dir_path =config.dir_path, user_name = config.user_name, pass_word = config.pass_word):
    curvefs = swig_operate.LibCurve()
    rc = curvefs.libcurve_statfs(dir_path, user_name, pass_word)

    if rc < 0:
        logger.info("stafs libcurve dir fail. rc = %s" %rc)
        return rc
        #raise AssertionError
    else:
        return rc
示例#12
0
def rename_libcurve_file(old_name=config.old_name, new_name=config.new_name, user_name=config.user_name, pass_word=config.pass_word):
    curvefs = swig_operate.LibCurve()
    rc = curvefs.libcurve_rename(user_name, old_name, new_name, pass_word)

    if rc != 0:
        logger.info("rename libcurve file fail. rc = %s" %rc)
        return rc
        #raise AssertionError
    else:
        return rc
示例#13
0
def extend_libcurve_file(file_name=config.file_name, user_name=config.user_name, new_size=config.new_size, pass_word=config.pass_word):
    curvefs = swig_operate.LibCurve()
    rc = curvefs.libcurve_extend(file_name, user_name, new_size, pass_word)

    if rc != 0:
        logger.info("extend libcurve file fail. rc = %s" %rc)
        return rc
        #raise AssertionError
    else:
        return rc
示例#14
0
def create_libcurve_file(file_name = config.file_name, user_name = config.user_name, size = config.size, pass_word = config.pass_word):
    curvefs = swig_operate.LibCurve()
    rc = curvefs.libcurve_create(file_name, user_name, size, pass_word)
    if rc != 0:
        logger.error("create libcurve file %s fail. rc = %s" %(file_name,rc))
        return rc

        #raise AssertionError
    else:

        return rc
示例#15
0
def loop_read_write_file_with_different_iosize(fd,offset=config.offset, length=config.length):
    curvefs = swig_operate.LibCurve()
    for i in range(1,10):
        buf = str(i)*length
        logger.debug("begin write buf_length = %d"%len(buf))
        rc = curvefs.libcurve_write(fd, buf, offset, length)
        assert rc == length
        content = curvefs.libcurve_read(fd, "", offset, length)
        assert buf == content,"buf is %s,content is %s"%(buf,content)
        offset += length
        length = length*2
示例#16
0
def check_loop_read(fd, offset=config.offset, length=config.length):
    curvefs = swig_operate.LibCurve()
    #logger.debug("buf_list is %s" % config.buf_list)
    i = 1
    for data in config.buf_list:
        buf = str(data) * length
        content = curvefs.libcurve_read(fd, buf, offset, length)
        assert buf == content, "buf is %s,content is %s" % (buf, content)
        logger.debug("read data is content %s" % content)
        i += 1
        offset += length
def create_curve_file_for_snapshot_delete(file_name="/lc-delete",
                                          user_name=config.user_name,
                                          size=config.size,
                                          pass_word=config.pass_word):
    curvefs = swig_operate.LibCurve()
    rc = curvefs.libcurve_create(file_name, user_name, size, pass_word)
    if rc != 0:
        logger.info("create_curve_file_for_snapshot file fail. rc = %s" % rc)
        return rc
    else:
        return rc
示例#18
0
def delete_multi_dir(depth,user_name=config.user_name, pass_word=config.pass_word):
    curvefs = swig_operate.LibCurve()
    last_path = ""
    for i in range(depth):
        last_path = last_path + "/" + str(i)
    dir_path = last_path
    for i in range(depth):
        rc = curvefs.libcurve_rmdir(dir_path, user_name, pass_word)
        logger.debug("rm dir dir_path %s" % dir_path)
        assert rc == 0, "rm dir %s fail ,rc is %d" % (dir_path, rc)
        dir_path = last_path.rsplit("/", 1)[0]
        last_path = dir_path
示例#19
0
def loop_write_file_noassert(fd, num, offset, length):
    curvefs = swig_operate.LibCurve()
    i = 1
    buf_list = []
    while i < num + 1:
        if config.write_stopped == True:
            break
        buf_data = random.randint(1, 9)
        buf = str(buf_data) * length
        logger.debug("begin write buf_data = %d" % buf_data)
        rc = curvefs.libcurve_write(fd, buf, offset, length)
        logger.debug("rc is %d" % rc)
        if rc > 0:
            buf_list.append(buf_data)
            i += 1
            offset += length
    config.buf_list = buf_list
    config.write_stopped = False
def modify_curve_file_for_snapshot(file_name=config.snapshot_file_name,
                                   user_name=config.user_name,
                                   pass_word=config.pass_word,
                                   offset=config.offset,
                                   length=config.length):
    curvefs = swig_operate.LibCurve()
    fd = curvefs.libcurve_open(file_name, user_name, pass_word)
    buf = "tttttttt" * 512
    logger.info("fd=%s, buf=%s, offset=%s, length=%s" %
                (fd, buf, offset, length))
    rs = curvefs.libcurve_write(fd, buf, offset, length)
    if rs < 0:
        logger.error(
            "write_curve_file_for_snapshot libcurve_write file fail. rc = %s" %
            rs)
        return rs
        raise AssertionError
    rc = curvefs.libcurve_close(fd)
    if rc != 0:
        logger.info(
            "write_curve_file_for_snapshot close libcurve file fail. rc = %s" %
            rc)
    return rc
def read_4k_length_curve_file():
    curvefs = swig_operate.LibCurve()
    fd = curvefs.libcurve_open(config.snapshot_file_name, config.user_name,
                               config.pass_word)
    content = curvefs.libcurve_read(fd, "", 0, 4096)
    return content
示例#22
0
def read_libcurve_file(fd, buf="", offset=config.offset, length=config.length):
    curvefs = swig_operate.LibCurve()
    content = curvefs.libcurve_read(fd, buf, offset, length)
    return content