summaryrefslogtreecommitdiffstats
path: root/vnftest/common/rest_client.py
diff options
context:
space:
mode:
authorMoshe <moshehoa@amdocs.com>2019-01-09 09:40:40 +0200
committerMoshe <moshehoa@amdocs.com>2019-01-09 11:53:20 +0200
commitce6df7403af5694aee412836cd3c86e33307e190 (patch)
treecd9799665cba2c44e517419d4d5570f2198939ff /vnftest/common/rest_client.py
parent6affd662a7793fda0be64ee103d7239702b9722b (diff)
refactor input parameters handling
Change-Id: I599be7b0c0f9724f954fb4790dcd7d03538fdcb7 Issue-ID: VNFSDK-350 Signed-off-by: Moshe <moshehoa@amdocs.com> fix test Issue-ID: VNFSDK-350 Change-Id: I8f3c0b80220e88660f0a0d00c1207abd30ed2208 Signed-off-by: Moshe <moshehoa@amdocs.com> fix test Issue-ID: VNFSDK-350 Change-Id: Ica479453d60129ed033dfcf613dbe73bb1c60bd0 Signed-off-by: Moshe <moshehoa@amdocs.com> fix test Issue-ID: VNFSDK-350 Change-Id: If9470517623074708e1c602b4683a958227d16c6 Signed-off-by: Moshe <moshehoa@amdocs.com>
Diffstat (limited to 'vnftest/common/rest_client.py')
-rw-r--r--vnftest/common/rest_client.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/vnftest/common/rest_client.py b/vnftest/common/rest_client.py
index 051f5dd..bd938e4 100644
--- a/vnftest/common/rest_client.py
+++ b/vnftest/common/rest_client.py
@@ -19,7 +19,8 @@ import logging
import os
import urllib2
import requests
-
+import sys
+import traceback
from vnftest.common import utils
logger = logging.getLogger(__name__)
@@ -39,8 +40,9 @@ def call(url, method, headers, data, logger):
f = urllib2.urlopen(req)
return_code = f.code
response_body = f.read()
- headers = f.headers
- content_type = headers.dict['content-type'] if 'content-type' in headers.dict else 'application/json'
+ headers = f.headers.dict
+
+ content_type = headers['content-type'] if 'content-type' in headers else 'application/json'
f.close()
if len(str(response_body)) == 0:
response_body = "{}"
@@ -48,9 +50,12 @@ def call(url, method, headers, data, logger):
response_body = utils.xml_to_dict(response_body)
else:
response_body = json.loads(response_body)
- result = {'return_code': return_code, 'body': response_body}
+ result = {'return_code': return_code, 'body': response_body, 'headers': headers}
return result
-
+ except urllib2.HTTPError as e:
+ error_message = e.read()
+ logger.exception(error_message)
+ raise RuntimeError(error_message)
except Exception as e:
message = "Cannot read content from {}, exception: {}".format(url, e)
logger.exception(message)
@@ -64,8 +69,8 @@ def upload_file(url, headers, file, logger):
logger.debug("Upload file. URL: {}".format(url))
response = None
try:
- response = requests.post(url, headers=headers, files=file)
- return {'return_code': response.status_code, 'body': response.json()}
+ response = requests.post(url, headers=headers, files=file, verify=False)
+ return {'return_code': response.status_code, 'body': response.json(), 'headers': response.headers}
except Exception as e:
message = "Error while uploading file to {}, exception: {}".format(url, e)
logger.exception(message)