pyXMLRPCssh : ExampleClient

HomePage :: Categories :: PageIndex :: RecentChanges :: RecentlyCommented :: Login/Register
#! /usr/bin/env python
# Example client.
# Usage:
#       ./ [--debug|-d] (--host=hostname) [--user=username] --cmd="server to execute"
# e.g.
#       ./client --user=fred

import sys, os
from pyXMLRPCssh import Client
from optparse import OptionParser
import paramiko

cwd = os.getcwd()

parser = OptionParser()
parser.add_option("", "--host", dest="host",
                  help="Target host", default="localhost")
parser.add_option("", "--cmd", dest="cmd",
                  help="Target server to start",
                  default=cwd + "/")
                  #default=cwd + "/ 2>" + cwd + "/log.err")
parser.add_option("", "--user", dest="user",
                  help="User name to connect with", default=None)
parser.add_option("", "--repeat", dest="repeat",
                  help="Repeat tests n times", default=10)
parser.add_option("", "--promptpwd", action="store_true", dest="PromptPwd",
                  help="Permit prompt for password, if needed", default=False)
parser.add_option("-d", "--debug", action="store_true", dest="debug",
                  help="enabled debugging", default=False)
(options, args) = parser.parse_args()

if options.debug:
    # setup logging
    paramiko.util.log_to_file('/tmp/pyXMLRPCssh_test.log', level=paramiko.common.DEBUG)
    logger = paramiko.util.get_logger('paramiko')"Log open")

# establish SimpleXMLRPXServer over SSH2 tunnel
client = Client(, port='ssh',

# call server methods
#print "\nAvailable methods"
#print   "~~~~~~~~~~~~~~~~~\n"
#for method in client.server.system.listMethods():
#    print "Method",method +":"
#    print client.server.system.methodHelp(method)
#    print
#print "\n"
## server methods defined in ./
#print client.server.HelloWorld()
#print client.server.PrintParm("parm1", "parm2")

print "\nStarting formal tests"
print   "~~~~~~~~~~~~~~~~~~~~~\n"

OK = True

for count in range(int(options.repeat)):
    print "test iteration",(count+1)
    res = client.server.Test1("MyParm")
    if res == "MyParmOK":
        print "Test1: OK"
        print "Test1: FAILED res =",res
        OK = False

    res = client.server.Test2("parm1", "parm2")
    if res == "parm1parm2OK":
        print "Test2: OK"
        print "Test2: FAILED res =", res
        OK = False

    res = client.server.Test3( ("parm1", "parm2") )
    if res == "parm1parm2OK":
        print "Test3: OK"
        print "Test3: FAILED res =", res
        OK = False

    res = client.server.Test4( ("parm1", "parm2") )
    if res[0] == "parm2" and res[1] == "parm1" and res[2] == "OK":
        print "Test4: OK"
        print "Test4: FAILED res =", res
        OK = False

if OK == True:
    print "\nAll tests OK"
    print "\nOne or more tests failed!"

if not OK:


There are no comments on this page. [Add comment]

Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by WikkaWiki
Get pyXMLRPCssh at Fast, secure and Free Open Source software downloads
Page was generated in 0.2814 seconds