Merge "Sync rootwrap with code from oslo"

This commit is contained in:
Jenkins 2013-09-27 03:27:22 +00:00 committed by Gerrit Code Review
commit 0a84f0c1e6
2 changed files with 16 additions and 6 deletions

View File

@ -1,4 +1,3 @@
#!/usr/bin/env python
# vim: tabstop=4 shiftwidth=4 softtabstop=4 # vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright (c) 2011 OpenStack Foundation. # Copyright (c) 2011 OpenStack Foundation.
@ -57,12 +56,21 @@ def _subprocess_setup():
def _exit_error(execname, message, errorcode, log=True): def _exit_error(execname, message, errorcode, log=True):
print("%s: %s" % (execname, message)) print("%s: %s" % (execname, message), file=sys.stderr)
if log: if log:
logging.error(message) logging.error(message)
sys.exit(errorcode) sys.exit(errorcode)
def _getlogin():
try:
return os.getlogin()
except OSError:
return (os.getenv('USER') or
os.getenv('USERNAME') or
os.getenv('LOGNAME'))
def main(): def main():
# Split arguments, require at least a command # Split arguments, require at least a command
execname = sys.argv.pop(0) execname = sys.argv.pop(0)
@ -107,7 +115,7 @@ def main():
exec_dirs=config.exec_dirs) exec_dirs=config.exec_dirs)
if config.use_syslog: if config.use_syslog:
logging.info("(%s > %s) Executing %s (filter match = %s)" % ( logging.info("(%s > %s) Executing %s (filter match = %s)" % (
os.getlogin(), pwd.getpwuid(os.getuid())[0], _getlogin(), pwd.getpwuid(os.getuid())[0],
command, filtermatch.name)) command, filtermatch.name))
obj = subprocess.Popen(command, obj = subprocess.Popen(command,

View File

@ -16,12 +16,13 @@
# under the License. # under the License.
import ConfigParser
import logging import logging
import logging.handlers import logging.handlers
import os import os
import string import string
from six import moves
from neutron.openstack.common.rootwrap import filters from neutron.openstack.common.rootwrap import filters
@ -107,8 +108,9 @@ def load_filters(filters_path):
for filterdir in filters_path: for filterdir in filters_path:
if not os.path.isdir(filterdir): if not os.path.isdir(filterdir):
continue continue
for filterfile in os.listdir(filterdir): for filterfile in filter(lambda f: not f.startswith('.'),
filterconfig = ConfigParser.RawConfigParser() os.listdir(filterdir)):
filterconfig = moves.configparser.RawConfigParser()
filterconfig.read(os.path.join(filterdir, filterfile)) filterconfig.read(os.path.join(filterdir, filterfile))
for (name, value) in filterconfig.items("Filters"): for (name, value) in filterconfig.items("Filters"):
filterdefinition = [string.strip(s) for s in value.split(',')] filterdefinition = [string.strip(s) for s in value.split(',')]