nfstest.rexec - Man Page

Remote procedure module


Provides a set of tools for executing a wide range commands, statements, expressions or functions on a remote host by running a server process on the remote host serving requests without disconnecting. This allows for a sequence of operations to be done remotely and not losing state. A file could be opened remotely, do some other things and then write to the same opened file without opening the file again.

The remote server can be executed as a different user by using the sudo option and sending seteuid. The server can be executed locally as well using fork when running as the same user or using the shell when the sudo option is used.

In order to use this module the user id must be able to 'ssh' to the remote host without the need for a password.


class RemoteServer

Methods defined here:


__init__(self, port, logfile=None)
Remote procedure server

log(self, msg)
Write message to log file


class Rexec(baseobj.BaseObj)

Rexec object

       Rexec() -> New remote procedure object

               Name or IP address of remote server
               Name of logfile to create on remote server
               Run remote server as root

           from nfstest.rexec import Rexec

           # Function to be defined at remote host
           def add_one(n):
               return n + 1

           # Function to be defined at remote host
           def get_time(delay=0):
               return time.time()

           # Create remote procedure object
           x = Rexec("")

           # Define function at remote host

           # Evaluate the expression calling add_one()
           out = x.reval("add_one(67)")

           # Run the function with the given argument
           out ="add_one", 7)

           # Run built-in functions
           import time
           out =

           # Import libraries and symbols
           x.rimport("time", ["sleep"])
 "sleep", 2)

           # Define function at remote host -- since function uses the
           # time module, this module must be first imported

           # Evaluate the expression calling get_time()
           out = x.reval("get_time()")

           # Run the function with the given argument
           out ="get_time", 10)

           # Open file on remote host
           fd =, "/tmp/testfile", os.O_WRONLY|os.O_CREAT|os.O_TRUNC)
           count =, fd, "hello there
 , fd)

           # Use of positional arguments
           out ="get_time", 2)

           # Use of named arguments
           out ="get_time", delay=2)

           # Use of NOWAIT option for long running functions so other things
           # can be done while waiting
 "get_time", 2, NOWAIT=True)
           while True:
               # Poll every 0.1 secs to see if function has finished
               if x.poll(0.1):
                   # Get results
                   out = x.results()

           # Create remote procedure object as a different user
           # First, run the remote server as root
           x = Rexec("", sudo=True)
           # Then set the effective user id
 , 1000)

Methods defined here:


__init__(self, servername=None, logfile=None, sudo=False, sync_timeout=0.1)

Initialize object's private data.

    Host name or IP address of host where remote server will run
    [Default: None (run locally)]
    Pathname of log file to be created on remote host
    [Default: None]
    Run remote procedure server as root
    [Default: False]
    Timeout used for synchronizing the connection stream
    [Default: 0.1]

Close connection to remote server

poll(self, timeout=0)
Return whether there is any data available to be read

    Maximum time in seconds to block, if timeout is None then
    an infinite timeout is used

rcode(self, code)
Define function on remote server

Return pending results

reval(self, expr)
Evaluate expression on remote server

rexec(self, expr)
Execute statement on remote server

rimport(self, module, symbols=[])
Import module on remote server

    Module to import in the remote server
    If given, import only these symbols from the module

run(self, *kwts, **kwds)
Run function on remote server

The first positional argument is the function to be executed.
All other positional arguments and any named arguments are treated
as arguments to the function

wait(self, objlist=None, timeout=0)
Return a list of Rexec objects where data is available to be read

    List of Rexec objects to poll, if not given use current object
    Maximum time in seconds to block, if timeout is None then
    an infinite timeout is used

See Also



No known bugs.


Jorge Mora (


14 February 2017 NFStest 2.1.5 rexec 1.2