[PATCH] pynfs: add courteous server tests

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add a first test that simply locks, sleeps for twice the lease period,
then unlocks.

Signed-off-by: Calum Mackay <calum.mackay@xxxxxxxxxx>
---

I plan to add some more tests shortly, but will send what I have now,
in case it's useful for the upcoming BAT. This first test has been tried
against Solaris & Linux (discourteous) servers.

 nfs4.1/server41tests/__init__.py    |  1 +
 nfs4.1/server41tests/st_courtesy.py | 47 +++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+)
 create mode 100644 nfs4.1/server41tests/st_courtesy.py

diff --git a/nfs4.1/server41tests/__init__.py b/nfs4.1/server41tests/__init__.py
index a4d7ee65fb5e..ebb4e8847151 100644
--- a/nfs4.1/server41tests/__init__.py
+++ b/nfs4.1/server41tests/__init__.py
@@ -25,4 +25,5 @@ __all__ = ["st_exchange_id.py", # draft 21
            "st_sparse.py",
            "st_flex.py",
            "st_xattr.py",
+           "st_courtesy.py",
            ]
diff --git a/nfs4.1/server41tests/st_courtesy.py b/nfs4.1/server41tests/st_courtesy.py
new file mode 100644
index 000000000000..5e13dad44a01
--- /dev/null
+++ b/nfs4.1/server41tests/st_courtesy.py
@@ -0,0 +1,47 @@
+from .st_create_session import create_session
+from xdrdef.nfs4_const import *
+
+from .environment import check, fail, create_file, open_file, close_file
+from .environment import open_create_file_op, use_obj
+from xdrdef.nfs4_type import open_owner4, openflag4, createhow4, open_claim4
+from xdrdef.nfs4_type import creatverfattr, fattr4, stateid4, locker4, lock_owner4
+from xdrdef.nfs4_type import open_to_lock_owner4
+import nfs_ops
+op = nfs_ops.NFS4ops()
+import threading
+
+
+def _getleasetime(sess):
+    res = sess.compound([op.putrootfh(), op.getattr(1 << FATTR4_LEASE_TIME)])
+    return res.resarray[-1].obj_attributes[FATTR4_LEASE_TIME]
+
+def testLockSleepLockU(t, env):
+    """test server courtesy by having LOCK and LOCKU
+       in separate compounds, separated by a sleep of twice the lease period
+
+    FLAGS: courteous
+    CODE: COUR1
+    """
+    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
+    open_to_lock_owner = open_to_lock_owner4( 0, stateid, 0, lock_owner4(0, b"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) ]
+    res = sess1.compound([op.putfh(fh)] + lock_ops)
+    check(res, NFS4_OK)
+
+    lease_time = _getleasetime(sess1)
+    env.sleep(lease_time * 2, "twice the lease period")
+
+    lock_stateid = res.resarray[-1].lock_stateid
+    lock_ops = [ op.locku(WRITE_LT, 0, lock_stateid, 0, NFS4_UINT64_MAX) ]
+    res = sess1.compound([op.putfh(fh)] + lock_ops)
+    check(res, NFS4_OK, warnlist = [NFS4ERR_BADSESSION])
+
+    res = close_file(sess1, fh, stateid=stateid)
+    check(res)
-- 
2.18.4




[Index of Archives]     [Linux Filesystem Development]     [Linux USB Development]     [Linux Media Development]     [Video for Linux]     [Linux NILFS]     [Linux Audio Users]     [Yosemite Info]     [Linux SCSI]

  Powered by Linux