Merge "Relax default strict option under python3.x for configparser"

This commit is contained in:
Jenkins 2016-12-23 05:00:55 +00:00 committed by Gerrit Code Review
commit 698ce0b516
2 changed files with 15 additions and 1 deletions

View File

@ -44,6 +44,18 @@ class RootwrapLoaderTestCase(testtools.TestCase):
self.assertEqual(["/fake/privsep-helper", "--context", "foo"],
filtermatch.get_command(privsep))
def test_strict_switched_off_in_configparser(self):
temp_dir = self.useFixture(fixtures.TempDir()).path
temp_file = os.path.join(temp_dir, 'test.conf')
f = open(temp_file, 'w')
f.write("""[Filters]
privsep: PathFilter, privsep-helper, root
privsep: PathFilter, privsep-helper, root
""")
f.close()
filterlist = wrapper.load_filters([temp_dir])
self.assertIsNotNone(filterlist)
class RootwrapTestCase(testtools.TestCase):
if os.path.exists('/sbin/ip'):

View File

@ -19,6 +19,7 @@ import os
import pwd
import signal
import six
from six import moves
from oslo_rootwrap import filters
@ -116,7 +117,8 @@ def load_filters(filters_path):
continue
for filterfile in filter(lambda f: not f.startswith('.'),
os.listdir(filterdir)):
filterconfig = moves.configparser.RawConfigParser()
kwargs = {"strict": False} if six.PY3 else {}
filterconfig = moves.configparser.RawConfigParser(**kwargs)
filterconfig.read(os.path.join(filterdir, filterfile))
for (name, value) in filterconfig.items("Filters"):
filterdefinition = [s.strip() for s in value.split(',')]