summaryrefslogtreecommitdiff
path: root/ironic/conductor/task_manager.py
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2015-08-10 16:23:01 -0700
committerJoshua Harlow <harlowja@yahoo-inc.com>2015-08-11 11:07:19 -0700
commit8821f42b20cdd5a4caa8028983b3c58871b48517 (patch)
treebdc7c9c61497cdb24ad3b47a076c7bce72da426e /ironic/conductor/task_manager.py
parent1d82c93652b2db512a1e0fe70156e6be8c6b0d7a (diff)
downloadironic-8821f42b20cdd5a4caa8028983b3c58871b48517.tar.gz
Use the oslo_utils.timeutils 'StopWatch' class
Instead of using time.time() to keep track of durations the stop watch class provides this same functionality in a nicely made helper class. It also internally uses monotonically increasing time so that drifts/going backwards should not be possible so it seems like a nice change to just use it vs computing similar information. Change-Id: Ic8906f42f6997412fffe950d4833dc2ad88ecf28
Diffstat (limited to 'ironic/conductor/task_manager.py')
-rw-r--r--ironic/conductor/task_manager.py15
1 files changed, 8 insertions, 7 deletions
diff --git a/ironic/conductor/task_manager.py b/ironic/conductor/task_manager.py
index 8d702d761..2edcabf70 100644
--- a/ironic/conductor/task_manager.py
+++ b/ironic/conductor/task_manager.py
@@ -95,11 +95,11 @@ raised in the background thread.):
"""
import functools
-import time
from oslo_config import cfg
from oslo_log import log as logging
from oslo_utils import excutils
+from oslo_utils import timeutils
import retrying
from ironic.common import driver_factory
@@ -193,6 +193,7 @@ class TaskManager(object):
self.fsm = states.machine.copy()
self._purpose = purpose
+ self._debug_timer = timeutils.StopWatch()
try:
LOG.debug("Attempting to get %(type)s lock on node %(node)s (for "
@@ -202,7 +203,7 @@ class TaskManager(object):
if not self.shared:
self._lock()
else:
- self._debug_timer = time.time()
+ self._debug_timer.restart()
self.node = objects.Node.get(context, node_id)
self.ports = objects.Port.list_by_node_id(context, self.node.id)
self.driver = driver_factory.get_driver(driver_name or
@@ -221,7 +222,7 @@ class TaskManager(object):
self.release_resources()
def _lock(self):
- self._debug_timer = time.time()
+ self._debug_timer.restart()
# NodeLocked exceptions can be annoying. Let's try to alleviate
# some of that pain by retrying our lock attempts. The retrying
@@ -236,8 +237,8 @@ class TaskManager(object):
LOG.debug("Node %(node)s successfully reserved for %(purpose)s "
"(took %(time).2f seconds)",
{'node': self.node_id, 'purpose': self._purpose,
- 'time': time.time() - self._debug_timer})
- self._debug_timer = time.time()
+ 'time': self._debug_timer.elapsed()})
+ self._debug_timer.restart()
reserve_node()
@@ -252,7 +253,7 @@ class TaskManager(object):
'to an exclusive one (shared lock was held %(time).2f '
'seconds)',
{'uuid': self.node.uuid, 'purpose': self._purpose,
- 'time': time.time() - self._debug_timer})
+ 'time': self._debug_timer.elapsed()})
self._lock()
self.shared = False
@@ -308,7 +309,7 @@ class TaskManager(object):
"on node %(node)s (lock was held %(time).2f sec)",
{'type': 'shared' if self.shared else 'exclusive',
'purpose': self._purpose, 'node': self.node.uuid,
- 'time': time.time() - self._debug_timer})
+ 'time': self._debug_timer.elapsed()})
self.node = None
self.driver = None
self.ports = None