]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Log dnsmasq host file generation
authorIan Wienand <iwienand@redhat.com>
Wed, 12 Mar 2014 04:37:56 +0000 (15:37 +1100)
committerIan Wienand <iwienand@redhat.com>
Wed, 19 Mar 2014 23:20:10 +0000 (10:20 +1100)
We've been seeing things that appear to be races between the hosts
files being written out for dnsmasq and dhcp requests coming in.  We
will get occasional errors from dnsmasq saying "no address available",
"duplicate IP address" but by the time you look, the corresponding
host file has long since been replaced.

If we had some debugging like this, we could at least correlate what
neutron thought dnsmasq knew at the time the requests were coming in.

We store the filename to avoid multiple lookups, and also
s/name/filename/ to avoid ambiguity and be more consistent with the
rest of the code.

Closes-Bug: #1294892
Change-Id: Ifa92ca71419ce0155b28d2015eff9e82557a0825

neutron/agent/linux/dhcp.py

index eefba2ec702d5e3027953fe0d897a7ac07e15582..a741d0d2020634ae24eebaa72bf94e7a1547e99d 100644 (file)
@@ -403,6 +403,9 @@ class Dnsmasq(DhcpLocalProcess):
         """Writes a dnsmasq compatible hosts file."""
         r = re.compile('[:.]')
         buf = six.StringIO()
+        filename = self.get_conf_file_name('host')
+
+        LOG.debug(_('Building host file: %s'), filename)
 
         for port in self.network.ports:
             for alloc in port.fixed_ips:
@@ -415,6 +418,11 @@ class Dnsmasq(DhcpLocalProcess):
                 ip_address = alloc.ip_address
                 if netaddr.valid_ipv6(ip_address):
                     ip_address = '[%s]' % ip_address
+
+                LOG.debug(_('Adding %(mac)s : %(name)s : %(ip)s'),
+                          {"mac": port.mac_address, "name": name,
+                           "ip": ip_address})
+
                 if getattr(port, 'extra_dhcp_opts', False):
                     if self.version >= self.MINIMUM_VERSION:
                         set_tag = 'set:'
@@ -426,9 +434,9 @@ class Dnsmasq(DhcpLocalProcess):
                     buf.write('%s,%s,%s\n' %
                               (port.mac_address, name, ip_address))
 
-        name = self.get_conf_file_name('host')
-        utils.replace_file(name, buf.getvalue())
-        return name
+        utils.replace_file(filename, buf.getvalue())
+        LOG.debug(_('Done building host file %s'), filename)
+        return filename
 
     def _read_hosts_file_leases(self, filename):
         leases = set()