]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Sync rootwrap with code from oslo
authorZhongyue Luo <zhongyue.nah@intel.com>
Tue, 24 Sep 2013 01:50:32 +0000 (09:50 +0800)
committerZhongyue Luo <zhongyue.nah@intel.com>
Thu, 26 Sep 2013 00:33:27 +0000 (08:33 +0800)
The rootwrap module had been directly edited in commit 1d366293.
These are all minor changes bringing neutron up to commit c03f247

c03f247 Skip hidden files while traversion rootwrap filters
3f4d1d5 Fix os.getlogin() problem with no tty
fc04531 Send rootwrap exit error message to stderr
3663010 rootwrap: improve Python 3 compatibility
28395d9 Fixes files with wrong bitmode

Fixes bug #1229492

Change-Id: Ica406e021700578b27c3337498011059c3a78719

neutron/openstack/common/rootwrap/cmd.py
neutron/openstack/common/rootwrap/wrapper.py

index 3ac8c5b23f67198e269ddd7eb135d9fd3e0a3b10..aa47507162c4b4bfb90d293e47c7687b0030c9b6 100644 (file)
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
 # vim: tabstop=4 shiftwidth=4 softtabstop=4
 
 # Copyright (c) 2011 OpenStack Foundation.
@@ -57,12 +56,21 @@ def _subprocess_setup():
 
 
 def _exit_error(execname, message, errorcode, log=True):
-    print("%s: %s" % (execname, message))
+    print("%s: %s" % (execname, message), file=sys.stderr)
     if log:
         logging.error(message)
     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():
     # Split arguments, require at least a command
     execname = sys.argv.pop(0)
@@ -107,7 +115,7 @@ def main():
                                               exec_dirs=config.exec_dirs)
             if config.use_syslog:
                 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))
 
             obj = subprocess.Popen(command,
index 16e3fbb39006fd530e5575e2f7d65590957e5700..5786ac37777905977c2a19feb70a4dff5a867d45 100644 (file)
 #    under the License.
 
 
-import ConfigParser
 import logging
 import logging.handlers
 import os
 import string
 
+from six import moves
+
 from neutron.openstack.common.rootwrap import filters
 
 
@@ -107,8 +108,9 @@ def load_filters(filters_path):
     for filterdir in filters_path:
         if not os.path.isdir(filterdir):
             continue
-        for filterfile in os.listdir(filterdir):
-            filterconfig = ConfigParser.RawConfigParser()
+        for filterfile in filter(lambda f: not f.startswith('.'),
+                                 os.listdir(filterdir)):
+            filterconfig = moves.configparser.RawConfigParser()
             filterconfig.read(os.path.join(filterdir, filterfile))
             for (name, value) in filterconfig.items("Filters"):
                 filterdefinition = [string.strip(s) for s in value.split(',')]