Change wait_for time to utc (#23987)

pull/23991/head
Brian-Williams 8 years ago committed by Matt Martz
parent 946658cd24
commit 8466c808d9

@ -442,7 +442,7 @@ def main():
except: except:
module.fail_json(msg="unknown active_connection_state ("+_connection_state+") defined") module.fail_json(msg="unknown active_connection_state ("+_connection_state+") defined")
start = datetime.datetime.now() start = datetime.datetime.utcnow()
if delay: if delay:
time.sleep(delay) time.sleep(delay)
@ -453,7 +453,7 @@ def main():
### first wait for the stop condition ### first wait for the stop condition
end = start + datetime.timedelta(seconds=timeout) end = start + datetime.timedelta(seconds=timeout)
while datetime.datetime.now() < end: while datetime.datetime.utcnow() < end:
if path: if path:
try: try:
f = open(path) f = open(path)
@ -470,7 +470,7 @@ def main():
# Conditions not yet met, wait and try again # Conditions not yet met, wait and try again
time.sleep(params['sleep']) time.sleep(params['sleep'])
else: else:
elapsed = datetime.datetime.now() - start elapsed = datetime.datetime.utcnow() - start
if port: if port:
module.fail_json(msg="Timeout when waiting for %s:%s to stop." % (host, port), elapsed=elapsed.seconds) module.fail_json(msg="Timeout when waiting for %s:%s to stop." % (host, port), elapsed=elapsed.seconds)
elif path: elif path:
@ -479,7 +479,7 @@ def main():
elif state in ['started', 'present']: elif state in ['started', 'present']:
### wait for start condition ### wait for start condition
end = start + datetime.timedelta(seconds=timeout) end = start + datetime.timedelta(seconds=timeout)
while datetime.datetime.now() < end: while datetime.datetime.utcnow() < end:
if path: if path:
try: try:
os.stat(path) os.stat(path)
@ -487,7 +487,7 @@ def main():
e = get_exception() e = get_exception()
# If anything except file not present, throw an error # If anything except file not present, throw an error
if e.errno != 2: 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) module.fail_json(msg="Failed to stat %s, %s" % (path, e.strerror), elapsed=elapsed.seconds)
# file doesn't exist yet, so continue # file doesn't exist yet, so continue
else: else:
@ -506,7 +506,7 @@ def main():
except IOError: except IOError:
pass pass
elif port: 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: try:
s = _create_connection(host, port, min(connect_timeout, alt_connect_timeout)) s = _create_connection(host, port, min(connect_timeout, alt_connect_timeout))
except: except:
@ -517,8 +517,8 @@ def main():
if compiled_search_re: if compiled_search_re:
data = '' data = ''
matched = False matched = False
while datetime.datetime.now() < end: while datetime.datetime.utcnow() < end:
max_timeout = math.ceil(_timedelta_total_seconds(end - datetime.datetime.now())) max_timeout = math.ceil(_timedelta_total_seconds(end - datetime.datetime.utcnow()))
(readable, w, e) = select.select([s], [], [], max_timeout) (readable, w, e) = select.select([s], [], [], max_timeout)
if not readable: if not readable:
# No new data. Probably means our timeout # No new data. Probably means our timeout
@ -550,7 +550,7 @@ def main():
else: # while-else else: # while-else
# Timeout expired # Timeout expired
elapsed = datetime.datetime.now() - start elapsed = datetime.datetime.utcnow() - start
if port: if port:
if search_regex: if search_regex:
module.fail_json(msg="Timeout when waiting for search string %s in %s:%s" % (search_regex, host, port), elapsed=elapsed.seconds) 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 ### wait until all active connections are gone
end = start + datetime.timedelta(seconds=timeout) end = start + datetime.timedelta(seconds=timeout)
tcpconns = TCPConnectionInfo(module) tcpconns = TCPConnectionInfo(module)
while datetime.datetime.now() < end: while datetime.datetime.utcnow() < end:
try: try:
if tcpconns.get_active_connections_count() == 0: if tcpconns.get_active_connections_count() == 0:
break break
@ -575,10 +575,10 @@ def main():
# Conditions not yet met, wait and try again # Conditions not yet met, wait and try again
time.sleep(params['sleep']) time.sleep(params['sleep'])
else: 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) 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) module.exit_json(state=state, port=port, search_regex=search_regex, path=path, elapsed=elapsed.seconds)
# import module snippets # import module snippets

Loading…
Cancel
Save