Merge "Make nova-dhcpbridge use CONFIG_FILE over FLAGFILE"

This commit is contained in:
Jenkins 2012-11-26 17:31:01 +00:00 committed by Gerrit Code Review
commit 1417218f43
3 changed files with 25 additions and 8 deletions

View File

@ -95,8 +95,11 @@ def init_leases(network_id):
def main(): def main():
"""Parse environment and arguments and call the approproate action.""" """Parse environment and arguments and call the approproate action."""
argv = config.parse_args(sys.argv, try:
default_config_files=[os.environ['FLAGFILE']]) config_file = os.environ['CONFIG_FILE']
except KeyError:
config_file = os.environ['FLAGFILE']
argv = config.parse_args(sys.argv, default_config_files=[config_file])
logging.setup("nova") logging.setup("nova")
if int(os.environ.get('TESTING', '0')): if int(os.environ.get('TESTING', '0')):

View File

@ -72,9 +72,11 @@ class RegExpFilter(CommandFilter):
class DnsmasqFilter(CommandFilter): class DnsmasqFilter(CommandFilter):
"""Specific filter for the dnsmasq call (which includes env)""" """Specific filter for the dnsmasq call (which includes env)"""
CONFIG_FILE_ARG = 'CONFIG_FILE'
def match(self, userargs): def match(self, userargs):
if (userargs[0] == 'env' and if (userargs[0] == 'env' and
userargs[1].startswith('FLAGFILE=') and userargs[1].startswith(self.CONFIG_FILE_ARG) and
userargs[2].startswith('NETWORK_ID=') and userargs[2].startswith('NETWORK_ID=') and
userargs[3] == 'dnsmasq'): userargs[3] == 'dnsmasq'):
return True return True
@ -86,11 +88,16 @@ class DnsmasqFilter(CommandFilter):
def get_environment(self, userargs): def get_environment(self, userargs):
env = os.environ.copy() env = os.environ.copy()
env['FLAGFILE'] = userargs[1].split('=')[-1] env[self.CONFIG_FILE_ARG] = userargs[1].split('=')[-1]
env['NETWORK_ID'] = userargs[2].split('=')[-1] env['NETWORK_ID'] = userargs[2].split('=')[-1]
return env return env
class DeprecatedDnsmasqFilter(DnsmasqFilter):
"""Variant of dnsmasq filter to support old-style FLAGFILE"""
CONFIG_FILE_ARG = 'FLAGFILE'
class KillFilter(CommandFilter): class KillFilter(CommandFilter):
"""Specific filter for the kill calls. """Specific filter for the kill calls.
1st argument is the user to run /bin/kill under 1st argument is the user to run /bin/kill under

View File

@ -54,15 +54,22 @@ class RootwrapTestCase(test.TestCase):
filtermatch = wrapper.match_filter(self.filters, invalid) filtermatch = wrapper.match_filter(self.filters, invalid)
self.assertTrue(filtermatch is None) self.assertTrue(filtermatch is None)
def test_DnsmasqFilter(self): def _test_DnsmasqFilter(self, filter_class, config_file_arg):
usercmd = ['env', 'FLAGFILE=A', 'NETWORK_ID=foobar', 'dnsmasq', 'foo'] usercmd = ['env', config_file_arg + '=A', 'NETWORK_ID=foobar',
f = filters.DnsmasqFilter("/usr/bin/dnsmasq", "root") 'dnsmasq', 'foo']
f = filter_class("/usr/bin/dnsmasq", "root")
self.assertTrue(f.match(usercmd)) self.assertTrue(f.match(usercmd))
self.assertEqual(f.get_command(usercmd), ['/usr/bin/dnsmasq', 'foo']) self.assertEqual(f.get_command(usercmd), ['/usr/bin/dnsmasq', 'foo'])
env = f.get_environment(usercmd) env = f.get_environment(usercmd)
self.assertEqual(env.get('FLAGFILE'), 'A') self.assertEqual(env.get(config_file_arg), 'A')
self.assertEqual(env.get('NETWORK_ID'), 'foobar') self.assertEqual(env.get('NETWORK_ID'), 'foobar')
def test_DnsmasqFilter(self):
self._test_DnsmasqFilter(filters.DnsmasqFilter, 'CONFIG_FILE')
def test_DeprecatedDnsmasqFilter(self):
self._test_DnsmasqFilter(filters.DeprecatedDnsmasqFilter, 'FLAGFILE')
def test_KillFilter(self): def test_KillFilter(self):
if not os.path.exists("/proc/%d" % os.getpid()): if not os.path.exists("/proc/%d" % os.getpid()):
self.skipTest("Test requires /proc filesystem (procfs)") self.skipTest("Test requires /proc filesystem (procfs)")