Skip to contentSkip to conversation

st_opendowngrade.py: add open upgrade with deny mode tests

PATCH New Dai Ngo 1 participant 1 message Feb 16, 2023

Subsystems (2)
lore
Share & tools
lore

Dai Ngo

author reviewer
#0 lore raw

PATCH 1/1 st_opendowngrade.py: add open upgrade with deny mode tests

Add 2 tests, OPDG12 and OPDG13, to test deny mode code paths in nfs4_upgrade_open.

OPDG12: test open upgrade that has deny mode conflict with an active client.

OPDG12: test open upgrade that has deny mode conflict with a courtesy client.

---
 nfs4.0/servertests/st_opendowngrade.py | 62 ++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)
nfs4.0/servertests/st_opendowngrade.py +62 -0
index 59e975000724..de7e4d3db2b0 100644
@@ -180,3 +180,65 @@ def testOpenDowngradeLock(t, env):
     os.open(OPEN4_SHARE_ACCESS_READ)
     os.downgrade(OPEN4_SHARE_ACCESS_READ)
     os.close()
+
+def testOpenUpgradeconflict(t, env):
+    """test open upgrade that conflicts with another active client
+
+    FLAGS: opendowngrade all
+    DEPEND: MKFILE
+    CODE:OPDG12
+    """
+    c = env.c1
+    c.init_connection()
+    os = open_sequence(c, t.word())
+    os.open(OPEN4_SHARE_ACCESS_WRITE)
+
+    c2 = env.c2
+    c2.init_connection()
+    res = c2.open_file(t.word(), access=OPEN4_SHARE_ACCESS_READ,
+                       deny=OPEN4_SHARE_DENY_NONE)
+    check(res)
+    fh, stateid = c2.confirm(t.word(), res)
+    res = c2.open_file(t.word(), access=OPEN4_SHARE_ACCESS_READ,
+                       deny=OPEN4_SHARE_DENY_WRITE)
+    check(res, NFS4ERR_SHARE_DENIED)
+
+    res = c2.close_file(t.word(), fh, stateid)
+    check(res)
+    os.close()
+
+def testOpenUpgradeCourtesy(t, env):
+    """test open upgrade that conflicts with courtesy client
+
+    FLAGS: opendowngrade all
+    DEPEND: MKFILE
+    CODE:OPDG13
+    """
+    c = env.c1
+    c.init_connection()
+    os = open_sequence(c, t.word())
+    os.open(OPEN4_SHARE_ACCESS_WRITE)
+    leasetime = c.getLeaseTime()
+    env.sleep(leasetime/2, "sleep 1/2 grace period")
+
+    c2 = env.c2
+    c2.init_connection()
+    owner = t.word()
+    res = c2.open_file(owner, access=OPEN4_SHARE_ACCESS_READ,
+                       deny=OPEN4_SHARE_DENY_NONE)
+    check(res)
+    fh, stateid = c2.confirm(owner, res)
+
+    env.sleep((leasetime/2) + 5, "wait for c1's lease to expire")
+    while 1:
+        res = c2.open_file(owner, access=OPEN4_SHARE_ACCESS_READ,
+                       deny=OPEN4_SHARE_DENY_WRITE)
+        if res.status == NFS4_OK: break
+        check(res, [NFS4_OK, NFS4ERR_DELAY],
+                   "Open which causes conflict with courtesy client")
+        env.sleep(2, 'Got NFS4ERR_DELAY on open')
+
+    fh = res.resarray[-1].switch.switch.object
+    stateid = res.resarray[-2].switch.switch.stateid
+    res = c2.close_file(owner, fh, stateid)
+    check(res)
Signature · 1 line
2.27.0