Add REST API timeouts to nfv-client
The VIM's nfv-client sends REST API messages to the VIM, but it currently does not set a timeout for these calls. In the case where a message is lost, the nfv-client would block forever, causing the calling process to hang. Fixing this by adding timeouts to the nfv-client to ensure that all REST API messages it sends will timeout even in the case of lost messages. Change-Id: Iba06924fb7bd14a1ee3362b4fd19aa4114dc34cd Partial-Bug: 1886037 Signed-off-by: Bart Wensley <barton.wensley@windriver.com>
This commit is contained in:
parent
0bec7460c8
commit
b39bc8c034
|
@ -61,7 +61,7 @@ def get_token(auth_uri, project_name, project_domain_name, username, password,
|
|||
|
||||
request_info.add_data(payload)
|
||||
|
||||
request = urllib.request.urlopen(request_info)
|
||||
request = urllib.request.urlopen(request_info, timeout=30)
|
||||
# Identity API v3 returns token id in X-Subject-Token
|
||||
# response header.
|
||||
token_id = request.info().getheader('X-Subject-Token')
|
||||
|
|
|
@ -8,9 +8,13 @@ from six.moves import http_client as httplib
|
|||
from six.moves import urllib
|
||||
|
||||
|
||||
def request(token_id, method, api_cmd, api_cmd_headers=None, api_cmd_payload=None):
|
||||
def request(token_id, method, api_cmd, api_cmd_headers=None,
|
||||
api_cmd_payload=None, timeout_in_secs=40):
|
||||
"""
|
||||
Make a rest-api request
|
||||
Note: Using a default timeout of 40 seconds. The VIM's internal handling
|
||||
of these requests times out after 30 seconds - we want that to happen
|
||||
first (if possible).
|
||||
"""
|
||||
headers_per_hop = ['connection', 'keep-alive', 'proxy-authenticate',
|
||||
'proxy-authorization', 'te', 'trailers',
|
||||
|
@ -30,7 +34,8 @@ def request(token_id, method, api_cmd, api_cmd_headers=None, api_cmd_payload=Non
|
|||
if api_cmd_payload is not None:
|
||||
request_info.add_data(api_cmd_payload)
|
||||
|
||||
url_request = urllib.request.urlopen(request_info)
|
||||
url_request = urllib.request.urlopen(request_info,
|
||||
timeout=timeout_in_secs)
|
||||
|
||||
headers = list() # list of tuples
|
||||
for key, value in url_request.info().items():
|
||||
|
|
Loading…
Reference in New Issue