]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Do not attempt to kill already-dead dnsmasq
authorGary Kotton <gkotton@redhat.com>
Thu, 2 May 2013 11:35:58 +0000 (11:35 +0000)
committerGary Kotton <gkotton@redhat.com>
Thu, 2 May 2013 11:58:00 +0000 (11:58 +0000)
Fixes bug 1080846

The fix is following comments by Thiery Carrez (ttx) on the bug.

Change-Id: If4f6baad4212c23845c46703140e15f1ffcfe558

quantum/agent/linux/dhcp.py
quantum/tests/unit/test_linux_dhcp.py

index dd397bcb8e0e2e7b475ed2bef62533cbed7ca900..4f834a1ea0415dec5f2f974907c3cd228133c3db 100644 (file)
@@ -301,8 +301,11 @@ class Dnsmasq(DhcpLocalProcess):
 
         self._output_hosts_file()
         self._output_opts_file()
-        cmd = ['kill', '-HUP', self.pid]
-        utils.execute(cmd, self.root_helper)
+        if self.active:
+            cmd = ['kill', '-HUP', self.pid]
+            utils.execute(cmd, self.root_helper)
+        else:
+            LOG.debug(_('Pid %d is stale, relaunching dnsmasq'), self.pid)
         LOG.debug(_('Reloading allocations for network: %s'), self.network.id)
 
     def _output_hosts_file(self):
index c19b96334535f48d51628d49c42527a2b6720993..414b197b190abe9ec8aaec9dc645db87b483208e 100644 (file)
@@ -538,6 +538,49 @@ tag:tag1,option:classless-static-route,%s,%s""".lstrip() % (fake_v6,
 
         exp_args = ['kill', '-HUP', 5]
 
+        with mock.patch('os.path.isdir') as isdir:
+            isdir.return_value = True
+            with mock.patch.object(dhcp.Dnsmasq, 'active') as active:
+                active.__get__ = mock.Mock(return_value=True)
+                with mock.patch.object(dhcp.Dnsmasq, 'pid') as pid:
+                    pid.__get__ = mock.Mock(return_value=5)
+                    dm = dhcp.Dnsmasq(self.conf, FakeDualNetwork(),
+                                      namespace='qdhcp-ns')
+
+                    method_name = '_make_subnet_interface_ip_map'
+                    with mock.patch.object(dhcp.Dnsmasq,
+                                           method_name) as ip_map:
+                        ip_map.return_value = {}
+                        dm.reload_allocations()
+                        self.assertTrue(ip_map.called)
+
+        self.safe.assert_has_calls([mock.call(exp_host_name, exp_host_data),
+                                    mock.call(exp_opt_name, exp_opt_data)])
+        self.execute.assert_called_once_with(exp_args, 'sudo')
+
+    def test_reload_allocations_stale_pid(self):
+        exp_host_name = '/dhcp/cccccccc-cccc-cccc-cccc-cccccccccccc/host'
+        exp_host_data = """
+00:00:80:aa:bb:cc,192-168-0-2.openstacklocal,192.168.0.2
+00:00:f3:aa:bb:cc,fdca-3ba5-a17a-4ba3--2.openstacklocal,fdca:3ba5:a17a:4ba3::2
+00:00:0f:aa:bb:cc,192-168-0-3.openstacklocal,192.168.0.3
+00:00:0f:aa:bb:cc,fdca-3ba5-a17a-4ba3--3.openstacklocal,fdca:3ba5:a17a:4ba3::3
+""".lstrip()
+        exp_opt_name = '/dhcp/cccccccc-cccc-cccc-cccc-cccccccccccc/opts'
+        exp_opt_data = "tag:tag0,option:router,192.168.0.1"
+        fake_v6 = 'gdca:3ba5:a17a:4ba3::1'
+        fake_v6_cidr = 'gdca:3ba5:a17a:4ba3::/64'
+        exp_opt_data = """
+tag:tag0,option:dns-server,8.8.8.8
+tag:tag0,option:classless-static-route,20.0.0.1/24,20.0.0.1
+tag:tag0,option:router,192.168.0.1
+tag:tag1,option:dns-server,%s
+tag:tag1,option:classless-static-route,%s,%s""".lstrip() % (fake_v6,
+                                                            fake_v6_cidr,
+                                                            fake_v6)
+
+        exp_args = ['cat', '/proc/5/cmdline']
+
         with mock.patch('os.path.isdir') as isdir:
             isdir.return_value = True
             with mock.patch.object(dhcp.Dnsmasq, 'pid') as pid: