Skip to content

Commit

Permalink
Tighten dnsmasq version regex
Browse files Browse the repository at this point in the history
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
  • Loading branch information
anguslees committed Dec 23, 2014
1 parent 98cd893 commit d51bb9b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 4 additions & 4 deletions neutron/agent/linux/dhcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,9 @@ def check_version(cls):
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 '
Expand All @@ -336,7 +336,7 @@ def check_version(cls):
'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):
Expand Down
6 changes: 6 additions & 0 deletions neutron/tests/unit/test_linux_dhcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1308,6 +1308,12 @@ def _check_version(self, cmd_out, expected_value):
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)
Expand Down

0 comments on commit d51bb9b

Please sign in to comment.