summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Still <mikal@stillhq.com>2013-05-03 06:45:51 +1000
committerMichael Still <mikal@stillhq.com>2013-05-03 06:45:51 +1000
commitb4826d85c25a56ad95ffb76c467cdb459daba0c4 (patch)
tree3aef4414b1437a9acff126c7b3b4443a65985700
parent8bb1cc2f82b0d1dcfb08777537584e5f574ae439 (diff)
downloadnova-b4826d85c25a56ad95ffb76c467cdb459daba0c4.tar.gz
nova-b4826d85c25a56ad95ffb76c467cdb459daba0c4.tar.xz
nova-b4826d85c25a56ad95ffb76c467cdb459daba0c4.zip
Update oslo-incubator import.
These are all minor changes bringing nova up to commit 90e83530d4dc49d570fa05ea63a93805717dcfa0 in oslo-incubator. Change-Id: I0291eed31b1e650da211fe2a8b65fad0c35c9053
-rw-r--r--nova/openstack/common/db/sqlalchemy/utils.py4
-rw-r--r--nova/openstack/common/log.py49
-rw-r--r--nova/openstack/common/rootwrap/filters.py46
-rw-r--r--nova/openstack/common/rpc/impl_qpid.py13
-rw-r--r--tools/install_venv_common.py17
5 files changed, 100 insertions, 29 deletions
diff --git a/nova/openstack/common/db/sqlalchemy/utils.py b/nova/openstack/common/db/sqlalchemy/utils.py
index 3f5ae737a..98ae05064 100644
--- a/nova/openstack/common/db/sqlalchemy/utils.py
+++ b/nova/openstack/common/db/sqlalchemy/utils.py
@@ -105,9 +105,9 @@ def paginate_query(query, model, limit, sort_keys, marker=None,
# Build up an array of sort criteria as in the docstring
criteria_list = []
- for i in xrange(0, len(sort_keys)):
+ for i in range(0, len(sort_keys)):
crit_attrs = []
- for j in xrange(0, i):
+ for j in range(0, i):
model_attr = getattr(model, sort_keys[j])
crit_attrs.append((model_attr == marker_values[j]))
diff --git a/nova/openstack/common/log.py b/nova/openstack/common/log.py
index 49dbadebe..6c15b6a98 100644
--- a/nova/openstack/common/log.py
+++ b/nova/openstack/common/log.py
@@ -37,7 +37,6 @@ import logging
import logging.config
import logging.handlers
import os
-import stat
import sys
import traceback
@@ -104,10 +103,7 @@ logging_cli_opts = [
generic_log_opts = [
cfg.BoolOpt('use_stderr',
default=True,
- help='Log output to standard error'),
- cfg.StrOpt('logfile_mode',
- default='0644',
- help='Default file mode used when creating log files'),
+ help='Log output to standard error')
]
log_opts = [
@@ -211,7 +207,27 @@ def _get_log_file_path(binary=None):
return '%s.log' % (os.path.join(logdir, binary),)
-class ContextAdapter(logging.LoggerAdapter):
+class BaseLoggerAdapter(logging.LoggerAdapter):
+
+ def audit(self, msg, *args, **kwargs):
+ self.log(logging.AUDIT, msg, *args, **kwargs)
+
+
+class LazyAdapter(BaseLoggerAdapter):
+ def __init__(self, name='unknown', version='unknown'):
+ self._logger = None
+ self.extra = {}
+ self.name = name
+ self.version = version
+
+ @property
+ def logger(self):
+ if not self._logger:
+ self._logger = getLogger(self.name, self.version)
+ return self._logger
+
+
+class ContextAdapter(BaseLoggerAdapter):
warn = logging.LoggerAdapter.warning
def __init__(self, logger, project_name, version_string):
@@ -219,8 +235,9 @@ class ContextAdapter(logging.LoggerAdapter):
self.project = project_name
self.version = version_string
- def audit(self, msg, *args, **kwargs):
- self.log(logging.AUDIT, msg, *args, **kwargs)
+ @property
+ def handlers(self):
+ return self.logger.handlers
def deprecated(self, msg, *args, **kwargs):
stdmsg = _("Deprecated: %s") % msg
@@ -340,7 +357,7 @@ class LogConfigError(Exception):
def _load_log_config(log_config):
try:
logging.config.fileConfig(log_config)
- except ConfigParser.Error, exc:
+ except ConfigParser.Error as exc:
raise LogConfigError(log_config, str(exc))
@@ -399,11 +416,6 @@ def _setup_logging_from_conf():
filelog = logging.handlers.WatchedFileHandler(logpath)
log_root.addHandler(filelog)
- mode = int(CONF.logfile_mode, 8)
- st = os.stat(logpath)
- if st.st_mode != (stat.S_IFREG | mode):
- os.chmod(logpath, mode)
-
if CONF.use_stderr:
streamlog = ColorHandler()
log_root.addHandler(streamlog)
@@ -449,6 +461,15 @@ def getLogger(name='unknown', version='unknown'):
return _loggers[name]
+def getLazyLogger(name='unknown', version='unknown'):
+ """
+ create a pass-through logger that does not create the real logger
+ until it is really needed and delegates all calls to the real logger
+ once it is created
+ """
+ return LazyAdapter(name, version)
+
+
class WritableLogger(object):
"""A thin wrapper that responds to `write` and logs."""
diff --git a/nova/openstack/common/rootwrap/filters.py b/nova/openstack/common/rootwrap/filters.py
index eadda256c..d9618af88 100644
--- a/nova/openstack/common/rootwrap/filters.py
+++ b/nova/openstack/common/rootwrap/filters.py
@@ -88,6 +88,52 @@ class RegExpFilter(CommandFilter):
return False
+class PathFilter(CommandFilter):
+ """Command filter checking that path arguments are within given dirs
+
+ One can specify the following constraints for command arguments:
+ 1) pass - pass an argument as is to the resulting command
+ 2) some_str - check if an argument is equal to the given string
+ 3) abs path - check if a path argument is within the given base dir
+
+ A typical rootwrapper filter entry looks like this:
+ # cmdname: filter name, raw command, user, arg_i_constraint [, ...]
+ chown: PathFilter, /bin/chown, root, nova, /var/lib/images
+
+ """
+
+ def match(self, userargs):
+ command, arguments = userargs[0], userargs[1:]
+
+ equal_args_num = len(self.args) == len(arguments)
+ exec_is_valid = super(PathFilter, self).match(userargs)
+ args_equal_or_pass = all(
+ arg == 'pass' or arg == value
+ for arg, value in zip(self.args, arguments)
+ if not os.path.isabs(arg) # arguments not specifying abs paths
+ )
+ paths_are_within_base_dirs = all(
+ os.path.commonprefix([arg, os.path.realpath(value)]) == arg
+ for arg, value in zip(self.args, arguments)
+ if os.path.isabs(arg) # arguments specifying abs paths
+ )
+
+ return (equal_args_num and
+ exec_is_valid and
+ args_equal_or_pass and
+ paths_are_within_base_dirs)
+
+ def get_command(self, userargs, exec_dirs=[]):
+ command, arguments = userargs[0], userargs[1:]
+
+ # convert path values to canonical ones; copy other args as is
+ args = [os.path.realpath(value) if os.path.isabs(arg) else value
+ for arg, value in zip(self.args, arguments)]
+
+ return super(PathFilter, self).get_command([command] + args,
+ exec_dirs)
+
+
class DnsmasqFilter(CommandFilter):
"""Specific filter for the dnsmasq call (which includes env)"""
diff --git a/nova/openstack/common/rpc/impl_qpid.py b/nova/openstack/common/rpc/impl_qpid.py
index 00f4d0e2a..93d2602dd 100644
--- a/nova/openstack/common/rpc/impl_qpid.py
+++ b/nova/openstack/common/rpc/impl_qpid.py
@@ -331,15 +331,16 @@ class Connection(object):
def reconnect(self):
"""Handles reconnecting and re-establishing sessions and queues"""
- if self.connection.opened():
- try:
- self.connection.close()
- except qpid_exceptions.ConnectionError:
- pass
-
attempt = 0
delay = 1
while True:
+ # Close the session if necessary
+ if self.connection.opened():
+ try:
+ self.connection.close()
+ except qpid_exceptions.ConnectionError:
+ pass
+
broker = self.brokers[attempt % len(self.brokers)]
attempt += 1
diff --git a/tools/install_venv_common.py b/tools/install_venv_common.py
index f0a1722c3..0401a958f 100644
--- a/tools/install_venv_common.py
+++ b/tools/install_venv_common.py
@@ -18,10 +18,13 @@
"""Provides methods needed by installation script for OpenStack development
virtual environments.
+Since this script is used to bootstrap a virtualenv from the system's Python
+environment, it should be kept strictly compatible with Python 2.6.
+
Synced in from openstack-common
"""
-import argparse
+import optparse
import os
import subprocess
import sys
@@ -131,12 +134,12 @@ class InstallVenv(object):
def parse_args(self, argv):
"""Parses command-line arguments."""
- parser = argparse.ArgumentParser()
- parser.add_argument('-n', '--no-site-packages',
- action='store_true',
- help="Do not inherit packages from global Python "
- "install")
- return parser.parse_args(argv[1:])
+ parser = optparse.OptionParser()
+ parser.add_option('-n', '--no-site-packages',
+ action='store_true',
+ help="Do not inherit packages from global Python "
+ "install")
+ return parser.parse_args(argv[1:])[0]
class Distro(InstallVenv):