From 3666dcf76dd8cf7a22743e407343b528331130f7 Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Wed, 12 Mar 2014 15:37:56 +1100 Subject: [PATCH] Log dnsmasq host file generation 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 | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/neutron/agent/linux/dhcp.py b/neutron/agent/linux/dhcp.py index eefba2ec7..a741d0d20 100644 --- a/neutron/agent/linux/dhcp.py +++ b/neutron/agent/linux/dhcp.py @@ -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() -- 2.45.2