From: Angus Lees Date: Fri, 28 Nov 2014 01:23:47 +0000 (+1100) Subject: Tighten dnsmasq version regex X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=d51bb9b4d0588d330a1d97dcc8d441c9dac500ae;p=openstack-build%2Fneutron-build.git Tighten dnsmasq version regex 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 --- diff --git a/neutron/agent/linux/dhcp.py b/neutron/agent/linux/dhcp.py index d6ee68c1c..96b6068a2 100644 --- a/neutron/agent/linux/dhcp.py +++ b/neutron/agent/linux/dhcp.py @@ -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): diff --git a/neutron/tests/unit/test_linux_dhcp.py b/neutron/tests/unit/test_linux_dhcp.py index 27b6f3d3e..fdbf83067 100644 --- a/neutron/tests/unit/test_linux_dhcp.py +++ b/neutron/tests/unit/test_linux_dhcp.py @@ -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)