]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Use correct time delta function
authorKevin Benton <blak111@gmail.com>
Thu, 28 May 2015 23:48:04 +0000 (16:48 -0700)
committerKevin Benton <blak111@gmail.com>
Fri, 29 May 2015 00:01:47 +0000 (17:01 -0700)
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

index a9ba6dfe86524737a8f892055cc1f29dc1ba1e8d..52dccf5c411a5884a34f5c92776e28f3c52fbe6a 100644 (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 "