From 9191b22b2ca5928e43a4535fafc6809d4a15c0c6 Mon Sep 17 00:00:00 2001 From: "Roche, Damien" Date: Tue, 24 Jan 2017 13:38:56 +0000 Subject: [PATCH 1/3] Enhanced wait_for_successful_query with request_interval --- salt/states/http.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/salt/states/http.py b/salt/states/http.py index be4277c143..311b26273d 100644 --- a/salt/states/http.py +++ b/salt/states/http.py @@ -10,13 +10,15 @@ Perform an HTTP query and statefully return the result # Import python libs from __future__ import absolute_import import re - +import logging import time __monitor__ = [ 'query', ] +log = logging.getLogger(__name__) + def query(name, match=None, match_type='string', status=None, wait_for=None, **kwargs): ''' @@ -129,6 +131,9 @@ def wait_for_successful_query(name, wait_for=300, **kwargs): ''' Like query but, repeat and wait until match/match_type or status is fulfilled. State returns result from last query state in case of success or if no successful query was made within wait_for timeout. + + request_interval + Optional interval to delay requests by N seconds to reduce the number of requests sent. ''' starttime = time.time() @@ -146,5 +151,9 @@ def wait_for_successful_query(name, wait_for=300, **kwargs): if not ret and caught_exception: # workaround pylint bug https://www.logilab.org/ticket/3207 raise caught_exception # pylint: disable=E0702 - return ret + else: + # Space requests out by delaying for an interval + if 'request_interval' in kwargs: + log.debug("delaying query for {} seconds.".format(kwargs['request_interval'])) + time.sleep(kwargs['request_interval']) From b3582f7a62ceb84870bc10d2eedb4de1ca372471 Mon Sep 17 00:00:00 2001 From: "Roche, Damien" Date: Tue, 24 Jan 2017 15:19:36 +0000 Subject: [PATCH 2/3] fixed lint issues --- salt/states/http.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/salt/states/http.py b/salt/states/http.py index 311b26273d..58e63f9184 100644 --- a/salt/states/http.py +++ b/salt/states/http.py @@ -133,7 +133,7 @@ def wait_for_successful_query(name, wait_for=300, **kwargs): query state in case of success or if no successful query was made within wait_for timeout. request_interval - Optional interval to delay requests by N seconds to reduce the number of requests sent. + Optional interval to delay requests by N seconds to reduce the number of requests sent. ''' starttime = time.time() @@ -153,7 +153,7 @@ def wait_for_successful_query(name, wait_for=300, **kwargs): raise caught_exception # pylint: disable=E0702 return ret else: - # Space requests out by delaying for an interval - if 'request_interval' in kwargs: - log.debug("delaying query for {} seconds.".format(kwargs['request_interval'])) - time.sleep(kwargs['request_interval']) + # Space requests out by delaying for an interval + if 'request_interval' in kwargs: + log.debug("delaying query for {} seconds.".format(kwargs['request_interval'])) + time.sleep(kwargs['request_interval']) From 1389c510cead307172e4b7df74cec7879edf0251 Mon Sep 17 00:00:00 2001 From: "Roche, Damien" Date: Tue, 24 Jan 2017 16:13:20 +0000 Subject: [PATCH 3/3] fixed lint issues --- salt/states/http.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/salt/states/http.py b/salt/states/http.py index 58e63f9184..08a56a860d 100644 --- a/salt/states/http.py +++ b/salt/states/http.py @@ -155,5 +155,5 @@ def wait_for_successful_query(name, wait_for=300, **kwargs): else: # Space requests out by delaying for an interval if 'request_interval' in kwargs: - log.debug("delaying query for {} seconds.".format(kwargs['request_interval'])) - time.sleep(kwargs['request_interval']) + log.debug("delaying query for {0} seconds.".format(kwargs['request_interval'])) + time.sleep(kwargs['request_interval'])