]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Tighten dnsmasq version regex
authorAngus Lees <gus@inodes.org>
Fri, 28 Nov 2014 01:23:47 +0000 (12:23 +1100)
committerAngus Lees <gus@inodes.org>
Tue, 23 Dec 2014 03:53:02 +0000 (14:53 +1100)
The previous regex forgot to escape the '.', resulting a more liberal
match than intended.  Luckily it continued to work, since the dnsmasq
version is the first number that appears in the --version output.

This change improves the regex to correctly escape the '.' (as
presumably originally intended) and to look for the prefix "version ".

Change-Id: I12548a7b2c21262aa54c84be4e31bda15eab8d52

neutron/agent/linux/dhcp.py
neutron/tests/unit/test_linux_dhcp.py

index d6ee68c1c74b49dee22a64ed36f13b494462bc8f..96b6068a218e2de869769d7a4c0f858705f14825 100644 (file)
@@ -323,9 +323,9 @@ class Dnsmasq(DhcpLocalProcess):
         try:
             cmd = ['dnsmasq', '--version']
             out = utils.execute(cmd)
-            ver = re.findall("\d+.\d+", out)[0]
-            is_valid_version = float(ver) >= cls.MINIMUM_VERSION
-            if not is_valid_version:
+            m = re.search(r"version (\d+\.\d+)", out)
+            ver = float(m.group(1)) if m else 0
+            if ver < cls.MINIMUM_VERSION:
                 LOG.error(_LE('FAILED VERSION REQUIREMENT FOR DNSMASQ. '
                               'DHCP AGENT MAY NOT RUN CORRECTLY! '
                               'Please ensure that its version is %s '
@@ -336,7 +336,7 @@ class Dnsmasq(DhcpLocalProcess):
                           'Please ensure that its version is %s '
                           'or above!'), cls.MINIMUM_VERSION)
             raise SystemExit(1)
-        return float(ver)
+        return ver
 
     @classmethod
     def existing_dhcp_networks(cls, conf, root_helper):
index 27b6f3d3ec5cd32e06f7b1f88b00c9d83d767b35..fdbf83067a8d9d47eb8b1fa4542434f0c7cc0cd7 100644 (file)
@@ -1308,6 +1308,12 @@ class TestDnsmasq(TestBase):
             result = dhcp.Dnsmasq.check_version()
             self.assertEqual(result, expected_value)
 
+    def test_check_find_version(self):
+        # Dnsmasq output currently gives the version number before the
+        # copyright year, but just in case ...
+        self._check_version('Copyright 2000-2014. Dnsmasq version 2.65 ...',
+                            float(2.65))
+
     def test_check_minimum_version(self):
         self._check_version('Dnsmasq version 2.63 Copyright (c)...',
                             dhcp.Dnsmasq.MINIMUM_VERSION)