X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=yardstick%2Fcommon%2FhttpClient.py;h=11c2d752dc043a301f303516459c9eca0ac5b11b;hb=270d6092c809e8de039a08efd8c108f865cf860e;hp=b6959b400b5ee9c8842dade9619613614fdc0a07;hpb=c383ae3fa6ccb865575eacf78209fdd3ac7efa69;p=yardstick.git diff --git a/yardstick/common/httpClient.py b/yardstick/common/httpClient.py index b6959b400..11c2d752d 100644 --- a/yardstick/common/httpClient.py +++ b/yardstick/common/httpClient.py @@ -6,9 +6,11 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -import json +from __future__ import absolute_import + import logging +from oslo_serialization import jsonutils import requests logger = logging.getLogger(__name__) @@ -17,11 +19,18 @@ logger = logging.getLogger(__name__) class HttpClient(object): def post(self, url, data): - data = json.dumps(data) + data = jsonutils.dump_as_bytes(data) headers = {'Content-Type': 'application/json'} try: response = requests.post(url, data=data, headers=headers) result = response.json() logger.debug('The result is: %s', result) + + return result except Exception as e: logger.debug('Failed: %s', e) + raise + + def get(self, url): + response = requests.get(url) + return response.json()