Merge "Make use of oslo_service for loopingcall"

This commit is contained in:
Jenkins 2015-07-07 18:17:51 +00:00 committed by Gerrit Code Review
commit 2380fa25a8
42 changed files with 39 additions and 237 deletions

View File

@ -1,6 +0,0 @@
[DEFAULT]
# The list of modules to copy from oslo-incubator.git
module=loopingcall
# The base module to hold the copy of openstack.common
base=vmware_nsx

View File

@ -16,6 +16,7 @@ oslo.db>=1.12.0 # Apache-2.0
oslo.i18n>=1.5.0 # Apache-2.0
oslo.log>=1.2.0 # Apache-2.0
oslo.serialization>=1.4.0 # Apache-2.0
oslo.service>=0.1.0 # Apache-2.0
oslo.utils>=1.6.0 # Apache-2.0
oslo.vmware>=0.13.1 # Apache-2.0
tooz>=0.16.0 # Apache-2.0

View File

@ -82,5 +82,5 @@ commands =
pylint --rcfile=.pylintrc --output-format=colorized {posargs:vmware_nsx/neutron}
[hacking]
import_exceptions = vmware_nsx.openstack.common._i18n
import_exceptions = neutron.i18n
local-check-factory = neutron.hacking.checks.factory

View File

@ -22,8 +22,8 @@ import time
from oslo_config import cfg
from oslo_log import log as logging
from neutron.i18n import _LE, _LI, _LW
from vmware_nsx.neutron.plugins.vmware import api_client
from vmware_nsx.openstack.common._i18n import _LE, _LI, _LW
LOG = logging.getLogger(__name__)

View File

@ -19,12 +19,12 @@ import httplib
from oslo_log import log as logging
from neutron.i18n import _LE
from vmware_nsx.neutron.plugins.vmware.api_client import base
from vmware_nsx.neutron.plugins.vmware.api_client import eventlet_client
from vmware_nsx.neutron.plugins.vmware.api_client import eventlet_request
from vmware_nsx.neutron.plugins.vmware.api_client import exception
from vmware_nsx.neutron.plugins.vmware.api_client import version
from vmware_nsx.openstack.common._i18n import _LE
LOG = logging.getLogger(__name__)

View File

@ -21,9 +21,9 @@ import eventlet
eventlet.monkey_patch()
from oslo_log import log as logging
from neutron.i18n import _LE
from vmware_nsx.neutron.plugins.vmware.api_client import base
from vmware_nsx.neutron.plugins.vmware.api_client import eventlet_request
from vmware_nsx.openstack.common._i18n import _LE
LOG = logging.getLogger(__name__)

View File

@ -21,8 +21,8 @@ import eventlet
from oslo_log import log as logging
from oslo_serialization import jsonutils
from neutron.i18n import _LI, _LW
from vmware_nsx.neutron.plugins.vmware.api_client import request
from vmware_nsx.openstack.common._i18n import _LI, _LW
LOG = logging.getLogger(__name__)
USER_AGENT = "Neutron eventlet client/2.0"

View File

@ -26,8 +26,8 @@ from oslo_utils import excutils
import six
import six.moves.urllib.parse as urlparse
from neutron.i18n import _LI, _LW
from vmware_nsx.neutron.plugins.vmware import api_client
from vmware_nsx.openstack.common._i18n import _LI, _LW
LOG = logging.getLogger(__name__)

View File

@ -17,7 +17,7 @@
from oslo_log import log as logging
from vmware_nsx.openstack.common._i18n import _LW
from neutron.i18n import _LW
LOG = logging.getLogger(__name__)

View File

@ -16,8 +16,8 @@ import logging
from oslo_config import cfg
from neutron.i18n import _LW
from vmware_nsx.neutron.plugins.vmware.common import exceptions as nsx_exc
from vmware_nsx.openstack.common._i18n import _LW
LOG = logging.getLogger(__name__)

View File

@ -17,6 +17,7 @@ from neutron.api.v2 import attributes as attr
from neutron.common import exceptions as n_exc
from neutron.extensions import multiprovidernet as mpnet
from neutron.extensions import providernet as pnet
from neutron.i18n import _LW
from oslo_log import log
import six
@ -30,7 +31,6 @@ from vmware_nsx.neutron.plugins.vmware.nsxlib import l2gateway as l2gwlib
from vmware_nsx.neutron.plugins.vmware.nsxlib import router as routerlib
from vmware_nsx.neutron.plugins.vmware.nsxlib import secgroup as secgrouplib
from vmware_nsx.neutron.plugins.vmware.nsxlib import switch as switchlib
from vmware_nsx.openstack.common._i18n import _LW
LOG = log.getLogger(__name__)

View File

@ -17,6 +17,7 @@ import random
from oslo_log import log
from oslo_serialization import jsonutils
from oslo_service import loopingcall
from oslo_utils import timeutils
import six
@ -27,6 +28,7 @@ from neutron.db import external_net_db
from neutron.db import l3_db
from neutron.db import models_v2
from neutron.extensions import l3
from neutron.i18n import _LE, _LI, _LW
from vmware_nsx.neutron.plugins.vmware.api_client import exception as api_exc
from vmware_nsx.neutron.plugins.vmware.common import exceptions as nsx_exc
@ -34,8 +36,6 @@ from vmware_nsx.neutron.plugins.vmware.common import nsx_utils
from vmware_nsx.neutron.plugins.vmware import nsxlib
from vmware_nsx.neutron.plugins.vmware.nsxlib import router as routerlib
from vmware_nsx.neutron.plugins.vmware.nsxlib import switch as switchlib
from vmware_nsx.openstack.common._i18n import _LE, _LI, _LW
from vmware_nsx.openstack.common import loopingcall
# Maximum page size for a single request
# NOTE(salv-orlando): This might become a version-dependent map should the

View File

@ -23,10 +23,10 @@ import six
from sqlalchemy.orm import exc
from sqlalchemy.sql import expression as expr
from neutron.i18n import _, _LE
from vmware_nsx.neutron.plugins.vmware.common import exceptions as nsx_exc
from vmware_nsx.neutron.plugins.vmware.common import nsxv_constants
from vmware_nsx.neutron.plugins.vmware.vshield.common import constants
from vmware_nsx.openstack.common._i18n import _, _LE
LOG = logging.getLogger(__name__)

View File

@ -23,7 +23,7 @@ from neutron.plugins.vmware.extensions import qos
from oslo_log import log
from oslo_utils import uuidutils
from vmware_nsx.openstack.common._i18n import _LI
from neutron.i18n import _LI
LOG = log.getLogger(__name__)

View File

@ -21,6 +21,7 @@ from oslo_db import exception as db_exc
from oslo_log import log as logging
from oslo_utils import excutils
from neutron.i18n import _LE, _LW
from vmware_nsx.neutron.plugins.vmware.api_client import exception as api_exc
from vmware_nsx.neutron.plugins.vmware.common import exceptions as p_exc
from vmware_nsx.neutron.plugins.vmware.common import nsx_utils
@ -28,7 +29,6 @@ from vmware_nsx.neutron.plugins.vmware.dbexts import lsn_db
from vmware_nsx.neutron.plugins.vmware.dhcp_meta import constants as const
from vmware_nsx.neutron.plugins.vmware.nsxlib import lsn as lsn_api
from vmware_nsx.neutron.plugins.vmware.nsxlib import switch as switch_api
from vmware_nsx.openstack.common._i18n import _LE, _LW
LOG = logging.getLogger(__name__)

View File

@ -20,10 +20,10 @@ from neutron.common import exceptions as n_exc
from neutron.extensions import external_net
from oslo_log import log as logging
from neutron.i18n import _LE
from vmware_nsx.neutron.plugins.vmware.common import exceptions as p_exc
from vmware_nsx.neutron.plugins.vmware.dhcp_meta import nsx
from vmware_nsx.neutron.plugins.vmware.dhcp_meta import rpc
from vmware_nsx.openstack.common._i18n import _LE
LOG = logging.getLogger(__name__)

View File

@ -25,7 +25,7 @@ from neutron.common import exceptions as n_exc
from neutron.db import db_base_plugin_v2
from neutron.db import l3_db
from neutron.extensions import external_net
from vmware_nsx.openstack.common._i18n import _LE, _LI
from neutron.i18n import _LE, _LI
from vmware_nsx.neutron.plugins.vmware.common import exceptions as p_exc
from vmware_nsx.neutron.plugins.vmware.dhcp_meta import constants as d_const
from vmware_nsx.neutron.plugins.vmware.nsxlib import lsn as lsn_api

View File

@ -25,7 +25,7 @@ from neutron.common import constants as const
from neutron.common import exceptions as ntn_exc
from neutron.db import db_base_plugin_v2
from neutron.db import models_v2
from vmware_nsx.openstack.common._i18n import _LE, _LI, _LW
from neutron.i18n import _LE, _LI, _LW
from vmware_nsx.neutron.plugins.vmware.api_client import exception as api_exc
from vmware_nsx.neutron.plugins.vmware.common import config
from vmware_nsx.neutron.plugins.vmware.common import exceptions as nsx_exc

View File

@ -27,6 +27,7 @@ from neutron.common import constants as const
from neutron.common import rpc as n_rpc
from neutron.common import topics
from neutron.db import agents_db
from neutron.i18n import _LW
from neutron.plugins.vmware.extensions import lsn
from vmware_nsx.neutron.plugins.vmware.common import config
@ -36,7 +37,6 @@ from vmware_nsx.neutron.plugins.vmware.dhcp_meta import lsnmanager
from vmware_nsx.neutron.plugins.vmware.dhcp_meta import migration
from vmware_nsx.neutron.plugins.vmware.dhcp_meta import nsx as nsx_svc
from vmware_nsx.neutron.plugins.vmware.dhcp_meta import rpc as nsx_rpc
from vmware_nsx.openstack.common._i18n import _LW
LOG = logging.getLogger(__name__)

View File

@ -17,9 +17,9 @@ from oslo_log import log as logging
from oslo_utils import excutils
from oslo_vmware import vim_util
from neutron.i18n import _LE, _LI
from vmware_nsx.neutron.plugins.vmware.common import exceptions as nsx_exc
from vmware_nsx.neutron.plugins.vmware.dvs import dvs_utils
from vmware_nsx.openstack.common._i18n import _LE, _LI
LOG = logging.getLogger(__name__)

View File

@ -17,8 +17,8 @@ from oslo_config import cfg
from oslo_log import log as logging
import six
from neutron.i18n import _LI
from vmware_nsx.neutron.plugins.vmware.common import exceptions
from vmware_nsx.openstack.common._i18n import _LI
LOG = logging.getLogger(__name__)
DEFAULT_PORT = 443

View File

@ -20,13 +20,13 @@ from oslo_serialization import jsonutils
from oslo_utils import excutils
import six
from neutron.i18n import _LE, _LI, _LW
from vmware_nsx.neutron.plugins.vmware.api_client import exception as api_exc
from vmware_nsx.neutron.plugins.vmware.common import exceptions as nsx_exc
from vmware_nsx.neutron.plugins.vmware.common import utils
from vmware_nsx.neutron.plugins.vmware import nsxlib
from vmware_nsx.neutron.plugins.vmware.nsxlib import switch
from vmware_nsx.neutron.plugins.vmware.nsxlib import versioning
from vmware_nsx.openstack.common._i18n import _LE, _LI, _LW
# @versioning.versioned decorator makes the apparent function body
# totally unrelated to the real function. This confuses pylint :(

View File

@ -19,10 +19,10 @@ from oslo_utils import excutils
from neutron.common import constants
from neutron.common import exceptions
from neutron.i18n import _LW
from vmware_nsx.neutron.plugins.vmware.common import utils
from vmware_nsx.neutron.plugins.vmware import nsxlib
from vmware_nsx.openstack.common._i18n import _LW
HTTP_GET = "GET"
HTTP_POST = "POST"

View File

@ -20,12 +20,12 @@ from oslo_serialization import jsonutils
from neutron.common import constants
from neutron.common import exceptions as exception
from neutron.i18n import _LE, _LI, _LW
from vmware_nsx.neutron.plugins.vmware.api_client import exception as api_exc
from vmware_nsx.neutron.plugins.vmware.common import exceptions as nsx_exc
from vmware_nsx.neutron.plugins.vmware.common import utils
from vmware_nsx.neutron.plugins.vmware import nsxlib
from vmware_nsx.openstack.common._i18n import _LE, _LI, _LW
HTTP_GET = "GET"
HTTP_POST = "POST"

View File

@ -19,9 +19,9 @@ from oslo_serialization import jsonutils
import requests
from requests import auth
from neutron.i18n import _LI, _LW
from vmware_nsx.neutron.plugins.vmware.common import exceptions as nsx_exc
from vmware_nsx.neutron.plugins.vmware.common import nsx_constants
from vmware_nsx.openstack.common._i18n import _LI, _LW
LOG = log.getLogger(__name__)

View File

@ -53,6 +53,7 @@ from neutron.extensions import portbindings as pbin
from neutron.extensions import portsecurity as psec
from neutron.extensions import providernet as pnet
from neutron.extensions import securitygroup as ext_sg
from neutron.i18n import _LE, _LI, _LW
from neutron.plugins.common import constants as plugin_const
from neutron.plugins.common import utils
from neutron.plugins.vmware.dbexts import nsx_models
@ -78,7 +79,6 @@ from vmware_nsx.neutron.plugins.vmware.nsxlib import queue as queuelib
from vmware_nsx.neutron.plugins.vmware.nsxlib import router as routerlib
from vmware_nsx.neutron.plugins.vmware.nsxlib import secgroup as secgrouplib
from vmware_nsx.neutron.plugins.vmware.nsxlib import switch as switchlib
from vmware_nsx.openstack.common._i18n import _LE, _LI, _LW
LOG = logging.getLogger(__name__)

View File

@ -35,6 +35,7 @@ from neutron.extensions import portbindings as pbin
from neutron.extensions import portsecurity as psec
from neutron.extensions import providernet as pnet
from neutron.extensions import securitygroup as ext_sg
from neutron.i18n import _LE, _LW
from neutron.plugins.common import constants
from neutron.plugins.common import utils
@ -46,7 +47,6 @@ from vmware_nsx.neutron.plugins.vmware.dbexts import db as nsx_db
from vmware_nsx.neutron.plugins.vmware import dhcpmeta_modes
from vmware_nsx.neutron.plugins.vmware.dvs import dvs
from vmware_nsx.neutron.plugins.vmware.dvs import dvs_utils
from vmware_nsx.openstack.common._i18n import _LE, _LW
LOG = logging.getLogger(__name__)

View File

@ -18,8 +18,8 @@ import stevedore
from oslo_log import log
from neutron.i18n import _LE, _LI
from vmware_nsx.neutron.plugins.vmware.common import exceptions as nsx_exc
from vmware_nsx.openstack.common._i18n import _LE, _LI
LOG = log.getLogger(__name__)
ROUTER_TYPE_DRIVERS = ["distributed", "exclusive", "shared"]

View File

@ -46,6 +46,7 @@ from neutron.extensions import portbindings as pbin
from neutron.extensions import portsecurity as psec
from neutron.extensions import providernet as pnet
from neutron.extensions import securitygroup as ext_sg
from neutron.i18n import _LE, _LI, _LW
from neutron.plugins.common import constants as plugin_const
from neutron.plugins.common import utils
from neutron.plugins.vmware.extensions import (
@ -72,7 +73,6 @@ from vmware_nsx.neutron.plugins.vmware.vshield.common import (
from vmware_nsx.neutron.plugins.vmware.vshield import edge_utils
from vmware_nsx.neutron.plugins.vmware.vshield import securitygroup_utils
from vmware_nsx.neutron.plugins.vmware.vshield import vcns_driver
from vmware_nsx.openstack.common._i18n import _LE, _LI, _LW
LOG = logging.getLogger(__name__)
PORTGROUP_PREFIX = 'dvportgroup'

View File

@ -36,13 +36,13 @@ from neutron.db import l3_db
from neutron.db import models_v2
from neutron.db import portbindings_db
from neutron.db import securitygroups_db
from neutron.i18n import _LW
from vmware_nsx.neutron.plugins.vmware.common import config # noqa
from vmware_nsx.neutron.plugins.vmware.common import exceptions as nsx_exc
from vmware_nsx.neutron.plugins.vmware.common import utils
from vmware_nsx.neutron.plugins.vmware.dbexts import db as nsx_db
from vmware_nsx.neutron.plugins.vmware.nsxlib import v3 as nsxlib
from vmware_nsx.openstack.common._i18n import _LW
LOG = log.getLogger(__name__)

View File

@ -25,6 +25,7 @@ from oslo_config import cfg
from oslo_log import log as logging
from oslo_utils import excutils
from neutron.i18n import _LE
from vmware_nsx.neutron.plugins.vmware.common import exceptions as nsxv_exc
from vmware_nsx.neutron.plugins.vmware.common import locking
from vmware_nsx.neutron.plugins.vmware.common import nsxv_constants
@ -34,7 +35,6 @@ from vmware_nsx.neutron.plugins.vmware.vshield import (
from vmware_nsx.neutron.plugins.vmware.vshield.common import (
constants as vcns_const)
from vmware_nsx.neutron.plugins.vmware.vshield import edge_utils
from vmware_nsx.openstack.common._i18n import _LE
METADATA_IP_ADDR = '169.254.169.254'
METADATA_TCP_PORT = 80

View File

@ -21,6 +21,7 @@ from oslo_log import log as logging
from oslo_serialization import jsonutils
from oslo_utils import excutils
from neutron.i18n import _LE, _LI, _LW
from vmware_nsx.neutron.plugins.vmware.common import nsxv_constants
from vmware_nsx.neutron.plugins.vmware.common import utils
from vmware_nsx.neutron.plugins.vmware.vshield.common import constants
@ -28,7 +29,6 @@ from vmware_nsx.neutron.plugins.vmware.vshield.common import exceptions
from vmware_nsx.neutron.plugins.vmware.vshield.tasks import (
constants as task_constants)
from vmware_nsx.neutron.plugins.vmware.vshield.tasks import tasks
from vmware_nsx.openstack.common._i18n import _LE, _LI, _LW
LOG = logging.getLogger(__name__)

View File

@ -16,13 +16,13 @@ from neutron.db import db_base_plugin_v2
from oslo_log import log as logging
from oslo_utils import excutils
from neutron.i18n import _, _LE
from vmware_nsx.neutron.plugins.vmware.dbexts import nsxv_db
from vmware_nsx.neutron.plugins.vmware.vshield.common import (
exceptions as vcns_exc)
from vmware_nsx.neutron.plugins.vmware.vshield.tasks import (
constants as task_const)
from vmware_nsx.neutron.plugins.vmware.vshield.tasks import tasks
from vmware_nsx.openstack.common._i18n import _, _LE
LOG = logging.getLogger(__name__)

View File

@ -15,9 +15,9 @@
from oslo_log import log as logging
from oslo_utils import excutils
from neutron.i18n import _LE, _LW
from vmware_nsx.neutron.plugins.vmware.vshield.common import (
exceptions as vcns_exc)
from vmware_nsx.openstack.common._i18n import _LE, _LW
LOG = logging.getLogger(__name__)

View File

@ -19,13 +19,13 @@ import netaddr
from oslo_log import log as logging
from oslo_utils import excutils
from neutron.i18n import _LE
from neutron import manager
from neutron.plugins.common import constants
from vmware_nsx.neutron.plugins.vmware.dbexts import nsxv_db
from vmware_nsx.neutron.plugins.vmware.vshield.common import (
exceptions as nsxv_exc)
from vmware_nsx.neutron.plugins.vmware.vshield import vcns as nsxv_api
from vmware_nsx.openstack.common._i18n import _LE
# TODO(kobis): protect in nsx_v.py against detaching of interface while

View File

@ -28,6 +28,7 @@ from sqlalchemy.orm import exc as sa_exc
from neutron.common import exceptions as n_exc
from neutron import context as q_context
from neutron.extensions import l3
from neutron.i18n import _LE, _LW
from neutron.plugins.common import constants as plugin_const
from vmware_nsx.neutron.plugins.vmware.common import locking
@ -39,7 +40,6 @@ from vmware_nsx.neutron.plugins.vmware.vshield.common import (
from vmware_nsx.neutron.plugins.vmware.vshield.tasks import (
constants as task_const)
from vmware_nsx.neutron.plugins.vmware.vshield.tasks import tasks
from vmware_nsx.openstack.common._i18n import _LE, _LW
from vmware_nsx.neutron.plugins.vmware.vshield import vcns
WORKER_POOL_SIZE = 8

View File

@ -20,11 +20,11 @@ from eventlet import event
from eventlet import greenthread
from neutron.common import exceptions
from oslo_log import log as logging
from oslo_service import loopingcall
import six
from neutron.i18n import _LE, _LI
from vmware_nsx.neutron.plugins.vmware.vshield.tasks import constants
from vmware_nsx.openstack.common._i18n import _LE, _LI
from vmware_nsx.openstack.common import loopingcall
DEFAULT_INTERVAL = 1000

View File

@ -18,16 +18,15 @@ import random
import eventlet
from eventlet.green import urllib2
import mock
from neutron.i18n import _LI
from neutron.tests import base
from oslo_log import log as logging
from vmware_nsx.neutron.plugins.vmware.api_client import (
eventlet_client as client)
from vmware_nsx.neutron.plugins.vmware.api_client import (
eventlet_request as request)
from vmware_nsx.neutron.tests.unit import vmware
from vmware_nsx.openstack.common._i18n import _LI
LOG = logging.getLogger(__name__)

View File

@ -1,45 +0,0 @@
# 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.
"""oslo.i18n integration module.
See http://docs.openstack.org/developer/oslo.i18n/usage.html
"""
try:
import oslo_i18n
# NOTE(dhellmann): This reference to o-s-l-o will be replaced by the
# application name when this module is synced into the separate
# repository. It is OK to have more than one translation function
# using the same domain, since there will still only be one message
# catalog.
_translators = oslo_i18n.TranslatorFactory(domain='vmware_nsx')
# The primary translation function using the well-known name "_"
_ = _translators.primary
# Translators for log levels.
#
# The abbreviated names are meant to reflect the usual use of a short
# name like '_'. The "L" is for "log" and the other letter comes from
# the level.
_LI = _translators.log_info
_LW = _translators.log_warning
_LE = _translators.log_error
_LC = _translators.log_critical
except ImportError:
# NOTE(dims): Support for cases where a project wants to use
# code from oslo-incubator, but is not ready to be internationalized
# (like tempest)
_ = _LI = _LW = _LE = _LC = lambda x: x

View File

@ -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 vmware_nsx.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