Sync with oslo-incubator

o-i revision: f989c4397d7e83c3e73e8da01a9f27bf4ca38b73

Additionally, remove unused o-i modules:

* fixtures.config
* timeutils
* versionutils

Change-Id: I5a63b5ef52119da66093a9b98c1c1dbfaa59dd9a
This commit is contained in:
Kiall Mac Innes 2015-02-28 13:38:49 +00:00
parent e7fc6804dc
commit 536a3826f7
13 changed files with 40 additions and 263 deletions

View File

@ -17,14 +17,14 @@ See http://docs.openstack.org/developer/oslo.i18n/usage.html
""" """
try: try:
import oslo.i18n import oslo_i18n
# NOTE(dhellmann): This reference to o-s-l-o will be replaced by the # NOTE(dhellmann): This reference to o-s-l-o will be replaced by the
# application name when this module is synced into the separate # application name when this module is synced into the separate
# repository. It is OK to have more than one translation function # repository. It is OK to have more than one translation function
# using the same domain, since there will still only be one message # using the same domain, since there will still only be one message
# catalog. # catalog.
_translators = oslo.i18n.TranslatorFactory(domain='designate') _translators = oslo_i18n.TranslatorFactory(domain='designate')
# The primary translation function using the well-known name "_" # The primary translation function using the well-known name "_"
_ = _translators.primary _ = _translators.primary
@ -40,6 +40,6 @@ try:
_LC = _translators.log_critical _LC = _translators.log_critical
except ImportError: except ImportError:
# NOTE(dims): Support for cases where a project wants to use # NOTE(dims): Support for cases where a project wants to use
# code from designate-incubator, but is not ready to be internationalized # code from oslo-incubator, but is not ready to be internationalized
# (like tempest) # (like tempest)
_ = _LI = _LW = _LE = _LC = lambda x: x _ = _LI = _LW = _LE = _LC = lambda x: x

View File

@ -19,17 +19,16 @@ from __future__ import print_function
import copy import copy
import errno import errno
import gc import gc
import logging
import os import os
import pprint import pprint
import socket import socket
import sys import sys
import traceback import traceback
import eventlet
import eventlet.backdoor import eventlet.backdoor
import greenlet import greenlet
from oslo.config import cfg from oslo_config import cfg
from oslo_log import log as logging
from designate.openstack.common._i18n import _LI from designate.openstack.common._i18n import _LI
@ -51,7 +50,7 @@ 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(eventlet_backdoor_opts))] return [(None, copy.deepcopy(eventlet_backdoor_opts))]

View File

@ -17,22 +17,25 @@ import contextlib
import errno import errno
import logging import logging
import os import os
import stat
import tempfile import tempfile
from oslo.utils import excutils from oslo_utils import excutils
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
_FILE_CACHE = {} _FILE_CACHE = {}
DEFAULT_MODE = stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO
def ensure_tree(path): def ensure_tree(path, mode=DEFAULT_MODE):
"""Create a directory (and any ancestor directories required) """Create a directory (and any ancestor directories required)
:param path: Directory to create :param path: Directory to create
:param mode: Directory creation permissions
""" """
try: try:
os.makedirs(path) os.makedirs(path, mode)
except OSError as exc: except OSError as exc:
if exc.errno == errno.EEXIST: if exc.errno == errno.EEXIST:
if not os.path.isdir(path): if not os.path.isdir(path):

View File

@ -1,17 +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.
import six
six.add_move(six.MovedModule('mox', 'mox', 'mox3.mox'))

View File

@ -15,12 +15,12 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import logging
import sys import sys
import time import time
from eventlet import event from eventlet import event
from eventlet import greenthread from eventlet import greenthread
from oslo_log import log as logging
from designate.openstack.common._i18n import _LE, _LW from designate.openstack.common._i18n import _LE, _LW
@ -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)s run outlasted ' LOG.warn(_LW('task %(func_name)r run outlasted '
'interval by %(delay).2f sec'), 'interval by %(delay).2f sec'),
{'func_name': repr(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()
@ -127,9 +127,9 @@ class DynamicLoopingCall(LoopingCallBase):
if periodic_interval_max is not None: if periodic_interval_max is not None:
idle = min(idle, periodic_interval_max) idle = min(idle, periodic_interval_max)
LOG.debug('Dynamic looping call %(func_name)s sleeping ' LOG.debug('Dynamic looping call %(func_name)r sleeping '
'for %(idle).02f seconds', 'for %(idle).02f seconds',
{'func_name': repr(self.f), 'idle': idle}) {'func_name': self.f, 'idle': idle})
greenthread.sleep(idle) greenthread.sleep(idle)
except LoopingCallDone as e: except LoopingCallDone as e:
self.stop() self.stop()

View File

@ -18,8 +18,8 @@
import copy import copy
from oslo.config import cfg from oslo_config import cfg
from oslo.utils import timeutils from oslo_utils import timeutils
memcache_opts = [ memcache_opts = [
cfg.ListOpt('memcached_servers', cfg.ListOpt('memcached_servers',
@ -31,7 +31,7 @@ CONF.register_opts(memcache_opts)
def list_opts(): def list_opts():
"""Entry point for oslo.config-generator.""" """Entry point for oslo-config-generator."""
return [(None, copy.deepcopy(memcache_opts))] return [(None, copy.deepcopy(memcache_opts))]

View File

@ -91,18 +91,18 @@ as it allows particular rules to be explicitly disabled.
import abc import abc
import ast import ast
import copy import copy
import logging
import os import os
import re import re
from oslo.config import cfg from oslo_config import cfg
from oslo_log import log as logging from oslo_serialization import jsonutils
from oslo.serialization import jsonutils
import six import six
import six.moves.urllib.parse as urlparse import six.moves.urllib.parse as urlparse
import six.moves.urllib.request as urlrequest import six.moves.urllib.request as urlrequest
from designate.openstack.common import fileutils from designate.openstack.common import fileutils
from designate.openstack.common._i18n import _, _LE, _LI from designate.openstack.common._i18n import _, _LE
policy_opts = [ policy_opts = [
@ -120,7 +120,8 @@ policy_opts = [
'in the search path defined by the config_dir ' 'in the search path defined by the config_dir '
'option, or absolute paths. The file defined by ' 'option, or absolute paths. The file defined by '
'policy_file must exist for these directories to ' 'policy_file must exist for these directories to '
'be searched.')), 'be searched. Missing or empty directories are '
'ignored.')),
] ]
CONF = cfg.CONF CONF = cfg.CONF
@ -132,7 +133,7 @@ _checks = {}
def list_opts(): def list_opts():
"""Entry point for oslo.config-generator.""" """Entry point for oslo-config-generator."""
return [(None, copy.deepcopy(policy_opts))] return [(None, copy.deepcopy(policy_opts))]
@ -272,7 +273,6 @@ class Enforcer(object):
try: try:
path = self._get_policy_path(path) path = self._get_policy_path(path)
except cfg.ConfigFilesNotFoundError: except cfg.ConfigFilesNotFoundError:
LOG.info(_LI("Can not find policy directory: %s"), path)
continue continue
self._walk_through_policy_directory(path, self._walk_through_policy_directory(path,
self._load_policy_file, self._load_policy_file,
@ -292,7 +292,8 @@ class Enforcer(object):
if reloaded or not self.rules or not overwrite: if reloaded or not self.rules or not overwrite:
rules = Rules.load_json(data, self.default_rule) rules = Rules.load_json(data, self.default_rule)
self.set_rules(rules, overwrite=overwrite, use_conf=True) self.set_rules(rules, overwrite=overwrite, use_conf=True)
LOG.debug("Rules successfully reloaded") LOG.debug("Reloaded policy file: %(path)s",
{'path': path})
def _get_policy_path(self, path): def _get_policy_path(self, path):
"""Locate the policy json data file/path. """Locate the policy json data file/path.

View File

@ -18,7 +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 logging as std_logging import logging
import os import os
import random import random
import signal import signal
@ -35,9 +35,7 @@ except ImportError:
import eventlet import eventlet
from eventlet import event from eventlet import event
from oslo.config import cfg from oslo_config import cfg
from oslo_log import log as logging
from designate.openstack.common import eventlet_backdoor from designate.openstack.common import eventlet_backdoor
from designate.openstack.common._i18n import _LE, _LI, _LW from designate.openstack.common._i18n import _LE, _LI, _LW
@ -164,7 +162,7 @@ class ServiceLauncher(Launcher):
signo = 0 signo = 0
LOG.debug('Full set of CONF:') LOG.debug('Full set of CONF:')
CONF.log_opt_values(LOG, std_logging.DEBUG) CONF.log_opt_values(LOG, logging.DEBUG)
try: try:
if ready_callback: if ready_callback:
@ -378,7 +376,7 @@ class ProcessLauncher(object):
systemd.notify_once() systemd.notify_once()
LOG.debug('Full set of CONF:') LOG.debug('Full set of CONF:')
CONF.log_opt_values(LOG, std_logging.DEBUG) CONF.log_opt_values(LOG, logging.DEBUG)
try: try:
while True: while True:
@ -398,7 +396,7 @@ class ProcessLauncher(object):
self.running = True self.running = True
self.sigcaught = None self.sigcaught = None
except eventlet.greenlet.GreenletExit: except eventlet.greenlet.GreenletExit:
LOG.info(_LI("Wait called after thread killed. Cleaning up.")) LOG.info(_LI("Wait called after thread killed. Cleaning up."))
self.stop() self.stop()
@ -435,8 +433,8 @@ class Service(object):
def start(self): def start(self):
pass pass
def stop(self): def stop(self, graceful=False):
self.tg.stop() self.tg.stop(graceful)
self.tg.wait() self.tg.wait()
# Signal that service cleanup is done: # Signal that service cleanup is done:
if not self._done.ready(): if not self._done.ready():

View File

@ -16,7 +16,7 @@ import copy
import os import os
import ssl import ssl
from oslo.config import cfg from oslo_config import cfg
from designate.openstack.common._i18n import _ from designate.openstack.common._i18n import _
@ -39,7 +39,7 @@ CONF.register_opts(ssl_opts, config_section)
def list_opts(): def list_opts():
"""Entry point for oslo.config-generator.""" """Entry point for oslo-config-generator."""
return [(config_section, copy.deepcopy(ssl_opts))] return [(config_section, copy.deepcopy(ssl_opts))]

View File

@ -16,12 +16,11 @@
Helper module for systemd service readiness notification. Helper module for systemd service readiness notification.
""" """
import logging
import os import os
import socket import socket
import sys import sys
from oslo_log import log as logging
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)

View File

@ -11,11 +11,11 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import logging
import threading import threading
import eventlet import eventlet
from eventlet import greenpool from eventlet import greenpool
from oslo_log import log as logging
from designate.openstack.common import loopingcall from designate.openstack.common import loopingcall

View File

@ -1,203 +0,0 @@
# Copyright (c) 2013 OpenStack Foundation
# 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.
"""
Helpers for comparing version strings.
"""
import functools
import inspect
from oslo_log import log as logging
import pkg_resources
import six
from designate.openstack.common._i18n import _
LOG = logging.getLogger(__name__)
class deprecated(object):
"""A decorator to mark callables as deprecated.
This decorator logs a deprecation message when the callable it decorates is
used. The message will include the release where the callable was
deprecated, the release where it may be removed and possibly an optional
replacement.
Examples:
1. Specifying the required deprecated release
>>> @deprecated(as_of=deprecated.ICEHOUSE)
... def a(): pass
2. Specifying a replacement:
>>> @deprecated(as_of=deprecated.ICEHOUSE, in_favor_of='f()')
... def b(): pass
3. Specifying the release where the functionality may be removed:
>>> @deprecated(as_of=deprecated.ICEHOUSE, remove_in=+1)
... def c(): pass
4. Specifying the deprecated functionality will not be removed:
>>> @deprecated(as_of=deprecated.ICEHOUSE, remove_in=0)
... def d(): pass
5. Specifying a replacement, deprecated functionality will not be removed:
>>> @deprecated(as_of=deprecated.ICEHOUSE, in_favor_of='f()', remove_in=0)
... def e(): pass
"""
# NOTE(morganfainberg): Bexar is used for unit test purposes, it is
# expected we maintain a gap between Bexar and Folsom in this list.
BEXAR = 'B'
FOLSOM = 'F'
GRIZZLY = 'G'
HAVANA = 'H'
ICEHOUSE = 'I'
JUNO = 'J'
KILO = 'K'
_RELEASES = {
# NOTE(morganfainberg): Bexar is used for unit test purposes, it is
# expected we maintain a gap between Bexar and Folsom in this list.
'B': 'Bexar',
'F': 'Folsom',
'G': 'Grizzly',
'H': 'Havana',
'I': 'Icehouse',
'J': 'Juno',
'K': 'Kilo',
}
_deprecated_msg_with_alternative = _(
'%(what)s is deprecated as of %(as_of)s in favor of '
'%(in_favor_of)s and may be removed in %(remove_in)s.')
_deprecated_msg_no_alternative = _(
'%(what)s is deprecated as of %(as_of)s and may be '
'removed in %(remove_in)s. It will not be superseded.')
_deprecated_msg_with_alternative_no_removal = _(
'%(what)s is deprecated as of %(as_of)s in favor of %(in_favor_of)s.')
_deprecated_msg_with_no_alternative_no_removal = _(
'%(what)s is deprecated as of %(as_of)s. It will not be superseded.')
def __init__(self, as_of, in_favor_of=None, remove_in=2, what=None):
"""Initialize decorator
:param as_of: the release deprecating the callable. Constants
are define in this class for convenience.
:param in_favor_of: the replacement for the callable (optional)
:param remove_in: an integer specifying how many releases to wait
before removing (default: 2)
:param what: name of the thing being deprecated (default: the
callable's name)
"""
self.as_of = as_of
self.in_favor_of = in_favor_of
self.remove_in = remove_in
self.what = what
def __call__(self, func_or_cls):
if not self.what:
self.what = func_or_cls.__name__ + '()'
msg, details = self._build_message()
if inspect.isfunction(func_or_cls):
@six.wraps(func_or_cls)
def wrapped(*args, **kwargs):
LOG.deprecated(msg, details)
return func_or_cls(*args, **kwargs)
return wrapped
elif inspect.isclass(func_or_cls):
orig_init = func_or_cls.__init__
# TODO(tsufiev): change `functools` module to `six` as
# soon as six 1.7.4 (with fix for passing `assigned`
# argument to underlying `functools.wraps`) is released
# and added to the designate-incubator requrements
@functools.wraps(orig_init, assigned=('__name__', '__doc__'))
def new_init(self, *args, **kwargs):
LOG.deprecated(msg, details)
orig_init(self, *args, **kwargs)
func_or_cls.__init__ = new_init
return func_or_cls
else:
raise TypeError('deprecated can be used only with functions or '
'classes')
def _get_safe_to_remove_release(self, release):
# TODO(dstanek): this method will have to be reimplemented once
# when we get to the X release because once we get to the Y
# release, what is Y+2?
new_release = chr(ord(release) + self.remove_in)
if new_release in self._RELEASES:
return self._RELEASES[new_release]
else:
return new_release
def _build_message(self):
details = dict(what=self.what,
as_of=self._RELEASES[self.as_of],
remove_in=self._get_safe_to_remove_release(self.as_of))
if self.in_favor_of:
details['in_favor_of'] = self.in_favor_of
if self.remove_in > 0:
msg = self._deprecated_msg_with_alternative
else:
# There are no plans to remove this function, but it is
# now deprecated.
msg = self._deprecated_msg_with_alternative_no_removal
else:
if self.remove_in > 0:
msg = self._deprecated_msg_no_alternative
else:
# There are no plans to remove this function, but it is
# now deprecated.
msg = self._deprecated_msg_with_no_alternative_no_removal
return msg, details
def is_compatible(requested_version, current_version, same_major=True):
"""Determine whether `requested_version` is satisfied by
`current_version`; in other words, `current_version` is >=
`requested_version`.
:param requested_version: version to check for compatibility
:param current_version: version to check against
:param same_major: if True, the major version must be identical between
`requested_version` and `current_version`. This is used when a
major-version difference indicates incompatibility between the two
versions. Since this is the common-case in practice, the default is
True.
:returns: True if compatible, False if not
"""
requested_parts = pkg_resources.parse_version(requested_version)
current_parts = pkg_resources.parse_version(current_version)
if same_major and (requested_parts[0] != current_parts[0]):
return False
return current_parts >= requested_parts

View File

@ -4,12 +4,9 @@
script=tools/install_venv_common.py script=tools/install_venv_common.py
# The list of modules to copy from oslo-incubator.git # The list of modules to copy from oslo-incubator.git
module=fixture.config
module=memorycache module=memorycache
module=policy module=policy
module=service module=service
module=timeutils
module=versionutils
# Modules needed for the deprecated oslo.wsgi we're still using # Modules needed for the deprecated oslo.wsgi we're still using
module=sslutils module=sslutils