From a0c9745e90596d4a3207e844332e078ca7ecc5fa Mon Sep 17 00:00:00 2001 From: Kevin Benton Date: Thu, 28 May 2015 16:48:04 -0700 Subject: [PATCH] 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 --- neutron/db/agents_db.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/neutron/db/agents_db.py b/neutron/db/agents_db.py index a9ba6dfe865..52dccf5c411 100644 --- a/neutron/db/agents_db.py +++ b/neutron/db/agents_db.py @@ -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 "