From f783d009bac32dc5d36ea6b357e93b720342ac82 Mon Sep 17 00:00:00 2001 From: Thomas Bechtold Date: Wed, 17 Jun 2015 22:41:12 +0200 Subject: [PATCH] Use loopingcall from oslo.service oslo.service replaces the loopingcall code from oslo-incubator so switch to the new oslo.service module. Change-Id: Iba8a86cc79f8bbda4b04c71568dd9a33f4ace6f6 --- manila/openstack/common/loopingcall.py | 147 ------------------ manila/service.py | 2 +- .../netapp/dataontap/cluster_mode/lib_base.py | 2 +- .../dataontap/cluster_mode/test_lib_base.py | 2 +- openstack-common.conf | 1 - requirements.txt | 1 + 6 files changed, 4 insertions(+), 151 deletions(-) delete mode 100644 manila/openstack/common/loopingcall.py diff --git a/manila/openstack/common/loopingcall.py b/manila/openstack/common/loopingcall.py deleted file mode 100644 index f67743f7..00000000 --- a/manila/openstack/common/loopingcall.py +++ /dev/null @@ -1,147 +0,0 @@ -# Copyright 2010 United States Government as represented by the -# Administrator of the National Aeronautics and Space Administration. -# Copyright 2011 Justin Santa Barbara -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import logging -import sys -import time - -from eventlet import event -from eventlet import greenthread - -from manila.openstack.common._i18n import _LE, _LW - -LOG = logging.getLogger(__name__) - -# NOTE(zyluo): This lambda function was declared to avoid mocking collisions -# with time.time() called in the standard logging module -# during unittests. -_ts = lambda: time.time() - - -class LoopingCallDone(Exception): - """Exception to break out and stop a LoopingCallBase. - - The poll-function passed to LoopingCallBase 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 LoopingCallBase.wait() - - """ - - def __init__(self, retvalue=True): - """:param retvalue: Value that LoopingCallBase.wait() should return.""" - self.retvalue = retvalue - - -class LoopingCallBase(object): - def __init__(self, f=None, *args, **kw): - self.args = args - self.kw = kw - self.f = f - self._running = False - self.done = None - - def stop(self): - self._running = False - - def wait(self): - return self.done.wait() - - -class FixedIntervalLoopingCall(LoopingCallBase): - """A fixed interval looping call.""" - - 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: - start = _ts() - self.f(*self.args, **self.kw) - end = _ts() - if not self._running: - break - delay = end - start - interval - if delay > 0: - LOG.warn(_LW('task %(func_name)r run outlasted ' - 'interval by %(delay).2f sec'), - {'func_name': self.f, 'delay': delay}) - greenthread.sleep(-delay if delay < 0 else 0) - except LoopingCallDone as e: - self.stop() - done.send(e.retvalue) - except Exception: - LOG.exception(_LE('in fixed duration looping call')) - done.send_exception(*sys.exc_info()) - return - else: - done.send(True) - - self.done = done - - greenthread.spawn_n(_inner) - return self.done - - -class DynamicLoopingCall(LoopingCallBase): - """A looping call which sleeps until the next known event. - - The function called should return how long to sleep for before being - called again. - """ - - def start(self, initial_delay=None, periodic_interval_max=None): - self._running = True - done = event.Event() - - def _inner(): - if initial_delay: - greenthread.sleep(initial_delay) - - try: - while self._running: - idle = self.f(*self.args, **self.kw) - if not self._running: - break - - if periodic_interval_max is not None: - idle = min(idle, periodic_interval_max) - LOG.debug('Dynamic looping call %(func_name)r sleeping ' - 'for %(idle).02f seconds', - {'func_name': self.f, 'idle': idle}) - greenthread.sleep(idle) - except LoopingCallDone as e: - self.stop() - done.send(e.retvalue) - except Exception: - LOG.exception(_LE('in dynamic looping call')) - done.send_exception(*sys.exc_info()) - return - else: - done.send(True) - - self.done = done - - greenthread.spawn(_inner) - return self.done diff --git a/manila/service.py b/manila/service.py index c1e890f6..6f14e572 100644 --- a/manila/service.py +++ b/manila/service.py @@ -30,6 +30,7 @@ import greenlet from oslo_config import cfg from oslo_log import log import oslo_messaging as messaging +from oslo_service import loopingcall from oslo_utils import importutils from manila import context @@ -38,7 +39,6 @@ from manila import exception from manila.i18n import _LE from manila.i18n import _LI from manila.i18n import _LW -from manila.openstack.common import loopingcall from manila import rpc from manila import version from manila import wsgi diff --git a/manila/share/drivers/netapp/dataontap/cluster_mode/lib_base.py b/manila/share/drivers/netapp/dataontap/cluster_mode/lib_base.py index 99c985c1..91262a97 100644 --- a/manila/share/drivers/netapp/dataontap/cluster_mode/lib_base.py +++ b/manila/share/drivers/netapp/dataontap/cluster_mode/lib_base.py @@ -24,12 +24,12 @@ import socket import time from oslo_log import log +from oslo_service import loopingcall from oslo_utils import units import six from manila import exception from manila.i18n import _, _LE, _LI, _LW -from manila.openstack.common import loopingcall from manila.share.drivers.netapp.dataontap.client import client_cmode from manila.share.drivers.netapp.dataontap.protocols import cifs_cmode from manila.share.drivers.netapp.dataontap.protocols import nfs_cmode diff --git a/manila/tests/share/drivers/netapp/dataontap/cluster_mode/test_lib_base.py b/manila/tests/share/drivers/netapp/dataontap/cluster_mode/test_lib_base.py index d5cbd452..9a5c0a47 100644 --- a/manila/tests/share/drivers/netapp/dataontap/cluster_mode/test_lib_base.py +++ b/manila/tests/share/drivers/netapp/dataontap/cluster_mode/test_lib_base.py @@ -23,9 +23,9 @@ import time import ddt import mock from oslo_log import log +from oslo_service import loopingcall from manila import exception -from manila.openstack.common import loopingcall from manila.share.drivers.netapp.dataontap.client import client_cmode from manila.share.drivers.netapp.dataontap.cluster_mode import lib_base from manila.share.drivers.netapp.dataontap.protocols import cifs_cmode diff --git a/openstack-common.conf b/openstack-common.conf index 5f6f042d..d51f986f 100644 --- a/openstack-common.conf +++ b/openstack-common.conf @@ -2,7 +2,6 @@ # The list of modules to copy from openstack-common module=eventlet_backdoor -module=loopingcall module=scheduler module=scheduler.filters module=scheduler.weights diff --git a/requirements.txt b/requirements.txt index 30b209a9..af508583 100644 --- a/requirements.txt +++ b/requirements.txt @@ -23,6 +23,7 @@ oslo.middleware!=2.0.0,>=1.2.0 # Apache-2.0 oslo.policy>=0.5.0 # Apache-2.0 oslo.rootwrap>=2.0.0 # Apache-2.0 oslo.serialization>=1.4.0 # Apache-2.0 +oslo.service>=0.1.0 oslo.utils>=1.6.0 # Apache-2.0 oslo.concurrency>=2.0.0 # Apache-2.0 paramiko>=1.13.0