Commit 36111fe7 authored by Jonathon Duerig's avatar Jonathon Duerig

Add a layer of retries when fetching credentials in test scripts.

parent f7db18d3
......@@ -76,12 +76,9 @@ print "Got my SA credential"
if dokeys:
params = {}
params["credential"] = mycredential
rval,response = do_method("sa", "GetKeys", params)
rval,response = do_method_retry("sa", "GetKeys", params)
if rval:
Fatal("Could not get my keys")
pass
mykeys = response["value"]
if debug: print str(mykeys)
pass
#
......@@ -105,7 +102,7 @@ if dokeys:
params["keys"] = mykeys
pass
params["impotent"] = impotent
rval,response = do_method("cm", "CreateSliver", params, version="2.0")
rval,response = do_method_retry("cm", "CreateSliver", params)
if rval:
Fatal("Could not create sliver")
pass
......
......@@ -62,7 +62,7 @@ params = {}
params["credential"] = mycredential
params["type"] = "Slice"
params["hrn"] = SLICENAME
rval,response = do_method("sa", "Resolve", params)
rval,response = do_method_retry("sa", "Resolve", params)
if rval == 0:
print "Slice already exists."
sys.exit(0)
......@@ -83,7 +83,7 @@ params["credential"] = mycredential
params["type"] = "Slice"
params["hrn"] = SLICENAME
params["expiration"] = valid_until
rval,response = do_method("sa", "Register", params)
rval,response = do_method_retry("sa", "Register", params)
if rval:
Fatal("Could not get my slice")
print str(rval)
......@@ -101,7 +101,7 @@ if OtherUser:
params["hrn"] = OtherUser;
params["credential"] = mycredential
params["type"] = "User"
rval,response = do_method("sa", "Resolve", params)
rval,response = do_method_retry("sa", "Resolve", params)
if rval:
Fatal("Could not resolve other user")
pass
......@@ -114,7 +114,7 @@ if OtherUser:
params = {}
params["urn"] = user["urn"]
params["credential"] = myslice
rval,response = do_method("sa", "BindToSlice", params)
rval,response = do_method_retry("sa", "BindToSlice", params)
if rval:
Fatal("Could not bind other user to slice")
pass
......
......@@ -352,6 +352,10 @@ def do_method(module, method, params, URI=None, quiet=False, version=None,
if not quiet: print >> sys.stderr, e
return (-1, None)
except xmlrpclib.Fault, e:
if e.faultCode == 503:
print >> sys.stderr, e.faultString + " Retrying\n";
time.sleep(5.0)
continue;
if not quiet: print >> sys.stderr, e.faultString
return (-1, None)
except M2Crypto.SSL.Checker.WrongHost, e:
......@@ -393,12 +397,22 @@ def get_self_credential():
f.close()
return c
params = {}
rval,response = do_method("sa", "GetCredential", params)
rval,response = do_method_retry("sa", "GetCredential", params)
if rval:
Fatal("Could not get my credential")
pass
return response["value"]
def do_method_retry(suffix, method, params):
count = 200;
rval, response = do_method(suffix, method, params)
while count > 0 and response and response["code"] == 14:
count = count - 1
print " Will try again in a few seconds\n"
time.sleep(5.0)
rval, response = do_method(suffix, method, params)
return (rval, response)
def resolve_slice( name, selfcredential ):
if slicecredentialfile:
myslice = {}
......@@ -413,21 +427,10 @@ def resolve_slice( name, selfcredential ):
params["hrn"] = name
pass
count = 20
while True:
rval,response = do_method("sa", "Resolve", params)
rval,response = do_method_retry("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
Fatal("Slice does not exist");
pass
else:
break
......@@ -450,21 +453,10 @@ def get_slice_credential( slice, selfcredential ):
params["uuid"] = slice["uuid"]
pass
count = 20
while True:
rval,response = do_method("sa", "GetCredential", params)
rval,response = do_method_retry("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
Fatal("Could not get Slice credential")
pass
else:
break
......
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