This is to avoid service module dependency on importutils that are now
moved to oslo.utils.
The following changes are included:
* neutron/openstack/common/eventlet_backdoor.py
5d40e14 Remove code that moved to oslo.i18n
90ae24b Remove redundant default=None for config options
fcf517d Update oslo log messages with translation domains
* neutron/openstack/common/loopingcall.py
5d40e14 Remove code that moved to oslo.i18n
e377393 Changes calcuation of variable delay
ab5d5f1 Use timestamp in loopingcall
bc48099 Log the function name of looping call
fb4e863 Remove deprecated LoopingCall
fcf517d Update oslo log messages with translation domains
* neutron/openstack/common/service.py
5d40e14 Remove code that moved to oslo.i18n
6ede600 rpc, notifier: remove deprecated modules
* neutron/openstack/common/systemd.py
17c4e21 Fix docstring indentation in systemd
* neutron/openstack/common/threadgroup.py
5a1a016 Make stop_timers() method public
fdc8883 Add graceful stop function to ThreadGroup.stop
2d06d6c Simple typo correction
4d18b57 threadgroup: use threading rather than greenthread
Change-Id: I4887545f861a93223e2c7cbcdd39efe991bff547
import greenlet
from oslo.config import cfg
-from neutron.openstack.common.gettextutils import _
+from neutron.openstack.common._i18n import _LI
from neutron.openstack.common import log as logging
help_for_backdoor_port = (
"chosen port is displayed in the service's log file.")
eventlet_backdoor_opts = [
cfg.StrOpt('backdoor_port',
- default=None,
help="Enable eventlet backdoor. %s" % help_for_backdoor_port)
]
# In the case of backdoor port being zero, a port number is assigned by
# listen(). In any case, pull the port number out here.
port = sock.getsockname()[1]
- LOG.info(_('Eventlet backdoor listening on %(port)s for process %(pid)d') %
- {'port': port, 'pid': os.getpid()})
+ LOG.info(
+ _LI('Eventlet backdoor listening on %(port)s for process %(pid)d') %
+ {'port': port, 'pid': os.getpid()}
+ )
eventlet.spawn_n(eventlet.backdoor.backdoor_server, sock,
locals=backdoor_locals)
return port
# under the License.
import sys
+import time
from eventlet import event
from eventlet import greenthread
-from neutron.openstack.common.gettextutils import _
+from neutron.openstack.common._i18n import _LE, _LW
from neutron.openstack.common import log as logging
-from neutron.openstack.common import timeutils
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 LoopingCall.
+ """Exception to break out and stop a LoopingCallBase.
- The poll-function passed to LoopingCall can raise this exception to
+ 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 LoopingCall.wait()
+ this return-value will be returned by LoopingCallBase.wait()
"""
def __init__(self, retvalue=True):
- """:param retvalue: Value that LoopingCall.wait() should return."""
+ """:param retvalue: Value that LoopingCallBase.wait() should return."""
self.retvalue = retvalue
try:
while self._running:
- start = timeutils.utcnow()
+ start = _ts()
self.f(*self.args, **self.kw)
- end = timeutils.utcnow()
+ end = _ts()
if not self._running:
break
- delay = interval - timeutils.delta_seconds(start, end)
- if delay <= 0:
- LOG.warn(_('task run outlasted interval by %s sec') %
- -delay)
- greenthread.sleep(delay if delay > 0 else 0)
+ delay = end - start - interval
+ if delay > 0:
+ LOG.warn(_LW('task %(func_name)s run outlasted '
+ 'interval by %(delay).2f sec'),
+ {'func_name': repr(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(_('in fixed duration looping call'))
+ LOG.exception(_LE('in fixed duration looping call'))
done.send_exception(*sys.exc_info())
return
else:
return self.done
-# TODO(mikal): this class name is deprecated in Havana and should be removed
-# in the I release
-LoopingCall = FixedIntervalLoopingCall
-
-
class DynamicLoopingCall(LoopingCallBase):
"""A looping call which sleeps until the next known event.
if periodic_interval_max is not None:
idle = min(idle, periodic_interval_max)
- LOG.debug(_('Dynamic looping call sleeping for %.02f '
- 'seconds'), idle)
+ LOG.debug('Dynamic looping call %(func_name)s sleeping '
+ 'for %(idle).02f seconds',
+ {'func_name': repr(self.f), 'idle': idle})
greenthread.sleep(idle)
except LoopingCallDone as e:
self.stop()
done.send(e.retvalue)
except Exception:
- LOG.exception(_('in dynamic looping call'))
+ LOG.exception(_LE('in dynamic looping call'))
done.send_exception(*sys.exc_info())
return
else:
from oslo.config import cfg
from neutron.openstack.common import eventlet_backdoor
-from neutron.openstack.common.gettextutils import _LE, _LI, _LW
-from neutron.openstack.common import importutils
+from neutron.openstack.common._i18n import _LE, _LI, _LW
from neutron.openstack.common import log as logging
from neutron.openstack.common import systemd
from neutron.openstack.common import threadgroup
-rpc = importutils.try_import('neutron.openstack.common.rpc')
CONF = cfg.CONF
LOG = logging.getLogger(__name__)
status = exc.code
finally:
self.stop()
- if rpc:
- try:
- rpc.cleanup()
- except Exception:
- # We're shutting down, so it doesn't matter at this point.
- LOG.exception(_LE('Exception during rpc cleanup.'))
return status, signo
def notify():
"""Send notification to Systemd that service is ready.
+
For details see
- http://www.freedesktop.org/software/systemd/man/sd_notify.html
+ http://www.freedesktop.org/software/systemd/man/sd_notify.html
"""
_sd_notify(False, 'READY=1')
def notify_once():
"""Send notification once to Systemd that service is ready.
+
Systemd sets NOTIFY_SOCKET environment variable with the name of the
socket listening for notifications from services.
This method removes the NOTIFY_SOCKET environment variable to ensure
# 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 threading
import eventlet
from eventlet import greenpool
-from eventlet import greenthread
from neutron.openstack.common import log as logging
from neutron.openstack.common import loopingcall
class ThreadGroup(object):
- """The point of the ThreadGroup classis to:
+ """The point of the ThreadGroup class is to:
* keep track of timers and greenthreads (making it easier to stop them
when need be).
def thread_done(self, thread):
self.threads.remove(thread)
- def stop(self):
- current = greenthread.getcurrent()
+ def _stop_threads(self):
+ current = threading.current_thread()
# Iterate over a copy of self.threads so thread_done doesn't
# modify the list while we're iterating
except Exception as ex:
LOG.exception(ex)
+ def stop_timers(self):
for x in self.timers:
try:
x.stop()
LOG.exception(ex)
self.timers = []
+ def stop(self, graceful=False):
+ """stop function has the option of graceful=True/False.
+
+ * In case of graceful=True, wait for all threads to be finished.
+ Never kill threads.
+ * In case of graceful=False, kill threads immediately.
+ """
+ self.stop_timers()
+ if graceful:
+ # In case of graceful=True, wait for all threads to be
+ # finished, never kill threads
+ self.wait()
+ else:
+ # In case of graceful=False(Default), kill threads
+ # immediately
+ self._stop_threads()
+
def wait(self):
for x in self.timers:
try:
pass
except Exception as ex:
LOG.exception(ex)
- current = greenthread.getcurrent()
+ current = threading.current_thread()
# Iterate over a copy of self.threads so thread_done doesn't
# modify the list while we're iterating