Use correct time delta function

The .seconds attribute of a timedetla object cannot be taken in
isolation because it can overflow into days. For example, a -1 second
difference will become -1 day and 86399 seconds.

This became a problem when the agent clock was slightly ahead of
the server clock. When calling (server_time - agent_time).seconds
in this scenario, it would go below 0 in the daily seconds and
wraparound to 86399 seconds and -1 day.

This patch corrects the issue by using a method in timeutils that
ends up calling total_seconds(), which was designed for this usecase.
It also restores the formatting that was removed in patch:
Ibfc30444b7a167fb18ae9051a775266236d4ecce

Closes-Bug: #1456760
Change-Id: Ie90249ab68bb5f8d117872d52180c7087d8fac9b
This commit is contained in:
Kevin Benton 2015-05-28 16:48:04 -07:00
parent 8f741f97e4
commit a0c9745e90
1 changed files with 4 additions and 3 deletions

View File

@ -294,15 +294,16 @@ class AgentExtRpcCallback(object):
"""
if agent_state.get('start_flag'):
time_server_now = timeutils.utcnow()
diff = abs((time_server_now - agent_time).seconds)
diff = abs(timeutils.delta_seconds(time_server_now, agent_time))
if diff > cfg.CONF.agent_down_time:
agent_name = agent_state['agent_type']
time_agent = timeutils.isotime(agent_time)
host = agent_state['host']
log_dict = {'host': host,
'agent_name': agent_name,
'agent_time': agent_time,
'agent_time': time_agent,
'threshold': cfg.CONF.agent_down_time,
'serv_time': time_server_now,
'serv_time': timeutils.isotime(time_server_now),
'diff': diff}
LOG.error(_LE("Message received from the host: %(host)s "
"during the registration of %(agent_name)s has "