]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Use loopingcall from openstack-common
authorEric Harney <eharney@redhat.com>
Fri, 3 Jan 2014 22:24:47 +0000 (17:24 -0500)
committerGerrit Code Review <review@openstack.org>
Thu, 16 Jan 2014 05:23:46 +0000 (05:23 +0000)
This removes cinder.utils.LoopingCall and uses the copy in
openstack-common instead.

Change-Id: Id76b89797dffcc65fbf37fd1442f221ff5bb4668

cinder/service.py
cinder/utils.py

index ea21cd4eba284f781922db7dc8eaab00750e4d63..5e8b20b9583970f5decaac84c0bd14ee60c3fe1d 100644 (file)
@@ -35,8 +35,8 @@ from cinder import db
 from cinder import exception
 from cinder.openstack.common import importutils
 from cinder.openstack.common import log as logging
+from cinder.openstack.common import loopingcall
 from cinder.openstack.common import rpc
-from cinder import utils
 from cinder import version
 from cinder import wsgi
 
@@ -386,7 +386,7 @@ class Service(object):
         self.manager.init_host()
 
         if self.report_interval:
-            pulse = utils.LoopingCall(self.report_state)
+            pulse = loopingcall.LoopingCall(self.report_state)
             pulse.start(interval=self.report_interval,
                         initial_delay=self.report_interval)
             self.timers.append(pulse)
@@ -397,7 +397,7 @@ class Service(object):
             else:
                 initial_delay = None
 
-            periodic = utils.LoopingCall(self.periodic_tasks)
+            periodic = loopingcall.LoopingCall(self.periodic_tasks)
             periodic.start(interval=self.periodic_interval,
                            initial_delay=initial_delay)
             self.timers.append(periodic)
index 90c62c6b50d53b009bc34a0ca35fd3c22316cf95..707ddf5cbf276cbfd99d6223b604d0f6c2191074 100644 (file)
@@ -31,8 +31,6 @@ import stat
 import sys
 import tempfile
 
-from eventlet import event
-from eventlet import greenthread
 from eventlet import pools
 from oslo.config import cfg
 import paramiko
@@ -430,66 +428,6 @@ class LazyPluggable(object):
         return getattr(backend, key)
 
 
-class LoopingCallDone(Exception):
-    """Exception to break out and stop a LoopingCall.
-
-    The poll-function passed to LoopingCall can raise this exception to
-    break out of the loop normally. This is somewhat analogous to
-    StopIteration.
-
-    An optional return-value can be included as the argument to the exception;
-    this return-value will be returned by LoopingCall.wait()
-
-    """
-
-    def __init__(self, retvalue=True):
-        """:param retvalue: Value that LoopingCall.wait() should return."""
-        self.retvalue = retvalue
-
-
-class LoopingCall(object):
-    def __init__(self, f=None, *args, **kw):
-        self.args = args
-        self.kw = kw
-        self.f = f
-        self._running = False
-
-    def start(self, interval, initial_delay=None):
-        self._running = True
-        done = event.Event()
-
-        def _inner():
-            if initial_delay:
-                greenthread.sleep(initial_delay)
-
-            try:
-                while self._running:
-                    self.f(*self.args, **self.kw)
-                    if not self._running:
-                        break
-                    greenthread.sleep(interval)
-            except LoopingCallDone as e:
-                self.stop()
-                done.send(e.retvalue)
-            except Exception:
-                LOG.exception(_('in looping call'))
-                done.send_exception(*sys.exc_info())
-                return
-            else:
-                done.send(True)
-
-        self.done = done
-
-        greenthread.spawn(_inner)
-        return self.done
-
-    def stop(self):
-        self._running = False
-
-    def wait(self):
-        return self.done.wait()
-
-
 class ProtectedExpatParser(expatreader.ExpatParser):
     """An expat parser which disables DTD's and entities by default."""