Merge "Use env to set environ when starting dnsmasq"

This commit is contained in:
Jenkins 2012-10-31 18:27:15 +00:00 committed by Gerrit Code Review
commit a93f67c2ac
3 changed files with 11 additions and 8 deletions

View File

@ -831,7 +831,8 @@ def restart_dhcp(context, dev, network_ref):
else:
LOG.debug(_('Pid %d is stale, relaunching dnsmasq'), pid)
cmd = ['FLAGFILE=%s' % FLAGS.dhcpbridge_flagfile,
cmd = ['env',
'FLAGFILE=%s' % FLAGS.dhcpbridge_flagfile,
'NETWORK_ID=%s' % str(network_ref['id']),
'dnsmasq',
'--strict-order',

View File

@ -73,19 +73,21 @@ class DnsmasqFilter(CommandFilter):
"""Specific filter for the dnsmasq call (which includes env)"""
def match(self, userargs):
if (userargs[0].startswith("FLAGFILE=") and
userargs[1].startswith("NETWORK_ID=") and
userargs[2] == "dnsmasq"):
if (userargs[0] == 'env' and
userargs[1].startswith('FLAGFILE=') and
userargs[2].startswith('NETWORK_ID=') and
userargs[3] == 'dnsmasq'):
return True
return False
def get_command(self, userargs):
return [self.exec_path] + userargs[3:]
dnsmasq_pos = userargs.index('dnsmasq')
return [self.exec_path] + userargs[dnsmasq_pos + 1:]
def get_environment(self, userargs):
env = os.environ.copy()
env['FLAGFILE'] = userargs[0].split('=')[-1]
env['NETWORK_ID'] = userargs[1].split('=')[-1]
env['FLAGFILE'] = userargs[1].split('=')[-1]
env['NETWORK_ID'] = userargs[2].split('=')[-1]
return env

View File

@ -55,7 +55,7 @@ class RootwrapTestCase(test.TestCase):
self.assertTrue(filtermatch is None)
def test_DnsmasqFilter(self):
usercmd = ['FLAGFILE=A', 'NETWORK_ID=foobar', 'dnsmasq', 'foo']
usercmd = ['env', 'FLAGFILE=A', 'NETWORK_ID=foobar', 'dnsmasq', 'foo']
f = filters.DnsmasqFilter("/usr/bin/dnsmasq", "root")
self.assertTrue(f.match(usercmd))
self.assertEqual(f.get_command(usercmd), ['/usr/bin/dnsmasq', 'foo'])