diff --git a/neutron/agent/linux/dhcp.py b/neutron/agent/linux/dhcp.py index 55509cb84b2..f594b775c0f 100644 --- a/neutron/agent/linux/dhcp.py +++ b/neutron/agent/linux/dhcp.py @@ -483,6 +483,8 @@ class Dnsmasq(DhcpLocalProcess): LOG.debug('Building host file: %s', filename) dhcp_enabled_subnet_ids = [s.id for s in self.network.subnets if s.enable_dhcp] + # NOTE(ihrachyshka): the loop should not log anything inside it, to + # avoid potential performance drop when lots of hosts are dumped for (port, alloc, hostname, name) in self._iter_hosts(): if not alloc: if getattr(port, 'extra_dhcp_opts', False): diff --git a/neutron/tests/unit/agent/linux/test_dhcp.py b/neutron/tests/unit/agent/linux/test_dhcp.py index 09a91a7caa5..fca35c1bb8b 100644 --- a/neutron/tests/unit/agent/linux/test_dhcp.py +++ b/neutron/tests/unit/agent/linux/test_dhcp.py @@ -1403,6 +1403,16 @@ class TestDnsmasq(TestBase): 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb'], sorted(result)) + def test__output_hosts_file_log_only_twice(self): + dm = self._get_dnsmasq(FakeDualStackNetworkSingleDHCP()) + with mock.patch.object(dhcp.LOG, 'process') as process: + process.return_value = ('fake_message', {}) + dm._output_hosts_file() + # The method logs twice, at the start of and the end. There should be + # no other logs, no matter how many hosts there are to dump in the + # file. + self.assertEqual(2, process.call_count) + def test_only_populates_dhcp_enabled_subnets(self): exp_host_name = '/dhcp/eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee/host' exp_host_data = ('00:00:80:aa:bb:cc,host-192-168-0-2.openstacklocal,'