Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
alecs_myu
erp5
Commits
d220540e
Commit
d220540e
authored
Sep 02, 2013
by
Benjamin Blanc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SlapOSMasterCommunicator: Add timeout + attemps on connections
parent
5a8f66c0
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
21 deletions
+23
-21
erp5/util/testnode/SlapOSMasterCommunicator.py
erp5/util/testnode/SlapOSMasterCommunicator.py
+23
-21
No files found.
erp5/util/testnode/SlapOSMasterCommunicator.py
View file @
d220540e
...
...
@@ -3,6 +3,8 @@ import httplib
import
urlparse
import
time
TIMEOUT
=
30
# TODO: News-> look list to get last news... (and not the first of the list)
class
SlapOSMasterCommunicator
(
object
):
...
...
@@ -53,39 +55,39 @@ class SlapOSMasterCommunicator(object):
def
_getConnection
(
self
,
certificate_path
,
key_path
,
url
):
api_scheme
,
api_netloc
,
api_path
,
api_query
,
api_fragment
=
urlparse
.
urlsplit
(
url
)
#self.log("HTTPS Connection with: %s, cert=%s, key=%s" %(api_netloc,key_path,certificate_path))
return
httplib
.
HTTPSConnection
(
api_netloc
,
key_file
=
key_path
,
cert_file
=
certificate_path
)
return
httplib
.
HTTPSConnection
(
api_netloc
,
key_file
=
key_path
,
cert_file
=
certificate_path
,
timeout
=
TIMEOUT
)
def
_curl
(
self
,
link
):
"""
'link' must look like : {'href':url,'type':content_type}
"""
#.log("_curl with: url:%s content_type:%s" %(link['href'], link['type']))
# Set timeout
import
socket
socket
.
setdefaulttimeout
(
1.0
*
TIMEOUT
)
api_scheme
,
api_netloc
,
api_path
,
api_query
,
api_fragment
=
urlparse
.
urlsplit
(
link
[
'href'
])
max_retry
=
10
# Try to use existing conection
try
:
self
.
connection
.
request
(
method
=
'GET'
,
url
=
api_path
,
headers
=
{
'Accept'
:
link
[
'type'
]},
body
=
""
)
response
=
self
.
connection
.
getresponse
()
except
:
try
:
# Try to update and use the connection
self
.
connection
=
self
.
_getConnection
(
self
.
certificate_path
,
self
.
key_path
,
self
.
url
)
self
.
connection
.
request
(
method
=
'GET'
,
url
=
api_path
,
headers
=
{
'Accept'
:
link
[
'type'
]},
body
=
""
)
response
=
self
.
connection
.
getresponse
()
except
:
raise
ValueError
(
"Impossible to use connection"
)
try
:
return
json
.
loads
(
response
.
read
())
# Create and use new connection
except
:
# Repet action after 2 secs
time
.
sleep
(
2
)
retry
=
0
# (re)Try several time to use new connection
while
retry
<
max_retry
:
try
:
# Try to update and use the connection
self
.
connection
=
self
.
_getConnection
(
self
.
certificate_path
,
self
.
key_path
,
self
.
url
)
self
.
connection
.
request
(
method
=
'GET'
,
url
=
api_path
,
headers
=
{
'Accept'
:
link
[
'type'
]},
body
=
""
)
response
=
self
.
connection
.
getresponse
()
except
:
raise
ValueError
(
"Impossible to use connection"
)
return
json
.
loads
(
response
.
read
())
except
:
self
.
log
(
"SlapOSMasterCommunicator: Connection failed.."
)
retry
+=
1
time
.
sleep
(
10
)
self
.
log
(
"SlapOSMasterCommunicator: All connection attempts failed after %d try.."
%
max_retry
)
raise
ValueError
(
"SlapOSMasterCommunicator: Impossible to use connection"
)
def
_update_hosting_subscription_informations
(
self
):
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment