#! /usr/bin/env python
#
# Example client.
#
# Usage:
# ./client.py [--debug|-d] (--host=hostname) [--user=username] --cmd="server to execute"
#
# e.g.
# ./client --host=examplehost.org --user=fred --cmd=serv.py
#
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 + "/serv.py")
#default=cwd + "/serv.py 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')
logger.info("Log open")
# establish SimpleXMLRPXServer over SSH2 tunnel
client = Client(host=options.host, port='ssh',
cmd=options.cmd,
user=options.user,
debug=options.debug,
PromptPwd=options.PromptPwd)
# 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 ./serv.py
#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"
else:
print "Test1: FAILED res =",res
OK = False
res = client.server.Test2("parm1", "parm2")
if res == "parm1parm2OK":
print "Test2: OK"
else:
print "Test2: FAILED res =", res
OK = False
res = client.server.Test3( ("parm1", "parm2") )
if res == "parm1parm2OK":
print "Test3: OK"
else:
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"
else:
print "Test4: FAILED res =", res
OK = False
if OK == True:
print "\nAll tests OK"
else:
print "\nOne or more tests failed!"
if not OK:
sys.exit(1)
client.close()
There are no comments on this page. [Add comment]