]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Do not require sudo/rootwrap to check for dnsmasq version
authorarmando-migliaccio <amigliaccio@nicira.com>
Fri, 10 May 2013 20:10:02 +0000 (13:10 -0700)
committerarmando-migliaccio <amigliaccio@nicira.com>
Fri, 10 May 2013 21:12:18 +0000 (14:12 -0700)
The dnsmasq version check does not need root privileges
to run as with low privs it works just fine. As a side
effect, the use of the rootwrapper was causing unit tests
to hung because the execute call in check_version was not
being stubbed out. Weirdly enough this wasn't caught in
a previous Gerrit run; there must be a passwordless sudo
lurking around somewhere in the Gerrit infrastructure.

Fixes bug #1178800

Change-Id: I4d0bd218768eec2439d3907587682ff35884a262

etc/quantum/rootwrap.d/dhcp.filters
quantum/agent/dhcp_agent.py
quantum/agent/linux/dhcp.py
quantum/rootwrap/filters.py
quantum/tests/unit/test_linux_dhcp.py

index 1e2150049be43ba98c2dff26228f2ad8450f5a5d..4a4635a263336481691e3d085b40a357eeee549b 100644 (file)
@@ -11,9 +11,7 @@
 # dhcp-agent
 ip_exec_dnsmasq: DnsmasqNetnsFilter, /sbin/ip, root
 dnsmasq: DnsmasqFilter, /sbin/dnsmasq, root
-dnsmasq_ver: DnsmasqVersionFilter, /sbin/dnsmasq, root
 dnsmasq_usr: DnsmasqFilter, /usr/sbin/dnsmasq, root
-dnsmasq_usr_ver: DnsmasqVersionFilter, /usr/sbin/dnsmasq, root
 # dhcp-agent uses kill as well, that's handled by the generic KillFilter
 # it looks like these are the only signals needed, per
 # quantum/agent/linux/dhcp.py
index afe79226b566dcc872aecfa5982fc4deb1a10571..f8f342c41deb1a2310fd40bd98f9e2e423ed4662 100644 (file)
@@ -80,7 +80,7 @@ class DhcpAgent(manager.Manager):
         self.device_manager = DeviceManager(self.conf, self.plugin_rpc)
         self.lease_relay = DhcpLeaseRelay(self.update_lease)
 
-        self.dhcp_driver_cls.check_version(self.root_helper)
+        self.dhcp_driver_cls.check_version()
         self._populate_networks_cache()
 
     def _populate_networks_cache(self):
index 95c9f14edfbe9e114ae1a918204e2a0aa91a70c6..dde040f64bf3677c774ecde8900ae9ed3d3685e6 100644 (file)
@@ -101,7 +101,7 @@ class DhcpBase(object):
         raise NotImplementedError
 
     @classmethod
-    def check_version(cls, root_helper):
+    def check_version(cls):
         """Execute version checks on DHCP server."""
 
         raise NotImplementedError
@@ -224,11 +224,11 @@ class Dnsmasq(DhcpLocalProcess):
     MINIMUM_VERSION = 2.59
 
     @classmethod
-    def check_version(cls, root_helper):
+    def check_version(cls):
         is_valid_version = None
         try:
             cmd = ['dnsmasq', '--version']
-            out = utils.execute(cmd, root_helper)
+            out = utils.execute(cmd)
             ver = re.findall("\d+.\d+", out)[0]
             is_valid_version = float(ver) >= cls.MINIMUM_VERSION
             if not is_valid_version:
@@ -236,7 +236,7 @@ class Dnsmasq(DhcpLocalProcess):
                               'DHCP AGENT MAY NOT RUN CORRECTLY! '
                               'Please ensure that its version is %s '
                               'or above!'), cls.MINIMUM_VERSION)
-        except (RuntimeError, IndexError, ValueError):
+        except (OSError, RuntimeError, IndexError, ValueError):
             LOG.warning(_('Unable to determine dnsmasq version. '
                           'Please ensure that its version is %s '
                           'or above!'), cls.MINIMUM_VERSION)
index 6461369402ae89706cd487dccbd05fbce65932ff..30472452caeabc6b29e758364e876a8c20ee77a5 100644 (file)
@@ -171,12 +171,6 @@ class DnsmasqFilter(CommandFilter):
         return env
 
 
-class DnsmasqVersionFilter(CommandFilter):
-    """Specific filter to check dnsmasq version."""
-    def match(self, userargs):
-        return userargs[0] == "dnsmasq" and userargs[1] == "--version"
-
-
 class DnsmasqNetnsFilter(DnsmasqFilter):
     """Specific filter for the dnsmasq call (which includes env)."""
 
index c5331b169b490f7e54d7e7a362d8ea1136607c4b..7a4426fb6640638a500ed8fe8e9d3750d074ff08 100644 (file)
@@ -142,7 +142,7 @@ class TestDhcpBase(base.BaseTestCase):
 
     def test_check_version_abstract_error(self):
         self.assertRaises(NotImplementedError,
-                          dhcp.DhcpBase.check_version, None)
+                          dhcp.DhcpBase.check_version)
 
     def test_base_abc_error(self):
         self.assertRaises(TypeError, dhcp.DhcpBase, None)
@@ -720,7 +720,7 @@ tag:tag1,option:classless-static-route,%s,%s""".lstrip() % (fake_v6,
     def _check_version(self, cmd_out, expected_value):
         with mock.patch('quantum.agent.linux.utils.execute') as cmd:
             cmd.return_value = cmd_out
-            result = dhcp.Dnsmasq.check_version('sudo')
+            result = dhcp.Dnsmasq.check_version()
             self.assertEqual(result, expected_value)
 
     def test_check_minimum_version(self):