]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix dhcp config dir removed too soon
authorDarragh O'Reilly <darragh.oreilly@hp.com>
Sun, 8 Mar 2015 11:10:34 +0000 (11:10 +0000)
committerDarragh O'Reilly <darragh.oreilly@hp.com>
Mon, 9 Mar 2015 17:01:03 +0000 (17:01 +0000)
The config dir is now removed after unplugging.
This patch also mocks out shutil.rmtree in all dhcp tests.

Change-Id: I68faacbb820957fa0bece7003676bd981c56de58
Closes-Bug: 1429559

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

index c558167c0c979b93a904aab3487410f6c98bb6ef..744ac1d53a4abfdcc99efcea874798beb5043329 100644 (file)
@@ -219,10 +219,9 @@ class DhcpLocalProcess(DhcpBase):
         """Disable DHCP for this network by killing the local process."""
         self.process_monitor.unregister(self.network.id, DNSMASQ_SERVICE_NAME)
         self._get_process_manager().disable()
-
-        self._remove_config_files()
         if not retain_port:
             self._destroy_namespace_and_port()
+        self._remove_config_files()
 
     def _destroy_namespace_and_port(self):
         try:
index 6533c9d28f7a0a731d81359ee4c84e27e1492ce1..779bd7108e7b14bd33f2322026d4840ef5555802 100644 (file)
@@ -622,6 +622,7 @@ class TestBase(base.BaseTestCase):
         self.makedirs = mock.patch('os.makedirs').start()
         self.isdir = mock.patch('os.path.isdir').start()
         self.isdir.return_value = False
+        self.rmtree = mock.patch('shutil.rmtree').start()
 
         self.external_process = mock.patch(
             'neutron.agent.linux.external_process.ProcessManager').start()
@@ -775,6 +776,18 @@ class TestDhcpLocalProcess(TestBase):
 
         ip.return_value.netns.delete.assert_called_with('qdhcp-ns')
 
+    def test_disable_config_dir_removed_after_destroy(self):
+        parent = mock.MagicMock()
+        parent.attach_mock(self.rmtree, 'rmtree')
+        parent.attach_mock(self.mock_mgr, 'DeviceManager')
+
+        lp = LocalChild(self.conf, FakeDualNetwork())
+        lp.disable(retain_port=False)
+
+        expected = [mock.call.DeviceManager().destroy(mock.ANY, mock.ANY),
+                    mock.call.rmtree(mock.ANY, ignore_errors=True)]
+        parent.assert_has_calls(expected)
+
     def test_get_interface_name(self):
         with mock.patch('__builtin__.open') as mock_open:
             mock_open.return_value.__enter__ = lambda s: s
@@ -1352,13 +1365,10 @@ class TestDnsmasq(TestBase):
         net = FakeV4Network()
         path = '/opt/data/neutron/dhcp'
         self.conf.dhcp_confs = path
-
-        with mock.patch('shutil.rmtree') as rmtree:
-            lp = LocalChild(self.conf, net)
-            lp._remove_config_files()
-
-            rmtree.assert_called_once_with(os.path.join(path, net.id),
-                                           ignore_errors=True)
+        lp = LocalChild(self.conf, net)
+        lp._remove_config_files()
+        self.rmtree.assert_called_once_with(os.path.join(path, net.id),
+                                            ignore_errors=True)
 
     def test_existing_dhcp_networks(self):
         path = '/opt/data/neutron/dhcp'