]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Add DNS and DHCP log into dhcp agent
authorchangzhi <changzhi@unitedstack.com>
Fri, 17 Jul 2015 02:43:09 +0000 (10:43 +0800)
committerchangzhi <changzhi@unitedstack.com>
Mon, 3 Aug 2015 08:10:20 +0000 (16:10 +0800)
Enable set DNS and DHCP log of dnsmasq for dhcp agent
Add a new configuration named 'dnsmasq_base_log_dir'
in dhcp_agent.ini.

This entry should be a path of log file. It should
like this:

    dnsmasq_base_log_dir=/tmp

And the DNS and DHCP log will be written into the file
"/tmp/aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa/dhcp_dns_log".
The dir path will be created if the given path doesn't exists.

DocImpact

Closes-Bug: #1475636
Change-Id: I87be346ec5059eaa8a29f48fe53933af82d1b155

etc/dhcp_agent.ini
neutron/agent/dhcp/config.py
neutron/agent/linux/dhcp.py
neutron/tests/unit/agent/linux/test_dhcp.py

index 0f56260f4c27b9fdf31e8bef38d28ac7d98f1e35..115ff86a297b05a735ec33ad421cd6387598b4fe 100644 (file)
 # 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
 
index d00a2fad6a4bb239a7dc89b64495bb51eb4c1acc..eefac85d449c78f90a799879c2b891c0e354ab62 100644 (file)
@@ -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),
index 0a06259c1a0d948b4fbab130a00c560dd5e16a1e..15fab0f594e664a9ecaf4f3b3badbf132198ef8b 100644 (file)
@@ -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):
index 41a3173d1f4eee7eb1ac923e9bdfb2d5db916730..ce9587066ccaaba325233eddf50cfa584dc7bd44 100644 (file)
@@ -1001,6 +1001,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'],