]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
tests: confirm that _output_hosts_file does not log too often
authorIhar Hrachyshka <ihrachys@redhat.com>
Mon, 20 Apr 2015 15:06:38 +0000 (17:06 +0200)
committerIhar Hrachyshka <ihrachys@redhat.com>
Tue, 21 Apr 2015 16:53:28 +0000 (18:53 +0200)
I3ad7864eeb2f959549ed356a1e34fa18804395cc didn't include any regression unit
tests to validate that the method won't ever log too often again,
reintroducing performance drop in later patches. It didn't play well
with stable backports of the fix, where context was lost when doing the
backport, that left the bug unfixed in stable/juno even though the patch
was merged there [1].

The patch adds an explicit note in the code that suggests not to add new
log messages inside the loop to avoid regression, and a unit test was
added to capture it.

Once the test is merged in master, it will be proposed for stable/juno
inclusion, with additional changes that would fix the regression again.

Related-Bug: #1414218
Change-Id: I5d43021932d6a994638c348eda277dd8337cf041

neutron/agent/linux/dhcp.py
neutron/tests/unit/agent/linux/test_dhcp.py

index 55509cb84b21f6a7c2c0f184ea1c9f279ae4671d..f594b775c0f74b6170b3c098abef42254b041374 100644 (file)
@@ -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):
index 09a91a7caa5d9449b356d71eb2ad89c5020ee42d..fca35c1bb8b83ff0419fc927ca06d8b4a8ac8f6a 100644 (file)
@@ -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,'