From 02a49e481bca9ad85e3b93471e86a26ebe5b2f19 Mon Sep 17 00:00:00 2001 From: DheerajDang Date: Fri, 21 May 2021 14:59:20 +0530 Subject: [PATCH] fixing condition to raise exception when URL is not reachable [Fixes #9] --- .../scenarios/kubernetes/services.py | 51 ++++++++++--------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/rally_plugins/scenarios/kubernetes/services.py b/rally_plugins/scenarios/kubernetes/services.py index 50f74ba..02ca598 100644 --- a/rally_plugins/scenarios/kubernetes/services.py +++ b/rally_plugins/scenarios/kubernetes/services.py @@ -229,32 +229,33 @@ def run(self, image, port, protocol, image_pull_policy='IfNotPresent', else: ip = "://" + server[:server.index(":") + 1] url = ("http" + ip + str(node_port) + "/") - while i < retries_total: - try: - kwargs = {} - if request_timeout: - kwargs["timeout"] = request_timeout - requests.get(url, **kwargs) - except (requests.ConnectionError, requests.ReadTimeout) as ex: - if i < retries_total: - i += 1 - commonutils.interruptable_sleep(sleep_time) + try: + while i < retries_total: + try: + kwargs = {} + if request_timeout: + kwargs["timeout"] = request_timeout + requests.get(url, **kwargs) + except (requests.ConnectionError, requests.ReadTimeout) as ex: + if i < retries_total: + i += 1 + commonutils.interruptable_sleep(sleep_time) + if i == retries_total: + raise exceptions.RallyException( + message="Unable to get response " + "from %(url)s: %(ex)s" % { + "url": url, + "ex": str(ex) + }) else: - raise exceptions.RallyException( - message="Unable to get response " - "from %(url)s: %(ex)s" % { - "url": url, - "ex": str(ex) - }) - else: - break - - self.client.delete_service(name, namespace=namespace) - self.client.delete_pod( - name, - namespace=namespace, - status_wait=status_wait - ) + break + finally: + self.client.delete_service(name, namespace=namespace) + self.client.delete_pod( + name, + namespace=namespace, + status_wait=status_wait + ) @scenario.configure(