Skip to content

Commit f46f718

Browse files
authored
Worker/Rsh: return maxrc properly for Rsh Worker (#448)
The current version of the Rsh Worker does not properly return the max error code with the -S option. This commit adds in a little "magic" to the end of the rsh command to pass back the return code.
1 parent 3ec8632 commit f46f718

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

lib/ClusterShell/Worker/Rsh.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import os
2828
import shlex
29+
import re
2930

3031
from ClusterShell.Worker.Exec import ExecClient, CopyClient, ExecWorker
3132

@@ -35,6 +36,12 @@ class RshClient(ExecClient):
3536
Rsh EngineClient.
3637
"""
3738

39+
def __init__(self, node, command, worker, stderr, timeout, autoclose=False,
40+
rank=None):
41+
ExecClient.__init__(self, node, command, worker, stderr, timeout,
42+
autoclose, rank)
43+
self.rsh_rc = None
44+
3845
def _build_cmd(self):
3946
"""
4047
Build the shell command line to start the rsh commmand.
@@ -59,8 +66,26 @@ def _build_cmd(self):
5966
cmd_l.append("%s" % self.key) # key is the node
6067
cmd_l.append("%s" % self.command)
6168

69+
# rsh does not properly return exit status
70+
# force the exit status to be printed out
71+
cmd_l.append("; echo XXRETCODE: $?")
72+
6273
return (cmd_l, None)
6374

75+
def _on_nodeset_msgline(self, nodes, msg, sname):
76+
"""Override _on_nodeset_msgline to parse magic return code"""
77+
match = re.search("^XXRETCODE: (\d+)$", msg.decode())
78+
if match:
79+
self.rsh_rc = int(match.group(1))
80+
else:
81+
ExecClient._on_nodeset_msgline(self, nodes, msg, sname)
82+
83+
def _on_nodeset_close(self, nodes, rc):
84+
"""Override _on_nodeset_close to return rsh_rc"""
85+
if (rc == 0 or rc == 1) and self.rsh_rc is not None:
86+
rc = self.rsh_rc
87+
ExecClient._on_nodeset_close(self, nodes, rc)
88+
6489

6590
class RcpClient(CopyClient):
6691
"""

0 commit comments

Comments
 (0)