summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Laski <andrew.laski@rackspace.com>2012-10-30 16:54:41 -0400
committerAndrew Laski <andrew.laski@rackspace.com>2012-10-30 21:30:58 -0400
commit1d7d733d017c0a8fe2f171d9822d752ff72d9fc6 (patch)
tree44892d6a03671cff053586e2dd2247dcc017e9a3
parent7aea941005deda6f057e1e1692018d81c4aebcdc (diff)
downloadnova-1d7d733d017c0a8fe2f171d9822d752ff72d9fc6.tar.gz
nova-1d7d733d017c0a8fe2f171d9822d752ff72d9fc6.tar.xz
nova-1d7d733d017c0a8fe2f171d9822d752ff72d9fc6.zip
Use env to set environ when starting dnsmasq
Explictly use env to setup needed environment variables for dnsmasq when starting to avoid problems with subprocess mis-interpreting the first command line argument as the executable name. Also update DnsmasqFilter to accept any command that starts with env followed by a set of args that include an equals sign, as long as the next arg is the dnsmasq command. fixes bug #1073253 Change-Id: I8ac08ba2d2309934a67ed2cb28049ed5d3277d63
-rw-r--r--nova/network/linux_net.py3
-rw-r--r--nova/rootwrap/filters.py14
-rw-r--r--nova/tests/test_nova_rootwrap.py2
3 files changed, 11 insertions, 8 deletions
diff --git a/nova/network/linux_net.py b/nova/network/linux_net.py
index 66156914c..9aafc50a1 100644
--- a/nova/network/linux_net.py
+++ b/nova/network/linux_net.py
@@ -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',
diff --git a/nova/rootwrap/filters.py b/nova/rootwrap/filters.py
index fc130139f..52808d9ec 100644
--- a/nova/rootwrap/filters.py
+++ b/nova/rootwrap/filters.py
@@ -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
diff --git a/nova/tests/test_nova_rootwrap.py b/nova/tests/test_nova_rootwrap.py
index f67f2f56c..dc615bf5d 100644
--- a/nova/tests/test_nova_rootwrap.py
+++ b/nova/tests/test_nova_rootwrap.py
@@ -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'])