How to use unlock_file method in autotest

Best Python code snippet using autotest_python

st_locku.py

Source:st_locku.py Github

copy

Full Screen

...13 res1 = c.lock_file(t.word(), fh, stateid)14 check(res1, msg="Locking file %s" % t.word())15 res2 = c.lock_test(fh)16 check(res2, NFS4ERR_DENIED, "Testing file %s is locked" % t.word())17 res3 = c.unlock_file(1, fh, res1.lockid)18 check(res3, msg="Unlocking locked file %s" % t.word())19 res2 = c.lock_test(fh)20 check(res2, msg="Testing file %s was unlocked" % t.word())21def testUnlocked(t, env):22 """LOCKU on an unlocked area should work or return NFS4ERR_LOCK_RANGE23 FLAGS: locku all24 DEPEND: MKFILE25 CODE: LKUNONE26 """27 c = env.c128 c.init_connection()29 fh, stateid = c.create_confirm(t.word())30 res1 = c.lock_file(t.word(), fh, stateid, 100, 100)31 check(res1, msg="Locking file %s" % t.word())32 res2 = c.unlock_file(1, fh, res1.lockid, 0, 50)33 check(res2, [NFS4_OK, NFS4ERR_LOCK_RANGE], "LOCKU on an unlocked area")34 if res2.status == NFS4ERR_LOCK_RANGE:35 t.fail_support("LOCKU on an unlocked area should return OK")36def testSplit(t, env):37 """LOCKU inside a locked range should work or return NFS4ERR_LOCK_RANGE38 FLAGS: locku all39 DEPEND: MKFILE40 CODE: LKUSPLIT41 """42 c = env.c143 c.init_connection()44 fh, stateid = c.create_confirm(t.word())45 res1 = c.lock_file(t.word(), fh, stateid, 100, 100)46 check(res1, msg="Locking file %s" % t.word())47 res2 = c.unlock_file(1, fh, res1.lockid, 125, 50)48 check(res2, [NFS4_OK, NFS4ERR_LOCK_RANGE], "LOCKU inside locked area")49 if res2.status == NFS4ERR_LOCK_RANGE:50 t.fail_support("LOCKU inside a locked area should return OK")51def testOverlap(t, env):52 """LOCKU on an overlapping range should work or return NFS4ERR_LOCK_RANGE53 FLAGS: locku all54 DEPEND: MKFILE LKUNONE LKUSPLIT55 CODE: LKUOVER56 """57 c = env.c158 c.init_connection()59 fh, stateid = c.create_confirm(t.word())60 res1 = c.lock_file(t.word(), fh, stateid, 100, 100)61 check(res1, msg="Locking file %s" % t.word())62 res2 = c.unlock_file(1, fh, res1.lockid, 50, 100)63 check(res2, [NFS4_OK, NFS4ERR_LOCK_RANGE],64 "LOCKU overlapping a locked area")65 if res2.status == NFS4ERR_LOCK_RANGE:66 t.fail("LOCKU overlapping a locked area should return OK, "67 "given server allows other non-matching LOCKUs")68def test32bitRange(t, env):69 """LOCKU ranges over 32 bits should work or return NFS4ERR_BAD_RANGE70 FLAGS: lock locku all71 DEPEND: MKFILE LOCKRNG LKUSPLIT72 CODE: LKU273 """74 c = env.c175 c.init_connection()76 fh, stateid = c.create_confirm(t.word())77 res1 = c.lock_file(t.word(), fh, stateid)78 check(res1)79 res2 = c.unlock_file(1, fh, res1.lockid, 0, 0xffffffffffff)80 check(res2, [NFS4_OK, NFS4ERR_BAD_RANGE, NFS4ERR_LOCK_RANGE],81 "LOCKU range over 32 bits")82 if res2.status == NFS4ERR_BAD_RANGE:83 t.fail("Allowed 64 bit LOCK range, but only 32 bit LOCKU range")84 if res2.status == NFS4ERR_LOCK_RANGE:85 t.fail("Allowed 32bit splitting of locks, but not 64bit")86def testZeroLen(t, env):87 """LOCKU with len=0 should return NFS4ERR_INVAL88 FLAGS: locku all89 DEPEND: MKFILE90 CODE: LKU391 """92 c = env.c193 c.init_connection()94 fh, stateid = c.create_confirm(t.word())95 res1 = c.lock_file(t.word(), fh, stateid)96 check(res1)97 res2 = c.unlock_file(1, fh, res1.lockid, 1, 0)98 check(res2, NFS4ERR_INVAL, "LOCKU with len=0")99 100def testLenTooLong(t, env):101 """LOCKU with offset+len overflow should return NFS4ERR_INVAL102 FLAGS: locku emptyfh all103 DEPEND: MKFILE104 CODE: LKU4105 """106 c = env.c1107 c.init_connection()108 fh, stateid = c.create_confirm(t.word())109 res1 = c.lock_file(t.word(), fh, stateid)110 check(res1)111 res2 = c.unlock_file(1, fh, res1.lockid, 100, 0xfffffffffffffffe)112 check(res2, NFS4ERR_INVAL, "LOCKU with offset+len overflow")113def testNoFh(t, env):114 """LOCKU with no (cfh) should return NFS4ERR_NOFILEHANDLE115 FLAGS: locku all116 DEPEND: MKFILE117 CODE: LKU5118 """119 c = env.c1120 c.init_connection()121 fh, stateid = c.create_confirm(t.word())122 res1 = c.lock_file(t.word(), fh, stateid)123 check(res1)124 res2 = c.unlock_file(1, None, res1.lockid)125 check(res2, NFS4ERR_NOFILEHANDLE, "LOCKU with no <cfh>")126def testBadLockSeqid(t, env):127 """LOCKU with a bad lockseqid should return NFS4ERR_BAD_SEQID128 FLAGS: locku seqid all129 DEPEND: MKFILE130 CODE: LKU6131 """132 c = env.c1133 c.init_connection()134 fh, stateid = c.create_confirm(t.word())135 res1 = c.lock_file(t.word(), fh, stateid)136 check(res1)137 res2 = c.unlock_file(2, fh, res1.lockid)138 check(res2, NFS4ERR_BAD_SEQID, "LOCKU with a bad lockseqid=2")139def testBadLockSeqid2(t, env):140 """LOCKU with a bad lockseqid should return NFS4ERR_BAD_SEQID141 FLAGS: locku seqid all142 DEPEND: MKFILE143 CODE: LKU6b144 """145 c = env.c1146 c.init_connection()147 fh, stateid = c.create_confirm(t.word())148 res1 = c.lock_file(t.word(), fh, stateid, 0, 50)149 check(res1)150 res2 = c.relock_file(1, fh, res1.lockid, 100, 50)151 check(res2)152 res3 = c.unlock_file(0, fh, res2.lockid)153 check(res3, NFS4ERR_BAD_SEQID, "LOCKU with a bad lockseqid=1")154# See 8.1.5, as well as def of BAD_SEQID in sec 12155# Turns out should expect replay of LOCK command.156# But nfs4lib will raise an error, and not allow checking of response157# FRED - fix this158def testBadLockSeqid3(t, env):159 """LOCKU with a bad lockseqid should return NFS4ERR_BAD_SEQID160# FLAGS: locku seqid all161 FLAGS: ganesha162 DEPEND: MKFILE163 CODE: LKU6c164 """165 c = env.c1166 c.init_connection()167 fh, stateid = c.create_confirm(t.word())168 res1 = c.lock_file(t.word(), fh, stateid, 0, 50)169 check(res1)170 res2 = c.relock_file(1, fh, res1.lockid, 100, 50)171 check(res2)172 res3 = c.unlock_file(1, fh, res2.lockid)173 check(res3, NFS4ERR_BAD_SEQID, "LOCKU with a bad lockseqid=1")174def testOldLockStateid(t, env):175 """LOCKU with old lock stateid should return NFS4ERR_OLD_STATEID176 FLAGS: locku oldid all177 DEPEND: MKFILE178 CODE: LKU7179 """180 c = env.c1181 c.init_connection()182 fh, stateid = c.create_confirm(t.word())183 res1 = c.lock_file(t.word(), fh, stateid)184 check(res1)185 res2 = c.unlock_file(1, fh, res1.lockid)186 check(res2)187 # Try to unlock again with old stateid188 res3 = c.unlock_file(2, fh, res1.lockid)189 check(res3, NFS4ERR_OLD_STATEID, "LOCKU with old lockstateid",190 [NFS4ERR_BAD_STATEID])191def testBadLockStateid(t, env):192 """LOCKU should return NFS4ERR_BAD_STATEID if use a bad id193 FLAGS: locku badid all194 DEPEND: MKFILE195 CODE: LKU8196 """197 c = env.c1198 c.init_connection()199 fh, stateid = c.create_confirm(t.word())200 res1 = c.lock_file(t.word(), fh, stateid)201 check(res1)202 res2 = c.unlock_file(1, fh, stateid4(0, b''))203 check(res2, NFS4ERR_BAD_STATEID, "LOCKU with a bad stateid")204 205def testStaleLockStateid(t, env):206 """LOCKU with stale lockstateid should return NFS4ERR_STALE_STATEID207 FLAGS: locku staleid all208 DEPEND: MKFILE209 CODE: LKU9210 """211 c = env.c1212 c.init_connection()213 fh, stateid = c.create_confirm(t.word())214 res1 = c.lock_file(t.word(), fh, stateid)215 check(res1)216 res2 = c.unlock_file(1, fh, makeStaleId(res1.lockid))217 check(res2, NFS4ERR_STALE_STATEID, "LOCKU with stale lockstateid",218 [NFS4ERR_BAD_STATEID, NFS4ERR_OLD_STATEID])219# FRED - what is correct error return?220def testTimedoutUnlock(t, env):221 """LOCKU: Try to unlock file after timed out 222 NFS4ER_EXPIRED return mandated by section 8.6.3 of rfc223 224 FLAGS: locku timed all225 DEPEND: MKFILE226 CODE: LKU10227 """228 c = env.c1229 sleeptime = c.getLeaseTime() * 3 // 2230 c.init_connection()231 fh, stateid = c.create_confirm(t.word(), attrs={FATTR4_MODE: 0o666})232 res1 = c.lock_file(t.word(), fh, stateid)233 check(res1)234 env.sleep(sleeptime)235 # Conflicting open should force server to drop state236 c2 = env.c2237 c2.init_connection()238 c2.open_confirm(t.word(), access=OPEN4_SHARE_ACCESS_WRITE)239 res2 = c.unlock_file(1, fh, res1.lockid)240 check(res2, [NFS4ERR_EXPIRED, NFS4_OK],...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful