diff --git a/etc/dhcp_agent.ini b/etc/dhcp_agent.ini index 0f56260f4c2..115ff86a297 100644 --- a/etc/dhcp_agent.ini +++ b/etc/dhcp_agent.ini @@ -68,6 +68,11 @@ # as forwarders. # dnsmasq_dns_servers = +# Base log dir for dnsmasq logging. The log contains DHCP and DNS log +# information and is useful for debugging issues with either DHCP or DNS. +# If this section is null, disable dnsmasq log. +# dnsmasq_base_log_dir = + # Limit number of leases to prevent a denial-of-service. # dnsmasq_lease_max = 16777216 diff --git a/neutron/agent/dhcp/config.py b/neutron/agent/dhcp/config.py index d00a2fad6a4..eefac85d449 100644 --- a/neutron/agent/dhcp/config.py +++ b/neutron/agent/dhcp/config.py @@ -54,6 +54,11 @@ DNSMASQ_OPTS = [ "This option is deprecated and " "will be removed in a future release."), deprecated_for_removal=True), + cfg.StrOpt('dnsmasq_base_log_dir', + help=_("Base log dir for dnsmasq logging. " + "The log contains DHCP and DNS log information and " + "is useful for debugging issues with either DHCP or " + "DNS. If this section is null, disable dnsmasq log.")), cfg.IntOpt( 'dnsmasq_lease_max', default=(2 ** 24), diff --git a/neutron/agent/linux/dhcp.py b/neutron/agent/linux/dhcp.py index efdf12fa3f8..597f460b58a 100644 --- a/neutron/agent/linux/dhcp.py +++ b/neutron/agent/linux/dhcp.py @@ -36,7 +36,7 @@ from neutron.common import exceptions from neutron.common import ipv6_utils from neutron.common import utils as commonutils from neutron.extensions import extra_dhcp_opt as edo_ext -from neutron.i18n import _LI, _LW +from neutron.i18n import _LI, _LW, _LE LOG = logging.getLogger(__name__) @@ -379,6 +379,20 @@ class Dnsmasq(DhcpLocalProcess): if self.conf.dhcp_broadcast_reply: cmd.append('--dhcp-broadcast') + if self.conf.dnsmasq_base_log_dir: + try: + if not os.path.exists(self.conf.dnsmasq_base_log_dir): + os.makedirs(self.conf.dnsmasq_base_log_dir) + log_filename = os.path.join( + self.conf.dnsmasq_base_log_dir, + self.network.id, 'dhcp_dns_log') + cmd.append('--log-queries') + cmd.append('--log-dhcp') + cmd.append('--log-facility=%s' % log_filename) + except OSError: + LOG.error(_LE('Error while create dnsmasq base log dir: %s'), + self.conf.dnsmasq_base_log_dir) + return cmd def spawn_process(self): diff --git a/neutron/tests/unit/agent/linux/test_dhcp.py b/neutron/tests/unit/agent/linux/test_dhcp.py index 2a306f12e94..61f4ea66ef8 100644 --- a/neutron/tests/unit/agent/linux/test_dhcp.py +++ b/neutron/tests/unit/agent/linux/test_dhcp.py @@ -1054,6 +1054,19 @@ class TestDnsmasq(TestBase): '--server=9.9.9.9', '--domain=openstacklocal']) + def test_spawn_cfg_enable_dnsmasq_log(self): + self.conf.set_override('dnsmasq_base_log_dir', '/tmp') + network = FakeV4Network() + dhcp_dns_log = \ + '/tmp/aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa/dhcp_dns_log' + + self._test_spawn(['--conf-file=', + '--domain=openstacklocal', + '--log-queries', + '--log-dhcp', + ('--log-facility=%s' % dhcp_dns_log)], + network) + def test_spawn_max_leases_is_smaller_than_cap(self): self._test_spawn( ['--conf-file=', '--domain=openstacklocal'],