diff --git a/climate/openstack/common/context.py b/climate/openstack/common/context.py index 795fe8a..93703db 100644 --- a/climate/openstack/common/context.py +++ b/climate/openstack/common/context.py @@ -40,15 +40,13 @@ class RequestContext(object): """ def __init__(self, auth_token=None, user=None, tenant=None, is_admin=False, - read_only=False, show_deleted=False, request_id=None, - instance_uuid=None): + read_only=False, show_deleted=False, request_id=None): self.auth_token = auth_token self.user = user self.tenant = tenant self.is_admin = is_admin self.read_only = read_only self.show_deleted = show_deleted - self.instance_uuid = instance_uuid if not request_id: request_id = generate_request_id() self.request_id = request_id @@ -60,8 +58,7 @@ class RequestContext(object): 'read_only': self.read_only, 'show_deleted': self.show_deleted, 'auth_token': self.auth_token, - 'request_id': self.request_id, - 'instance_uuid': self.instance_uuid} + 'request_id': self.request_id} def get_admin_context(show_deleted=False): diff --git a/climate/openstack/common/db/sqlalchemy/session.py b/climate/openstack/common/db/sqlalchemy/session.py index 6056f49..9f29076 100644 --- a/climate/openstack/common/db/sqlalchemy/session.py +++ b/climate/openstack/common/db/sqlalchemy/session.py @@ -279,9 +279,7 @@ database_opts = [ deprecated_opts=[cfg.DeprecatedOpt('sql_connection', group='DEFAULT'), cfg.DeprecatedOpt('sql_connection', - group='DATABASE'), - cfg.DeprecatedOpt('connection', - group='sql'), ]), + group='DATABASE')]), cfg.StrOpt('slave_connection', default='', help='The SQLAlchemy connection string used to connect to the ' diff --git a/climate/openstack/common/excutils.py b/climate/openstack/common/excutils.py index 2e97c75..8093be8 100644 --- a/climate/openstack/common/excutils.py +++ b/climate/openstack/common/excutils.py @@ -79,7 +79,7 @@ def forever_retry_uncaught_exceptions(infunc): try: return infunc(*args, **kwargs) except Exception as exc: - this_exc_message = six.u(str(exc)) + this_exc_message = unicode(exc) if this_exc_message == last_exc_message: exc_count += 1 else: diff --git a/climate/openstack/common/fileutils.py b/climate/openstack/common/fileutils.py index 9a61724..3c0450e 100644 --- a/climate/openstack/common/fileutils.py +++ b/climate/openstack/common/fileutils.py @@ -19,7 +19,6 @@ import contextlib import errno import os -import tempfile from climate.openstack.common import excutils from climate.openstack.common.gettextutils import _ # noqa @@ -110,30 +109,3 @@ def file_open(*args, **kwargs): state at all (for unit tests) """ return file(*args, **kwargs) - - -def write_to_tempfile(content, path=None, suffix='', prefix='tmp'): - """Create temporary file or use existing file. - - This util is needed for creating temporary file with - specified content, suffix and prefix. If path is not None, - it will be used for writing content. If the path doesn't - exist it'll be created. - - :param content: content for temporary file. - :param path: same as parameter 'dir' for mkstemp - :param suffix: same as parameter 'suffix' for mkstemp - :param prefix: same as parameter 'prefix' for mkstemp - - For example: it can be used in database tests for creating - configuration files. - """ - if path: - ensure_tree(path) - - (fd, path) = tempfile.mkstemp(suffix=suffix, dir=path, prefix=prefix) - try: - os.write(fd, content) - finally: - os.close(fd) - return path diff --git a/climate/openstack/common/gettextutils.py b/climate/openstack/common/gettextutils.py index 6584429..edb1bc7 100644 --- a/climate/openstack/common/gettextutils.py +++ b/climate/openstack/common/gettextutils.py @@ -60,8 +60,6 @@ def _(msg): if USE_LAZY: return Message(msg, 'climate') else: - if six.PY3: - return _t.gettext(msg) return _t.ugettext(msg) @@ -107,17 +105,13 @@ def install(domain, lazy=False): """ return Message(msg, domain) - from six import moves - moves.builtins.__dict__['_'] = _lazy_gettext + import __builtin__ + __builtin__.__dict__['_'] = _lazy_gettext else: localedir = '%s_LOCALEDIR' % domain.upper() - if six.PY3: - gettext.install(domain, - localedir=os.environ.get(localedir)) - else: - gettext.install(domain, - localedir=os.environ.get(localedir), - unicode=True) + gettext.install(domain, + localedir=os.environ.get(localedir), + unicode=True) class Message(_userString.UserString, object): @@ -127,8 +121,8 @@ class Message(_userString.UserString, object): self._msg = msg self._left_extra_msg = '' self._right_extra_msg = '' - self._locale = None self.params = None + self.locale = None self.domain = domain @property @@ -148,13 +142,8 @@ class Message(_userString.UserString, object): localedir=localedir, fallback=True) - if six.PY3: - ugettext = lang.gettext - else: - ugettext = lang.ugettext - full_msg = (self._left_extra_msg + - ugettext(self._msg) + + lang.ugettext(self._msg) + self._right_extra_msg) if self.params is not None: @@ -162,33 +151,6 @@ class Message(_userString.UserString, object): return six.text_type(full_msg) - @property - def locale(self): - return self._locale - - @locale.setter - def locale(self, value): - self._locale = value - if not self.params: - return - - # This Message object may have been constructed with one or more - # Message objects as substitution parameters, given as a single - # Message, or a tuple or Map containing some, so when setting the - # locale for this Message we need to set it for those Messages too. - if isinstance(self.params, Message): - self.params.locale = value - return - if isinstance(self.params, tuple): - for param in self.params: - if isinstance(param, Message): - param.locale = value - return - if isinstance(self.params, dict): - for param in self.params.values(): - if isinstance(param, Message): - param.locale = value - def _save_dictionary_parameter(self, dict_param): full_msg = self.data # look for %(blah) fields in string; @@ -207,7 +169,7 @@ class Message(_userString.UserString, object): params[key] = copy.deepcopy(dict_param[key]) except TypeError: # cast uncopyable thing to unicode string - params[key] = six.text_type(dict_param[key]) + params[key] = unicode(dict_param[key]) return params @@ -226,7 +188,7 @@ class Message(_userString.UserString, object): try: self.params = copy.deepcopy(other) except TypeError: - self.params = six.text_type(other) + self.params = unicode(other) return self @@ -235,13 +197,11 @@ class Message(_userString.UserString, object): return self.data def __str__(self): - if six.PY3: - return self.__unicode__() return self.data.encode('utf-8') def __getstate__(self): to_copy = ['_msg', '_right_extra_msg', '_left_extra_msg', - 'domain', 'params', '_locale'] + 'domain', 'params', 'locale'] new_dict = self.__dict__.fromkeys(to_copy) for attr in to_copy: new_dict[attr] = copy.deepcopy(self.__dict__[attr]) @@ -333,7 +293,7 @@ def get_localized_message(message, user_locale): if isinstance(message, Message): if user_locale: message.locale = user_locale - return six.text_type(message) + return unicode(message) else: return message diff --git a/climate/openstack/common/jsonutils.py b/climate/openstack/common/jsonutils.py index 44b9f4e..7ae624e 100644 --- a/climate/openstack/common/jsonutils.py +++ b/climate/openstack/common/jsonutils.py @@ -46,7 +46,6 @@ except ImportError: import six -from climate.openstack.common import gettextutils from climate.openstack.common import importutils from climate.openstack.common import timeutils @@ -136,8 +135,6 @@ def to_primitive(value, convert_instances=False, convert_datetime=True, if convert_datetime and isinstance(value, datetime.datetime): return timeutils.strtime(value) - elif isinstance(value, gettextutils.Message): - return value.data elif hasattr(value, 'iteritems'): return recursive(dict(value.iteritems()), level=level + 1) elif hasattr(value, '__iter__'): diff --git a/climate/openstack/common/log.py b/climate/openstack/common/log.py index e4753db..7d18cdd 100644 --- a/climate/openstack/common/log.py +++ b/climate/openstack/common/log.py @@ -39,7 +39,6 @@ import sys import traceback from oslo.config import cfg -import six from six import moves from climate.openstack.common.gettextutils import _ # noqa @@ -250,13 +249,6 @@ class ContextAdapter(BaseLoggerAdapter): self.warn(stdmsg, *args, **kwargs) def process(self, msg, kwargs): - # NOTE(mrodden): catch any Message/other object and - # coerce to unicode before they can get - # to the python logging and possibly - # cause string encoding trouble - if not isinstance(msg, six.string_types): - msg = six.text_type(msg) - if 'extra' not in kwargs: kwargs['extra'] = {} extra = kwargs['extra'] @@ -268,14 +260,14 @@ class ContextAdapter(BaseLoggerAdapter): extra.update(_dictify_context(context)) instance = kwargs.pop('instance', None) - instance_uuid = (extra.get('instance_uuid', None) or - kwargs.pop('instance_uuid', None)) instance_extra = '' if instance: instance_extra = CONF.instance_format % instance - elif instance_uuid: - instance_extra = (CONF.instance_uuid_format - % {'uuid': instance_uuid}) + else: + instance_uuid = kwargs.pop('instance_uuid', None) + if instance_uuid: + instance_extra = (CONF.instance_uuid_format + % {'uuid': instance_uuid}) extra.update({'instance': instance_extra}) extra.update({"project": self.project}) diff --git a/climate/openstack/common/middleware/audit.py b/climate/openstack/common/middleware/audit.py index 4d070e4..c83c5a9 100644 --- a/climate/openstack/common/middleware/audit.py +++ b/climate/openstack/common/middleware/audit.py @@ -1,6 +1,6 @@ # vim: tabstop=4 shiftwidth=4 softtabstop=4 -# Copyright (c) 2013 OpenStack Foundation +# Copyright (c) 2013 OpenStack LLC. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/climate/openstack/common/notifier/rpc_notifier.py b/climate/openstack/common/notifier/rpc_notifier.py index abee7b2..11d0027 100644 --- a/climate/openstack/common/notifier/rpc_notifier.py +++ b/climate/openstack/common/notifier/rpc_notifier.py @@ -43,5 +43,4 @@ def notify(context, message): rpc.notify(context, topic, message) except Exception: LOG.exception(_("Could not send notification to %(topic)s. " - "Payload=%(message)s"), - {"topic": topic, "message": message}) + "Payload=%(message)s"), locals()) diff --git a/climate/openstack/common/notifier/rpc_notifier2.py b/climate/openstack/common/notifier/rpc_notifier2.py index 803a427..92206ac 100644 --- a/climate/openstack/common/notifier/rpc_notifier2.py +++ b/climate/openstack/common/notifier/rpc_notifier2.py @@ -49,5 +49,4 @@ def notify(context, message): rpc.notify(context, topic, message, envelope=True) except Exception: LOG.exception(_("Could not send notification to %(topic)s. " - "Payload=%(message)s"), - {"topic": topic, "message": message}) + "Payload=%(message)s"), locals()) diff --git a/climate/openstack/common/policy.py b/climate/openstack/common/policy.py index 485027c..db061d0 100644 --- a/climate/openstack/common/policy.py +++ b/climate/openstack/common/policy.py @@ -221,7 +221,7 @@ class Enforcer(object): if policy_file: return policy_file - raise cfg.ConfigFilesNotFoundError((self.policy_file,)) + raise cfg.ConfigFilesNotFoundError((CONF.policy_file,)) def enforce(self, rule, target, creds, do_raise=False, exc=None, *args, **kwargs): @@ -449,6 +449,7 @@ class OrCheck(BaseCheck): for rule in self.rules: if rule(target, cred, enforcer): return True + return False def add_check(self, rule): @@ -845,13 +846,7 @@ class GenericCheck(Check): """ # TODO(termie): do dict inspection via dot syntax - try: - match = self.match % target - except KeyError: - # While doing GenericCheck if key not - # present in Target return false - return False - + match = self.match % target if self.kind in creds: return match == six.text_type(creds[self.kind]) return False diff --git a/climate/openstack/common/rpc/common.py b/climate/openstack/common/rpc/common.py index 27e8de5..9724650 100644 --- a/climate/openstack/common/rpc/common.py +++ b/climate/openstack/common/rpc/common.py @@ -29,7 +29,6 @@ from climate.openstack.common import importutils from climate.openstack.common import jsonutils from climate.openstack.common import local from climate.openstack.common import log as logging -from climate.openstack.common import versionutils CONF = cfg.CONF @@ -442,15 +441,19 @@ def client_exceptions(*exceptions): return outer -# TODO(sirp): we should deprecate this in favor of -# using `versionutils.is_compatible` directly def version_is_compatible(imp_version, version): """Determine whether versions are compatible. :param imp_version: The version implemented :param version: The version requested by an incoming message. """ - return versionutils.is_compatible(version, imp_version) + version_parts = version.split('.') + imp_version_parts = imp_version.split('.') + if int(version_parts[0]) != int(imp_version_parts[0]): # Major + return False + if int(version_parts[1]) > int(imp_version_parts[1]): # Minor + return False + return True def serialize_msg(raw_msg): diff --git a/climate/openstack/common/service.py b/climate/openstack/common/service.py index 6f23790..9a3b9d5 100644 --- a/climate/openstack/common/service.py +++ b/climate/openstack/common/service.py @@ -221,9 +221,6 @@ class ProcessLauncher(object): status = None signo = 0 - # NOTE(johannes): All exceptions are caught to ensure this - # doesn't fallback into the loop spawning children. It would - # be bad for a child to spawn more children. try: launcher.wait() except SignalExit as exc: @@ -276,6 +273,9 @@ class ProcessLauncher(object): pid = os.fork() if pid == 0: + # NOTE(johannes): All exceptions are caught to ensure this + # doesn't fallback into the loop spawning children. It would + # be bad for a child to spawn more children. launcher = self._child_process(wrap.service) while True: self._child_process_handle_signal() diff --git a/climate/openstack/common/test.py b/climate/openstack/common/test.py index 06cde34..bd97197 100644 --- a/climate/openstack/common/test.py +++ b/climate/openstack/common/test.py @@ -30,7 +30,6 @@ class BaseTestCase(testtools.TestCase): self._set_timeout() self._fake_output() self.useFixture(fixtures.FakeLogger('climate.openstack.common')) - self.useFixture(fixtures.NestedTempfile()) def _set_timeout(self): test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0) diff --git a/climate/openstack/common/timeutils.py b/climate/openstack/common/timeutils.py index 98d877d..60f02bc 100644 --- a/climate/openstack/common/timeutils.py +++ b/climate/openstack/common/timeutils.py @@ -117,15 +117,12 @@ def iso8601_from_timestamp(timestamp): utcnow.override_time = None -def set_time_override(override_time=None): +def set_time_override(override_time=datetime.datetime.utcnow()): """Overrides utils.utcnow. Make it return a constant time or a list thereof, one at a time. - - :param override_time: datetime instance or list thereof. If not - given, defaults to the current UTC time. """ - utcnow.override_time = override_time or datetime.datetime.utcnow() + utcnow.override_time = override_time def advance_time_delta(timedelta):