Skip to content

Commit

Permalink
Changed timeout to REST_TIMEOUT and multiples for file uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
Naval Patel committed Feb 6, 2019
1 parent d5e2857 commit 9d58faf
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions pylxca/pylxca_api/lxca_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def get_chassis(self,url, session, uuid, status ):
url = url + "?status=managed"

try:
resp = session.get(url,verify=False,timeout=3)
resp = session.get(url,verify=False,timeout=REST_TIMEOUT)
resp.raise_for_status()
except HTTPError as re:
logger.error("REST API Exception: Exception = %s", re)
Expand Down Expand Up @@ -627,7 +627,7 @@ def get_updaterepo(self, url, session, key, mt, scope):
else:
raise Exception("Invalid argument scope: " + scope)

resp = session.get(url,verify=False, timeout=3)
resp = session.get(url,verify=False, timeout=REST_TIMEOUT)
resp.raise_for_status()
return resp

Expand Down Expand Up @@ -693,7 +693,7 @@ def put_updaterepo(self, url, session, action , fixids, mt, type, scope):
if action == "acquire":
payload['type'] = "latest"

resp = session.put(url, data=json.dumps(payload), verify=False, timeout=3)
resp = session.put(url, data=json.dumps(payload), verify=False, timeout=REST_TIMEOUT)
resp.raise_for_status()
return resp

Expand Down Expand Up @@ -725,7 +725,7 @@ def get_managementserver(self, url, session, key, fixids, type):
if key not in ['all']:
url = url + "?key=" + key

resp = session.get(url,verify=False, timeout=3)
resp = session.get(url,verify=False, timeout=REST_TIMEOUT)
resp.raise_for_status()
return resp

Expand All @@ -746,7 +746,7 @@ def set_managementserver(self, url, session, action, files, jobid, fixids):
payload['fixids'] = [fixids]
else:
raise Exception("Invalid argument apply requires fixids")
resp = session.put(url, data=json.dumps(payload), verify=False, timeout=3)
resp = session.put(url, data=json.dumps(payload), verify=False, timeout=REST_TIMEOUT)
return resp
# Creations of Import job POST
if not action == None and action == "import":
Expand All @@ -766,7 +766,7 @@ def set_managementserver(self, url, session, action, files, jobid, fixids):
'type': file_type_dict[os.path.splitext(os.path.basename(file))[-1]]
} for index, file in enumerate(file_list)]
payload = {'files' : payload_files}
resp = session.post(url, data=json.dumps(payload), verify=False, timeout=120)
resp = session.post(url, data=json.dumps(payload), verify=False, timeout=2*REST_TIMEOUT)
return resp

else :
Expand All @@ -779,7 +779,7 @@ def set_managementserver(self, url, session, action, files, jobid, fixids):
) for file in file_list]
)
monitor = MultipartEncoderMonitor(m, callback)
resp = session.post(url, data = monitor, headers={'Content-Type': monitor.content_type}, verify=False, timeout=6000)
resp = session.post(url, data = monitor, headers={'Content-Type': monitor.content_type}, verify=False, timeout=100 * REST_TIMEOUT)
return resp

if not action == None \
Expand All @@ -791,15 +791,15 @@ def set_managementserver(self, url, session, action, files, jobid, fixids):
payload['fixids'] = fixids_list
else:
raise Exception("Invalid argument key action: acquire requires fixids ")
resp = session.post(url, data=json.dumps(payload), verify=False, timeout=3)
resp = session.post(url, data=json.dumps(payload), verify=False, timeout=REST_TIMEOUT)
return resp

if not action == None \
and action == "refresh":
url = url + "?action=refresh"
payload = {}
payload['mts'] = ['lxca']
resp = session.post(url, data=json.dumps(payload), verify=False, timeout=3)
resp = session.post(url, data=json.dumps(payload), verify=False, timeout=REST_TIMEOUT)
return resp

if not action == None \
Expand All @@ -810,7 +810,7 @@ def set_managementserver(self, url, session, action, files, jobid, fixids):
else:
raise Exception("Invalid argument key action: delete requires fixids ")

resp = session.delete(url, verify=False, timeout=3)
resp = session.delete(url, verify=False, timeout=REST_TIMEOUT)
return resp

except HTTPError as re:
Expand Down Expand Up @@ -1294,7 +1294,7 @@ def get_osimage(self, osimages_info, **kwargs):

try:
# print "I'm in lxca_rest get_osimage, url=", url
resp = session.get(url, verify=False, timeout=3) ## It raises HTTPError here
resp = session.get(url, verify=False, timeout=REST_TIMEOUT) ## It raises HTTPError here
resp.raise_for_status()
except HTTPError as re:
logger.error("REST API Exception: Exception = %s", re)
Expand Down Expand Up @@ -1362,7 +1362,7 @@ def set_osimage(self, osimages_info, **kwargs):
else:
url = url + "%s=%s&" %(k,v)
url = url.rstrip('&')
resp = session.post(url, data=json.dumps(payload), verify=False, timeout=600)
resp = session.post(url, data=json.dumps(payload), verify=False, timeout=20 * REST_TIMEOUT)
return resp
else: # local case
for k,v in list(kwargs.items()):
Expand All @@ -1379,7 +1379,7 @@ def set_osimage(self, osimages_info, **kwargs):
#'name':(None,'uploadedfile'),
'uploadedfile': ('trail.py', open('/home/naval/trail.py', 'rb'),'text/plain')}
#files = {'file': ('trail.py', open('/home/naval/trail.py', 'r'), 'text/plain')}
resp = session.post(url, files=files, verify=False, timeout=600)
resp = session.post(url, files=files, verify=False, timeout=20 * REST_TIMEOUT)
return resp
# postcall for remoteFileServers DONE
if 'remoteFileServers' in osimages_info and 'putid' not in kwargs and 'deleteid' not in kwargs:
Expand Down Expand Up @@ -1536,7 +1536,7 @@ def set_osimage(self, osimages_info, **kwargs):
def get_method(self, url, session, **kwargs):
resp = None
try:
resp = session.get(url,verify=False, timeout=3) ## It raises HTTPError here
resp = session.get(url,verify=False, timeout=REST_TIMEOUT) ## It raises HTTPError here
resp.raise_for_status()
except HTTPError as re:
logger.error("REST API Exception: Exception = %s", re)
Expand All @@ -1547,7 +1547,7 @@ def put_method(self, url, session, payload, **kwargs):
resp = None
try:
resp = session.put(url, data = json.dumps(payload), verify=False,
timeout=60) ## It raises HTTPError here
timeout=REST_TIMEOUT) ## It raises HTTPError here
resp.raise_for_status()
except HTTPError as re:
logger.error("REST API Exception: Exception = %s", re)
Expand All @@ -1557,7 +1557,7 @@ def put_method(self, url, session, payload, **kwargs):
def delete_method(self,url, session, payload, **kwargs):
resp = None
try:
resp = session.delete(url, data = json.dumps(payload), verify=False, timeout=3) ## It raises HTTPError here
resp = session.delete(url, data = json.dumps(payload), verify=False, timeout=REST_TIMEOUT) ## It raises HTTPError here
resp.raise_for_status()
except HTTPError as re:
logger.error("REST API Exception: Exception = %s", re)
Expand All @@ -1567,7 +1567,7 @@ def delete_method(self,url, session, payload, **kwargs):
def post_method(self,url, session, payload, **kwargs):
resp = None
try:
resp = session.post(url, data = json.dumps(payload), verify=False, timeout=3) ## It raises HTTPError here
resp = session.post(url, data = json.dumps(payload), verify=False, timeout=REST_TIMEOUT) ## It raises HTTPError here
resp.raise_for_status()
except HTTPError as re:
logger.error("REST API Exception: Exception = %s", re)
Expand All @@ -1581,7 +1581,7 @@ def get_rules(self,url, session, id):
url = url + '/' + id

try:
resp = session.get(url, verify=False, timeout=3)
resp = session.get(url, verify=False, timeout=REST_TIMEOUT)
resp.raise_for_status()
except HTTPError as re:
logger.error("REST API Exception: Exception = %s", re)
Expand Down Expand Up @@ -1653,7 +1653,7 @@ def get_storedcredentials(self,url, session, id):
url = url + '/' + id

try:
resp = session.get(url, verify=False, timeout=3)
resp = session.get(url, verify=False, timeout=REST_TIMEOUT)
resp.raise_for_status()
except HTTPError as re:
logger.error("REST API Exception: Exception = %s", re)
Expand Down

0 comments on commit 9d58faf

Please sign in to comment.