]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Dnsmasq config files syntax issue when dhcp_domain is empty
authorBertrand Lallau <bertrand.lallau@thalesgroup.com>
Wed, 11 Jun 2014 13:46:58 +0000 (15:46 +0200)
committerBertrand Lallau <bertrand.lallau@thalesgroup.com>
Tue, 15 Jul 2014 12:44:21 +0000 (14:44 +0200)
When using dhcp-agent with the following property dhcp_domain=""
addn_hosts and host files genererated for Dnsmasq have wrong syntax
concerning hostname parameter (dot char at the end).

As described in RFC-952 the hostname grammar is as follows:
<hname> ::= <name>*["."<name>]
<name>  ::= <let>[*[<let-or-digit-or-hyphen>]<let-or-digit>]
Hence it can't be conclude with a dot char.

Dnsmasq process is waiting for a hostname (2nd parameter) in the
following files:
"addn_hosts" file contains:
   20.0.0.3 host-20-0-0-3. host-20-0-0-3
"host" file contains:
   fa:16:3e:bf:e1:e4,host-20-0-0-3.,20.0.0.3

With the patch you will get:
"addn_hosts":
   20.0.0.3 host-20-0-0-3 host-20-0-0-3
"host":
   fa:16:3e:bf:e1:e4,host-20-0-0-3,20.0.0.3

Change-Id: I4c10169019becaed6b2968b74f03ef356244a057
Closes-Bug: #1326256

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

index 7ea1cdb938171743681adaf20ca3aee70195ca62..266c125a2a70feeba75c4dd983762ac6f13d83a0 100644 (file)
@@ -454,7 +454,7 @@ class Dnsmasq(DhcpLocalProcess):
             port,  # a DictModel instance representing the port.
             alloc,  # a DictModel instance of the allocated ip and subnet.
             host_name,  # Host name.
-            name,  # Host name and domain name in the format 'hostname.domain'.
+            name,  # Canonical hostname in the format 'hostname[.domain]'.
         )
         """
         v6_nets = dict((subnet.id, subnet) for subnet in
@@ -471,7 +471,9 @@ class Dnsmasq(DhcpLocalProcess):
                         continue
                 hostname = 'host-%s' % alloc.ip_address.replace(
                     '.', '-').replace(':', '-')
-                fqdn = '%s.%s' % (hostname, self.conf.dhcp_domain)
+                fqdn = hostname
+                if self.conf.dhcp_domain:
+                    fqdn = '%s.%s' % (fqdn, self.conf.dhcp_domain)
                 yield (port, alloc, hostname, fqdn)
 
     def _output_hosts_file(self):
index 14b80c792192bc119257fb10618fd73230786037..a7c9671fc1b894e9cf39241627f81537c74d3905 100644 (file)
@@ -767,8 +767,12 @@ class TestDnsmasq(TestBase):
         self._test_spawn(['--conf-file=/foo', '--domain=openstacklocal'])
 
     def test_spawn_no_dhcp_domain(self):
+        (exp_host_name, exp_host_data,
+         exp_addn_name, exp_addn_data) = self._test_no_dhcp_domain_alloc_data
         self.conf.set_override('dhcp_domain', '')
         self._test_spawn(['--conf-file='])
+        self.safe.assert_has_calls([mock.call(exp_host_name, exp_host_data),
+                                    mock.call(exp_addn_name, exp_addn_data)])
 
     def test_spawn_no_dnsmasq_ipv6_mode(self):
         network = FakeV6Network()
@@ -1062,6 +1066,38 @@ tag:tag0,option:router""".lstrip()
 
         self.safe.assert_called_once_with('/foo/opts', expected)
 
+    @property
+    def _test_no_dhcp_domain_alloc_data(self):
+        exp_host_name = '/dhcp/cccccccc-cccc-cccc-cccc-cccccccccccc/host'
+        exp_host_data = ('00:00:80:aa:bb:cc,host-192-168-0-2,'
+                         '192.168.0.2\n'
+                         '00:00:f3:aa:bb:cc,host-fdca-3ba5-a17a-4ba3--2,'
+                         '[fdca:3ba5:a17a:4ba3::2]\n'
+                         '00:00:0f:aa:bb:cc,host-192-168-0-3,'
+                         '192.168.0.3\n'
+                         '00:00:0f:aa:bb:cc,host-fdca-3ba5-a17a-4ba3--3,'
+                         '[fdca:3ba5:a17a:4ba3::3]\n'
+                         '00:00:0f:rr:rr:rr,host-192-168-0-1,'
+                         '192.168.0.1\n').lstrip()
+        exp_addn_name = '/dhcp/cccccccc-cccc-cccc-cccc-cccccccccccc/addn_hosts'
+        exp_addn_data = (
+            '192.168.0.2\t'
+            'host-192-168-0-2 host-192-168-0-2\n'
+            'fdca:3ba5:a17a:4ba3::2\t'
+            'host-fdca-3ba5-a17a-4ba3--2 '
+            'host-fdca-3ba5-a17a-4ba3--2\n'
+            '192.168.0.3\thost-192-168-0-3 '
+            'host-192-168-0-3\n'
+            'fdca:3ba5:a17a:4ba3::3\t'
+            'host-fdca-3ba5-a17a-4ba3--3 '
+            'host-fdca-3ba5-a17a-4ba3--3\n'
+            '192.168.0.1\t'
+            'host-192-168-0-1 '
+            'host-192-168-0-1\n'
+        ).lstrip()
+        return (exp_host_name, exp_host_data,
+                exp_addn_name, exp_addn_data)
+
     @property
     def _test_reload_allocation_data(self):
         exp_host_name = '/dhcp/cccccccc-cccc-cccc-cccc-cccccccccccc/host'