Add missing timeouts to some API calls

Several API calls were missing a timeout.  A default timeout of 30
seconds was given to each.

No issues have been  reported. This is a preventive change,
meant to tighten behaviour.

Test Plan:
Bootstrap, unlock, lock in SX configuration
Bootstrap, unlock, lock in DX configuration

Closes-Bug: 1927775

Signed-off-by: Joshua Kraitberg <joshua.kraitberg@windriver.com>
Change-Id: I8cb5717557cdde34345af948eb5a8c9613c1995b
This commit is contained in:
Joshua Kraitberg 2022-08-18 08:55:57 -04:00
parent 197fe530f5
commit 7a674bf9bf
3 changed files with 8 additions and 8 deletions

View File

@ -19,7 +19,7 @@ LOG = log.getLogger(__name__)
def rest_api_request(token, method, api_cmd, api_cmd_headers=None,
api_cmd_payload=None):
api_cmd_payload=None, timeout=30):
"""
Make a rest-api request
"""
@ -37,7 +37,7 @@ def rest_api_request(token, method, api_cmd, api_cmd_headers=None,
request_info.add_header("Content-type", "application/json")
request_info.data = api_cmd_payload
request = urlrequest.urlopen(request_info)
request = urlrequest.urlopen(request_info, timeout=timeout)
response = request.read()
if response == "":
@ -64,7 +64,7 @@ def rest_api_request(token, method, api_cmd, api_cmd_headers=None,
def get_token(auth_url, auth_project, auth_user, auth_password,
user_domain, project_domain):
user_domain, project_domain, timeout=30):
"""
Ask OpenStack Keystone for a token
"""
@ -96,7 +96,7 @@ def get_token(auth_url, auth_project, auth_user, auth_password,
request_info.data = payload
request = urlrequest.urlopen(request_info)
request = urlrequest.urlopen(request_info, timeout=timeout)
# Identity API v3 returns token id in X-Subject-Token
# response header.
token_id = request.info().getheader('X-Subject-Token')

View File

@ -25,7 +25,7 @@ LOG = log.getLogger(__name__)
def _get_token(auth_url, auth_project, username, password, user_domain,
project_domain, region_name):
project_domain, region_name, timeout=30):
"""
Ask OpenStack Keystone for a token
Returns: token object or None on failure
@ -57,7 +57,7 @@ def _get_token(auth_url, auth_project, username, password, user_domain,
request_info.data = encodeutils.safe_encode(payload)
request = urlopen(request_info)
request = urlopen(request_info, timeout=timeout)
# Identity API v3 returns token id in X-Subject-Token
# response header.
token_id = request.headers.get('X-Subject-Token')

View File

@ -744,7 +744,7 @@ class RoleCheck(Check):
@register('http')
class HttpCheck(Check):
def __call__(self, target, creds):
def __call__(self, target, creds, timeout=30):
"""
Check http: rules by calling to a remote server.
@ -756,7 +756,7 @@ class HttpCheck(Check):
data = {'target': jsonutils.dumps(target),
'credentials': jsonutils.dumps(creds)}
post_data = urlencode(data)
f = urlopen(url, post_data)
f = urlopen(url, post_data, timeout=timeout)
return f.read() == "True"