Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change wait_for time to utc #23987

Merged
merged 1 commit into from
Apr 25, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 12 additions & 12 deletions lib/ansible/modules/utilities/logic/wait_for.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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:
Expand All @@ -479,15 +479,15 @@ 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)
except OSError:
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:
Expand All @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down