def xtestClientStateSeqid(t, env): """Verify server enforce that client stateid.seqid==0 See 8.1.3.1(draft-10): The client must...set the sequence value to zero. FLAGS: open all CODE: OPEN3 """ name = env.testname(t) c1 = env.c1.new_client(name) sess1 = c1.create_session() owner = "owner_%s" % name path = sess1.c.homedir + [name] res = create_file(sess1, owner, path, access=OPEN4_SHARE_ACCESS_WRITE) check(res) expect(res, seqid=1) # Now use returned stateid (w/o zeroing seqid) fh = res.resarray[-1].object stateid = res.resarray[-2].stateid res = sess1.compound( [op.putfh(fh), op.write(stateid, 5, FILE_SYNC4, "write test data")]) check(res, NFS4ERR_BAD_STATEID, "Using an open_stateid w/o zeroing the seqid")
def testRepTooBig(t, env): """If requester sends a request for which the size of the reply would exceed ca_maxresponsesize, the replier will return NFS4ERR_REP_TOO_BIG FLAGS: create_session all CODE: CSESS26 """ name = env.testname(t) c1 = env.c1.new_client(name) # create session with a small ca_maxresponsesize chan_attrs = channel_attrs4(0,8192,500,8192,128,8,[]) sess1 = c1.create_session(fore_attrs=chan_attrs) sess1.compound([op.reclaim_complete(FALSE)]) owner = "owner_%s" % name path = sess1.c.homedir + [name] res = create_file(sess1, owner, path, access=OPEN4_SHARE_ACCESS_BOTH) check(res) # write some data to file fh = res.resarray[-1].object stateid = res.resarray[-2].stateid res = sess1.compound([op.putfh(fh), op.write(stateid, 5, FILE_SYNC4, "write test data " * 10)]) check(res) # read data rather than ca_maxresponsesize res = sess1.compound([op.putfh(fh), op.read(stateid, 0, 500)]) check(res, NFS4ERR_REP_TOO_BIG)
def testReadWrite(t, env): """Do a simple READ and WRITE FLAGS: open all CODE: OPEN30 """ c1 = env.c1.new_client(env.testname(t)) sess1 = c1.create_session() owner = open_owner4(0, "My Open Owner") res = create_file(sess1, env.testname(t)) check(res) expect(res, seqid=1) fh = res.resarray[-1].object stateid = res.resarray[-2].stateid stateid.seqid = 0 data = "write test data" res = sess1.compound( [op.putfh(fh), op.write(stateid, 5, FILE_SYNC4, data)]) check(res) res = sess1.compound([op.putfh(fh), op.read(stateid, 0, 1000)]) check(res) if not res.resarray[-1].eof: fail("EOF not set on read") desired = "\0" * 5 + data if res.resarray[-1].data != desired: fail("Expected %r, got %r" % (desired, res.resarray[-1].data))
def testOPENClaimFH(t, env): """OPEN file with claim_type is CLAIM_FH FLAGS: open all CODE: OPEN7 """ sess1 = env.c1.new_client_session(env.testname(t)) res = create_file(sess1, env.testname(t)) check(res) fh = res.resarray[-1].object stateid = res.resarray[-2].stateid res = close_file(sess1, fh, stateid=stateid) check(res) claim = open_claim4(CLAIM_FH) how = openflag4(OPEN4_NOCREATE) oowner = open_owner4(0, "My Open Owner 2") open_op = op.open(0, OPEN4_SHARE_ACCESS_BOTH, OPEN4_SHARE_DENY_NONE, oowner, how, claim) res = sess1.compound([op.putfh(fh), open_op]) check(res) stateid = res.resarray[-1].stateid stateid.seqid = 0 data = "write test data" res = sess1.compound([op.putfh(fh), op.write(stateid, 5, FILE_SYNC4, data)]) check(res) res = sess1.compound([op.putfh(fh), op.read(stateid, 0, 1000)]) check(res) if not res.resarray[-1].eof: fail("EOF not set on read") desired = "\0"*5 + data if res.resarray[-1].data != desired: fail("Expected %r, got %r" % (desired, res.resarray[-1].data))
def testReadWrite(t, env): """Do a simple READ and WRITE FLAGS: open all CODE: OPEN400 """ c1 = env.c1.new_client(env.testname(t)) sess1 = c1.create_session() owner = open_owner4(0, "My Open Owner") how = openflag4(OPEN4_CREATE, createhow4(GUARDED4, {FATTR4_SIZE:0})) claim = open_claim4(CLAIM_NULL, env.testname(t)) open_op = op.open(0, OPEN4_SHARE_ACCESS_BOTH , OPEN4_SHARE_DENY_NONE, owner, how, claim) fh_op = op.putrootfh() res = sess1.compound([fh_op, open_op, op.getfh()]) # OPEN print res check(res) fh = res.resarray[-1].object stateid = res.resarray[-2].stateid stateid.seqid = 0 res = sess1.compound([op.putfh(fh), op.write(stateid, 5, FILE_SYNC4, "write test data")]) print res check(res) res = sess1.compound([op.putfh(fh), op.read(stateid, 0, 1000)]) print res check(res)
def ops(i): return [ op.putfh(fh), op.write(stateid, i * 1000, UNSTABLE4, chr(97 + i) * 100), op.getattr(42950721818L) ]
def testReadWrite(t, env): """Do a simple READ and WRITE FLAGS: open all CODE: OPEN400 """ c1 = env.c1.new_client(env.testname(t)) sess1 = c1.create_session() owner = open_owner4(0, "My Open Owner") how = openflag4(OPEN4_CREATE, createhow4(GUARDED4, {FATTR4_SIZE: 0})) claim = open_claim4(CLAIM_NULL, env.testname(t)) open_op = op.open(0, OPEN4_SHARE_ACCESS_BOTH, OPEN4_SHARE_DENY_NONE, owner, how, claim) fh_op = op.putrootfh() res = sess1.compound([fh_op, open_op, op.getfh()]) # OPEN print res check(res) fh = res.resarray[-1].object stateid = res.resarray[-2].stateid stateid.seqid = 0 res = sess1.compound( [op.putfh(fh), op.write(stateid, 5, FILE_SYNC4, "write test data")]) print res check(res) res = sess1.compound([op.putfh(fh), op.read(stateid, 0, 1000)]) print res check(res)
def testLockWriteLocku(t, env): """test current state id processing by having LOCK, WRITE and LOCKU in a single compound FLAGS: currentstateid all CODE: CSID4 """ sess1 = env.c1.new_client_session(env.testname(t)) res = create_file(sess1, env.testname(t)) check(res) fh = res.resarray[-1].object stateid = res.resarray[-2].stateid data = "write test data" open_to_lock_owner = open_to_lock_owner4(0, stateid, 0, lock_owner4(0, "lock1")) lock_owner = locker4(open_owner=open_to_lock_owner, new_lock_owner=True) lock_ops = [ op.lock(WRITE_LT, False, 0, NFS4_UINT64_MAX, lock_owner), op.write(current_stateid, 5, FILE_SYNC4, data), op.locku(WRITE_LT, 0, current_stateid, 0, NFS4_UINT64_MAX), op.close(0, stateid) ] res = sess1.compound([op.putfh(fh)] + lock_ops) check(res, NFS4_OK)
def testOpenWriteClose(t, env): """test current state id processing by having OPEN, WRITE and CLOSE in a single compound FLAGS: currentstateid all CODE: CSID3 """ sess1 = env.c1.new_client_session(env.testname(t)) data = "write test data" open_op = open_create_file_op(sess1, env.testname(t), open_create=OPEN4_CREATE) res = sess1.compound(open_op + [op.write(current_stateid, 5, FILE_SYNC4, data), op.close(0, current_stateid)]) check(res, NFS4_OK)
def testOpenWriteClose(t, env): """test current state id processing by having OPEN, WRITE and CLOSE in a single compound FLAGS: currentstateid all CODE: CSID3 """ sess1 = env.c1.new_client_session(env.testname(t)) data = "write test data" open_op = open_create_file_op(sess1, env.testname(t), open_create=OPEN4_CREATE) res = sess1.compound(open_op + [ op.write(current_stateid, 5, FILE_SYNC4, data), op.close(0, current_stateid) ]) check(res, NFS4_OK)
def _maketree(self, sess): """Make test tree""" # ensure /tmp (and path leading up) exists path = [] for comp in self.opts.home: path.append(comp) res = sess.compound(use_obj(path)) checklist(res, [NFS4_OK, NFS4ERR_NOENT], "LOOKUP /%s," % '/'.join(path)) if res.status == NFS4ERR_NOENT: res = create_obj(sess, path, NF4DIR) check(res, msg="Trying to create /%s," % '/'.join(path)) # ensure /tree exists and is empty tree = self.opts.path + ['tree'] res = sess.compound(use_obj(tree)) checklist(res, [NFS4_OK, NFS4ERR_NOENT]) if res.status == NFS4ERR_NOENT: res = create_obj(sess, tree, NF4DIR) check(res, msg="Trying to create /%s," % '/'.join(tree)) else: clean_dir(sess, tree) # make non-file objects in /tree d = { 'dir': NF4DIR, 'socket': NF4SOCK, 'fifo': NF4FIFO, 'link': createtype4(NF4LNK, linkdata=self.linkdata), 'block': createtype4(NF4BLK, devdata=specdata4(1, 2)), 'char': createtype4(NF4CHR, devdata=specdata4(1, 2)), } for name, kind in d.items(): path = tree + [name] res = create_obj(sess, path, kind) if res.status != NFS4_OK: log.warning("could not create /%s" % '/'.join(path)) # Make file-object in /tree fh, stateid = create_confirm(sess, 'maketree', tree + ['file']) stateid.seqid = 0 ops = [op.putfh(fh), op.write(stateid, 0, FILE_SYNC4, self.filedata)] res = sess.compound(ops) check(res, msg="Writing data to /%s/file" % '/'.join(tree)) res = close_file(sess, fh, stateid) check(res)
def _maketree(self, sess): """Make test tree""" # ensure /tmp (and path leading up) exists path = [] for comp in self.opts.home: path.append(comp) res = sess.compound(use_obj(path)) checklist(res, [NFS4_OK, NFS4ERR_NOENT], "LOOKUP /%s," % '/'.join(path)) if res.status == NFS4ERR_NOENT: res = create_obj(sess, path, NF4DIR) check(res, msg="Trying to create /%s," % '/'.join(path)) # ensure /tree exists and is empty tree = self.opts.path + ['tree'] res = sess.compound(use_obj(tree)) checklist(res, [NFS4_OK, NFS4ERR_NOENT]) if res.status == NFS4ERR_NOENT: res = create_obj(sess, tree, NF4DIR) check(res, msg="Trying to create /%s," % '/'.join(tree)) else: clean_dir(sess, tree) # make non-file objects in /tree d = {'dir': NF4DIR, 'socket': NF4SOCK, 'fifo': NF4FIFO, 'link': createtype4(NF4LNK, linkdata=self.linkdata), 'block': createtype4(NF4BLK, devdata=specdata4(1, 2)), 'char': createtype4(NF4CHR, devdata=specdata4(1, 2)), } for name, kind in d.items(): path = tree + [name] res = create_obj(sess, path, kind) if res.status != NFS4_OK: log.warning("could not create /%s" % '/'.join(path)) # Make file-object in /tree fh, stateid = create_confirm(sess, 'maketree', tree + ['file']) ops = [op.putfh(fh), op.write(stateid, 0, FILE_SYNC4, self.filedata)] res = sess.compound(ops) check(res, msg="Writing data to /%s/file" % '/'.join(tree)) res = close_file(sess, fh, stateid) check(res)
def xtestClientStateSeqid(t, env): """Verify server enforce that client stateid.seqid==0 See 8.1.3.1(draft-10): The client must...set the sequence value to zero. FLAGS: open all CODE: OPEN3 """ name = env.testname(t) sess1 = env.c1.new_client_session(name) owner = "owner_%s" % name path = sess1.c.homedir + [name] res = create_file(sess1, owner, path, access=OPEN4_SHARE_ACCESS_WRITE) check(res) expect(res, seqid=1) # Now use returned stateid (w/o zeroing seqid) fh = res.resarray[-1].object stateid = res.resarray[-2].stateid res = sess1.compound([op.putfh(fh), op.write(stateid, 5, FILE_SYNC4, "write test data")]) check(res, NFS4ERR_BAD_STATEID, "Using an open_stateid w/o zeroing the seqid")
def testLockWriteLocku(t, env): """test current state id processing by having LOCK, WRITE and LOCKU in a single compound FLAGS: currentstateid all CODE: CSID4 """ sess1 = env.c1.new_client_session(env.testname(t)) res = create_file(sess1, env.testname(t)) check(res) fh = res.resarray[-1].object stateid = res.resarray[-2].stateid data = "write test data" open_to_lock_owner = open_to_lock_owner4( 0, stateid, 0, lock_owner4(0, "lock1")) lock_owner = locker4(open_owner=open_to_lock_owner, new_lock_owner=True) lock_ops = [ op.lock(WRITE_LT, False, 0, NFS4_UINT64_MAX, lock_owner), op.write(current_stateid, 5, FILE_SYNC4, data), op.locku(WRITE_LT, 0, current_stateid, 0, NFS4_UINT64_MAX), op.close(0, stateid)] res = sess1.compound([op.putfh(fh)] + lock_ops) check(res, NFS4_OK)
def testOPENClaimFH(t, env): """OPEN file with claim_type is CLAIM_FH FLAGS: open all CODE: OPEN7 """ sess1 = env.c1.new_client_session(env.testname(t)) res = create_file(sess1, env.testname(t)) check(res) fh = res.resarray[-1].object stateid = res.resarray[-2].stateid res = close_file(sess1, fh, stateid=stateid) check(res) claim = open_claim4(CLAIM_FH) how = openflag4(OPEN4_NOCREATE) oowner = open_owner4(0, "My Open Owner 2") open_op = op.open(0, OPEN4_SHARE_ACCESS_BOTH, OPEN4_SHARE_DENY_NONE, oowner, how, claim) res = sess1.compound([op.putfh(fh), open_op]) check(res) stateid = res.resarray[-1].stateid stateid.seqid = 0 data = "write test data" res = sess1.compound( [op.putfh(fh), op.write(stateid, 5, FILE_SYNC4, data)]) check(res) res = sess1.compound([op.putfh(fh), op.read(stateid, 0, 1000)]) check(res) if not res.resarray[-1].eof: fail("EOF not set on read") desired = "\0" * 5 + data if res.resarray[-1].data != desired: fail("Expected %r, got %r" % (desired, res.resarray[-1].data))
def testReadWrite(t, env): """Do a simple READ and WRITE FLAGS: open all CODE: OPEN30 """ sess1 = env.c1.new_client_session(env.testname(t)) owner = open_owner4(0, "My Open Owner") res = create_file(sess1, env.testname(t)) check(res) expect(res, seqid=1) fh = res.resarray[-1].object stateid = res.resarray[-2].stateid stateid.seqid = 0 data = "write test data" res = sess1.compound([op.putfh(fh), op.write(stateid, 5, FILE_SYNC4, data)]) check(res) res = sess1.compound([op.putfh(fh), op.read(stateid, 0, 1000)]) check(res) if not res.resarray[-1].eof: fail("EOF not set on read") desired = "\0"*5 + data if res.resarray[-1].data != desired: fail("Expected %r, got %r" % (desired, res.resarray[-1].data))
def ops(i): return [op.putfh(fh), op.write(stateid, i*1000, UNSTABLE4, chr(97+i)*100), op.getattr(42950721818L) ]