Sync with latest oslo-incubator
Periodic sync with latest changes in oslo-incubator Change-Id: Ic61448ebda764900b01e76e78d4c6327663f9a4b
This commit is contained in:
parent
fbb958ac7c
commit
39885e89e2
|
@ -28,8 +28,8 @@ import traceback
|
||||||
|
|
||||||
import eventlet.backdoor
|
import eventlet.backdoor
|
||||||
import greenlet
|
import greenlet
|
||||||
|
from oslo_config import cfg
|
||||||
|
|
||||||
from barbican.common import config
|
|
||||||
from barbican.openstack.common._i18n import _LI
|
from barbican.openstack.common._i18n import _LI
|
||||||
|
|
||||||
help_for_backdoor_port = (
|
help_for_backdoor_port = (
|
||||||
|
@ -39,15 +39,20 @@ help_for_backdoor_port = (
|
||||||
"is in use); and <start>:<end> results in listening on the smallest "
|
"is in use); and <start>:<end> results in listening on the smallest "
|
||||||
"unused port number within the specified range of port numbers. The "
|
"unused port number within the specified range of port numbers. The "
|
||||||
"chosen port is displayed in the service's log file.")
|
"chosen port is displayed in the service's log file.")
|
||||||
|
eventlet_backdoor_opts = [
|
||||||
|
cfg.StrOpt('backdoor_port',
|
||||||
|
help="Enable eventlet backdoor. %s" % help_for_backdoor_port)
|
||||||
|
]
|
||||||
|
|
||||||
CONF = config.CONF
|
CONF = cfg.CONF
|
||||||
|
CONF.register_opts(eventlet_backdoor_opts)
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def list_opts():
|
def list_opts():
|
||||||
"""Entry point for oslo.config-generator.
|
"""Entry point for oslo-config-generator.
|
||||||
"""
|
"""
|
||||||
return [(None, copy.deepcopy(config.eventlet_backdoor_opts))]
|
return [(None, copy.deepcopy(eventlet_backdoor_opts))]
|
||||||
|
|
||||||
|
|
||||||
class EventletBackdoorConfigValueError(Exception):
|
class EventletBackdoorConfigValueError(Exception):
|
||||||
|
@ -138,7 +143,7 @@ def initialize_if_enabled():
|
||||||
# listen(). In any case, pull the port number out here.
|
# listen(). In any case, pull the port number out here.
|
||||||
port = sock.getsockname()[1]
|
port = sock.getsockname()[1]
|
||||||
LOG.info(
|
LOG.info(
|
||||||
_LI('Eventlet backdoor listening on %(port)s for process %(pid)d') %
|
_LI('Eventlet backdoor listening on %(port)s for process %(pid)d'),
|
||||||
{'port': port, 'pid': os.getpid()}
|
{'port': port, 'pid': os.getpid()}
|
||||||
)
|
)
|
||||||
eventlet.spawn_n(eventlet.backdoor.backdoor_server, sock,
|
eventlet.spawn_n(eventlet.backdoor.backdoor_server, sock,
|
||||||
|
|
|
@ -84,9 +84,9 @@ class FixedIntervalLoopingCall(LoopingCallBase):
|
||||||
break
|
break
|
||||||
delay = end - start - interval
|
delay = end - start - interval
|
||||||
if delay > 0:
|
if delay > 0:
|
||||||
LOG.warn(_LW('task %(func_name)r run outlasted '
|
LOG.warning(_LW('task %(func_name)r run outlasted '
|
||||||
'interval by %(delay).2f sec'),
|
'interval by %(delay).2f sec'),
|
||||||
{'func_name': self.f, 'delay': delay})
|
{'func_name': self.f, 'delay': delay})
|
||||||
greenthread.sleep(-delay if delay < 0 else 0)
|
greenthread.sleep(-delay if delay < 0 else 0)
|
||||||
except LoopingCallDone as e:
|
except LoopingCallDone as e:
|
||||||
self.stop()
|
self.stop()
|
||||||
|
|
|
@ -16,13 +16,21 @@ import logging
|
||||||
import random
|
import random
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
from oslo_config import cfg
|
||||||
import six
|
import six
|
||||||
|
|
||||||
from barbican.common import config
|
|
||||||
from barbican.openstack.common._i18n import _, _LE, _LI
|
from barbican.openstack.common._i18n import _, _LE, _LI
|
||||||
|
|
||||||
|
|
||||||
CONF = config.CONF
|
periodic_opts = [
|
||||||
|
cfg.BoolOpt('run_external_periodic_tasks',
|
||||||
|
default=True,
|
||||||
|
help='Some periodic tasks can be run in a separate process. '
|
||||||
|
'Should we run them here?'),
|
||||||
|
]
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
|
CONF.register_opts(periodic_opts)
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -214,11 +222,11 @@ class PeriodicTasks(object):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
task(self, context)
|
task(self, context)
|
||||||
except Exception as e:
|
except Exception:
|
||||||
if raise_on_error:
|
if raise_on_error:
|
||||||
raise
|
raise
|
||||||
LOG.exception(_LE("Error during %(full_task_name)s: %(e)s"),
|
LOG.exception(_LE("Error during %(full_task_name)s"),
|
||||||
{"full_task_name": full_task_name, "e": e})
|
{"full_task_name": full_task_name})
|
||||||
time.sleep(0)
|
time.sleep(0)
|
||||||
|
|
||||||
return idle_for
|
return idle_for
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
"""Generic Node base class for all workers that run on hosts."""
|
"""Generic Node base class for all workers that run on hosts."""
|
||||||
|
|
||||||
import errno
|
import errno
|
||||||
|
import io
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
|
@ -25,25 +26,17 @@ import signal
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
|
||||||
try:
|
|
||||||
# Importing just the symbol here because the io module does not
|
|
||||||
# exist in Python 2.6.
|
|
||||||
from io import UnsupportedOperation # noqa
|
|
||||||
except ImportError:
|
|
||||||
# Python 2.6
|
|
||||||
UnsupportedOperation = None
|
|
||||||
|
|
||||||
import eventlet
|
import eventlet
|
||||||
from eventlet import event
|
from eventlet import event
|
||||||
|
from oslo_config import cfg
|
||||||
|
|
||||||
from barbican.common import config
|
|
||||||
from barbican.openstack.common import eventlet_backdoor
|
from barbican.openstack.common import eventlet_backdoor
|
||||||
from barbican.openstack.common._i18n import _LE, _LI, _LW
|
from barbican.openstack.common._i18n import _LE, _LI, _LW
|
||||||
from barbican.openstack.common import systemd
|
from barbican.openstack.common import systemd
|
||||||
from barbican.openstack.common import threadgroup
|
from barbican.openstack.common import threadgroup
|
||||||
|
|
||||||
|
|
||||||
CONF = config.CONF
|
CONF = cfg.CONF
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@ -59,15 +52,15 @@ def _is_daemon():
|
||||||
# http://www.gnu.org/software/bash/manual/bashref.html#Job-Control-Basics
|
# http://www.gnu.org/software/bash/manual/bashref.html#Job-Control-Basics
|
||||||
try:
|
try:
|
||||||
is_daemon = os.getpgrp() != os.tcgetpgrp(sys.stdout.fileno())
|
is_daemon = os.getpgrp() != os.tcgetpgrp(sys.stdout.fileno())
|
||||||
|
except io.UnsupportedOperation:
|
||||||
|
# Could not get the fileno for stdout, so we must be a daemon.
|
||||||
|
is_daemon = True
|
||||||
except OSError as err:
|
except OSError as err:
|
||||||
if err.errno == errno.ENOTTY:
|
if err.errno == errno.ENOTTY:
|
||||||
# Assume we are a daemon because there is no terminal.
|
# Assume we are a daemon because there is no terminal.
|
||||||
is_daemon = True
|
is_daemon = True
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
except UnsupportedOperation:
|
|
||||||
# Could not get the fileno for stdout, so we must be a daemon.
|
|
||||||
is_daemon = True
|
|
||||||
return is_daemon
|
return is_daemon
|
||||||
|
|
||||||
|
|
||||||
|
@ -138,7 +131,7 @@ class Launcher(object):
|
||||||
:returns: None
|
:returns: None
|
||||||
|
|
||||||
"""
|
"""
|
||||||
config.CONF.reload_config_files()
|
cfg.CONF.reload_config_files()
|
||||||
self.services.restart()
|
self.services.restart()
|
||||||
|
|
||||||
|
|
||||||
|
@ -199,6 +192,13 @@ class ServiceWrapper(object):
|
||||||
|
|
||||||
|
|
||||||
class ProcessLauncher(object):
|
class ProcessLauncher(object):
|
||||||
|
_signal_handlers_set = set()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _handle_class_signals(cls, *args, **kwargs):
|
||||||
|
for handler in cls._signal_handlers_set:
|
||||||
|
handler(*args, **kwargs)
|
||||||
|
|
||||||
def __init__(self, wait_interval=0.01):
|
def __init__(self, wait_interval=0.01):
|
||||||
"""Constructor.
|
"""Constructor.
|
||||||
|
|
||||||
|
@ -214,7 +214,8 @@ class ProcessLauncher(object):
|
||||||
self.handle_signal()
|
self.handle_signal()
|
||||||
|
|
||||||
def handle_signal(self):
|
def handle_signal(self):
|
||||||
_set_signals_handler(self._handle_signal)
|
self._signal_handlers_set.add(self._handle_signal)
|
||||||
|
_set_signals_handler(self._handle_class_signals)
|
||||||
|
|
||||||
def _handle_signal(self, signo, frame):
|
def _handle_signal(self, signo, frame):
|
||||||
self.sigcaught = signo
|
self.sigcaught = signo
|
||||||
|
@ -226,7 +227,7 @@ class ProcessLauncher(object):
|
||||||
def _pipe_watcher(self):
|
def _pipe_watcher(self):
|
||||||
# This will block until the write end is closed when the parent
|
# This will block until the write end is closed when the parent
|
||||||
# dies unexpectedly
|
# dies unexpectedly
|
||||||
self.readpipe.read()
|
self.readpipe.read(1)
|
||||||
|
|
||||||
LOG.info(_LI('Parent process has died unexpectedly, exiting'))
|
LOG.info(_LI('Parent process has died unexpectedly, exiting'))
|
||||||
|
|
||||||
|
@ -234,15 +235,12 @@ class ProcessLauncher(object):
|
||||||
|
|
||||||
def _child_process_handle_signal(self):
|
def _child_process_handle_signal(self):
|
||||||
# Setup child signal handlers differently
|
# Setup child signal handlers differently
|
||||||
def _sigterm(*args):
|
|
||||||
signal.signal(signal.SIGTERM, signal.SIG_DFL)
|
|
||||||
raise SignalExit(signal.SIGTERM)
|
|
||||||
|
|
||||||
def _sighup(*args):
|
def _sighup(*args):
|
||||||
signal.signal(signal.SIGHUP, signal.SIG_DFL)
|
signal.signal(signal.SIGHUP, signal.SIG_DFL)
|
||||||
raise SignalExit(signal.SIGHUP)
|
raise SignalExit(signal.SIGHUP)
|
||||||
|
|
||||||
signal.signal(signal.SIGTERM, _sigterm)
|
# Parent signals with SIGTERM when it wants us to go away.
|
||||||
|
signal.signal(signal.SIGTERM, signal.SIG_DFL)
|
||||||
if _sighup_supported():
|
if _sighup_supported():
|
||||||
signal.signal(signal.SIGHUP, _sighup)
|
signal.signal(signal.SIGHUP, _sighup)
|
||||||
# Block SIGINT and let the parent send us a SIGTERM
|
# Block SIGINT and let the parent send us a SIGTERM
|
||||||
|
@ -391,8 +389,14 @@ class ProcessLauncher(object):
|
||||||
if not _is_sighup_and_daemon(self.sigcaught):
|
if not _is_sighup_and_daemon(self.sigcaught):
|
||||||
break
|
break
|
||||||
|
|
||||||
|
cfg.CONF.reload_config_files()
|
||||||
|
for service in set(
|
||||||
|
[wrap.service for wrap in self.children.values()]):
|
||||||
|
service.reset()
|
||||||
|
|
||||||
for pid in self.children:
|
for pid in self.children:
|
||||||
os.kill(pid, signal.SIGHUP)
|
os.kill(pid, signal.SIGHUP)
|
||||||
|
|
||||||
self.running = True
|
self.running = True
|
||||||
self.sigcaught = None
|
self.sigcaught = None
|
||||||
except eventlet.greenlet.GreenletExit:
|
except eventlet.greenlet.GreenletExit:
|
||||||
|
|
|
@ -17,6 +17,7 @@ import threading
|
||||||
import eventlet
|
import eventlet
|
||||||
from eventlet import greenpool
|
from eventlet import greenpool
|
||||||
|
|
||||||
|
from barbican.openstack.common._i18n import _LE
|
||||||
from barbican.openstack.common import loopingcall
|
from barbican.openstack.common import loopingcall
|
||||||
|
|
||||||
|
|
||||||
|
@ -98,15 +99,15 @@ class ThreadGroup(object):
|
||||||
x.stop()
|
x.stop()
|
||||||
except eventlet.greenlet.GreenletExit:
|
except eventlet.greenlet.GreenletExit:
|
||||||
pass
|
pass
|
||||||
except Exception as ex:
|
except Exception:
|
||||||
LOG.exception(ex)
|
LOG.exception(_LE('Error stopping thread.'))
|
||||||
|
|
||||||
def stop_timers(self):
|
def stop_timers(self):
|
||||||
for x in self.timers:
|
for x in self.timers:
|
||||||
try:
|
try:
|
||||||
x.stop()
|
x.stop()
|
||||||
except Exception as ex:
|
except Exception:
|
||||||
LOG.exception(ex)
|
LOG.exception(_LE('Error stopping timer.'))
|
||||||
self.timers = []
|
self.timers = []
|
||||||
|
|
||||||
def stop(self, graceful=False):
|
def stop(self, graceful=False):
|
||||||
|
@ -132,8 +133,8 @@ class ThreadGroup(object):
|
||||||
x.wait()
|
x.wait()
|
||||||
except eventlet.greenlet.GreenletExit:
|
except eventlet.greenlet.GreenletExit:
|
||||||
pass
|
pass
|
||||||
except Exception as ex:
|
except Exception:
|
||||||
LOG.exception(ex)
|
LOG.exception(_LE('Error waiting on ThreadGroup.'))
|
||||||
current = threading.current_thread()
|
current = threading.current_thread()
|
||||||
|
|
||||||
# Iterate over a copy of self.threads so thread_done doesn't
|
# Iterate over a copy of self.threads so thread_done doesn't
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
[DEFAULT]
|
[DEFAULT]
|
||||||
|
|
||||||
# The list of modules to copy from openstack-common
|
# The list of modules to copy from openstack-common
|
||||||
modules=local,policy,eventlet_backdoor,service,periodic_task
|
modules=eventlet_backdoor,service,periodic_task
|
||||||
|
|
||||||
# The base module to hold the copy of openstack.common
|
# The base module to hold the copy of openstack.common
|
||||||
base=barbican
|
base=barbican
|
||||||
|
|
Loading…
Reference in New Issue