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