From 690b9b7e26a7580c5ac12364e525e623b3980dfc Mon Sep 17 00:00:00 2001 From: Benjamin Blanc <benjamin.blanc@tiolive.com> Date: Wed, 31 Jul 2013 10:58:59 +0200 Subject: [PATCH] erp5_bootstrap: add while/try for getConnection --- .../erp5_bootstrap/template/erp5_bootstrap.in | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/slapos/recipe/erp5_bootstrap/template/erp5_bootstrap.in b/slapos/recipe/erp5_bootstrap/template/erp5_bootstrap.in index 043ac4614..1dd8cf3e7 100644 --- a/slapos/recipe/erp5_bootstrap/template/erp5_bootstrap.in +++ b/slapos/recipe/erp5_bootstrap/template/erp5_bootstrap.in @@ -7,6 +7,7 @@ import time MAX_INSTALLATION_TIME = 60*30 MAX_TESTING_TIME = 60 +MAX_GETTING_CONNECTION_TIME = 60*5 user = "%(user)s" password = "%(password)s" @@ -21,12 +22,20 @@ header_dict = {'Authorization': 'Basic %%s' %% \ def getConnection(): print "Getting new connection" - if protocol == 'https': - return httplib.HTTPSConnection(host) - elif protocol == 'http': - return httplib.HTTPConnection(host) - else: - raise ValueError("Protocol not implemented") + start_time = time.time() + count = 0 + while MAX_GETTING_CONNECTION_TIME > time.time()-start_time: + try: + count = count + 1 + if protocol == 'https': + return httplib.HTTPSConnection(host) + elif protocol == 'http': + return httplib.HTTPConnection(host) + else: + raise ValueError("Protocol not implemented") + except: + print "Getting new connection failed, retry" + raise ValueError("Cannot get new connection after %%d try (for %%s s)" %%(count, str(time.time()-start_time))) def testIfExist(page, unexcepted_content="Site Error"): print "Test if %%s exists" %%(page) -- 2.30.9