示例#1
0
文件: test_pylut.py 项目: ncsa/pylut
def test_setstripe_existing_path( testdir ):
    """
    Setstripe fails only if attempting to change stripe of an existing file
    """
    genr = ( f.path for f in testdir.files if f.typ == 'f' )
    path = genr.next()
    for c in [ None, 2 ]:
        for s in [ None, 1048576 ]:
            for i in [ None, 1 ]:
                with pytest.raises( Run_Cmd_Error ) as einfo:
                    pylut.setstripeinfo( path, count=c, size=s, offset=i )
                assert einfo.value.code == 17
                assert 'stripe already set' in einfo.value.reason
示例#2
0
def test_setstripe_existing_path(testdir):
    """
    Setstripe fails only if attempting to change stripe of an existing file
    """
    genr = (f.path for f in testdir.files if f.typ == 'f')
    path = genr.next()
    for c in [None, 2]:
        for s in [None, 1048576]:
            for i in [None, 1]:
                with pytest.raises(Run_Cmd_Error) as einfo:
                    pylut.setstripeinfo(path, count=c, size=s, offset=i)
                assert einfo.value.code == 17
                assert 'stripe already set' in einfo.value.reason
示例#3
0
文件: test_pylut.py 项目: ncsa/pylut
def test_setstripe_files( testdir ):
    """
    Verify resulting files have the correct stripe information
    """
    genr = ( f.path for f in testdir.files if f.typ == 'f' )
    for c in [ 1, 2 ]:
        for s in [ 524288, 1048576, 2097152 ]:
            for i in [ -1, 1, 2 ]:
                newpath = '{0}xyz'.format( genr.next() )
                pylut.setstripeinfo( newpath, count=c, size=s, offset=i )
                sinfo = pylut.getstripeinfo( newpath )
                assert sinfo.count == c
                assert sinfo.size == s
                if i > 0:
                    assert sinfo.offset == i
                else:
                    assert sinfo.offset >= 0
示例#4
0
def test_setstripe_files(testdir):
    """
    Verify resulting files have the correct stripe information
    """
    genr = (f.path for f in testdir.files if f.typ == 'f')
    for c in [1, 2]:
        for s in [524288, 1048576, 2097152]:
            for i in [-1, 1, 2]:
                newpath = '{0}xyz'.format(genr.next())
                pylut.setstripeinfo(newpath, count=c, size=s, offset=i)
                sinfo = pylut.getstripeinfo(newpath)
                assert sinfo.count == c
                assert sinfo.size == s
                if i > 0:
                    assert sinfo.offset == i
                else:
                    assert sinfo.offset >= 0
示例#5
0
文件: test_pylut.py 项目: ncsa/pylut
def test_setstripe_dirs( testdir ):
    """
    Verify dirs get updated stripe settings
    """
    dirs = [ d.path for d in testdir.directories ]
    while len(dirs) < 18:
        dirs = dirs*2
    counter = 0
    for c in [ 1, 2 ]:
        for s in [ 524288, 1048576, 2097152 ]:
            for i in [ -1, 1, 2 ]:
                path = dirs[ counter ]
                pylut.setstripeinfo( path, count=c, size=s, offset=i )
                sinfo = pylut.getstripeinfo( path )
                assert sinfo.count == c
                assert sinfo.size == s
                assert sinfo.offset == i
                counter+=1
示例#6
0
def test_setstripe_dirs(testdir):
    """
    Verify dirs get updated stripe settings
    """
    dirs = [d.path for d in testdir.directories]
    while len(dirs) < 18:
        dirs = dirs * 2
    counter = 0
    for c in [1, 2]:
        for s in [524288, 1048576, 2097152]:
            for i in [-1, 1, 2]:
                path = dirs[counter]
                pylut.setstripeinfo(path, count=c, size=s, offset=i)
                sinfo = pylut.getstripeinfo(path)
                assert sinfo.count == c
                assert sinfo.size == s
                assert sinfo.offset == i
                counter += 1
示例#7
0
文件: test_pylut.py 项目: ncsa/pylut
def _mkregfile( f, size=1024, stripeinfo=None ):
    """
    Overwrite contents of file with random data
    If stripeinfo is provided, first attempt to create file with given stripeinfo
    f must be an instance of fsitem
    """
    fn = str( f )
    if stripeinfo:
        if f.exists():
            os.unlink( fn )
        params = dict( count=None, size=None )
        for k in params:
            v = getatts( stripeinfo, k )
            if v > 0:
                params[ k ] = v
        pylut.setstripeinfo( fn, **params )
    if size < 1:
        return _touch( f )
    if size > 1048576:
        raise UserWarning( 'size too big for mkfile {0}'.format( size ) )
    with open( fn, 'wb' ) as fh:
        fh.write( os.urandom( size ) )
示例#8
0
def _mkregfile(f, size=1024, stripeinfo=None):
    """
    Overwrite contents of file with random data
    If stripeinfo is provided, first attempt to create file with given stripeinfo
    f must be an instance of fsitem
    """
    fn = str(f)
    if stripeinfo:
        if f.exists():
            os.unlink(fn)
        params = dict(count=None, size=None)
        for k in params:
            v = getatts(stripeinfo, k)
            if v > 0:
                params[k] = v
        pylut.setstripeinfo(fn, **params)
    if size < 1:
        return _touch(f)
    if size > 1048576:
        raise UserWarning('size too big for mkfile {0}'.format(size))
    with open(fn, 'wb') as fh:
        fh.write(os.urandom(size))