2021-08-06 07:33:29

by [email protected]

[permalink] [raw]
Subject: [PATCH 1/2] nfstest: python3: fix rexec error while calling self.process.stdin.write

While running nfstest_delegation of nfstest in v3.0:

$ ./nfstest_delegation --nfsversion=4.2 -e /nfsroot \
--server 192.168.220.184 --client 192.168.220.107
Traceback (most recent call last):
File "./nfstest_delegation", line 1666, in <module>
x = DelegTest(usage=USAGE, testnames=TESTNAMES, testgroups=TESTGROUPS, sid=SCRIPT_ID)
File "./nfstest_delegation", line 363, in __init__
self.create_rexec(client_name)
File "/root/nfstest/nfstest/test_util.py", line 1370, in create_rexec
self.rexecobj = Rexec(servername, **kwds)
File "/root/nfstest/nfstest/rexec.py", line 295, in __init__
self.process.stdin.write(server_code)
TypeError: a bytes-like object is required, not 'str'

In python3, self.process.stdin.write() only accepts a bytes-like
object not 'str'.
Fix it by calling server_code.encode() and self.process.stdin.flush().

Signed-off-by: Su Yue <[email protected]>
---
nfstest/rexec.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/nfstest/rexec.py b/nfstest/rexec.py
index fa941b6..51586c5 100644
--- a/nfstest/rexec.py
+++ b/nfstest/rexec.py
@@ -292,7 +292,8 @@ class Rexec(BaseObj):
self.process = Popen(" ".join(cmdlist), shell=True, stdin=PIPE)

# Send the server code to be executed via standard input
- self.process.stdin.write(server_code)
+ self.process.stdin.write(server_code.encode())
+ self.process.stdin.flush()

# Connect to remote server
etime = time.time() + 5.0
--
2.30.1 (Apple Git-130)


2021-08-06 07:34:20

by [email protected]

[permalink] [raw]
Subject: 回复: [PATCH 1/2] nfstest: python3: fix rexe c error while calling self.process.stdin.write

And CC Jorge Mora. I can not found other mailing list about nfstest so I guess it's linux-nfs.
Sorry if those patches bother you nfs folks.

--
Su

________________________________________
??????: Su, Yue/?? Խ
????ʱ??: 2021??8??6?? 10:47
?ռ???: [email protected]
????: [PATCH 1/2] nfstest: python3: fix rexec error while calling self.process.stdin.write

While running nfstest_delegation of nfstest in v3.0:

$ ./nfstest_delegation --nfsversion=4.2 -e /nfsroot \
--server 192.168.220.184 --client 192.168.220.107
Traceback (most recent call last):
File "./nfstest_delegation", line 1666, in <module>
x = DelegTest(usage=USAGE, testnames=TESTNAMES, testgroups=TESTGROUPS, sid=SCRIPT_ID)
File "./nfstest_delegation", line 363, in __init__
self.create_rexec(client_name)
File "/root/nfstest/nfstest/test_util.py", line 1370, in create_rexec
self.rexecobj = Rexec(servername, **kwds)
File "/root/nfstest/nfstest/rexec.py", line 295, in __init__
self.process.stdin.write(server_code)
TypeError: a bytes-like object is required, not 'str'

In python3, self.process.stdin.write() only accepts a bytes-like
object not 'str'.
Fix it by calling server_code.encode() and self.process.stdin.flush().

Signed-off-by: Su Yue <[email protected]>
---
nfstest/rexec.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/nfstest/rexec.py b/nfstest/rexec.py
index fa941b6..51586c5 100644
--- a/nfstest/rexec.py
+++ b/nfstest/rexec.py
@@ -292,7 +292,8 @@ class Rexec(BaseObj):
self.process = Popen(" ".join(cmdlist), shell=True, stdin=PIPE)

# Send the server code to be executed via standard input
- self.process.stdin.write(server_code)
+ self.process.stdin.write(server_code.encode())
+ self.process.stdin.flush()

# Connect to remote server
etime = time.time() + 5.0
--
2.30.1 (Apple Git-130)