From 536a3826f7aa7de1c53105eeabd24228d52df5b7 Mon Sep 17 00:00:00 2001 From: Kiall Mac Innes Date: Sat, 28 Feb 2015 13:38:49 +0000 Subject: [PATCH] Sync with oslo-incubator o-i revision: f989c4397d7e83c3e73e8da01a9f27bf4ca38b73 Additionally, remove unused o-i modules: * fixtures.config * timeutils * versionutils Change-Id: I5a63b5ef52119da66093a9b98c1c1dbfaa59dd9a --- designate/openstack/common/_i18n.py | 6 +- .../openstack/common/eventlet_backdoor.py | 7 +- designate/openstack/common/fileutils.py | 9 +- .../openstack/common/fixture/__init__.py | 17 -- designate/openstack/common/loopingcall.py | 10 +- designate/openstack/common/memorycache.py | 6 +- designate/openstack/common/policy.py | 17 +- designate/openstack/common/service.py | 16 +- designate/openstack/common/sslutils.py | 4 +- designate/openstack/common/systemd.py | 3 +- designate/openstack/common/threadgroup.py | 2 +- designate/openstack/common/versionutils.py | 203 ------------------ openstack-common.conf | 3 - 13 files changed, 40 insertions(+), 263 deletions(-) delete mode 100644 designate/openstack/common/fixture/__init__.py delete mode 100644 designate/openstack/common/versionutils.py diff --git a/designate/openstack/common/_i18n.py b/designate/openstack/common/_i18n.py index c0454b66e..fd1b98e6d 100644 --- a/designate/openstack/common/_i18n.py +++ b/designate/openstack/common/_i18n.py @@ -17,14 +17,14 @@ See http://docs.openstack.org/developer/oslo.i18n/usage.html """ try: - import oslo.i18n + 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='designate') + _translators = oslo_i18n.TranslatorFactory(domain='designate') # The primary translation function using the well-known name "_" _ = _translators.primary @@ -40,6 +40,6 @@ try: _LC = _translators.log_critical except ImportError: # 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) _ = _LI = _LW = _LE = _LC = lambda x: x diff --git a/designate/openstack/common/eventlet_backdoor.py b/designate/openstack/common/eventlet_backdoor.py index bfa3fd325..42924ca75 100644 --- a/designate/openstack/common/eventlet_backdoor.py +++ b/designate/openstack/common/eventlet_backdoor.py @@ -19,17 +19,16 @@ from __future__ import print_function import copy import errno import gc +import logging import os import pprint import socket import sys import traceback -import eventlet import eventlet.backdoor import greenlet -from oslo.config import cfg -from oslo_log import log as logging +from oslo_config import cfg from designate.openstack.common._i18n import _LI @@ -51,7 +50,7 @@ LOG = logging.getLogger(__name__) def list_opts(): - """Entry point for oslo.config-generator. + """Entry point for oslo-config-generator. """ return [(None, copy.deepcopy(eventlet_backdoor_opts))] diff --git a/designate/openstack/common/fileutils.py b/designate/openstack/common/fileutils.py index ec26eaf9c..9097c35d4 100644 --- a/designate/openstack/common/fileutils.py +++ b/designate/openstack/common/fileutils.py @@ -17,22 +17,25 @@ import contextlib import errno import logging import os +import stat import tempfile -from oslo.utils import excutils +from oslo_utils import excutils LOG = logging.getLogger(__name__) _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) :param path: Directory to create + :param mode: Directory creation permissions """ try: - os.makedirs(path) + os.makedirs(path, mode) except OSError as exc: if exc.errno == errno.EEXIST: if not os.path.isdir(path): diff --git a/designate/openstack/common/fixture/__init__.py b/designate/openstack/common/fixture/__init__.py deleted file mode 100644 index d1223eaf7..000000000 --- a/designate/openstack/common/fixture/__init__.py +++ /dev/null @@ -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')) diff --git a/designate/openstack/common/loopingcall.py b/designate/openstack/common/loopingcall.py index ea94b1200..96e01b0d5 100644 --- a/designate/openstack/common/loopingcall.py +++ b/designate/openstack/common/loopingcall.py @@ -15,12 +15,12 @@ # 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 oslo_log import log as logging from designate.openstack.common._i18n import _LE, _LW @@ -84,9 +84,9 @@ class FixedIntervalLoopingCall(LoopingCallBase): break delay = end - start - interval 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'), - {'func_name': repr(self.f), 'delay': delay}) + {'func_name': self.f, 'delay': delay}) greenthread.sleep(-delay if delay < 0 else 0) except LoopingCallDone as e: self.stop() @@ -127,9 +127,9 @@ class DynamicLoopingCall(LoopingCallBase): if periodic_interval_max is not None: 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', - {'func_name': repr(self.f), 'idle': idle}) + {'func_name': self.f, 'idle': idle}) greenthread.sleep(idle) except LoopingCallDone as e: self.stop() diff --git a/designate/openstack/common/memorycache.py b/designate/openstack/common/memorycache.py index f793c9371..e72c26df1 100644 --- a/designate/openstack/common/memorycache.py +++ b/designate/openstack/common/memorycache.py @@ -18,8 +18,8 @@ import copy -from oslo.config import cfg -from oslo.utils import timeutils +from oslo_config import cfg +from oslo_utils import timeutils memcache_opts = [ cfg.ListOpt('memcached_servers', @@ -31,7 +31,7 @@ CONF.register_opts(memcache_opts) def list_opts(): - """Entry point for oslo.config-generator.""" + """Entry point for oslo-config-generator.""" return [(None, copy.deepcopy(memcache_opts))] diff --git a/designate/openstack/common/policy.py b/designate/openstack/common/policy.py index 0c7bf293e..b80472160 100644 --- a/designate/openstack/common/policy.py +++ b/designate/openstack/common/policy.py @@ -91,18 +91,18 @@ as it allows particular rules to be explicitly disabled. import abc import ast import copy +import logging import os import re -from oslo.config import cfg -from oslo_log import log as logging -from oslo.serialization import jsonutils +from oslo_config import cfg +from oslo_serialization import jsonutils import six import six.moves.urllib.parse as urlparse import six.moves.urllib.request as urlrequest from designate.openstack.common import fileutils -from designate.openstack.common._i18n import _, _LE, _LI +from designate.openstack.common._i18n import _, _LE policy_opts = [ @@ -120,7 +120,8 @@ policy_opts = [ 'in the search path defined by the config_dir ' 'option, or absolute paths. The file defined by ' 'policy_file must exist for these directories to ' - 'be searched.')), + 'be searched. Missing or empty directories are ' + 'ignored.')), ] CONF = cfg.CONF @@ -132,7 +133,7 @@ _checks = {} def list_opts(): - """Entry point for oslo.config-generator.""" + """Entry point for oslo-config-generator.""" return [(None, copy.deepcopy(policy_opts))] @@ -272,7 +273,6 @@ class Enforcer(object): try: path = self._get_policy_path(path) except cfg.ConfigFilesNotFoundError: - LOG.info(_LI("Can not find policy directory: %s"), path) continue self._walk_through_policy_directory(path, self._load_policy_file, @@ -292,7 +292,8 @@ class Enforcer(object): if reloaded or not self.rules or not overwrite: rules = Rules.load_json(data, self.default_rule) 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): """Locate the policy json data file/path. diff --git a/designate/openstack/common/service.py b/designate/openstack/common/service.py index 87ee15eb8..52e74be7b 100644 --- a/designate/openstack/common/service.py +++ b/designate/openstack/common/service.py @@ -18,7 +18,7 @@ """Generic Node base class for all workers that run on hosts.""" import errno -import logging as std_logging +import logging import os import random import signal @@ -35,9 +35,7 @@ except ImportError: import eventlet from eventlet import event -from oslo.config import cfg -from oslo_log import log as logging - +from oslo_config import cfg from designate.openstack.common import eventlet_backdoor from designate.openstack.common._i18n import _LE, _LI, _LW @@ -164,7 +162,7 @@ class ServiceLauncher(Launcher): signo = 0 LOG.debug('Full set of CONF:') - CONF.log_opt_values(LOG, std_logging.DEBUG) + CONF.log_opt_values(LOG, logging.DEBUG) try: if ready_callback: @@ -378,7 +376,7 @@ class ProcessLauncher(object): systemd.notify_once() LOG.debug('Full set of CONF:') - CONF.log_opt_values(LOG, std_logging.DEBUG) + CONF.log_opt_values(LOG, logging.DEBUG) try: while True: @@ -398,7 +396,7 @@ class ProcessLauncher(object): self.running = True self.sigcaught = None 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() @@ -435,8 +433,8 @@ class Service(object): def start(self): pass - def stop(self): - self.tg.stop() + def stop(self, graceful=False): + self.tg.stop(graceful) self.tg.wait() # Signal that service cleanup is done: if not self._done.ready(): diff --git a/designate/openstack/common/sslutils.py b/designate/openstack/common/sslutils.py index b38f09795..a4aa58a15 100644 --- a/designate/openstack/common/sslutils.py +++ b/designate/openstack/common/sslutils.py @@ -16,7 +16,7 @@ import copy import os import ssl -from oslo.config import cfg +from oslo_config import cfg from designate.openstack.common._i18n import _ @@ -39,7 +39,7 @@ CONF.register_opts(ssl_opts, config_section) def list_opts(): - """Entry point for oslo.config-generator.""" + """Entry point for oslo-config-generator.""" return [(config_section, copy.deepcopy(ssl_opts))] diff --git a/designate/openstack/common/systemd.py b/designate/openstack/common/systemd.py index 52bbeda64..36243b342 100644 --- a/designate/openstack/common/systemd.py +++ b/designate/openstack/common/systemd.py @@ -16,12 +16,11 @@ Helper module for systemd service readiness notification. """ +import logging import os import socket import sys -from oslo_log import log as logging - LOG = logging.getLogger(__name__) diff --git a/designate/openstack/common/threadgroup.py b/designate/openstack/common/threadgroup.py index 1b2dd911a..fab04c76f 100644 --- a/designate/openstack/common/threadgroup.py +++ b/designate/openstack/common/threadgroup.py @@ -11,11 +11,11 @@ # 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 threading import eventlet from eventlet import greenpool -from oslo_log import log as logging from designate.openstack.common import loopingcall diff --git a/designate/openstack/common/versionutils.py b/designate/openstack/common/versionutils.py deleted file mode 100644 index a5124b84f..000000000 --- a/designate/openstack/common/versionutils.py +++ /dev/null @@ -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 diff --git a/openstack-common.conf b/openstack-common.conf index 4dde6d511..5e31620fe 100644 --- a/openstack-common.conf +++ b/openstack-common.conf @@ -4,12 +4,9 @@ script=tools/install_venv_common.py # The list of modules to copy from oslo-incubator.git -module=fixture.config module=memorycache module=policy module=service -module=timeutils -module=versionutils # Modules needed for the deprecated oslo.wsgi we're still using module=sslutils