Commit 7c2281e5 authored by Gary Wong's avatar Gary Wong

Make (at least some of) the test scripts friendlier for the tutorial.

Merge in Leigh's changes to retry operations on transient errors.
Show a heartbeat when waiting for XMLRPC requests to return.
parent dcaca0b0
......@@ -53,15 +53,20 @@ else:
#
# Get a credential for myself, that allows me to do things at the SA.
#
print "Obtaining SA credential..."
print "Obtaining SA credential...",
sys.stdout.flush()
mycredential = get_self_credential()
print " "
#
# Lookup my ssh keys.
#
params = {}
params["credential"] = mycredential
print "Looking up SSH keys...",
sys.stdout.flush()
rval,response = do_method("sa", "GetKeys", params)
print " "
if rval:
Fatal("Could not get my keys")
pass
......@@ -80,17 +85,22 @@ params = {}
params["credential"] = mycredential
params["type"] = "Slice"
params["hrn"] = SLICENAME
print "Looking up slice...",
sys.stdout.flush()
rval,response = do_method("sa", "Resolve", params)
print " "
if rval:
#
# Create a slice.
#
print "Creating new slice called " + SLICENAME
print "Creating new slice called " + SLICENAME + "...",
sys.stdout.flush()
params = {}
params["credential"] = mycredential
params["type"] = "Slice"
params["hrn"] = SLICENAME
rval,response = do_method("sa", "Register", params)
print " "
if rval:
Fatal("Could not create new slice")
pass
......@@ -101,16 +111,18 @@ else:
#
# Get the slice credential.
#
print "Asking for slice credential for " + SLICENAME + "..."
print "Asking for slice credential for " + SLICENAME + "...",
sys.stdout.flush()
myslice = response["value"]
myslice = get_slice_credential( myslice, mycredential )
print "Got the slice credential."
print " "
pass
#
# Create the sliver.
#
print "Creating the sliver..."
print "Creating the sliver...",
sys.stdout.flush()
params = {}
params["credentials"] = (myslice,)
params["slice_urn"] = SLICEURN
......@@ -118,6 +130,7 @@ params["rspec"] = rspec
params["keys"] = mykeys
params["impotent"] = impotent
rval,response = do_method("cm", "CreateSliver", params, version="2.0")
print " "
if rval:
Fatal("Could not create sliver")
pass
......
......@@ -29,29 +29,37 @@ execfile( "test-common.py" )
#
# Get a credential for myself, that allows me to do things at the SA.
#
print "Obtaining SA credential...",
sys.stdout.flush()
mycredential = get_self_credential()
print "Got my SA credential. Looking for slice ..."
print " "
#
# Lookup slice, delete before proceeding.
#
print "Looking up slice...",
sys.stdout.flush()
myslice = resolve_slice( SLICENAME, mycredential )
print "Found the slice, asking for a credential ..."
print " "
#
# Get the slice credential.
#
print "Obtaining slice credential...",
sys.stdout.flush()
slicecred = get_slice_credential( myslice, mycredential )
print "Got the slice credential"
print " "
#
# Delete the Slice
#
print "Deleting the slice"
print "Deleting the slice...",
sys.stdout.flush()
params = {}
params["credentials"] = (slicecred,)
params["slice_urn"] = SLICEURN
rval,response = do_method("cm", "DeleteSlice", params, version="2.0")
print " "
if rval:
Fatal("Could not delete slice")
pass
......
......@@ -36,8 +36,10 @@ if len(REQARGS) == 1:
#
# Get a credential for myself, that allows me to do things at the SA.
#
print "Obtaining SA credential...",
sys.stdout.flush()
mycredential = get_self_credential()
print "Got my SA credential"
print " "
#
# Lookup slice, delete before proceeding.
......@@ -46,7 +48,10 @@ params = {}
params["credential"] = mycredential
params["type"] = "Slice"
params["hrn"] = SLICENAME
print "Looking for existing slice...",
sys.stdout.flush()
rval,response = do_method("sa", "Resolve", params)
print " "
if rval == 0:
print "Deleting previously registered slice";
params = {}
......@@ -62,12 +67,14 @@ if rval == 0:
#
# Create a slice.
#
print "Creating new slice called " + SLICENAME
print "Creating new slice called " + SLICENAME + "...",
sys.stdout.flush()
params = {}
params["credential"] = mycredential
params["type"] = "Slice"
params["hrn"] = SLICENAME
rval,response = do_method("sa", "Register", params)
print " "
if rval:
Fatal("Could not get my slice")
print str(rval)
......
......@@ -46,18 +46,22 @@ if len( args ) != 1:
#
# Get a credential for myself, that allows me to do things at the SA.
#
print "Obtaining SA credential..."
print "Obtaining SA credential...",
sys.stdout.flush()
mycredential = get_self_credential()
print " "
#
# Lookup the user.
#
print "Looking up user..."
print "Looking up user...",
sys.stdout.flush()
params = {}
params["hrn"] = args[ 0 ]
params["credential"] = mycredential
params["type"] = "User"
rval,response = do_method("sa", "Resolve", params)
print " "
if rval:
Fatal("Could not resolve " + params[ "hrn" ] )
......
......@@ -18,6 +18,8 @@ import xmlrpclib
import M2Crypto
from M2Crypto import X509
import socket
import time;
import threading;
# Debugging output.
debug = 0
......@@ -175,6 +177,15 @@ def geni_am_response_handler(method, method_args):
"""
return apply(method, method_args)
def dotty():
counter = 0
while threading.currentThread().keep_going:
# #@(%ing stupid Python #@(%s up the whitespace if you try "print"
sys.stderr.write( ( "/-\\|"[ counter ] ) + "\010" )
counter = ( counter + 1 ) & 3
sys.stderr.flush()
time.sleep( 0.125 )
#
# Call the rpc server.
#
......@@ -246,26 +257,46 @@ def do_method(module, method, params, URI=None, quiet=False, version=None,
# This is the case when running the GENI AM.
return response_handler(meth, params)
if not quiet:
t = threading.Thread( None, dotty )
t.daemon = True
t.keep_going = True
t.start()
#
# Make the call.
#
try:
response = apply(meth, meth_args)
pass
except xmlrpclib.Fault, e:
if not quiet: print >> sys.stderr, e.faultString
return (-1, None)
except xmlrpclib.ProtocolError, e:
if not quiet: print >> sys.stderr, e.errmsg
return (-1, None)
except M2Crypto.SSL.Checker.WrongHost, e:
if not quiet:
print >> sys.stderr, "Warning: certificate host name mismatch."
print >> sys.stderr, "Please consult:"
print >> sys.stderr, " http://www.protogeni.net/trac/protogeni/wiki/HostNameMismatch"
print >> sys.stderr, "for recommended solutions."
print >> sys.stderr, e
return (-1, None)
while True:
try:
response = apply(meth, meth_args)
break
except xmlrpclib.Fault, e:
if not quiet:
t.keep_going = False
print >> sys.stderr, e.faultString
if e.faultCode == 511:
print >> sys.stderr, "Will try again in a moment. Be patient!"
time.sleep(5.0)
continue
pass
return (-1, None)
except xmlrpclib.ProtocolError, e:
if not quiet:
t.keep_going = False
print >> sys.stderr, e.errmsg
t.keep_going = False
return (-1, None)
except M2Crypto.SSL.Checker.WrongHost, e:
if not quiet:
t.keep_going = False
print >> sys.stderr, "Warning: certificate host name mismatch."
print >> sys.stderr, "Please consult:"
print >> sys.stderr, " http://www.protogeni.net/trac/protogeni/wiki/HostNameMismatch"
print >> sys.stderr, "for recommended solutions."
print >> sys.stderr, e
pass
return (-1, None)
if not quiet: t.keep_going = False
#
# Parse the Response, which is a Dictionary. See EmulabResponse in the
......@@ -310,12 +341,28 @@ def resolve_slice( name, selfcredential ):
params["urn"] = name
else:
params["hrn"] = name
rval,response = do_method("sa", "Resolve", params)
if rval:
Fatal("Slice does not exist");
pass
else:
return response["value"]
count = 2
while True:
rval,response = do_method("sa", "Resolve", params)
if rval:
if rval == 14:
if count:
print " Will try again in a few seconds"
count = count - 1;
time.sleep(5.0)
else:
Fatal("Giving up, busy for too long");
pass
else:
Fatal("Slice does not exist");
pass
pass
else:
break
pass
return response["value"]
def get_slice_credential( slice, selfcredential ):
if slicecredentialfile:
......@@ -331,8 +378,25 @@ def get_slice_credential( slice, selfcredential ):
params["urn"] = slice["urn"]
else:
params["uuid"] = slice["uuid"]
rval,response = do_method("sa", "GetCredential", params)
if rval:
Fatal("Could not get Slice credential")
pass
count = 2
while True:
rval,response = do_method("sa", "GetCredential", params)
if rval:
if rval == 14:
if count:
print " Will try again in a few seconds"
count = count - 1;
time.sleep(5.0)
else:
Fatal("Giving up, busy for too long");
pass
else:
Fatal("Could not get Slice credential")
pass
pass
else:
break
pass
return response["value"]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment