From 8466c808d92e4327ea225e91a4da0d146aa5b843 Mon Sep 17 00:00:00 2001 From: Brian-Williams Date: Tue, 25 Apr 2017 18:04:29 -0400 Subject: [PATCH] Change wait_for time to utc (#23987) --- .../modules/utilities/logic/wait_for.py | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/ansible/modules/utilities/logic/wait_for.py b/lib/ansible/modules/utilities/logic/wait_for.py index 58262334e6..8d87c0f785 100644 --- a/lib/ansible/modules/utilities/logic/wait_for.py +++ b/lib/ansible/modules/utilities/logic/wait_for.py @@ -442,7 +442,7 @@ def main(): except: module.fail_json(msg="unknown active_connection_state ("+_connection_state+") defined") - start = datetime.datetime.now() + start = datetime.datetime.utcnow() if delay: time.sleep(delay) @@ -453,7 +453,7 @@ def main(): ### first wait for the stop condition end = start + datetime.timedelta(seconds=timeout) - while datetime.datetime.now() < end: + while datetime.datetime.utcnow() < end: if path: try: f = open(path) @@ -470,7 +470,7 @@ def main(): # Conditions not yet met, wait and try again time.sleep(params['sleep']) else: - elapsed = datetime.datetime.now() - start + elapsed = datetime.datetime.utcnow() - start if port: module.fail_json(msg="Timeout when waiting for %s:%s to stop." % (host, port), elapsed=elapsed.seconds) elif path: @@ -479,7 +479,7 @@ def main(): elif state in ['started', 'present']: ### wait for start condition end = start + datetime.timedelta(seconds=timeout) - while datetime.datetime.now() < end: + while datetime.datetime.utcnow() < end: if path: try: os.stat(path) @@ -487,7 +487,7 @@ def main(): e = get_exception() # If anything except file not present, throw an error if e.errno != 2: - elapsed = datetime.datetime.now() - start + elapsed = datetime.datetime.utcnow() - start module.fail_json(msg="Failed to stat %s, %s" % (path, e.strerror), elapsed=elapsed.seconds) # file doesn't exist yet, so continue else: @@ -506,7 +506,7 @@ def main(): except IOError: pass elif port: - alt_connect_timeout = math.ceil(_timedelta_total_seconds(end - datetime.datetime.now())) + alt_connect_timeout = math.ceil(_timedelta_total_seconds(end - datetime.datetime.utcnow())) try: s = _create_connection(host, port, min(connect_timeout, alt_connect_timeout)) except: @@ -517,8 +517,8 @@ def main(): if compiled_search_re: data = '' matched = False - while datetime.datetime.now() < end: - max_timeout = math.ceil(_timedelta_total_seconds(end - datetime.datetime.now())) + while datetime.datetime.utcnow() < end: + max_timeout = math.ceil(_timedelta_total_seconds(end - datetime.datetime.utcnow())) (readable, w, e) = select.select([s], [], [], max_timeout) if not readable: # No new data. Probably means our timeout @@ -550,7 +550,7 @@ def main(): else: # while-else # Timeout expired - elapsed = datetime.datetime.now() - start + elapsed = datetime.datetime.utcnow() - start if port: if search_regex: module.fail_json(msg="Timeout when waiting for search string %s in %s:%s" % (search_regex, host, port), elapsed=elapsed.seconds) @@ -566,7 +566,7 @@ def main(): ### wait until all active connections are gone end = start + datetime.timedelta(seconds=timeout) tcpconns = TCPConnectionInfo(module) - while datetime.datetime.now() < end: + while datetime.datetime.utcnow() < end: try: if tcpconns.get_active_connections_count() == 0: break @@ -575,10 +575,10 @@ def main(): # Conditions not yet met, wait and try again time.sleep(params['sleep']) else: - elapsed = datetime.datetime.now() - start + elapsed = datetime.datetime.utcnow() - start module.fail_json(msg="Timeout when waiting for %s:%s to drain" % (host, port), elapsed=elapsed.seconds) - elapsed = datetime.datetime.now() - start + elapsed = datetime.datetime.utcnow() - start module.exit_json(state=state, port=port, search_regex=search_regex, path=path, elapsed=elapsed.seconds) # import module snippets