Skip to content

Commit

Permalink
Update oslo-incubator import.
Browse files Browse the repository at this point in the history
These are all minor changes bringing nova up to commit
90e83530d4dc49d570fa05ea63a93805717dcfa0 in oslo-incubator.

Change-Id: I0291eed31b1e650da211fe2a8b65fad0c35c9053
  • Loading branch information
mikalstill committed May 2, 2013
1 parent 8bb1cc2 commit b4826d8
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 29 deletions.
4 changes: 2 additions & 2 deletions nova/openstack/common/db/sqlalchemy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]))

Expand Down
49 changes: 35 additions & 14 deletions nova/openstack/common/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import logging.config
import logging.handlers
import os
import stat
import sys
import traceback

Expand Down Expand Up @@ -104,10 +103,7 @@
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 = [
Expand Down Expand Up @@ -211,16 +207,37 @@ 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):
self.logger = logger
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
Expand Down Expand Up @@ -340,7 +357,7 @@ def __str__(self):
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))


Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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."""

Expand Down
46 changes: 46 additions & 0 deletions nova/openstack/common/rootwrap/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,52 @@ def match(self, userargs):
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)"""

Expand Down
13 changes: 7 additions & 6 deletions nova/openstack/common/rpc/impl_qpid.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,15 +331,16 @@ def _lookup_consumer(self, receiver):

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

Expand Down
17 changes: 10 additions & 7 deletions tools/install_venv_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -131,12 +134,12 @@ def post_process(self):

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):
Expand Down

0 comments on commit b4826d8

Please sign in to comment.