aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/common/httpClient.py
diff options
context:
space:
mode:
authorMaciej Skrocki <maciej.skrocki@intel.com>2017-09-19 14:00:53 -0700
committerRoss Brattain <ross.b.brattain@intel.com>2017-09-21 00:41:31 +0000
commitc039fecf1c533b09286b0eec89ddc13862b3d452 (patch)
treedd640db085b5fc873c985fd0601dbc70e0cd2b0c /yardstick/common/httpClient.py
parent661d78e5ad9a831a4e6c36287d17ff6829b062d0 (diff)
Introduced timeout to post method of HttpClient
We seen cases where grafana container bring-up code would fail, because of too quick access to the http api. Added 10sec timeout for the first query of the API. Change-Id: Ifc95a626d0ab5552a1f26fb167fc3f65791392d7 Signed-off-by: Maciej Skrocki <maciej.skrocki@intel.com>
Diffstat (limited to 'yardstick/common/httpClient.py')
-rw-r--r--yardstick/common/httpClient.py24
1 files changed, 14 insertions, 10 deletions
diff --git a/yardstick/common/httpClient.py b/yardstick/common/httpClient.py
index 11c2d752d..54f7be670 100644
--- a/yardstick/common/httpClient.py
+++ b/yardstick/common/httpClient.py
@@ -9,6 +9,7 @@
from __future__ import absolute_import
import logging
+import time
from oslo_serialization import jsonutils
import requests
@@ -18,18 +19,21 @@ logger = logging.getLogger(__name__)
class HttpClient(object):
- def post(self, url, data):
+ def post(self, url, data, timeout=0):
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
+ t_end = time.time() + timeout
+ while True:
+ try:
+ response = requests.post(url, data=data, headers=headers)
+ result = response.json()
+ logger.debug('The result is: %s', result)
+ return result
+ except Exception:
+ if time.time() > t_end:
+ logger.exception('')
+ raise
+ time.sleep(1)
def get(self, url):
response = requests.get(url)